libshare: use AVL tree with static data, pass all data in arguments

This makes it so we don't leak a consistent 64 bytes anymore,
makes the searches simpler and faster, removes /all allocations/
from the driver (quite trivially, since they were absolutely needless),
and makes libshare thread-safe (except, maybe, linux/smb, but that only
does pointer-width loads/stores so it's also mostly fine, except for
leaking smb_shares)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13165
This commit is contained in:
наб
2022-02-28 14:50:28 +01:00
committed by Brian Behlendorf
parent 4ccbb23971
commit 63ce6dd988
8 changed files with 119 additions and 413 deletions
+7 -39
View File
@@ -45,8 +45,6 @@
#define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports"
#define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock"
static sa_fstype_t *nfs_fstype;
typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
void *cookie);
@@ -229,7 +227,6 @@ foreach_nfs_host(sa_share_impl_t impl_share, FILE *tmpfile,
nfs_host_callback_t callback, void *cookie)
{
nfs_host_cookie_t udata;
char *shareopts;
udata.callback = callback;
udata.sharepath = impl_share->sa_mountpoint;
@@ -237,10 +234,8 @@ foreach_nfs_host(sa_share_impl_t impl_share, FILE *tmpfile,
udata.tmpfile = tmpfile;
udata.security = "sys";
shareopts = FSINFO(impl_share, nfs_fstype)->shareopts;
return (foreach_nfs_shareopt(shareopts, foreach_nfs_host_cb,
&udata));
return (foreach_nfs_shareopt(impl_share->sa_shareopts,
foreach_nfs_host_cb, &udata));
}
/*
@@ -411,11 +406,10 @@ nfs_add_entry(FILE *tmpfile, const char *sharepath,
static int
nfs_enable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
{
char *shareopts, *linux_opts;
char *linux_opts;
int error;
shareopts = FSINFO(impl_share, nfs_fstype)->shareopts;
error = get_linux_shareopts(shareopts, &linux_opts);
error = get_linux_shareopts(impl_share->sa_shareopts, &linux_opts);
if (error != SA_OK)
return (error);
@@ -475,23 +469,6 @@ nfs_validate_shareopts(const char *shareopts)
return (SA_OK);
}
static int
nfs_update_shareopts(sa_share_impl_t impl_share, const char *shareopts)
{
FSINFO(impl_share, nfs_fstype)->shareopts = (char *)shareopts;
return (SA_OK);
}
/*
* Clears a share's NFS options. Used by libshare to
* clean up shares that are about to be free()'d.
*/
static void
nfs_clear_shareopts(sa_share_impl_t impl_share)
{
FSINFO(impl_share, nfs_fstype)->shareopts = NULL;
}
static int
nfs_commit_shares(void)
{
@@ -504,22 +481,13 @@ nfs_commit_shares(void)
return (libzfs_run_process(argv[0], argv, 0));
}
static const sa_share_ops_t nfs_shareops = {
sa_fstype_t libshare_nfs_type = {
.protocol = "nfs",
.enable_share = nfs_enable_share,
.disable_share = nfs_disable_share,
.is_shared = nfs_is_shared,
.validate_shareopts = nfs_validate_shareopts,
.update_shareopts = nfs_update_shareopts,
.clear_shareopts = nfs_clear_shareopts,
.commit_shares = nfs_commit_shares,
};
/*
* Initializes the NFS functionality of libshare.
*/
void
libshare_nfs_init(void)
{
nfs_fstype = register_fstype("nfs", &nfs_shareops);
}