aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libshare
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-04-17 15:03:03 +0200
committerBrian Behlendorf <[email protected]>2022-05-12 09:27:12 -0700
commit53600767ee8c9e3c25fff3fbb61de89a2952a4ef (patch)
treed17e5c5e29e3b4f22d9368da4958952600a1f6ef /lib/libshare
parent086af23e683c62d24055b46a6b93de78825a5219 (diff)
linux: libshare/nfs: don't do anything unless exportfs is available
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13165 Closes #13324
Diffstat (limited to 'lib/libshare')
-rw-r--r--lib/libshare/os/linux/nfs.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c
index a7b40ea77..1da6d1617 100644
--- a/lib/libshare/os/linux/nfs.c
+++ b/lib/libshare/os/linux/nfs.c
@@ -45,6 +45,9 @@
#define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports"
#define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock"
+
+static boolean_t nfs_available(void);
+
typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
void *cookie);
@@ -424,6 +427,9 @@ nfs_enable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
static int
nfs_enable_share(sa_share_impl_t impl_share)
{
+ if (!nfs_available())
+ return (SA_SYSTEM_ERR);
+
return (nfs_toggle_share(
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
nfs_enable_share_impl));
@@ -442,6 +448,9 @@ nfs_disable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
static int
nfs_disable_share(sa_share_impl_t impl_share)
{
+ if (!nfs_available())
+ return (SA_SYSTEM_ERR);
+
return (nfs_toggle_share(
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
nfs_disable_share_impl));
@@ -450,6 +459,9 @@ nfs_disable_share(sa_share_impl_t impl_share)
static boolean_t
nfs_is_shared(sa_share_impl_t impl_share)
{
+ if (!nfs_available())
+ return (SA_SYSTEM_ERR);
+
return (nfs_is_shared_impl(ZFS_EXPORTS_FILE, impl_share));
}
@@ -471,6 +483,9 @@ nfs_validate_shareopts(const char *shareopts)
static int
nfs_commit_shares(void)
{
+ if (!nfs_available())
+ return (SA_SYSTEM_ERR);
+
char *argv[] = {
(char *)"/usr/sbin/exportfs",
(char *)"-ra",
@@ -488,3 +503,18 @@ const sa_fstype_t libshare_nfs_type = {
.validate_shareopts = nfs_validate_shareopts,
.commit_shares = nfs_commit_shares,
};
+
+static boolean_t
+nfs_available(void)
+{
+ static int avail;
+
+ if (!avail) {
+ if (access("/usr/sbin/exportfs", F_OK) != 0)
+ avail = -1;
+ else
+ avail = 1;
+ }
+
+ return (avail == 1);
+}