mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 19:04:45 +03:00
libzfs: get rid of libzfs_handle::libzfs_mnttab
All users did a freopen() on it. Even some non-users did! This is point-less ‒ just open the mtab when needed If I understand Solaris' getextmntent(3C) correctly, the non-user freopen()s are very likely an odd, twisted vestigial tail of that ‒ but it's got a completely different calling convention and caching semantics than any platform we support Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #11868
This commit is contained in:
+2539
-2654
File diff suppressed because it is too large
Load Diff
@@ -808,13 +808,13 @@ libzfs_mnttab_init(libzfs_handle_t *hdl)
|
||||
static int
|
||||
libzfs_mnttab_update(libzfs_handle_t *hdl)
|
||||
{
|
||||
FILE *mnttab;
|
||||
struct mnttab entry;
|
||||
|
||||
/* Reopen MNTTAB to prevent reading stale data from open file */
|
||||
if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
|
||||
while (getmntent(mnttab, &entry) == 0) {
|
||||
mnttab_node_t *mtn;
|
||||
avl_index_t where;
|
||||
|
||||
@@ -840,6 +840,7 @@ libzfs_mnttab_update(libzfs_handle_t *hdl)
|
||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||
}
|
||||
|
||||
(void) fclose(mnttab);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -871,6 +872,7 @@ 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;
|
||||
@@ -881,16 +883,14 @@ libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache))
|
||||
libzfs_mnttab_fini(hdl);
|
||||
|
||||
/* Reopen MNTTAB to prevent reading stale data from open file */
|
||||
if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
srch.mnt_special = (char *)fsname;
|
||||
srch.mnt_fstype = MNTTYPE_ZFS;
|
||||
if (getmntany(hdl->libzfs_mnttab, entry, &srch) == 0)
|
||||
return (0);
|
||||
else
|
||||
return (ENOENT);
|
||||
ret = getmntany(mnttab, entry, &srch) ? ENOENT : 0;
|
||||
(void) fclose(mnttab);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&hdl->libzfs_mnttab_cache_lock);
|
||||
|
||||
@@ -1528,6 +1528,7 @@ int
|
||||
zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
|
||||
{
|
||||
int used, alloc;
|
||||
FILE *mnttab;
|
||||
struct mnttab entry;
|
||||
size_t namelen;
|
||||
char **mountpoints = NULL;
|
||||
@@ -1539,12 +1540,11 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
|
||||
|
||||
namelen = strlen(zhp->zpool_name);
|
||||
|
||||
/* Reopen MNTTAB to prevent reading stale data from open file */
|
||||
if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
used = alloc = 0;
|
||||
while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
|
||||
while (getmntent(mnttab, &entry) == 0) {
|
||||
/*
|
||||
* Ignore non-ZFS entries.
|
||||
*/
|
||||
@@ -1646,6 +1646,7 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
(void) fclose(mnttab);
|
||||
for (i = 0; i < used; i++) {
|
||||
if (datasets[i])
|
||||
zfs_close(datasets[i]);
|
||||
|
||||
@@ -1025,19 +1025,8 @@ libzfs_init(void)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SETMNTENT
|
||||
if ((hdl->libzfs_mnttab = setmntent(MNTTAB, "re")) == NULL) {
|
||||
#else
|
||||
if ((hdl->libzfs_mnttab = fopen(MNTTAB, "re")) == NULL) {
|
||||
#endif
|
||||
(void) close(hdl->libzfs_fd);
|
||||
free(hdl);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (libzfs_core_init() != 0) {
|
||||
(void) close(hdl->libzfs_fd);
|
||||
(void) fclose(hdl->libzfs_mnttab);
|
||||
free(hdl);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -1056,7 +1045,6 @@ libzfs_init(void)
|
||||
&hdl->libzfs_max_nvlist))) {
|
||||
errno = error;
|
||||
(void) close(hdl->libzfs_fd);
|
||||
(void) fclose(hdl->libzfs_mnttab);
|
||||
free(hdl);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -1087,12 +1075,6 @@ void
|
||||
libzfs_fini(libzfs_handle_t *hdl)
|
||||
{
|
||||
(void) close(hdl->libzfs_fd);
|
||||
if (hdl->libzfs_mnttab)
|
||||
#ifdef HAVE_SETMNTENT
|
||||
(void) endmntent(hdl->libzfs_mnttab);
|
||||
#else
|
||||
(void) fclose(hdl->libzfs_mnttab);
|
||||
#endif
|
||||
zpool_free_handles(hdl);
|
||||
namespace_clear(hdl);
|
||||
libzfs_mnttab_fini(hdl);
|
||||
@@ -1139,10 +1121,6 @@ zfs_path_to_zhandle(libzfs_handle_t *hdl, const char *path, zfs_type_t argtype)
|
||||
return (zfs_open(hdl, path, argtype));
|
||||
}
|
||||
|
||||
/* Reopen MNTTAB to prevent reading stale data from open file */
|
||||
if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (getextmntent(path, &entry, &statbuf) != 0)
|
||||
return (NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user