From a7ca559bdebfcef9a38dfedb8e4757d42431bf94 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Wed, 27 Apr 2011 04:46:23 +0000 Subject: Detect read-only filesystem and fail the brick creation operation. Signed-off-by: Krishnan Parthasarathi Signed-off-by: Anand Avati BUG: 2609 (Error message not properly provided when trying to create a volume from a read-only source) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2609 --- xlators/mgmt/glusterd/src/glusterd-utils.c | 40 ++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'xlators') diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index ad2b7dde8..1dcfdf4b4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -35,6 +35,7 @@ #include "md5.h" #include "compat-errno.h" #include "statedump.h" +#include "syscall.h" #include "glusterd-mem-types.h" #include "glusterd.h" #include "glusterd-op-sm.h" @@ -2915,25 +2916,44 @@ glusterd_brick_create_path (char *host, char *path, mode_t mode, snprintf (msg, sizeof (msg), "brick %s:%s, " "path %s is not a directory", host, path, path); gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); ret = -1; goto out; } else if (!ret) { - goto out; + goto check_xattr; + } else { + ret = mkdir (path, mode); + if (ret) { + snprintf (msg, sizeof (msg), "brick: %s:%s, path " + "creation failed, reason: %s", + host, path, strerror(errno)); + gf_log ("glusterd", GF_LOG_ERROR, "%s", msg); + goto out; + } else { + goto check_xattr; + } } - ret = mkdir (path, mode); - if ((ret == -1) && (EEXIST != errno)) { - snprintf (msg, sizeof (msg), "brick: %s:%s, path " - "creation failed, reason: %s", - host, path, strerror(errno)); - gf_log ("glusterd",GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); +/* To check if filesystem is read-only + and if it supports extended attributes */ +check_xattr: + ret = sys_lsetxattr (path, "trusted.glusterfs.test", + "working", 8, 0); + if (ret) { + snprintf (msg, sizeof (msg), "glusterfs is not" + " supported on brick: %s:%s.\nSetting" + " extended attributes failed, reason:" + " %s.", host, path, strerror(errno)); + + gf_log ("glusterd", GF_LOG_ERROR, "%s", msg); } else { - ret = 0; + /* Remove xattr *cannot* fail after setting it succeeded */ + sys_lremovexattr (path, "trusted.glusterfs.test"); } out: + if (msg[0] != '\0') + *op_errstr = gf_strdup (msg); + gf_log ("", GF_LOG_DEBUG, "returning %d", ret); return ret; } -- cgit