Honor all options of "zfs mount -o"

The existing code in zmount incorrectly parses the comma-delimited option
string. The result is that nmount only honors the last option. AFAICT the
parsing has been broken ever since ZFS's initial import in change 168404.

PR:		222078
Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D12232
This commit is contained in:
Alan Somers 2017-09-05 19:28:35 +00:00
parent 1a11bb8f76
commit 0a7b460e70

View File

@ -74,7 +74,7 @@ zmount(const char *spec, const char *dir, int mflag, char *fstype,
char *dataptr, int datalen, char *optptr, int optlen) char *dataptr, int datalen, char *optptr, int optlen)
{ {
struct iovec *iov; struct iovec *iov;
char *optstr, *os, *p; char *optstr, *os, *p, *tofree;
int iovlen, rv; int iovlen, rv;
assert(spec != NULL); assert(spec != NULL);
@ -87,7 +87,7 @@ zmount(const char *spec, const char *dir, int mflag, char *fstype,
assert(optptr != NULL); assert(optptr != NULL);
assert(optlen > 0); assert(optlen > 0);
optstr = strdup(optptr); tofree = optstr = strdup(optptr);
assert(optstr != NULL); assert(optstr != NULL);
iov = NULL; iov = NULL;
@ -98,11 +98,9 @@ zmount(const char *spec, const char *dir, int mflag, char *fstype,
build_iovec(&iov, &iovlen, "fspath", __DECONST(char *, dir), build_iovec(&iov, &iovlen, "fspath", __DECONST(char *, dir),
(size_t)-1); (size_t)-1);
build_iovec(&iov, &iovlen, "from", __DECONST(char *, spec), (size_t)-1); build_iovec(&iov, &iovlen, "from", __DECONST(char *, spec), (size_t)-1);
for (p = optstr; p != NULL; strsep(&p, ",/ ")) { while ((p = strsep(&optstr, ",/")) != NULL)
if (*p != '\0') build_iovec(&iov, &iovlen, p, NULL, (size_t)-1);
build_iovec(&iov, &iovlen, p, NULL, (size_t)-1);
}
rv = nmount(iov, iovlen, 0); rv = nmount(iov, iovlen, 0);
free(optstr); free(tofree);
return (rv); return (rv);
} }