mirror of https://github.com/schoebel/mars
import mars-68.tgz
This commit is contained in:
parent
7dec70085d
commit
bbff01d71f
11
mars.h
11
mars.h
|
@ -332,17 +332,16 @@ extern int mars_kill_brick(struct mars_brick *brick);
|
|||
|
||||
// mid-level brick instantiation (identity is based on path strings)
|
||||
|
||||
extern char *vpath_make(struct mars_dent *parent, const char *fmt, va_list *args);
|
||||
extern char *path_make(struct mars_dent *parent, const char *fmt, ...);
|
||||
extern char *vpath_make(const char *fmt, va_list *args);
|
||||
extern char *path_make(const char *fmt, ...);
|
||||
|
||||
extern struct mars_brick *path_find_brick(struct mars_global *global, const void *brick_type, struct mars_dent *parent, const char *fmt, ...);
|
||||
extern struct mars_brick *path_find_brick(struct mars_global *global, const void *brick_type, const char *fmt, ...);
|
||||
|
||||
/* Create a new brick and connect its inputs to a set of predecessors.
|
||||
* When @timeout > 0, switch on the brick as well as its predecessors.
|
||||
*/
|
||||
extern struct mars_brick *make_brick_all(
|
||||
struct mars_global *global,
|
||||
struct mars_dent *parent,
|
||||
struct mars_dent *belongs,
|
||||
int timeout,
|
||||
const char *new_name,
|
||||
|
@ -375,8 +374,8 @@ extern int mars_lchown(const char *path, uid_t uid);
|
|||
* from the main instantiation logic (separate modprobe for mars_server
|
||||
* is possible).
|
||||
*/
|
||||
extern struct generic_brick_type *_client_brick_type;
|
||||
extern struct generic_brick_type *_aio_brick_type;
|
||||
extern const struct generic_brick_type *_client_brick_type;
|
||||
extern const struct generic_brick_type *_aio_brick_type;
|
||||
|
||||
/* Kludge: our kernel threads will have no mm context, but need one
|
||||
* for stuff like ioctx_alloc() / aio_setup_ring() etc
|
||||
|
|
|
@ -43,19 +43,20 @@ static int _connect(struct client_output *output, const char *str)
|
|||
struct sockaddr_storage sockaddr = {};
|
||||
int status;
|
||||
|
||||
if (!output->host) {
|
||||
output->host = kstrdup(str, GFP_MARS);
|
||||
if (!output->path) {
|
||||
output->path = kstrdup(str, GFP_MARS);
|
||||
status = -ENOMEM;
|
||||
if (!output->host)
|
||||
if (!output->path)
|
||||
goto done;
|
||||
status = -EINVAL;
|
||||
output->path = strchr(output->host, '+');
|
||||
if (!output->path) {
|
||||
kfree(output->host);
|
||||
output->host = NULL;
|
||||
output->host = strchr(output->path, '@');
|
||||
if (!output->host) {
|
||||
kfree(output->path);
|
||||
output->path = NULL;
|
||||
MARS_ERR("parameter string '%s' contains no remote specifier with '@'-syntax\n", str);
|
||||
goto done;
|
||||
}
|
||||
*output->path++ = '\0';
|
||||
*output->host++ = '\0';
|
||||
}
|
||||
|
||||
status = mars_create_sockaddr(&sockaddr, output->host);
|
||||
|
@ -270,7 +271,7 @@ done:
|
|||
if (output->socket) {
|
||||
MARS_INF("shutting down socket\n");
|
||||
kernel_sock_shutdown(output->socket, SHUT_WR);
|
||||
//msleep(1000);
|
||||
msleep(1000);
|
||||
output->socket = NULL;
|
||||
}
|
||||
return status;
|
||||
|
@ -432,8 +433,10 @@ static int client_output_construct(struct client_output *output)
|
|||
|
||||
static int client_output_destruct(struct client_output *output)
|
||||
{
|
||||
if (output->host)
|
||||
kfree(output->host);
|
||||
if (output->path) {
|
||||
kfree(output->path);
|
||||
output->path = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#define _STRATEGY
|
||||
#include "mars.h"
|
||||
|
||||
#include "mars_client.h"
|
||||
|
||||
#include <linux/syscalls.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/kthread.h>
|
||||
|
@ -117,7 +119,7 @@ EXPORT_SYMBOL_GPL(mars_mkdir);
|
|||
|
||||
int mars_symlink(const char *oldpath, const char *newpath, const struct timespec *stamp, uid_t uid)
|
||||
{
|
||||
char *tmp = path_make(NULL, "%s.tmp", newpath);
|
||||
char *tmp = path_make("%s.tmp", newpath);
|
||||
mm_segment_t oldfs;
|
||||
int status = -ENOMEM;
|
||||
|
||||
|
@ -914,39 +916,37 @@ EXPORT_SYMBOL_GPL(mars_kill_brick);
|
|||
|
||||
// mid-level brick instantiation (identity is based on path strings)
|
||||
|
||||
char *vpath_make(struct mars_dent *parent, const char *fmt, va_list *args)
|
||||
char *vpath_make(const char *fmt, va_list *args)
|
||||
{
|
||||
int len = parent ? parent->d_pathlen : 0;
|
||||
int len = strlen(fmt);
|
||||
char *res = kmalloc(len + MARS_PATH_MAX, GFP_MARS);
|
||||
|
||||
if (likely(res)) {
|
||||
if (parent)
|
||||
memcpy(res, parent->d_path, len);
|
||||
vsnprintf(res + len, MARS_PATH_MAX, fmt, *args);
|
||||
vsnprintf(res, MARS_PATH_MAX, fmt, *args);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vpath_make);
|
||||
|
||||
char *path_make(struct mars_dent *parent, const char *fmt, ...)
|
||||
char *path_make(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *res;
|
||||
va_start(args, fmt);
|
||||
res = vpath_make(parent, fmt, &args);
|
||||
res = vpath_make(fmt, &args);
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(path_make);
|
||||
|
||||
struct mars_brick *path_find_brick(struct mars_global *global, const void *brick_type, struct mars_dent *parent, const char *fmt, ...)
|
||||
struct mars_brick *path_find_brick(struct mars_global *global, const void *brick_type, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *fullpath;
|
||||
struct mars_brick *res;
|
||||
|
||||
va_start(args, fmt);
|
||||
fullpath = vpath_make(parent, fmt, &args);
|
||||
fullpath = vpath_make(fmt, &args);
|
||||
va_end(args);
|
||||
|
||||
if (!fullpath) {
|
||||
|
@ -959,14 +959,13 @@ struct mars_brick *path_find_brick(struct mars_global *global, const void *brick
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(path_find_brick);
|
||||
|
||||
struct generic_brick_type *_client_brick_type = NULL;
|
||||
const struct generic_brick_type *_client_brick_type = NULL;
|
||||
EXPORT_SYMBOL_GPL(_client_brick_type);
|
||||
struct generic_brick_type *_aio_brick_type = NULL;
|
||||
const struct generic_brick_type *_aio_brick_type = NULL;
|
||||
EXPORT_SYMBOL_GPL(_aio_brick_type);
|
||||
|
||||
struct mars_brick *make_brick_all(
|
||||
struct mars_global *global,
|
||||
struct mars_dent *parent,
|
||||
struct mars_dent *belongs,
|
||||
int timeout,
|
||||
const char *new_name,
|
||||
|
@ -979,7 +978,8 @@ struct mars_brick *make_brick_all(
|
|||
)
|
||||
{
|
||||
va_list args;
|
||||
char *new_path;
|
||||
const char *new_path;
|
||||
const char *_new_path = NULL;
|
||||
struct mars_brick *brick = NULL;
|
||||
char *paths[prev_count];
|
||||
struct mars_brick *prev[prev_count];
|
||||
|
@ -987,9 +987,13 @@ struct mars_brick *make_brick_all(
|
|||
|
||||
// treat variable arguments
|
||||
va_start(args, prev_count);
|
||||
new_path = vpath_make(parent, new_fmt, &args);
|
||||
if (new_fmt) {
|
||||
new_path = _new_path = vpath_make(new_fmt, &args);
|
||||
} else {
|
||||
new_path = new_name;
|
||||
}
|
||||
for (i = 0; i < prev_count; i++) {
|
||||
paths[i] = vpath_make(parent, prev_fmt[i], &args);
|
||||
paths[i] = vpath_make(prev_fmt[i], &args);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
|
@ -999,11 +1003,13 @@ struct mars_brick *make_brick_all(
|
|||
}
|
||||
|
||||
// don't do anything if brick already exists
|
||||
brick = mars_find_brick(global, new_brick_type, new_path);
|
||||
brick = mars_find_brick(global, new_brick_type != _aio_brick_type ? new_brick_type : NULL, new_path);
|
||||
if (brick) {
|
||||
MARS_DBG("found brick '%s'\n", new_path);
|
||||
goto done;
|
||||
}
|
||||
if (!new_name)
|
||||
new_name = new_path;
|
||||
|
||||
MARS_DBG("----> new brick type = '%s' path = '%s' name = '%s'\n", new_brick_type->type_name, new_path, new_name);
|
||||
|
||||
|
@ -1028,15 +1034,16 @@ struct mars_brick *make_brick_all(
|
|||
// create it...
|
||||
brick = NULL;
|
||||
if (new_brick_type == _aio_brick_type && _client_brick_type != NULL) {
|
||||
char *remote = strchr(new_path, '@');
|
||||
char *remote = strchr(new_name, '@');
|
||||
if (remote) {
|
||||
new_path[remote-new_path] = '\0';
|
||||
remote++;
|
||||
brick = mars_make_brick(global, NULL, _client_brick_type, new_path, remote);
|
||||
MARS_DBG("substitute by remote brick '%s' on peer '%s'\n", new_name, remote);
|
||||
|
||||
brick = mars_make_brick(global, belongs, _client_brick_type, new_path, new_name);
|
||||
}
|
||||
}
|
||||
if (!brick)
|
||||
brick = mars_make_brick(global, NULL, new_brick_type, new_path, new_name);
|
||||
brick = mars_make_brick(global, belongs, new_brick_type, new_path, new_name);
|
||||
if (unlikely(!brick)) {
|
||||
MARS_DBG("creation failed '%s' '%s'\n", new_path, new_name);
|
||||
goto err;
|
||||
|
@ -1075,8 +1082,8 @@ done:
|
|||
kfree(paths[i]);
|
||||
}
|
||||
}
|
||||
if (new_path)
|
||||
kfree(new_path);
|
||||
if (_new_path)
|
||||
kfree(_new_path);
|
||||
|
||||
return brick;
|
||||
}
|
||||
|
|
204
mars_light.c
204
mars_light.c
|
@ -131,37 +131,46 @@ char *_backskip_replace(const char *path, char delim, bool insert, const char *f
|
|||
static
|
||||
int __make_copy(
|
||||
struct mars_global *global,
|
||||
struct mars_dent *parent,
|
||||
struct mars_dent *belongs,
|
||||
const char *path,
|
||||
const char *parent,
|
||||
const char *argv[],
|
||||
loff_t start_pos,
|
||||
struct copy_brick **__copy)
|
||||
{
|
||||
struct mars_brick *copy;
|
||||
struct copy_brick *_copy;
|
||||
const char *fullpath[2] = {};
|
||||
struct mars_output *output[2] = {};
|
||||
struct mars_info info[2] = {};
|
||||
int i;
|
||||
int status = -1;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
const char *target = argv[i];
|
||||
struct mars_brick *aio;
|
||||
|
||||
if (parent) {
|
||||
fullpath[i] = path_make("%s/%s", parent, argv[i]);
|
||||
if (!fullpath[i]) {
|
||||
MARS_ERR("cannot make path '%s/%s'\n", parent, argv[i]);
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
fullpath[i] = argv[i];
|
||||
}
|
||||
|
||||
aio =
|
||||
make_brick_all(global,
|
||||
parent,
|
||||
parent,
|
||||
NULL,
|
||||
10 * HZ,
|
||||
target,
|
||||
NULL,
|
||||
(const struct generic_brick_type*)&device_aio_brick_type,
|
||||
(const struct generic_brick_type*[]){},
|
||||
"/%s",
|
||||
fullpath[i],
|
||||
(const char *[]){},
|
||||
0,
|
||||
target);
|
||||
0);
|
||||
if (!aio) {
|
||||
MARS_DBG("cannot instantiate '%s'\n", target);
|
||||
MARS_DBG("cannot instantiate '%s'\n", fullpath[i]);
|
||||
goto done;
|
||||
}
|
||||
output[i] = aio->outputs[0];
|
||||
|
@ -169,17 +178,19 @@ int __make_copy(
|
|||
|
||||
copy =
|
||||
make_brick_all(global,
|
||||
parent,
|
||||
belongs,
|
||||
1,
|
||||
0,
|
||||
path,
|
||||
(const struct generic_brick_type*)©_brick_type,
|
||||
(const struct generic_brick_type*[]){NULL,NULL,NULL,NULL},
|
||||
"/copy%s",
|
||||
(const char *[]){"/%s", "/%s", "/%s", "/%s"},
|
||||
"%s",
|
||||
(const char *[]){"%s", "%s", "%s", "%s"},
|
||||
4,
|
||||
path,
|
||||
argv[0], argv[0], argv[1], argv[1]);
|
||||
fullpath[0],
|
||||
fullpath[0],
|
||||
fullpath[1],
|
||||
fullpath[1]);
|
||||
if (!copy) {
|
||||
MARS_DBG("fail '%s'\n", path);
|
||||
goto done;
|
||||
|
@ -203,12 +214,12 @@ int __make_copy(
|
|||
if (start_pos != -1) {
|
||||
_copy->copy_start = start_pos;
|
||||
if (unlikely(info[0].current_size != info[1].current_size)) {
|
||||
MARS_ERR("oops, devices have different size %lld != %lld at '%s'\n", info[0].current_size, info[1].current_size, parent->d_path);
|
||||
MARS_ERR("oops, devices have different size %lld != %lld at '%s'\n", info[0].current_size, info[1].current_size, path);
|
||||
status = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
if (unlikely(start_pos > info[0].current_size)) {
|
||||
MARS_ERR("bad start position %lld is larger than actual size %lld on '%s'\n", start_pos, info[0].current_size, parent->d_path);
|
||||
MARS_ERR("bad start position %lld is larger than actual size %lld on '%s'\n", start_pos, info[0].current_size, path);
|
||||
status = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
@ -225,6 +236,10 @@ int __make_copy(
|
|||
|
||||
done:
|
||||
MARS_DBG("status = %d\n", status);
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fullpath[i] && fullpath[i] != argv[i])
|
||||
kfree(fullpath[i]);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -244,19 +259,21 @@ struct mars_peerinfo {
|
|||
};
|
||||
|
||||
static
|
||||
int _update_file(struct mars_global *global, struct mars_dent *parent, const char *peer, const char *path)
|
||||
int _update_file(struct mars_global *global, const char *path, const char *peer)
|
||||
{
|
||||
char *tmp = path_make(NULL, "%s@%s", path, peer);
|
||||
const char *argv[2] = { tmp, path};
|
||||
const char *tmp = path_make("%s@%s", path, peer);
|
||||
const char *argv[2] = { tmp, path };
|
||||
int status = -ENOMEM;
|
||||
|
||||
if (unlikely(!tmp))
|
||||
goto done;
|
||||
|
||||
status = __make_copy(global, parent, parent, tmp, argv, -1, NULL);
|
||||
kfree(tmp);
|
||||
MARS_DBG("tmp = '%s' path = '%s'\n", tmp, path);
|
||||
status = __make_copy(global, NULL, path, NULL, argv, -1, NULL);
|
||||
|
||||
done:
|
||||
if (tmp)
|
||||
kfree(tmp);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -347,13 +364,15 @@ int run_bones(void *buf, struct mars_dent *dent)
|
|||
|
||||
if (!stat_ok || local_stat.size < src_size) {
|
||||
// check whether connect is allowed
|
||||
char *connect_path = _backskip_replace(dent->d_path, '/', false, "/connect-%d", my_id());
|
||||
char *connect_path = _backskip_replace(dent->d_path, '/', false, "/connect-%s", my_id());
|
||||
if (likely(connect_path)) {
|
||||
struct kstat connect_stat = {};
|
||||
status = mars_lstat(connect_path, &connect_stat);
|
||||
MARS_DBG("connect_path = '%s' stat status = %d uid = %d\n", connect_path, status, connect_stat.uid);
|
||||
kfree(connect_path);
|
||||
if (status >= 0 && !connect_stat.uid) {
|
||||
status = _update_file(peer->global, dent->d_parent, peer->peer, dent->d_name);
|
||||
// parent is not available here
|
||||
status = _update_file(peer->global, dent->d_path, peer->peer);
|
||||
MARS_DBG("update '%s' from peer '%s' status = %d\n", dent->d_path, peer->peer, status);
|
||||
if (status >= 0) {
|
||||
char *tmp = _backskip_replace(dent->d_path, '-', false, "-%s", my_id());
|
||||
|
@ -643,9 +662,11 @@ void _create_new_logfile(char *path)
|
|||
set_fs(get_ds());
|
||||
f = filp_open(path, flags, prot);
|
||||
set_fs(oldfs);
|
||||
if (f) {
|
||||
filp_close(f, NULL);
|
||||
if (IS_ERR(f)) {
|
||||
MARS_ERR("could not create logfile '%s' status = %d\n", path, (int)PTR_ERR(f));
|
||||
} else {
|
||||
MARS_DBG("created empty logfile '%s'\n", path);
|
||||
filp_close(f, NULL);
|
||||
mars_trigger();
|
||||
}
|
||||
}
|
||||
|
@ -658,10 +679,10 @@ int _update_link(struct mars_rotate *rot, struct mars_dent *parent, int sequence
|
|||
char *new;
|
||||
int status = -ENOMEM;
|
||||
|
||||
old = path_make(NULL, "log-%09d-%s,%lld", sequence, my_id(), pos);
|
||||
old = path_make("log-%09d-%s,%lld", sequence, my_id(), pos);
|
||||
if (!old)
|
||||
goto out_old;
|
||||
new = path_make(parent, "/replay-%s", my_id());
|
||||
new = path_make("%s/replay-%s", parent->d_path, my_id());
|
||||
if (!new)
|
||||
goto out_new;
|
||||
|
||||
|
@ -723,7 +744,7 @@ int make_log_init(void *buf, struct mars_dent *parent)
|
|||
/* Fetch the replay status symlink.
|
||||
* It must exist, and its value will control everything.
|
||||
*/
|
||||
replay_path = path_make(parent, "/replay-%s", my_id());
|
||||
replay_path = path_make("%s/replay-%s", parent->d_path, my_id());
|
||||
if (unlikely(!replay_path)) {
|
||||
MARS_ERR("cannot make path\n");
|
||||
status = -ENOMEM;
|
||||
|
@ -745,7 +766,7 @@ int make_log_init(void *buf, struct mars_dent *parent)
|
|||
|
||||
/* Fetch the referenced AIO dentry.
|
||||
*/
|
||||
aio_path = path_make(parent, "/%s", replay_link->d_argv[0]);
|
||||
aio_path = path_make("%s/%s", parent->d_path, replay_link->d_argv[0]);
|
||||
if (unlikely(!aio_path)) {
|
||||
MARS_ERR("cannot make path\n");
|
||||
status = -ENOMEM;
|
||||
|
@ -767,7 +788,6 @@ int make_log_init(void *buf, struct mars_dent *parent)
|
|||
*/
|
||||
aio_brick =
|
||||
make_brick_all(global,
|
||||
NULL,
|
||||
aio_dent,
|
||||
10 * HZ,
|
||||
aio_path,
|
||||
|
@ -802,15 +822,16 @@ int make_log_init(void *buf, struct mars_dent *parent)
|
|||
*/
|
||||
trans_brick =
|
||||
make_brick_all(global,
|
||||
parent,
|
||||
parent,
|
||||
0,
|
||||
aio_path,
|
||||
(const struct generic_brick_type*)&trans_logger_brick_type,
|
||||
(const struct generic_brick_type*[]){(const struct generic_brick_type*)&device_aio_brick_type},
|
||||
"/logger",
|
||||
(const char *[]){"/data-%s"},
|
||||
"%s/logger",
|
||||
(const char *[]){"%s/data-%s"},
|
||||
1,
|
||||
parent->d_path,
|
||||
parent->d_path,
|
||||
my_id());
|
||||
status = -ENOENT;
|
||||
if (!trans_brick) {
|
||||
|
@ -1032,7 +1053,6 @@ int _start_trans(struct mars_rotate *rot)
|
|||
*/
|
||||
rot->relevant_brick =
|
||||
make_brick_all(rot->global,
|
||||
NULL,
|
||||
rot->relevant_log,
|
||||
10 * HZ,
|
||||
rot->relevant_log->d_path,
|
||||
|
@ -1136,7 +1156,7 @@ int make_log_finalize(struct mars_global *global, struct mars_dent *parent)
|
|||
* normally userspace should control what happens in MARS.
|
||||
*/
|
||||
if (!rot->relevant_log && rot->is_primary && !rot->has_error && rot->max_sequence > 0 && !rot->create_once) { // try to create an empty logfile
|
||||
char *tmp = path_make(parent, "/log-%09d-%s", rot->max_sequence + 1, my_id());
|
||||
char *tmp = path_make("%s/log-%09d-%s", parent->d_path, rot->max_sequence + 1, my_id());
|
||||
if (likely(tmp)) {
|
||||
_create_new_logfile(tmp);
|
||||
kfree(tmp);
|
||||
|
@ -1210,7 +1230,6 @@ int make_aio(void *buf, struct mars_dent *dent)
|
|||
dent->d_kill_inactive = true;
|
||||
brick =
|
||||
make_brick_all(global,
|
||||
NULL,
|
||||
dent,
|
||||
10 * HZ,
|
||||
dent->d_path,
|
||||
|
@ -1269,16 +1288,17 @@ static int make_dev(void *buf, struct mars_dent *dent)
|
|||
|
||||
dev_brick =
|
||||
make_brick_all(global,
|
||||
dent->d_parent,
|
||||
dent,
|
||||
10 * HZ,
|
||||
dent->d_argv[0],
|
||||
(const struct generic_brick_type*)&if_device_brick_type,
|
||||
(const struct generic_brick_type*[]){(const struct generic_brick_type*)&trans_logger_brick_type},
|
||||
"/linuxdev-%s",
|
||||
(const char *[]){"/logger"},
|
||||
"%s/linuxdev-%s",
|
||||
(const char *[]){"%s/logger"},
|
||||
1,
|
||||
dent->d_argv[0]);
|
||||
dent->d_parent->d_path,
|
||||
dent->d_argv[0],
|
||||
dent->d_parent->d_path);
|
||||
if (!dev_brick) {
|
||||
MARS_DBG("fail\n");
|
||||
return -1;
|
||||
|
@ -1304,15 +1324,15 @@ static int _make_direct(void *buf, struct mars_dent *dent)
|
|||
}
|
||||
brick =
|
||||
make_brick_all(global,
|
||||
dent->d_parent,
|
||||
dent,
|
||||
10 * HZ,
|
||||
dent->d_argv[0],
|
||||
(const struct generic_brick_type*)&device_aio_brick_type,
|
||||
(const struct generic_brick_type*[]){},
|
||||
"/%s",
|
||||
"%s/%s",
|
||||
(const char *[]){},
|
||||
0,
|
||||
dent->d_parent->d_path,
|
||||
dent->d_argv[0]);
|
||||
status = -1;
|
||||
if (!brick) {
|
||||
|
@ -1322,16 +1342,18 @@ static int _make_direct(void *buf, struct mars_dent *dent)
|
|||
|
||||
brick =
|
||||
make_brick_all(global,
|
||||
dent->d_parent,
|
||||
dent,
|
||||
10 * HZ,
|
||||
dent->d_argv[1],
|
||||
(const struct generic_brick_type*)&if_device_brick_type,
|
||||
(const struct generic_brick_type*[]){NULL},
|
||||
"/linuxdev-%s",
|
||||
(const char *[]){dent->d_argv[0]},
|
||||
"%s/linuxdev-%s",
|
||||
(const char *[]){ "%s/%s" },
|
||||
1,
|
||||
dent->d_argv[1]),
|
||||
dent->d_parent->d_path,
|
||||
dent->d_argv[1],
|
||||
dent->d_parent->d_path,
|
||||
dent->d_argv[0]),
|
||||
status = -1;
|
||||
if (!brick) {
|
||||
MARS_DBG("fail\n");
|
||||
|
@ -1357,7 +1379,7 @@ static int _make_copy(void *buf, struct mars_dent *dent)
|
|||
goto done;
|
||||
}
|
||||
|
||||
status = __make_copy(global, dent->d_parent, dent, dent->d_path, (const char**)dent->d_argv, -1, NULL);
|
||||
status = __make_copy(global, dent, dent->d_path, dent->d_parent->d_path, (const char**)dent->d_argv, -1, NULL);
|
||||
|
||||
done:
|
||||
MARS_DBG("status = %d\n", status);
|
||||
|
@ -1392,7 +1414,7 @@ static int make_sync(void *buf, struct mars_dent *dent)
|
|||
|
||||
/* Determine peer
|
||||
*/
|
||||
tmp = path_make(dent->d_parent, "/connect-%s", my_id());
|
||||
tmp = path_make("%s/connect-%s", dent->d_parent->d_path, my_id());
|
||||
status = -ENOMEM;
|
||||
if (unlikely(!tmp))
|
||||
goto done;
|
||||
|
@ -1412,8 +1434,8 @@ static int make_sync(void *buf, struct mars_dent *dent)
|
|||
|
||||
/* Start copy
|
||||
*/
|
||||
src = path_make(NULL, "data-%s@%s", peer, peer);
|
||||
dst = path_make(NULL, "data-%s", my_id());
|
||||
src = path_make("data-%s@%s", peer, peer);
|
||||
dst = path_make("data-%s", my_id());
|
||||
status = -ENOMEM;
|
||||
if (unlikely(!src || !dst))
|
||||
goto done;
|
||||
|
@ -1422,7 +1444,7 @@ static int make_sync(void *buf, struct mars_dent *dent)
|
|||
|
||||
{
|
||||
const char *argv[2] = { src, dst };
|
||||
status = __make_copy(global, dent->d_parent, dent, dent->d_path, argv, start_pos, ©);
|
||||
status = __make_copy(global, dent, dent->d_path, dent->d_parent->d_path, argv, start_pos, ©);
|
||||
}
|
||||
|
||||
/* Update syncstatus symlink
|
||||
|
@ -1430,8 +1452,8 @@ static int make_sync(void *buf, struct mars_dent *dent)
|
|||
if (status >= 0 && copy && copy->power.button && copy->power.led_on) {
|
||||
kfree(src);
|
||||
kfree(dst);
|
||||
src = path_make(NULL, "%lld", copy->copy_last);
|
||||
dst = path_make(dent->d_parent, "/syncstatus-%s", my_id());
|
||||
src = path_make("%lld", copy->copy_last);
|
||||
dst = path_make("%s/syncstatus-%s", dent->d_parent->d_path, my_id());
|
||||
status = -ENOMEM;
|
||||
if (unlikely(!src || !dst))
|
||||
goto done;
|
||||
|
@ -1825,7 +1847,7 @@ void _show_status(struct mars_global *global)
|
|||
MARS_DBG("status symlink '%s' -> '%s' status = %d\n", dst, src, status);
|
||||
if (test->status_level > 1) {
|
||||
char perc[8];
|
||||
char *dst2 = path_make(NULL, "%s.percent", dst);
|
||||
char *dst2 = path_make("%s.percent", dst);
|
||||
if (likely(dst2)) {
|
||||
snprintf(perc, sizeof(perc), "%d", test->power.percent_done);
|
||||
status = mars_symlink(perc, dst2, NULL, 0);
|
||||
|
@ -1838,6 +1860,44 @@ void _show_status(struct mars_global *global)
|
|||
up(&global->mutex);
|
||||
}
|
||||
|
||||
#ifdef STAT_DEBUGGING
|
||||
static
|
||||
void _show_statist(struct mars_global *global)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
int dent_count = 0;
|
||||
int brick_count = 0;
|
||||
|
||||
down(&global->mutex);
|
||||
MARS_STAT("----------- lists:\n");
|
||||
for (tmp = global->dent_anchor.next; tmp != &global->dent_anchor; tmp = tmp->next) {
|
||||
struct mars_dent *dent;
|
||||
dent = container_of(tmp, struct mars_dent, dent_link);
|
||||
MARS_STAT("dent '%s'\n", dent->d_path);
|
||||
dent_count++;
|
||||
}
|
||||
for (tmp = global->brick_anchor.next; tmp != &global->brick_anchor; tmp = tmp->next) {
|
||||
struct mars_brick *test;
|
||||
int i;
|
||||
test = container_of(tmp, struct mars_brick, global_brick_link);
|
||||
MARS_STAT("brick type = %s path = '%s' name = '%s' level = %d button = %d off = %d on = %d\n", test->type->type_name, test->brick_path, test->brick_name, test->status_level, test->power.button, test->power.led_off, test->power.led_on);
|
||||
brick_count++;
|
||||
for (i = 0; i < test->nr_inputs; i++) {
|
||||
struct mars_input *input = test->inputs[i];
|
||||
struct mars_output *output = input ? input->connect : NULL;
|
||||
if (output) {
|
||||
MARS_STAT(" input %d connected with %s path = '%s' name = '%s'\n", i, output->brick->type->type_name, output->brick->brick_path, output->brick->brick_name);
|
||||
} else {
|
||||
MARS_STAT(" input %d not connected\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
up(&global->mutex);
|
||||
|
||||
MARS_INF("----------- STATISTICS: %d dents, %d bricks\n", dent_count, brick_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int light_thread(void *data)
|
||||
{
|
||||
char *id = my_id();
|
||||
|
@ -1871,36 +1931,14 @@ static int light_thread(void *data)
|
|||
MARS_DBG("worker status = %d\n", status);
|
||||
|
||||
_show_status(&global);
|
||||
#ifdef STAT_DEBUGGING
|
||||
_show_statist(&global);
|
||||
#endif
|
||||
|
||||
msleep(1000);
|
||||
|
||||
wait_event_interruptible_timeout(global.main_event, global.main_trigger, 30 * HZ);
|
||||
global.main_trigger = false;
|
||||
|
||||
#ifdef STAT_DEBUGGING
|
||||
{
|
||||
struct list_head *tmp;
|
||||
int dent_count = 0;
|
||||
int brick_count = 0;
|
||||
|
||||
down(&global.mutex);
|
||||
MARS_STAT("----------- lists:\n");
|
||||
for (tmp = global.dent_anchor.next; tmp != &global.dent_anchor; tmp = tmp->next) {
|
||||
struct mars_dent *dent;
|
||||
dent = container_of(tmp, struct mars_dent, dent_link);
|
||||
MARS_STAT("dent '%s'\n", dent->d_path);
|
||||
dent_count++;
|
||||
}
|
||||
for (tmp = global.brick_anchor.next; tmp != &global.brick_anchor; tmp = tmp->next) {
|
||||
struct mars_brick *test;
|
||||
test = container_of(tmp, struct mars_brick, global_brick_link);
|
||||
MARS_STAT("brick type = %s path = '%s' name = '%s' level = %d button = %d on = %d off = %d\n", test->type->type_name, test->brick_path, test->brick_name, test->status_level, test->power.button, test->power.led_on, test->power.led_off);
|
||||
brick_count++;
|
||||
}
|
||||
up(&global.mutex);
|
||||
|
||||
MARS_INF("----------- STATISTICS: %d dents, %d bricks\n", dent_count, brick_count);
|
||||
}
|
||||
msleep(500);
|
||||
#endif
|
||||
}
|
||||
|
||||
done:
|
||||
|
@ -1944,6 +1982,10 @@ static int __init init_light(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// force module loading
|
||||
const void *dummy1 = &client_brick_type;
|
||||
const void *dummy2 = &server_brick_type;
|
||||
|
||||
MODULE_DESCRIPTION("MARS Light");
|
||||
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
|
11
mars_net.c
11
mars_net.c
|
@ -47,7 +47,7 @@ char *mars_translate_hostname(struct mars_global *global, const char *name)
|
|||
if (unlikely(!global)) {
|
||||
goto done;
|
||||
}
|
||||
tmp = path_make(NULL, "/mars/ips/ip-%s", name);
|
||||
tmp = path_make("/mars/ips/ip-%s", name);
|
||||
if (unlikely(!tmp)) {
|
||||
goto done;
|
||||
}
|
||||
|
@ -192,18 +192,13 @@ int mars_send(struct socket **sock, void *buf, int len)
|
|||
|
||||
//MARS_IO("buf = %p, len = %d\n", buf, len);
|
||||
while (sent < len) {
|
||||
mm_segment_t oldfs;
|
||||
|
||||
if (unlikely(!*sock)) {
|
||||
MARS_ERR("socket has disappeared\n");
|
||||
status = -EIDRM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
status = kernel_sendmsg(*sock, &msg, &iov, 1, len);
|
||||
set_fs(oldfs);
|
||||
|
||||
if (status == -EAGAIN) {
|
||||
msleep(50);
|
||||
|
@ -248,7 +243,6 @@ int mars_recv(struct socket **sock, void *buf, int minlen, int maxlen)
|
|||
}
|
||||
|
||||
while (done < minlen) {
|
||||
mm_segment_t oldfs;
|
||||
struct kvec iov = {
|
||||
.iov_base = buf + done,
|
||||
.iov_len = maxlen - done,
|
||||
|
@ -267,10 +261,7 @@ int mars_recv(struct socket **sock, void *buf, int minlen, int maxlen)
|
|||
|
||||
MARS_IO("done %d, fetching %d bytes\n", done, maxlen-done);
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
status = kernel_recvmsg(*sock, &msg, &iov, 1, maxlen-done, msg.msg_flags);
|
||||
set_fs(oldfs);
|
||||
|
||||
if (status == -EAGAIN) {
|
||||
#if 0
|
||||
|
|
|
@ -29,6 +29,7 @@ static struct task_struct *server_thread = NULL;
|
|||
|
||||
///////////////////////// own helper functions ////////////////////////
|
||||
|
||||
|
||||
static int server_checker(const char *path, const char *name, int namlen, unsigned int d_type, int *prefix, int *serial)
|
||||
{
|
||||
return 0;
|
||||
|
@ -55,6 +56,7 @@ static void server_endio(struct generic_callback *cb)
|
|||
CHECK_PTR(brick, err);
|
||||
sock = mref_a->sock;
|
||||
CHECK_PTR(sock, err);
|
||||
CHECK_PTR(*sock, err);
|
||||
|
||||
down(&brick->socket_sem);
|
||||
status = mars_send_cb(sock, mref);
|
||||
|
@ -90,7 +92,7 @@ static int handler_thread(void *data)
|
|||
|
||||
status = mars_recv_struct(sock, &cmd, mars_cmd_meta);
|
||||
if (status < 0) {
|
||||
MARS_ERR("command status = %d\n", status);
|
||||
MARS_ERR("bad command status = %d\n", status);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -161,7 +163,6 @@ static int handler_thread(void *data)
|
|||
//prev = mars_find_brick(mars_global, NULL, cmd.cmd_str1);
|
||||
prev =
|
||||
make_brick_all(mars_global,
|
||||
NULL,
|
||||
NULL,
|
||||
10 * HZ,
|
||||
path,
|
||||
|
@ -231,16 +232,19 @@ static int handler_thread(void *data)
|
|||
break;
|
||||
}
|
||||
|
||||
//kernel_sock_shutdown(*sock, SHUT_WR);
|
||||
sock_release(*sock);
|
||||
kernel_sock_shutdown(*sock, SHUT_WR);
|
||||
//sock_release(*sock);
|
||||
//cleanup_mm();
|
||||
|
||||
done:
|
||||
MARS_DBG("handler_thread terminating, status = %d\n", status);
|
||||
do {
|
||||
int status = mars_kill_brick((void*)brick);
|
||||
if (status >= 0)
|
||||
if (status >= 0) {
|
||||
//if(*sock)
|
||||
//sock_release(*sock);
|
||||
break;
|
||||
}
|
||||
if (status >= 0 || max_round-- < 0) {
|
||||
MARS_INF("not dead, giving up....\n");
|
||||
break;
|
||||
|
@ -444,8 +448,9 @@ static int _server_thread(void *data)
|
|||
err:
|
||||
if (new_socket) {
|
||||
kernel_sock_shutdown(new_socket, SHUT_WR);
|
||||
sock_release(new_socket);
|
||||
//sock_release(new_socket);
|
||||
}
|
||||
msleep(3000);
|
||||
}
|
||||
|
||||
MARS_INF("-------- cleaning up ----------\n");
|
||||
|
@ -500,7 +505,7 @@ static void __exit exit_server(void)
|
|||
}
|
||||
kthread_stop(server_thread);
|
||||
if (server_socket && !server_thread) {
|
||||
sock_release(server_socket);
|
||||
//sock_release(server_socket);
|
||||
server_socket = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,10 @@ sub get_size {
|
|||
|
||||
# helpers
|
||||
|
||||
sub _trigger {
|
||||
system("echo 1 > /proc/sys/mars 2>/dev/null");
|
||||
}
|
||||
|
||||
sub _switch {
|
||||
my ($path, $on) = @_;
|
||||
|
||||
|
@ -369,3 +373,4 @@ if($res eq "all") {
|
|||
do_res($cmd, $res, @ARGV);
|
||||
}
|
||||
|
||||
_trigger();
|
||||
|
|
Loading…
Reference in New Issue