mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-04-12 22:51:46 +03:00
libzfs/mnttab: use SPL mutexes
More consistent, less typing, and we can check ownership. 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
02224bca40
commit
b5637fba1c
@ -34,6 +34,7 @@
|
||||
#include <sys/nvpair.h>
|
||||
#include <sys/dmu.h>
|
||||
#include <sys/zfs_ioctl.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include <libzfs.h>
|
||||
@ -64,7 +65,7 @@ struct libzfs_handle {
|
||||
* lock only protects the integrity of the avl tree, and does
|
||||
* not protect the contents of the mnttab entries themselves.
|
||||
*/
|
||||
pthread_mutex_t libzfs_mnttab_cache_lock;
|
||||
kmutex_t libzfs_mnttab_cache_lock;
|
||||
avl_tree_t libzfs_mnttab_cache;
|
||||
int libzfs_pool_iter;
|
||||
boolean_t libzfs_prop_debug;
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/mntent.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <libzfs.h>
|
||||
#include "libzfs_impl.h"
|
||||
|
||||
@ -61,7 +62,7 @@ libzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
|
||||
void
|
||||
libzfs_mnttab_init(libzfs_handle_t *hdl)
|
||||
{
|
||||
pthread_mutex_init(&hdl->libzfs_mnttab_cache_lock, NULL);
|
||||
mutex_init(&hdl->libzfs_mnttab_cache_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
|
||||
avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
|
||||
sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
|
||||
@ -73,6 +74,8 @@ libzfs_mnttab_update(libzfs_handle_t *hdl)
|
||||
FILE *mnttab;
|
||||
struct mnttab entry;
|
||||
|
||||
ASSERT(MUTEX_HELD(&hdl->libzfs_mnttab_cache_lock));
|
||||
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
@ -121,7 +124,7 @@ libzfs_mnttab_fini(libzfs_handle_t *hdl)
|
||||
free(mtn);
|
||||
}
|
||||
avl_destroy(&hdl->libzfs_mnttab_cache);
|
||||
(void) pthread_mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
|
||||
(void) mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
|
||||
}
|
||||
|
||||
void
|
||||
@ -155,12 +158,12 @@ libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
|
||||
return (ret);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&hdl->libzfs_mnttab_cache_lock);
|
||||
mutex_enter(&hdl->libzfs_mnttab_cache_lock);
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0) {
|
||||
int error;
|
||||
|
||||
if ((error = libzfs_mnttab_update(hdl)) != 0) {
|
||||
pthread_mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
|
||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
@ -171,7 +174,7 @@ libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
|
||||
*entry = mtn->mtn_mt;
|
||||
ret = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
|
||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@ -181,7 +184,7 @@ libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
|
||||
{
|
||||
mnttab_node_t *mtn;
|
||||
|
||||
pthread_mutex_lock(&hdl->libzfs_mnttab_cache_lock);
|
||||
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);
|
||||
@ -202,7 +205,7 @@ libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
|
||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
|
||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||
}
|
||||
|
||||
void
|
||||
@ -211,7 +214,7 @@ libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
|
||||
mnttab_node_t find;
|
||||
mnttab_node_t *ret;
|
||||
|
||||
pthread_mutex_lock(&hdl->libzfs_mnttab_cache_lock);
|
||||
mutex_enter(&hdl->libzfs_mnttab_cache_lock);
|
||||
find.mtn_mt.mnt_special = (char *)fsname;
|
||||
if ((ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL))
|
||||
!= NULL) {
|
||||
@ -222,5 +225,5 @@ libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
|
||||
free(ret->mtn_mt.mnt_mntopts);
|
||||
free(ret);
|
||||
}
|
||||
pthread_mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
|
||||
mutex_exit(&hdl->libzfs_mnttab_cache_lock);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user