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>
|
2011-07-02 19:34:05 +00:00
|
|
|
#include <strings.h>
|
2018-02-16 01:53:18 +00:00
|
|
|
#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
|
|
|
|
2011-07-02 19:34:05 +00:00
|
|
|
static sa_fstype_t *nfs_fstype;
|
|
|
|
|
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;
|
|
|
|
char *shareopts;
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
shareopts = FSINFO(impl_share, nfs_fstype)->shareopts;
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
return (foreach_nfs_shareopt(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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
|
|
|
|
if (strcmp(key, "insecure") != 0 && strcmp(key, "secure") != 0 &&
|
|
|
|
strcmp(key, "async") != 0 && strcmp(key, "sync") != 0 &&
|
|
|
|
strcmp(key, "no_wdelay") != 0 && strcmp(key, "wdelay") != 0 &&
|
|
|
|
strcmp(key, "nohide") != 0 && strcmp(key, "hide") != 0 &&
|
|
|
|
strcmp(key, "crossmnt") != 0 &&
|
|
|
|
strcmp(key, "no_subtree_check") != 0 &&
|
|
|
|
strcmp(key, "subtree_check") != 0 &&
|
|
|
|
strcmp(key, "insecure_locks") != 0 &&
|
|
|
|
strcmp(key, "secure_locks") != 0 &&
|
|
|
|
strcmp(key, "no_auth_nlm") != 0 && strcmp(key, "auth_nlm") != 0 &&
|
|
|
|
strcmp(key, "no_acl") != 0 && strcmp(key, "mountpoint") != 0 &&
|
|
|
|
strcmp(key, "mp") != 0 && strcmp(key, "fsuid") != 0 &&
|
|
|
|
strcmp(key, "refer") != 0 && strcmp(key, "replicas") != 0 &&
|
|
|
|
strcmp(key, "root_squash") != 0 &&
|
|
|
|
strcmp(key, "no_root_squash") != 0 &&
|
|
|
|
strcmp(key, "all_squash") != 0 &&
|
2012-02-13 09:27:01 +00:00
|
|
|
strcmp(key, "no_all_squash") != 0 && strcmp(key, "fsid") != 0 &&
|
2011-07-02 19:34:05 +00:00
|
|
|
strcmp(key, "anonuid") != 0 && strcmp(key, "anongid") != 0) {
|
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
|
|
|
|
2021-05-17 18:34:04 +00:00
|
|
|
if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath,
|
|
|
|
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");
|
2020-07-13 16:19:18 +00:00
|
|
|
return (SA_SYSTEM_ERR);
|
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
return (SA_OK);
|
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
|
|
|
{
|
2020-07-13 16:19:18 +00:00
|
|
|
char *shareopts, *linux_opts;
|
|
|
|
int error;
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
shareopts = FSINFO(impl_share, nfs_fstype)->shareopts;
|
|
|
|
error = get_linux_shareopts(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
|
|
|
{
|
2020-07-13 16:19:18 +00:00
|
|
|
char *linux_opts;
|
|
|
|
int error;
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
error = get_linux_shareopts(shareopts, &linux_opts);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
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_update_shareopts(sa_share_impl_t impl_share, const char *shareopts)
|
|
|
|
{
|
|
|
|
FSINFO(impl_share, nfs_fstype)->shareopts = (char *)shareopts;
|
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
|
|
|
* Clears a share's NFS options. Used by libshare to
|
|
|
|
* clean up shares that are about to be free()'d.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
static void
|
|
|
|
nfs_clear_shareopts(sa_share_impl_t impl_share)
|
|
|
|
{
|
|
|
|
FSINFO(impl_share, nfs_fstype)->shareopts = NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
static int
|
|
|
|
nfs_commit_shares(void)
|
|
|
|
{
|
|
|
|
char *argv[] = {
|
|
|
|
"/usr/sbin/exportfs",
|
|
|
|
"-ra",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
return (libzfs_run_process(argv[0], argv, 0));
|
|
|
|
}
|
|
|
|
|
2011-07-02 19:34:05 +00:00
|
|
|
static const sa_share_ops_t nfs_shareops = {
|
|
|
|
.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,
|
|
|
|
.update_shareopts = nfs_update_shareopts,
|
|
|
|
.clear_shareopts = nfs_clear_shareopts,
|
2020-07-13 16:19:18 +00:00
|
|
|
.commit_shares = nfs_commit_shares,
|
2011-07-02 19:34:05 +00:00
|
|
|
};
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
2011-12-03 22:01:06 +00:00
|
|
|
* Initializes the NFS functionality of libshare.
|
|
|
|
*/
|
2011-07-02 19:34:05 +00:00
|
|
|
void
|
|
|
|
libshare_nfs_init(void)
|
|
|
|
{
|
|
|
|
nfs_fstype = register_fstype("nfs", &nfs_shareops);
|
|
|
|
}
|