mars/kernel/sy_old/mars_proc.c

309 lines
8.3 KiB
C
Raw Normal View History

2011-03-02 16:20:36 +00:00
// (c) 2011 Thomas Schoebel-Theuer / 1&1 Internet AG
//#define BRICK_DEBUGGING
//#define MARS_DEBUGGING
//#define IO_DEBUGGING
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/sysctl.h>
#include <linux/uaccess.h>
2011-07-22 10:43:40 +00:00
#include "strategy.h"
2011-03-02 16:20:36 +00:00
#include "mars_proc.h"
#include "../lib_mapfree.h"
#include "../mars_bio.h"
#include "../mars_aio.h"
#include "../mars_copy.h"
#include "../mars_client.h"
#include "../mars_server.h"
#include "../mars_trans_logger.h"
2011-03-02 16:20:36 +00:00
mars_info_fn mars_info = NULL;
static
int trigger_sysctl_handler(
ctl_table *table,
int write,
void __user *buffer,
size_t *length,
loff_t *ppos)
2011-03-02 16:20:36 +00:00
{
ssize_t res = 0;
size_t len = *length;
MARS_DBG("write = %d len = %ld pos = %lld\n", write, len, *ppos);
if (!len || *ppos > 0) {
goto done;
}
if (write) {
char tmp[8] = {};
int code = 0;
res = len; // fake consumption of all data
if (len > 7)
len = 7;
if (!copy_from_user(tmp, buffer, len)) {
sscanf(tmp, "%d", &code);
if (code > 0) {
2011-03-02 16:20:36 +00:00
mars_trigger();
}
if (code > 1) {
mars_remote_trigger();
2011-03-02 16:20:36 +00:00
}
}
} else {
2013-05-13 07:53:57 +00:00
char *answer = "MARS module not operational\n";
2011-03-02 16:20:36 +00:00
char *tmp = NULL;
int mylen;
if (mars_info) {
answer = "internal error while determining mars_info\n";
tmp = mars_info();
if (tmp)
answer = tmp;
}
mylen = strlen(answer);
if (len > mylen)
len = mylen;
res = len;
if (copy_to_user(buffer, answer, len)) {
MARS_ERR("write %ld bytes at %p failed\n", len, buffer);
res = -EFAULT;
}
2011-08-12 11:09:48 +00:00
brick_string_free(tmp);
2011-03-02 16:20:36 +00:00
}
done:
MARS_DBG("res = %ld\n", res);
*length = res;
if (res >= 0) {
*ppos += res;
return 0;
}
return res;
}
static
int lamport_sysctl_handler(
ctl_table *table,
int write,
void __user *buffer,
size_t *length,
loff_t *ppos)
{
ssize_t res = 0;
size_t len = *length;
MARS_DBG("write = %d len = %ld pos = %lld\n", write, len, *ppos);
if (!len || *ppos > 0) {
goto done;
}
if (write) {
return -EINVAL;
} else {
char *tmp = brick_string_alloc(len);
2013-05-06 13:39:37 +00:00
struct timespec know = CURRENT_TIME;
struct timespec lnow;
get_lamport(&lnow);
res = snprintf(tmp, len,
"CURRENT_TIME=%ld.%09ld\n"
"lamport_now=%ld.%09ld\n",
2013-05-06 13:39:37 +00:00
know.tv_sec, know.tv_nsec,
lnow.tv_sec, lnow.tv_nsec
);
if (copy_to_user(buffer, tmp, res)) {
MARS_ERR("write %ld bytes at %p failed\n", res, buffer);
res = -EFAULT;
}
brick_string_free(tmp);
}
done:
MARS_DBG("res = %ld\n", res);
*length = res;
if (res >= 0) {
*ppos += res;
return 0;
}
return res;
}
#ifdef CONFIG_MARS_LOADAVG_LIMIT
int mars_max_loadavg = 0;
EXPORT_SYMBOL_GPL(mars_max_loadavg);
#endif
2012-09-18 06:13:33 +00:00
#ifdef CTL_UNNUMBERED
#define _CTL_NAME .ctl_name = CTL_UNNUMBERED,
#define _CTL_STRATEGY(handler) .strategy = &handler,
#else
#define _CTL_NAME /*empty*/
#define _CTL_STRATEGY(handler) /*empty*/
#endif
#define INT_ENTRY(NAME,VAR,MODE) \
{ \
_CTL_NAME \
.procname = NAME, \
.data = &(VAR), \
.maxlen = sizeof(int), \
.mode = MODE, \
.proc_handler = &proc_dointvec, \
_CTL_STRATEGY(sysctl_intvec) \
}
#define LIMITER_ENTRIES(VAR, PREFIX, SUFFIX) \
INT_ENTRY(PREFIX "_limit_" SUFFIX, (VAR)->lim_max_rate, 0600), \
INT_ENTRY(PREFIX "_rate_" SUFFIX, (VAR)->lim_rate, 0400) \
#define THRESHOLD_ENTRIES(VAR, PREFIX) \
INT_ENTRY(PREFIX "_threshold_us", (VAR)->thr_limit, 0600), \
INT_ENTRY(PREFIX "_factor_percent", (VAR)->thr_factor, 0600), \
INT_ENTRY(PREFIX "_plus_us", (VAR)->thr_plus, 0600), \
INT_ENTRY(PREFIX "_triggered", (VAR)->thr_triggered,0400), \
INT_ENTRY(PREFIX "_true_hit", (VAR)->thr_true_hit, 0400) \
static
ctl_table tuning_table[] = {
LIMITER_ENTRIES(&client_limiter, "traffic", "kb"),
LIMITER_ENTRIES(&server_limiter, "server_io", "kb"),
LIMITER_ENTRIES(&global_writeback.limiter, "writeback", "kb"),
INT_ENTRY("writeback_until_percent", global_writeback.until_percent, 0600),
THRESHOLD_ENTRIES(&bio_submit_threshold, "bio_submit"),
THRESHOLD_ENTRIES(&bio_io_threshold[0], "bio_io_r"),
THRESHOLD_ENTRIES(&bio_io_threshold[1], "bio_io_w"),
THRESHOLD_ENTRIES(&aio_submit_threshold, "aio_submit"),
THRESHOLD_ENTRIES(&aio_io_threshold[0], "aio_io_r"),
THRESHOLD_ENTRIES(&aio_io_threshold[1], "aio_io_w"),
THRESHOLD_ENTRIES(&aio_sync_threshold, "aio_sync"),
{}
};
2011-03-02 16:20:36 +00:00
static
ctl_table mars_table[] = {
{
2012-09-18 06:13:33 +00:00
_CTL_NAME
.procname = "trigger",
.mode = 0200,
.proc_handler = &trigger_sysctl_handler,
},
2013-05-13 07:53:57 +00:00
{
_CTL_NAME
.procname = "info",
.mode = 0400,
.proc_handler = &trigger_sysctl_handler,
},
{
_CTL_NAME
.procname = "lamport_clock",
.mode = 0400,
.proc_handler = &lamport_sysctl_handler,
},
2013-04-08 08:45:20 +00:00
INT_ENTRY("show_log_messages", brick_say_logging, 0600),
INT_ENTRY("show_debug_messages", brick_say_debug, 0600),
INT_ENTRY("show_statistics_global", global_show_statist, 0600),
INT_ENTRY("show_statistics_server", server_show_statist, 0600),
INT_ENTRY("show_connections", global_show_connections, 0600),
INT_ENTRY("aio_sync_mode", aio_sync_mode, 0600),
INT_ENTRY("logger_completion_semantics", trans_logger_completion_semantics, 0600),
INT_ENTRY("logger_do_crc", trans_logger_do_crc, 0600),
INT_ENTRY("syslog_min_class", brick_say_syslog_min, 0600),
INT_ENTRY("syslog_max_class", brick_say_syslog_max, 0600),
INT_ENTRY("delay_say_on_overflow",delay_say_on_overflow, 0600),
INT_ENTRY("mapfree_period_sec", mapfree_period_sec, 0600),
2013-09-16 09:51:03 +00:00
INT_ENTRY("mapfree_grace_keep_mb", mapfree_grace_keep_mb, 0600),
INT_ENTRY("logger_max_interleave", trans_logger_max_interleave, 0600),
INT_ENTRY("logger_resume", trans_logger_resume, 0600),
INT_ENTRY("logger_replay_timeout_sec", trans_logger_replay_timeout, 0600),
INT_ENTRY("mem_limit_percent", mars_mem_percent, 0600),
2012-11-15 13:35:02 +00:00
INT_ENTRY("logger_mem_used_kb", trans_logger_mem_usage, 0400),
INT_ENTRY("mem_used_raw_kb", brick_global_block_used,0400),
INT_ENTRY("io_flying_count", mars_global_io_flying, 0400),
INT_ENTRY("copy_overlap", mars_copy_overlap, 0600),
INT_ENTRY("copy_read_prio", mars_copy_read_prio, 0600),
INT_ENTRY("copy_write_prio", mars_copy_write_prio, 0600),
2013-07-22 07:15:53 +00:00
INT_ENTRY("copy_read_max_fly", mars_copy_read_max_fly, 0600),
INT_ENTRY("copy_write_max_fly", mars_copy_write_max_fly,0600),
INT_ENTRY("statusfiles_rollover_sec", mars_rollover_interval, 0600),
INT_ENTRY("scan_interval_sec", mars_scan_interval, 0600),
INT_ENTRY("propagate_interval_sec", mars_propagate_interval, 0600),
INT_ENTRY("sync_flip_interval_sec", mars_sync_flip_interval, 0600),
INT_ENTRY("do_fast_fullsync", mars_fast_fullsync, 0600),
INT_ENTRY("logrot_auto_gb", global_logrot_auto, 0600),
INT_ENTRY("required_total_space_0_gb", global_free_space_0, 0600),
INT_ENTRY("required_free_space_1_gb", global_free_space_1, 0600),
INT_ENTRY("required_free_space_2_gb", global_free_space_2, 0600),
INT_ENTRY("required_free_space_3_gb", global_free_space_3, 0600),
INT_ENTRY("required_free_space_4_gb", global_free_space_4, 0600),
INT_ENTRY("mars_emergency_mode", mars_emergency_mode, 0600),
INT_ENTRY("mars_reset_emergency", mars_reset_emergency, 0600),
#ifdef CONFIG_MARS_LOADAVG_LIMIT
INT_ENTRY("loadavg_limit", mars_max_loadavg, 0600),
#endif
2013-04-09 13:03:46 +00:00
// changing makes no sense because the server will immediately start upon modprobe
INT_ENTRY("mars_port", mars_net_default_port, 0400),
INT_ENTRY("network_io_timeout", global_net_io_timeout, 0600),
2012-08-21 11:43:56 +00:00
{
2012-09-18 06:13:33 +00:00
_CTL_NAME
.procname = "tuning",
.mode = 0500,
.child = tuning_table,
2012-09-26 09:29:18 +00:00
},
{}
};
static
ctl_table mars_root_table[] = {
2011-03-02 16:20:36 +00:00
{
2012-09-18 06:13:33 +00:00
_CTL_NAME
2011-03-02 16:20:36 +00:00
.procname = "mars",
.mode = 0500,
.child = mars_table,
2011-03-02 16:20:36 +00:00
},
{}
};
////////////////// module init stuff /////////////////////////
static struct ctl_table_header *header = NULL;
2011-08-25 10:16:32 +00:00
int __init init_mars_proc(void)
2011-03-02 16:20:36 +00:00
{
MARS_INF("init_proc()\n");
2011-08-26 10:31:56 +00:00
header = register_sysctl_table(mars_root_table);
2011-03-02 16:20:36 +00:00
return 0;
}
2011-08-25 10:16:32 +00:00
void __exit exit_mars_proc(void)
2011-03-02 16:20:36 +00:00
{
MARS_INF("exit_proc()\n");
if (header) {
unregister_sysctl_table(header);
header = NULL;
}
}
2011-08-25 10:16:32 +00:00
#ifndef CONFIG_MARS_HAVE_BIGMODULE
2011-03-02 16:20:36 +00:00
MODULE_DESCRIPTION("MARS /proc/ infrastructure");
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
MODULE_LICENSE("GPL");
2011-08-25 10:16:32 +00:00
module_init(init_mars_proc);
module_exit(exit_mars_proc);
#endif