Skip to content

Commit 41e55b4

Browse files
authored
Fix nfs_truncate_shares without /etc/exports.d
Calling nfs_reset_shares on Linux prints a warning: `failed to lock /etc/exports.d/zfs.exports.lock: No such file or directory` when /etc/exports.d does not exist. The directory gets created, when a filesystem is actually exported through nfs_toggle_share and nfs_init_share. The truncation of /etc/exports.d/zfs.exports happens unconditionally when calling `zfs mount -a` (via zfs_do_mount and share_mount in `cmd/zfs/zfs_main.c`). Fixing the issue only in the Linux part, since the exports file on freebsd is in `/etc/zfs/`, which seems present on 2 FreeBSD systems I have access to (through `/etc/zfs/compatibility.d/`), while a Debian box does not have the directory even if `/usr/sbin/exportfs` is present through the `nfs-kernel-server` package. The code for exports_available is copied from nfs_available above. Fixes: ede037c ("Make zfs-share service resilient to stale exports") Reviewed-by: Brian Atkinson <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Stoiko Ivanov <[email protected]> Closes #15369 Closes #15468
1 parent 763ca47 commit 41e55b4

File tree

1 file changed

+18
-0
lines changed
  • lib/libshare/os/linux

1 file changed

+18
-0
lines changed

lib/libshare/os/linux/nfs.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848

4949
static boolean_t nfs_available(void);
50+
static boolean_t exports_available(void);
5051

5152
typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
5253
void *cookie);
@@ -539,6 +540,8 @@ nfs_commit_shares(void)
539540
static void
540541
nfs_truncate_shares(void)
541542
{
543+
if (!exports_available())
544+
return;
542545
nfs_reset_shares(ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE);
543546
}
544547

@@ -566,3 +569,18 @@ nfs_available(void)
566569

567570
return (avail == 1);
568571
}
572+
573+
static boolean_t
574+
exports_available(void)
575+
{
576+
static int avail;
577+
578+
if (!avail) {
579+
if (access(ZFS_EXPORTS_DIR, F_OK) != 0)
580+
avail = -1;
581+
else
582+
avail = 1;
583+
}
584+
585+
return (avail == 1);
586+
}

0 commit comments

Comments
 (0)