DAFS: allow salvager to detect whether FSYNC server is DAFS
authorDerrick Brashear <shadow@dementia.org>
Wed, 8 Dec 2010 02:23:53 +0000 (21:23 -0500)
committerDerrick Brashear <shadow@dementia.org>
Tue, 22 Mar 2011 11:52:50 +0000 (04:52 -0700)
in order to enable the right commands and print the right errors,
query for DAFS-only FSYNC op.
doesn't use bozo InstanceInfo as it's possible you can run fileserver
outside of bos.

Change-Id: Ib94f7b3a2960cd493f110af4d5dee7e97a6493c9
Reviewed-on: http://gerrit.openafs.org/3486
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/tsalvaged/Makefile.in
src/vol/salvager.c
src/vol/vol-salvage.c
src/vol/vol-salvage.h
src/vol/volume.h

index 9dec8dd..e409f73 100644 (file)
@@ -21,7 +21,7 @@ MODULE_CFLAGS = -DNINTERFACE -DRXDEBUG -DFSSYNC_BUILD_CLIENT \
                -DSALVSYNC_BUILD_SERVER -DSALVSYNC_BUILD_CLIENT \
                -DAFS_DEMAND_ATTACH_FS
 
-SCFLAGS=$(COMMON_CFLAGS) -I.. -DNINTERFACE ${XCFLAGS} ${ARCHFLAGS} -DRXDEBUG -DFSSYNC_BUILD_CLIENT
+SCFLAGS=$(COMMON_CFLAGS) -I.. -DNINTERFACE ${XCFLAGS} ${ARCHFLAGS} -DRXDEBUG -DFSSYNC_BUILD_CLIENT -DAFS_DEMAND_ATTACH_FS
 
 SCCRULE=${MT_CC} ${SCFLAGS} -c $? -o $@
 
index 7da1373..78ad821 100644 (file)
@@ -167,9 +167,11 @@ handleit(struct cmd_syndesc *as, void *arock)
        char *msg =
            "Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!";
 
+#ifndef AFS_NT40_ENV
        if (useSyslog)
            Log(msg);
        else
+#endif
            printf("%s\n", msg);
 
        Exit(0);
@@ -201,7 +203,7 @@ handleit(struct cmd_syndesc *as, void *arock)
        Testing = 1;
     if (as->parms[4].items)    /* -inodes */
        ListInodeOption = 1;
-    if (as->parms[5].items || as->parms[20].items)     /* -force, -f */
+    if (as->parms[5].items || as->parms[21].items)     /* -force, -f */
        ForceSalvage = 1;
     if (as->parms[6].items)    /* -oktozap */
        OKToZap = 1;
@@ -282,23 +284,14 @@ handleit(struct cmd_syndesc *as, void *arock)
        char *msg =
            "Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!";
 
+#ifndef AFS_NT40_ENV
        if (useSyslog)
            Log(msg);
        else
+#endif
            printf("%s\n", msg);
        Exit(0);
     }
-#elif defined(DEMAND_ATTACH_ENABLE)
-    if (seenvol && !as->parms[19].items) {
-       char * msg =
-           "The standalone salvager cannot be run concurrently with a Demand Attach Fileserver.  Please use 'salvageserver -client <partition> <volume id>' to manually schedule volume salvages with the salvageserver (new versions of 'bos salvage' automatically do this for you).  Or, if you insist on using the standalone salvager, add the -forceDAFS flag to your salvager command line.";
-
-       if (useSyslog)
-           Log(msg);
-       else
-           printf("%s\n", msg);
-       Exit(1);
-    }
 #endif
 
     if (get_salvage_lock) {
@@ -331,6 +324,40 @@ handleit(struct cmd_syndesc *as, void *arock)
        Log("errors encountered initializing volume package; salvage aborted\n");
        Exit(1);
     }
+
+    /*
+     * Ok to defer this as Exit will clean up and no real work is done
+     * init'ing volume package
+     */
+    if (seenvol) {
+       char *msg = NULL;
+#ifdef AFS_DEMAND_ATTACH_FS
+       if (!AskDAFS()) {
+           msg =
+               "The DAFS dasalvager cannot be run with a non-DAFS fileserver.  Please use 'salvager'.";
+       }
+       if (!msg && !as->parms[20].items) {
+           msg =
+               "The standalone salvager cannot be run concurrently with a Demand Attach Fileserver.  Please use 'salvageserver -client <partition> <volume id>' to manually schedule volume salvages with the salvageserver (new versions of 'bos salvage' automatically do this for you).  Or, if you insist on using the standalone salvager, add the -forceDAFS flag to your salvager command line.";
+       }
+#else
+       if (AskDAFS()) {
+           msg =
+               "The non-DAFS salvager cannot be run with a Demand Attach Fileserver.  Please use 'salvageserver -client <partition> <volume id>' to manually schedule volume salvages with the salvageserver (new versions of 'bos salvage' automatically do this for you).  Or, if you insist on using the standalone salvager, run dasalvager with the -forceDAFS flag.";
+       }
+#endif
+
+       if (msg) {
+#ifndef AFS_NT40_ENV
+           if (useSyslog)
+               Log("%s", msg);
+           else
+#endif
+               printf("%s\n", msg);
+           Exit(1);
+       }
+    }
+
     DInit(10);
 #ifdef AFS_NT40_ENV
     if (myjob.cj_number != NOT_CHILD) {
@@ -494,11 +521,12 @@ main(int argc, char **argv)
 #ifdef FAST_RESTART
     cmd_AddParm(ts, "-DontSalvage", CMD_FLAG, CMD_OPTIONAL,
                "Don't salvage. This my be set in BosConfig to let the fileserver restart immediately after a crash. Bad volumes will be taken offline");
-#elif defined(DEMAND_ATTACH_ENABLE)
+#elif defined(AFS_DEMAND_ATTACH_FS)
+    cmd_Seek(ts, 20); /* skip DontSalvage */
     cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL,
                "For Demand Attach Fileserver, permit a manual volume salvage outside of the salvageserver");
 #endif /* FAST_RESTART */
-    cmd_Seek(ts, 20);
+    cmd_Seek(ts, 21); /* skip DontSalvage and forceDAFS if needed */
     cmd_AddParm(ts, "-f", CMD_FLAG, CMD_OPTIONAL, "Alias for -force");
     err = cmd_Dispatch(argc, argv);
     Exit(err);
index 0408d83..5fd41bf 100644 (file)
@@ -4322,20 +4322,27 @@ AskOffline(struct SalvInfo *salvinfo, VolumeId volumeId)
        if (code == SYNC_OK) {
            break;
        } else if (code == SYNC_DENIED) {
-#ifdef DEMAND_ATTACH_ENABLE
-           Log("AskOffline:  file server denied offline request; a general salvage may be required.\n");
-#else
-           Log("AskOffline:  file server denied offline request; a general salvage is required.\n");
-#endif
+           if (AskDAFS())
+               Log("AskOffline:  file server denied offline request; a general salvage may be required.\n");
+           else
+               Log("AskOffline:  file server denied offline request; a general salvage is required.\n");
            Abort("Salvage aborted\n");
        } else if (code == SYNC_BAD_COMMAND) {
            Log("AskOffline:  fssync protocol mismatch (bad command word '%d'); salvage aborting.\n",
                FSYNC_VOL_OFF);
-#ifdef DEMAND_ATTACH_ENABLE
-           Log("AskOffline:  please make sure fileserver, volserver, salvageserver and salvager binaries are same version.\n");
+           if (AskDAFS()) {
+#ifdef AFS_DEMAND_ATTACH_FS
+               Log("AskOffline:  please make sure dafileserver, davolserver, salvageserver and dasalvager binaries are same version.\n");
+#else
+               Log("AskOffline:  fileserver is DAFS but we are not.\n");
+#endif
+           } else {
+#ifdef AFS_DEMAND_ATTACH_FS
+               Log("AskOffline:  fileserver is not DAFS but we are.\n");
 #else
-           Log("AskOffline:  please make sure fileserver, volserver and salvager binaries are same version.\n");
+               Log("AskOffline:  please make sure fileserver, volserver and salvager binaries are same version.\n");
 #endif
+           }
            Abort("Salvage aborted\n");
        } else if (i < 2) {
            /* try it again */
@@ -4350,6 +4357,50 @@ AskOffline(struct SalvInfo *salvinfo, VolumeId volumeId)
     }
 }
 
+/* don't want to pass around state; remember it here */
+static int isDAFS = -1;
+int
+AskDAFS(void)
+{
+    afs_int32 code, i, ret = 0;
+    SYNC_response res;
+
+    /* we don't care if we race. the answer shouldn't change */
+    if (isDAFS != -1)
+       return isDAFS;
+
+    memset(&res, 0, sizeof(res));
+
+    for (i = 0; i < 3; i++) {
+       code = FSYNC_VolOp(1, NULL,
+                          FSYNC_VOL_QUERY_VOP, FSYNC_SALVAGE, &res);
+
+       if (code == SYNC_OK) {
+           ret = 1;
+           break;
+       } else if (code == SYNC_DENIED) {
+           ret = 1;
+           break;
+       } else if (code == SYNC_BAD_COMMAND) {
+           ret = 0;
+           break;
+       } else if (code == SYNC_FAILED) {
+           if (res.hdr.reason == FSYNC_UNKNOWN_VOLID)
+               ret = 1;
+           else
+               ret = 0;
+       } else if (i < 2) {
+           /* try it again */
+           Log("AskDAFS:  request to query fileserver failed; trying again...\n");
+           FSYNC_clientFinis();
+           FSYNC_clientInit();
+       }
+    }
+
+    isDAFS = ret;
+    return ret;
+}
+
 void
 AskOnline(struct SalvInfo *salvinfo, VolumeId volumeId)
 {
@@ -4366,11 +4417,7 @@ AskOnline(struct SalvInfo *salvinfo, VolumeId volumeId)
        } else if (code == SYNC_BAD_COMMAND) {
            Log("AskOnline:  fssync protocol mismatch (bad command word '%d')\n",
                FSYNC_VOL_ON);
-#ifdef DEMAND_ATTACH_ENABLE
-           Log("AskOnline:  please make sure fileserver, volserver, salvageserver and salvager binaries are same version.\n");
-#else
-           Log("AskOnline:  please make sure fileserver, volserver and salvager binaries are same version.\n");
-#endif
+           Log("AskOnline:  please make sure file server binaries are same version.\n");
            break;
        } else if (i < 2) {
            /* try it again */
@@ -4397,11 +4444,19 @@ AskDelete(struct SalvInfo *salvinfo, VolumeId volumeId)
        } else if (code == SYNC_BAD_COMMAND) {
            Log("AskOnline:  fssync protocol mismatch (bad command word '%d')\n",
                FSYNC_VOL_DONE);
-#ifdef DEMAND_ATTACH_ENABLE
-           Log("AskOnline:  please make sure fileserver, volserver, salvageserver and salvager binaries are same version.\n");
+           if (AskDAFS()) {
+#ifdef AFS_DEMAND_ATTACH_FS
+               Log("AskOnline:  please make sure dafileserver, davolserver, salvageserver and dasalvager binaries are same version.\n");
 #else
-           Log("AskOnline:  please make sure fileserver, volserver and salvager binaries are same version.\n");
+               Log("AskOnline:  fileserver is DAFS but we are not.\n");
 #endif
+           } else {
+#ifdef AFS_DEMAND_ATTACH_FS
+               Log("AskOnline:  fileserver is not DAFS but we are.\n");
+#else
+               Log("AskOnline:  please make sure fileserver, volserver and salvager binaries are same version.\n");
+#endif
+           }
            break;
        } else if (i < 2) {
            /* try it again */
index b6babab..3f05900 100644 (file)
@@ -193,6 +193,7 @@ extern void Exit(int code) AFS_NORETURN;
 extern int Fork(void);
 extern int Wait(char *prog);
 extern char *ToString(const char *s);
+extern int AskDAFS(void);
 extern void AskOffline(struct SalvInfo *salvinfo, VolumeId volumeId);
 extern void AskOnline(struct SalvInfo *salvinfo, VolumeId volumeId);
 extern void AskDelete(struct SalvInfo *salvinfo, VolumeId volumeId);
index e4dad3c..20694c5 100644 (file)
@@ -101,6 +101,8 @@ extern pthread_t vol_glock_holder;
 #define VTRANS_LOCK MUTEX_ENTER(&vol_trans_mutex)
 #define VTRANS_UNLOCK MUTEX_EXIT(&vol_trans_mutex)
 #else /* AFS_PTHREAD_ENV */
+#define VOL_CV_WAIT(cv)
+#define VOL_CV_TIMEDWAIT(cv, ts, to)
 #define VOL_LOCK
 #define VOL_UNLOCK
 #define VSALVSYNC_LOCK