aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libshare/os/linux
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-04-11 19:37:48 +0200
committerBrian Behlendorf <[email protected]>2021-04-19 09:06:52 -0700
commita3d387b31de44e2069c00bed18491e032c7424dc (patch)
treecb5573421f2be96b3f8469feea22200a4f24ab32 /lib/libshare/os/linux
parent0f4d83117a6baad3743a1ada469f296a3e7ae3d0 (diff)
libshare: nfs: commonify nfs_exports_[un]lock(), FILE_HEADER
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: George Wilson <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11886
Diffstat (limited to 'lib/libshare/os/linux')
-rw-r--r--lib/libshare/os/linux/nfs.c58
1 files changed, 7 insertions, 51 deletions
diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c
index a7bcbd138..08c7db1bc 100644
--- a/lib/libshare/os/linux/nfs.c
+++ b/lib/libshare/os/linux/nfs.c
@@ -42,7 +42,6 @@
#include "libshare_impl.h"
#include "nfs.h"
-#define FILE_HEADER "# !!! DO NOT EDIT THIS FILE MANUALLY !!!\n\n"
#define ZFS_EXPORTS_DIR "/etc/exports.d"
#define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports"
#define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock"
@@ -55,49 +54,6 @@ typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
typedef int (*nfs_host_callback_t)(const char *sharepath, const char *filename,
const char *host, const char *security, const char *access, void *cookie);
-static int nfs_lock_fd = -1;
-
-/*
- * The nfs_exports_[lock|unlock] is used to guard against conconcurrent
- * updates to the exports file. Each protocol is responsible for
- * providing the necessary locking to ensure consistency.
- */
-static int
-nfs_exports_lock(void)
-{
- int err;
-
- nfs_lock_fd = open(ZFS_EXPORTS_LOCK,
- O_RDWR | O_CREAT | O_CLOEXEC, 0600);
- if (nfs_lock_fd == -1) {
- err = errno;
- fprintf(stderr, "failed to lock %s: %s\n",
- ZFS_EXPORTS_LOCK, strerror(err));
- return (err);
- }
- if (flock(nfs_lock_fd, LOCK_EX) != 0) {
- err = errno;
- fprintf(stderr, "failed to lock %s: %s\n",
- ZFS_EXPORTS_LOCK, strerror(err));
- (void) close(nfs_lock_fd);
- return (err);
- }
- return (0);
-}
-
-static void
-nfs_exports_unlock(void)
-{
- verify(nfs_lock_fd > 0);
-
- if (flock(nfs_lock_fd, LOCK_UN) != 0) {
- fprintf(stderr, "failed to unlock %s: %s\n",
- ZFS_EXPORTS_LOCK, strerror(errno));
- }
- close(nfs_lock_fd);
- nfs_lock_fd = -1;
-}
-
/*
* Invokes the specified callback function for each Solaris share option
* listed in the specified string.
@@ -563,7 +519,7 @@ nfs_enable_share(sa_share_impl_t impl_share)
if ((filename = nfs_init_tmpfile()) == NULL)
return (SA_SYSTEM_ERR);
- error = nfs_exports_lock();
+ error = nfs_exports_lock(ZFS_EXPORTS_LOCK);
if (error != 0) {
unlink(filename);
free(filename);
@@ -574,7 +530,7 @@ nfs_enable_share(sa_share_impl_t impl_share)
if (error != SA_OK) {
unlink(filename);
free(filename);
- nfs_exports_unlock();
+ nfs_exports_unlock(ZFS_EXPORTS_LOCK);
return (error);
}
@@ -583,7 +539,7 @@ nfs_enable_share(sa_share_impl_t impl_share)
if (error != SA_OK) {
unlink(filename);
free(filename);
- nfs_exports_unlock();
+ nfs_exports_unlock(ZFS_EXPORTS_LOCK);
return (error);
}
@@ -596,7 +552,7 @@ nfs_enable_share(sa_share_impl_t impl_share)
unlink(filename);
free(filename);
}
- nfs_exports_unlock();
+ nfs_exports_unlock(ZFS_EXPORTS_LOCK);
return (error);
}
@@ -612,7 +568,7 @@ nfs_disable_share(sa_share_impl_t impl_share)
if ((filename = nfs_init_tmpfile()) == NULL)
return (SA_SYSTEM_ERR);
- error = nfs_exports_lock();
+ error = nfs_exports_lock(ZFS_EXPORTS_LOCK);
if (error != 0) {
unlink(filename);
free(filename);
@@ -623,11 +579,11 @@ nfs_disable_share(sa_share_impl_t impl_share)
if (error != SA_OK) {
unlink(filename);
free(filename);
- nfs_exports_unlock();
+ nfs_exports_unlock(ZFS_EXPORTS_LOCK);
return (error);
}
error = nfs_fini_tmpfile(filename);
- nfs_exports_unlock();
+ nfs_exports_unlock(ZFS_EXPORTS_LOCK);
return (error);
}