[sheepdog] [PATCH 4/5] sheep: use new journal API for config file
Liu Yuan
namei.unix at gmail.com
Tue Apr 2 11:23:01 CEST 2013
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..6d5603d 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_confi((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.
*
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index e8031fe..24b4014 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -290,7 +290,8 @@ int epoch_log_read_with_timestamp(uint32_t epoch, struct sd_node *nodes,
int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len,
time_t *timestamp);
uint32_t get_latest_epoch(void);
-int init_config_path(const char *base_path);
+void init_config_path(const char *base_path);
+int init_config_file(void);
int set_cluster_ctime(uint64_t ctime);
uint64_t get_cluster_ctime(void);
int get_obj_list(const struct sd_list_req *, struct sd_list_rsp *, void *);
diff --git a/sheep/store.c b/sheep/store.c
index af9da9e..4a28cdc 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -411,9 +411,7 @@ int init_global_pathnames(const char *d, char *argp)
if (ret)
return ret;
- ret = init_config_path(d);
- if (ret)
- return ret;
+ init_config_path(d);
return 0;
}
--
1.7.9.5
More information about the sheepdog
mailing list