diff options
author | John M. Layman <[email protected]> | 2014-03-26 13:17:17 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2014-04-04 09:46:20 -0700 |
commit | cbca6076b33e3d1af330e0e1f00cbf1baaf26d82 (patch) | |
tree | 30c041bd7cea206aeac962f4cd48d4b264663b18 /cmd | |
parent | f3ad9cd67ae57760a7ec9e8cdb0e33aa8bbea4d0 (diff) |
Fix for re-reading /etc/mtab.
This is a continuation of fb5c53ea65b75c67c23f90ebbbb1134a5bb6c140:
When /etc/mtab is updated on Linux it's done atomically with
rename(2). A new mtab is written, the existing mtab is unlinked,
and the new mtab is renamed to /etc/mtab. This means that we
must close the old file and open the new file to get the updated
contents. Using rewind(3) will just move the file pointer back
to the start of the file, freopen(3) will close and open the file.
In this commit, a few more rewind(3) calls were replaced with freopen(3)
to allow updated mtab entries to be picked up immediately.
Signed-off-by: John M. Layman <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #2215
Issue #1611
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zfs/zfs_main.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 836979bdf..d7c1a2a47 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -5862,7 +5862,11 @@ share_mount(int op, int argc, char **argv) * display any active ZFS mounts. We hide any snapshots, since * they are controlled automatically. */ - rewind(mnttab_file); + + /* Reopen MNTTAB to prevent reading stale data from open file */ + if (freopen(MNTTAB, "r", mnttab_file) == NULL) + return (ENOENT); + while (getmntent(mnttab_file, &entry) == 0) { if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0 || strchr(entry.mnt_special, '@') != NULL) @@ -5965,7 +5969,11 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) /* * Search for the given (major,minor) pair in the mount table. */ - rewind(mnttab_file); + + /* Reopen MNTTAB to prevent reading stale data from open file */ + if (freopen(MNTTAB, "r", mnttab_file) == NULL) + return (ENOENT); + while ((ret = getextmntent(mnttab_file, &entry, 0)) == 0) { if (entry.mnt_major == major(statbuf.st_dev) && entry.mnt_minor == minor(statbuf.st_dev)) @@ -6119,7 +6127,10 @@ unshare_unmount(int op, int argc, char **argv) ((tree = uu_avl_create(pool, NULL, UU_DEFAULT)) == NULL)) nomem(); - rewind(mnttab_file); + /* Reopen MNTTAB to prevent reading stale data from open file */ + if (freopen(MNTTAB, "r", mnttab_file) == NULL) + return (ENOENT); + while (getmntent(mnttab_file, &entry) == 0) { /* ignore non-ZFS entries */ |