sbin/hammer: Partly bring back removed braces from 52e2f1b5
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 10 Apr 2017 17:20:40 +0000 (20:20 +0300)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 10 Apr 2017 21:42:16 +0000 (00:42 +0300)
based on comments from dillon@.

(dillon) three types, yah.  (1) multi-line condition in if(), (2) if TRUE or FALSE body spans more than one line, put braces around both
(dillon) (including if a comment is part of the body)

19 files changed:
sbin/hammer/cache.c
sbin/hammer/cmd_blockmap.c
sbin/hammer/cmd_cleanup.c
sbin/hammer/cmd_config.c
sbin/hammer/cmd_dedup.c
sbin/hammer/cmd_history.c
sbin/hammer/cmd_mirror.c
sbin/hammer/cmd_pfs.c
sbin/hammer/cmd_recover.c
sbin/hammer/cmd_show.c
sbin/hammer/cmd_snapshot.c
sbin/hammer/cmd_softprune.c
sbin/hammer/cmd_strip.c
sbin/hammer/cmd_version.c
sbin/hammer/cmd_volume.c
sbin/hammer/cycle.c
sbin/hammer/hammer.c
sbin/hammer/misc.c
sbin/hammer/ondisk.c

index e1f7bdd..003fd21 100644 (file)
@@ -109,7 +109,7 @@ hammer_cache_flush(void)
        struct cache_info *first = NULL;
        int count = 0;
 
-       if (CacheUse >= CacheMax)
+       if (CacheUse >= CacheMax) {
                while ((cache = TAILQ_FIRST(&CacheList)) != NULL) {
                        if (cache == first)
                                break; /* seen this ref'd before */
@@ -133,5 +133,6 @@ hammer_cache_flush(void)
                        if (CacheUse < CacheMax / 2)
                                break;
                }
+       }
 }
 
index 2be3fd5..4cf5125 100644 (file)
@@ -135,8 +135,9 @@ dump_blockmap(int zone)
                        ++num_bad_layer1;
                }
                if (xerr == ' ' &&
-                   layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL)
+                   layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL) {
                        continue;
+               }
                printf("%c layer1 %016jx @%016jx blocks-free %jd\n",
                        xerr,
                        (uintmax_t)phys_offset,
@@ -171,17 +172,19 @@ dump_blockmap(int zone)
 
                        if (VerboseOpt < 2 &&
                            xerr == ' ' && aerr == ' ' && ferr == ' ' &&
-                           layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX)
+                           layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX) {
                                break;
+                       }
                        printf("%c%c%c     %016jx zone=%-2d ",
                                xerr, aerr, ferr, (uintmax_t)zone_offset, layer2->zone);
-                       if (VerboseOpt)
+                       if (VerboseOpt) {
                                printf("vol=%-3d L1#=%-6d L2#=%-6d L1=%-7lu L2=%-7lu ",
                                        HAMMER_VOL_DECODE(zone_offset),
                                        HAMMER_BLOCKMAP_LAYER1_INDEX(zone_offset),
                                        HAMMER_BLOCKMAP_LAYER2_INDEX(zone_offset),
                                        HAMMER_BLOCKMAP_LAYER1_OFFSET(zone_offset),
                                        HAMMER_BLOCKMAP_LAYER2_OFFSET(zone_offset));
+                       }
                        printf("app=%-7d free=%-7d",
                                layer2->append_off,
                                layer2->bytes_free);
@@ -570,10 +573,11 @@ dump_collect(collect_t collect, struct zone_stat *stats)
                if (track2->entry_crc == 0)
                        continue;
 
-               if (DebugOpt)
+               if (DebugOpt) {
                        assert((layer2->zone == HAMMER_ZONE_UNDO_INDEX) ||
                                (layer2->zone == HAMMER_ZONE_FREEMAP_INDEX) ||
                                hammer_is_index_record(layer2->zone));
+               }
                if (stats)
                        hammer_add_zone_stat_layer2(stats, layer2);
 
index 91f43ef..5b76680 100644 (file)
@@ -113,7 +113,7 @@ hammer_cmd_cleanup(char **av, int ac)
        tzset();
        if (ac == 0) {
                mntsize = getmntinfo(&stfsbuf, MNT_NOWAIT);
-               if (mntsize > 0)
+               if (mntsize > 0) {
                        for (i=0; i < mntsize; i++) {
                                /*
                                 * We will cleanup in the case fstype is hammer.
@@ -131,6 +131,7 @@ hammer_cmd_cleanup(char **av, int ac)
                                        do_cleanup(path);
                                }
                        }
+               }
        } else {
                while (ac) {
                        do_cleanup(*av);
@@ -198,21 +199,24 @@ do_cleanup(const char *path)
        HammerVersion = version.cur_version;
 
        bzero(&config, sizeof(config));
-       if (version.cur_version >= 3)
+       if (version.cur_version >= 3) {
                if (ioctl(fd, HAMMERIOC_GET_CONFIG, &config) == 0 &&
-                   config.head.error == 0)
+                   config.head.error == 0) {
                        new_config = 1;
+               }
+       }
 
        /*
         * Make sure we have not already handled this PFS.  Several nullfs
         * mounts might alias the same PFS.
         */
-       for (didpfs = FirstPFS; didpfs; didpfs = didpfs->next)
+       for (didpfs = FirstPFS; didpfs; didpfs = didpfs->next) {
                if (bcmp(&didpfs->uuid, &mrec_tmp.pfs.pfsd.unique_uuid, sizeof(uuid_t)) == 0) {
                        printf(" PFS#%d already handled\n", pfs.pfs_id);
                        close(fd);
                        return;
                }
+       }
        didpfs = malloc(sizeof(*didpfs));
        didpfs->next = FirstPFS;
        FirstPFS = didpfs;
@@ -286,7 +290,7 @@ do_cleanup(const char *path)
                /*
                 * Create missing snapshots directory for HAMMER VERSION < 3
                 */
-               if (stat(snapshots_path, &st) < 0)
+               if (stat(snapshots_path, &st) < 0) {
                        if (mkdir(snapshots_path, 0755) != 0) {
                                free(snapshots_path);
                                printf(" unable to create snapshot dir \"%s\": %s\n",
@@ -294,6 +298,7 @@ do_cleanup(const char *path)
                                close(fd);
                                return;
                        }
+               }
 
                /*
                 *  Create missing config file for HAMMER VERSION < 3
@@ -450,12 +455,13 @@ do_cleanup(const char *path)
                        printf("disabled\n");
                } else if (strcmp(cmd, "prune") == 0) {
                        if (check_period(snapshots_path, cmd, arg1, &savet)) {
-                               if (prune_warning)
+                               if (prune_warning) {
                                        printf("run - WARNING snapshot "
                                               "softlinks present "
                                               "but snapshots disabled\n");
-                               else
+                               } else {
                                        printf("run\n");
+                               }
                                r = cleanup_prune(path, snapshots_path,
                                              arg1, arg2, snapshots_disabled);
                        } else {
@@ -518,12 +524,13 @@ do_cleanup(const char *path)
         * Add new rebalance feature if the config doesn't have it.
         * (old style config only).
         */
-       if (new_config == 0 && found_rebal == 0)
+       if (new_config == 0 && found_rebal == 0) {
                if ((fp = fopen(config_path, "r+")) != NULL) {
                        fseek(fp, 0L, 2);
                        fprintf(fp, "rebalance 1d 5m\n");
                        fclose(fp);
                }
+       }
 
        /*
         * Cleanup, and delay a little
@@ -544,10 +551,11 @@ config_init(const char *path, struct hammer_ioc_config *config)
 
        if (strcmp(path, "/tmp") == 0 ||
            strcmp(path, "/var/tmp") == 0 ||
-           strcmp(path, "/usr/obj") == 0)
+           strcmp(path, "/usr/obj") == 0) {
                snapshots = "snapshots 0d 0d\n";
-       else
+       } else {
                snapshots = "snapshots 1d 60d\n";
+       }
        bzero(config->config.text, sizeof(config->config.text));
        snprintf(config->config.text, sizeof(config->config.text) - 1, "%s%s",
                snapshots,
@@ -654,8 +662,9 @@ migrate_one_snapshot(int fd, const char *fpath,
                bzero(linkbuf, sizeof(linkbuf));
                if (readlink(fpath, linkbuf, sizeof(linkbuf) - 1) > 0 &&
                    (ptr = strrchr(linkbuf, '@')) != NULL &&
-                   ptr > linkbuf && ptr[-1] == '@')
+                   ptr > linkbuf && ptr[-1] == '@') {
                        tid = strtoull(ptr + 1, NULL, 16);
+               }
                if (t != (time_t)-1 && tid != (hammer_tid_t)(int64_t)-1) {
                        snap = &snapshot->snaps[snapshot->count];
                        bzero(snap, sizeof(*snap));
@@ -867,9 +876,11 @@ check_softlinks(int fd, int new_config, const char *snapshots_path)
 
                bzero(&snapshot, sizeof(snapshot));
                do {
-                       if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0)
+                       if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0) {
                                err(2, "hammer cleanup: check_softlink "
                                        "snapshot error");
+                               /* not reached */
+                       }
                        res += snapshot.count;
                } while (snapshot.head.error == 0 && snapshot.count);
        }
@@ -900,9 +911,10 @@ cleanup_softlinks(int fd, int new_config,
                        if (lstat(fpath, &st) == 0 && S_ISLNK(st.st_mode) &&
                            (anylink || strncmp(den->d_name, "snap-", 5) == 0)) {
                                if (check_expired(den->d_name, arg2)) {
-                                       if (VerboseOpt)
+                                       if (VerboseOpt) {
                                                printf("    expire %s\n",
                                                        fpath);
+                                       }
                                        remove(fpath);
                                }
                        }
@@ -928,16 +940,19 @@ cleanup_softlinks(int fd, int new_config,
                bzero(&snapshot, sizeof(snapshot));
                bzero(&dsnapshot, sizeof(dsnapshot));
                do {
-                       if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0)
+                       if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0) {
                                err(2, "hammer cleanup: check_softlink "
                                        "snapshot error");
+                               /* not reached */
+                       }
                        for (i = 0; i < snapshot.count; ++i) {
                                snap = &snapshot.snaps[i];
                                t = snap->ts / 1000000ULL;
                                dt = time(NULL) - t;
-                               if ((int)dt > arg2 || snap->tid == 0)
+                               if ((int)dt > arg2 || snap->tid == 0) {
                                        dsnapshot.snaps[dsnapshot.count++] =
                                                *snap;
+                               }
                                if ((int)dt > arg2 && VerboseOpt) {
                                        tp = localtime(&t);
                                        strftime(snapts, sizeof(snapts),
@@ -1057,17 +1072,18 @@ cleanup_prune(const char *path, const char *snapshots_path,
         * If snapshots have been disabled run prune-everything instead
         * of prune.
         */
-       if (snapshots_disabled && arg2)
+       if (snapshots_disabled && arg2) {
                runcmd(NULL,
                       "hammer -c %s/.prune.cycle -t %d prune-everything %s",
                       snapshots_path, arg2, path);
-       else if (snapshots_disabled)
+       } else if (snapshots_disabled) {
                runcmd(NULL, "hammer prune-everything %s", path);
-       else if (arg2)
+       } else if (arg2) {
                runcmd(NULL, "hammer -c %s/.prune.cycle -t %d prune %s",
                        snapshots_path, arg2, path_or_snapshots_path);
-       else
+       } else {
                runcmd(NULL, "hammer prune %s", path_or_snapshots_path);
+       }
        return(0);
 }
 
index 1f347c2..c1e308b 100644 (file)
@@ -57,33 +57,39 @@ hammer_cmd_config(char **av, int ac)
        bzero(&config, sizeof(config));
        if (ac == 0) {
                config_get(".", &config);
-               if (config.head.error == 0)
+               if (config.head.error == 0) {
                        printf("%s", config.config.text);
-               else
+               } else {
                        errx(2, "hammer config: no configuration found");
+                       /* not reached */
+               }
                return;
        }
        dirpath = av[0];
        if (ac == 1) {
                config_get(dirpath, &config);
-               if (config.head.error == 0)
+               if (config.head.error == 0) {
                        printf("%s", config.config.text);
-               else
+               } else {
                        errx(2, "hammer config: no configuration found");
+                       /* not reached */
+               }
                return;
        }
        config_get(dirpath, &config);   /* ignore errors */
        config.head.error = 0;
 
        fd = open(av[1], O_RDONLY);
-       if (fd < 0)
+       if (fd < 0) {
                err(2, "hammer config: %s", av[1]);
-
+               /* not reached */
+       }
        n = read(fd, config.config.text, sizeof(config.config.text) - 1);
-       if (n == sizeof(config.config.text) - 1)
+       if (n == sizeof(config.config.text) - 1) {
                err(2, "hammer config: config file too big, limit %zu bytes",
                    sizeof(config.config.text) - 1);
-
+               /* not reached */
+       }
        bzero(config.config.text + n, sizeof(config.config.text) - n);
        config_set(dirpath, &config);
        close(fd);
@@ -104,8 +110,10 @@ hammer_cmd_viconfig(char **av, int ac)
        ssize_t n;
        int fd;
 
-       if (ac > 1)
+       if (ac > 1) {
                errx(1, "hammer viconfig: 0 or 1 argument (<fs>) only");
+               /* not reached */
+       }
        if (ac == 0)
                dirpath = ".";
        else
@@ -125,9 +133,11 @@ hammer_cmd_viconfig(char **av, int ac)
                         "#recopy    30d 10m\n");
                config.head.error = 0;
        }
-       if (config.head.error)
+       if (config.head.error) {
                errx(2, "hammer viconfig: read config failed error: %s",
                        strerror(config.head.error));
+               /* not reached */
+       }
 
        /*
         * Edit a temporary file and write back if it was modified.
@@ -174,10 +184,11 @@ hammer_cmd_viconfig(char **av, int ac)
        n = read(fd, config.config.text, sizeof(config.config.text) - 1);
        if (n < 0)
                err(2, "hammer viconfig: unable to read %s", path);
-       if (n == sizeof(config.config.text) - 1)
+       if (n == sizeof(config.config.text) - 1) {
                err(2, "hammer config: config file too big, limit %zu bytes",
                    sizeof(config.config.text) - 1);
-
+               /* not reached */
+       }
        bzero(config.config.text + n, sizeof(config.config.text) - n);
        config_set(dirpath, &config);
        free(editor);
index 022f1b2..c18ac38 100644 (file)
@@ -519,7 +519,7 @@ process_btree_elm(hammer_btree_leaf_elm_t scan_leaf, int flags)
                        de = RB_MAX(dedup_entry_rb_tree, &dedup_tree);
                        if (de == NULL || de->leaf.data_crc < DedupCrcEnd)
                                break;
-                       if (de->flags & HAMMER_DEDUP_ENTRY_FICTITIOUS)
+                       if (de->flags & HAMMER_DEDUP_ENTRY_FICTITIOUS) {
                                while ((sha_de = RB_ROOT(&de->u.fict_root)) !=
                                       NULL) {
                                        RB_REMOVE(sha_dedup_entry_rb_tree,
@@ -527,6 +527,7 @@ process_btree_elm(hammer_btree_leaf_elm_t scan_leaf, int flags)
                                        MemoryUse -= sizeof(*sha_de);
                                        free(sha_de);
                                }
+                       }
                        RB_REMOVE(dedup_entry_rb_tree, &dedup_tree, de);
                        MemoryUse -= sizeof(*de);
                        free(de);
@@ -563,7 +564,7 @@ process_btree_elm(hammer_btree_leaf_elm_t scan_leaf, int flags)
                 * data_offset/data_len in the SHA elements we already have
                 * before reading the data block and generating a new SHA.
                 */
-               RB_FOREACH(sha_de, sha_dedup_entry_rb_tree, &de->u.fict_root)
+               RB_FOREACH(sha_de, sha_dedup_entry_rb_tree, &de->u.fict_root) {
                        if (sha_de->leaf.data_offset ==
                                                scan_leaf->data_offset &&
                            sha_de->leaf.data_len == scan_leaf->data_len) {
@@ -571,6 +572,7 @@ process_btree_elm(hammer_btree_leaf_elm_t scan_leaf, int flags)
                                        SHA256_DIGEST_LENGTH);
                                break;
                        }
+               }
 
                /*
                 * Entry in CRC tree is fictitious, so we already had problems
@@ -869,10 +871,11 @@ scan_pfs(char *filesystem, scan_pfs_cb_t func, const char *id)
        hammer_key_beg_init(&mirror.key_beg);
        hammer_get_cycle(&mirror.key_beg, &mirror.tid_beg);
 
-       if (mirror.key_beg.obj_id != (int64_t)HAMMER_MIN_OBJID)
+       if (mirror.key_beg.obj_id != (int64_t)HAMMER_MIN_OBJID) {
                if (VerboseOpt)
                        fprintf(stderr, "%s: mirror-read: Resuming at object %016jx\n",
                            id, (uintmax_t)mirror.key_beg.obj_id);
+       }
 
        hammer_key_end_init(&mirror.key_end);
 
@@ -927,8 +930,9 @@ scan_pfs(char *filesystem, scan_pfs_cb_t func, const char *id)
                                        if (elm.data_crc < DedupCrcStart)
                                                continue;
                                        if (DedupCrcEnd &&
-                                           elm.data_crc >= DedupCrcEnd)
+                                           elm.data_crc >= DedupCrcEnd) {
                                                continue;
+                                       }
                                }
                                func(&elm, 0);
                        }
@@ -984,11 +988,12 @@ dump_simulated_dedup(void)
        struct sim_dedup_entry *sim_de;
 
        printf("=== Dumping simulated dedup entries:\n");
-       RB_FOREACH(sim_de, sim_dedup_entry_rb_tree, &sim_dedup_tree)
+       RB_FOREACH(sim_de, sim_dedup_entry_rb_tree, &sim_dedup_tree) {
                printf("\tcrc=%08x cnt=%ju size=%ju\n",
                        sim_de->crc,
                        (intmax_t)sim_de->ref_blks,
                        (intmax_t)sim_de->ref_size);
+       }
        printf("end of dump ===\n");
 }
 
index d20ab65..289e3fa 100644 (file)
@@ -117,12 +117,13 @@ hammer_do_history(const char *path, off_t off, long len)
                        printf("    %016jx %s",
                               (uintmax_t)hist.hist_ary[i].tid,
                               timestr32(hist.hist_ary[i].time32));
-                       if (off >= 0)
+                       if (off >= 0) {
                                if (VerboseOpt) {
                                        printf(" '");
                                        dumpat(hist_path, off, len);
                                        printf("'");
                                }
+                       }
                        printf("\n");
                        free(hist_path);
                }
index fd7c133..ec74f1e 100644 (file)
@@ -193,9 +193,10 @@ again:
         *     now picking it up again.  Do another histogram.
         */
 #if 0
-       if (streaming && histogram && histindex == histend)
+       if (streaming && histogram && histindex == histend) {
                if (mirror.tid_end - mirror.tid_beg > BULK_MINIMUM)
                        histogram = 0;
+       }
 #endif
 
        /*
@@ -257,9 +258,10 @@ again:
                fprintf(stderr, "\n");
                fflush(stderr);
        }
-       if (mirror.key_beg.obj_id != (int64_t)HAMMER_MIN_OBJID)
+       if (mirror.key_beg.obj_id != (int64_t)HAMMER_MIN_OBJID) {
                fprintf(stderr, "Mirror-read: Resuming at object %016jx\n",
                        (uintmax_t)mirror.key_beg.obj_id);
+       }
 
        /*
         * Nothing to do if begin equals end.
@@ -296,11 +298,12 @@ again:
                                filesystem, mirror.head.error);
                }
                if (mirror.count) {
-                       if (BandwidthOpt)
+                       if (BandwidthOpt) {
                                n = writebw(1, mirror.ubuf, mirror.count,
                                            &bwcount, &bwtv);
-                       else
+                       } else {
                                n = write(1, mirror.ubuf, mirror.count);
+                       }
                        if (n != mirror.count) {
                                score_printf(LINE3,
                                             "Mirror-read %s failed: "
@@ -361,12 +364,13 @@ done:
         * Write out the termination sync record - only if not interrupted
         */
        if (interrupted == 0) {
-               if (didwork)
+               if (didwork) {
                        write_mrecord(1, HAMMER_MREC_TYPE_SYNC,
                                      &mrec_tmp, sizeof(mrec_tmp.sync));
-               else
+               } else {
                        write_mrecord(1, HAMMER_MREC_TYPE_IDLE,
                                      &mrec_tmp, sizeof(mrec_tmp.sync));
+               }
        }
 
        /*
@@ -378,9 +382,10 @@ done:
                mrec = read_mrecord(0, &error, &pickup);
                if (mrec == NULL ||
                    mrec->head.type != HAMMER_MREC_TYPE_UPDATE ||
-                   mrec->head.rec_size != sizeof(mrec->update))
+                   mrec->head.rec_size != sizeof(mrec->update)) {
                        errx(1, "mirror_read: Did not get final "
                                "acknowledgement packet from target");
+               }
                if (interrupted) {
                        if (CyclePath) {
                                hammer_set_cycle(&mirror.key_cur,
@@ -415,14 +420,16 @@ done:
                 * way if we get interrupted a restart doesn't have to
                 * start from scratch.
                 */
-               if (streaming && histogram)
+               if (streaming && histogram) {
                        if (histindex != histmax) {
                                if (VerboseOpt && VerboseOpt < 2 &&
-                                   streaming >= 0)
+                                   streaming >= 0) {
                                        fprintf(stderr, " (bulk incremental)");
+                               }
                                relpfs(fd, &pfs);
                                goto again;
                        }
+               }
 
                if (VerboseOpt && streaming >= 0) {
                        fprintf(stderr, " W");
@@ -512,9 +519,10 @@ generate_histogram(int fd, const char *filesystem,
        tid_end = mirror.tid_end;
        mirror.head.flags |= HAMMER_IOC_MIRROR_NODATA;
 
-       if (*histogram_ary == NULL)
+       if (*histogram_ary == NULL) {
                *histogram_ary = malloc(sizeof(struct histogram) *
                                        (HIST_COUNT + 2));
+       }
        if (tid_beg >= tid_end)
                return(0);
 
@@ -597,9 +605,10 @@ generate_histogram(int fd, const char *filesystem,
                        if (tid && tid >= tid_beg && tid <= tid_end) {
                                len = HAMMER_HEAD_DOALIGN(mrec->head.rec_size);
                                if (mrec->head.type ==
-                                   HAMMER_MREC_TYPE_REC_NODATA)
+                                   HAMMER_MREC_TYPE_REC_NODATA) {
                                        len += HAMMER_HEAD_DOALIGN(
                                                    mrec->rec.leaf.data_len);
+                               }
                                i = (tid - tid_beg) * HIST_COUNT /
                                    (tid_end - tid_beg);
                                tidx = tid_beg + i * (tid_end - tid_beg) /
@@ -844,11 +853,12 @@ again:
                        errx(1, "Mirror-write %s fatal error %d",
                                filesystem, mirror.head.error);
 #if 0
-               if (mirror.head.flags & HAMMER_IOC_HEAD_INTR)
+               if (mirror.head.flags & HAMMER_IOC_HEAD_INTR) {
                        errx(1, "Mirror-write %s interrupted by timer at"
                                " %016llx",
                                filesystem,
                                mirror.key_cur.obj_id);
+               }
 #endif
        }
 
@@ -868,10 +878,11 @@ again:
        if (mrec == NULL ||
            (mrec->head.type != HAMMER_MREC_TYPE_SYNC &&
             mrec->head.type != HAMMER_MREC_TYPE_IDLE) ||
-           mrec->head.rec_size != sizeof(mrec->sync))
+           mrec->head.rec_size != sizeof(mrec->sync)) {
                errx(1, "Mirror-write %s: Did not get termination "
                        "sync record, or rec_size is wrong rt=%d",
                        filesystem, (mrec ? (int)mrec->head.type : -1));
+       }
 
        /*
         * Update the PFS info on the target so the user has visibility
@@ -884,9 +895,10 @@ again:
                synctid.op = HAMMER_SYNCTID_SYNC2;
                ioctl(fd, HAMMERIOC_SYNCTID, &synctid);
 
-               if (VerboseOpt >= 2)
+               if (VerboseOpt >= 2) {
                        fprintf(stderr, "Mirror-write %s: succeeded\n",
                                filesystem);
+               }
        }
 
        free(mrec);
@@ -971,8 +983,9 @@ again:
                                        mrec->rec.leaf.base.rec_type,
                                        mrec->rec.leaf.base.obj_type);
                                if (mrec->head.type ==
-                                   HAMMER_MREC_TYPE_REC_BADCRC)
+                                   HAMMER_MREC_TYPE_REC_BADCRC) {
                                        printf(" (BAD CRC)");
+                               }
                                printf("\n");
                                printf("       tids %016jx:%016jx data=%d\n",
                                    (uintmax_t)mrec->rec.leaf.base.create_tid,
@@ -1016,9 +1029,10 @@ again:
        mrec = read_mrecord(0, &error, &pickup);
        if (mrec == NULL ||
            (mrec->head.type != HAMMER_MREC_TYPE_SYNC &&
-            mrec->head.type != HAMMER_MREC_TYPE_IDLE))
+            mrec->head.type != HAMMER_MREC_TYPE_IDLE)) {
                fprintf(stderr, "Mirror-dump: Did not get termination "
                                "sync record\n");
+       }
        free(mrec);
 
        /*
@@ -1279,8 +1293,9 @@ read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
                if (type != HAMMER_MREC_TYPE_PFSD &&
                    type != HAMMER_MREC_TYPE_REC &&
                    type != HAMMER_MREC_TYPE_SKIP &&
-                   type != HAMMER_MREC_TYPE_PASS)
+                   type != HAMMER_MREC_TYPE_PASS) {
                        break;
+               }
 
                /*
                 * Read the remainder and clear the pickup signature.
@@ -1314,9 +1329,10 @@ read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
 
                if (type == HAMMER_MREC_TYPE_REC) {
                        if (mrec->head.rec_size <
-                           sizeof(mrec->rec) + mrec->rec.leaf.data_len)
+                           sizeof(mrec->rec) + mrec->rec.leaf.data_len) {
                                errx(1, "read_mrecords: malformed record on "
                                        "pipe, illegal element data_len");
+                       }
                        if (mrec->rec.leaf.data_len &&
                            mrec->rec.leaf.data_offset &&
                            hammer_crc_test_leaf(HammerVersion, &mrec->rec + 1, &mrec->rec.leaf) == 0) {
@@ -1660,8 +1676,9 @@ hammer_check_restrict(const char *filesystem)
        while (filesystem[rlen]) {
                if (atslash &&
                    filesystem[rlen] == '.' &&
-                   filesystem[rlen+1] == '.')
+                   filesystem[rlen+1] == '.') {
                        errx(1, "hammer-remote: '..' not allowed");
+               }
                if (filesystem[rlen] == '/')
                        atslash = 1;
                else
index e4f623d..bd97043 100644 (file)
@@ -391,19 +391,21 @@ hammer_cmd_pseudofs_upgrade(char **av, int ac)
                pseudofs_usage(1);
        fd = getpfs(&pfs, av[0]);
 
-       if (pfs.pfs_id == HAMMER_ROOT_PFSID)
+       if (pfs.pfs_id == HAMMER_ROOT_PFSID) {
                errx(1, "You cannot upgrade PFS#%d"
                        " (It should already be a master)",
                        HAMMER_ROOT_PFSID);
-       else if (hammer_is_pfs_master(pfs.ondisk))
+       } else if (hammer_is_pfs_master(pfs.ondisk)) {
                errx(1, "It is already a master");
+       }
 
-       if (ioctl(fd, HAMMERIOC_UPG_PSEUDOFS, &pfs) == 0)
+       if (ioctl(fd, HAMMERIOC_UPG_PSEUDOFS, &pfs) == 0) {
                printf("pfs-upgrade of PFS#%d (%s) succeeded\n",
                        pfs.pfs_id, pfs.ondisk->label);
-       else
+       } else {
                err(1, "pfs-upgrade of PFS#%d (%s) failed",
                        pfs.pfs_id, pfs.ondisk->label);
+       }
        relpfs(fd, &pfs);
 }
 
@@ -422,12 +424,13 @@ hammer_cmd_pseudofs_downgrade(char **av, int ac)
        else if (hammer_is_pfs_slave(pfs.ondisk))
                errx(1, "It is already a slave");
 
-       if (ioctl(fd, HAMMERIOC_DGD_PSEUDOFS, &pfs) == 0)
+       if (ioctl(fd, HAMMERIOC_DGD_PSEUDOFS, &pfs) == 0) {
                printf("pfs-downgrade of PFS#%d (%s) succeeded\n",
                        pfs.pfs_id, pfs.ondisk->label);
-       else
+       } else {
                err(1, "pfs-downgrade of PFS#%d (%s) failed",
                        pfs.pfs_id, pfs.ondisk->label);
+       }
        relpfs(fd, &pfs);
 }
 
@@ -447,17 +450,19 @@ hammer_cmd_pseudofs_update(char **av, int ac)
        if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) == 0) {
                parse_pfsd_options(av + 1, ac - 1, pfs.ondisk);
                if (hammer_is_pfs_slave(pfs.ondisk) &&
-                   pfs.pfs_id == HAMMER_ROOT_PFSID)
+                   pfs.pfs_id == HAMMER_ROOT_PFSID) {
                        errx(1, "The real mount point cannot be made a PFS "
                               "slave, only PFS sub-directories can be made "
                               "slaves");
+               }
                pfs.bytes = sizeof(*pfs.ondisk);
                if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) == 0) {
-                       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) == 0)
+                       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) == 0) {
                                dump_pfsd(pfs.ondisk, fd);
-                       else
+                       } else {
                                err(1, "Unable to retrieve PFS configuration "
                                        "after successful update");
+                       }
                } else {
                        err(1, "Unable to adjust PFS configuration");
                }
@@ -499,19 +504,20 @@ dump_pfsd(hammer_pseudofs_data_t pfsd, int fd)
        printf("    label=\"%s\"\n", pfsd->label);
        if (pfsd->snapshots[0])
                printf("    snapshots=\"%s\"\n", pfsd->snapshots);
-       if (pfsd->prune_min < (60 * 60 * 24))
+       if (pfsd->prune_min < (60 * 60 * 24)) {
                printf("    prune-min=%02d:%02d:%02d\n",
                        pfsd->prune_min / 60 / 60 % 24,
                        pfsd->prune_min / 60 % 60,
                        pfsd->prune_min % 60);
-       else if (pfsd->prune_min % (60 * 60 * 24))
+       } else if (pfsd->prune_min % (60 * 60 * 24)) {
                printf("    prune-min=%dd/%02d:%02d:%02d\n",
                        pfsd->prune_min / 60 / 60 / 24,
                        pfsd->prune_min / 60 / 60 % 24,
                        pfsd->prune_min / 60 % 60,
                        pfsd->prune_min % 60);
-       else
+       } else {
                printf("    prune-min=%dd\n", pfsd->prune_min / 60 / 60 / 24);
+       }
 
        if (hammer_is_pfs_slave(pfsd))
                printf("    operating as a SLAVE\n");
@@ -530,12 +536,13 @@ dump_pfsd(hammer_pseudofs_data_t pfsd, int fd)
                        return;
                HammerVersion = version.cur_version;
                if (version.cur_version < 3) {
-                       if (hammer_is_pfs_slave(pfsd))
+                       if (hammer_is_pfs_slave(pfsd)) {
                                printf("    snapshots directory not set for "
                                       "slave\n");
-                       else
+                       } else {
                                printf("    snapshots directory for master "
                                       "defaults to <pfs>/snapshots\n");
+                       }
                } else {
                        printf("    snapshots directory defaults to "
                               "/var/hammer/<pfs>\n");
@@ -586,24 +593,27 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                                fprintf(stderr,
                                        "option %s: '%s' must be an "
                                        "absolute path\n", cmd, ptr);
-                               if (ptr[0] == 0)
+                               if (ptr[0] == 0) {
                                        fprintf(stderr,
                                                "use 'snapshots-clear' "
                                                "to unset snapshots dir\n");
+                               }
                                exit(1);
                        }
-                       if (len >= (int)sizeof(pfsd->snapshots))
+                       if (len >= (int)sizeof(pfsd->snapshots)) {
                                errx(1, "option %s: path too long, %d "
                                        "character limit", cmd, len);
+                       }
                        snprintf(pfsd->snapshots, sizeof(pfsd->snapshots),
                                 "%s", ptr);
                } else if (strcmp(cmd, "snapshots-clear") == 0) {
                        pfsd->snapshots[0] = 0;
                } else if (strcmp(cmd, "prune-min") == 0) {
                        pfsd->prune_min = timetosecs(ptr);
-                       if (pfsd->prune_min < 0)
+                       if (pfsd->prune_min < 0) {
                                errx(1, "option %s: illegal time spec, "
                                        "use Nd or [Nd/]hh[:mm[:ss]]", ptr);
+                       }
                } else {
                        errx(1, "invalid option: %s", cmd);
                }
index 05f4d87..fb724d7 100644 (file)
@@ -147,9 +147,10 @@ hammer_cmd_recover(char **av, int ac)
        }
        assert(!full || !quick);
 
-       if (mkdir(TargetDir, 0777) == -1)
+       if (mkdir(TargetDir, 0777) == -1) {
                if (errno != EEXIST)
                        err(1, "mkdir");
+       }
 
        printf("Running %sraw scan of HAMMER image, recovering to %s\n",
                full ? "full " : quick ? "quick " : "",
@@ -206,11 +207,12 @@ hammer_cmd_recover(char **av, int ac)
                        if (off_blk == 0)
                                b = get_bigblock_entry(off);
 
-                       if (raw_limit)
+                       if (raw_limit) {
                                if (off >= raw_limit) {
                                        printf("Done %016jx\n", (uintmax_t)off);
                                        goto end;
                                }
+                       }
                        if (zone_limit) {
                                if (off >= zone_limit) {
                                        printf("Done %016jx\n", (uintmax_t)off);
@@ -292,12 +294,13 @@ recover_top(char *ptr, hammer_off_t offset)
                }
                offset += sizeof(*node);
 
-               if (isnode && node->type == HAMMER_BTREE_TYPE_LEAF)
+               if (isnode && node->type == HAMMER_BTREE_TYPE_LEAF) {
                        for (i = 0; i < node->count && i < maxcount; ++i) {
                                elm = &node->elms[i];
                                if (elm->base.btype == HAMMER_BTREE_TYPE_RECORD)
                                        recover_elm(&elm->leaf);
                        }
+               }
        }
 }
 
@@ -366,9 +369,10 @@ recover_elm(hammer_btree_leaf_elm_t leaf)
                 * We found an inode which also tells us where the file
                 * or directory is in the directory hierarchy.
                 */
-               if (VerboseOpt)
+               if (VerboseOpt) {
                        printf("inode %016jx:%05d found\n",
                                (uintmax_t)leaf->base.obj_id, pfs_id);
+               }
                path1 = recover_path(dict);
 
                /*
@@ -427,12 +431,13 @@ recover_elm(hammer_btree_leaf_elm_t leaf)
                 */
                if (leaf->base.obj_id == 0)
                        break;
-               if (VerboseOpt)
+               if (VerboseOpt) {
                        printf("inode %016jx:%05d data %016jx,%d\n",
                                (uintmax_t)leaf->base.obj_id,
                                pfs_id,
                                (uintmax_t)leaf->base.key - len,
                                len);
+               }
 
                /*
                 * Update the dictionary entry
@@ -487,9 +492,10 @@ recover_elm(hammer_btree_leaf_elm_t leaf)
                lseek(fd, (off_t)file_offset, SEEK_SET);
                while (len) {
                        if (dict->size == -1) {
-                               for (zfill = chunk - 1; zfill >= 0; --zfill)
+                               for (zfill = chunk - 1; zfill >= 0; --zfill) {
                                        if (((char *)ondisk)[zfill])
                                                break;
+                               }
                                ++zfill;
                        } else {
                                zfill = chunk;
@@ -540,12 +546,13 @@ recover_elm(hammer_btree_leaf_elm_t leaf)
                name[nlen] = 0;
                sanitize_string(name);
 
-               if (VerboseOpt)
+               if (VerboseOpt) {
                        printf("dir %016jx:%05d entry %016jx \"%s\"\n",
                                (uintmax_t)leaf->base.obj_id,
                                pfs_id,
                                (uintmax_t)ondisk->entry.obj_id,
                                name);
+               }
 
                /*
                 * We can't deal with hardlinks so if the object already
@@ -612,9 +619,10 @@ get_dict(int64_t obj_id, uint16_t pfs_id)
                return(NULL);
 
        i = crc32(&obj_id, sizeof(obj_id)) & RD_HMASK;
-       for (dict = RDHash[i]; dict; dict = dict->next)
+       for (dict = RDHash[i]; dict; dict = dict->next) {
                if (dict->obj_id == obj_id && dict->pfs_id == pfs_id)
                        break;
+       }
 
        if (dict == NULL) {
                dict = malloc(sizeof(*dict));
@@ -693,10 +701,11 @@ recover_path_helper(struct recover_dict *dict, struct path_info *info)
                ++info->len;
 
                if (dict->parent &&
-                   (dict->parent->flags & DICTF_TRAVERSED) == 0)
+                   (dict->parent->flags & DICTF_TRAVERSED) == 0) {
                        recover_path_helper(dict->parent, info);
-               else
+               } else {
                        info->len += strlen(TargetDir) + 1;
+               }
                break;
        case PI_LOAD:
                if (dict->parent &&
@@ -708,14 +717,15 @@ recover_path_helper(struct recover_dict *dict, struct path_info *info)
                }
 
                *info->next++ = '/';
-               if (dict->obj_id == HAMMER_OBJID_ROOT)
+               if (dict->obj_id == HAMMER_OBJID_ROOT) {
                        snprintf(info->next, STRLEN_PFSID + 1,
                                "PFS%05d", info->pfs_id);
-               else if (dict->name)
+               } else if (dict->name) {
                        strcpy(info->next, dict->name);
-               else
+               } else {
                        snprintf(info->next, STRLEN_OBJID + 1,
                                "obj_0x%016jx", (uintmax_t)dict->obj_id);
+               }
                info->next += strlen(info->next);
                break;
        }
@@ -785,10 +795,11 @@ scan_raw_limit(void)
                                offset = 0; /* failed */
                                goto end;
                        }
-                       if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX)
+                       if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX) {
                                break;
-                       else if (layer2->zone && layer2->zone != zone)
+                       } else if (layer2->zone && layer2->zone != zone) {
                                offset = phys_offset + block_offset;
+                       }
                }
        }
 end:
@@ -851,10 +862,11 @@ scan_bigblocks(int target_zone)
                        if (!hammer_crc_test_layer2(HammerVersion, layer2)) {
                        }
                        */
-                       if (layer2->zone == target_zone)
+                       if (layer2->zone == target_zone) {
                                add_bigblock_entry(offset, layer1, layer2);
-                       else if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX)
+                       } else if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX) {
                                break;
+                       }
                }
        }
        rel_buffer(buffer1);
index a781bf0..f6d05f5 100644 (file)
@@ -222,7 +222,7 @@ print_btree_node(hammer_off_t node_offset, hammer_tid_t mirror_tid,
        for (i = 0; i < node->count; ++i) {
                elm = &node->elms[i];
                ext = NULL;
-               if (opt.limit)
+               if (opt.limit) {
                        switch (node->type) {
                        case HAMMER_BTREE_TYPE_INTERNAL:
                                if (!test_btree_out_of_range(elm))
@@ -233,6 +233,7 @@ print_btree_node(hammer_off_t node_offset, hammer_tid_t mirror_tid,
                                        ext = "*";
                                break;
                        }
+               }
                print_btree_elm(node, node_offset, elm, lbe, ext);
        }
        if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
@@ -242,12 +243,13 @@ print_btree_node(hammer_off_t node_offset, hammer_tid_t mirror_tid,
        }
        printf("%s     }\n", INDENT);
 
-       if (node->type == HAMMER_BTREE_TYPE_INTERNAL)
+       if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
                for (i = 0; i < node->count; ++i) {
                        elm = &node->elms[i];
-                       if (opt.limit && opt.filter)
+                       if (opt.limit && opt.filter) {
                                if (test_btree_out_of_range(elm))
                                        continue;
+                       }
                        if (elm->internal.subtree_offset) {
                                print_subtree(elm);
                                /*
@@ -259,6 +261,7 @@ print_btree_node(hammer_off_t node_offset, hammer_tid_t mirror_tid,
                                        opt.filter = 0;
                        }
                }
+       }
        rel_buffer(buffer);
        depth--;
 }
@@ -487,14 +490,17 @@ get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
                        flags |= FLAG_BADCHILDPARENT;
 
                if (node->mirror_tid == 0 &&
-                   !(node->parent == 0 && node->count == 2))
+                   !(node->parent == 0 && node->count == 2)) {
                        flags |= FLAG_BADMIRRORTID;
+               }
                if (elm->base.create_tid && node->mirror_tid &&
-                   elm->base.create_tid > node->mirror_tid)
+                   elm->base.create_tid > node->mirror_tid) {
                        flags |= FLAG_BADMIRRORTID;
+               }
                if (elm->base.delete_tid && node->mirror_tid &&
-                   elm->base.delete_tid > node->mirror_tid)
+                   elm->base.delete_tid > node->mirror_tid) {
                        flags |= FLAG_BADMIRRORTID;
+               }
                switch(elm->base.btype) {
                case HAMMER_BTREE_TYPE_RECORD:
                        flags |= test_lr(elm, lbe);
@@ -731,11 +737,12 @@ print_config(char *cfgtxt)
 
        printf("\n%s%17s", INDENT, "");
        printf("config text=\"\n");
-       if (cfgtxt != NULL)
+       if (cfgtxt != NULL) {
                while((token = strsep(&cfgtxt, "\r\n")) != NULL)
                        if (strlen(token))
                                printf("%s%17s            %s\n",
                                        INDENT, "", token);
+       }
        printf("%s%17s            \"", INDENT, "");
 }
 
index acc993a..9b8ab6e 100644 (file)
@@ -92,6 +92,7 @@ hammer_cmd_snap(char **av, int ac, int tostdout, int fsbase)
        } else {
                err(2, "hammer snap: File %s exists and is not a directory",
                    av[0]);
+               /* not reached */
        }
 
        /*
@@ -99,21 +100,26 @@ hammer_cmd_snap(char **av, int ac, int tostdout, int fsbase)
         * ioctl (so it is stored in the correct PFS).
         */
        fsfd = open(dirpath, O_RDONLY);
-       if (fsfd < 0)
+       if (fsfd < 0) {
                err(2, "hammer snap: Cannot open directory %s", dirpath);
+               /* not reached */
+       }
 
        /*
         * Must be at least version 3 to use this command.
         */
        bzero(&version, sizeof(version));
 
-       if (ioctl(fsfd, HAMMERIOC_GET_VERSION, &version) < 0)
+       if (ioctl(fsfd, HAMMERIOC_GET_VERSION, &version) < 0) {
                err(2, "Unable to create snapshot");
-       else if (version.cur_version < 3)
+               /* not reached */
+       } else if (version.cur_version < 3) {
                errx(2, "Unable to create snapshot: This directive requires "
                        "you to upgrade\n"
                        "the filesystem to version 3.  "
                        "Use 'hammer snapshot' for legacy operation.");
+               /* not reached */
+       }
        HammerVersion = version.cur_version;
 
        /*
@@ -121,16 +127,18 @@ hammer_cmd_snap(char **av, int ac, int tostdout, int fsbase)
         */
        bzero(&synctid, sizeof(synctid));
        synctid.op = HAMMER_SYNCTID_SYNC2;
-       if (ioctl(fsfd, HAMMERIOC_SYNCTID, &synctid) < 0)
+       if (ioctl(fsfd, HAMMERIOC_SYNCTID, &synctid) < 0) {
                err(2, "hammer snap: Synctid %s failed",
                    dirpath);
+       }
        if (tostdout) {
-               if (strcmp(dirpath, ".") == 0 || strcmp(dirpath, "..") == 0)
+               if (strcmp(dirpath, ".") == 0 || strcmp(dirpath, "..") == 0) {
                        printf("%s/@@0x%016jx\n",
                                dirpath, (uintmax_t)synctid.tid);
-               else
+               } else {
                        printf("%s@@0x%016jx\n",
                                dirpath, (uintmax_t)synctid.tid);
+               }
                fsym = NULL;
                tsym = NULL;
        }
@@ -141,9 +149,10 @@ hammer_cmd_snap(char **av, int ac, int tostdout, int fsbase)
        if (fsbase) {
                struct statfs buf;
 
-               if (statfs(dirpath, &buf) < 0)
+               if (statfs(dirpath, &buf) < 0) {
                        err(2, "hammer snap: Cannot determine mount for %s",
                            dirpath);
+               }
                asprintf(&fsym, "%s/@@0x%016jx",
                         buf.f_mntonname, (uintmax_t)synctid.tid);
        } else if (strcmp(dirpath, ".") == 0 || strcmp(dirpath, "..") == 0) {
@@ -206,9 +215,11 @@ hammer_cmd_snaprm(char **av, int ac)
        for (i = 0; i < ac; ++i) {
                if (lstat(av[i], &st) < 0) {
                        tid = strtoull(av[i], &ptr, 16);
-                       if (*ptr)
+                       if (*ptr) {
                                err(2, "hammer snaprm: not a file or tid: %s",
                                    av[i]);
+                               /* not reached */
+                       }
                        if (mode == path_m) {
                                snapshot_usage(1);
                                /* not reached */
@@ -225,16 +236,20 @@ hammer_cmd_snaprm(char **av, int ac)
                        if (fsfd >= 0)
                                close(fsfd);
                        fsfd = open(av[i], O_RDONLY);
-                       if (fsfd < 0)
+                       if (fsfd < 0) {
                                err(2, "hammer snaprm: cannot open dir %s",
                                    av[i]);
+                               /* not reached */
+                       }
                        mode = tid_m;
                } else if (S_ISLNK(st.st_mode)) {
                        dirpath = dirpart(av[i]);
                        bzero(linkbuf, sizeof(linkbuf));
-                       if (readlink(av[i], linkbuf, sizeof(linkbuf) - 1) < 0)
+                       if (readlink(av[i], linkbuf, sizeof(linkbuf) - 1) < 0) {
                                err(2, "hammer snaprm: cannot read softlink: "
                                       "%s", av[i]);
+                               /* not reached */
+                       }
                        if (linkbuf[0] == '/') {
                                free(dirpath);
                                dirpath = dirpart(linkbuf);
@@ -248,9 +263,11 @@ hammer_cmd_snaprm(char **av, int ac)
                        if (fsfd >= 0)
                                close(fsfd);
                        fsfd = open(dirpath, O_RDONLY);
-                       if (fsfd < 0)
+                       if (fsfd < 0) {
                                err(2, "hammer snaprm: cannot open dir %s",
                                    dirpath);
+                               /* not reached */
+                       }
 
                        delete = 1;
                        if (i == 0 && ac > 1) {
@@ -281,6 +298,7 @@ hammer_cmd_snaprm(char **av, int ac)
                } else {
                        err(2, "hammer snaprm: not directory or snapshot "
                               "softlink: %s", av[i]);
+                       /* not reached */
                }
        }
        if (fsfd >= 0)
@@ -324,9 +342,10 @@ hammer_cmd_snapshot(char **av, int ac)
                        err(2, "File %s already exists", softlink_dir);
 
                if (filesystem == NULL) {
-                       if (statfs(softlink_dir, &buf) != 0)
+                       if (statfs(softlink_dir, &buf) != 0) {
                                err(2, "Unable to determine filesystem of %s",
                                    softlink_dir);
+                       }
                        filesystem = buf.f_mntonname;
                }
 
@@ -353,12 +372,14 @@ hammer_cmd_snapshot(char **av, int ac)
                                *pos = '\0';
 
                        if (stat(softlink_fmt, &st) != 0 ||
-                           !S_ISDIR(st.st_mode))
+                           !S_ISDIR(st.st_mode)) {
                                err(2, "Unable to determine softlink dir %s",
                                    softlink_fmt);
-                       if (statfs(softlink_fmt, &buf) != 0)
+                       }
+                       if (statfs(softlink_fmt, &buf) != 0) {
                                err(2, "Unable to determine filesystem of %s",
                                    softlink_fmt);
+                       }
                        filesystem = buf.f_mntonname;
 
                        /* restore '/' */
@@ -425,16 +446,19 @@ snapshot_add(int fd, const char *fsym, const char *tsym, const char *label,
                snapshot.count = 1;
                snapshot.snaps[0].tid = tid;
                snapshot.snaps[0].ts = time(NULL) * 1000000ULL;
-               if (label)
+               if (label) {
                        snprintf(snapshot.snaps[0].label,
                                 sizeof(snapshot.snaps[0].label),
                                 "%s",
                                 label);
-               if (ioctl(fd, HAMMERIOC_ADD_SNAPSHOT, &snapshot) < 0)
+               }
+               if (ioctl(fd, HAMMERIOC_ADD_SNAPSHOT, &snapshot) < 0) {
                        err(2, "Unable to create snapshot");
-               else if (snapshot.head.error && snapshot.head.error != EEXIST)
+               } else if (snapshot.head.error &&
+                          snapshot.head.error != EEXIST) {
                        errx(2, "Unable to create snapshot: %s",
                                strerror(snapshot.head.error));
+               }
         }
 
        /*
@@ -443,8 +467,9 @@ snapshot_add(int fd, const char *fsym, const char *tsym, const char *label,
         */
        if (fsym && tsym) {
                remove(tsym);
-               if (symlink(fsym, tsym) < 0)
+               if (symlink(fsym, tsym) < 0) {
                        err(2, "Unable to create symlink %s", tsym);
+               }
        }
 }
 
@@ -464,25 +489,33 @@ snapshot_ls(const char *path)
        char snapts[64];
 
        fd = open(path, O_RDONLY);
-       if (fd < 0)
+       if (fd < 0) {
                err(2, "hammer snapls: cannot open %s", path);
+               /* not reached */
+       }
 
        clrpfs(&pfs, &pfs_od, -1);
-       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0)
+       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0) {
                err(2, "hammer snapls: cannot retrieve PFS info on %s", path);
+               /* not reached */
+       }
 
        bzero(&info, sizeof(info));
-       if ((ioctl(fd, HAMMERIOC_GET_INFO, &info)) < 0)
+       if ((ioctl(fd, HAMMERIOC_GET_INFO, &info)) < 0) {
                 err(2, "hammer snapls: cannot retrieve HAMMER info");
+               /* not reached */
+       }
 
        printf("Snapshots on %s\tPFS#%d\n", path, pfs.pfs_id);
        printf("Transaction ID\t\tTimestamp\t\tNote\n");
 
        bzero(&snapshot, sizeof(snapshot));
        do {
-               if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0)
+               if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0) {
                        err(2, "hammer snapls: %s: not HAMMER fs or "
                                "version < 3", path);
+                       /* not reached */
+               }
                for (i = 0; i < snapshot.count; ++i) {
                        snap = &snapshot.snaps[i];
 
@@ -506,12 +539,14 @@ snapshot_del(int fsfd, hammer_tid_t tid)
 
         bzero(&version, sizeof(version));
 
-        if (ioctl(fsfd, HAMMERIOC_GET_VERSION, &version) < 0)
+        if (ioctl(fsfd, HAMMERIOC_GET_VERSION, &version) < 0) {
                err(2, "hammer snaprm 0x%016jx", (uintmax_t)tid);
+       }
        HammerVersion = version.cur_version;
-       if (version.cur_version < 3)
+       if (version.cur_version < 3) {
                errx(2, "hammer snaprm 0x%016jx: You must upgrade to version "
                        " 3 to use this directive", (uintmax_t)tid);
+       }
 
        bzero(&snapshot, sizeof(snapshot));
        snapshot.count = 1;
@@ -520,16 +555,17 @@ snapshot_del(int fsfd, hammer_tid_t tid)
        /*
         * Do not abort if we are unable to remove the meta-data.
         */
-       if (ioctl(fsfd, HAMMERIOC_DEL_SNAPSHOT, &snapshot) < 0)
+       if (ioctl(fsfd, HAMMERIOC_DEL_SNAPSHOT, &snapshot) < 0) {
                err(2, "hammer snaprm 0x%016jx",
                      (uintmax_t)tid);
-       else if (snapshot.head.error == ENOENT)
+       } else if (snapshot.head.error == ENOENT) {
                fprintf(stderr, "Warning: hammer snaprm 0x%016jx: "
                                "meta-data not found\n",
                        (uintmax_t)tid);
-       else if (snapshot.head.error)
+       } else if (snapshot.head.error) {
                fprintf(stderr, "Warning: hammer snaprm 0x%016jx: %s\n",
                        (uintmax_t)tid, strerror(snapshot.head.error));
+       }
 }
 
 static
index 2defbfc..1e005a9 100644 (file)
@@ -175,12 +175,13 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt)
                 * Finalize operations
                 */
                hammer_softprune_finalize(scan);
-               if (everything_opt)
+               if (everything_opt) {
                        printf("Prune %s: EVERYTHING\n",
                               scan->filesystem);
-               else
+               } else {
                        printf("Prune %s: %d snapshots\n",
                               scan->filesystem, scan->prune.nelms);
+               }
                if (scan->prune.nelms == 0 &&
                    (scan->prune.head.flags & HAMMER_IOC_PRUNE_ALL) == 0) {
                        fprintf(stderr, "No snapshots found\n");
@@ -277,10 +278,11 @@ hammer_softprune_scandir(struct softprune **basep,
                        continue;
                linkbuf[len] = 0;
                if ((ptr = strrchr(linkbuf, '@')) &&
-                   ptr > linkbuf && ptr[-1] == '@')
+                   ptr > linkbuf && ptr[-1] == '@') {
                        hammer_softprune_addentry(basep, template,
                                                  dirname, den->d_name, &st,
                                                  linkbuf, ptr - 1);
+               }
        }
        free(linkbuf);
        if (path)
@@ -403,14 +405,15 @@ hammer_softprune_addentry(struct softprune **basep,
        /*
         * Calculate filesystem path.
         */
-       if (linkbuf[0] == '/')
+       if (linkbuf[0] == '/') {
                asprintf(&fspath, "%*.*s",
                         (int)(tidptr - linkbuf), (int)(tidptr - linkbuf),
                         linkbuf);
-       else
+       } else {
                asprintf(&fspath, "%s/%*.*s", dirpath,
                         (int)(tidptr - linkbuf), (int)(tidptr - linkbuf),
                         linkbuf);
+       }
        if (statfs(fspath, &fs) < 0) {
                free(fspath);
                return(NULL);
@@ -538,9 +541,10 @@ hammer_softprune_finalize(struct softprune *scan)
                         * Remove duplicate
                         */
                        --scan->prune.nelms;
-                       if (i != scan->prune.nelms)
+                       if (i != scan->prune.nelms) {
                                bcopy(elm + 1, elm,
                                      (scan->prune.nelms - i) * sizeof(*elm));
+                       }
                        --i;
                        continue;
                } else {
index d45a206..040e12c 100644 (file)
@@ -125,7 +125,7 @@ hammer_strip_bigblock(int zone, hammer_off_t offset)
        /*
         * This format is taken from hammer blockmap.
         */
-       if (VerboseOpt)
+       if (VerboseOpt) {
                printf("%016jx zone=%-2d vol=%-3d L1#=%-6d L2#=%-6d L1=%-7lu L2=%-7lu\n",
                        offset,
                        zone,
@@ -134,8 +134,9 @@ hammer_strip_bigblock(int zone, hammer_off_t offset)
                        HAMMER_BLOCKMAP_LAYER2_INDEX(offset),
                        HAMMER_BLOCKMAP_LAYER1_OFFSET(offset),
                        HAMMER_BLOCKMAP_LAYER2_OFFSET(offset));
-       else
+       } else {
                printf("%016jx\n", offset);
+       }
 
        for (i = 0; i < HAMMER_BIGBLOCK_SIZE; i += HAMMER_BUFSIZE) {
                get_buffer_data(offset + i, &buffer, 1);
index 9521175..6879d5e 100644 (file)
@@ -131,12 +131,13 @@ hammer_cmd_set_version(char **av, int ac)
                errx(1, "hammer version-upgrade ioctl");
 
        printf("hammer version-upgrade: succeeded\n");
-       if (overs < 3 && nvers >= 3)
+       if (overs < 3 && nvers >= 3) {
                printf("NOTE!  Please run 'hammer cleanup' to convert the\n"
                       "<pfs>/snapshots directories to the new meta-data\n"
                       "format.  Once converted configuration data will\n"
                       "no longer resides in <pfs>/snapshots and you can\n"
                       "even rm -rf it entirely if you want.\n");
+       }
 
        close(fd);
 }
index cd3b337..3d36623 100644 (file)
@@ -155,12 +155,13 @@ hammer_cmd_volume_list(char **av, int ac)
        for (i = 0; i < ioc.nvols; i++) {
                device_name = ioc.vols[i].device_name;
                vol_no = ioc.vols[i].vol_no;
-               if (VerboseOpt)
+               if (VerboseOpt) {
                        printf("%d\t%s%s\n", vol_no, device_name,
                                (vol_no == HAMMER_ROOT_VOLNO ?
                                " (Root Volume)" : ""));
-               else
+               } else {
                        printf("%s\n", device_name);
+               }
        }
 
        free(ioc.vols);
index 196ee6b..e27a5fb 100644 (file)
@@ -61,10 +61,12 @@ hammer_get_cycle(hammer_base_elm_t base, hammer_tid_t *extra)
                                CyclePath, strerror(errno));
                        return;
                }
-               if (extra)
-                       if (read(fd, extra, sizeof(*extra)) != sizeof(*extra))
+               if (extra) {
+                       if (read(fd, extra, sizeof(*extra)) != sizeof(*extra)) {
                                fprintf(stderr, "cycle-file %s: Warning, malformed\n",
                                        CyclePath);
+                       }
+               }
                close(fd);
        }
        /* ok if the file does not exist */
index b2969dc..d825a21 100644 (file)
@@ -237,9 +237,10 @@ main(int ac, char **av)
                char *elm, *dup;
 
                dup = ptr = strdup(restrictcmd);
-               while ((elm = strsep(&ptr, ",")) != NULL)
+               while ((elm = strsep(&ptr, ",")) != NULL) {
                        if (strcmp(av[0], elm) == 0)
                                break;
+               }
                if (elm == NULL)
                        errx(1, "hammer-remote: request does not match "
                                "restricted command");
@@ -250,9 +251,10 @@ main(int ac, char **av)
         * Lookup the filesystem type
         */
        uuid_name_lookup(&Hammer_FSType, HAMMER_FSTYPE_STRING, &status);
-       if (status != uuid_s_ok)
+       if (status != uuid_s_ok) {
                errx(1, "uuids file does not have the DragonFly "
                        "HAMMER filesystem type");
+       }
 
        /*
         * Parse commands
@@ -573,9 +575,10 @@ __hammer_parsedevs(const char *blkdevs, int oflags, int verify)
        char *volname;
        int volnum = 0;
 
-       if (blkdevs == NULL)
+       if (blkdevs == NULL) {
                errx(1, "A -f blkdevs specification is required "
                        "for this command");
+       }
 
        copy = strdup(blkdevs);
        while ((volname = copy) != NULL) {
index 5159242..81a4bc5 100644 (file)
@@ -77,8 +77,9 @@ getyn(void)
        if (strcmp(buf, "y") == 0 ||
            strcmp(buf, "yes") == 0 ||
            strcmp(buf, "Y") == 0 ||
-           strcmp(buf, "YES") == 0)
+           strcmp(buf, "YES") == 0) {
                return(1);
+       }
        return(0);
 }
 
@@ -87,19 +88,20 @@ sizetostr(off_t size)
 {
        static char buf[32];
 
-       if (size < 1024 / 2)
+       if (size < 1024 / 2) {
                snprintf(buf, sizeof(buf), "%6.2fB", (double)size);
-       else if (size < 1024 * 1024 / 2)
+       } else if (size < 1024 * 1024 / 2) {
                snprintf(buf, sizeof(buf), "%6.2fKB", (double)size / 1024);
-       else if (size < 1024 * 1024 * 1024LL / 2)
+       } else if (size < 1024 * 1024 * 1024LL / 2) {
                snprintf(buf, sizeof(buf), "%6.2fMB",
                        (double)size / (1024 * 1024));
-       else if (size < 1024 * 1024 * 1024LL * 1024LL / 2)
+       } else if (size < 1024 * 1024 * 1024LL * 1024LL / 2) {
                snprintf(buf, sizeof(buf), "%6.2fGB",
                        (double)size / (1024 * 1024 * 1024LL));
-       else
+       } else {
                snprintf(buf, sizeof(buf), "%6.2fTB",
                        (double)size / (1024 * 1024 * 1024LL * 1024LL));
+       }
        return(buf);
 }
 
@@ -146,11 +148,12 @@ hammer_fs_to_rootvol(const char *fs, char *buf, int len)
        if (hammer_fs_to_vol(fs, &ioc) == -1)
                return(-1);
 
-       for (i = 0; i < ioc.nvols; i++)
+       for (i = 0; i < ioc.nvols; i++) {
                if (ioc.vols[i].vol_no == HAMMER_ROOT_VOLNO) {
                        strlcpy(buf, ioc.vols[i].device_name, len);
                        break;
                }
+       }
        assert(i != ioc.nvols);  /* root volume must exist */
 
        free(ioc.vols);
@@ -239,11 +242,12 @@ hammer_cleanup_zone_stat(struct zone_stat *stats)
 {
        int i;
 
-       if (l1_bits)
+       if (l1_bits) {
                for (i = 0; i < HAMMER_MAX_VOLUMES; i++) {
                        free(l1_bits[i]);
                        l1_bits[i] = NULL;
                }
+       }
 
        free(l1_bits);
        l1_bits = NULL;
index 46f85f6..13d5911 100644 (file)
@@ -116,16 +116,19 @@ __add_volume(struct volume_info *volume)
                errx(1, "add_volume: %s: Failed to stat", volume->name);
 
        TAILQ_FOREACH(scan, &VolList, entry) {
-               if (scan->vol_no == volume->vol_no)
+               if (scan->vol_no == volume->vol_no) {
                        errx(1, "add_volume: %s: Duplicate volume number %d "
                                "against %s",
                                volume->name, volume->vol_no, scan->name);
-               if (fstat(scan->fd, &st2) != 0)
+               }
+               if (fstat(scan->fd, &st2) != 0) {
                        errx(1, "add_volume: %s: Failed to stat %s",
                                volume->name, scan->name);
-               if ((st1.st_ino == st2.st_ino) && (st1.st_dev == st2.st_dev))
+               }
+               if ((st1.st_ino == st2.st_ino) && (st1.st_dev == st2.st_dev)) {
                        errx(1, "add_volume: %s: Specified more than once",
                                volume->name);
+               }
        }
 
        TAILQ_INSERT_TAIL(&VolList, volume, entry);
@@ -136,18 +139,22 @@ __verify_volume(struct volume_info *volume)
 {
        hammer_volume_ondisk_t ondisk = volume->ondisk;
 
-       if (ondisk->vol_signature != HAMMER_FSBUF_VOLUME)
+       if (ondisk->vol_signature != HAMMER_FSBUF_VOLUME) {
                errx(1, "verify_volume: Invalid volume signature %016jx",
                        ondisk->vol_signature);
-       if (ondisk->vol_rootvol != HAMMER_ROOT_VOLNO)
+       }
+       if (ondisk->vol_rootvol != HAMMER_ROOT_VOLNO) {
                errx(1, "verify_volume: Invalid root volume# %d",
                        ondisk->vol_rootvol);
-       if (bcmp(&Hammer_FSType, &ondisk->vol_fstype, sizeof(Hammer_FSType)))
+       }
+       if (bcmp(&Hammer_FSType, &ondisk->vol_fstype, sizeof(Hammer_FSType))) {
                errx(1, "verify_volume: %s: Header does not indicate "
                        "that this is a HAMMER volume", volume->name);
-       if (bcmp(&Hammer_FSId, &ondisk->vol_fsid, sizeof(Hammer_FSId)))
+       }
+       if (bcmp(&Hammer_FSId, &ondisk->vol_fsid, sizeof(Hammer_FSId))) {
                errx(1, "verify_volume: %s: FSId does not match other volumes!",
                        volume->name);
+       }
 }
 
 /*
@@ -178,9 +185,10 @@ load_volume(const char *filename, int oflags, int verify)
        volume = __alloc_volume(filename, oflags);
 
        n = readhammervol(volume);
-       if (n == -1)
+       if (n == -1) {
                err(1, "load_volume: %s: Read failed at offset 0",
                    volume->name);
+       }
        volume->vol_no = volume->ondisk->vol_no;
        HammerVersion = volume->ondisk->vol_version;
 
@@ -220,13 +228,15 @@ check_volume(struct volume_info *volume)
                 * sector size must be compatible.  HAMMER uses 16384 byte
                 * filesystem buffers.
                 */
-               if (pinfo.reserved_blocks)
+               if (pinfo.reserved_blocks) {
                        errx(1, "HAMMER cannot be placed in a partition "
                                "which overlaps the disklabel or MBR");
+               }
                if (pinfo.media_blksize > HAMMER_BUFSIZE ||
-                   HAMMER_BUFSIZE % pinfo.media_blksize)
+                   HAMMER_BUFSIZE % pinfo.media_blksize) {
                        errx(1, "A media sector size of %d is not supported",
                             pinfo.media_blksize);
+               }
 
                volume->size = pinfo.media_size;
                volume->device_offset = pinfo.media_offset;
@@ -248,9 +258,10 @@ get_volume(int32_t vol_no)
 {
        struct volume_info *volume;
 
-       TAILQ_FOREACH(volume, &VolList, entry)
+       TAILQ_FOREACH(volume, &VolList, entry) {
                if (volume->vol_no == vol_no)
                        break;
+       }
 
        return(volume);
 }
@@ -295,12 +306,14 @@ __alloc_buffer(hammer_off_t zone2_offset, int isnew)
        buffer->volume = volume;
        buffer->ondisk = calloc(1, HAMMER_BUFSIZE);
 
-       if (isnew <= 0)
-               if (readhammerbuf(buffer) == -1)
+       if (isnew <= 0) {
+               if (readhammerbuf(buffer) == -1) {
                        err(1, "Failed to read %s:%016jx at %016jx",
                            volume->name,
                            (intmax_t)buffer->zone2_offset,
                            (intmax_t)buffer->raw_offset);
+               }
+       }
 
        hi = buffer_hash(zone2_offset);
        TAILQ_INSERT_TAIL(&volume->buffer_lists[hi], buffer, entry);
@@ -391,7 +404,7 @@ rel_buffer(struct buffer_info *buffer)
        if (buffer == NULL)
                return;
        assert(buffer->cache.refs > 0);
-       if (--buffer->cache.refs == 0)
+       if (--buffer->cache.refs == 0) {
                if (buffer->cache.delete) {
                        hi = buffer_hash(buffer->zone2_offset);
                        volume = buffer->volume;
@@ -402,6 +415,7 @@ rel_buffer(struct buffer_info *buffer)
                        free(buffer->ondisk);
                        free(buffer);
                }
+       }
 }
 
 /*
@@ -652,8 +666,9 @@ count_freemap(struct volume_info *volume)
 
        for (phys_offset = HAMMER_ENCODE_RAW_BUFFER(volume->vol_no, 0);
             phys_offset < aligned_vol_free_end;
-            phys_offset += HAMMER_BLOCKMAP_LAYER2)
+            phys_offset += HAMMER_BLOCKMAP_LAYER2) {
                vol_free_off += HAMMER_BIGBLOCK_SIZE;
+       }
 
        for (phys_offset = HAMMER_ENCODE_RAW_BUFFER(volume->vol_no, 0);
             phys_offset < aligned_vol_free_end;
@@ -843,9 +858,10 @@ flush_volume(struct volume_info *volume)
        struct buffer_info *buffer;
        int i;
 
-       for (i = 0; i < HAMMER_BUFLISTS; ++i)
+       for (i = 0; i < HAMMER_BUFLISTS; ++i) {
                TAILQ_FOREACH(buffer, &volume->buffer_lists[i], entry)
                        flush_buffer(buffer);
+       }
        if (writehammervol(volume) == -1)
                err(1, "Write volume %d (%s)", volume->vol_no, volume->name);
 }