From 7dec70085da55fb128ddce045086e6fc3cbc4b1c Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 2 Mar 2011 17:20:36 +0100 Subject: [PATCH] import mars-67.tgz --- Makefile | 2 +- mars_proc.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++ mars_proc.h | 11 +++++ userspace/marsadm | 26 ++++++++-- 4 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 mars_proc.c create mode 100644 mars_proc.h diff --git a/Makefile b/Makefile index 70e0d990..d5d8c4c7 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Makefile for MARS # -obj-$(CONFIG_MARS) += brick.o mars_generic.o mars_net.o +obj-$(CONFIG_MARS) += brick.o mars_generic.o mars_net.o mars_proc.o obj-$(CONFIG_MARS_DUMMY) += mars_dummy.o obj-$(CONFIG_MARS_CHECK) += mars_check.o obj-$(CONFIG_MARS_IF_DEVICE) += mars_if_device.o diff --git a/mars_proc.c b/mars_proc.c new file mode 100644 index 00000000..e09153c4 --- /dev/null +++ b/mars_proc.c @@ -0,0 +1,123 @@ +// (c) 2011 Thomas Schoebel-Theuer / 1&1 Internet AG + +//#define BRICK_DEBUGGING +//#define MARS_DEBUGGING +//#define IO_DEBUGGING + +#include +#include +#include + +#include +#include + +#define _STRATEGY +#include "mars.h" +#include "mars_proc.h" + +mars_info_fn mars_info = NULL; + +static +int mars_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) { + 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) { + mars_trigger(); + } + } + } else { + char *answer = "MARS module not loaded\n"; + 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; + } + if (tmp) + kfree(tmp); + } + +done: + MARS_DBG("res = %ld\n", res); + *length = res; + if (res >= 0) { + *ppos += res; + return 0; + } + return res; +} + +static +ctl_table mars_table[] = { + { + .ctl_name = CTL_UNNUMBERED, + .procname = "mars", + .mode = 0600, + .proc_handler = &mars_sysctl_handler, + }, + {} +}; + +////////////////// module init stuff ///////////////////////// + +static struct ctl_table_header *header = NULL; + +static int __init _init_proc(void) +{ + + MARS_INF("init_proc()\n"); + + header = register_sysctl_table(mars_table); + + return 0; +} + +static void __exit _exit_proc(void) +{ + MARS_INF("exit_proc()\n"); + if (header) { + unregister_sysctl_table(header); + header = NULL; + } +} + +MODULE_DESCRIPTION("MARS /proc/ infrastructure"); +MODULE_AUTHOR("Thomas Schoebel-Theuer "); +MODULE_LICENSE("GPL"); + +module_init(_init_proc); +module_exit(_exit_proc); diff --git a/mars_proc.h b/mars_proc.h new file mode 100644 index 00000000..feaab77a --- /dev/null +++ b/mars_proc.h @@ -0,0 +1,11 @@ +// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG +#ifndef MARS_PROC_H +#define MARS_PROC_H + +#include "brick.h" + +typedef char * (*mars_info_fn)(void); + +extern mars_info_fn mars_info; + +#endif diff --git a/userspace/marsadm b/userspace/marsadm index c41b8689..5eb026ed 100644 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -346,8 +346,26 @@ my $res = shift || die "resource argument is missing\n"; die "unknown command '$cmd'\n" if !exists $cmd_table{$cmd}; check_id($res); -check_res($res) unless $cmd =~ m/^(join-system|create-resource)$/; -check_res_member($res) unless $cmd =~ m/^(join|create)-(system|resource)$/; -my $func = $cmd_table{$cmd}; -&{$func}($cmd, $res, @ARGV); +sub do_res { + my $cmd = shift; + my $res = shift; + + check_res($res) unless $cmd =~ m/^(join-system|create-resource)$/; + check_res_member($res) unless $cmd =~ m/^(join|create)-(system|resource)$/; + + my $func = $cmd_table{$cmd}; + &{$func}($cmd, $res, @_); +} + +if($res eq "all") { + foreach $res (glob("$mars/resource-*")) { + next unless -e "$res/data-$host"; + $res =~ s/^.*\/resource-(.*)$/$1/; + print "--------- resource $res\n"; + do_res($cmd, $res, @ARGV); + } +} else { + do_res($cmd, $res, @ARGV); +} +