From 45ae60c90dd286aebc06827474da076a1e29d42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Fri, 9 Apr 2021 00:44:23 +0200 Subject: [PATCH] libzfs: get rid of libzfs_handle::libzfs_mnttab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Ahelenia Ziemiańska --- cmd/zfs/zfs_main.c | 31 +- include/libzfs_impl.h | 1 - lib/libspl/os/linux/getmntany.c | 4 - lib/libzfs/libzfs.abi | 5285 +++++++++++++++---------------- lib/libzfs/libzfs_dataset.c | 18 +- lib/libzfs/libzfs_mount.c | 7 +- lib/libzfs/libzfs_util.c | 22 - 7 files changed, 2609 insertions(+), 2759 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 395fc353fe1b..24ff074c4ee0 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -83,7 +83,6 @@ libzfs_handle_t *g_zfs; -static FILE *mnttab_file; static char history_str[HIS_MAX_RECORD_LEN]; static boolean_t log_history = B_TRUE; @@ -7063,8 +7062,7 @@ share_mount(int op, int argc, char **argv) get_all_datasets(&cb, verbose); if (cb.cb_used == 0) { - if (options != NULL) - free(options); + free(options); return (0); } @@ -7094,6 +7092,7 @@ share_mount(int op, int argc, char **argv) zfs_close(cb.cb_handles[i]); free(cb.cb_handles); } else if (argc == 0) { + FILE *mnttab; struct mnttab entry; if ((op == OP_SHARE) || (options != NULL)) { @@ -7109,14 +7108,12 @@ share_mount(int op, int argc, char **argv) * automatically. */ - /* Reopen MNTTAB to prevent reading stale data from open file */ - if (freopen(MNTTAB, "r", mnttab_file) == NULL) { - if (options != NULL) - free(options); + if ((mnttab = fopen(MNTTAB, "re")) == NULL) { + free(options); return (ENOENT); } - while (getmntent(mnttab_file, &entry) == 0) { + while (getmntent(mnttab, &entry) == 0) { if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0 || strchr(entry.mnt_special, '@') != NULL) continue; @@ -7125,6 +7122,7 @@ share_mount(int op, int argc, char **argv) entry.mnt_mountp); } + (void) fclose(mnttab); } else { zfs_handle_t *zhp; @@ -7145,9 +7143,7 @@ share_mount(int op, int argc, char **argv) } } - if (options != NULL) - free(options); - + free(options); return (ret); } @@ -7210,10 +7206,6 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) * Search for the given (major,minor) pair in the mount table. */ - /* Reopen MNTTAB to prevent reading stale data from open file */ - if (freopen(MNTTAB, "r", mnttab_file) == NULL) - return (ENOENT); - if (getextmntent(path, &entry, &statbuf) != 0) { if (op == OP_SHARE) { (void) fprintf(stderr, gettext("cannot %s '%s': not " @@ -7353,6 +7345,7 @@ unshare_unmount(int op, int argc, char **argv) * the special type (dataset name), and walk the result in * reverse to make sure to get any snapshots first. */ + FILE *mnttab; struct mnttab entry; uu_avl_pool_t *pool; uu_avl_t *tree = NULL; @@ -7385,11 +7378,10 @@ unshare_unmount(int op, int argc, char **argv) ((tree = uu_avl_create(pool, NULL, UU_DEFAULT)) == NULL)) nomem(); - /* Reopen MNTTAB to prevent reading stale data from open file */ - if (freopen(MNTTAB, "r", mnttab_file) == NULL) + if ((mnttab = fopen(MNTTAB, "re")) == NULL) return (ENOENT); - while (getmntent(mnttab_file, &entry) == 0) { + while (getmntent(mnttab, &entry) == 0) { /* ignore non-ZFS entries */ if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0) @@ -7459,6 +7451,7 @@ unshare_unmount(int op, int argc, char **argv) free(node); } } + (void) fclose(mnttab); /* * Walk the AVL tree in reverse, unmounting each filesystem and @@ -8649,8 +8642,6 @@ main(int argc, char **argv) return (1); } - mnttab_file = g_zfs->libzfs_mnttab; - zfs_save_arguments(argc, argv, history_str, sizeof (history_str)); libzfs_print_on_error(g_zfs, B_TRUE); diff --git a/include/libzfs_impl.h b/include/libzfs_impl.h index dfb63285c1fd..d138a829af48 100644 --- a/include/libzfs_impl.h +++ b/include/libzfs_impl.h @@ -48,7 +48,6 @@ extern "C" { struct libzfs_handle { int libzfs_error; int libzfs_fd; - FILE *libzfs_mnttab; zpool_handle_t *libzfs_pool_handles; uu_avl_pool_t *libzfs_ns_avlpool; uu_avl_t *libzfs_ns_avl; diff --git a/lib/libspl/os/linux/getmntany.c b/lib/libspl/os/linux/getmntany.c index a27db60ec3cd..79c1b5593366 100644 --- a/lib/libspl/os/linux/getmntany.c +++ b/lib/libspl/os/linux/getmntany.c @@ -127,11 +127,7 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) } -#ifdef HAVE_SETMNTENT - if ((fp = setmntent(MNTTAB, "re")) == NULL) { -#else if ((fp = fopen(MNTTAB, "re")) == NULL) { -#endif (void) fprintf(stderr, "cannot open %s\n", MNTTAB); return (-1); } diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index 572297123035..76eed246d0c4 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -421,40 +421,40 @@ - - + + - + - + - + - + - + - + - + - + - + - + - + @@ -561,10 +561,10 @@ - + - + @@ -573,47 +573,47 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -621,389 +621,277 @@ - + - + - + - + - + - - + + - - + + - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - - - - + + + + + + - - + + - + + - + - + - + - + - + - - - - - - - - - - - - + + + + + + + + + + + + - - + + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - - + + - - + + - - + + + - + - + - + - + - + - + - + - + - + - - + + - - - - - + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - + + + + + + + + + @@ -1011,34 +899,34 @@ - - + + - + - + - + - + - + - + - + - + @@ -1048,583 +936,583 @@ - - - - - - - - - - - - + + + + + + + + + + + + - - - + + + - - - - - - + + + + + + - - + + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - - + + - - + + - + - + - + - + - + - - + + - - + + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - - - + + + - - - - - - - + + + + + + + - - - - - - + + + + + + - - + + - - - - + + + + - - + + - - - - + + + + - - - + + + - - + + - - + + - - + + - - + + - + - + - + - + - - + + - + - - + + - + - - + + - - + + - + - + - + - + - - + + - + - + - - + + - + - + - - + + - - + + - + - - - + + + - + - + - - - - - + + + + + - - + + - - - - + + + + - - - + + + - - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - - - - - + + + + + + - - - - - + + + + + - - - + + + - - - - + + + + - - - + + + - - - - - + + + + + - - - - + + + + - - - - - - + + + + + + - + @@ -1640,52 +1528,52 @@ - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - + @@ -1693,45 +1581,45 @@ - + - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - + + - + @@ -1742,127 +1630,127 @@ - - - - - + + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - - - + + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - + + + + - + @@ -1871,143 +1759,143 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - + + + + - - - + + + - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + - + - + - + - + - + @@ -2016,262 +1904,262 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - - + + - - - - - - - + + + + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - - - + + + - + @@ -2285,448 +2173,445 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - - - - + - + - + - + - - - - - + + + + + - - - - - - - + + + + + + + - - + + - - + + - - + + - + - + - + - + - + - + - + - - + + - + - + - - - - - - - - + + + + + + + + @@ -2737,479 +2622,479 @@ - - - - - - - - + + + + + + + + - - + + - + - + - + - + - + - - + + - - - - - + + + + + - - + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - + + + + - - - - - - - + + + + + + + - - - - + + + + - + - + - + - + - - + + - + - + - - + + - - + + - - + + - + - + - + - + - + - - + + - + - - + + - - + + - - + + - - - - + + + + - - - - + + + + - - - - - - - - - + + + + + + + + + - + - + - + - + - - - - - - + + + + + + - - - + + + - - - - + + + + - - - + + + - - + + - - + + - - + + - - - + + + - - - + + + - - - - + + + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - - - - + + + + + + - - + + - - + + - - - + + + - - - - - + + + + + - - + + - - - + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - + + + - - - - + + + + - - - - - - + + + + + + - - - - + + + + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - - - - + + + + - - - - - + + + + + - + @@ -3221,131 +3106,131 @@ - - - - - - + + + + + + - - - + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - + + + + - - - + + + - - - - - - + + + + + + - - - - - + + + + + - - - + + + - - - - - - + + + + + + - - - + + + - - - + + + - - - - - + + + + + - - - + + + - - - + + + - - + + - - - + + + - - - - + + + + - - - - + + + + - - + + - - - + + + - + @@ -3356,30 +3241,30 @@ - - - - - - - + + + + + + + - - - + + + - - - - - - - + + + + + + + - + @@ -3403,26 +3288,26 @@ - - - - - + + + + + - - - - + + + + - - - - + + + + - + @@ -3433,72 +3318,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + - + - - + + - - - - - + + + + + - + - - + + @@ -3509,160 +3394,160 @@ - + - - - - - - - + + + + + + + - + - - - - - + + + + + - - - - + + + + - - - - - - + + + + + + - - - + + + - - - - - + + + + + - - - - - - + + + + + + - - - + + + - - - - + + + + - - - + + + - - + + - - + + - - - + + + - - - - - - + + + + + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - - - + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - - + + + + - + @@ -3700,40 +3585,40 @@ - - - - - - - - + + + + + + + + - - - + + + - - - - + + + + - - - - - + + + + + - - + + - - - + + + - + @@ -3741,173 +3626,173 @@ - - - - - - - + + + + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + @@ -3948,19 +3833,19 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -4013,168 +3898,168 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - + + @@ -4210,8 +4095,8 @@ - - + + @@ -4219,93 +4104,93 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - + - - - - + + + + - - + + - - - + + + - + - - - - + + + + - - - - - - - - + + + + + + + + - - - - + + + + - - - + + + - - - - - + + + + + - + - + - + - + - + - + - - - + + + @@ -4337,35 +4222,35 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + @@ -4377,13 +4262,13 @@ - + - + @@ -4392,518 +4277,518 @@ - + - - + + - - + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + - - - - - + + + + + - - + + - - + + - - + + - - - + + + - + - - + + - - - - + + + + - - - - - - - + + + + + + + - - - - - - + + + + + + - - - - + + + + - - - - + + + + - - - + + + - - - - - - + + + + + + - - - + + + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - + - - - + + + - - + + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - + - + - - + + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + @@ -4911,177 +4796,177 @@ - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - + + - - + + - + - + - + - - + + - + - + - + - + - - + + - - + + - - + + - - + + - - - + + + - - - - + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + @@ -5120,70 +5005,70 @@ - - + + - - + + - - - - + + + + - - + + - + - - + + - + - - + + - - + + - + - + - - + + - + - - + + - + - + @@ -5194,26 +5079,26 @@ - + - + - + - + - + - - + + - - + + @@ -5225,19 +5110,19 @@ - + - - + + - + - + @@ -5272,15 +5157,15 @@ - - + + - - + + - - + + @@ -5294,303 +5179,303 @@ - + - - - - + + + + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - + + - - + + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + - - - - + + + + - + - - - - - + + + + + - - - + + + - - - - - + + + + + - - - + + + - - + + - - - - - + + + + + - - - - - + + + + + - - - + + + - + - + - - - - + + + + - - - + + + - - + + - + - + - + - + - + - + - + - + - - - - - - - - - - - - + + + + + + + + + + + + - - - + + + - - - - - + + + + + - - - - + + + + - - + + - - - + + + - - + + - - + + - + - + @@ -5606,78 +5491,78 @@ - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - + - - + + - - + + - + - - + + - + - + @@ -5685,10 +5570,10 @@ - + - + @@ -5702,15 +5587,15 @@ - + - + - + @@ -5724,16 +5609,16 @@ - + - + - + @@ -5743,69 +5628,69 @@ - - + + - + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + @@ -5817,13 +5702,13 @@ - + - + - + @@ -5831,121 +5716,121 @@ - - + + - + - + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - - - + + + - - - + + + - - - + + + - + - + - - + + - - + + - + - + - - + + - - + + - - + + - + - + - + - + @@ -5956,36 +5841,36 @@ - + - + - + - - + + - - + + - + - - + + @@ -5993,260 +5878,260 @@ - - - + + + - - + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - - + + - - + + - + - + - - - - + + + + - - + + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - + + + - - + + - - - + + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - - + + - - - - + + + + - + - + diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index f469f3a4bf09..423050e045d0 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -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); diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index 45dccccd4e29..4d946fce4a35 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -1505,6 +1505,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; @@ -1516,12 +1517,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. */ @@ -1623,6 +1623,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]); diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 01537b5359a6..8038f7fa343e 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -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);