From 7c0d35b2e7e234084d0414b3cf1e09969a43a677 Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Thu, 27 Dec 2012 15:57:13 +0530 Subject: glusterd: harden 'volume start' staging to check for brick dirs' presence PROBLEM: When the brick directory of a volume is absent on any of the servers, AND an attempt is made to start the volume, commit fails ONLY on the node where the brick dir is absent, leading to a split-brain like situation. FIX: Harden 'volume start' to check for the presence of brick directories at the time of staging, thereby preventing commit failure. Change-Id: I67faeb9afbd3aa76f08645924462db126bf7a977 BUG: 889996 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/4365 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/common-utils.c | 30 ++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 3 +++ 2 files changed, 33 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 75b977225..19afeee3d 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -44,6 +44,7 @@ #include "stack.h" #include "globals.h" #include "lkowner.h" +#include "syscall.h" #ifndef AI_ADDRCONFIG #define AI_ADDRCONFIG 0 @@ -112,6 +113,35 @@ out: return ret; } +int +gf_lstat_dir (const char *path, struct stat *stbuf_in) +{ + int ret = -1; + struct stat stbuf = {0,}; + + if (path == NULL) { + errno = EINVAL; + goto out; + } + + ret = sys_lstat (path, &stbuf); + if (ret) + goto out; + + if (!S_ISDIR (stbuf.st_mode)) { + errno = ENOTDIR; + ret = -1; + goto out; + } + ret = 0; + +out: + if (!ret && stbuf_in) + *stbuf_in = stbuf; + + return ret; +} + int log_base2 (unsigned long x) { diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index bbafd1fb0..d04df579b 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -483,6 +483,9 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks); * nr */ +int +gf_lstat_dir (const char *path, struct stat *stbuf_in); + int32_t gf_roundup_power_of_two (int32_t nr); /* -- cgit