linux: libshare/nfs: don't do anything unless exportfs is available
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13165 Closes #13324
This commit is contained in:
parent
086af23e68
commit
53600767ee
|
@ -45,6 +45,9 @@
|
||||||
#define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports"
|
#define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports"
|
||||||
#define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock"
|
#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,
|
typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
|
||||||
void *cookie);
|
void *cookie);
|
||||||
|
|
||||||
|
@ -424,6 +427,9 @@ nfs_enable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
|
||||||
static int
|
static int
|
||||||
nfs_enable_share(sa_share_impl_t impl_share)
|
nfs_enable_share(sa_share_impl_t impl_share)
|
||||||
{
|
{
|
||||||
|
if (!nfs_available())
|
||||||
|
return (SA_SYSTEM_ERR);
|
||||||
|
|
||||||
return (nfs_toggle_share(
|
return (nfs_toggle_share(
|
||||||
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
|
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
|
||||||
nfs_enable_share_impl));
|
nfs_enable_share_impl));
|
||||||
|
@ -442,6 +448,9 @@ nfs_disable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
|
||||||
static int
|
static int
|
||||||
nfs_disable_share(sa_share_impl_t impl_share)
|
nfs_disable_share(sa_share_impl_t impl_share)
|
||||||
{
|
{
|
||||||
|
if (!nfs_available())
|
||||||
|
return (SA_SYSTEM_ERR);
|
||||||
|
|
||||||
return (nfs_toggle_share(
|
return (nfs_toggle_share(
|
||||||
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
|
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
|
||||||
nfs_disable_share_impl));
|
nfs_disable_share_impl));
|
||||||
|
@ -450,6 +459,9 @@ nfs_disable_share(sa_share_impl_t impl_share)
|
||||||
static boolean_t
|
static boolean_t
|
||||||
nfs_is_shared(sa_share_impl_t impl_share)
|
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));
|
return (nfs_is_shared_impl(ZFS_EXPORTS_FILE, impl_share));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,6 +483,9 @@ nfs_validate_shareopts(const char *shareopts)
|
||||||
static int
|
static int
|
||||||
nfs_commit_shares(void)
|
nfs_commit_shares(void)
|
||||||
{
|
{
|
||||||
|
if (!nfs_available())
|
||||||
|
return (SA_SYSTEM_ERR);
|
||||||
|
|
||||||
char *argv[] = {
|
char *argv[] = {
|
||||||
(char *)"/usr/sbin/exportfs",
|
(char *)"/usr/sbin/exportfs",
|
||||||
(char *)"-ra",
|
(char *)"-ra",
|
||||||
|
@ -488,3 +503,18 @@ const sa_fstype_t libshare_nfs_type = {
|
||||||
.validate_shareopts = nfs_validate_shareopts,
|
.validate_shareopts = nfs_validate_shareopts,
|
||||||
.commit_shares = nfs_commit_shares,
|
.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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue