sbin/hammer: Cleanup blocks with a single statement
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 9 Apr 2017 00:04:16 +0000 (03:04 +0300)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 9 Apr 2017 18:49:12 +0000 (21:49 +0300)
This commit basically does the same as what Linux kernel's coding
style mentions for braces, which is basically the same with BSDs.
https://github.com/torvalds/linux/blob/master/Documentation/process/coding-style.rst#3-placing-braces-and-spaces

No diff in sbin/hammer/hammer binary when assert(3) is disabled.

26 files changed:
sbin/hammer/blockmap.c
sbin/hammer/cache.c
sbin/hammer/cmd_abort.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_rebalance.c
sbin/hammer/cmd_reblock.c
sbin/hammer/cmd_recover.c
sbin/hammer/cmd_show.c
sbin/hammer/cmd_snapshot.c
sbin/hammer/cmd_softprune.c
sbin/hammer/cmd_stats.c
sbin/hammer/cmd_strip.c
sbin/hammer/cmd_synctid.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
sbin/hammer/test_dupkey.c

index 75e27c5..09d2393 100644 (file)
@@ -144,9 +144,8 @@ again:
        assert(blockmap->next_offset != HAMMER_ZONE_ENCODE(zone + 1, 0));
 
        tmp_offset = blockmap->next_offset + bytes - 1;
-       if ((blockmap->next_offset ^ tmp_offset) & ~HAMMER_BUFMASK64) {
+       if ((blockmap->next_offset ^ tmp_offset) & ~HAMMER_BUFMASK64)
                blockmap->next_offset = tmp_offset & ~HAMMER_BUFMASK64;
-       }
 
        /*
         * Dive layer 1.
index 003fd21..e1f7bdd 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,6 +133,5 @@ hammer_cache_flush(void)
                        if (CacheUse < CacheMax / 2)
                                break;
                }
-       }
 }
 
index ac6d461..6eea5fd 100644 (file)
@@ -63,9 +63,8 @@ hammer_cmd_abort_cleanup(char **av __unused, int ac __unused)
        static const char termmsg[] = "Terminated cleanup process %u\n";
        const size_t pflen = sizeof(prefix) - 1;
 
-       if ((dir = opendir(pidfile_loc)) == NULL) {
+       if ((dir = opendir(pidfile_loc)) == NULL)
                return;
-       }
 
        while ((den = readdir(dir)) != NULL) {
                if (strncmp(den->d_name, prefix, pflen) == 0) {
@@ -73,19 +72,16 @@ hammer_cmd_abort_cleanup(char **av __unused, int ac __unused)
                                pidfile_loc, den->d_name);
                        pid = strtol((char *)(den->d_name + pflen), &str, 10);
                        pf_fd = open(pidfile, O_RDONLY | O_CLOEXEC);
-                       if (pf_fd == -1) {
+                       if (pf_fd == -1)
                                continue;
-                       }
 
                        if (flock(pf_fd, LOCK_EX | LOCK_NB) < 0) {
                                if (errno == EWOULDBLOCK) {
                                        /* error expected during cleanup */
-                                       if (kill (pid, SIGTERM) == 0) {
+                                       if (kill (pid, SIGTERM) == 0)
                                                printf (termmsg, pid);
-                                       }
                                }
-                       }
-                       else {
+                       } else {
                                /* lock succeeded so pidfile is stale */
                                flock (pf_fd, LOCK_UN);
                        }
index 92d5cfa..2be3fd5 100644 (file)
@@ -135,9 +135,8 @@ 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,
@@ -172,19 +171,17 @@ 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);
@@ -211,12 +208,10 @@ dump_blockmap(int zone)
                hammer_cleanup_zone_stat(stats);
        }
 
-       if (num_bad_layer1 || VerboseOpt) {
+       if (num_bad_layer1 || VerboseOpt)
                printf("%d bad layer1\n", num_bad_layer1);
-       }
-       if (num_bad_layer2 || VerboseOpt) {
+       if (num_bad_layer2 || VerboseOpt)
                printf("%d bad layer2\n", num_bad_layer1);
-       }
 }
 
 void
@@ -548,12 +543,10 @@ dump_collect_table(void)
                hammer_cleanup_zone_stat(stats);
        }
 
-       if (num_bad_node || VerboseOpt) {
+       if (num_bad_node || VerboseOpt)
                printf("%d bad nodes\n", num_bad_node);
-       }
-       if (error || VerboseOpt) {
+       if (error || VerboseOpt)
                printf("%d errors\n", error);
-       }
 }
 
 static
@@ -577,11 +570,10 @@ 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 7b97fed..91f43ef 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,8 +131,6 @@ hammer_cmd_cleanup(char **av, int ac)
                                        do_cleanup(path);
                                }
                        }
-               }
-
        } else {
                while (ac) {
                        do_cleanup(*av);
@@ -200,24 +198,21 @@ 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;
@@ -291,7 +286,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",
@@ -299,7 +294,6 @@ do_cleanup(const char *path)
                                close(fd);
                                return;
                        }
-               }
 
                /*
                 *  Create missing config file for HAMMER VERSION < 3
@@ -354,9 +348,9 @@ do_cleanup(const char *path)
                                        runcmd(&r, "mkdir -p %s", npath);
                                        runcmd(&r, "cpdup %s %s", snapshots_path, npath);
                                        if (r != 0) {
-                                   printf("Unable to move snapshots directory!\n");
-                                   printf("Please fix this critical error.\n");
-                                   printf("Aborting cleanup of %s\n", path);
+                                               printf("Unable to move snapshots directory!\n");
+                                               printf("Please fix this critical error.\n");
+                                               printf("Aborting cleanup of %s\n", path);
                                                close(fd);
                                                return;
                                        }
@@ -390,9 +384,8 @@ do_cleanup(const char *path)
        snprintf (pidfile, PIDFILE_BUFSIZE, "%s/hammer.cleanup.%d",
                pidfile_loc, getpid());
        pfh = pidfile_open(pidfile, 0644, NULL);
-       if (pfh == NULL) {
+       if (pfh == NULL)
                warn ("Unable to open or create %s", pidfile);
-       }
        pidfile_write(pfh);
 
        /*
@@ -457,13 +450,12 @@ 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 {
@@ -526,13 +518,12 @@ 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
@@ -553,11 +544,10 @@ 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,
@@ -604,9 +594,8 @@ migrate_snapshots(int fd, const char *snapshots_path)
                        if (den->d_name[0] == '.')
                                continue;
                        asprintf(&fpath, "%s/%s", snapshots_path, den->d_name);
-                       if (lstat(fpath, &st) == 0 && S_ISLNK(st.st_mode)) {
+                       if (lstat(fpath, &st) == 0 && S_ISLNK(st.st_mode))
                                migrate_one_snapshot(fd, fpath, &snapshot);
-                       }
                        free(fpath);
                }
                closedir(dir);
@@ -665,9 +654,8 @@ 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));
@@ -879,11 +867,9 @@ 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);
        }
@@ -914,10 +900,9 @@ 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);
                                }
                        }
@@ -943,19 +928,16 @@ 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),
@@ -1075,18 +1057,17 @@ 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 c1e308b..1f347c2 100644 (file)
@@ -57,39 +57,33 @@ 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);
@@ -110,10 +104,8 @@ 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
@@ -133,11 +125,9 @@ 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.
@@ -184,11 +174,10 @@ 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 1560a45..022f1b2 100644 (file)
@@ -444,12 +444,10 @@ collect_btree_elm(hammer_btree_leaf_elm_t scan_leaf, int flags __unused)
 static __inline int
 validate_dedup_pair(hammer_btree_leaf_elm_t p, hammer_btree_leaf_elm_t q)
 {
-       if (HAMMER_ZONE(p->data_offset) != HAMMER_ZONE(q->data_offset)) {
+       if (HAMMER_ZONE(p->data_offset) != HAMMER_ZONE(q->data_offset))
                return (1);
-       }
-       if (p->data_len != q->data_len) {
+       if (p->data_len != q->data_len)
                return (1);
-       }
 
        return (0);
 }
@@ -471,30 +469,24 @@ deduplicate(hammer_btree_leaf_elm_t p, hammer_btree_leaf_elm_t q)
         * If data_offset fields are the same there is no need to run ioctl,
         * candidate is already dedup'ed.
         */
-       if (p->data_offset == q->data_offset) {
+       if (p->data_offset == q->data_offset)
                return (0);
-       }
 
        dedup.elm1 = p->base;
        dedup.elm2 = q->base;
        RunningIoctl = 1;
        if (ioctl(glob_fd, HAMMERIOC_DEDUP, &dedup) < 0) {
-               if (errno == EOPNOTSUPP) {
-                       /* must be at least version 5 */
-                       return (DEDUP_VERS_FAILURE);
-               }
+               if (errno == EOPNOTSUPP)
+                       return (DEDUP_VERS_FAILURE); /* must be at least version 5 */
                /* Technical failure - locking or w/e */
                return (DEDUP_TECH_FAILURE);
        }
-       if (dedup.head.flags & HAMMER_IOC_DEDUP_CMP_FAILURE) {
+       if (dedup.head.flags & HAMMER_IOC_DEDUP_CMP_FAILURE)
                return (DEDUP_CMP_FAILURE);
-       }
-       if (dedup.head.flags & HAMMER_IOC_DEDUP_INVALID_ZONE) {
+       if (dedup.head.flags & HAMMER_IOC_DEDUP_INVALID_ZONE)
                return (DEDUP_INVALID_ZONE);
-       }
-       if (dedup.head.flags & HAMMER_IOC_DEDUP_UNDERFLOW) {
+       if (dedup.head.flags & HAMMER_IOC_DEDUP_UNDERFLOW)
                return (DEDUP_UNDERFLOW);
-       }
        RunningIoctl = 0;
        ++dedup_successes_count;
        dedup_successes_bytes += p->data_len;
@@ -527,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,
@@ -535,7 +527,6 @@ 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);
@@ -572,7 +563,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) {
@@ -580,7 +571,6 @@ 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
@@ -746,9 +736,8 @@ crc_failure:
                 * SHA subtree. If upgrade fails insert the candidate into
                 * Pass2 list.
                 */
-               if (upgrade_chksum(scan_leaf, temp.sha_hash)) {
+               if (upgrade_chksum(scan_leaf, temp.sha_hash))
                        goto pass2_insert;
-               }
                sha_de = RB_FIND(sha_dedup_entry_rb_tree, &de->u.fict_root,
                                 &temp);
                if (sha_de != NULL)
@@ -880,11 +869,10 @@ 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);
 
@@ -939,9 +927,8 @@ 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);
                        }
@@ -997,12 +984,11 @@ 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 289e3fa..d20ab65 100644 (file)
@@ -117,13 +117,12 @@ 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 7bfffd1..fd7c133 100644 (file)
@@ -193,10 +193,9 @@ 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
 
        /*
@@ -238,9 +237,8 @@ again:
         * A cycle file overrides the beginning TID only if we are
         * not operating in two-way or histogram mode.
         */
-       if (TwoWayPipeOpt == 0 && histogram == 0) {
+       if (TwoWayPipeOpt == 0 && histogram == 0)
                hammer_get_cycle(&mirror.key_beg, &mirror.tid_beg);
-       }
 
        /*
         * An additional argument overrides the beginning TID regardless
@@ -259,10 +257,9 @@ 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.
@@ -299,12 +296,11 @@ 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: "
@@ -365,13 +361,12 @@ 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));
-               }
        }
 
        /*
@@ -383,10 +378,9 @@ 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,
@@ -421,16 +415,14 @@ 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");
@@ -520,10 +512,9 @@ 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);
 
@@ -606,10 +597,9 @@ 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) /
@@ -711,12 +701,10 @@ create_pfs(const char *filesystem, uuid_t *s_uuid)
                 filesystem, shared_uuid);
        free(shared_uuid);
 
-       if (cmd == NULL) {
+       if (cmd == NULL)
                errx(1, "Failed to alloc memory");
-       }
-       if (system(cmd) != 0) {
+       if (system(cmd) != 0)
                fprintf(stderr, "Failed to create PFS\n");
-       }
        free(cmd);
 }
 
@@ -800,9 +788,8 @@ again:
        /*
         * Create slave PFS if it doesn't yet exist
         */
-       if (lstat(filesystem, &st) != 0) {
+       if (lstat(filesystem, &st) != 0)
                create_pfs(filesystem, &mrec->pfs.pfsd.shared_uuid);
-       }
        free(mrec);
        mrec = NULL;
 
@@ -857,12 +844,11 @@ 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
        }
 
@@ -882,11 +868,10 @@ 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
@@ -899,10 +884,9 @@ 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);
@@ -987,9 +971,8 @@ 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,
@@ -1033,10 +1016,9 @@ 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);
 
        /*
@@ -1097,8 +1079,7 @@ again:
                                xav[xac++] = "-l";
                                xav[xac++] = user;
                                xav[xac++] = host;
-                       }
-                       else {
+                       } else {
                                host = strndup( av[0], (rfs++ - av[0]));
                                user = NULL;
                                xav[xac++] = host;
@@ -1125,9 +1106,8 @@ again:
                                xav[xac++] = "-vvv";
                                break;
                        }
-                       if (ForceYesOpt) {
+                       if (ForceYesOpt)
                                xav[xac++] = "-y";
-                       }
                        xav[xac++] = "-2";
                        if (TimeoutOpt) {
                                snprintf(tbuf, sizeof(tbuf), "%d", TimeoutOpt);
@@ -1179,8 +1159,7 @@ again:
                                xav[xac++] = "-l";
                                xav[xac++] = user;
                                xav[xac++] = host;
-                       }
-                       else {
+                       } else {
                                host = strndup( av[1], (rfs++ - av[1]));
                                user = NULL;
                                xav[xac++] = host;
@@ -1206,9 +1185,8 @@ again:
                                xav[xac++] = "-vvv";
                                break;
                        }
-                       if (ForceYesOpt) {
+                       if (ForceYesOpt)
                                xav[xac++] = "-y";
-                       }
                        xav[xac++] = "-2";
                        xav[xac++] = "mirror-write";
                        xav[xac++] = rfs;
@@ -1301,9 +1279,8 @@ 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.
@@ -1337,10 +1314,9 @@ 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) {
@@ -1684,9 +1660,8 @@ 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 40b3231..e4f623d 100644 (file)
@@ -83,9 +83,8 @@ getlink(const char *path)
                        linkpath[i--] = 0;
                lstat(linkpath, &st);
        }
-       if (S_ISLNK(st.st_mode)) {
+       if (S_ISLNK(st.st_mode))
                return(linkpath);
-       }
 
        free(linkpath);
        return(NULL);
@@ -106,9 +105,8 @@ getpfs(struct hammer_ioc_pseudofs_rw *pfs, const char *path)
         * Extract the PFS id.
         * dirname(path) is supposed to be a directory in root PFS.
         */
-       if (scanpfsid(pfs, path) == 0) {
+       if (scanpfsid(pfs, path) == 0)
                path = dirname(path); /* strips trailing / first if any */
-       }
 
        /*
         * Open the path regardless of scanpfsid() result, since some
@@ -140,13 +138,12 @@ scanpfsid(struct hammer_ioc_pseudofs_rw *pfs, const char *path)
        uintmax_t dummy_tid;
        struct stat st;
 
-       if (stat(path, &st)) {
-               /* possibly slave PFS */
-       } else if (S_ISDIR(st.st_mode)) {
-               /* possibly master or slave PFS */
-       } else {
+       if (stat(path, &st))
+               /* possibly slave PFS */
+       else if (S_ISDIR(st.st_mode))
+               /* possibly master or slave PFS */
+       else
                return(-1);  /* neither */
-       }
 
        linkpath = getlink(path);
        if (linkpath) {
@@ -252,11 +249,10 @@ hammer_cmd_pseudofs_create(char **av, int ac, int is_slave)
        if (ac == 0)
                pseudofs_usage(1);
        path = av[0];
-       if (lstat(path, &st) == 0) {
+       if (lstat(path, &st) == 0)
                errx(1, "Cannot create %s, file exists!", path);
-       } else if (path[strlen(path) - 1] == '/') {
+       else if (path[strlen(path) - 1] == '/')
                errx(1, "Invalid PFS path %s with trailing /", path);
-       }
 
        /*
         * Figure out the directory prefix, taking care of degenerate
@@ -294,11 +290,10 @@ hammer_cmd_pseudofs_create(char **av, int ac, int is_slave)
                        break;
                }
        }
-       if (pfs_id == HAMMER_MAX_PFS) {
+       if (pfs_id == HAMMER_MAX_PFS)
                errx(1, "Cannot create %s, all PFSs in use", path);
-       } else if (pfs_id == HAMMER_ROOT_PFSID) {
+       else if (pfs_id == HAMMER_ROOT_PFSID)
                errx(1, "Fatal error: PFS#%d must exist", HAMMER_ROOT_PFSID);
-       }
 
        /*
         * Create the new PFS
@@ -396,21 +391,19 @@ 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);
 }
 
@@ -424,19 +417,17 @@ hammer_cmd_pseudofs_downgrade(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 downgrade PFS#%d", HAMMER_ROOT_PFSID);
-       } else if (hammer_is_pfs_slave(pfs.ondisk)) {
+       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);
 }
 
@@ -456,19 +447,17 @@ 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");
                }
@@ -510,26 +499,24 @@ 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)) {
+       if (hammer_is_pfs_slave(pfsd))
                printf("    operating as a SLAVE\n");
-       } else {
+       else
                printf("    operating as a MASTER\n");
-       }
 
        /*
         * Snapshots directory cannot be shown when there is no fd since
@@ -543,13 +530,12 @@ 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");
@@ -600,33 +586,29 @@ 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);
                }
-               if (status != uuid_s_ok) {
+               if (status != uuid_s_ok)
                        errx(1, "option %s: error parsing uuid %s", cmd, ptr);
-               }
                --ac;
                ++av;
        }
index 0a34998..327a230 100644 (file)
@@ -88,9 +88,8 @@ hammer_cmd_rebalance(char **av, int ac)
                        filesystem,
                        (uintmax_t)rebal.key_cur.obj_id,
                        rebal.key_cur.localization);
-               if (CyclePath) {
+               if (CyclePath)
                        hammer_set_cycle(&rebal.key_cur, 0);
-               }
        } else {
                if (CyclePath)
                        hammer_reset_cycle();
index 5ac55d6..78ed812 100644 (file)
@@ -117,9 +117,8 @@ hammer_cmd_reblock(char **av, int ac, int flags)
                        filesystem,
                        (uintmax_t)reblock.key_cur.obj_id,
                        reblock.key_cur.localization);
-               if (CyclePath) {
+               if (CyclePath)
                        hammer_set_cycle(&reblock.key_cur, 0);
-               }
        } else {
                if (CyclePath)
                        hammer_reset_cycle();
index a4189da..05f4d87 100644 (file)
@@ -147,10 +147,9 @@ 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 " : "",
@@ -207,12 +206,11 @@ 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);
@@ -294,13 +292,12 @@ 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);
                        }
-               }
        }
 }
 
@@ -369,10 +366,9 @@ 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);
 
                /*
@@ -431,13 +427,12 @@ 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
@@ -463,11 +458,10 @@ recover_elm(hammer_btree_leaf_elm_t leaf)
                 * Create the file if necessary, report file creations
                 */
                path1 = recover_path(dict);
-               if (CachedPath && strcmp(CachedPath, path1) == 0) {
+               if (CachedPath && strcmp(CachedPath, path1) == 0)
                        fd = CachedFd;
-               } else {
+               else
                        fd = open(path1, O_CREAT|O_RDWR, 0666);
-               }
                if (fd < 0) {
                        printf("Unable to create %s: %s\n",
                                path1, strerror(errno));
@@ -493,10 +487,9 @@ 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;
@@ -547,13 +540,12 @@ 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
@@ -620,12 +612,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) {
-               if (dict->obj_id == obj_id &&
-                   dict->pfs_id == pfs_id) {
+       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));
                bzero(dict, sizeof(*dict));
@@ -703,11 +693,10 @@ 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 &&
@@ -719,15 +708,14 @@ 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;
        }
@@ -797,11 +785,10 @@ 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:
@@ -864,11 +851,10 @@ 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 d00bb9b..a781bf0 100644 (file)
@@ -145,15 +145,12 @@ hammer_cmd_show(const char *arg, int filter, int obfuscate, int indent)
                hammer_cleanup_zone_stat(stats);
        }
 
-       if (num_bad_node || VerboseOpt) {
+       if (num_bad_node || VerboseOpt)
                printf("%d bad nodes\n", num_bad_node);
-       }
-       if (num_bad_elm || VerboseOpt) {
+       if (num_bad_elm || VerboseOpt)
                printf("%d bad elms\n", num_bad_elm);
-       }
-       if (num_bad_rec || VerboseOpt) {
+       if (num_bad_rec || VerboseOpt)
                printf("%d bad records\n", num_bad_rec);
-       }
 }
 
 static __inline
@@ -225,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))
@@ -236,7 +233,6 @@ 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) {
@@ -246,13 +242,12 @@ 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);
                                /*
@@ -264,7 +259,6 @@ print_btree_node(hammer_off_t node_offset, hammer_tid_t mirror_tid,
                                        opt.filter = 0;
                        }
                }
-       }
        rel_buffer(buffer);
        depth--;
 }
@@ -487,25 +481,20 @@ get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
                }
                break;
        case HAMMER_BTREE_TYPE_LEAF:
-               if (elm->leaf.data_offset == 0) {
+               if (elm->leaf.data_offset == 0)
                        flags |= FLAG_BADCHILDPARENT;
-               }
-               if (elm->leaf.data_len == 0) {
+               if (elm->leaf.data_len == 0)
                        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);
@@ -636,9 +625,8 @@ check_data_crc(hammer_btree_elm_t elm, const char **whichp)
        data_offset = elm->leaf.data_offset;
        data_len = elm->leaf.data_len;
        data_buffer = NULL;
-       if (data_offset == 0 || data_len == 0) {
+       if (data_offset == 0 || data_len == 0)
                return("ZO");  /* zero offset or length */
-       }
 
        crc = 0;
        switch (elm->leaf.base.rec_type) {
@@ -743,12 +731,11 @@ 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 bf98c48..acc993a 100644 (file)
@@ -92,7 +92,6 @@ 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 */
        }
 
        /*
@@ -100,26 +99,21 @@ 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));
+       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");
-               /* not reached */
-       } else if (version.cur_version < 3) {
+       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;
 
        /*
@@ -127,18 +121,16 @@ 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;
        }
@@ -149,10 +141,9 @@ 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) {
@@ -215,11 +206,9 @@ 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 */
@@ -236,20 +225,16 @@ 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);
@@ -263,11 +248,9 @@ 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) {
@@ -298,7 +281,6 @@ 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)
@@ -342,10 +324,9 @@ 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;
                }
 
@@ -372,14 +353,12 @@ 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 '/' */
@@ -446,19 +425,16 @@ 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));
-               }
         }
 
        /*
@@ -467,9 +443,8 @@ 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);
-               }
        }
 }
 
@@ -489,33 +464,25 @@ 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];
 
@@ -539,14 +506,12 @@ 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;
@@ -555,17 +520,16 @@ 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 99ceb1f..2defbfc 100644 (file)
@@ -175,13 +175,12 @@ 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");
@@ -278,11 +277,10 @@ 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)
@@ -405,15 +403,14 @@ 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);
@@ -541,10 +538,9 @@ 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 {
@@ -626,4 +622,3 @@ softprune_usage(int code)
        exit(code);
 }
 
-
index ee63b2c..d90adbd 100644 (file)
@@ -217,9 +217,8 @@ hammer_cmd_stats(char **av, int ac)
                collect_bstats(&bst1);
                collect_iostats(&ist1);
                if (count) {
-                       if ((count & 15) == 1) {
+                       if ((count & 15) == 1)
                                printf(bstats_title"\t"iostats_title"\n");
-                       }
                        print_bstats(&bst1, &bst2);
                        printf("\t");
                        print_iostats(&ist1, &ist2);
index 040e12c..d45a206 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,9 +134,8 @@ 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 5abab43..39997dd 100644 (file)
@@ -63,11 +63,10 @@ hammer_cmd_synctid(char **av, int ac)
        fd = open(filesystem, O_RDONLY);
        if (fd < 0)
                err(1, "Unable to open %s", filesystem);
-       if (ioctl(fd, HAMMERIOC_SYNCTID, &synctid) < 0) {
+       if (ioctl(fd, HAMMERIOC_SYNCTID, &synctid) < 0)
                err(1, "Synctid %s failed", filesystem);
-       } else {
+       else
                printf("0x%016jx\n", (uintmax_t)synctid.tid);
-       }
        close(fd);
 }
 
index 6879d5e..9521175 100644 (file)
@@ -131,13 +131,12 @@ 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 3d36623..cd3b337 100644 (file)
@@ -155,13 +155,12 @@ 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 e27a5fb..196ee6b 100644 (file)
@@ -61,12 +61,10 @@ 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 e9c4cdb..b2969dc 100644 (file)
@@ -237,10 +237,9 @@ 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");
@@ -251,10 +250,9 @@ 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
@@ -513,15 +511,14 @@ main(int ac, char **av)
                if (ac > 2) {
                        dup = ptr = strdup(av[2]);
                        while ((p = strsep(&ptr, ",")) != NULL) {
-                               if (strcmp(p, "filter") == 0) {
+                               if (strcmp(p, "filter") == 0)
                                        filter = 1;
-                               } else if (strcmp(p, "nofilter") == 0) {
+                               else if (strcmp(p, "nofilter") == 0)
                                        filter = 0;
-                               } else if (strcmp(p, "obfuscate") == 0) {
+                               else if (strcmp(p, "obfuscate") == 0)
                                        obfuscate = 1;
-                               } else if (strcmp(p, "indent") == 0) {
+                               else if (strcmp(p, "indent") == 0)
                                        indent = 1;
-                               }
                        }
                        free(dup);
                }
@@ -576,10 +573,9 @@ __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 fdcb0c1..5159242 100644 (file)
@@ -77,9 +77,8 @@ 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);
 }
 
@@ -88,21 +87,19 @@ 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) {
-               snprintf(buf, sizeof(buf), "%6.2fKB",
-                       (double)size / 1024);
-       } else if (size < 1024 * 1024 * 1024LL / 2) {
+       else if (size < 1024 * 1024 / 2)
+               snprintf(buf, sizeof(buf), "%6.2fKB", (double)size / 1024);
+       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);
 }
 
@@ -149,12 +146,11 @@ 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);
@@ -243,12 +239,11 @@ 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 4d20587..46f85f6 100644 (file)
@@ -116,19 +116,16 @@ __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);
@@ -139,22 +136,18 @@ __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);
-       }
 }
 
 /*
@@ -185,10 +178,9 @@ 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;
 
@@ -228,15 +220,13 @@ 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;
@@ -258,10 +248,9 @@ 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);
 }
@@ -306,14 +295,12 @@ __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);
@@ -404,7 +391,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;
@@ -415,7 +402,6 @@ rel_buffer(struct buffer_info *buffer)
                        free(buffer->ondisk);
                        free(buffer);
                }
-       }
 }
 
 /*
@@ -666,18 +652,16 @@ 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;
             phys_offset += HAMMER_BIGBLOCK_SIZE) {
-               if (phys_offset < vol_free_off) {
+               if (phys_offset < vol_free_off)
                        ;
-               } else if (phys_offset < volume->vol_free_end) {
+               else if (phys_offset < volume->vol_free_end)
                        ++count;
-               }
        }
 
        return(count);
@@ -737,12 +721,10 @@ format_undomap(struct volume_info *root_vol, int64_t *undo_buffer_size)
        limit_index = undo_limit / HAMMER_BIGBLOCK_SIZE;
        assert(limit_index <= HAMMER_MAX_UNDO_BIGBLOCKS);
 
-       for (n = 0; n < limit_index; ++n) {
+       for (n = 0; n < limit_index; ++n)
                ondisk->vol0_undo_array[n] = alloc_undo_bigblock(root_vol);
-       }
-       while (n < HAMMER_MAX_UNDO_BIGBLOCKS) {
+       while (n < HAMMER_MAX_UNDO_BIGBLOCKS)
                ondisk->vol0_undo_array[n++] = HAMMER_BLOCKMAP_UNAVAIL;
-       }
 
        /*
         * Pre-initialize the UNDO blocks (HAMMER version 4+)
@@ -861,10 +843,9 @@ 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);
 }
@@ -942,11 +923,10 @@ int64_t init_boot_area_size(int64_t value, off_t avg_vol_size)
                        value >>= 1;
        }
 
-       if (value < HAMMER_BOOT_MINBYTES) {
+       if (value < HAMMER_BOOT_MINBYTES)
                value = HAMMER_BOOT_MINBYTES;
-       } else if (value > HAMMER_BOOT_MAXBYTES) {
+       else if (value > HAMMER_BOOT_MAXBYTES)
                value = HAMMER_BOOT_MAXBYTES;
-       }
 
        return(value);
 }
@@ -959,11 +939,10 @@ int64_t init_memory_log_size(int64_t value, off_t avg_vol_size)
                        value >>= 1;
        }
 
-       if (value < HAMMER_MEM_MINBYTES) {
+       if (value < HAMMER_MEM_MINBYTES)
                value = HAMMER_MEM_MINBYTES;
-       } else if (value > HAMMER_MEM_MAXBYTES) {
+       else if (value > HAMMER_MEM_MAXBYTES)
                value = HAMMER_MEM_MAXBYTES;
-       }
 
        return(value);
 }
index 97b710a..d52e3b4 100644 (file)
@@ -32,9 +32,8 @@ main(int ac, char **av)
                key = namekey(name);
                ptr = &bitmap[key / 32];
                mask = 1 << (key & 31);
-               if (*ptr & mask) {
+               if (*ptr & mask)
                        break;
-               }
                *ptr |= mask;
                ++count;
        }