Deleted Added
full compact
libzfs_mount.c (208472) libzfs_mount.c (209962)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 60 unchanged lines hidden (view full) ---

69#include <libgen.h>
70#include <libintl.h>
71#include <stdio.h>
72#include <stdlib.h>
73#include <strings.h>
74#include <unistd.h>
75#include <zone.h>
76#include <sys/mntent.h>
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 60 unchanged lines hidden (view full) ---

69#include <libgen.h>
70#include <libintl.h>
71#include <stdio.h>
72#include <stdlib.h>
73#include <strings.h>
74#include <unistd.h>
75#include <zone.h>
76#include <sys/mntent.h>
77#include <sys/mnttab.h>
78#include <sys/mount.h>
79#include <sys/stat.h>
80
81#include <libzfs.h>
82
83#include "libzfs_impl.h"
84
85#include <libshare.h>

--- 152 unchanged lines hidden (view full) ---

238/*
239 * Checks to see if the mount is active. If the filesystem is mounted, we fill
240 * in 'where' with the current mountpoint, and return 1. Otherwise, we return
241 * 0.
242 */
243boolean_t
244is_mounted(libzfs_handle_t *zfs_hdl, const char *special, char **where)
245{
77#include <sys/mount.h>
78#include <sys/stat.h>
79
80#include <libzfs.h>
81
82#include "libzfs_impl.h"
83
84#include <libshare.h>

--- 152 unchanged lines hidden (view full) ---

237/*
238 * Checks to see if the mount is active. If the filesystem is mounted, we fill
239 * in 'where' with the current mountpoint, and return 1. Otherwise, we return
240 * 0.
241 */
242boolean_t
243is_mounted(libzfs_handle_t *zfs_hdl, const char *special, char **where)
244{
246 struct mnttab search = { 0 }, entry;
245 struct mnttab entry;
247
246
248 /*
249 * Search for the entry in /etc/mnttab. We don't bother getting the
250 * mountpoint, as we can just search for the special device. This will
251 * also let us find mounts when the mountpoint is 'legacy'.
252 */
253 search.mnt_special = (char *)special;
254 search.mnt_fstype = MNTTYPE_ZFS;
255
256 rewind(zfs_hdl->libzfs_mnttab);
257 if (getmntany(zfs_hdl->libzfs_mnttab, &entry, &search) != 0)
247 if (libzfs_mnttab_find(zfs_hdl, special, &entry) != 0)
258 return (B_FALSE);
259
260 if (where != NULL)
261 *where = zfs_strdup(zfs_hdl, entry.mnt_mountp);
262
263 return (B_TRUE);
264}
265

--- 96 unchanged lines hidden (view full) ---

362 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
363 "mountpoint or dataset is busy"));
364 } else if (errno == EPERM) {
365 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
366 "Insufficient privileges"));
367 } else {
368 zfs_error_aux(hdl, strerror(errno));
369 }
248 return (B_FALSE);
249
250 if (where != NULL)
251 *where = zfs_strdup(zfs_hdl, entry.mnt_mountp);
252
253 return (B_TRUE);
254}
255

--- 96 unchanged lines hidden (view full) ---

352 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
353 "mountpoint or dataset is busy"));
354 } else if (errno == EPERM) {
355 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
356 "Insufficient privileges"));
357 } else {
358 zfs_error_aux(hdl, strerror(errno));
359 }
370
371 return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
372 dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
373 zhp->zfs_name));
374 }
375
360 return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
361 dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
362 zhp->zfs_name));
363 }
364
365 /* add the mounted entry into our cache */
366 libzfs_mnttab_add(hdl, zfs_get_name(zhp), mountpoint,
367 mntopts);
376 return (0);
377}
378
379/*
380 * Unmount a single filesystem.
381 */
382static int
383unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)

--- 9 unchanged lines hidden (view full) ---

393}
394
395/*
396 * Unmount the given filesystem.
397 */
398int
399zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
400{
368 return (0);
369}
370
371/*
372 * Unmount a single filesystem.
373 */
374static int
375unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)

--- 9 unchanged lines hidden (view full) ---

385}
386
387/*
388 * Unmount the given filesystem.
389 */
390int
391zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
392{
401 struct mnttab search = { 0 }, entry;
393 libzfs_handle_t *hdl = zhp->zfs_hdl;
394 struct mnttab entry;
402 char *mntpt = NULL;
403
395 char *mntpt = NULL;
396
404 /* check to see if need to unmount the filesystem */
405 search.mnt_special = zhp->zfs_name;
406 search.mnt_fstype = MNTTYPE_ZFS;
407 rewind(zhp->zfs_hdl->libzfs_mnttab);
397 /* check to see if we need to unmount the filesystem */
408 if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
398 if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
409 getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) == 0)) {
410
399 libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0)) {
411 /*
412 * mountpoint may have come from a call to
413 * getmnt/getmntany if it isn't NULL. If it is NULL,
400 /*
401 * mountpoint may have come from a call to
402 * getmnt/getmntany if it isn't NULL. If it is NULL,
414 * we know it comes from getmntany which can then get
415 * overwritten later. We strdup it to play it safe.
403 * we know it comes from libzfs_mnttab_find which can
404 * then get freed later. We strdup it to play it safe.
416 */
417 if (mountpoint == NULL)
405 */
406 if (mountpoint == NULL)
418 mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
407 mntpt = zfs_strdup(hdl, entry.mnt_mountp);
419 else
408 else
420 mntpt = zfs_strdup(zhp->zfs_hdl, mountpoint);
409 mntpt = zfs_strdup(hdl, mountpoint);
421
422 /*
423 * Unshare and unmount the filesystem
424 */
425 if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0)
426 return (-1);
427
410
411 /*
412 * Unshare and unmount the filesystem
413 */
414 if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0)
415 return (-1);
416
428 if (unmount_one(zhp->zfs_hdl, mntpt, flags) != 0) {
417 if (unmount_one(hdl, mntpt, flags) != 0) {
429 free(mntpt);
430 (void) zfs_shareall(zhp);
431 return (-1);
432 }
418 free(mntpt);
419 (void) zfs_shareall(zhp);
420 return (-1);
421 }
422 libzfs_mnttab_remove(hdl, zhp->zfs_name);
433 free(mntpt);
434 }
435
436 return (0);
437}
438
439/*
440 * Unmount this filesystem and any children inheriting the mountpoint property.

--- 453 unchanged lines hidden (view full) ---

894
895/*
896 * Unshare the given filesystem.
897 */
898int
899zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
900 zfs_share_proto_t *proto)
901{
423 free(mntpt);
424 }
425
426 return (0);
427}
428
429/*
430 * Unmount this filesystem and any children inheriting the mountpoint property.

--- 453 unchanged lines hidden (view full) ---

884
885/*
886 * Unshare the given filesystem.
887 */
888int
889zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
890 zfs_share_proto_t *proto)
891{
902 struct mnttab search = { 0 }, entry;
892 libzfs_handle_t *hdl = zhp->zfs_hdl;
893 struct mnttab entry;
903 char *mntpt = NULL;
904
905 /* check to see if need to unmount the filesystem */
894 char *mntpt = NULL;
895
896 /* check to see if need to unmount the filesystem */
906 search.mnt_special = (char *)zfs_get_name(zhp);
907 search.mnt_fstype = MNTTYPE_ZFS;
908 rewind(zhp->zfs_hdl->libzfs_mnttab);
909 if (mountpoint != NULL)
897 rewind(zhp->zfs_hdl->libzfs_mnttab);
898 if (mountpoint != NULL)
910 mntpt = zfs_strdup(zhp->zfs_hdl, mountpoint);
899 mountpoint = mntpt = zfs_strdup(hdl, mountpoint);
911
912 if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
900
901 if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
913 getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) == 0)) {
902 libzfs_mnttab_find(hdl, zfs_get_name(zhp), &entry) == 0)) {
914 zfs_share_proto_t *curr_proto;
915
916 if (mountpoint == NULL)
917 mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
918
919 for (curr_proto = proto; *curr_proto != PROTO_END;
920 curr_proto++) {
921
903 zfs_share_proto_t *curr_proto;
904
905 if (mountpoint == NULL)
906 mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
907
908 for (curr_proto = proto; *curr_proto != PROTO_END;
909 curr_proto++) {
910
922 if (is_shared(zhp->zfs_hdl, mntpt, *curr_proto) &&
923 unshare_one(zhp->zfs_hdl, zhp->zfs_name,
911 if (is_shared(hdl, mntpt, *curr_proto) &&
912 unshare_one(hdl, zhp->zfs_name,
924 mntpt, *curr_proto) != 0) {
925 if (mntpt != NULL)
926 free(mntpt);
927 return (-1);
928 }
929 }
930 }
931 if (mntpt != NULL)

--- 489 unchanged lines hidden ---
913 mntpt, *curr_proto) != 0) {
914 if (mntpt != NULL)
915 free(mntpt);
916 return (-1);
917 }
918 }
919 }
920 if (mntpt != NULL)

--- 489 unchanged lines hidden ---