Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. cleanups from #12928 pt. 2 #12968

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3039,9 +3039,8 @@ show_import(nvlist_t *config, boolean_t report_error)
ZPOOL_CONFIG_MMP_HOSTID);

(void) printf(gettext(" action: The pool must be "
"exported from %s (hostid=%lx)\n\tbefore it "
"can be safely imported.\n"), hostname,
(unsigned long) hostid);
"exported from %s (hostid=%"PRIx64")\n\tbefore it "
"can be safely imported.\n"), hostname, hostid);
break;
case ZPOOL_STATUS_HOSTID_REQUIRED:
(void) printf(gettext(" action: Set a unique system "
Expand Down Expand Up @@ -3136,7 +3135,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
{
int ret = 0;
zpool_handle_t *zhp;
char *name;
const char *name;
uint64_t version;

name = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME);
Expand All @@ -3157,7 +3156,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
ZPOOL_CONFIG_MMP_STATE);

if (mmp_state == MMP_STATE_ACTIVE) {
char *hostname = "<unknown>";
const char *hostname = "<unknown>";
uint64_t hostid = 0;

if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_HOSTNAME))
Expand All @@ -3170,17 +3169,17 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,

(void) fprintf(stderr, gettext("cannot import '%s': "
"pool is imported on %s (hostid: "
"0x%lx)\nExport the pool on the other system, "
"then run 'zpool import'.\n"),
name, hostname, (unsigned long) hostid);
"0x%"PRIx64")\nExport the pool on the other "
"system, then run 'zpool import'.\n"),
name, hostname, hostid);
} else if (mmp_state == MMP_STATE_NO_HOSTID) {
(void) fprintf(stderr, gettext("Cannot import '%s': "
"pool has the multihost property on and the\n"
"system's hostid is not set. Set a unique hostid "
"with the zgenhostid(8) command.\n"), name);
} else {
char *hostname = "<unknown>";
uint64_t timestamp = 0;
const char *hostname = "<unknown>";
time_t timestamp = 0;
uint64_t hostid = 0;

if (nvlist_exists(config, ZPOOL_CONFIG_HOSTNAME))
Expand All @@ -3197,10 +3196,10 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,

(void) fprintf(stderr, gettext("cannot import '%s': "
"pool was previously in use from another system.\n"
"Last accessed by %s (hostid=%lx) at %s"
"Last accessed by %s (hostid=%"PRIx64") at %s"
"The pool can be imported, use 'zpool import -f' "
"to import the pool.\n"), name, hostname,
(unsigned long)hostid, ctime((time_t *)&timestamp));
hostid, ctime(&timestamp));
}

return (1);
Expand All @@ -3210,7 +3209,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
return (1);

if (newname != NULL)
name = (char *)newname;
name = newname;

if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
return (1);
Expand All @@ -3219,11 +3218,9 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
* Loading keys is best effort. We don't want to return immediately
* if it fails but we do want to give the error to the caller.
*/
if (flags & ZFS_IMPORT_LOAD_KEYS) {
ret = zfs_crypto_attempt_load_keys(g_zfs, name);
if (ret != 0)
if (flags & ZFS_IMPORT_LOAD_KEYS &&
zfs_crypto_attempt_load_keys(g_zfs, name) != 0)
ret = 1;
}

if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
!(flags & ZFS_IMPORT_ONLY) &&
Expand Down Expand Up @@ -3273,7 +3270,7 @@ import_pools(nvlist_t *pools, nvlist_t *props, char *mntopts, int flags,
if (first)
first = B_FALSE;
else if (!do_all)
(void) printf("\n");
(void) putchar('\n');

if (do_all) {
err |= do_import(config, NULL, mntopts,
Expand Down Expand Up @@ -3724,9 +3721,8 @@ zpool_do_import(int argc, char **argv)
if (argc == 0 && geteuid() != 0) {
(void) fprintf(stderr, gettext("cannot "
"discover pools: permission denied\n"));
if (searchdirs != NULL)
free(searchdirs);

free(searchdirs);
nvlist_free(props);
nvlist_free(policy);
return (1);
Expand Down
4 changes: 2 additions & 2 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ _LIBZFS_H int zfs_crypto_create(libzfs_handle_t *, char *, nvlist_t *,
nvlist_t *, boolean_t stdin_available, uint8_t **, uint_t *);
_LIBZFS_H int zfs_crypto_clone_check(libzfs_handle_t *, zfs_handle_t *, char *,
nvlist_t *);
_LIBZFS_H int zfs_crypto_attempt_load_keys(libzfs_handle_t *, char *);
_LIBZFS_H int zfs_crypto_load_key(zfs_handle_t *, boolean_t, char *);
_LIBZFS_H int zfs_crypto_attempt_load_keys(libzfs_handle_t *, const char *);
_LIBZFS_H int zfs_crypto_load_key(zfs_handle_t *, boolean_t, const char *);
_LIBZFS_H int zfs_crypto_unload_key(zfs_handle_t *);
_LIBZFS_H int zfs_crypto_rewrap(zfs_handle_t *, nvlist_t *, boolean_t);

Expand Down
2 changes: 1 addition & 1 deletion lib/libspl/os/linux/zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <zone.h>

zoneid_t
getzoneid()
getzoneid(void)
{
return (GLOBAL_ZONEID);
}
3 changes: 1 addition & 2 deletions lib/libtpool/thread_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ job_cleanup(void *arg)
tpool_active_t **activepp;

pthread_mutex_lock(&tpool->tp_mutex);
/* CSTYLED */
for (activepp = &tpool->tp_active;; activepp = &activep->tpa_next) {
for (activepp = &tpool->tp_active; ; activepp = &activep->tpa_next) {
activep = *activepp;
if (activep->tpa_tid == my_tid) {
*activepp = activep->tpa_next;
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_changelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ changelist_rename(prop_changelist_t *clp, const char *src, const char *dst)
* unshare all the datasets in the list.
*/
int
changelist_unshare(prop_changelist_t *clp, zfs_share_proto_t *proto)
changelist_unshare(prop_changelist_t *clp, const zfs_share_proto_t *proto)
{
prop_changenode_t *cn;
uu_avl_walk_t *walk;
Expand Down
9 changes: 5 additions & 4 deletions lib/libzfs/libzfs_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ get_key_material_https(libzfs_handle_t *hdl, const char *uri,
*/
static int
get_key_material(libzfs_handle_t *hdl, boolean_t do_verify, boolean_t newkey,
zfs_keyformat_t keyformat, char *keylocation, const char *fsname,
zfs_keyformat_t keyformat, const char *keylocation, const char *fsname,
uint8_t **km_out, size_t *kmlen_out, boolean_t *can_retry_out)
{
int ret;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ load_keys_cb(zfs_handle_t *zhp, void *arg)
* filesystem and all of its children.
*/
int
zfs_crypto_attempt_load_keys(libzfs_handle_t *hdl, char *fsname)
zfs_crypto_attempt_load_keys(libzfs_handle_t *hdl, const char *fsname)
{
int ret;
zfs_handle_t *zhp = NULL;
Expand Down Expand Up @@ -1275,15 +1275,16 @@ zfs_crypto_attempt_load_keys(libzfs_handle_t *hdl, char *fsname)
}

int
zfs_crypto_load_key(zfs_handle_t *zhp, boolean_t noop, char *alt_keylocation)
zfs_crypto_load_key(zfs_handle_t *zhp, boolean_t noop,
const char *alt_keylocation)
{
int ret, attempts = 0;
char errbuf[1024];
uint64_t keystatus, iters = 0, salt = 0;
uint64_t keyformat = ZFS_KEYFORMAT_NONE;
char prop_keylocation[MAXNAMELEN];
char prop_encroot[MAXNAMELEN];
char *keylocation = NULL;
const char *keylocation = NULL;
uint8_t *key_material = NULL, *key_data = NULL;
size_t key_material_len;
boolean_t is_encroot, can_retry = B_FALSE, correctible = B_FALSE;
Expand Down
11 changes: 5 additions & 6 deletions lib/libzfs/libzfs_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ extern void changelist_remove(prop_changelist_t *, const char *);
extern void changelist_free(prop_changelist_t *);
extern prop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int,
int);
extern int changelist_unshare(prop_changelist_t *, zfs_share_proto_t *);
extern int changelist_unshare(prop_changelist_t *, const zfs_share_proto_t *);
extern int changelist_haszonedchild(prop_changelist_t *);

extern void remove_mountpoint(zfs_handle_t *);
Expand Down Expand Up @@ -240,14 +240,13 @@ typedef struct differ_info {
int datafd;
} differ_info_t;

extern proto_table_t proto_table[PROTO_END];

extern int do_mount(zfs_handle_t *zhp, const char *mntpt, char *opts,
int flags);
extern int do_unmount(zfs_handle_t *zhp, const char *mntpt, int flags);
extern int zfs_mount_delegation_check(void);
extern int zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto);
extern int zfs_unshare_proto(zfs_handle_t *, const char *, zfs_share_proto_t *);
extern int zfs_share_proto(zfs_handle_t *zhp, const zfs_share_proto_t *proto);
extern int zfs_unshare_proto(zfs_handle_t *, const char *,
const zfs_share_proto_t *);
extern int unshare_one(libzfs_handle_t *hdl, const char *name,
const char *mountpoint, zfs_share_proto_t proto);
extern boolean_t zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen,
Expand All @@ -259,7 +258,7 @@ extern int zpool_relabel_disk(libzfs_handle_t *hdl, const char *path,
const char *msg);
extern int find_shares_object(differ_info_t *di);
extern void libzfs_set_pipe_max(int infd);
extern void zfs_commit_proto(zfs_share_proto_t *);
extern void zfs_commit_proto(const zfs_share_proto_t *);

#ifdef __cplusplus
}
Expand Down
33 changes: 17 additions & 16 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ static zfs_share_type_t zfs_is_shared_proto(zfs_handle_t *, char **,
* The share protocols table must be in the same order as the zfs_share_proto_t
* enum in libzfs_impl.h
*/
proto_table_t proto_table[PROTO_END] = {
static const proto_table_t proto_table[PROTO_END] = {
{ZFS_PROP_SHARENFS, "nfs", EZFS_SHARENFSFAILED, EZFS_UNSHARENFSFAILED},
{ZFS_PROP_SHARESMB, "smb", EZFS_SHARESMBFAILED, EZFS_UNSHARESMBFAILED},
};

static zfs_share_proto_t nfs_only[] = {
static const zfs_share_proto_t nfs_only[] = {
PROTO_NFS,
PROTO_END
};

static zfs_share_proto_t smb_only[] = {
static const zfs_share_proto_t smb_only[] = {
PROTO_SMB,
PROTO_END
};
static zfs_share_proto_t share_all_proto[] = {
static const zfs_share_proto_t share_all_proto[] = {
PROTO_NFS,
PROTO_SMB,
PROTO_END
Expand Down Expand Up @@ -706,7 +706,7 @@ boolean_t
zfs_is_shared(zfs_handle_t *zhp)
{
zfs_share_type_t rc = 0;
zfs_share_proto_t *curr_proto;
const zfs_share_proto_t *curr_proto;

if (ZFS_IS_VOLUME(zhp))
return (B_FALSE);
Expand Down Expand Up @@ -762,12 +762,12 @@ is_shared(const char *mountpoint, zfs_share_proto_t proto)
* on "libshare" to do the dirty work for us.
*/
int
zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
zfs_share_proto(zfs_handle_t *zhp, const zfs_share_proto_t *proto)
{
char mountpoint[ZFS_MAXPROPLEN];
char shareopts[ZFS_MAXPROPLEN];
char sourcestr[ZFS_MAXPROPLEN];
zfs_share_proto_t *curr_proto;
const zfs_share_proto_t *curr_proto;
zprop_source_t sourcetype;
int err = 0;

Expand Down Expand Up @@ -872,12 +872,11 @@ zfs_parse_options(char *options, zfs_share_proto_t proto)
}

void
zfs_commit_proto(zfs_share_proto_t *proto)
zfs_commit_proto(const zfs_share_proto_t *proto)
{
zfs_share_proto_t *curr_proto;
for (curr_proto = proto; *curr_proto != PROTO_END; curr_proto++) {
const zfs_share_proto_t *curr_proto;
for (curr_proto = proto; *curr_proto != PROTO_END; curr_proto++)
sa_commit_shares(proto_table[*curr_proto].p_name);
}
}

void
Expand Down Expand Up @@ -932,7 +931,7 @@ zfs_shareall(zfs_handle_t *zhp)
*/
int
zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
zfs_share_proto_t *proto)
const zfs_share_proto_t *proto)
{
libzfs_handle_t *hdl = zhp->zfs_hdl;
struct mnttab entry;
Expand All @@ -944,7 +943,7 @@ zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,

if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
libzfs_mnttab_find(hdl, zfs_get_name(zhp), &entry) == 0)) {
zfs_share_proto_t *curr_proto;
const zfs_share_proto_t *curr_proto;

if (mountpoint == NULL)
mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
Expand Down Expand Up @@ -984,7 +983,7 @@ zfs_unshare_smb(zfs_handle_t *zhp, const char *mountpoint)
* Same as zfs_unmountall(), but for NFS and SMB unshares.
*/
static int
zfs_unshareall_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
zfs_unshareall_proto(zfs_handle_t *zhp, const zfs_share_proto_t *proto)
{
prop_changelist_t *clp;
int ret;
Expand Down Expand Up @@ -1353,7 +1352,7 @@ zfs_mount_task(void *arg)
sizeof (mountpoint), NULL, NULL, 0, B_FALSE) == 0);

if (mp->mnt_func(handles[idx], mp->mnt_data) != 0)
return;
goto out;

/*
* We dispatch tasks to mount filesystems with mountpoints underneath
Expand All @@ -1374,6 +1373,8 @@ zfs_mount_task(void *arg)
zfs_dispatch_mount(mp->mnt_hdl, handles, num_handles, i,
mp->mnt_func, mp->mnt_data, mp->mnt_tp);
}

out:
free(mp);
}

Expand Down Expand Up @@ -1616,7 +1617,7 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
* Walk through and first unshare everything.
*/
for (i = 0; i < used; i++) {
zfs_share_proto_t *curr_proto;
const zfs_share_proto_t *curr_proto;
for (curr_proto = share_all_proto; *curr_proto != PROTO_END;
curr_proto++) {
if (is_shared(sets[i].mountpoint, *curr_proto) &&
Expand Down
4 changes: 2 additions & 2 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
nvlist_t *nv = NULL;
nvlist_t *nvinfo = NULL;
nvlist_t *missing = NULL;
char *thename;
const char *thename;
char *origname;
int ret;
int error = 0;
Expand All @@ -2047,7 +2047,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
return (zfs_error_fmt(hdl, EZFS_INVALIDNAME,
dgettext(TEXT_DOMAIN, "cannot import '%s'"),
newname));
thename = (char *)newname;
thename = newname;
} else {
thename = origname;
}
Expand Down