summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorAnand Avati <avati@gluster.com>2011-07-12 02:16:17 +0000
committerAnand Avati <avati@gluster.com>2011-07-12 02:24:31 -0700
commitbed94fc008b3446ce390eded41aab5cda297cf4b (patch)
tree0a464c9dff54c16311cf396e2cdd67dfc748aa10 /xlators
parent0de3de4523a987893965240c5425f811f1c3e172 (diff)
storage/posix: detect race in posix_rename()
detect a race in rename between two clients by checking for reassigned gfid or presence of dir when not expecting. checks not necessary for rename of files. Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2522 ([glusterfs-3.1.3qa8]: rm -rf shows invalid argument) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2522
Diffstat (limited to 'xlators')
-rw-r--r--xlators/storage/posix/src/posix.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 2472ff9..27dc534 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -1797,6 +1797,8 @@ posix_rename (call_frame_t *frame, xlator_t *this,
struct iatt postoldparent = {0, };
struct iatt prenewparent = {0, };
struct iatt postnewparent = {0, };
+ char olddirid[64];
+ char newdirid[64];
DECLARE_OLD_FS_ID_VAR;
@@ -1845,6 +1847,27 @@ posix_rename (call_frame_t *frame, xlator_t *this,
was_present = 0;
}
+ if (was_present && IA_ISDIR(stbuf.ia_type) && !newloc->inode) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "found directory at %s while expecting ENOENT",
+ real_newpath);
+ op_ret = -1;
+ op_errno = EEXIST;
+ goto out;
+ }
+
+ if (was_present && IA_ISDIR(stbuf.ia_type) &&
+ uuid_compare (newloc->inode->gfid, stbuf.ia_gfid)) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "found directory %s at %s while renaming %s",
+ uuid_utoa_r (newloc->inode->gfid, olddirid),
+ real_newpath,
+ uuid_utoa_r (stbuf.ia_gfid, newdirid));
+ op_ret = -1;
+ op_errno = EEXIST;
+ goto out;
+ }
+
op_ret = sys_rename (real_oldpath, real_newpath);
if (op_ret == -1) {
op_errno = errno;