Skip to content

Commit

Permalink
Fix nfs_truncate_shares without /etc/exports.d
Browse files Browse the repository at this point in the history
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 <batkinson@lanl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Closes openzfs#15369 
Closes openzfs#15468
  • Loading branch information
siv0 authored Oct 31, 2023
1 parent 763ca47 commit 41e55b4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/libshare/os/linux/nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@


static boolean_t nfs_available(void);
static boolean_t exports_available(void);

typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
void *cookie);
Expand Down Expand Up @@ -539,6 +540,8 @@ nfs_commit_shares(void)
static void
nfs_truncate_shares(void)
{
if (!exports_available())
return;
nfs_reset_shares(ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE);
}

Expand Down Expand Up @@ -566,3 +569,18 @@ nfs_available(void)

return (avail == 1);
}

static boolean_t
exports_available(void)
{
static int avail;

if (!avail) {
if (access(ZFS_EXPORTS_DIR, F_OK) != 0)
avail = -1;
else
avail = 1;
}

return (avail == 1);
}

0 comments on commit 41e55b4

Please sign in to comment.