Add braces to empty conditional blocks
[openafs.git] / src / volser / vsprocs.c
index 9bd17d8..b879ebc 100644 (file)
@@ -1570,8 +1570,9 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
        fflush(STDOUT);
        if (fscanf(stdin, "%c", &in) < 1)
            in = 0;
-       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
-           ; /* don't care */
+       if (fscanf(stdin, "%c", &lf) < 0) {
+           /* toss away; don't care */
+       }
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -1928,8 +1929,9 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
        fflush(STDOUT);
        if (fscanf(stdin, "%c", &in) < 1)
            in = 0;
-       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
-           ; /* don't care */
+       if (fscanf(stdin, "%c", &lf) < 0) {
+           /* toss away, don't care */
+       }
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -1963,8 +1965,9 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
        fflush(STDOUT);
        if (fscanf(stdin, "%c", &in) < 1)
            in = 0;
-       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
-           ; /* don't care */
+       if (fscanf(stdin, "%c", &lf) < 0) {
+           /* toss away; don't care */
+       }
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -2048,8 +2051,9 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
        fflush(STDOUT);
        if (fscanf(stdin, "%c", &in) < 1)
            in = 0;
-       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
-           ; /* don't care */
+       if (fscanf(stdin, "%c", &lf) < 0) {     /* toss away */
+           /* don't care */
+       }
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -2925,8 +2929,6 @@ UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
        goto bfail;
     }
 
-    VDONE;
-
     /* Will update the vldb below */
 
   bfail:
@@ -3086,8 +3088,6 @@ UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
        }
     }
 
-    VDONE;
-
   bfail:
     if (ttid) {
        code = AFSVolEndTrans(aconn, ttid, &rcode);
@@ -3431,11 +3431,11 @@ PutTrans(afs_int32 *vldbindex, struct replica *replicas,
 /**
  * Release a volume to read-only sites
  *
- * Release volume <afromvol> on <afromserver> <afrompart> to all
- * its RO sites (full release). Unless the previous release was
- * incomplete: in which case we bring the remaining incomplete
- * volumes up to date with the volumes that were released
- * successfully.
+ * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
+ * sites (complete release), unless the previous release was incomplete
+ * or new sites were added without changes to the read-write volume, in
+ * which case we bring the remaining volumes up to date with the volumes
+ * that were previously released successfully.
  *
  * Will create a clone from the RW, then dump the clone out to
  * the remaining replicas. If there is more than 1 RO sites,
@@ -3495,7 +3495,7 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
     int new_sites = 0; /* number of ro sites markes as new */
 
     typedef enum {
-        CR_RECOVER    = 0x0000, /**< not complete: a recovery from a previous failed release */
+        CR_PARTIAL    = 0x0000, /**< just new sites added or recover from a previous failed release */
         CR_FORCED     = 0x0001, /**< complete: forced by caller */
         CR_LAST_OK    = 0x0002, /**< complete: no sites have been marked as new release */
         CR_ALL_NEW    = 0x0004, /**< complete: all sites have been marked as new release */
@@ -3503,7 +3503,7 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
         CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
     } complete_release_t;
 
-    complete_release_t complete_release = CR_RECOVER;
+    complete_release_t complete_release = CR_PARTIAL;
 
     memset(remembertime, 0, sizeof(remembertime));
     memset(&results, 0, sizeof(results));
@@ -3671,8 +3671,13 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
                    "This is a recovery of previously failed release\n");
        } else {
            fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
-           /* Give the reasons for a complete release, except if only CR_LAST_OK. */
-           if (complete_release != CR_LAST_OK) {
+           if (complete_release == CR_LAST_OK) {
+               if (justnewsites) {
+                   tried_justnewsites = 1;
+                   fprintf(STDOUT, "\nThere are new RO sites; we will try to "
+                           "only release to new sites");
+               }
+           } else {
                char *sep = " (";
                if (complete_release & CR_FORCED) {
                    fprintf(STDOUT, "%sforced", sep);
@@ -3696,11 +3701,6 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
                fprintf(STDOUT, ")");
            }
            fprintf(STDOUT, "\n");
-           if (justnewsites) {
-               tried_justnewsites = 1;
-               fprintf(STDOUT, "There are new RO sites; we will try to "
-                       "only release to new sites\n");
-           }
        }
     }
 
@@ -3913,7 +3913,7 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
     if (justnewsites) {
        VPRINT("RW vol has not changed; only releasing to new RO sites\n");
        /* act like this is a completion of a previous release */
-       complete_release = CR_RECOVER;
+       complete_release = CR_PARTIAL;
     } else if (tried_justnewsites) {
        VPRINT("RW vol has changed; releasing to all sites\n");
     }
@@ -4011,11 +4011,16 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
                /* Do a full dump when forced by the caller. */
                VPRINT("This will be a full dump: forced\n");
                thisdate = 0;
-           } else if (!complete_release) {
-               /* If this release is a recovery of a failed release, we can't be
-                * sure the creation date is good, so do a full dump.
-                */
-               VPRINT("This will be a full dump: previous release failed\n");
+           } else if (complete_release == CR_PARTIAL) {
+               if (justnewsites) {
+                   VPRINT("This will be a full dump: read-only volume needs be created for new site\n");
+               } else {
+                   /*
+                    * We cannot be sure the creation date is good since the previous
+                    * release failed, so do a full dump.
+                    */
+                   VPRINT("This will be a full dump: previous release failed\n");
+               }
                thisdate = 0;
            } else if (times[volcount].crtime == 0) {
                /* A full dump is needed for a new read-only volume. */
@@ -4067,7 +4072,7 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
 
        code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
        if (code) {
-           code = ENOENT;
+           error = ENOENT;
            goto rfail;
        }
 
@@ -4426,8 +4431,8 @@ UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
     afs_int32 fromtid = 0, rcode = 0;
     afs_int32 code = 0, error = 0;
     afs_uint32 tmpVol;
-    char vname[64];
     time_t tmv = fromdate;
+    char *volName = NULL;
 
     if (setjmp(env))
        ERROR_EXIT(EPIPE);
@@ -4453,6 +4458,12 @@ UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
           afromvol);
     VEDONE;
 
+    VEPRINT1("Getting the name for volume %u ...", afromvol);
+    code = AFSVolGetName(fromconn, fromtid, &volName);
+    EGOTO1(error_exit, code,
+          "Failed to get the name of the volume %u\n",afromvol);
+    VEDONE;
+
     /* Get a clone id */
     VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
     tmpVol = clonevol;
@@ -4466,10 +4477,9 @@ UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
     /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
     VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
            clonevol);
-    strcpy(vname, "dump-clone-temp");
     tmpVol = clonevol;
     code =
-       AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
+       AFSVolClone(fromconn, fromtid, 0, readonlyVolume, volName, &tmpVol);
     clonevol = tmpVol;
     EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
           afromvol);
@@ -4520,6 +4530,9 @@ UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
     VEDONE;
 
   error_exit:
+    if (volName)
+       free(volName);
+
     /* now delete the clone */
     VEPRINT1("Deleting the cloned volume %u ...", clonevol);
     code = AFSVolDeleteVolume(fromconn, clonetid);
@@ -6947,6 +6960,7 @@ UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
     aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
 
     /* Set up attributes to search VLDB  */
+    memset(&attributes, 0, sizeof(attributes));
     attributes.server = ntohl(aserver);
     attributes.Mask = VLLIST_SERVER;
     if ((flags & 1)) {