diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index a8d68cd03c..433850f42c 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -414,10 +414,9 @@ get_usage(zfs_help_t idx) return (gettext("\tunjail \n")); case HELP_WAIT: return (gettext("\twait [-t ] \n")); + default: + __builtin_unreachable(); } - - abort(); - /* NOTREACHED */ } void diff --git a/cmd/zgenhostid/zgenhostid.c b/cmd/zgenhostid/zgenhostid.c index 4a4ca80e00..853931c6ad 100644 --- a/cmd/zgenhostid/zgenhostid.c +++ b/cmd/zgenhostid/zgenhostid.c @@ -36,7 +36,7 @@ #include #include -static void +static __attribute__((noreturn)) void usage(void) { (void) fprintf(stderr, @@ -51,7 +51,6 @@ usage(void) " will be generated.\n" "The value must be unique among your systems.\n"); exit(EXIT_FAILURE); - /* NOTREACHED */ } int diff --git a/cmd/zhack/zhack.c b/cmd/zhack/zhack.c index c1017ec238..b27423f538 100644 --- a/cmd/zhack/zhack.c +++ b/cmd/zhack/zhack.c @@ -56,7 +56,7 @@ static importargs_t g_importargs; static char *g_pool; static boolean_t g_readonly; -static void +static __attribute__((noreturn)) void usage(void) { (void) fprintf(stderr, @@ -81,7 +81,7 @@ usage(void) } -static void +static __attribute__((noreturn)) __attribute__((format(printf, 3, 4))) void fatal(spa_t *spa, void *tag, const char *fmt, ...) { va_list ap; @@ -112,7 +112,6 @@ space_delta_cb(dmu_object_type_t bonustype, const void *data, return (ENOENT); (void) fprintf(stderr, "modifying object that needs user accounting"); abort(); - /* NOTREACHED */ } /* @@ -318,7 +317,8 @@ zhack_do_feature_enable(int argc, char **argv) mos = spa->spa_meta_objset; if (zfeature_is_supported(feature.fi_guid)) - fatal(spa, FTAG, "'%s' is a real feature, will not enable"); + fatal(spa, FTAG, "'%s' is a real feature, will not enable", + feature.fi_guid); if (0 == zap_contains(mos, spa->spa_feat_desc_obj, feature.fi_guid)) fatal(spa, FTAG, "feature already enabled: %s", feature.fi_guid); @@ -412,7 +412,8 @@ zhack_do_feature_ref(int argc, char **argv) if (zfeature_is_supported(feature.fi_guid)) { fatal(spa, FTAG, - "'%s' is a real feature, will not change refcount"); + "'%s' is a real feature, will not change refcount", + feature.fi_guid); } if (0 == zap_contains(mos, spa->spa_feat_for_read_obj, diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 35a59710c0..897c961252 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -429,10 +429,9 @@ get_usage(zpool_help_t idx) case HELP_WAIT: return (gettext("\twait [-Hp] [-T d|u] [-t [,...]] " " [interval]\n")); + default: + __builtin_unreachable(); } - - abort(); - /* NOTREACHED */ } static void diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index a580396ebd..5a5c381409 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -622,7 +622,7 @@ static void sig_handler(int signo) char *fatal_msg; -static void +static __attribute__((noreturn)) __attribute__((format(printf, 2, 3))) void fatal(int do_perror, char *message, ...) { va_list args; @@ -674,7 +674,6 @@ str2shift(const char *buf) } (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", buf); usage(B_FALSE); - /* NOTREACHED */ } static uint64_t @@ -875,7 +874,7 @@ ztest_random(uint64_t range) return (0); if (read(ztest_fd_rand, &r, sizeof (r)) != sizeof (r)) - fatal(1, "short read from /dev/urandom"); + fatal(B_TRUE, "short read from /dev/urandom"); return (r % range); } @@ -1210,9 +1209,8 @@ ztest_is_draid_spare(const char *name) { uint64_t spare_id = 0, parity = 0, vdev_id = 0; - if (sscanf(name, VDEV_TYPE_DRAID "%llu-%llu-%llu", - (u_longlong_t *)&parity, (u_longlong_t *)&vdev_id, - (u_longlong_t *)&spare_id) == 3) { + if (sscanf(name, VDEV_TYPE_DRAID "%"PRIu64"-%"PRIu64"-%"PRIu64"", + &parity, &vdev_id, &spare_id) == 3) { return (B_TRUE); } @@ -1254,9 +1252,9 @@ make_vdev_file(char *path, char *aux, char *pool, size_t size, uint64_t ashift) if (size != 0 && !draid_spare) { int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666); if (fd == -1) - fatal(1, "can't open %s", path); + fatal(B_TRUE, "can't open %s", path); if (ftruncate(fd, size) != 0) - fatal(1, "can't ftruncate %s", path); + fatal(B_TRUE, "can't ftruncate %s", path); (void) close(fd); } @@ -2841,8 +2839,9 @@ ztest_od_init(ztest_od_t *od, uint64_t id, char *tag, uint64_t index, od->od_blocksize = 0; od->od_gen = 0; - (void) snprintf(od->od_name, sizeof (od->od_name), "%s(%lld)[%llu]", - tag, (longlong_t)id, (u_longlong_t)index); + (void) snprintf(od->od_name, sizeof (od->od_name), + "%s(%"PRId64")[%"PRIu64"]", + tag, id, index); } /* @@ -2985,7 +2984,7 @@ ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id) VERIFY0(spa_open(zo->zo_pool, &spa, FTAG)); int error = spa_destroy(zo->zo_pool); if (error != EBUSY && error != ZFS_ERR_EXPORT_IN_PROGRESS) { - fatal(0, "spa_destroy(%s) returned unexpected value %d", + fatal(B_FALSE, "spa_destroy(%s) returned unexpected value %d", spa->spa_name, error); } spa_close(spa, FTAG); @@ -3108,8 +3107,9 @@ ztest_spa_upgrade(ztest_ds_t *zd, uint64_t id) newversion = ztest_random_spa_version(version + 1); if (ztest_opts.zo_verbose >= 4) { - (void) printf("upgrading spa version from %llu to %llu\n", - (u_longlong_t)version, (u_longlong_t)newversion); + (void) printf("upgrading spa version from " + "%"PRIu64" to %"PRIu64"\n", + version, newversion); } spa_upgrade(spa, newversion); @@ -3139,7 +3139,7 @@ ztest_spa_checkpoint(spa_t *spa) ztest_record_enospc(FTAG); break; default: - fatal(0, "spa_checkpoint(%s) = %d", spa->spa_name, error); + fatal(B_FALSE, "spa_checkpoint(%s) = %d", spa->spa_name, error); } } @@ -3156,7 +3156,7 @@ ztest_spa_discard_checkpoint(spa_t *spa) case ZFS_ERR_NO_CHECKPOINT: break; default: - fatal(0, "spa_discard_checkpoint(%s) = %d", + fatal(B_FALSE, "spa_discard_checkpoint(%s) = %d", spa->spa_name, error); } @@ -3266,7 +3266,7 @@ ztest_vdev_add_remove(ztest_ds_t *zd, uint64_t id) case ZFS_ERR_DISCARDING_CHECKPOINT: break; default: - fatal(0, "spa_vdev_remove() = %d", error); + fatal(B_FALSE, "spa_vdev_remove() = %d", error); } } else { spa_config_exit(spa, SCL_VDEV, FTAG); @@ -3289,7 +3289,7 @@ ztest_vdev_add_remove(ztest_ds_t *zd, uint64_t id) ztest_record_enospc("spa_vdev_add"); break; default: - fatal(0, "spa_vdev_add() = %d", error); + fatal(B_FALSE, "spa_vdev_add() = %d", error); } } @@ -3347,7 +3347,7 @@ ztest_vdev_class_add(ztest_ds_t *zd, uint64_t id) if (error == ENOSPC) ztest_record_enospc("spa_vdev_add"); else if (error != 0) - fatal(0, "spa_vdev_add() = %d", error); + fatal(B_FALSE, "spa_vdev_add() = %d", error); /* * 50% of the time allow small blocks in the special class @@ -3453,7 +3453,7 @@ ztest_vdev_aux_add_remove(ztest_ds_t *zd, uint64_t id) case 0: break; default: - fatal(0, "spa_vdev_add(%p) = %d", nvroot, error); + fatal(B_FALSE, "spa_vdev_add(%p) = %d", nvroot, error); } fnvlist_free(nvroot); } else { @@ -3475,8 +3475,9 @@ ztest_vdev_aux_add_remove(ztest_ds_t *zd, uint64_t id) break; default: if (error != ignore_err) - fatal(0, "spa_vdev_remove(%llu) = %d", guid, - error); + fatal(B_FALSE, + "spa_vdev_remove(%"PRIu64") = %d", + guid, error); } } @@ -3698,7 +3699,8 @@ ztest_vdev_attach_detach(ztest_ds_t *zd, uint64_t id) if (error != 0 && error != ENODEV && error != EBUSY && error != ENOTSUP && error != ZFS_ERR_CHECKPOINT_EXISTS && error != ZFS_ERR_DISCARDING_CHECKPOINT) - fatal(0, "detach (%s) returned %d", oldpath, error); + fatal(B_FALSE, "detach (%s) returned %d", + oldpath, error); goto out; } @@ -3813,7 +3815,7 @@ ztest_vdev_attach_detach(ztest_ds_t *zd, uint64_t id) expected_error = error; if (error != expected_error && expected_error != EBUSY) { - fatal(0, "attach (%s %llu, %s %llu, %d) " + fatal(B_FALSE, "attach (%s %"PRIu64", %s %"PRIu64", %d) " "returned %d, expected %d", oldpath, oldsize, newpath, newsize, replacing, error, expected_error); @@ -3944,8 +3946,8 @@ online_vdev(vdev_t *vd, void *arg) */ if (error || newstate != VDEV_STATE_HEALTHY) { if (ztest_opts.zo_verbose >= 5) { - (void) printf("Unable to expand vdev, state %llu, " - "error %d\n", (u_longlong_t)newstate, error); + (void) printf("Unable to expand vdev, state %u, " + "error %d\n", newstate, error); } return (vd); } @@ -3960,12 +3962,12 @@ online_vdev(vdev_t *vd, void *arg) if (generation != spa->spa_config_generation) { if (ztest_opts.zo_verbose >= 5) { (void) printf("vdev configuration has changed, " - "guid %llu, state %llu, expected gen %llu, " - "got gen %llu\n", - (u_longlong_t)guid, - (u_longlong_t)tvd->vdev_state, - (u_longlong_t)generation, - (u_longlong_t)spa->spa_config_generation); + "guid %"PRIu64", state %"PRIu64", " + "expected gen %"PRIu64", got gen %"PRIu64"\n", + guid, + tvd->vdev_state, + generation, + spa->spa_config_generation); } return (vd); } @@ -4126,7 +4128,8 @@ ztest_vdev_LUN_growth(ztest_ds_t *zd, uint64_t id) * Make sure we were able to grow the vdev. */ if (new_ms_count <= old_ms_count) { - fatal(0, "LUN expansion failed: ms_count %llu < %llu\n", + fatal(B_FALSE, + "LUN expansion failed: ms_count %"PRIu64" < %"PRIu64"\n", old_ms_count, new_ms_count); } @@ -4134,7 +4137,8 @@ ztest_vdev_LUN_growth(ztest_ds_t *zd, uint64_t id) * Make sure we were able to grow the pool. */ if (new_class_space <= old_class_space) { - fatal(0, "LUN expansion failed: class_space %llu < %llu\n", + fatal(B_FALSE, + "LUN expansion failed: class_space %"PRIu64" < %"PRIu64"\n", old_class_space, new_class_space); } @@ -4281,7 +4285,7 @@ ztest_snapshot_create(char *osname, uint64_t id) char snapname[ZFS_MAX_DATASET_NAME_LEN]; int error; - (void) snprintf(snapname, sizeof (snapname), "%llu", (u_longlong_t)id); + (void) snprintf(snapname, sizeof (snapname), "%"PRIu64"", id); error = dmu_objset_snapshot_one(osname, snapname); if (error == ENOSPC) { @@ -4289,7 +4293,7 @@ ztest_snapshot_create(char *osname, uint64_t id) return (B_FALSE); } if (error != 0 && error != EEXIST) { - fatal(0, "ztest_snapshot_create(%s@%s) = %d", osname, + fatal(B_FALSE, "ztest_snapshot_create(%s@%s) = %d", osname, snapname, error); } return (B_TRUE); @@ -4301,12 +4305,13 @@ ztest_snapshot_destroy(char *osname, uint64_t id) char snapname[ZFS_MAX_DATASET_NAME_LEN]; int error; - (void) snprintf(snapname, sizeof (snapname), "%s@%llu", osname, - (u_longlong_t)id); + (void) snprintf(snapname, sizeof (snapname), "%s@%"PRIu64"", + osname, id); error = dsl_destroy_snapshot(snapname, B_FALSE); if (error != 0 && error != ENOENT) - fatal(0, "ztest_snapshot_destroy(%s) = %d", snapname, error); + fatal(B_FALSE, "ztest_snapshot_destroy(%s) = %d", + snapname, error); return (B_TRUE); } @@ -4326,8 +4331,8 @@ ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id) (void) pthread_rwlock_rdlock(&ztest_name_lock); - (void) snprintf(name, sizeof (name), "%s/temp_%llu", - ztest_opts.zo_pool, (u_longlong_t)id); + (void) snprintf(name, sizeof (name), "%s/temp_%"PRIu64"", + ztest_opts.zo_pool, id); /* * If this dataset exists from a previous run, process its replay log @@ -4366,7 +4371,7 @@ ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id) ztest_record_enospc(FTAG); goto out; } - fatal(0, "dmu_objset_create(%s) = %d", name, error); + fatal(B_FALSE, "dmu_objset_create(%s) = %d", name, error); } VERIFY0(ztest_dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, B_TRUE, @@ -4448,32 +4453,35 @@ ztest_dsl_dataset_cleanup(char *osname, uint64_t id) clone2name = umem_alloc(ZFS_MAX_DATASET_NAME_LEN, UMEM_NOFAIL); snap3name = umem_alloc(ZFS_MAX_DATASET_NAME_LEN, UMEM_NOFAIL); - (void) snprintf(snap1name, ZFS_MAX_DATASET_NAME_LEN, - "%s@s1_%llu", osname, (u_longlong_t)id); - (void) snprintf(clone1name, ZFS_MAX_DATASET_NAME_LEN, - "%s/c1_%llu", osname, (u_longlong_t)id); - (void) snprintf(snap2name, ZFS_MAX_DATASET_NAME_LEN, - "%s@s2_%llu", clone1name, (u_longlong_t)id); - (void) snprintf(clone2name, ZFS_MAX_DATASET_NAME_LEN, - "%s/c2_%llu", osname, (u_longlong_t)id); - (void) snprintf(snap3name, ZFS_MAX_DATASET_NAME_LEN, - "%s@s3_%llu", clone1name, (u_longlong_t)id); + (void) snprintf(snap1name, ZFS_MAX_DATASET_NAME_LEN, "%s@s1_%"PRIu64"", + osname, id); + (void) snprintf(clone1name, ZFS_MAX_DATASET_NAME_LEN, "%s/c1_%"PRIu64"", + osname, id); + (void) snprintf(snap2name, ZFS_MAX_DATASET_NAME_LEN, "%s@s2_%"PRIu64"", + clone1name, id); + (void) snprintf(clone2name, ZFS_MAX_DATASET_NAME_LEN, "%s/c2_%"PRIu64"", + osname, id); + (void) snprintf(snap3name, ZFS_MAX_DATASET_NAME_LEN, "%s@s3_%"PRIu64"", + clone1name, id); error = dsl_destroy_head(clone2name); if (error && error != ENOENT) - fatal(0, "dsl_destroy_head(%s) = %d", clone2name, error); + fatal(B_FALSE, "dsl_destroy_head(%s) = %d", clone2name, error); error = dsl_destroy_snapshot(snap3name, B_FALSE); if (error && error != ENOENT) - fatal(0, "dsl_destroy_snapshot(%s) = %d", snap3name, error); + fatal(B_FALSE, "dsl_destroy_snapshot(%s) = %d", + snap3name, error); error = dsl_destroy_snapshot(snap2name, B_FALSE); if (error && error != ENOENT) - fatal(0, "dsl_destroy_snapshot(%s) = %d", snap2name, error); + fatal(B_FALSE, "dsl_destroy_snapshot(%s) = %d", + snap2name, error); error = dsl_destroy_head(clone1name); if (error && error != ENOENT) - fatal(0, "dsl_destroy_head(%s) = %d", clone1name, error); + fatal(B_FALSE, "dsl_destroy_head(%s) = %d", clone1name, error); error = dsl_destroy_snapshot(snap1name, B_FALSE); if (error && error != ENOENT) - fatal(0, "dsl_destroy_snapshot(%s) = %d", snap1name, error); + fatal(B_FALSE, "dsl_destroy_snapshot(%s) = %d", + snap1name, error); umem_free(snap1name, ZFS_MAX_DATASET_NAME_LEN); umem_free(clone1name, ZFS_MAX_DATASET_NAME_LEN); @@ -4507,16 +4515,16 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) ztest_dsl_dataset_cleanup(osname, id); - (void) snprintf(snap1name, ZFS_MAX_DATASET_NAME_LEN, - "%s@s1_%llu", osname, (u_longlong_t)id); - (void) snprintf(clone1name, ZFS_MAX_DATASET_NAME_LEN, - "%s/c1_%llu", osname, (u_longlong_t)id); - (void) snprintf(snap2name, ZFS_MAX_DATASET_NAME_LEN, - "%s@s2_%llu", clone1name, (u_longlong_t)id); - (void) snprintf(clone2name, ZFS_MAX_DATASET_NAME_LEN, - "%s/c2_%llu", osname, (u_longlong_t)id); - (void) snprintf(snap3name, ZFS_MAX_DATASET_NAME_LEN, - "%s@s3_%llu", clone1name, (u_longlong_t)id); + (void) snprintf(snap1name, ZFS_MAX_DATASET_NAME_LEN, "%s@s1_%"PRIu64"", + osname, id); + (void) snprintf(clone1name, ZFS_MAX_DATASET_NAME_LEN, "%s/c1_%"PRIu64"", + osname, id); + (void) snprintf(snap2name, ZFS_MAX_DATASET_NAME_LEN, "%s@s2_%"PRIu64"", + clone1name, id); + (void) snprintf(clone2name, ZFS_MAX_DATASET_NAME_LEN, "%s/c2_%"PRIu64"", + osname, id); + (void) snprintf(snap3name, ZFS_MAX_DATASET_NAME_LEN, "%s@s3_%"PRIu64"", + clone1name, id); error = dmu_objset_snapshot_one(osname, strchr(snap1name, '@') + 1); if (error && error != EEXIST) { @@ -4524,7 +4532,7 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) ztest_record_enospc(FTAG); goto out; } - fatal(0, "dmu_take_snapshot(%s) = %d", snap1name, error); + fatal(B_FALSE, "dmu_take_snapshot(%s) = %d", snap1name, error); } error = dmu_objset_clone(clone1name, snap1name); @@ -4533,7 +4541,7 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) ztest_record_enospc(FTAG); goto out; } - fatal(0, "dmu_objset_create(%s) = %d", clone1name, error); + fatal(B_FALSE, "dmu_objset_create(%s) = %d", clone1name, error); } error = dmu_objset_snapshot_one(clone1name, strchr(snap2name, '@') + 1); @@ -4542,7 +4550,7 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) ztest_record_enospc(FTAG); goto out; } - fatal(0, "dmu_open_snapshot(%s) = %d", snap2name, error); + fatal(B_FALSE, "dmu_open_snapshot(%s) = %d", snap2name, error); } error = dmu_objset_snapshot_one(clone1name, strchr(snap3name, '@') + 1); @@ -4551,7 +4559,7 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) ztest_record_enospc(FTAG); goto out; } - fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error); + fatal(B_FALSE, "dmu_open_snapshot(%s) = %d", snap3name, error); } error = dmu_objset_clone(clone2name, snap3name); @@ -4560,13 +4568,13 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) ztest_record_enospc(FTAG); goto out; } - fatal(0, "dmu_objset_create(%s) = %d", clone2name, error); + fatal(B_FALSE, "dmu_objset_create(%s) = %d", clone2name, error); } error = ztest_dmu_objset_own(snap2name, DMU_OST_ANY, B_TRUE, B_TRUE, FTAG, &os); if (error) - fatal(0, "dmu_objset_own(%s) = %d", snap2name, error); + fatal(B_FALSE, "dmu_objset_own(%s) = %d", snap2name, error); error = dsl_dataset_promote(clone2name, NULL); if (error == ENOSPC) { dmu_objset_disown(os, B_TRUE, FTAG); @@ -4574,8 +4582,8 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id) goto out; } if (error != EBUSY) - fatal(0, "dsl_dataset_promote(%s), %d, not EBUSY", clone2name, - error); + fatal(B_FALSE, "dsl_dataset_promote(%s), %d, not EBUSY", + clone2name, error); dmu_objset_disown(os, B_TRUE, FTAG); out: @@ -4662,8 +4670,8 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id) size = sizeof (ztest_od_t) * OD_ARRAY_SIZE; od = umem_alloc(size, UMEM_NOFAIL); dmu_tx_t *tx; - int i, freeit, error; - uint64_t n, s, txg; + int freeit, error; + uint64_t i, n, s, txg; bufwad_t *packbuf, *bigbuf, *pack, *bigH, *bigT; uint64_t packobj, packoff, packsize, bigobj, bigoff, bigsize; uint64_t chunksize = (1000 + ztest_random(1000)) * sizeof (uint64_t); @@ -4810,18 +4818,22 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id) ASSERT3U((uintptr_t)bigT - (uintptr_t)bigbuf, <, bigsize); if (pack->bw_txg > txg) - fatal(0, "future leak: got %llx, open txg is %llx", + fatal(B_FALSE, + "future leak: got %"PRIx64", open txg is %"PRIx64"", pack->bw_txg, txg); if (pack->bw_data != 0 && pack->bw_index != n + i) - fatal(0, "wrong index: got %llx, wanted %llx+%llx", + fatal(B_FALSE, "wrong index: " + "got %"PRIx64", wanted %"PRIx64"+%"PRIx64"", pack->bw_index, n, i); if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0) - fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH); + fatal(B_FALSE, "pack/bigH mismatch in %p/%p", + pack, bigH); if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0) - fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT); + fatal(B_FALSE, "pack/bigT mismatch in %p/%p", + pack, bigT); if (freeit) { bzero(pack, sizeof (bufwad_t)); @@ -4842,20 +4854,16 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id) if (freeit) { if (ztest_opts.zo_verbose >= 7) { - (void) printf("freeing offset %llx size %llx" - " txg %llx\n", - (u_longlong_t)bigoff, - (u_longlong_t)bigsize, - (u_longlong_t)txg); + (void) printf("freeing offset %"PRIx64" size %"PRIx64"" + " txg %"PRIx64"\n", + bigoff, bigsize, txg); } VERIFY0(dmu_free_range(os, bigobj, bigoff, bigsize, tx)); } else { if (ztest_opts.zo_verbose >= 7) { - (void) printf("writing offset %llx size %llx" - " txg %llx\n", - (u_longlong_t)bigoff, - (u_longlong_t)bigsize, - (u_longlong_t)txg); + (void) printf("writing offset %"PRIx64" size %"PRIx64"" + " txg %"PRIx64"\n", + bigoff, bigsize, txg); } dmu_write(os, bigobj, bigoff, bigsize, bigbuf, tx); } @@ -4913,18 +4921,22 @@ compare_and_update_pbbufs(uint64_t s, bufwad_t *packbuf, bufwad_t *bigbuf, ASSERT3U((uintptr_t)bigT - (uintptr_t)bigbuf, <, bigsize); if (pack->bw_txg > txg) - fatal(0, "future leak: got %llx, open txg is %llx", + fatal(B_FALSE, + "future leak: got %"PRIx64", open txg is %"PRIx64"", pack->bw_txg, txg); if (pack->bw_data != 0 && pack->bw_index != n + i) - fatal(0, "wrong index: got %llx, wanted %llx+%llx", + fatal(B_FALSE, "wrong index: " + "got %"PRIx64", wanted %"PRIx64"+%"PRIx64"", pack->bw_index, n, i); if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0) - fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH); + fatal(B_FALSE, "pack/bigH mismatch in %p/%p", + pack, bigH); if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0) - fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT); + fatal(B_FALSE, "pack/bigT mismatch in %p/%p", + pack, bigT); pack->bw_index = n + i; pack->bw_txg = txg; @@ -5103,11 +5115,9 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id) */ dmu_write(os, packobj, packoff, packsize, packbuf, tx); if (ztest_opts.zo_verbose >= 7) { - (void) printf("writing offset %llx size %llx" - " txg %llx\n", - (u_longlong_t)bigoff, - (u_longlong_t)bigsize, - (u_longlong_t)txg); + (void) printf("writing offset %"PRIx64" size %"PRIx64"" + " txg %"PRIx64"\n", + bigoff, bigsize, txg); } for (off = bigoff, j = 0; j < s; j++, off += chunksize) { dmu_buf_t *dbt; @@ -5308,8 +5318,8 @@ ztest_zap(ztest_ds_t *zd, uint64_t id) ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS); prop = ztest_random(ZTEST_ZAP_MAX_PROPS); - (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop); - (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop); + (void) sprintf(propname, "prop_%"PRIu64"", prop); + (void) sprintf(txgname, "txg_%"PRIu64"", prop); bzero(value, sizeof (value)); last_txg = 0; @@ -5354,7 +5364,8 @@ ztest_zap(ztest_ds_t *zd, uint64_t id) goto out; if (last_txg > txg) - fatal(0, "zap future leak: old %llu new %llu", last_txg, txg); + fatal(B_FALSE, "zap future leak: old %"PRIu64" new %"PRIu64"", + last_txg, txg); for (i = 0; i < ints; i++) value[i] = txg + object + i; @@ -5370,8 +5381,8 @@ ztest_zap(ztest_ds_t *zd, uint64_t id) * Remove a random pair of entries. */ prop = ztest_random(ZTEST_ZAP_MAX_PROPS); - (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop); - (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop); + (void) sprintf(propname, "prop_%"PRIu64"", prop); + (void) sprintf(txgname, "txg_%"PRIu64"", prop); error = zap_length(os, object, txgname, &zl_intsize, &zl_ints); @@ -5400,8 +5411,7 @@ ztest_fzap(ztest_ds_t *zd, uint64_t id) { objset_t *os = zd->zd_os; ztest_od_t *od; - uint64_t object, txg; - int i; + uint64_t object, txg, value; od = umem_alloc(sizeof (ztest_od_t), UMEM_NOFAIL); ztest_od_init(od, id, FTAG, 0, DMU_OT_ZAP_OTHER, 0, 0, 0); @@ -5416,14 +5426,13 @@ ztest_fzap(ztest_ds_t *zd, uint64_t id) * and gets upgraded to a fatzap. Also, since we are adding * 2050 entries we should see ptrtbl growth and leaf-block split. */ - for (i = 0; i < 2050; i++) { + for (value = 0; value < 2050; value++) { char name[ZFS_MAX_DATASET_NAME_LEN]; - uint64_t value = i; dmu_tx_t *tx; int error; - (void) snprintf(name, sizeof (name), "fzap-%llu-%llu", - (u_longlong_t)id, (u_longlong_t)value); + (void) snprintf(name, sizeof (name), "fzap-%"PRIu64"-%"PRIu64"", + id, value); tx = dmu_tx_create(os); dmu_tx_hold_zap(tx, object, B_TRUE, name); @@ -5527,8 +5536,8 @@ ztest_zap_parallel(ztest_ds_t *zd, uint64_t id) if (error == 0) { if (data == string_value && bcmp(name, data, namelen) != 0) - fatal(0, "name '%s' != val '%s' len %d", - name, data, namelen); + fatal(B_FALSE, "name '%s' != val '%s' len %d", + name, (char *)data, namelen); } else { ASSERT3U(error, ==, ENOENT); } @@ -5580,9 +5589,10 @@ ztest_commit_callback(void *arg, int error) synced_txg = spa_last_synced_txg(data->zcd_spa); if (data->zcd_txg > synced_txg) - fatal(0, "commit callback of txg %" PRIu64 " called prematurely" - ", last synced txg = %" PRIu64 "\n", data->zcd_txg, - synced_txg); + fatal(B_FALSE, + "commit callback of txg %"PRIu64" called prematurely, " + "last synced txg = %"PRIu64"\n", + data->zcd_txg, synced_txg); data->zcd_called = B_TRUE; @@ -5704,7 +5714,8 @@ ztest_dmu_commit_callbacks(ztest_ds_t *zd, uint64_t id) &old_txg, DMU_READ_PREFETCH)); if (old_txg > txg) - fatal(0, "future leak: got %" PRIu64 ", open txg is %" PRIu64, + fatal(B_FALSE, + "future leak: got %"PRIu64", open txg is %"PRIu64"", old_txg, txg); dmu_write(os, od->od_object, 0, sizeof (uint64_t), &txg, tx); @@ -5726,8 +5737,10 @@ ztest_dmu_commit_callbacks(ztest_ds_t *zd, uint64_t id) tmp_cb = list_head(&zcl.zcl_callbacks); if (tmp_cb != NULL && tmp_cb->zcd_txg + ZTEST_COMMIT_CB_THRESH < txg) { - fatal(0, "Commit callback threshold exceeded, oldest txg: %" - PRIu64 ", open txg: %" PRIu64 "\n", tmp_cb->zcd_txg, txg); + fatal(B_FALSE, + "Commit callback threshold exceeded, " + "oldest txg: %"PRIu64", open txg: %"PRIu64"\n", + tmp_cb->zcd_txg, txg); } /* @@ -5885,12 +5898,11 @@ ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id) dmu_objset_name(os, osname); - (void) snprintf(snapname, sizeof (snapname), "sh1_%llu", - (u_longlong_t)id); + (void) snprintf(snapname, sizeof (snapname), "sh1_%"PRIu64"", id); (void) snprintf(fullname, sizeof (fullname), "%s@%s", osname, snapname); - (void) snprintf(clonename, sizeof (clonename), - "%s/ch1_%llu", osname, (u_longlong_t)id); - (void) snprintf(tag, sizeof (tag), "tag_%llu", (u_longlong_t)id); + (void) snprintf(clonename, sizeof (clonename), "%s/ch1_%"PRIu64"", + osname, id); + (void) snprintf(tag, sizeof (tag), "tag_%"PRIu64"", id); /* * Clean up from any previous run. @@ -5915,7 +5927,7 @@ ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id) ztest_record_enospc("dmu_objset_snapshot"); goto out; } - fatal(0, "dmu_objset_snapshot(%s) = %d", fullname, error); + fatal(B_FALSE, "dmu_objset_snapshot(%s) = %d", fullname, error); } error = dmu_objset_clone(clonename, fullname); @@ -5924,22 +5936,22 @@ ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id) ztest_record_enospc("dmu_objset_clone"); goto out; } - fatal(0, "dmu_objset_clone(%s) = %d", clonename, error); + fatal(B_FALSE, "dmu_objset_clone(%s) = %d", clonename, error); } error = dsl_destroy_snapshot(fullname, B_TRUE); if (error) { - fatal(0, "dsl_destroy_snapshot(%s, B_TRUE) = %d", + fatal(B_FALSE, "dsl_destroy_snapshot(%s, B_TRUE) = %d", fullname, error); } error = dsl_destroy_head(clonename); if (error) - fatal(0, "dsl_destroy_head(%s) = %d", clonename, error); + fatal(B_FALSE, "dsl_destroy_head(%s) = %d", clonename, error); error = dmu_objset_hold(fullname, FTAG, &origin); if (error != ENOENT) - fatal(0, "dmu_objset_hold(%s) = %d", fullname, error); + fatal(B_FALSE, "dmu_objset_hold(%s) = %d", fullname, error); /* * Create snapshot, add temporary hold, verify that we can't @@ -5952,7 +5964,7 @@ ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id) ztest_record_enospc("dmu_objset_snapshot"); goto out; } - fatal(0, "dmu_objset_snapshot(%s) = %d", fullname, error); + fatal(B_FALSE, "dmu_objset_snapshot(%s) = %d", fullname, error); } holds = fnvlist_alloc(); @@ -5964,25 +5976,26 @@ ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id) ztest_record_enospc("dsl_dataset_user_hold"); goto out; } else if (error) { - fatal(0, "dsl_dataset_user_hold(%s, %s) = %u", + fatal(B_FALSE, "dsl_dataset_user_hold(%s, %s) = %u", fullname, tag, error); } error = dsl_destroy_snapshot(fullname, B_FALSE); if (error != EBUSY) { - fatal(0, "dsl_destroy_snapshot(%s, B_FALSE) = %d", + fatal(B_FALSE, "dsl_destroy_snapshot(%s, B_FALSE) = %d", fullname, error); } error = dsl_destroy_snapshot(fullname, B_TRUE); if (error) { - fatal(0, "dsl_destroy_snapshot(%s, B_TRUE) = %d", + fatal(B_FALSE, "dsl_destroy_snapshot(%s, B_TRUE) = %d", fullname, error); } error = user_release_one(fullname, tag); if (error) - fatal(0, "user_release_one(%s, %s) = %d", fullname, tag, error); + fatal(B_FALSE, "user_release_one(%s, %s) = %d", + fullname, tag, error); VERIFY3U(dmu_objset_hold(fullname, FTAG, &origin), ==, ENOENT); @@ -6263,14 +6276,15 @@ ztest_fault_inject(ztest_ds_t *zd, uint64_t id) } if (pwrite(fd, &bad, sizeof (bad), offset) != sizeof (bad)) - fatal(1, "can't inject bad word at 0x%llx in %s", + fatal(B_TRUE, + "can't inject bad word at 0x%"PRIx64" in %s", offset, pathrand); mutex_exit(&ztest_vdev_lock); if (ztest_opts.zo_verbose >= 7) (void) printf("injected bad word into %s," - " offset 0x%llx\n", pathrand, (u_longlong_t)offset); + " offset 0x%"PRIx64"\n", pathrand, offset); } (void) close(fd); @@ -6358,8 +6372,8 @@ ztest_reguid(ztest_ds_t *zd, uint64_t id) return; if (ztest_opts.zo_verbose >= 4) { - (void) printf("Changed guid old %llu -> %llu\n", - (u_longlong_t)orig, (u_longlong_t)spa_guid(spa)); + (void) printf("Changed guid old %"PRIu64" -> %"PRIu64"\n", + orig, spa_guid(spa)); } VERIFY3U(orig, !=, spa_guid(spa)); @@ -6600,7 +6614,7 @@ ztest_get_zdb_bin(char *bin, int len) strlcpy(bin, zdb_path, len); /* In env */ if (!ztest_check_path(bin)) { ztest_dump_core = 0; - fatal(1, "invalid ZDB_PATH '%s'", bin); + fatal(B_TRUE, "invalid ZDB_PATH '%s'", bin); } return; } @@ -6840,9 +6854,10 @@ ztest_run_zdb(char *pool) ztest_dump_core = 0; if (WIFEXITED(status)) - fatal(0, "'%s' exit code %d", zdb, WEXITSTATUS(status)); + fatal(B_FALSE, "'%s' exit code %d", zdb, WEXITSTATUS(status)); else - fatal(0, "'%s' died with signal %d", zdb, WTERMSIG(status)); + fatal(B_FALSE, "'%s' died with signal %d", + zdb, WTERMSIG(status)); out: umem_free(bin, len); umem_free(zdb, len); @@ -7013,7 +7028,8 @@ ztest_deadman_thread(void *arg) * I/Os then it will end up aborting the tests. */ if (spa_suspended(spa) || spa->spa_root_vdev == NULL) { - fatal(0, "aborting test after %llu seconds because " + fatal(B_FALSE, + "aborting test after %lu seconds because " "pool has transitioned to a suspended state.", zfs_deadman_synctime_ms / 1000); } @@ -7026,7 +7042,8 @@ ztest_deadman_thread(void *arg) */ overdue = zs->zs_proc_stop + MSEC2NSEC(zfs_deadman_synctime_ms); if (gethrtime() > overdue) { - fatal(0, "aborting test after %llu seconds because " + fatal(B_FALSE, + "aborting test after %llu seconds because " "the process is overdue for termination.", (gethrtime() - zs->zs_proc_start) / NANOSEC); } @@ -7187,7 +7204,8 @@ ztest_dataset_open(int d) if (zilog->zl_header->zh_claim_lr_seq != 0 && zilog->zl_header->zh_claim_lr_seq < committed_seq) - fatal(0, "missing log records: claimed %llu < committed %llu", + fatal(B_FALSE, "missing log records: " + "claimed %"PRIu64" < committed %"PRIu64"", zilog->zl_header->zh_claim_lr_seq, committed_seq); ztest_dataset_dirobj_verify(zd); @@ -7197,17 +7215,19 @@ ztest_dataset_open(int d) ztest_dataset_dirobj_verify(zd); if (ztest_opts.zo_verbose >= 6) - (void) printf("%s replay %llu blocks, %llu records, seq %llu\n", + (void) printf("%s replay %"PRIu64" blocks, " + "%"PRIu64" records, seq %"PRIu64"\n", zd->zd_name, - (u_longlong_t)zilog->zl_parse_blk_count, - (u_longlong_t)zilog->zl_parse_lr_count, - (u_longlong_t)zilog->zl_replaying_seq); + zilog->zl_parse_blk_count, + zilog->zl_parse_lr_count, + zilog->zl_replaying_seq); zilog = zil_open(os, ztest_get_data); if (zilog->zl_replaying_seq != 0 && zilog->zl_replaying_seq < committed_seq) - fatal(0, "missing log records: replayed %llu < committed %llu", + fatal(B_FALSE, "missing log records: " + "replayed %"PRIu64" < committed %"PRIu64"", zilog->zl_replaying_seq, committed_seq); return (0); @@ -7244,11 +7264,12 @@ ztest_replay_zil_cb(const char *name, void *arg) ztest_opts.zo_verbose >= 6) { zilog_t *zilog = dmu_objset_zil(os); - (void) printf("%s replay %llu blocks, %llu records, seq %llu\n", + (void) printf("%s replay %"PRIu64" blocks, " + "%"PRIu64" records, seq %"PRIu64"\n", name, - (u_longlong_t)zilog->zl_parse_blk_count, - (u_longlong_t)zilog->zl_parse_lr_count, - (u_longlong_t)zilog->zl_replaying_seq); + zilog->zl_parse_blk_count, + zilog->zl_parse_lr_count, + zilog->zl_replaying_seq); } umem_free(zdtmp, sizeof (ztest_ds_t)); @@ -7845,7 +7866,7 @@ exec_child(char *cmd, char *libpath, boolean_t ignorekill, int *statusp) } if (pid == -1) - fatal(1, "fork failed"); + fatal(B_TRUE, "fork failed"); if (pid == 0) { /* child */ char *emptyargv[2] = { cmd, NULL }; @@ -7894,7 +7915,6 @@ exec_child(char *cmd, char *libpath, boolean_t ignorekill, int *statusp) } else { (void) fprintf(stderr, "something strange happened to child\n"); exit(4); - /* NOTREACHED */ } } @@ -8044,14 +8064,14 @@ main(int argc, char **argv) hasalt = (strlen(ztest_opts.zo_alt_ztest) != 0); if (ztest_opts.zo_verbose >= 1) { - (void) printf("%llu vdevs, %d datasets, %d threads," - "%d %s disks, %llu seconds...\n\n", - (u_longlong_t)ztest_opts.zo_vdevs, + (void) printf("%"PRIu64" vdevs, %d datasets, %d threads," + "%d %s disks, %"PRIu64" seconds...\n\n", + ztest_opts.zo_vdevs, ztest_opts.zo_datasets, ztest_opts.zo_threads, ztest_opts.zo_raid_children, ztest_opts.zo_raid_type, - (u_longlong_t)ztest_opts.zo_time); + ztest_opts.zo_time); } cmd = umem_alloc(MAXNAMELEN, UMEM_NOFAIL); @@ -8133,11 +8153,11 @@ main(int argc, char **argv) print_time(zs->zs_proc_stop - now, timebuf); nicenum(zs->zs_space, numbuf, sizeof (numbuf)); - (void) printf("Pass %3d, %8s, %3llu ENOSPC, " + (void) printf("Pass %3d, %8s, %3"PRIu64" ENOSPC, " "%4.1f%% of %5s used, %3.0f%% done, %8s to go\n", iters, WIFEXITED(status) ? "Complete" : "SIGKILL", - (u_longlong_t)zs->zs_enospc_count, + zs->zs_enospc_count, 100.0 * zs->zs_alloc / zs->zs_space, numbuf, 100.0 * (now - zs->zs_proc_start) / @@ -8154,8 +8174,8 @@ main(int argc, char **argv) zi = &ztest_info[f]; zc = ZTEST_GET_SHARED_CALLSTATE(f); print_time(zc->zc_time, timebuf); - (void) printf("%7llu %9s %s\n", - (u_longlong_t)zc->zc_count, timebuf, + (void) printf("%7"PRIu64" %9s %s\n", + zc->zc_count, timebuf, zi->zi_funcname); } (void) printf("\n"); diff --git a/module/os/freebsd/zfs/zfs_ctldir.c b/module/os/freebsd/zfs/zfs_ctldir.c index a9fe1b6472..3b405e9d68 100644 --- a/module/os/freebsd/zfs/zfs_ctldir.c +++ b/module/os/freebsd/zfs/zfs_ctldir.c @@ -1084,7 +1084,7 @@ zfsctl_snapdir_readdir(struct vop_readdir_args *ap) } zfs_uio_setoffset(&uio, cookie + dots_offset); } - /* NOTREACHED */ + __builtin_unreachable(); } static int diff --git a/module/zfs/zfs_log.c b/module/zfs/zfs_log.c index 6d2e41ad93..e248dc3cc4 100644 --- a/module/zfs/zfs_log.c +++ b/module/zfs/zfs_log.c @@ -79,7 +79,6 @@ zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap) return (TX_CREATE_ACL); else return (TX_CREATE_ATTR); - /*NOTREACHED*/ case Z_DIR: if (vsecp == NULL && !isxvattr) return (TX_MKDIR); diff --git a/tests/zfs-tests/cmd/mkbusy/Makefile.am b/tests/zfs-tests/cmd/mkbusy/Makefile.am index abae69dea8..8d5885e084 100644 --- a/tests/zfs-tests/cmd/mkbusy/Makefile.am +++ b/tests/zfs-tests/cmd/mkbusy/Makefile.am @@ -4,3 +4,5 @@ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin pkgexec_PROGRAMS = mkbusy mkbusy_SOURCES = mkbusy.c + +mkbusy_LDADD = $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la diff --git a/tests/zfs-tests/cmd/mkbusy/mkbusy.c b/tests/zfs-tests/cmd/mkbusy/mkbusy.c index a03076ffc0..ab2856b3f7 100644 --- a/tests/zfs-tests/cmd/mkbusy/mkbusy.c +++ b/tests/zfs-tests/cmd/mkbusy/mkbusy.c @@ -29,19 +29,21 @@ #include #include #include +#include -static void + +static __attribute__((noreturn)) void usage(char *progname) { (void) fprintf(stderr, "Usage: %s \n", progname); exit(1); } -static void -fail(char *err, int rval) +static __attribute__((noreturn)) void +fail(char *err) { perror(err); - exit(rval); + exit(1); } static void @@ -50,7 +52,7 @@ daemonize(void) pid_t pid; if ((pid = fork()) < 0) { - fail("fork", 1); + fail("fork"); } else if (pid != 0) { (void) fprintf(stdout, "%ld\n", (long)pid); exit(0); @@ -65,24 +67,14 @@ daemonize(void) int main(int argc, char *argv[]) { - int ret, c; + int c; boolean_t isdir = B_FALSE; - boolean_t fflag = B_FALSE; - boolean_t rflag = B_FALSE; struct stat sbuf; char *fpath = NULL; char *prog = argv[0]; - while ((c = getopt(argc, argv, "fr")) != -1) { + while ((c = getopt(argc, argv, "")) != -1) { switch (c) { - /* Open the file or directory read only */ - case 'r': - rflag = B_TRUE; - break; - /* Run in the foreground */ - case 'f': - fflag = B_TRUE; - break; default: usage(prog); } @@ -94,84 +86,68 @@ main(int argc, char *argv[]) if (argc != 1) usage(prog); - if ((ret = stat(argv[0], &sbuf)) != 0) { - char *arg, *dname, *fname; - int arglen; - char *slash; - int rc; + if (stat(argv[0], &sbuf) != 0) { + char *arg; + const char *dname, *fname; + size_t arglen; + ssize_t dnamelen; /* * The argument supplied doesn't exist. Copy the path, and * remove the trailing slash if present. */ if ((arg = strdup(argv[0])) == NULL) - fail("strdup", 1); + fail("strdup"); arglen = strlen(arg); if (arg[arglen - 1] == '/') arg[arglen - 1] = '\0'; - /* - * Get the directory and file names, using the current directory - * if the provided path doesn't specify a directory at all. - */ - if ((slash = strrchr(arg, '/')) == NULL) { - dname = strdup("."); - fname = strdup(arg); - } else { - *slash = '\0'; - dname = strdup(arg); - fname = strdup(slash + 1); - } - free(arg); - if (dname == NULL || fname == NULL) - fail("strdup", 1); + /* Get the directory and file names. */ + fname = zfs_basename(arg); + dname = arg; + if ((dnamelen = zfs_dirnamelen(arg)) != -1) + arg[dnamelen] = '\0'; + else + dname = "."; /* The directory portion of the path must exist */ - if ((ret = stat(dname, &sbuf)) != 0 || !(sbuf.st_mode & - S_IFDIR)) + if (stat(dname, &sbuf) != 0 || !(sbuf.st_mode & S_IFDIR)) usage(prog); - rc = asprintf(&fpath, "%s/%s", dname, fname); - free(dname); - free(fname); - if (rc == -1 || fpath == NULL) - fail("asprintf", 1); + if (asprintf(&fpath, "%s/%s", dname, fname) == -1) + fail("asprintf"); - } else if ((sbuf.st_mode & S_IFMT) == S_IFREG || - (sbuf.st_mode & S_IFMT) == S_IFLNK || - (sbuf.st_mode & S_IFMT) == S_IFCHR || - (sbuf.st_mode & S_IFMT) == S_IFBLK) { - fpath = strdup(argv[0]); - } else if ((sbuf.st_mode & S_IFMT) == S_IFDIR) { - fpath = strdup(argv[0]); - isdir = B_TRUE; - } else { - usage(prog); - } + free(arg); + } else + switch (sbuf.st_mode & S_IFMT) { + case S_IFDIR: + isdir = B_TRUE; + /* FALLTHROUGH */ + case S_IFLNK: + case S_IFCHR: + case S_IFBLK: + if ((fpath = strdup(argv[0])) == NULL) + fail("strdup"); + break; + default: + usage(prog); + } - if (fpath == NULL) - fail("strdup", 1); + if (!isdir) { + int fd; - if (isdir == B_FALSE) { - int fd, flags; - mode_t mode = S_IRUSR | S_IWUSR; - - flags = rflag == B_FALSE ? O_CREAT | O_RDWR : O_RDONLY; - - if ((fd = open(fpath, flags, mode)) < 0) - fail("open", 1); + if ((fd = open(fpath, O_CREAT | O_RDWR, 0600)) < 0) + fail("open"); } else { DIR *dp; if ((dp = opendir(fpath)) == NULL) - fail("opendir", 1); + fail("opendir"); } free(fpath); - if (fflag == B_FALSE) - daemonize(); + daemonize(); (void) pause(); - /* NOTREACHED */ return (0); } diff --git a/tests/zfs-tests/cmd/mkfile/mkfile.c b/tests/zfs-tests/cmd/mkfile/mkfile.c index 4cf3755faa..673cbf9e00 100644 --- a/tests/zfs-tests/cmd/mkfile/mkfile.c +++ b/tests/zfs-tests/cmd/mkfile/mkfile.c @@ -44,7 +44,7 @@ #define FILE_MODE (S_ISVTX + S_IRUSR + S_IWUSR) -static void usage(void); +static void usage(void) __attribute__((noreturn)); int main(int argc, char **argv) @@ -278,5 +278,4 @@ static void usage() (void) fprintf(stderr, gettext( "Usage: mkfile [-nv] [g|k|b|m] [] ...\n")); exit(1); - /* NOTREACHED */ } diff --git a/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c b/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c index 152f5ba90e..1f344534d5 100644 --- a/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c +++ b/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c @@ -66,19 +66,15 @@ normal_writer(void *filename) err(1, "failed to open %s", file_path); } - char *buf = malloc(1); + char buf; while (1) { - write_num = write(fd, buf, 1); + write_num = write(fd, &buf, 1); if (write_num == 0) { err(1, "write failed!"); break; } lseek(fd, page_size, SEEK_CUR); } - - if (buf) { - free(buf); - } } static void * @@ -140,7 +136,7 @@ main(int argc, char **argv) int i = 0; if (argc != 3) { - (void) printf("usage: %s " + (void) printf("usage: %s " "\n", argv[0]); exit(1); } @@ -156,7 +152,6 @@ main(int argc, char **argv) err(1, "pthread_create map_writer failed."); } - /* NOTREACHED */ pthread_join(map_write_tid, NULL); return (0); }