2011-07-02 19:34:05 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* Copyright (c) 2011 Gunnar Beutner
|
2012-09-05 16:44:53 +00:00
|
|
|
* Copyright (c) 2012 Cyril Plisko. All rights reserved.
|
2020-07-13 16:19:18 +00:00
|
|
|
* Copyright (c) 2019, 2020 by Delphix. All rights reserved.
|
2011-07-02 19:34:05 +00:00
|
|
|
*/
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
#include <dirent.h>
|
2011-07-02 19:34:05 +00:00
|
|
|
#include <stdio.h>
|
2018-02-16 01:53:18 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2020-09-04 19:03:57 +00:00
|
|
|
#include <fcntl.h>
|
2020-07-13 16:19:18 +00:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2011-07-02 19:34:05 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libzfs.h>
|
|
|
|
#include <libshare.h>
|
|
|
|
#include "libshare_impl.h"
|
2020-06-11 20:25:39 +00:00
|
|
|
#include "nfs.h"
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
#define ZFS_EXPORTS_DIR "/etc/exports.d"
|
|
|
|
#define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports"
|
|
|
|
#define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock"
|
2012-09-05 16:44:53 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value,
|
|
|
|
void *cookie);
|
|
|
|
|
2021-05-17 16:13:18 +00:00
|
|
|
typedef int (*nfs_host_callback_t)(FILE *tmpfile, const char *sharepath,
|
2020-07-13 16:19:18 +00:00
|
|
|
const char *host, const char *security, const char *access, void *cookie);
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Invokes the specified callback function for each Solaris share option
|
|
|
|
* listed in the specified string.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
|
|
|
foreach_nfs_shareopt(const char *shareopts,
|
|
|
|
nfs_shareopt_callback_t callback, void *cookie)
|
|
|
|
{
|
|
|
|
char *shareopts_dup, *opt, *cur, *value;
|
2020-07-13 16:19:18 +00:00
|
|
|
int was_nul, error;
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
if (shareopts == NULL)
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_OK);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
if (strcmp(shareopts, "on") == 0)
|
|
|
|
shareopts = "rw,crossmnt";
|
|
|
|
|
2011-07-02 19:34:05 +00:00
|
|
|
shareopts_dup = strdup(shareopts);
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
|
2011-07-02 19:34:05 +00:00
|
|
|
if (shareopts_dup == NULL)
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_NO_MEMORY);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
opt = shareopts_dup;
|
|
|
|
was_nul = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
cur = opt;
|
|
|
|
|
|
|
|
while (*cur != ',' && *cur != '\0')
|
|
|
|
cur++;
|
|
|
|
|
|
|
|
if (*cur == '\0')
|
|
|
|
was_nul = 1;
|
|
|
|
|
|
|
|
*cur = '\0';
|
|
|
|
|
|
|
|
if (cur > opt) {
|
|
|
|
value = strchr(opt, '=');
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
*value = '\0';
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
error = callback(opt, value, cookie);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
if (error != SA_OK) {
|
2011-07-02 19:34:05 +00:00
|
|
|
free(shareopts_dup);
|
2020-07-13 16:19:18 +00:00
|
|
|
return (error);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
opt = cur + 1;
|
|
|
|
|
|
|
|
if (was_nul)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(shareopts_dup);
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
return (SA_OK);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct nfs_host_cookie_s {
|
|
|
|
nfs_host_callback_t callback;
|
|
|
|
const char *sharepath;
|
|
|
|
void *cookie;
|
2021-05-17 16:13:18 +00:00
|
|
|
FILE *tmpfile;
|
2011-07-02 19:34:05 +00:00
|
|
|
const char *security;
|
|
|
|
} nfs_host_cookie_t;
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Helper function for foreach_nfs_host. This function checks whether the
|
|
|
|
* current share option is a host specification and invokes a callback
|
|
|
|
* function with information about the host.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
|
|
|
foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
|
|
|
|
{
|
2020-07-13 16:19:18 +00:00
|
|
|
int error;
|
2011-07-02 19:34:05 +00:00
|
|
|
const char *access;
|
2021-10-20 17:40:00 +00:00
|
|
|
char *host_dup, *host, *next, *v6Literal;
|
2011-07-02 19:34:05 +00:00
|
|
|
nfs_host_cookie_t *udata = (nfs_host_cookie_t *)pcookie;
|
2021-10-20 17:40:00 +00:00
|
|
|
int cidr_len;
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "foreach_nfs_host_cb: key=%s, value=%s\n", opt, value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (strcmp(opt, "sec") == 0)
|
|
|
|
udata->security = value;
|
|
|
|
|
|
|
|
if (strcmp(opt, "rw") == 0 || strcmp(opt, "ro") == 0) {
|
|
|
|
if (value == NULL)
|
|
|
|
value = "*";
|
|
|
|
|
|
|
|
access = opt;
|
|
|
|
|
|
|
|
host_dup = strdup(value);
|
|
|
|
|
|
|
|
if (host_dup == NULL)
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_NO_MEMORY);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
host = host_dup;
|
|
|
|
|
|
|
|
do {
|
2021-10-20 17:40:00 +00:00
|
|
|
if (*host == '[') {
|
|
|
|
host++;
|
|
|
|
v6Literal = strchr(host, ']');
|
|
|
|
if (v6Literal == NULL) {
|
|
|
|
free(host_dup);
|
|
|
|
return (SA_SYNTAX_ERR);
|
|
|
|
}
|
|
|
|
if (v6Literal[1] == '\0') {
|
|
|
|
*v6Literal = '\0';
|
|
|
|
next = NULL;
|
|
|
|
} else if (v6Literal[1] == '/') {
|
|
|
|
next = strchr(v6Literal + 2, ':');
|
|
|
|
if (next == NULL) {
|
|
|
|
cidr_len =
|
|
|
|
strlen(v6Literal + 1);
|
|
|
|
memmove(v6Literal,
|
|
|
|
v6Literal + 1,
|
|
|
|
cidr_len);
|
|
|
|
v6Literal[cidr_len] = '\0';
|
|
|
|
} else {
|
|
|
|
cidr_len = next - v6Literal - 1;
|
|
|
|
memmove(v6Literal,
|
|
|
|
v6Literal + 1,
|
|
|
|
cidr_len);
|
|
|
|
v6Literal[cidr_len] = '\0';
|
|
|
|
next++;
|
|
|
|
}
|
|
|
|
} else if (v6Literal[1] == ':') {
|
|
|
|
*v6Literal = '\0';
|
|
|
|
next = v6Literal + 2;
|
|
|
|
} else {
|
|
|
|
free(host_dup);
|
|
|
|
return (SA_SYNTAX_ERR);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
next = strchr(host, ':');
|
|
|
|
if (next != NULL) {
|
|
|
|
*next = '\0';
|
|
|
|
next++;
|
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 16:13:18 +00:00
|
|
|
error = udata->callback(udata->tmpfile,
|
2020-07-13 16:19:18 +00:00
|
|
|
udata->sharepath, host, udata->security,
|
|
|
|
access, udata->cookie);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
if (error != SA_OK) {
|
2011-07-02 19:34:05 +00:00
|
|
|
free(host_dup);
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
return (error);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
host = next;
|
|
|
|
} while (host != NULL);
|
|
|
|
|
|
|
|
free(host_dup);
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_OK);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Invokes a callback function for all NFS hosts that are set for a share.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
2021-05-17 16:13:18 +00:00
|
|
|
foreach_nfs_host(sa_share_impl_t impl_share, FILE *tmpfile,
|
2020-07-13 16:19:18 +00:00
|
|
|
nfs_host_callback_t callback, void *cookie)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
|
|
|
nfs_host_cookie_t udata;
|
|
|
|
|
|
|
|
udata.callback = callback;
|
2020-07-13 16:19:18 +00:00
|
|
|
udata.sharepath = impl_share->sa_mountpoint;
|
2011-07-02 19:34:05 +00:00
|
|
|
udata.cookie = cookie;
|
2021-05-17 16:13:18 +00:00
|
|
|
udata.tmpfile = tmpfile;
|
2011-07-02 19:34:05 +00:00
|
|
|
udata.security = "sys";
|
|
|
|
|
2022-02-28 13:50:28 +00:00
|
|
|
return (foreach_nfs_shareopt(impl_share->sa_shareopts,
|
|
|
|
foreach_nfs_host_cb, &udata));
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Converts a Solaris NFS host specification to its Linux equivalent.
|
|
|
|
*/
|
2021-05-17 18:34:04 +00:00
|
|
|
static const char *
|
|
|
|
get_linux_hostspec(const char *solaris_hostspec)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For now we just support CIDR masks (e.g. @192.168.0.0/16) and host
|
|
|
|
* wildcards (e.g. *.example.org).
|
|
|
|
*/
|
|
|
|
if (solaris_hostspec[0] == '@') {
|
|
|
|
/*
|
|
|
|
* Solaris host specifier, e.g. @192.168.0.0/16; we just need
|
|
|
|
* to skip the @ in this case
|
|
|
|
*/
|
2021-05-17 18:34:04 +00:00
|
|
|
return (solaris_hostspec + 1);
|
2011-07-02 19:34:05 +00:00
|
|
|
} else {
|
2021-05-17 18:34:04 +00:00
|
|
|
return (solaris_hostspec);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Adds a Linux share option to an array of NFS options.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
|
|
|
add_linux_shareopt(char **plinux_opts, const char *key, const char *value)
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
|
|
|
char *new_linux_opts;
|
|
|
|
|
|
|
|
if (*plinux_opts != NULL)
|
|
|
|
len = strlen(*plinux_opts);
|
|
|
|
|
|
|
|
new_linux_opts = realloc(*plinux_opts, len + 1 + strlen(key) +
|
|
|
|
(value ? 1 + strlen(value) : 0) + 1);
|
|
|
|
|
|
|
|
if (new_linux_opts == NULL)
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_NO_MEMORY);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
new_linux_opts[len] = '\0';
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
strcat(new_linux_opts, ",");
|
|
|
|
|
|
|
|
strcat(new_linux_opts, key);
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
strcat(new_linux_opts, "=");
|
|
|
|
strcat(new_linux_opts, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
*plinux_opts = new_linux_opts;
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_OK);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 16:44:06 +00:00
|
|
|
static int string_cmp(const void *lhs, const void *rhs) {
|
|
|
|
const char *const *l = lhs, *const *r = rhs;
|
|
|
|
return (strcmp(*l, *r));
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Validates and converts a single Solaris share option to its Linux
|
|
|
|
* equivalent.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
|
|
|
get_linux_shareopts_cb(const char *key, const char *value, void *cookie)
|
|
|
|
{
|
2022-02-28 16:44:06 +00:00
|
|
|
/* This list must remain sorted, since we bsearch() it */
|
|
|
|
static const char *const valid_keys[] = { "all_squash", "anongid",
|
|
|
|
"anonuid", "async", "auth_nlm", "crossmnt", "fsid", "fsuid", "hide",
|
|
|
|
"insecure", "insecure_locks", "mountpoint", "mp", "no_acl",
|
|
|
|
"no_all_squash", "no_auth_nlm", "no_root_squash",
|
|
|
|
"no_subtree_check", "no_wdelay", "nohide", "refer", "replicas",
|
|
|
|
"root_squash", "secure", "secure_locks", "subtree_check", "sync",
|
|
|
|
"wdelay" };
|
|
|
|
|
2011-07-02 19:34:05 +00:00
|
|
|
char **plinux_opts = (char **)cookie;
|
|
|
|
|
|
|
|
/* host-specific options, these are taken care of elsewhere */
|
|
|
|
if (strcmp(key, "ro") == 0 || strcmp(key, "rw") == 0 ||
|
|
|
|
strcmp(key, "sec") == 0)
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_OK);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
if (strcmp(key, "anon") == 0)
|
|
|
|
key = "anonuid";
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
if (strcmp(key, "root_mapping") == 0) {
|
|
|
|
(void) add_linux_shareopt(plinux_opts, "root_squash", NULL);
|
|
|
|
key = "anonuid";
|
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
if (strcmp(key, "nosub") == 0)
|
|
|
|
key = "subtree_check";
|
|
|
|
|
2022-02-28 16:44:06 +00:00
|
|
|
if (bsearch(&key, valid_keys, ARRAY_SIZE(valid_keys),
|
|
|
|
sizeof (*valid_keys), string_cmp) == NULL)
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_SYNTAX_ERR);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
(void) add_linux_shareopt(plinux_opts, key, value);
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
return (SA_OK);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Takes a string containing Solaris share options (e.g. "sync,no_acl") and
|
|
|
|
* converts them to a NULL-terminated array of Linux NFS options.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
|
|
|
get_linux_shareopts(const char *shareopts, char **plinux_opts)
|
|
|
|
{
|
2020-07-13 16:19:18 +00:00
|
|
|
int error;
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
assert(plinux_opts != NULL);
|
|
|
|
|
|
|
|
*plinux_opts = NULL;
|
|
|
|
|
2019-10-14 02:13:26 +00:00
|
|
|
/* no_subtree_check - Default as of nfs-utils v1.1.0 */
|
2011-07-02 19:34:05 +00:00
|
|
|
(void) add_linux_shareopt(plinux_opts, "no_subtree_check", NULL);
|
2019-10-14 02:13:26 +00:00
|
|
|
|
|
|
|
/* mountpoint - Restrict exports to ZFS mountpoints */
|
2011-07-02 19:34:05 +00:00
|
|
|
(void) add_linux_shareopt(plinux_opts, "mountpoint", NULL);
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
error = foreach_nfs_shareopt(shareopts, get_linux_shareopts_cb,
|
2013-11-01 19:26:11 +00:00
|
|
|
plinux_opts);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
if (error != SA_OK) {
|
2011-07-02 19:34:05 +00:00
|
|
|
free(*plinux_opts);
|
|
|
|
*plinux_opts = NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
return (error);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2020-07-13 16:19:18 +00:00
|
|
|
* This function populates an entry into /etc/exports.d/zfs.exports.
|
|
|
|
* This file is consumed by the linux nfs server so that zfs shares are
|
|
|
|
* automatically exported upon boot or whenever the nfs server restarts.
|
2011-12-03 22:01:06 +00:00
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
2021-05-17 16:13:18 +00:00
|
|
|
nfs_add_entry(FILE *tmpfile, const char *sharepath,
|
2020-07-13 16:19:18 +00:00
|
|
|
const char *host, const char *security, const char *access_opts,
|
|
|
|
void *pcookie)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2020-07-13 16:19:18 +00:00
|
|
|
const char *linux_opts = (const char *)pcookie;
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
if (linux_opts == NULL)
|
|
|
|
linux_opts = "";
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2022-02-28 19:42:22 +00:00
|
|
|
boolean_t need_free;
|
|
|
|
char *mp;
|
|
|
|
int rc = nfs_escape_mountpoint(sharepath, &mp, &need_free);
|
|
|
|
if (rc != SA_OK)
|
|
|
|
return (rc);
|
|
|
|
if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", mp,
|
2021-05-17 18:34:04 +00:00
|
|
|
get_linux_hostspec(host), security, access_opts,
|
|
|
|
linux_opts) < 0) {
|
2021-05-17 16:13:18 +00:00
|
|
|
fprintf(stderr, "failed to write to temporary file\n");
|
2022-02-28 19:42:22 +00:00
|
|
|
rc = SA_SYSTEM_ERR;
|
2020-07-13 16:19:18 +00:00
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2022-02-28 19:42:22 +00:00
|
|
|
if (need_free)
|
|
|
|
free(mp);
|
|
|
|
return (rc);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2020-07-13 16:19:18 +00:00
|
|
|
* Enables NFS sharing for the specified share.
|
2011-12-03 22:01:06 +00:00
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
2021-05-17 16:13:18 +00:00
|
|
|
nfs_enable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2022-02-28 16:44:06 +00:00
|
|
|
char *linux_opts = NULL;
|
|
|
|
int error = get_linux_shareopts(impl_share->sa_shareopts, &linux_opts);
|
2021-04-15 22:40:22 +00:00
|
|
|
if (error != SA_OK)
|
2020-07-13 16:19:18 +00:00
|
|
|
return (error);
|
|
|
|
|
2021-05-17 16:13:18 +00:00
|
|
|
error = foreach_nfs_host(impl_share, tmpfile, nfs_add_entry,
|
2020-07-13 16:19:18 +00:00
|
|
|
linux_opts);
|
|
|
|
free(linux_opts);
|
|
|
|
return (error);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 22:40:22 +00:00
|
|
|
static int
|
|
|
|
nfs_enable_share(sa_share_impl_t impl_share)
|
|
|
|
{
|
|
|
|
return (nfs_toggle_share(
|
|
|
|
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
|
|
|
|
nfs_enable_share_impl));
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2020-07-13 16:19:18 +00:00
|
|
|
* Disables NFS sharing for the specified share.
|
2011-12-03 22:01:06 +00:00
|
|
|
*/
|
2021-04-15 22:40:22 +00:00
|
|
|
static int
|
2021-05-17 16:13:18 +00:00
|
|
|
nfs_disable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
|
2021-04-15 22:40:22 +00:00
|
|
|
{
|
2021-12-12 14:26:39 +00:00
|
|
|
(void) impl_share, (void) tmpfile;
|
2021-04-15 22:40:22 +00:00
|
|
|
return (SA_OK);
|
|
|
|
}
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
static int
|
|
|
|
nfs_disable_share(sa_share_impl_t impl_share)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2021-04-15 22:40:22 +00:00
|
|
|
return (nfs_toggle_share(
|
|
|
|
ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share,
|
|
|
|
nfs_disable_share_impl));
|
2020-07-13 16:19:18 +00:00
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
static boolean_t
|
|
|
|
nfs_is_shared(sa_share_impl_t impl_share)
|
|
|
|
{
|
2021-05-17 18:25:29 +00:00
|
|
|
return (nfs_is_shared_impl(ZFS_EXPORTS_FILE, impl_share));
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2020-07-13 16:19:18 +00:00
|
|
|
* Checks whether the specified NFS share options are syntactically correct.
|
2011-12-03 22:01:06 +00:00
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static int
|
2020-07-13 16:19:18 +00:00
|
|
|
nfs_validate_shareopts(const char *shareopts)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2022-02-28 16:44:06 +00:00
|
|
|
char *linux_opts = NULL;
|
|
|
|
int error = get_linux_shareopts(shareopts, &linux_opts);
|
2020-07-13 16:19:18 +00:00
|
|
|
if (error != SA_OK)
|
|
|
|
return (error);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
free(linux_opts);
|
|
|
|
return (SA_OK);
|
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
static int
|
|
|
|
nfs_commit_shares(void)
|
|
|
|
{
|
|
|
|
char *argv[] = {
|
2022-02-28 12:13:10 +00:00
|
|
|
(char *)"/usr/sbin/exportfs",
|
|
|
|
(char *)"-ra",
|
2020-07-13 16:19:18 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
return (libzfs_run_process(argv[0], argv, 0));
|
|
|
|
}
|
|
|
|
|
2022-02-28 14:46:25 +00:00
|
|
|
const sa_fstype_t libshare_nfs_type = {
|
2011-07-02 19:34:05 +00:00
|
|
|
.enable_share = nfs_enable_share,
|
|
|
|
.disable_share = nfs_disable_share,
|
2020-07-13 16:19:18 +00:00
|
|
|
.is_shared = nfs_is_shared,
|
2011-07-02 19:34:05 +00:00
|
|
|
|
|
|
|
.validate_shareopts = nfs_validate_shareopts,
|
2020-07-13 16:19:18 +00:00
|
|
|
.commit_shares = nfs_commit_shares,
|
2011-07-02 19:34:05 +00:00
|
|
|
};
|