From b44afa839b7c5dd33ab83958f0871edac32fc7ac Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Mon, 11 Feb 2008 03:42:40 +0000 Subject: [PATCH] vos-syncv-dryrun-20080210 LICENSE IPL10 add a dryrun mode to vos syncvldb and syncserv --- src/volser/vos.c | 13 +++++-- src/volser/vsprocs.c | 83 +++++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/src/volser/vos.c b/src/volser/vos.c index 63006d947d..cc63064cdd 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -3720,6 +3720,10 @@ SyncVldb(register struct cmd_syndesc *as, void *arock) } } + if (as->parms[3].items) { + flags |= 2; /* don't update */ + } + if (as->parms[2].items) { /* Synchronize an individual volume */ volname = as->parms[2].items->data; @@ -3746,7 +3750,7 @@ SyncVldb(register struct cmd_syndesc *as, void *arock) if (tserver) { fprintf(STDOUT, " with state of server %s", as->parms[0].items->data); } - if (flags) { + if (flags & 1) { MapPartIdIntoName(pnum, part); fprintf(STDOUT, " partition %s\n", part); } @@ -3790,12 +3794,15 @@ SyncServer(register struct cmd_syndesc *as, void *arock) pnum = -1; } + if (as->parms[2].items) { + flags |= 2; /* don't update */ + } code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ ); if (code) { PrintDiagnostics("syncserv", code); exit(1); } - if (flags) { + if (flags & 1) { MapPartIdIntoName(pnum, part); fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n", as->parms[0].items->data, part); @@ -5867,12 +5874,14 @@ main(argc, argv) cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID"); + cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating"); COMMONPARMS; ts = cmd_CreateSyntax("syncserv", SyncServer, NULL, "synchronize server with VLDB"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating"); COMMONPARMS; ts = cmd_CreateSyntax("examine", ExamineVolume, NULL, diff --git a/src/volser/vsprocs.c b/src/volser/vsprocs.c index 13781cc86c..dde6ebd10d 100644 --- a/src/volser/vsprocs.c +++ b/src/volser/vsprocs.c @@ -5272,11 +5272,14 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart, afs_int32 code, error = 0; struct nvldbentry entry, storeEntry; char pname[10]; - int pass = 0, islocked = 0, createentry, addvolume, modified, mod; + int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1; afs_int32 rwvolid; - if (modentry) + if (modentry) { + if (*modentry == 1) + doit = 0; *modentry = 0; + } rwvolid = ((volumeinfo->type == RWVOL) ? volumeinfo->volid : volumeinfo->parentID); @@ -5632,7 +5635,7 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart, if (entry.volumeId[RWVOL] > *maxvolid) *maxvolid = entry.volumeId[RWVOL]; - if (modified) { + if (modified && doit) { MapNetworkToHost(&entry, &storeEntry); if (createentry) { @@ -5667,7 +5670,7 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart, } } - if (verbose) { + if (verbose && doit) { fprintf(STDOUT, "-- status after --\n"); if (modified) EnumerateEntry(&entry); @@ -5734,13 +5737,15 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) volumeInfo.volEntries_val = (volintInfo *) 0; volumeInfo.volEntries_len = 0; - if (!aserver && flags) { + if (!aserver && (flags & 1)) { /* fprintf(STDERR,"Partition option requires a server option\n"); */ ERROR_EXIT(EINVAL); } /* Turn verbose logging off and do our own verbose logging */ tverbose = verbose; + if (flags & 2) + tverbose = 1; verbose = 0; /* Read the VLDB entry */ @@ -5772,6 +5777,11 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) * Equivalent to a syncserv. */ if (!vcode) { + /* Tell CheckVldb not to update if appropriate */ + if (flags & 2) + mod = 1; + else + mod = 0; code = CheckVldb(&vldbentry, &mod); if (code) { fprintf(STDERR, "Could not process VLDB entry for volume %s\n", @@ -5785,7 +5795,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) /* If aserver is given, we will search for the desired volume on it */ if (aserver) { /* Generate array of partitions on the server that we will check */ - if (!flags) { + if (!(flags & 1)) { code = UV_ListPartitions(aserver, &PartList, &pcnt); if (code) { fprintf(STDERR, @@ -5811,6 +5821,10 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) ERROR_EXIT(code); } } else { + if (flags & 2) + mod = 1; + else + mod = 0; /* Found one, sync it with VLDB entry */ code = CheckVolume(volumeInfo.volEntries_val, aserver, @@ -5861,6 +5875,10 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) ERROR_EXIT(code); } } else { + if (flags & 2) + mod = 1; + else + mod = 0; /* Found one, sync it with VLDB entry */ code = CheckVolume(volumeInfo.volEntries_val, aserver, @@ -5881,7 +5899,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) /* if (aserver) */ /* If verbose output, print a summary of what changed */ - if (tverbose) { + if (tverbose && !(flags & 2)) { fprintf(STDOUT, "-- status after --\n"); code = VLDB_GetEntryByName(avolname, &vldbentry); if (code && (code != VL_NOENT)) { @@ -5963,7 +5981,7 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force) aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); /* Generate array of partitions to check */ - if (!flags) { + if (!(flags & 1)) { code = UV_ListPartitions(aserver, &PartList, &pcnt); if (code) { fprintf(STDERR, @@ -6011,6 +6029,10 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force) fflush(STDOUT); } + if (flags & 2) + modified = 1; + else + modified = 0; code = CheckVolume(vi, aserver, apart, &modified, &maxvolid); if (code) { PrintError("", code); @@ -6041,8 +6063,13 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force) } /* thru all partitions */ - VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries, - failures, modifications); + if (flags & 2) { + VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n", + tentries, failures, modifications); + } else { + VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", + tentries, failures, modifications); + } error_exit: /* Now check if the maxvolid is larger than that stored in the VLDB */ @@ -6275,10 +6302,13 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified) afs_int32 code, error = 0; struct nvldbentry storeEntry; int islocked = 0, mod, modentry, delentry = 0; - int pass = 0; + int pass = 0, doit=1; - if (modified) + if (modified) { + if (*modified == 1) + doit = 0; *modified = 0; + } if (verbose) { fprintf(STDOUT, "_______________________________\n"); fprintf(STDOUT, "\n-- status before -- \n"); @@ -6325,7 +6355,7 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified) code = CheckVldbRWBK(entry, &mod); if (code) ERROR_EXIT(code); - if (mod && (pass == 1)) + if (mod && (pass == 1) && doit) goto retry; if (mod) modentry++; @@ -6334,7 +6364,7 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified) code = CheckVldbRO(entry, &mod); if (code) ERROR_EXIT(code); - if (mod && (pass == 1)) + if (mod && (pass == 1) && doit) goto retry; if (mod) modentry++; @@ -6342,12 +6372,12 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified) /* The VLDB entry has been updated. If it as been modified, then * write the entry back out the the VLDB. */ - if (modentry) { + if (modentry && doit) { if (pass == 1) goto retry; if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS) - && !(entry->flags & RO_EXISTS)) { + && !(entry->flags & RO_EXISTS) && doit) { /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */ code = ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL], @@ -6377,7 +6407,7 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified) islocked = 0; } - if (verbose) { + if (verbose && doit) { fprintf(STDOUT, "-- status after --\n"); if (delentry) fprintf(STDOUT, "\n**entry deleted**\n"); @@ -6421,12 +6451,15 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force) struct nvldbentry *vlentry; afs_int32 si, nsi, j; + if (flags & 2) + verbose = 1; + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); /* Set up attributes to search VLDB */ attributes.server = ntohl(aserver); attributes.Mask = VLLIST_SERVER; - if (flags) { + if ((flags & 1)) { attributes.partition = apart; attributes.Mask |= VLLIST_PARTITION; } @@ -6457,6 +6490,11 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force) VPRINT1("Processing VLDB entry %d ...\n", j + 1); + /* Tell CheckVldb not to update if appropriate */ + if (flags & 2) + modified = 1; + else + modified = 0; code = CheckVldb(vlentry, &modified); if (code) { PrintError("", code); @@ -6483,8 +6521,13 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force) } } - VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries, - failures, modifications); + if (flags & 2) { + VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n", + tentries, failures, modifications); + } else { + VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", + tentries, failures, modifications); + } error_exit: if (aconn)