From 610b513ac9f0b6e0a3b9a4cae177783762c102b9 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Mon, 11 Sep 2017 18:19:47 +0200 Subject: [PATCH] main: factor out rot activation --- kernel/sy_old/mars_main.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/kernel/sy_old/mars_main.c b/kernel/sy_old/mars_main.c index e41c26d2..a3a8f2e3 100644 --- a/kernel/sy_old/mars_main.c +++ b/kernel/sy_old/mars_main.c @@ -632,6 +632,7 @@ struct mars_rotate { bool has_double_logfile; bool has_hole_logfile; bool allow_update; + bool rot_activated; bool forbid_replay; bool replay_mode; bool todo_primary; @@ -4181,13 +4182,25 @@ done: return status; } +static +void activate_rot(struct mars_rotate *rot) +{ + const char *tmp; + + if (rot->rot_activated) + return; + rot->rot_activated = true; + tmp = path_make("%s|%s/", tmp_resource_list, rot->parent_path); + brick_string_free(tmp_resource_list); + tmp_resource_list = tmp; +} + static int make_bio(void *buf, struct mars_dent *dent) { struct mars_global *global = buf; struct mars_rotate *rot; struct mars_brick *brick; - const char *tmp; bool switch_on; int status = 0; @@ -4210,9 +4223,7 @@ int make_bio(void *buf, struct mars_dent *dent) if (strcmp(dent->d_rest, my_id())) goto done; - tmp = path_make("%s|%s/", tmp_resource_list, rot->parent_path); - brick_string_free(tmp_resource_list); - tmp_resource_list = tmp; + activate_rot(rot); switch_on = _check_allow(global, dent->d_parent, "attach"); if (switch_on && rot->res_shutdown) { @@ -5818,6 +5829,7 @@ static int _main_thread(void *data) MARS_INF("-------- starting as host '%s' ----------\n", id); while (_global.global_power.button || !list_empty(&_global.brick_anchor)) { + struct list_head *tmp; int status; MARS_DBG("-------- NEW ROUND %d ---------\n", atomic_read(&server_handler_count)); @@ -5853,6 +5865,14 @@ static int _main_thread(void *data) _global.deleted_border = _global.deleted_min; MARS_DBG("-------- worker deleted_min = %d status = %d\n", _global.deleted_min, status); + down_read(&rot_sem); + for (tmp = rot_anchor.next; tmp != &rot_anchor; tmp = tmp->next) { + struct mars_rotate *rot = container_of(tmp, struct mars_rotate, rot_head); + + rot->rot_activated = false; + } + up_read(&rot_sem); + if (!_global.global_power.button) { status = mars_kill_brick_when_possible(&_global, &_global.brick_anchor, false, (void*)©_brick_type, true); MARS_DBG("kill copy bricks (when possible) = %d\n", status);