diff options
author | наб <[email protected]> | 2021-04-09 00:44:23 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-04-13 14:14:44 -0700 |
commit | 533527725bf3fa72b8feb61993d1ed0d6e5672dc (patch) | |
tree | 3255d96e5f8570d66c0d9212af724f407220243c /cmd/zfs/zfs_main.c | |
parent | 74e48f470e8190ed64bbea020e6535f69e17c1a8 (diff) |
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 <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #11868
Diffstat (limited to 'cmd/zfs/zfs_main.c')
-rw-r--r-- | cmd/zfs/zfs_main.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 395fc353f..24ff074c4 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); |