2010-06-14 14:27:40 +00:00
|
|
|
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
//#define BRICK_DEBUGGING
|
|
|
|
//#define MARS_DEBUGGING
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
2011-02-23 20:48:06 +00:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/utsname.h>
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
#include "mars.h"
|
2011-03-03 09:02:10 +00:00
|
|
|
#include "mars_client.h"
|
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// infrastructure
|
|
|
|
|
|
|
|
static char *id = NULL;
|
2011-02-23 20:48:06 +00:00
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
/* TODO: better use MAC addresses (or motherboard IDs where available).
|
|
|
|
* Or, at least, some checks for MAC addresses should be recorded / added.
|
|
|
|
* When the nodename is misconfigured, data might be scrambled.
|
|
|
|
* MAC addresses should be more secure.
|
|
|
|
* In ideal case, further checks should be added to prohibit accidental
|
|
|
|
* name clashes.
|
|
|
|
*/
|
|
|
|
char *my_id(void)
|
|
|
|
{
|
|
|
|
struct new_utsname *u;
|
2011-08-12 11:09:48 +00:00
|
|
|
if (!id) {
|
|
|
|
//down_read(&uts_sem); // FIXME: this is currenty not EXPORTed from the kernel!
|
|
|
|
u = utsname();
|
|
|
|
if (u) {
|
|
|
|
id = brick_strdup(u->nodename);
|
|
|
|
}
|
|
|
|
//up_read(&uts_sem);
|
2011-07-22 10:43:40 +00:00
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(my_id);
|
2011-04-19 14:46:38 +00:00
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// object stuff
|
|
|
|
|
|
|
|
const struct generic_object_type mref_type = {
|
|
|
|
.object_type_name = "mref",
|
|
|
|
.default_size = sizeof(struct mref_object),
|
|
|
|
.brick_obj_nr = BRICK_OBJ_MREF,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(mref_type);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// brick stuff
|
|
|
|
|
2011-02-28 18:00:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// meta descriptions
|
|
|
|
|
|
|
|
const struct meta mars_info_meta[] = {
|
|
|
|
META_INI(current_size, struct mars_info, FIELD_INT),
|
|
|
|
META_INI(transfer_order, struct mars_info, FIELD_INT),
|
|
|
|
META_INI(transfer_size, struct mars_info, FIELD_INT),
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(mars_info_meta);
|
|
|
|
|
|
|
|
const struct meta mars_mref_meta[] = {
|
2011-10-04 11:34:18 +00:00
|
|
|
META_INI(_object_cb.cb_error, struct mref_object, FIELD_INT),
|
2011-02-28 18:00:32 +00:00
|
|
|
META_INI(ref_pos, struct mref_object, FIELD_INT),
|
|
|
|
META_INI(ref_len, struct mref_object, FIELD_INT),
|
|
|
|
META_INI(ref_may_write, struct mref_object, FIELD_INT),
|
2011-03-10 11:40:06 +00:00
|
|
|
META_INI(ref_prio, struct mref_object, FIELD_INT),
|
2011-03-07 10:27:38 +00:00
|
|
|
META_INI(ref_timeout, struct mref_object, FIELD_INT),
|
2011-03-24 16:05:46 +00:00
|
|
|
META_INI(ref_total_size, struct mref_object, FIELD_INT),
|
2011-02-28 18:00:32 +00:00
|
|
|
META_INI(ref_flags, struct mref_object, FIELD_INT),
|
|
|
|
META_INI(ref_rw, struct mref_object, FIELD_INT),
|
|
|
|
META_INI(ref_id, struct mref_object, FIELD_INT),
|
2011-03-24 16:05:46 +00:00
|
|
|
META_INI(ref_skip_sync, struct mref_object, FIELD_INT),
|
2011-02-28 18:00:32 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(mars_mref_meta);
|
|
|
|
|
|
|
|
const struct meta mars_timespec_meta[] = {
|
|
|
|
META_INI(tv_sec, struct timespec, FIELD_INT),
|
|
|
|
META_INI(tv_nsec, struct timespec, FIELD_INT),
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(mars_timespec_meta);
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
// tracing
|
|
|
|
|
|
|
|
#ifdef MARS_TRACING
|
|
|
|
|
2011-03-29 14:40:40 +00:00
|
|
|
unsigned long long start_trace_clock = 0;
|
|
|
|
EXPORT_SYMBOL_GPL(start_trace_clock);
|
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
struct file *mars_log_file = NULL;
|
|
|
|
loff_t mars_log_pos = 0;
|
|
|
|
|
|
|
|
void _mars_log(char *buf, int len)
|
|
|
|
{
|
|
|
|
static DECLARE_MUTEX(trace_lock);
|
|
|
|
mm_segment_t oldfs;
|
|
|
|
|
|
|
|
|
|
|
|
oldfs = get_fs();
|
|
|
|
set_fs(get_ds());
|
|
|
|
down(&trace_lock);
|
|
|
|
|
|
|
|
vfs_write(mars_log_file, buf, len, &mars_log_pos);
|
|
|
|
|
|
|
|
up(&trace_lock);
|
|
|
|
set_fs(oldfs);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(_mars_log);
|
|
|
|
|
|
|
|
void mars_log(const char *fmt, ...)
|
|
|
|
{
|
2011-08-25 10:16:32 +00:00
|
|
|
char *buf = brick_string_alloc(0);
|
2011-03-27 15:18:38 +00:00
|
|
|
va_list args;
|
|
|
|
int len;
|
|
|
|
if (!buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
len = vsnprintf(buf, PAGE_SIZE, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_mars_log(buf, len);
|
|
|
|
|
2011-08-12 11:09:48 +00:00
|
|
|
brick_string_free(buf);
|
2011-03-27 15:18:38 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_log);
|
|
|
|
|
|
|
|
void mars_trace(struct mref_object *mref, const char *info)
|
|
|
|
{
|
|
|
|
int index = mref->ref_traces;
|
2011-03-29 14:40:40 +00:00
|
|
|
if (likely(index < MAX_TRACES)) {
|
|
|
|
mref->ref_trace_stamp[index] = cpu_clock(raw_smp_processor_id());
|
2011-03-27 15:18:38 +00:00
|
|
|
mref->ref_trace_info[index] = info;
|
|
|
|
mref->ref_traces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_trace);
|
|
|
|
|
|
|
|
void mars_log_trace(struct mref_object *mref)
|
|
|
|
{
|
2011-08-25 10:16:32 +00:00
|
|
|
char *buf = brick_string_alloc(0);
|
2011-03-29 14:40:40 +00:00
|
|
|
unsigned long long old;
|
|
|
|
unsigned long long diff;
|
2011-03-27 15:18:38 +00:00
|
|
|
int i;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mars_log_file || !mref->ref_traces) {
|
|
|
|
goto done;
|
|
|
|
}
|
2011-03-29 14:40:40 +00:00
|
|
|
if (!start_trace_clock) {
|
|
|
|
start_trace_clock = mref->ref_trace_stamp[0];
|
2011-03-27 15:18:38 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 14:40:40 +00:00
|
|
|
diff = mref->ref_trace_stamp[mref->ref_traces-1] - mref->ref_trace_stamp[0];
|
2011-03-27 15:18:38 +00:00
|
|
|
|
2011-07-20 13:11:44 +00:00
|
|
|
len = snprintf(buf, PAGE_SIZE, "%c ;%12lld ;%6d;%10llu", mref->ref_rw ? 'W' : 'R', mref->ref_pos, mref->ref_len, diff / 1000);
|
2011-03-27 15:18:38 +00:00
|
|
|
|
2011-03-29 14:40:40 +00:00
|
|
|
old = start_trace_clock;
|
2011-03-27 15:18:38 +00:00
|
|
|
for (i = 0; i < mref->ref_traces; i++) {
|
2011-03-29 14:40:40 +00:00
|
|
|
diff = mref->ref_trace_stamp[i] - old;
|
2011-03-27 15:18:38 +00:00
|
|
|
|
2011-07-20 13:11:44 +00:00
|
|
|
len += snprintf(buf + len, PAGE_SIZE - len, " ; %s ;%10llu", mref->ref_trace_info[i], diff / 1000);
|
2011-03-27 15:18:38 +00:00
|
|
|
old = mref->ref_trace_stamp[i];
|
|
|
|
}
|
2011-07-20 13:11:44 +00:00
|
|
|
len +=snprintf(buf + len, PAGE_SIZE - len, "\n");
|
2011-03-27 15:18:38 +00:00
|
|
|
|
|
|
|
_mars_log(buf, len);
|
|
|
|
|
|
|
|
done:
|
2011-08-12 11:09:48 +00:00
|
|
|
brick_string_free(buf);
|
2011-03-29 14:40:40 +00:00
|
|
|
mref->ref_traces = 0;
|
2011-03-27 15:18:38 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_log_trace);
|
|
|
|
|
|
|
|
#endif // MARS_TRACING
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
// power led handling
|
2011-03-23 17:58:02 +00:00
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
void mars_power_led_on(struct generic_brick *brick, bool val)
|
2011-02-23 20:48:06 +00:00
|
|
|
{
|
|
|
|
bool oldval = brick->power.led_on;
|
|
|
|
if (val != oldval) {
|
2011-07-22 10:43:40 +00:00
|
|
|
//MARS_DBG("brick '%s' type '%s' led_on %d -> %d\n", brick->brick_path, brick->type->type_name, oldval, val);
|
2011-02-23 20:48:06 +00:00
|
|
|
set_led_on(&brick->power, val);
|
|
|
|
mars_trigger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_power_led_on);
|
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
void mars_power_led_off(struct generic_brick *brick, bool val)
|
2011-02-23 20:48:06 +00:00
|
|
|
{
|
|
|
|
bool oldval = brick->power.led_off;
|
|
|
|
if (val != oldval) {
|
2011-07-22 10:43:40 +00:00
|
|
|
//MARS_DBG("brick '%s' type '%s' led_off %d -> %d\n", brick->brick_path, brick->type->type_name, oldval, val);
|
2011-02-23 20:48:06 +00:00
|
|
|
set_led_off(&brick->power, val);
|
|
|
|
mars_trigger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_power_led_off);
|
2010-07-30 11:50:20 +00:00
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// init stuff
|
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
void (*_mars_trigger)(void) = NULL;
|
|
|
|
EXPORT_SYMBOL_GPL(_mars_trigger);
|
|
|
|
|
2011-03-02 09:30:56 +00:00
|
|
|
struct mm_struct *mm_fake = NULL;
|
|
|
|
EXPORT_SYMBOL_GPL(mm_fake);
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
int __init init_mars(void)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
2011-02-23 20:48:06 +00:00
|
|
|
MARS_INF("init_mars()\n");
|
2011-05-13 11:19:28 +00:00
|
|
|
|
2011-03-02 09:30:56 +00:00
|
|
|
set_fake();
|
2011-05-13 11:19:28 +00:00
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
#ifdef MARS_TRACING
|
|
|
|
{
|
|
|
|
int flags = O_CREAT | O_TRUNC | O_RDWR | O_LARGEFILE;
|
|
|
|
int prot = 0600;
|
|
|
|
mm_segment_t oldfs;
|
|
|
|
oldfs = get_fs();
|
|
|
|
set_fs(get_ds());
|
|
|
|
mars_log_file = filp_open("/mars/trace.csv", flags, prot);
|
|
|
|
set_fs(oldfs);
|
|
|
|
if (IS_ERR(mars_log_file)) {
|
|
|
|
MARS_ERR("cannot create trace logfile, status = %ld\n", PTR_ERR(mars_log_file));
|
|
|
|
mars_log_file = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
void __exit exit_mars(void)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
2011-02-23 20:48:06 +00:00
|
|
|
MARS_INF("exit_mars()\n");
|
2011-03-02 09:30:56 +00:00
|
|
|
put_fake();
|
2011-03-27 15:18:38 +00:00
|
|
|
#ifdef MARS_TRACING
|
|
|
|
if (mars_log_file) {
|
|
|
|
filp_close(mars_log_file, NULL);
|
|
|
|
mars_log_file = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2011-07-22 10:43:40 +00:00
|
|
|
if (id) {
|
2011-08-12 11:09:48 +00:00
|
|
|
brick_string_free(id);
|
2011-07-22 10:43:40 +00:00
|
|
|
id = NULL;
|
|
|
|
}
|
2010-06-14 14:27:40 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
#ifndef CONFIG_MARS_HAVE_BIGMODULE
|
2010-06-14 14:27:40 +00:00
|
|
|
MODULE_DESCRIPTION("MARS block storage");
|
|
|
|
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(init_mars);
|
|
|
|
module_exit(exit_mars);
|
2011-08-25 10:16:32 +00:00
|
|
|
#endif
|