diff options
author | Krishnan Parthasarathi <kp@gluster.com> | 2011-04-27 04:46:23 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-05-09 13:26:40 -0700 |
commit | a7ca559bdebfcef9a38dfedb8e4757d42431bf94 (patch) | |
tree | 3ee7509f982df3d2bf1f72294e983622e3a2bb9b | |
parent | 57b53ca592c8d2d01767c7943cb071eb24e6835f (diff) |
Detect read-only filesystem and fail the brick creation operation.
Signed-off-by: Krishnan Parthasarathi <kp@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
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
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index ad2b7dde893..1dcfdf4b4c7 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; } |