[sheepdog] [PATCH 2/2] use xmkdir where possible
Liu Yuan
namei.unix at gmail.com
Wed Mar 20 10:25:40 CET 2013
From: Liu Yuan <tailai.ly at taobao.com>
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/farm/farm.c | 30 ++++++++++++------------------
sheep/md.c | 3 +--
sheep/object_cache.c | 31 ++++++++++++-------------------
sheep/plain_store.c | 8 +++-----
sheepfs/core.c | 8 +++-----
sheepfs/shadow_file.c | 10 ++++------
6 files changed, 35 insertions(+), 55 deletions(-)
diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 7becdd1..952a70b 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -32,33 +32,27 @@ static int create_directory(const char *p)
strbuf_addstr(&buf, p);
strbuf_addstr(&buf, ".farm");
- if (mkdir(buf.buf, 0755) < 0) {
- if (errno != EEXIST) {
- sd_eprintf("%m");
- ret = -1;
- goto err;
- }
+ if (xmkdir(buf.buf, 0755) < 0) {
+ sd_eprintf("%m");
+ ret = -1;
+ goto err;
}
if (!strlen(farm_dir))
strbuf_copyout(&buf, farm_dir, sizeof(farm_dir));
strbuf_addstr(&buf, "/objects");
- if (mkdir(buf.buf, 0755) < 0) {
- if (errno != EEXIST) {
- sd_eprintf("%m");
- ret = -1;
- goto err;
- }
+ if (xmkdir(buf.buf, 0755) < 0) {
+ sd_eprintf("%m");
+ ret = -1;
+ goto err;
}
for (i = 0; i < 256; i++) {
strbuf_addf(&buf, "/%02x", i);
- if (mkdir(buf.buf, 0755) < 0) {
- if (errno != EEXIST) {
- sd_eprintf("%m");
- ret = -1;
- goto err;
- }
+ if (xmkdir(buf.buf, 0755) < 0) {
+ sd_eprintf("%m");
+ ret = -1;
+ goto err;
}
strbuf_remove(&buf, buf.len - 3, 3);
}
diff --git a/sheep/md.c b/sheep/md.c
index 0bbb160..3569acc 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -114,8 +114,7 @@ int md_init_disk(char *path)
{
md_nr_disks++;
- if (mkdir(path, def_dmode) < 0)
- if (errno != EEXIST)
+ if (xmkdir(path, def_dmode) < 0)
panic("%s, %m", path);
pstrcpy(md_disks[md_nr_disks - 1].path, PATH_MAX, path);
sd_iprintf("%s added to md, nr %d", md_disks[md_nr_disks - 1].path,
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 0781c28..3090233 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -561,13 +561,10 @@ static int create_dir_for(uint32_t vid)
char p[PATH_MAX];
snprintf(p, sizeof(p), "%s/%06"PRIx32, object_cache_dir, vid);
- if (mkdir(p, def_dmode) < 0)
- if (errno != EEXIST) {
- sd_eprintf("%s, %m", p);
- ret = -1;
- goto err;
- }
-err:
+ if (xmkdir(p, def_dmode) < 0) {
+ sd_eprintf("%s, %m", p);
+ ret = -1;
+ }
return ret;
}
@@ -1254,20 +1251,16 @@ int object_cache_init(const char *p)
struct strbuf buf = STRBUF_INIT;
strbuf_addstr(&buf, p);
- if (mkdir(buf.buf, def_dmode) < 0) {
- if (errno != EEXIST) {
- sd_eprintf("%s %m", buf.buf);
- ret = -1;
- goto err;
- }
+ if (xmkdir(buf.buf, def_dmode) < 0) {
+ sd_eprintf("%s %m", buf.buf);
+ ret = -1;
+ goto err;
}
strbuf_addstr(&buf, "/cache");
- if (mkdir(buf.buf, def_dmode) < 0) {
- if (errno != EEXIST) {
- sd_eprintf("%s %m", buf.buf);
- ret = -1;
- goto err;
- }
+ if (xmkdir(buf.buf, def_dmode) < 0) {
+ sd_eprintf("%s %m", buf.buf);
+ ret = -1;
+ goto err;
}
strbuf_copyout(&buf, object_cache_dir, sizeof(object_cache_dir));
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index ad55e09..7bda5cd 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -136,11 +136,9 @@ static int make_stale_dir(char *path)
char p[PATH_MAX];
snprintf(p, PATH_MAX, "%s/.stale", path);
- if (mkdir(p, def_dmode) < 0) {
- if (errno != EEXIST) {
- sd_eprintf("%s failed, %m", p);
- return SD_RES_EIO;
- }
+ if (xmkdir(p, def_dmode) < 0) {
+ sd_eprintf("%s failed, %m", p);
+ return SD_RES_EIO;
}
return SD_RES_SUCCESS;
}
diff --git a/sheepfs/core.c b/sheepfs/core.c
index b232429..5553b09 100644
--- a/sheepfs/core.c
+++ b/sheepfs/core.c
@@ -364,11 +364,9 @@ int main(int argc, char **argv)
strbuf_addf(&path, "%s/%s", cwd, ".sheepfs");
free(cwd);
memcpy(sheepfs_shadow, path.buf, path.len);
- if (mkdir(sheepfs_shadow, 0755) < 0) {
- if (errno != EEXIST) {
- fprintf(stderr, "%m\n");
- exit(1);
- }
+ if (xmkdir(sheepfs_shadow, 0755) < 0) {
+ fprintf(stderr, "%m\n");
+ exit(1);
}
strbuf_release(&path);
diff --git a/sheepfs/shadow_file.c b/sheepfs/shadow_file.c
index 0545f52..9579c78 100644
--- a/sheepfs/shadow_file.c
+++ b/sheepfs/shadow_file.c
@@ -85,17 +85,15 @@ int shadow_dir_create(const char *path)
char p[PATH_MAX];
snprintf(p, sizeof(p), "%s%s", sheepfs_shadow, path);
- if (mkdir(p, 0755) < 0) {
- if (errno != EEXIST) {
- sheepfs_pr("%m\n");
- return -1;
- }
+ if (xmkdir(p, 0755) < 0) {
+ sheepfs_pr("%m\n");
+ return -1;
}
return 0;
}
int shadow_file_setxattr(const char *path, const char *name,
- const void *value, size_t size)
+ const void *value, size_t size)
{
char p[PATH_MAX];
--
1.7.9.5
More information about the sheepdog
mailing list