mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-04-13 07:01:46 +03:00
libzfs/mnttab: lift node alloc/free
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
0ecf5e3f62
commit
f43cb1fef6
@ -47,6 +47,28 @@ typedef struct mnttab_node {
|
|||||||
avl_node_t mtn_node;
|
avl_node_t mtn_node;
|
||||||
} mnttab_node_t;
|
} mnttab_node_t;
|
||||||
|
|
||||||
|
static mnttab_node_t *
|
||||||
|
mnttab_node_alloc(libzfs_handle_t *hdl, const char *special,
|
||||||
|
const char *mountp, const char *mntopts)
|
||||||
|
{
|
||||||
|
mnttab_node_t *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 = (char *)MNTTYPE_ZFS;
|
||||||
|
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
|
||||||
|
return (mtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mnttab_node_free(libzfs_handle_t *hdl, mnttab_node_t *mtn)
|
||||||
|
{
|
||||||
|
(void) hdl;
|
||||||
|
free(mtn->mtn_mt.mnt_special);
|
||||||
|
free(mtn->mtn_mt.mnt_mountp);
|
||||||
|
free(mtn->mtn_mt.mnt_mntopts);
|
||||||
|
free(mtn);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
libzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
|
libzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
|
||||||
{
|
{
|
||||||
@ -86,19 +108,12 @@ libzfs_mnttab_update(libzfs_handle_t *hdl)
|
|||||||
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
|
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
|
mtn = mnttab_node_alloc(hdl, entry.mnt_special,
|
||||||
mtn->mtn_mt.mnt_special = zfs_strdup(hdl, entry.mnt_special);
|
entry.mnt_mountp, entry.mnt_mntopts);
|
||||||
mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, entry.mnt_mountp);
|
|
||||||
mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, entry.mnt_fstype);
|
|
||||||
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, entry.mnt_mntopts);
|
|
||||||
|
|
||||||
/* Exclude duplicate mounts */
|
/* Exclude duplicate mounts */
|
||||||
if (avl_find(&hdl->libzfs_mnttab_cache, mtn, &where) != NULL) {
|
if (avl_find(&hdl->libzfs_mnttab_cache, mtn, &where) != NULL) {
|
||||||
free(mtn->mtn_mt.mnt_special);
|
mnttab_node_free(hdl, mtn);
|
||||||
free(mtn->mtn_mt.mnt_mountp);
|
|
||||||
free(mtn->mtn_mt.mnt_fstype);
|
|
||||||
free(mtn->mtn_mt.mnt_mntopts);
|
|
||||||
free(mtn);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +131,9 @@ libzfs_mnttab_fini(libzfs_handle_t *hdl)
|
|||||||
mnttab_node_t *mtn;
|
mnttab_node_t *mtn;
|
||||||
|
|
||||||
while ((mtn = avl_destroy_nodes(&hdl->libzfs_mnttab_cache, &cookie))
|
while ((mtn = avl_destroy_nodes(&hdl->libzfs_mnttab_cache, &cookie))
|
||||||
!= NULL) {
|
!= NULL)
|
||||||
free(mtn->mtn_mt.mnt_special);
|
mnttab_node_free(hdl, mtn);
|
||||||
free(mtn->mtn_mt.mnt_mountp);
|
|
||||||
free(mtn->mtn_mt.mnt_fstype);
|
|
||||||
free(mtn->mtn_mt.mnt_mntopts);
|
|
||||||
free(mtn);
|
|
||||||
}
|
|
||||||
avl_destroy(&hdl->libzfs_mnttab_cache);
|
avl_destroy(&hdl->libzfs_mnttab_cache);
|
||||||
(void) mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
|
(void) mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
|
||||||
}
|
}
|
||||||
@ -170,25 +181,16 @@ libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
|
|||||||
|
|
||||||
mutex_enter(&hdl->libzfs_mnttab_cache_lock);
|
mutex_enter(&hdl->libzfs_mnttab_cache_lock);
|
||||||
|
|
||||||
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
|
mtn = mnttab_node_alloc(hdl, special, mountp, mntopts);
|
||||||
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
|
* Another thread may have already added this entry
|
||||||
* via libzfs_mnttab_update. If so we should skip it.
|
* via libzfs_mnttab_update. If so we should skip it.
|
||||||
*/
|
*/
|
||||||
if (avl_find(&hdl->libzfs_mnttab_cache, mtn, NULL) != NULL) {
|
if (avl_find(&hdl->libzfs_mnttab_cache, mtn, NULL) != NULL)
|
||||||
free(mtn->mtn_mt.mnt_special);
|
mnttab_node_free(hdl, mtn);
|
||||||
free(mtn->mtn_mt.mnt_mountp);
|
else
|
||||||
free(mtn->mtn_mt.mnt_fstype);
|
|
||||||
free(mtn->mtn_mt.mnt_mntopts);
|
|
||||||
free(mtn);
|
|
||||||
} else {
|
|
||||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||||
}
|
|
||||||
|
|
||||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||||
}
|
}
|
||||||
@ -204,11 +206,7 @@ libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
|
|||||||
if ((ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL))
|
if ((ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL))
|
||||||
!= NULL) {
|
!= NULL) {
|
||||||
avl_remove(&hdl->libzfs_mnttab_cache, ret);
|
avl_remove(&hdl->libzfs_mnttab_cache, ret);
|
||||||
free(ret->mtn_mt.mnt_special);
|
mnttab_node_free(hdl, ret);
|
||||||
free(ret->mtn_mt.mnt_mountp);
|
|
||||||
free(ret->mtn_mt.mnt_fstype);
|
|
||||||
free(ret->mtn_mt.mnt_mntopts);
|
|
||||||
free(ret);
|
|
||||||
}
|
}
|
||||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user