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 <allan@klarasystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Don Brady <don.brady@delphix.com>
Closes #13775
This commit is contained in:
Don Brady
2022-09-09 11:54:16 -06:00
committed by GitHub
parent 60d995727a
commit ede037cda7
12 changed files with 101 additions and 24 deletions
+11 -1
View File
@@ -22,7 +22,7 @@
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Gunnar Beutner
* Copyright (c) 2018, 2020 by Delphix. All rights reserved.
* Copyright (c) 2018, 2022 by Delphix. All rights reserved.
*/
#include <stdio.h>
@@ -96,6 +96,16 @@ sa_commit_shares(enum sa_protocol protocol)
fstypes[protocol]->commit_shares();
}
void
sa_truncate_shares(enum sa_protocol protocol)
{
/* CSTYLED */
VALIDATE_PROTOCOL(protocol, );
if (fstypes[protocol]->truncate_shares != NULL)
fstypes[protocol]->truncate_shares();
}
int
sa_validate_shareopts(const char *options, enum sa_protocol protocol)
{
+2 -1
View File
@@ -22,7 +22,7 @@
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Gunnar Beutner
* Copyright (c) 2019, 2020 by Delphix. All rights reserved.
* Copyright (c) 2019, 2022 by Delphix. All rights reserved.
*/
#ifndef _LIBSPL_LIBSHARE_IMPL_H
#define _LIBSPL_LIBSHARE_IMPL_H
@@ -39,6 +39,7 @@ typedef struct {
boolean_t (*const is_shared)(sa_share_impl_t share);
int (*const validate_shareopts)(const char *shareopts);
int (*const commit_shares)(void);
void (*const truncate_shares)(void);
} sa_fstype_t;
extern const sa_fstype_t libshare_nfs_type, libshare_smb_type;
+12
View File
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <errno.h>
#include <libshare.h>
#include <unistd.h>
#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)
{
+2
View File
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Gunnar Beutner
* Copyright (c) 2022 by Delphix. All rights reserved.
*/
#include "libshare_impl.h"
@@ -33,3 +34,4 @@ boolean_t nfs_is_shared_impl(const char *exports, sa_share_impl_t impl_share);
int nfs_toggle_share(const char *lockfile, const char *exports,
const char *expdir, sa_share_impl_t impl_share,
int(*cbk)(sa_share_impl_t impl_share, FILE *tmpfile));
void nfs_reset_shares(const char *lockfile, const char *exports);
+8 -1
View File
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Copyright (c) 2020 by Delphix. All rights reserved.
* Copyright (c) 2020, 2022 by Delphix. All rights reserved.
*/
#include <sys/cdefs.h>
@@ -195,6 +195,12 @@ start:
return (SA_OK);
}
static void
nfs_truncate_shares(void)
{
nfs_reset_shares(ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE);
}
const sa_fstype_t libshare_nfs_type = {
.enable_share = nfs_enable_share,
.disable_share = nfs_disable_share,
@@ -202,4 +208,5 @@ const sa_fstype_t libshare_nfs_type = {
.validate_shareopts = nfs_validate_shareopts,
.commit_shares = nfs_commit_shares,
.truncate_shares = nfs_truncate_shares,
};
+8 -1
View File
@@ -23,7 +23,7 @@
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Gunnar Beutner
* Copyright (c) 2012 Cyril Plisko. All rights reserved.
* Copyright (c) 2019, 2020 by Delphix. All rights reserved.
* Copyright (c) 2019, 2022 by Delphix. All rights reserved.
*/
#include <dirent.h>
@@ -495,6 +495,12 @@ nfs_commit_shares(void)
return (libzfs_run_process(argv[0], argv, 0));
}
static void
nfs_truncate_shares(void)
{
nfs_reset_shares(ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE);
}
const sa_fstype_t libshare_nfs_type = {
.enable_share = nfs_enable_share,
.disable_share = nfs_disable_share,
@@ -502,6 +508,7 @@ const sa_fstype_t libshare_nfs_type = {
.validate_shareopts = nfs_validate_shareopts,
.commit_shares = nfs_commit_shares,
.truncate_shares = nfs_truncate_shares,
};
static boolean_t