infra: systematics of make_brick_all() switching, remove superfluos parameter

This commit is contained in:
Thomas Schoebel-Theuer 2013-05-10 08:15:00 +02:00 committed by Thomas Schoebel-Theuer
parent e9035548a4
commit cdd7b85417
4 changed files with 24 additions and 44 deletions

View File

@ -394,8 +394,7 @@ int handler_thread(void *data)
path,
(const struct generic_brick_type*)_bio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
1, // start always
2, // start always
path,
(const char *[]){},
0);

View File

@ -1174,8 +1174,7 @@ int __make_copy(
NULL,
(const struct generic_brick_type*)&bio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
switch_copy ? 1 : -1,
switch_copy ? 2 : -1,
cc.fullpath[i],
(const char *[]){},
0);
@ -1198,8 +1197,7 @@ int __make_copy(
cc.fullpath[1],
(const struct generic_brick_type*)&copy_brick_type,
(const struct generic_brick_type*[]){NULL,NULL,NULL,NULL},
NULL,
(!switch_copy || IS_EXHAUSTED()) ? -1 : 0,
(!switch_copy || IS_EXHAUSTED()) ? -1 : 2,
"%s",
(const char *[]){"%s", "%s", "%s", "%s"},
4,
@ -2225,8 +2223,7 @@ int make_log_init(void *buf, struct mars_dent *dent)
aio_path,
(const struct generic_brick_type*)&aio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
rot->trans_brick || switch_on ? 1 : -1, // disallow detach when trans_logger is present
rot->trans_brick || switch_on ? 2 : -1, // disallow detach when trans_logger is present
"%s",
(const char *[]){},
0,
@ -2271,8 +2268,7 @@ int make_log_init(void *buf, struct mars_dent *dent)
aio_path,
(const struct generic_brick_type*)&trans_logger_brick_type,
(const struct generic_brick_type*[]){NULL},
NULL,
rot->trans_brick && rot->trans_brick->power.led_on ? 1 : switch_on ? -100 : -1, // keep old state, create always if attach
1, // create when necessary, but leave in current state otherwise
"%s/logger",
(const char *[]){"%s/data-%s"},
1,
@ -2657,8 +2653,7 @@ void _rotate_trans(struct mars_rotate *rot)
rot->next_relevant_log->d_path,
(const struct generic_brick_type*)&aio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
0, // let switch decide
2, // create + activate
rot->next_relevant_log->d_path,
(const char *[]){},
0);
@ -2770,8 +2765,7 @@ int _start_trans(struct mars_rotate *rot)
rot->relevant_log->d_path,
(const struct generic_brick_type*)&aio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
1, // start always
2, // start always
rot->relevant_log->d_path,
(const char *[]){},
0);
@ -3079,8 +3073,7 @@ int make_bio(void *buf, struct mars_dent *dent)
dent->d_path,
(const struct generic_brick_type*)&bio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
switch_on ? 1 : -1,
switch_on ? 2 : -1,
dent->d_path,
(const char *[]){},
0);
@ -3197,8 +3190,7 @@ int make_dev(void *buf, struct mars_dent *dent)
dent->d_argv[0],
(const struct generic_brick_type*)&if_brick_type,
(const struct generic_brick_type*[]){(const struct generic_brick_type*)&trans_logger_brick_type},
NULL,
switch_on ? 1 : -1,
switch_on ? 2 : -1,
"%s/device-%s",
(const char *[]){"%s/logger"},
1,
@ -3283,8 +3275,7 @@ static int _make_direct(void *buf, struct mars_dent *dent)
src_path,
(const struct generic_brick_type*)&bio_brick_type,
(const struct generic_brick_type*[]){},
NULL,
switch_on ? 1 : -1,
switch_on ? 2 : -1,
"%s",
(const char *[]){},
0,
@ -3303,8 +3294,7 @@ static int _make_direct(void *buf, struct mars_dent *dent)
dent->d_argv[1],
(const struct generic_brick_type*)&if_brick_type,
(const struct generic_brick_type*[]){NULL},
NULL,
switch_on ? 1 : -1,
switch_on ? 2 : -1,
"%s/directdevice-%s",
(const char *[]){ "%s" },
1,

View File

@ -126,8 +126,7 @@ extern struct mars_brick *make_brick_all(
const char *new_name,
const struct generic_brick_type *new_brick_type,
const struct generic_brick_type *prev_brick_type[],
const char *switch_fmt,
int switch_override, // -1 = off, +1 = on, 0 = let switch decide
int switch_override, // -1 = off, 0 = leave in current state, +1 = create when necessary, +2 = create + switch on
const char *new_fmt,
const char *prev_fmt[],
int prev_count,

View File

@ -1447,8 +1447,7 @@ struct mars_brick *make_brick_all(
const char *new_name,
const struct generic_brick_type *new_brick_type,
const struct generic_brick_type *prev_brick_type[],
const char *switch_fmt,
int switch_override, // -1 = off, +1 = on, 0 = let switch decide
int switch_override, // -1 = off, 0 = leave in current state, +1 = create when necessary, +2 = create + switch on
const char *new_fmt,
const char *prev_fmt[],
int prev_count,
@ -1456,24 +1455,17 @@ struct mars_brick *make_brick_all(
)
{
va_list args;
char *switch_path = NULL;
const char *new_path;
char *_new_path = NULL;
struct mars_brick *brick = NULL;
char *paths[prev_count];
struct mars_brick *prev[prev_count];
int switch_state = true;
bool switch_state;
int i;
int status;
// treat variable arguments
va_start(args, prev_count);
if (switch_fmt) {
switch_state = false;
if (switch_fmt[0] && global && global->global_power.button) {
switch_path = vpath_make(switch_fmt, &args);
}
}
if (new_fmt) {
new_path = _new_path = vpath_make(new_fmt, &args);
} else {
@ -1488,14 +1480,15 @@ struct mars_brick *make_brick_all(
MARS_ERR("could not create new path\n");
goto err;
}
if (switch_path) {
struct mars_dent *test = mars_find_dent(global, switch_path);
if (test && test->new_link) {
sscanf(test->new_link, "%d", &switch_state);
}
// get old switch state
brick = mars_find_brick(global, NULL, new_path);
switch_state = false;
if (brick) {
switch_state = brick->power.button;
}
// override?
if (switch_override > 0)
if (switch_override > 1)
switch_state = true;
else if (switch_override < 0)
switch_state = false;
@ -1505,7 +1498,6 @@ struct mars_brick *make_brick_all(
}
// brick already existing?
brick = mars_find_brick(global, NULL, new_path);
if (brick) {
// just switch the power state
MARS_DBG("found existing brick '%s'\n", new_path);
@ -1517,7 +1509,9 @@ struct mars_brick *make_brick_all(
}
goto do_switch;
}
if (!switch_state && switch_override > -99) { // don't start => also don't create
// brick not existing => check whether to create it
if (switch_override < 1) { // don't create
MARS_DBG("no need for brick '%s'\n", new_path);
goto done;
}
@ -1629,8 +1623,6 @@ done:
}
if (_new_path)
brick_string_free(_new_path);
if (switch_path)
brick_string_free(switch_path);
return brick;
}