[sheepdog] [PATCH 1/3] sheep: don't start recovery if cluster was shutdowned
Liu Yuan
namei.unix at gmail.com
Fri Aug 30 13:43:38 CEST 2013
Add a new field in the config file to indicate shutdown status. The layout of
config file isn't modified, just find a free slot to hold shutdown status.
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
sheep/config.c | 14 +++++++++++++-
sheep/group.c | 4 +++-
sheep/ops.c | 5 +++++
sheep/sheep_priv.h | 2 ++
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/sheep/config.c b/sheep/config.c
index 67198c0..1770ed1 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -19,7 +19,8 @@ static struct sheepdog_config {
uint16_t flags;
uint8_t copies;
uint8_t store[STORE_LEN];
- uint8_t __pad[3];
+ uint8_t shutdown;
+ uint8_t __pad[2];
uint16_t version;
uint64_t space;
} config;
@@ -171,6 +172,17 @@ bool is_cluster_formatted(void)
return cinfo.ctime != 0;
}
+int set_cluster_shutdown(bool down)
+{
+ config.shutdown = down;
+ return write_config();
+}
+
+bool was_cluster_shutdowned(void)
+{
+ return config.shutdown;
+}
+
static inline __attribute__((used)) void __sd_config_format_build_bug_ons(void)
{
/* never called, only for checking BUILD_BUG_ON()s */
diff --git a/sheep/group.c b/sheep/group.c
index 44e4058..aff0ca2 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -665,10 +665,12 @@ static void update_cluster_info(const struct cluster_info *cinfo,
start_recovery(main_thread_get(current_vnode_info),
old_vnode_info, true);
- } else
+ } else if (!was_cluster_shutdowned()) {
start_recovery(main_thread_get(current_vnode_info),
main_thread_get(current_vnode_info),
false);
+ }
+ set_cluster_shutdown(false);
}
put_vnode_info(old_vnode_info);
diff --git a/sheep/ops.c b/sheep/ops.c
index f2d0a4d..816b12a 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -272,7 +272,12 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
static int cluster_shutdown(const struct sd_req *req, struct sd_rsp *rsp,
void *data)
{
+ int ret;
+
sys->cinfo.status = SD_STATUS_SHUTDOWN;
+ ret = set_cluster_shutdown(true);
+ if (ret != SD_RES_SUCCESS)
+ sd_err("failed to set cluster as shutdown");
return SD_RES_SUCCESS;
}
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 52b6b05..bb3ebbb 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -326,6 +326,8 @@ int get_cluster_config(struct cluster_info *cinfo);
int set_node_space(uint64_t space);
int get_node_space(uint64_t *space);
bool is_cluster_formatted(void);
+bool was_cluster_shutdowned(void);
+int set_cluster_shutdown(bool);
int store_file_write(void *buffer, size_t len);
void *store_file_read(void);
--
1.7.9.5
More information about the sheepdog
mailing list