Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- Hi Yuan, Isn't it better to add a nohalt field instead of a generic name "flags"? This would be the most intuitive way. The size of config file wouldn't become a problem, so we don't need to save bits, I think. How do you think? Thanks, Kazutaka sheep/sheep_priv.h | 2 ++ sheep/store.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletions(-) diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h index cccb986..e087558 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -210,6 +210,8 @@ int update_epoch_store(uint32_t epoch); int set_global_nr_copies(uint32_t copies); int get_global_nr_copies(uint32_t *copies); +int set_cluster_nohalt(int on); +int is_cluster_nohalt(void); #define NR_GW_WORKER_THREAD 4 #define NR_IO_WORKER_THREAD 4 diff --git a/sheep/store.c b/sheep/store.c index 3da5713..addc41a 100644 --- a/sheep/store.c +++ b/sheep/store.c @@ -27,7 +27,7 @@ struct sheepdog_config { uint64_t ctime; uint32_t copies; - uint32_t flags; + uint32_t nohalt; }; static char *obj_path; @@ -2054,3 +2054,49 @@ int get_global_nr_copies(uint32_t *copies) return SD_RES_SUCCESS; } + +int set_cluster_nohalt(int on) +{ + int fd, ret; + struct sheepdog_config config = { + .nohalt = on, + }; + + fd = open(config_path, O_SYNC | O_WRONLY); + if (fd < 0) + return SD_RES_EIO; + + ret = jrnl_perform(fd, &config.nohalt, sizeof(config.nohalt), + offsetof(struct sheepdog_config, nohalt), + config_path, jrnl_path); + close(fd); + + if (ret != 0) + return SD_RES_EIO; + + return SD_RES_SUCCESS; +} + +/* + * Returns 1 if the cluster serves the IO requests even if there + * aren't enough redundant nodes. Otherwise, returns 0. On error, + * returns a negative value + */ +int is_cluster_nohalt(void) +{ + int fd, ret; + struct sheepdog_config config; + + fd = open(config_path, O_RDONLY); + if (fd < 0) + return SD_RES_EIO; + + ret = pread64(fd, &config.nohalt, sizeof(config.nohalt), + offsetof(struct sheepdog_config, nohalt)); + close(fd); + + if (ret != sizeof(config.nohalt)) + return -SD_RES_EIO; + + return !!config.nohalt; +} -- 1.7.2.5 |