[sheepdog] [PATCH v6 4/7] sheep: use new journal API for config file
MORITA Kazutaka
morita.kazutaka at gmail.com
Sat Apr 13 16:18:33 CEST 2013
At Mon, 8 Apr 2013 14:04:58 +0800,
Liu Yuan wrote:
>
> From: Liu Yuan <tailai.ly at taobao.com>
>
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
> sheep/config.c | 33 ++++++++++++++++++---------------
> sheep/sheep.c | 26 +++++++++++++++-----------
> sheep/sheep_priv.h | 3 ++-
> sheep/store.c | 4 +---
> 4 files changed, 36 insertions(+), 30 deletions(-)
>
> diff --git a/sheep/config.c b/sheep/config.c
> index 63cfe87..14da875 100644
> --- a/sheep/config.c
> +++ b/sheep/config.c
> @@ -36,7 +36,14 @@ char *config_path;
> static int write_config(void)
> {
> int fd, ret;
> - void *jd;
> +
> + if (uatomic_is_true(&sys->use_journal) &&
> + journal_write_config((char *)&config, sizeof(config))
> + != SD_RES_SUCCESS) {
> + sd_eprintf("turn off journaling");
> + uatomic_set_false(&sys->use_journal);
> + sync();
> + }
>
> fd = open(config_path, O_DSYNC | O_WRONLY | O_CREAT, def_fmode);
> if (fd < 0) {
> @@ -44,32 +51,20 @@ static int write_config(void)
> return SD_RES_EIO;
> }
>
> - jd = jrnl_begin(&config, sizeof(config), 0, config_path, jrnl_path);
> - if (!jd) {
> - sd_eprintf("failed to write config data to journal, %m");
> - ret = SD_RES_EIO;
> - goto out;
> - }
> ret = xwrite(fd, &config, sizeof(config));
> if (ret != sizeof(config)) {
> sd_eprintf("failed to write config data, %m");
> ret = SD_RES_EIO;
> } else
> ret = SD_RES_SUCCESS;
> -
> - jrnl_end(jd);
> -out:
> close(fd);
>
> return ret;
> }
>
> -int init_config_path(const char *base_path)
> +int init_config_file(void)
> {
> - int fd, ret, len = strlen(base_path) + strlen(CONFIG_PATH) + 1;
> -
> - config_path = xzalloc(len);
> - snprintf(config_path, len, "%s" CONFIG_PATH, base_path);
> + int fd, ret;
>
> fd = open(config_path, O_RDONLY);
> if (fd < 0) {
> @@ -126,6 +121,14 @@ create:
> return 0;
> }
>
> +void init_config_path(const char *base_path)
> +{
> + int len = strlen(base_path) + strlen(CONFIG_PATH) + 1;
> +
> + config_path = xzalloc(len);
> + snprintf(config_path, len, "%s" CONFIG_PATH, base_path);
> +}
> +
> int set_cluster_ctime(uint64_t ct)
> {
> config.ctime = ct;
> diff --git a/sheep/sheep.c b/sheep/sheep.c
> index 4fa7d58..cda8493 100644
> --- a/sheep/sheep.c
> +++ b/sheep/sheep.c
> @@ -597,6 +597,21 @@ int main(int argc, char **argv)
> if (ret)
> exit(1);
>
> + /* We should init journal file before config file init */
> + if (uatomic_is_true(&sys->use_journal)) {
> + if (!strlen(jpath))
> + /* internal journal */
> + memcpy(jpath, dir, strlen(dir));
> + sd_dprintf("%s, %zu, %d", jpath, jsize, jskip);
> + ret = journal_file_init(jpath, jsize, jskip);
> + if (ret)
> + exit(1);
> + }
> +
> + ret = init_config_file();
> + if (ret)
> + exit(1);
> +
> ret = create_listen_port(bindaddr, port);
> if (ret)
> exit(1);
> @@ -625,17 +640,6 @@ int main(int argc, char **argv)
> exit(1);
> }
>
> - /* We should init journal file before backend init */
> - if (uatomic_is_true(&sys->use_journal)) {
> - if (!strlen(jpath))
> - /* internal journal */
> - memcpy(jpath, dir, strlen(dir));
> - sd_dprintf("%s, %zu, %d", jpath, jsize, jskip);
> - ret = journal_file_init(jpath, jsize, jskip);
> - if (ret)
> - exit(1);
> - }
> -
> /*
> * After this function, we are multi-threaded.
> *
I've found that we cannot pass tests/047 with -md because of this
change. We have to call init_disk_space() before journal_file_init().
Otherwise, sheep cannot replay journal entries correctly since
md_disks are setup in md_init_space().
However, we read the config file in init_disk_space(), so
journal_file_init() must be called before init_disk_space() in that
sense. I think we need to give up using journal against the config
file, or store a vdisk index to the journal descriptor so that we can
get a correct object path.
Thanks,
Kazutaka
More information about the sheepdog
mailing list