Give a default reason in *sync-debug
[openafs.git] / src / tsalvaged / salvsync-debug.c
index f25c89f..3f64b7c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2006, Sine Nomine Associates and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -18,9 +18,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -38,10 +35,13 @@ RCSID
 #include <sys/time.h>
 #endif /* ITIMER_REAL */
 #endif
+
+#include <roken.h>
+
 #include <rx/xdr.h>
 #include <afs/afsint.h>
-#include <afs/assert.h>
-
+#include <afs/afs_assert.h>
+#include <afs/dir.h>
 
 #include <fcntl.h>
 
@@ -53,15 +53,15 @@ RCSID
 #include <afs/afsutil.h>
 #include <afs/fileutil.h>
 
-#include "nfs.h"
-#include "lwp.h"
-#include "lock.h"
-#include "ihandle.h"
-#include "vnode.h"
-#include "volume.h"
-#include "partition.h"
-#include "daemon_com.h"
-#include "salvsync.h"
+#include <afs/nfs.h>
+#include <lwp.h>
+#include <lock.h>
+#include <afs/ihandle.h>
+#include <afs/vnode.h>
+#include <afs/volume.h>
+#include <afs/partition.h>
+#include <afs/daemon_com.h>
+#include <afs/salvsync.h>
 #ifdef AFS_NT40_ENV
 #include <pthread.h>
 #endif
@@ -97,7 +97,6 @@ static int do_salvop(struct state *, afs_int32 command, SYNC_response * res);
 static char * response_code_to_string(afs_int32);
 static char * command_code_to_string(afs_int32);
 static char * reason_code_to_string(afs_int32);
-static char * program_type_to_string(afs_int32);
 static char * state_code_to_string(afs_int32);
 
 
@@ -139,8 +138,6 @@ main(int argc, char **argv)
 {
     struct cmd_syndesc *ts;
     int err = 0;
-    int i;
-    extern char cml_version_number[];
 
     /* Initialize directory paths */
     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
@@ -181,7 +178,8 @@ main(int argc, char **argv)
 static int
 common_prolog(struct cmd_syndesc * as, struct state * state)
 {
-    register struct cmd_item *ti;
+    struct cmd_item *ti;
+    VolumePackageOptions opts;
 
 #ifdef AFS_NT40_ENV
     if (afs_winsockInit() < 0) {
@@ -189,13 +187,22 @@ common_prolog(struct cmd_syndesc * as, struct state * state)
     }
 #endif
 
-    VInitVolumePackage(debugUtility, 1, 1,
-                      DONT_CONNECT_FS, 0);
+    VOptDefaults(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 */
        state->reason = atoi(ti->data);
+    } else {
+       state->reason = SALVSYNC_REASON_WHATEVER;
     }
+
     if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) {       /* -programtype */
        if (!strcmp(ti->data, "fileServer")) {
            programType = fileServer;
@@ -205,6 +212,10 @@ common_prolog(struct cmd_syndesc * as, struct state * state)
            programType = salvager;
        } else if (!strcmp(ti->data, "salvageServer")) {
            programType = salvageServer;
+       } else if (!strcmp(ti->data, "volumeServer")) {
+           programType = volumeServer;
+       } else if (!strcmp(ti->data, "volumeSalvager")) {
+           programType = volumeSalvager;
        } else {
            programType = (ProgramType) atoi(ti->data);
        }
@@ -218,8 +229,7 @@ common_prolog(struct cmd_syndesc * as, struct state * state)
 static int
 common_salv_prolog(struct cmd_syndesc * as, struct state * state)
 {
-    register struct cmd_item *ti;
-    char pname[100], *temp;
+    struct cmd_item *ti;
 
     state->sop = (struct salv_state *) calloc(1, sizeof(struct salv_state));
     assert(state->sop != NULL);
@@ -260,7 +270,7 @@ do_salvop(struct state * state, afs_int32 command, SYNC_response * res)
        hdr = (SALVSYNC_response_hdr *) res->payload.buf;
     }
 
-    fprintf(stderr, "calling SALVSYNC_SalvageVolume with command code %d (%s)\n", 
+    fprintf(stderr, "calling SALVSYNC_SalvageVolume with command code %d (%s)\n",
            command, command_code_to_string(command));
 
     code = SALVSYNC_SalvageVolume(state->sop->volume,
@@ -279,9 +289,9 @@ do_salvop(struct state * state, afs_int32 command, SYNC_response * res)
     }
 
     fprintf(stderr, "SALVSYNC_SalvageVolume returned %d (%s)\n", code, response_code_to_string(code));
-    fprintf(stderr, "protocol response code was %d (%s)\n", 
+    fprintf(stderr, "protocol response code was %d (%s)\n",
            res->hdr.response, response_code_to_string(res->hdr.response));
-    fprintf(stderr, "protocol reason code was %d (%s)\n", 
+    fprintf(stderr, "protocol reason code was %d (%s)\n",
            res->hdr.reason, reason_code_to_string(res->hdr.reason));
 
     printf("state = {\n");
@@ -295,6 +305,8 @@ do_salvop(struct state * state, afs_int32 command, SYNC_response * res)
     printf("}\n");
 
     VDisconnectSALV();
+
+    return 0;
 }
 
 static char *
@@ -358,6 +370,7 @@ reason_code_to_string(afs_int32 reason)
     }
 }
 
+#if 0
 static char *
 program_type_to_string(afs_int32 type)
 {
@@ -374,6 +387,7 @@ program_type_to_string(afs_int32 type)
        return "**UNKNOWN**";
     }
 }
+#endif
 
 static char *
 state_code_to_string(afs_int32 state)