From ede037cda73675f42b1452187e8dd3438fafc220 Mon Sep 17 00:00:00 2001 From: Don Brady Date: Fri, 9 Sep 2022 11:54:16 -0600 Subject: Make zfs-share service resilient to stale exports The are a few cases where stale entries in /etc/exports.d/zfs.exports will cause the nfs-server service to fail when starting up. Since the nfs-server startup consumes /etc/exports.d/zfs.exports, the zfs-share service (which rebuilds the list of zfs exports) should run before the nfs-server service. To make the zfs-share service resilient to stale exports, this change truncates the zfs config file as part of the zfs share -a operation. Reviewed-by: Allan Jude Reviewed-by: Brian Behlendorf Signed-off-by: Don Brady Closes #13775 --- lib/libshare/nfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/libshare/nfs.c') diff --git a/lib/libshare/nfs.c b/lib/libshare/nfs.c index 161bbfb0c..bbaea93fc 100644 --- a/lib/libshare/nfs.c +++ b/lib/libshare/nfs.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "nfs.h" @@ -281,6 +282,17 @@ fullerr: return (error); } +void +nfs_reset_shares(const char *lockfile, const char *exports) +{ + int nfs_lock_fd = -1; + + if (nfs_exports_lock(lockfile, &nfs_lock_fd) == 0) { + (void) ! truncate(exports, 0); + nfs_exports_unlock(lockfile, &nfs_lock_fd); + } +} + static boolean_t nfs_is_shared_cb(void *userdata, char *line, boolean_t found_mountpoint) { -- cgit v1.2.3