From 83c41c69411ece7ac1dd0a7b15d4ee9746edcf23 Mon Sep 17 00:00:00 2001 From: Jacob Thebault-Spieker Date: Tue, 19 Jul 2011 15:01:26 -0700 Subject: [PATCH] allow cloning of any volume to any volume with same parent ID remove checks to disallow cloning of ro volumes to rw volumes, which allows cloning of any volume within the same parent ID grouping, including allowing destruction of newer version of the volumes. Change-Id: I13f600c33934b9af8237f049225d6bacfbbb5690 Reviewed-on: http://gerrit.openafs.org/5049 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/volser/volprocs.c | 27 +++------------------------ src/volser/volser.p.h | 1 + src/volser/vos.c | 7 +++++++ src/volser/vsprocs.c | 12 +++++++++--- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/volser/volprocs.c b/src/volser/volprocs.c index 8083cc2e3..ce14408e2 100644 --- a/src/volser/volprocs.c +++ b/src/volser/volprocs.c @@ -727,8 +727,6 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId, } newId = *newNumber; - if (newType != readonlyVolume && newType != backupVolume) - return EINVAL; tt = FindTrans(atrans); if (!tt) return ENOENT; @@ -778,15 +776,8 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId, error = EINVAL; goto fail; } - if (V_type(originalvp) == readonlyVolume - && V_parentId(originalvp) != V_parentId(purgevp)) { - Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, purgeId); - error = EXDEV; - goto fail; - } - if (V_type(originalvp) == readwriteVolume - && tt->volid != V_parentId(purgevp)) { - Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", purgeId, tt->volid); + if (V_parentId(originalvp) != V_parentId(purgevp)) { + Log("1 Volser: Clone: Volume %u and volume %u were not originally cloned from the same parent; aborted\n", purgeId, tt->volid); error = EXDEV; goto fail; } @@ -951,19 +942,7 @@ VolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId) error = EXDEV; goto fail; } - if (V_type(clonevp) != readonlyVolume && V_type(clonevp) != backupVolume) { - Log("1 Volser: Clone: The \"recloned\" volume must be a read only volume; aborted\n"); - error = EINVAL; - goto fail; - } - if (V_type(originalvp) == readonlyVolume - && V_parentId(originalvp) != V_parentId(clonevp)) { - Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, cloneId); - error = EXDEV; - goto fail; - } - if (V_type(originalvp) == readwriteVolume - && tt->volid != V_parentId(clonevp)) { + if (V_parentId(originalvp) != V_parentId(clonevp)) { Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", cloneId, tt->volid); error = EXDEV; goto fail; diff --git a/src/volser/volser.p.h b/src/volser/volser.p.h index ab68f73af..4d8ed084b 100644 --- a/src/volser/volser.p.h +++ b/src/volser/volser.p.h @@ -181,6 +181,7 @@ struct partList { /*used by the backup system */ #define RV_NOVLDB 0x040000 #define RV_NOCLONE 0x080000 #define RV_NODEL 0x100000 +#define RV_RWONLY 0x200000 struct ubik_client; extern afs_uint32 vsu_GetVolumeID(char *astring, struct ubik_client *acstruct, afs_int32 *errp); diff --git a/src/volser/vos.c b/src/volser/vos.c index 38c5aa6a1..2735ac11e 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -2733,7 +2733,12 @@ CloneVolume(struct cmd_syndesc *as, void *arock) flags = 0; if (as->parms[5].items) flags |= RV_OFFLINE; + if (as->parms[6].items && as->parms[7].items) { + fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n"); + return EINVAL; + } if (as->parms[6].items) flags |= RV_RDONLY; + if (as->parms[7].items) flags |= RV_RWONLY; code = @@ -5977,6 +5982,8 @@ main(int argc, char **argv) "leave clone volume offline"); cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL, "make clone volume read-only, not readwrite"); + cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL, + "make clone volume readwrite, not read-only"); COMMONPARMS; ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume"); diff --git a/src/volser/vsprocs.c b/src/volser/vsprocs.c index b32075985..94df88469 100644 --- a/src/volser/vsprocs.c +++ b/src/volser/vsprocs.c @@ -3000,6 +3000,7 @@ UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid, afs_int32 error = 0; int backexists = 1; volEntries volumeInfo; + int type = 0; aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); @@ -3086,9 +3087,14 @@ UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid, } else { VPRINT1("Creating a new clone %u ...", acloneid); - code = AFSVolClone(aconn, ttid, 0, - (flags & RV_RDONLY) ? readonlyVolume : backupVolume, - aname, &acloneid); + if (flags & RV_RWONLY) + type = readwriteVolume; + else if (flags & RV_RDONLY) + type = readonlyVolume; + else + type = backupVolume; + + code = AFSVolClone(aconn, ttid, 0, type, aname, &acloneid); if (code) { fprintf(STDERR, "Failed to clone the volume %lu\n", (unsigned long)avolid); -- 2.39.5