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 /lib | |
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 'lib')
-rw-r--r-- | lib/libzfs/libzfs_mount.c | 5 | ||||
-rw-r--r-- | lib/libzfs/libzfs_util.c | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index 3cd6406b2..b85c5d04f 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -1165,7 +1165,10 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force) namelen = strlen(zhp->zpool_name); - rewind(hdl->libzfs_mnttab); + /* Reopen MNTTAB to prevent reading stale data from open file */ + if (freopen(MNTTAB, "r", hdl->libzfs_mnttab) == NULL) + return (ENOENT); + used = alloc = 0; while (getmntent(hdl->libzfs_mnttab, &entry) == 0) { /* diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 706ae1769..e99603b49 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -793,7 +793,10 @@ zfs_path_to_zhandle(libzfs_handle_t *hdl, char *path, zfs_type_t argtype) return (NULL); } - rewind(hdl->libzfs_mnttab); + /* Reopen MNTTAB to prevent reading stale data from open file */ + if (freopen(MNTTAB, "r", hdl->libzfs_mnttab) == NULL) + return (NULL); + while ((ret = getextmntent(hdl->libzfs_mnttab, &entry, 0)) == 0) { if (makedevice(entry.mnt_major, entry.mnt_minor) == statbuf.st_dev) { |