vos: convertROtoRW may create 2nd RW on a fileserver
authorMark Vitale <mvitale@sinenomine.net>
Thu, 2 Aug 2012 22:37:05 +0000 (18:37 -0400)
committerDerrick Brashear <shadow@dementix.org>
Thu, 9 Aug 2012 15:05:32 +0000 (08:05 -0700)
If an RW is already present on disk on the target server (any partition),
'vos convertROtoRW' will still convert the RO, creating a second RW on the server.
Detect this and refuse to convert the RO by returning EXDEV (invalid cross-device link).

Change-Id: Ide15a7c39f2a975fd8597e497094b6a67b448e4f
Reviewed-on: http://gerrit.openafs.org/7934
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

src/vol/namei_ops.c

index 0c006f8..7274af5 100644 (file)
@@ -2894,6 +2894,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
     struct DiskPartition64 *partP;
     struct ViceInodeInfo info;
     struct VolumeDiskHeader h;
+    char *rwpart, *rwname;
+    Error ec;
 # ifdef AFS_DEMAND_ATTACH_FS
     int locktype = 0;
 # endif /* AFS_DEMAND_ATTACH_FS */
@@ -2923,6 +2925,19 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
        goto done;
     }
 
+    /* check for existing RW on any partition on this server; */
+    /* if found, return EXDEV - invalid cross-device link */
+    VOL_LOCK;
+    VGetVolumePath(&ec, h.parent, &rwpart, &rwname);
+    if (ec == 0) {
+       Log("1 namei_ConvertROtoRWvolume: RW volume %lu already exists on server partition %s.\n",
+           afs_printable_uint32_lu(h.parent), rwpart);
+       code = EXDEV;
+       VOL_UNLOCK;
+       goto done;
+    }
+    VOL_UNLOCK;
+
     FSYNC_VolOp(volumeId, pname, FSYNC_VOL_BREAKCBKS, 0, NULL);
 
     ino = namei_MakeSpecIno(h.parent, VI_LINKTABLE);