[sheepdog] [PATCH 1/2] migrate: update config file with a new format version
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Thu Oct 4 22:28:50 CEST 2012
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/config.c | 10 ++++++++++
sheep/migrate.c | 30 +++++++++++++++++++-----------
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/sheep/config.c b/sheep/config.c
index b2e9f58..e38bea0 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -96,6 +96,16 @@ int init_config_path(const char *base_path)
if (sys->upgrade) {
/* upgrade sheep store */
ret = sd_migrate_store(config.version, SD_FORMAT_VERSION);
+ if (ret == 0) {
+ /* reload config file */
+ ret = xpread(fd, &config, sizeof(config), 0);
+ if (ret != sizeof(config)) {
+ eprintf("failed to reload config file,"
+ " %m\n");
+ ret = -1;
+ } else
+ ret = 0;
+ }
goto out;
}
diff --git a/sheep/migrate.c b/sheep/migrate.c
index bbad644..d253ead 100644
--- a/sheep/migrate.c
+++ b/sheep/migrate.c
@@ -81,21 +81,29 @@ static int migrate_from_v0_to_v1(void)
return ret;
}
+ config.version = 1;
+ ret = xpwrite(fd, &config, sizeof(config), 0);
+ if (ret != sizeof(config)) {
+ eprintf("failed to write config data, %m\n");
+ close(fd);
+ return -1;
+ }
+
+ /* 0.5.1 could wrongly extend the config file, so truncate it here */
+ ret = ftruncate(fd, sizeof(config));
+ if (ret != 0) {
+ eprintf("failed to truncate config data, %m\n");
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
/* If the config file contains a space field, the store layout
* is compatible with v1. In this case, what we need to do is
* only adding version number to the config file. */
- if (config.space > 0) {
- config.version = 1;
- ret = xwrite(fd, &config, sizeof(config));
- if (ret != sizeof(config)) {
- eprintf("failed to write config data, %m\n");
- close(fd);
- return -1;
- }
-
- close(fd);
+ if (config.space > 0)
return 0;
- }
/* upgrade epoch log */
le = get_latest_epoch();
--
1.7.2.5
More information about the sheepdog
mailing list