]> git.proxmox.com Git - zfsonlinux.git/blame - debian/patches/0012-Fix-nfs_truncate_shares-without-etc-exports.d.patch
cherry-pick fix for data corruption
[zfsonlinux.git] / debian / patches / 0012-Fix-nfs_truncate_shares-without-etc-exports.d.patch
CommitLineData
0f9a07b5
SI
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: siv0 <github@nomore.at>
3Date: Tue, 31 Oct 2023 21:57:54 +0100
4Subject: [PATCH] Fix nfs_truncate_shares without /etc/exports.d
5
6Calling nfs_reset_shares on Linux prints a warning:
7`failed to lock /etc/exports.d/zfs.exports.lock: No such file or
8directory`
9when /etc/exports.d does not exist. The directory gets created, when a
10filesystem is actually exported through nfs_toggle_share and
11nfs_init_share. The truncation of /etc/exports.d/zfs.exports happens
12unconditionally when calling `zfs mount -a` (via zfs_do_mount and
13share_mount in `cmd/zfs/zfs_main.c`).
14
15Fixing the issue only in the Linux part, since the exports file on
16freebsd is in `/etc/zfs/`, which seems present on 2 FreeBSD systems I
17have access to (through `/etc/zfs/compatibility.d/`), while a Debian
18box does not have the directory even if `/usr/sbin/exportfs` is
19present through the `nfs-kernel-server` package.
20
21The code for exports_available is copied from nfs_available above.
22
23Fixes: ede037cda73675f42b1452187e8dd3438fafc220
24("Make zfs-share service resilient to stale exports")
25
26Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
27Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
28Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
29Closes #15369
30Closes #15468
31(cherry picked from commit 41e55b476bcfc90f1ad81c02c5375367fdace9e9)
32Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
33---
34 lib/libshare/os/linux/nfs.c | 18 ++++++++++++++++++
35 1 file changed, 18 insertions(+)
36
37diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c
38index 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+}