From 7cbdace58c0fabefc3296250ce33512ebbc22586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 12 Jan 2022 17:36:36 +0100 Subject: [PATCH] libzfs: share_proto: constify, staticify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12968 --- lib/libzfs/libzfs_changelist.c | 2 +- lib/libzfs/libzfs_impl.h | 11 +++++------ lib/libzfs/libzfs_mount.c | 29 ++++++++++++++--------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/libzfs/libzfs_changelist.c b/lib/libzfs/libzfs_changelist.c index 9c8241a874fa..f2282ee01177 100644 --- a/lib/libzfs/libzfs_changelist.c +++ b/lib/libzfs/libzfs_changelist.c @@ -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; diff --git a/lib/libzfs/libzfs_impl.h b/lib/libzfs/libzfs_impl.h index 33b3feed43e6..cf8d0d4e6742 100644 --- a/lib/libzfs/libzfs_impl.h +++ b/lib/libzfs/libzfs_impl.h @@ -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 *); @@ -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, @@ -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 } diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index 7959933ede5a..3c35c0ed0793 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -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 @@ -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); @@ -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; @@ -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 @@ -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; @@ -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); @@ -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; @@ -1616,7 +1615,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) &&