[Sheepdog] [PATCH 1/5] sheep: find vdis from old epoch directories too
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Thu Sep 1 11:46:40 CEST 2011
The latest epoch directory may not contain all the vdi objects if the
node crashed before completing the object recovery. To avoid data
loss, it is better to find vdi objects from older epoch directories
too.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/store.c | 45 +++++++++++++++++++++++----------------------
1 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/sheep/store.c b/sheep/store.c
index 1f0daff..d251d21 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -1959,7 +1959,7 @@ static int init_obj_path(const char *base_path)
static int init_epoch_path(const char *base_path)
{
int new, ret;
- uint32_t epoch;
+ uint32_t epoch, latest_epoch;
DIR *dir;
char path[1024];
struct dirent *dent;
@@ -1972,37 +1972,38 @@ static int init_epoch_path(const char *base_path)
if (new || ret)
return ret;
- epoch = get_latest_epoch();
+ latest_epoch = get_latest_epoch();
- snprintf(path, sizeof(path), "%s/%08u", obj_path, epoch);
+ for (epoch = 1; epoch <= latest_epoch; epoch++) {
+ snprintf(path, sizeof(path), "%s/%08u", obj_path, epoch);
- vprintf(SDOG_INFO "found the epoch dir, %s\n", path);
+ vprintf(SDOG_INFO "found the obj dir, %s\n", path);
- dir = opendir(path);
- if (!dir) {
- if (errno == ENOENT)
- /* probably, sheepdog is not formatted yet */
- return 0;
+ dir = opendir(path);
+ if (!dir) {
+ if (errno == ENOENT)
+ continue;
- vprintf(SDOG_ERR "failed to open the epoch dir, %m\n");
- return SD_RES_EIO;
- }
+ vprintf(SDOG_ERR "failed to open the epoch dir, %m\n");
+ return SD_RES_EIO;
+ }
- while ((dent = readdir(dir))) {
- if (!strcmp(dent->d_name, ".") ||
- !strcmp(dent->d_name, ".."))
- continue;
+ while ((dent = readdir(dir))) {
+ if (!strcmp(dent->d_name, ".") ||
+ !strcmp(dent->d_name, ".."))
+ continue;
- oid = strtoull(dent->d_name, NULL, 16);
+ oid = strtoull(dent->d_name, NULL, 16);
- if (!is_vdi_obj(oid))
- continue;
+ if (!is_vdi_obj(oid))
+ continue;
- vprintf(SDOG_DEBUG "found the vdi obj, %" PRIx64 "\n", oid);
+ vprintf(SDOG_DEBUG "found the vdi obj, %" PRIx64 "\n", oid);
- set_bit(oid_to_vid(oid), sys->vdi_inuse);
+ set_bit(oid_to_vid(oid), sys->vdi_inuse);
+ }
+ closedir(dir);
}
- closedir(dir);
return 0;
}
--
1.7.2.5
More information about the sheepdog
mailing list