]>
Commit | Line | Data |
---|---|---|
0f9a07b5 SI |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: siv0 <github@nomore.at> | |
3 | Date: Tue, 31 Oct 2023 21:57:54 +0100 | |
4 | Subject: [PATCH] Fix nfs_truncate_shares without /etc/exports.d | |
5 | ||
6 | Calling nfs_reset_shares on Linux prints a warning: | |
7 | `failed to lock /etc/exports.d/zfs.exports.lock: No such file or | |
8 | directory` | |
9 | when /etc/exports.d does not exist. The directory gets created, when a | |
10 | filesystem is actually exported through nfs_toggle_share and | |
11 | nfs_init_share. The truncation of /etc/exports.d/zfs.exports happens | |
12 | unconditionally when calling `zfs mount -a` (via zfs_do_mount and | |
13 | share_mount in `cmd/zfs/zfs_main.c`). | |
14 | ||
15 | Fixing the issue only in the Linux part, since the exports file on | |
16 | freebsd is in `/etc/zfs/`, which seems present on 2 FreeBSD systems I | |
17 | have access to (through `/etc/zfs/compatibility.d/`), while a Debian | |
18 | box does not have the directory even if `/usr/sbin/exportfs` is | |
19 | present through the `nfs-kernel-server` package. | |
20 | ||
21 | The code for exports_available is copied from nfs_available above. | |
22 | ||
23 | Fixes: ede037cda73675f42b1452187e8dd3438fafc220 | |
24 | ("Make zfs-share service resilient to stale exports") | |
25 | ||
26 | Reviewed-by: Brian Atkinson <batkinson@lanl.gov> | |
27 | Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> | |
28 | Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com> | |
29 | Closes #15369 | |
30 | Closes #15468 | |
31 | (cherry picked from commit 41e55b476bcfc90f1ad81c02c5375367fdace9e9) | |
32 | Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com> | |
33 | --- | |
34 | lib/libshare/os/linux/nfs.c | 18 ++++++++++++++++++ | |
35 | 1 file changed, 18 insertions(+) | |
36 | ||
37 | diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c | |
38 | index 004946b0c..3dce81840 100644 | |
39 | --- a/lib/libshare/os/linux/nfs.c | |
40 | +++ b/lib/libshare/os/linux/nfs.c | |
41 | @@ -47,6 +47,7 @@ | |
42 | ||
43 | ||
44 | static boolean_t nfs_available(void); | |
45 | +static boolean_t exports_available(void); | |
46 | ||
47 | typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value, | |
48 | void *cookie); | |
49 | @@ -539,6 +540,8 @@ nfs_commit_shares(void) | |
50 | static void | |
51 | nfs_truncate_shares(void) | |
52 | { | |
53 | + if (!exports_available()) | |
54 | + return; | |
55 | nfs_reset_shares(ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE); | |
56 | } | |
57 | ||
58 | @@ -566,3 +569,18 @@ nfs_available(void) | |
59 | ||
60 | return (avail == 1); | |
61 | } | |
62 | + | |
63 | +static boolean_t | |
64 | +exports_available(void) | |
65 | +{ | |
66 | + static int avail; | |
67 | + | |
68 | + if (!avail) { | |
69 | + if (access(ZFS_EXPORTS_DIR, F_OK) != 0) | |
70 | + avail = -1; | |
71 | + else | |
72 | + avail = 1; | |
73 | + } | |
74 | + | |
75 | + return (avail == 1); | |
76 | +} |