From a90b7c5d640bc7bf1bd648c69127fd1953e27421 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Tue, 9 Jun 2015 10:02:11 +0530 Subject: features/bitrot: handle scrub states via state machine Backport of http://review.gluster.org/11149 A bunch of command line options for scrubber tempted the use of state machine to track current state of scrubber under various circumstances where the options could be in effect. Change-Id: Id614bb2e6af30a90d2391ea31ae0a3edeb4e0d69 BUG: 1226666 Signed-off-by: Venky Shankar Reviewed-on: http://review.gluster.org/11541 Reviewed-by: Raghavendra Bhat Tested-by: Gluster Build System --- xlators/features/bit-rot/src/bitd/bit-rot-ssm.c | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 xlators/features/bit-rot/src/bitd/bit-rot-ssm.c (limited to 'xlators/features/bit-rot/src/bitd/bit-rot-ssm.c') diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c b/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c new file mode 100644 index 00000000000..c95e5551c0d --- /dev/null +++ b/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c @@ -0,0 +1,91 @@ +/* + Copyright (c) 2015 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#include "bit-rot-ssm.h" +#include "bit-rot-scrub.h" + +int br_scrub_ssm_noop (xlator_t *this, br_child_t *child) +{ + return 0; +} + +int +br_scrub_ssm_state_pause (xlator_t *this, br_child_t *child) +{ + gf_log (this->name, GF_LOG_INFO, + "Scrubber paused [Brick: %s]", child->brick_path); + _br_child_set_scrub_state (child, BR_SCRUB_STATE_PAUSED); + return 0; +} + +int +br_scrub_ssm_state_ipause (xlator_t *this, br_child_t *child) +{ + gf_log (this->name, GF_LOG_INFO, + "Scrubber paused [Brick: %s]", child->brick_path); + _br_child_set_scrub_state (child, BR_SCRUB_STATE_IPAUSED); + return 0; +} + +int +br_scrub_ssm_state_active (xlator_t *this, br_child_t *child) +{ + struct br_scanfs *fsscan = &child->fsscan; + + if (fsscan->over) { + (void) br_fsscan_activate (this, child); + } else { + gf_log (this->name, GF_LOG_INFO, + "Scrubbing resumed [Brick %s]", child->brick_path); + _br_child_set_scrub_state (child, BR_SCRUB_STATE_ACTIVE); + } + + return 0; +} + +int +br_scrub_ssm_state_stall (xlator_t *this, br_child_t *child) +{ + gf_log (this->name, GF_LOG_INFO, "Brick [%s] is under active " + "scrubbing. Pausing scrub..", child->brick_path); + _br_child_set_scrub_state (child, BR_SCRUB_STATE_STALLED); + return 0; +} + +static br_scrub_ssm_call * +br_scrub_ssm[BR_SCRUB_MAXSTATES][BR_SCRUB_MAXEVENTS] = { + {br_fsscan_schedule, br_scrub_ssm_state_ipause}, /* INACTIVE */ + {br_fsscan_reschedule, br_fsscan_deactivate}, /* PENDING */ + {br_scrub_ssm_noop, br_scrub_ssm_state_stall}, /* ACTIVE */ + {br_fsscan_activate, br_scrub_ssm_noop}, /* PAUSED */ + {br_fsscan_schedule, br_scrub_ssm_noop}, /* IPAUSED */ + {br_scrub_ssm_state_active, br_scrub_ssm_noop}, /* STALLED */ +}; + +int32_t +br_scrub_state_machine (xlator_t *this, br_child_t *child) +{ + br_private_t *priv = NULL; + br_scrub_ssm_call *call = NULL; + struct br_scanfs *fsscan = NULL; + struct br_scrubber *fsscrub = NULL; + br_scrub_state_t currstate = 0; + br_scrub_event_t event = 0; + + priv = this->private; + fsscan = &child->fsscan; + fsscrub = &priv->fsscrub; + + currstate = fsscan->state; + event = _br_child_get_scrub_event (fsscrub); + + call = br_scrub_ssm[currstate][event]; + return call (this, child); +} -- cgit