From 1544243167b0f294f080866710b3f29dec133f02 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Mon, 11 Jan 2010 13:36:32 -0600 Subject: [PATCH] Always check VInitVolumePackage2 return code Some programs were not checking the return code of VInitVolumePackage2. Although some programs do not care so much if we fail to properly init the volume package (SYNC debug tools), at the very least log/print an error, so it doesn't silently fail. Other programs are changed to exit when VInitVolumePackage2 fail, so e.g. salvages don't accidentally cause corruption on 'logging'-mounted UFS partitions. In any case, ensure the return code is always checked anywhere it is called. Change-Id: I164d5920a5ea2dd7e5ed9ad4ccc578e9bdf0db0b Reviewed-on: http://gerrit.openafs.org/1090 Tested-by: Andrew Deason Reviewed-by: Derrick Brashear --- src/tsalvaged/salvsync-debug.c | 8 +++++++- src/vol/fssync-debug.c | 8 +++++++- src/vol/salvaged.c | 13 +++++++++++-- src/vol/salvager.c | 5 ++++- src/vol/test/testpart.c | 5 ++++- src/volser/vol-dump.c | 5 ++++- src/volser/volmain.c | 5 ++++- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/tsalvaged/salvsync-debug.c b/src/tsalvaged/salvsync-debug.c index f3775350e4..b802c58786 100644 --- a/src/tsalvaged/salvsync-debug.c +++ b/src/tsalvaged/salvsync-debug.c @@ -186,7 +186,13 @@ common_prolog(struct cmd_syndesc * as, struct state * state) #endif VOptDefaults(debugUtility, &opts); - VInitVolumePackage2(debugUtility, &opts); + if (VInitVolumePackage2(debugUtility, &opts)) { + /* VInitVolumePackage2 can fail on e.g. partition attachment errors, + * but we don't really care, since all we're doing is trying to use + * SALVSYNC */ + fprintf(stderr, "errors encountered initializing volume package, but " + "trying to continue anyway\n"); + } DInit(1); if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */ diff --git a/src/vol/fssync-debug.c b/src/vol/fssync-debug.c index c746ed0c53..a5414d5496 100644 --- a/src/vol/fssync-debug.c +++ b/src/vol/fssync-debug.c @@ -232,7 +232,13 @@ common_prolog(struct cmd_syndesc * as, struct state * state) #endif VOptDefaults(debugUtility, &opts); - VInitVolumePackage2(debugUtility, &opts); + if (VInitVolumePackage2(debugUtility, &opts)) { + /* VInitVolumePackage2 can fail on e.g. partition attachment errors, + * but we don't really care, since all we're doing is trying to use + * FSSYNC */ + fprintf(stderr, "errors encountered initializing volume package, but " + "trying to continue anyway\n"); + } DInit(1); if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */ diff --git a/src/vol/salvaged.c b/src/vol/salvaged.c index 2dbbc18e01..64680fe579 100644 --- a/src/vol/salvaged.c +++ b/src/vol/salvaged.c @@ -423,7 +423,13 @@ SalvageClient(VolumeId vid, char * pname) VolumePackageOptions opts; VOptDefaults(volumeUtility, &opts); - VInitVolumePackage2(volumeUtility, &opts); + if (VInitVolumePackage2(volumeUtility, &opts)) { + /* VInitVolumePackage2 can fail on e.g. partition attachment errors, + * but we don't really care, since all we're doing is trying to use + * SALVSYNC */ + fprintf(stderr, "errors encountered initializing volume package, but " + "trying to continue anyway\n"); + } SALVSYNC_clientInit(); code = SALVSYNC_SalvageVolume(vid, pname, SALVSYNC_SALVAGE, SALVSYNC_OPERATOR, 0, NULL); @@ -511,7 +517,10 @@ SalvageServer(void) /* initialize things */ VOptDefaults(salvageServer, &opts); - VInitVolumePackage2(salvageServer, &opts); + if (VInitVolumePackage2(salvageServer, &opts)) { + Log("Shutting down: errors encountered initializing volume package\n"); + Exit(1); + } DInit(10); queue_Init(&pending_q); queue_Init(&log_cleanup_queue); diff --git a/src/vol/salvager.c b/src/vol/salvager.c index 093bbac48c..5f305c8902 100644 --- a/src/vol/salvager.c +++ b/src/vol/salvager.c @@ -324,7 +324,10 @@ handleit(struct cmd_syndesc *as, void *arock) } VOptDefaults(pt, &opts); - VInitVolumePackage2(pt, &opts); + if (VInitVolumePackage2(pt, &opts)) { + Log("errors encountered initializing volume package; salvage aborted\n"); + Exit(1); + } DInit(10); #ifdef AFS_NT40_ENV if (myjob.cj_number != NOT_CHILD) { diff --git a/src/vol/test/testpart.c b/src/vol/test/testpart.c index 9044c6c598..dc29b80847 100644 --- a/src/vol/test/testpart.c +++ b/src/vol/test/testpart.c @@ -41,7 +41,10 @@ main(argc, argv) VolumePackageOptions opts; VOptDefaults(1, &opts); - VInitVolumePackage2(1, &opts); + if (VInitVolumePackage2(1, &opts)) { + printf("errors encountered initializing volume package\n"); + exit(-1); + } VPrintDiskStats(); } diff --git a/src/volser/vol-dump.c b/src/volser/vol-dump.c index ae743ad2c9..c53ad37c96 100644 --- a/src/volser/vol-dump.c +++ b/src/volser/vol-dump.c @@ -302,7 +302,10 @@ main(int argc, char **argv) VolumePackageOptions opts; VOptDefaults(volumeUtility, &opts); - VInitVolumePackage2(volumeUtility, &opts); + if (VInitVolumePackage2(volumeUtility, &opts)) { + fprintf(stderr, "errors encountered initializing volume package, but " + "trying to continue anyway\n"); + } ts = cmd_CreateSyntax(NULL, handleit, NULL, "Dump a volume to a 'vos dump' format file without using volserver"); diff --git a/src/volser/volmain.c b/src/volser/volmain.c index 46e8541296..f9024f68ed 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -426,7 +426,10 @@ main(int argc, char **argv) OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH); VOptDefaults(volumeServer, &opts); - VInitVolumePackage2(volumeServer, &opts); + if (VInitVolumePackage2(volumeServer, &opts)) { + Log("Shutting down: errors encountered initializing volume package\n"); + exit(1); + } /* For nuke() */ Lock_Init(&localLock); DInit(40);