From 681ffcb35eef747eb9115c3b49b6e76c0309849b Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Fri, 21 Oct 2011 14:50:43 +0200 Subject: [PATCH] introduced allow-replay (independent from pause-sync) --- sy_old/mars_light.c | 25 ++++++++++++++++++++++-- userspace/marsadm | 47 +++++++++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/sy_old/mars_light.c b/sy_old/mars_light.c index 67db6fa3..fac3a403 100644 --- a/sy_old/mars_light.c +++ b/sy_old/mars_light.c @@ -1887,6 +1887,26 @@ int __update_all_links(struct mars_global *global, struct mars_dent *parent, str return status; } +static +bool _check_allow_replay(struct mars_global *global, struct mars_dent *parent) +{ + int res = false; + char *path = path_make("%s/todo-%s/allow-replay", parent->d_path, my_id()); + struct mars_dent *allow_dent; + + if (!path) + goto done; + allow_dent = mars_find_dent(global, path); + if (!allow_dent || !allow_dent->new_link) + goto done; + sscanf(allow_dent->new_link, "%d", &res); + MARS_DBG("'%s' -> %d\n", path, res); + +done: + brick_string_free(path); + return res; +} + static int make_log_finalize(struct mars_global *global, struct mars_dent *dent) { @@ -1910,7 +1930,7 @@ int make_log_finalize(struct mars_global *global, struct mars_dent *dent) if (trans_brick->power.button && trans_brick->power.led_on && !trans_brick->power.led_off) { bool do_stop = true; if (trans_brick->do_replay) { - do_stop = trans_brick->replay_code != 0; + do_stop = trans_brick->replay_code != 0 || !_check_allow_replay(global, parent); } else { do_stop = !rot->is_primary || @@ -1947,7 +1967,8 @@ int make_log_finalize(struct mars_global *global, struct mars_dent *dent) goto done; } - do_start = (!rot->do_replay || rot->start_pos != rot->end_pos); + do_start = (!rot->do_replay || + (rot->start_pos != rot->end_pos && _check_allow_replay(global, parent))); MARS_DBG("do_start = %d\n", (int)do_start); if (do_start) { diff --git a/userspace/marsadm b/userspace/marsadm index fe6f20f6..b70cb634 100644 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -338,6 +338,7 @@ sub create_res { symlink("1", "$todo/attach"); symlink("0", "$todo/connect"); symlink("1", "$todo/sync"); + symlink("1", "$todo/allow-replay"); system("rm -f $tmp/syncstatus-$host"); if($create) { @@ -384,9 +385,9 @@ sub attach_res { sub connect_res { my ($cmd, $res) = @_; my $disconnect = ($cmd eq "disconnect"); - my @paths = glob("$mars/resource-$res/todo-*/connect"); + my @paths = glob("$mars/resource-$res/todo-*/"); for my $path (@paths) { - _switch($cmd, $res, $path, !$disconnect); + _switch($cmd, $res, "$path/connect", !$disconnect); } } @@ -397,33 +398,51 @@ sub connect_local_res { _switch($cmd, $res, $path, !$disconnect); } -sub pause_res { +sub pause_sync_res { my ($cmd, $res) = @_; my $pause = ($cmd eq "pause-sync"); - my @paths = glob("$mars/resource-$res/todo-*/sync"); + my @paths = glob("$mars/resource-$res/todo-*/"); for my $path (@paths) { - _switch($cmd, $res, $path, !$pause); + _switch($cmd, $res, "$path/sync", !$pause); } } -sub pause_local_res { +sub pause_sync_local_res { my ($cmd, $res) = @_; my $pause = ($cmd eq "pause-sync-local"); my $path = "$mars/resource-$res/todo-$host/sync"; _switch($cmd, $res, $path, !$pause); } +sub pause_replay_res { + my ($cmd, $res) = @_; + my $pause = ($cmd eq "pause-replay"); + my @paths = glob("$mars/resource-$res/todo-*/"); + for my $path (@paths) { + _switch($cmd, $res, "$path/allow-replay", !$pause); + } +} + +sub pause_replay_local_res { + my ($cmd, $res) = @_; + my $pause = ($cmd eq "pause-sync-local"); + my $path = "$mars/resource-$res/todo-$host/allow-replay"; + _switch($cmd, $res, $path, !$pause); +} + sub up_res { my ($cmd, $res) = @_; my $down = ($cmd eq "down"); if($down) { - pause_res("pause-sync", $res); + pause_replay_res("pause-replay", $res); + pause_sync_res("pause-sync", $res); connect_res("disconnect", $res); attach_res("detach", $res); } else { attach_res("attach", $res); connect_res("connect", $res); - pause_res("resume-sync", $res); + pause_sync_res("resume-sync", $res); + pause_replay_res("resume-replay", $res); } } @@ -535,10 +554,14 @@ my %cmd_table = "status" => \&nyi_cmd, "dump" => \&senseless_cmd, "verify" => \&nyi_cmd, - "pause-sync" => \&pause_res, - "resume-sync" => \&pause_res, - "pause-sync-local" => \&pause_local_res, - "resume-sync-local" => \&pause_local_res, + "pause-sync" => \&pause_sync_res, + "resume-sync" => \&pause_sync_res, + "pause-sync-local" => \&pause_sync_local_res, + "resume-sync-local" => \&pause_sync_local_res, + "pause-replay" => \&pause_replay_res, + "resume-replay" => \&pause_replay_res, + "pause-replay-local" => \&pause_replay_local_res, + "resume-replay-local" => \&pause_replay_local_res, "new-current-uuid" => \&senseless_cmd, "dstate" => \&nyi_cmd, "hidden-commands" => \&ignore_cmd,