[sheepdog] [PATCH v3 1/2] md: move purge_directory in init_path_space()
Liu Yuan
namei.unix at gmail.com
Thu Sep 5 04:52:52 CEST 2013
Or it will falsely remove .stale directory for newly added disk. For startup,
we don't purge directory.
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
sheep/md.c | 13 ++++++++-----
sheep/sheep_priv.h | 2 +-
sheep/store.c | 4 ++--
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/sheep/md.c b/sheep/md.c
index 37feeb2..25d1069 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -209,7 +209,7 @@ out:
* safely use 0 to represent failure case because 0 space path can be
* considered as broken path.
*/
-static uint64_t init_path_space(const char *path)
+static uint64_t init_path_space(const char *path, bool purge)
{
uint64_t size;
char stale[PATH_MAX];
@@ -219,6 +219,9 @@ static uint64_t init_path_space(const char *path)
goto broken_path;
}
+ if (purge && purge_directory(path) < 0)
+ sd_err("failed to purge %s", path);
+
snprintf(stale, PATH_MAX, "%s/.stale", path);
if (xmkdir(stale, sd_def_dmode) < 0) {
sd_err("can't mkdir for %s, %m", stale);
@@ -251,7 +254,7 @@ broken_path:
}
/* We don't need lock at init stage */
-bool md_add_disk(const char *path)
+bool md_add_disk(const char *path, bool purge)
{
struct disk *new;
@@ -267,7 +270,7 @@ bool md_add_disk(const char *path)
new = xmalloc(sizeof(*new));
pstrcpy(new->path, PATH_MAX, path);
- new->space = init_path_space(new->path);
+ new->space = init_path_space(new->path, purge);
if (!new->space) {
free(new);
return false;
@@ -614,8 +617,8 @@ static int do_plug_unplug(char *disks, bool plug)
path = strtok(disks, ",");
do {
if (plug) {
- if (md_add_disk(path) && purge_directory(path) < 0)
- md_del_disk(path);
+ if (!md_add_disk(path, true))
+ sd_err("failed to add %s", path);
} else {
md_del_disk(path);
}
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 60ebbe0..3643d12 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -437,7 +437,7 @@ journal_write_store(uint64_t oid, const char *buf, size_t size, off_t, bool);
int journal_remove_object(uint64_t oid);
/* md.c */
-bool md_add_disk(const char *path);
+bool md_add_disk(const char *path, bool);
uint64_t md_init_space(void);
const char *md_get_object_path(uint64_t oid);
int md_handle_eio(const char *);
diff --git a/sheep/store.c b/sheep/store.c
index 3e898b8..a5239d5 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -222,14 +222,14 @@ static int init_obj_path(const char *base_path, char *argp)
* it. This is helpful to upgrade old sheep cluster to
* the MD-enabled.
*/
- md_add_disk(obj_path);
+ md_add_disk(obj_path, false);
} else {
do {
if (is_meta_store(p)) {
sd_err("%s is meta-store, abort", p);
return -1;
}
- md_add_disk(p);
+ md_add_disk(p, false);
} while ((p = strtok(NULL, ",")));
}
return xmkdir(obj_path, sd_def_dmode);
--
1.7.9.5
More information about the sheepdog
mailing list