Changeset View
Changeset View
Standalone View
Standalone View
head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
boolean_t | boolean_t | ||||
zfs_is_mounted(zfs_handle_t *zhp, char **where) | zfs_is_mounted(zfs_handle_t *zhp, char **where) | ||||
{ | { | ||||
return (is_mounted(zhp->zfs_hdl, zfs_get_name(zhp), where)); | return (is_mounted(zhp->zfs_hdl, zfs_get_name(zhp), where)); | ||||
} | } | ||||
static boolean_t | |||||
zfs_is_mountable_internal(zfs_handle_t *zhp, const char *mountpoint) | |||||
{ | |||||
if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) && | |||||
getzoneid() == GLOBAL_ZONEID) | |||||
return (B_FALSE); | |||||
return (B_TRUE); | |||||
} | |||||
/* | /* | ||||
* Returns true if the given dataset is mountable, false otherwise. Returns the | * Returns true if the given dataset is mountable, false otherwise. Returns the | ||||
* mountpoint in 'buf'. | * mountpoint in 'buf'. | ||||
*/ | */ | ||||
static boolean_t | static boolean_t | ||||
zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen, | zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen, | ||||
zprop_source_t *source) | zprop_source_t *source) | ||||
{ | { | ||||
char sourceloc[MAXNAMELEN]; | char sourceloc[MAXNAMELEN]; | ||||
zprop_source_t sourcetype; | zprop_source_t sourcetype; | ||||
if (!zfs_prop_valid_for_type(ZFS_PROP_MOUNTPOINT, zhp->zfs_type)) | if (!zfs_prop_valid_for_type(ZFS_PROP_MOUNTPOINT, zhp->zfs_type)) | ||||
return (B_FALSE); | return (B_FALSE); | ||||
verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, buf, buflen, | verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, buf, buflen, | ||||
&sourcetype, sourceloc, sizeof (sourceloc), B_FALSE) == 0); | &sourcetype, sourceloc, sizeof (sourceloc), B_FALSE) == 0); | ||||
if (strcmp(buf, ZFS_MOUNTPOINT_NONE) == 0 || | if (strcmp(buf, ZFS_MOUNTPOINT_NONE) == 0 || | ||||
strcmp(buf, ZFS_MOUNTPOINT_LEGACY) == 0) | strcmp(buf, ZFS_MOUNTPOINT_LEGACY) == 0) | ||||
return (B_FALSE); | return (B_FALSE); | ||||
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_OFF) | if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_OFF) | ||||
return (B_FALSE); | return (B_FALSE); | ||||
if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) && | if (!zfs_is_mountable_internal(zhp, buf)) | ||||
getzoneid() == GLOBAL_ZONEID) | |||||
return (B_FALSE); | return (B_FALSE); | ||||
if (source) | if (source) | ||||
*source = sourcetype; | *source = sourcetype; | ||||
return (B_TRUE); | return (B_TRUE); | ||||
} | } | ||||
/* | /* | ||||
* Mount the given filesystem. | * Mount the given filesystem. | ||||
*/ | */ | ||||
int | int | ||||
zfs_mount(zfs_handle_t *zhp, const char *options, int flags) | zfs_mount(zfs_handle_t *zhp, const char *options, int flags) | ||||
{ | { | ||||
struct stat buf; | |||||
char mountpoint[ZFS_MAXPROPLEN]; | char mountpoint[ZFS_MAXPROPLEN]; | ||||
if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL)) | |||||
return (0); | |||||
return (zfs_mount_at(zhp, options, flags, mountpoint)); | |||||
} | |||||
int | |||||
zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags, | |||||
const char *mountpoint) | |||||
{ | |||||
struct stat buf; | |||||
char mntopts[MNT_LINE_MAX]; | char mntopts[MNT_LINE_MAX]; | ||||
libzfs_handle_t *hdl = zhp->zfs_hdl; | libzfs_handle_t *hdl = zhp->zfs_hdl; | ||||
if (options == NULL) | if (options == NULL) | ||||
mntopts[0] = '\0'; | mntopts[0] = '\0'; | ||||
else | else | ||||
(void) strlcpy(mntopts, options, sizeof (mntopts)); | (void) strlcpy(mntopts, options, sizeof (mntopts)); | ||||
/* | /* | ||||
* If the pool is imported read-only then all mounts must be read-only | * If the pool is imported read-only then all mounts must be read-only | ||||
*/ | */ | ||||
if (zpool_get_prop_int(zhp->zpool_hdl, ZPOOL_PROP_READONLY, NULL)) | if (zpool_get_prop_int(zhp->zpool_hdl, ZPOOL_PROP_READONLY, NULL)) | ||||
flags |= MS_RDONLY; | flags |= MS_RDONLY; | ||||
if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL)) | if (!zfs_is_mountable_internal(zhp, mountpoint)) | ||||
return (0); | return (B_FALSE); | ||||
/* Create the directory if it doesn't already exist */ | /* Create the directory if it doesn't already exist */ | ||||
if (lstat(mountpoint, &buf) != 0) { | if (lstat(mountpoint, &buf) != 0) { | ||||
if (mkdirp(mountpoint, 0755) != 0) { | if (mkdirp(mountpoint, 0755) != 0) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"failed to create mountpoint")); | "failed to create mountpoint")); | ||||
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED, | return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED, | ||||
dgettext(TEXT_DOMAIN, "cannot mount '%s'"), | dgettext(TEXT_DOMAIN, "cannot mount '%s'"), | ||||
▲ Show 20 Lines • Show All 1,344 Lines • Show Last 20 Lines |