mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-04-12 22:51:46 +03:00
libzfs/mnttab: always enable the cache
There's no real reason not to enable it always; the `zfs` command always enables it anyway, and right now there's multiple places that do mount work that don't go through the cache anyway. Having it always be on lets us remove a bunch of the fallback code. Sponsored-by: TrueNAS Reviewed-by: Ameer Hamza <ahamza@ixsystems.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <rob.norris@truenas.com> Closes #18296
This commit is contained in:
parent
b5637fba1c
commit
0ecf5e3f62
@ -9426,7 +9426,6 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* Run the appropriate command.
|
||||
*/
|
||||
libzfs_mnttab_cache(g_zfs, B_TRUE);
|
||||
if (find_command_idx(cmdname, &i) == 0) {
|
||||
current_command = &command_table[i];
|
||||
ret = command_table[i].func(argc - 1, newargv + 1);
|
||||
|
||||
@ -58,7 +58,6 @@ struct libzfs_handle {
|
||||
char libzfs_action[1024];
|
||||
char libzfs_desc[1024];
|
||||
int libzfs_printerr;
|
||||
boolean_t libzfs_mnttab_enable;
|
||||
/*
|
||||
* We need a lock to handle the case where parallel mount
|
||||
* threads are populating the mnttab cache simultaneously. The
|
||||
|
||||
@ -130,34 +130,18 @@ libzfs_mnttab_fini(libzfs_handle_t *hdl)
|
||||
void
|
||||
libzfs_mnttab_cache(libzfs_handle_t *hdl, boolean_t enable)
|
||||
{
|
||||
hdl->libzfs_mnttab_enable = enable;
|
||||
/* This is a no-op to preserve ABI backward compatibility. */
|
||||
(void) hdl, (void) enable;
|
||||
}
|
||||
|
||||
int
|
||||
libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
|
||||
struct mnttab *entry)
|
||||
{
|
||||
FILE *mnttab;
|
||||
mnttab_node_t find;
|
||||
mnttab_node_t *mtn;
|
||||
int ret = ENOENT;
|
||||
|
||||
if (!hdl->libzfs_mnttab_enable) {
|
||||
struct mnttab srch = { 0 };
|
||||
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache))
|
||||
libzfs_mnttab_fini(hdl);
|
||||
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
srch.mnt_special = (char *)fsname;
|
||||
srch.mnt_fstype = (char *)MNTTYPE_ZFS;
|
||||
ret = getmntany(mnttab, entry, &srch) ? ENOENT : 0;
|
||||
(void) fclose(mnttab);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
mutex_enter(&hdl->libzfs_mnttab_cache_lock);
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0) {
|
||||
int error;
|
||||
@ -185,26 +169,27 @@ libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
|
||||
mnttab_node_t *mtn;
|
||||
|
||||
mutex_enter(&hdl->libzfs_mnttab_cache_lock);
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache) != 0) {
|
||||
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
|
||||
mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
|
||||
mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
|
||||
mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
|
||||
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
|
||||
/*
|
||||
* Another thread may have already added this entry
|
||||
* via libzfs_mnttab_update. If so we should skip it.
|
||||
*/
|
||||
if (avl_find(&hdl->libzfs_mnttab_cache, mtn, NULL) != NULL) {
|
||||
free(mtn->mtn_mt.mnt_special);
|
||||
free(mtn->mtn_mt.mnt_mountp);
|
||||
free(mtn->mtn_mt.mnt_fstype);
|
||||
free(mtn->mtn_mt.mnt_mntopts);
|
||||
free(mtn);
|
||||
} else {
|
||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||
}
|
||||
|
||||
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
|
||||
mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
|
||||
mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
|
||||
mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
|
||||
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
|
||||
|
||||
/*
|
||||
* Another thread may have already added this entry
|
||||
* via libzfs_mnttab_update. If so we should skip it.
|
||||
*/
|
||||
if (avl_find(&hdl->libzfs_mnttab_cache, mtn, NULL) != NULL) {
|
||||
free(mtn->mtn_mt.mnt_special);
|
||||
free(mtn->mtn_mt.mnt_mountp);
|
||||
free(mtn->mtn_mt.mnt_fstype);
|
||||
free(mtn->mtn_mt.mnt_mntopts);
|
||||
free(mtn);
|
||||
} else {
|
||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||
}
|
||||
|
||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user