[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1441289792-64064-7-git-send-email-thehajime@gmail.com>
Date: Thu, 3 Sep 2015 23:16:28 +0900
From: Hajime Tazaki <thehajime@...il.com>
To: linux-arch@...r.kernel.org
Cc: Hajime Tazaki <thehajime@...il.com>, Arnd Bergmann <arnd@...db.de>,
Jonathan Corbet <corbet@....net>,
Christoph Lameter <cl@...ux.com>,
Jekka Enberg <penberg@...nel.org>,
Javid Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Jndrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
netdev@...r.kernel.org, linux-mm@...ck.org,
Jeff Dike <jdike@...toit.com>,
Richard Weinberger <richard@....at>,
Rusty Russell <rusty@...tcorp.com.au>,
Ryo Nakamura <upa@...ena.net>,
Christoph Paasch <christoph.paasch@...il.com>,
Mathieu Lacage <mathieu.lacage@...il.com>,
libos-nuse@...glegroups.com
Subject: [PATCH v6 06/10] lib: sysctl handling (kernel glue code)
This interacts with fs/proc_fs.c for sysctl-like interface registered via
lib_init() API.
Signed-off-by: Hajime Tazaki <thehajime@...il.com>
---
arch/lib/sysctl.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 270 insertions(+)
create mode 100644 arch/lib/sysctl.c
diff --git a/arch/lib/sysctl.c b/arch/lib/sysctl.c
new file mode 100644
index 000000000000..5f08f9f97103
--- /dev/null
+++ b/arch/lib/sysctl.c
@@ -0,0 +1,270 @@
+/*
+ * sysctl wrapper for library version of Linux kernel
+ * Copyright (c) 2015 INRIA, Hajime Tazaki
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@...il.com>
+ * Hajime Tazaki <tazaki@....wide.ad.jp>
+ */
+
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/mman.h>
+#include <linux/ratelimit.h>
+#include <linux/proc_fs.h>
+#include "sim-assert.h"
+#include "sim-types.h"
+
+int drop_caches_sysctl_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *length, loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *length,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int min_free_kbytes_sysctl_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *length, loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+
+int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *length,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int dirty_background_ratio_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *lenp,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int dirty_background_bytes_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *lenp,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int dirty_ratio_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *lenp,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int dirty_bytes_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *lenp,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
+ void *buffer, size_t *length,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int scan_unevictable_handler(struct ctl_table *table, int write,
+ void __user *buffer,
+ size_t *length, loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+int sched_rt_handler(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp,
+ loff_t *ppos)
+{
+ lib_assert(false);
+ return 0;
+}
+
+int sysctl_overcommit_memory = OVERCOMMIT_GUESS;
+int sysctl_overcommit_ratio = 50;
+int sysctl_panic_on_oom = 0;
+int sysctl_oom_dump_tasks = 0;
+int sysctl_oom_kill_allocating_task = 0;
+int sysctl_nr_trim_pages = 0;
+int sysctl_drop_caches = 0;
+int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES - 1] = { 32 };
+unsigned int sysctl_sched_child_runs_first = 0;
+unsigned int sysctl_sched_compat_yield = 0;
+unsigned int sysctl_sched_rt_period = 1000000;
+int sysctl_sched_rt_runtime = 950000;
+
+int vm_highmem_is_dirtyable;
+unsigned long vm_dirty_bytes = 0;
+int vm_dirty_ratio = 20;
+int dirty_background_ratio = 10;
+unsigned int dirty_expire_interval = 30 * 100;
+unsigned int dirty_writeback_interval = 5 * 100;
+unsigned long dirty_background_bytes = 0;
+int percpu_pagelist_fraction = 0;
+int panic_timeout = 0;
+int panic_on_oops = 0;
+int printk_delay_msec = 0;
+int panic_on_warn = 0;
+DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
+
+#define RESERVED_PIDS 300
+int pid_max = PID_MAX_DEFAULT;
+int pid_max_min = RESERVED_PIDS + 1;
+int pid_max_max = PID_MAX_LIMIT;
+int min_free_kbytes = 1024;
+int max_threads = 100;
+int laptop_mode = 0;
+
+#define DEFAULT_MESSAGE_LOGLEVEL 4
+#define MINIMUM_CONSOLE_LOGLEVEL 1
+#define DEFAULT_CONSOLE_LOGLEVEL 7
+int console_printk[4] = {
+ DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */
+ DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */
+ MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */
+ DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
+};
+
+int print_fatal_signals = 0;
+unsigned int core_pipe_limit = 0;
+int core_uses_pid = 0;
+int vm_swappiness = 60;
+int nr_pdflush_threads = 0;
+unsigned long scan_unevictable_pages = 0;
+int suid_dumpable = 0;
+int page_cluster = 0;
+int block_dump = 0;
+int C_A_D = 0;
+#include <linux/nsproxy.h>
+struct nsproxy init_nsproxy;
+#include <linux/reboot.h>
+char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
+unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
+unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
+
+int pdflush_proc_obsolete(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+ return nr_pdflush_threads;
+}
+#include <linux/fs.h>
+
+/**
+ * Honestly, I don't understand half of that code.
+ * It was modeled after fs/proc/proc_sysctl.c proc_sys_readdir
+ *
+ * Me either ;) (Hajime, Jan 2013)
+ */
+
+/* from proc_sysctl.c (XXX) */
+extern struct ctl_table_root sysctl_table_root;
+void ctl_table_first_entry(struct ctl_dir *dir,
+ struct ctl_table_header **phead, struct ctl_table **pentry);
+void ctl_table_next_entry(struct ctl_table_header **phead, struct ctl_table **pentry);
+struct ctl_table *ctl_table_find_entry(struct ctl_table_header **phead,
+ struct ctl_dir *dir, const char *name,
+ int namelen);
+struct ctl_dir *ctl_table_xlate_dir(struct ctl_table_set *set, struct ctl_dir *dir);
+/* for init_net (XXX, should be fixed) */
+#include <net/net_namespace.h>
+
+static void iterate_table_recursive(const struct SimSysIterator *iter,
+ struct ctl_table_header *head)
+{
+ struct ctl_table *entry;
+
+ for (entry = head->ctl_table; entry->procname; entry++) {
+ bool may_read = (head->ctl_table->mode & MAY_READ);
+ bool may_write = (head->ctl_table->mode & MAY_WRITE);
+ int flags = 0;
+
+ flags |= may_read ? SIM_SYS_FILE_READ : 0;
+ flags |= may_write ? SIM_SYS_FILE_WRITE : 0;
+ iter->report_file(iter, entry->procname, flags,
+ (struct SimSysFile *)entry);
+ }
+}
+
+
+static void iterate_recursive(const struct SimSysIterator *iter,
+ struct ctl_table_header *head)
+{
+ struct ctl_table_header *h = NULL;
+ struct ctl_table *entry;
+ struct ctl_dir *ctl_dir;
+
+ ctl_dir = container_of(head, struct ctl_dir, header);
+ for (ctl_table_first_entry(ctl_dir, &h, &entry); h;
+ ctl_table_next_entry(&h, &entry)) {
+ struct ctl_dir *dir;
+ int ret;
+ const char *procname;
+
+ /* copy from sysctl_follow_link () */
+ if (S_ISLNK(entry->mode)) {
+ dir = ctl_table_xlate_dir(&init_net.sysctls, h->parent);
+ if (IS_ERR(dir)) {
+ ret = PTR_ERR(dir);
+ lib_assert(false);
+ } else {
+ procname = entry->procname;
+ h = NULL;
+ entry =
+ ctl_table_find_entry(&h, dir, procname,
+ strlen(procname));
+ ret = -ENOENT;
+ }
+ }
+
+ if (S_ISDIR(entry->mode)) {
+ iter->report_start_dir(iter, entry->procname);
+ iterate_recursive(iter, h);
+ iter->report_end_dir(iter);
+ } else
+ iterate_table_recursive(iter, h);
+ }
+
+}
+
+
+void lib_sys_iterate_files(const struct SimSysIterator *iter)
+{
+ struct ctl_table_header *root =
+ &sysctl_table_root.default_set.dir.header;
+
+ iterate_recursive(iter, root);
+}
+
+int lib_sys_file_read(const struct SimSysFile *file, char *buffer, int size,
+ int offset)
+{
+ struct ctl_table *table = (struct ctl_table *)file;
+ loff_t ppos = offset;
+ size_t result = size;
+ int error;
+
+ error = table->proc_handler(table, 0, buffer, &result, &ppos);
+ return result;
+}
+int lib_sys_file_write(const struct SimSysFile *file, const char *buffer,
+ int size, int offset)
+{
+ struct ctl_table *table = (struct ctl_table *)file;
+ loff_t ppos = offset;
+ size_t result = size;
+ int error;
+
+ error = table->proc_handler(table, 1, (char *)buffer, &result, &ppos);
+ return result;
+}
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists