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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>.
24 * All rights reserved.
28 * ZFS control directory (a.k.a. ".zfs")
30 * This directory provides a common location for all ZFS meta-objects.
31 * Currently, this is only the 'snapshot' directory, but this may expand in the
32 * future. The elements are built using the GFS primitives, as the hierarchy
33 * does not actually exist on disk.
35 * For 'snapshot', we don't want to have all snapshots always mounted, because
36 * this would take up a huge amount of space in /etc/mnttab. We have three
39 * ctldir ------> snapshotdir -------> snapshot
45 * The 'snapshot' node contains just enough information to lookup '..' and act
46 * as a mountpoint for the snapshot. Whenever we lookup a specific snapshot, we
47 * perform an automount of the underlying filesystem and return the
48 * corresponding vnode.
50 * All mounts are handled automatically by the kernel, but unmounts are
51 * (currently) handled from user land. The main reason is that there is no
52 * reliable way to auto-unmount the filesystem when it's "no longer in use".
53 * When the user unmounts a filesystem, we call zfsctl_unmount(), which
54 * unmounts any snapshots within the snapshot directory.
56 * The '.zfs', '.zfs/snapshot', and all directories created under
57 * '.zfs/snapshot' (ie: '.zfs/snapshot/<snapname>') are all GFS nodes and
58 * share the same vfs_t as the head filesystem (what '.zfs' lives under).
60 * File systems mounted ontop of the GFS nodes '.zfs/snapshot/<snapname>'
61 * (ie: snapshots) are ZFS nodes and have their own unique vfs_t.
62 * However, vnodes within these mounted on file systems have their v_vfsp
63 * fields set to the head filesystem to make NFS happy (see
64 * zfsctl_snapdir_lookup()). We VFS_HOLD the head filesystem's vfs_t
65 * so that it cannot be freed until all snapshots have been unmounted.
68 #include <sys/zfs_context.h>
69 #include <sys/zfs_ctldir.h>
70 #include <sys/zfs_ioctl.h>
71 #include <sys/zfs_vfsops.h>
72 #include <sys/namei.h>
76 #include <sys/dsl_deleg.h>
77 #include <sys/mount.h>
78 #include <sys/sunddi.h>
80 #include "zfs_namecheck.h"
82 typedef struct zfsctl_node {
83 gfs_dir_t zc_gfs_private;
85 timestruc_t zc_cmtime; /* ctime and mtime, always the same */
88 typedef struct zfsctl_snapdir {
89 zfsctl_node_t sd_node;
101 snapentry_compare(const void *a, const void *b)
103 const zfs_snapentry_t *sa = a;
104 const zfs_snapentry_t *sb = b;
105 int ret = strcmp(sa->se_name, sb->se_name);
116 vnodeops_t *zfsctl_ops_root;
117 vnodeops_t *zfsctl_ops_snapdir;
118 vnodeops_t *zfsctl_ops_snapshot;
119 vnodeops_t *zfsctl_ops_shares;
120 vnodeops_t *zfsctl_ops_shares_dir;
122 static const fs_operation_def_t zfsctl_tops_root[];
123 static const fs_operation_def_t zfsctl_tops_snapdir[];
124 static const fs_operation_def_t zfsctl_tops_snapshot[];
125 static const fs_operation_def_t zfsctl_tops_shares[];
127 static struct vop_vector zfsctl_ops_root;
128 static struct vop_vector zfsctl_ops_snapdir;
129 static struct vop_vector zfsctl_ops_snapshot;
130 static struct vop_vector zfsctl_ops_shares;
131 static struct vop_vector zfsctl_ops_shares_dir;
134 static vnode_t *zfsctl_mknode_snapdir(vnode_t *);
135 static vnode_t *zfsctl_mknode_shares(vnode_t *);
136 static vnode_t *zfsctl_snapshot_mknode(vnode_t *, uint64_t objset);
137 static int zfsctl_unmount_snap(zfs_snapentry_t *, int, cred_t *);
140 static gfs_opsvec_t zfsctl_opsvec[] = {
141 { ".zfs", zfsctl_tops_root, &zfsctl_ops_root },
142 { ".zfs/snapshot", zfsctl_tops_snapdir, &zfsctl_ops_snapdir },
143 { ".zfs/snapshot/vnode", zfsctl_tops_snapshot, &zfsctl_ops_snapshot },
144 { ".zfs/shares", zfsctl_tops_shares, &zfsctl_ops_shares_dir },
145 { ".zfs/shares/vnode", zfsctl_tops_shares, &zfsctl_ops_shares },
151 * Root directory elements. We only have two entries
152 * snapshot and shares.
154 static gfs_dirent_t zfsctl_root_entries[] = {
155 { "snapshot", zfsctl_mknode_snapdir, GFS_CACHE_VNODE },
156 { "shares", zfsctl_mknode_shares, GFS_CACHE_VNODE },
160 /* include . and .. in the calculation */
161 #define NROOT_ENTRIES ((sizeof (zfsctl_root_entries) / \
162 sizeof (gfs_dirent_t)) + 1)
166 * Initialize the various GFS pieces we'll need to create and manipulate .zfs
167 * directories. This is called from the ZFS init routine, and initializes the
168 * vnode ops vectors that we'll be using.
174 VERIFY(gfs_make_opsvec(zfsctl_opsvec) == 0);
183 * Remove vfsctl vnode ops
186 vn_freevnodeops(zfsctl_ops_root);
187 if (zfsctl_ops_snapdir)
188 vn_freevnodeops(zfsctl_ops_snapdir);
189 if (zfsctl_ops_snapshot)
190 vn_freevnodeops(zfsctl_ops_snapshot);
191 if (zfsctl_ops_shares)
192 vn_freevnodeops(zfsctl_ops_shares);
193 if (zfsctl_ops_shares_dir)
194 vn_freevnodeops(zfsctl_ops_shares_dir);
196 zfsctl_ops_root = NULL;
197 zfsctl_ops_snapdir = NULL;
198 zfsctl_ops_snapshot = NULL;
199 zfsctl_ops_shares = NULL;
200 zfsctl_ops_shares_dir = NULL;
205 zfsctl_is_node(vnode_t *vp)
207 return (vn_matchops(vp, zfsctl_ops_root) ||
208 vn_matchops(vp, zfsctl_ops_snapdir) ||
209 vn_matchops(vp, zfsctl_ops_snapshot) ||
210 vn_matchops(vp, zfsctl_ops_shares) ||
211 vn_matchops(vp, zfsctl_ops_shares_dir));
216 * Return the inode number associated with the 'snapshot' or
217 * 'shares' directory.
221 zfsctl_root_inode_cb(vnode_t *vp, int index)
223 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
228 return (ZFSCTL_INO_SNAPDIR);
230 return (zfsvfs->z_shares_dir);
234 * Create the '.zfs' directory. This directory is cached as part of the VFS
235 * structure. This results in a hold on the vfs_t. The code in zfs_umount()
236 * therefore checks against a vfs_count of 2 instead of 1. This reference
237 * is removed when the ctldir is destroyed in the unmount.
240 zfsctl_create(zfsvfs_t *zfsvfs)
246 ASSERT(zfsvfs->z_ctldir == NULL);
248 vp = gfs_root_create(sizeof (zfsctl_node_t), zfsvfs->z_vfs,
249 &zfsctl_ops_root, ZFSCTL_INO_ROOT, zfsctl_root_entries,
250 zfsctl_root_inode_cb, MAXNAMELEN, NULL, NULL);
252 zcp->zc_id = ZFSCTL_INO_ROOT;
254 VERIFY(VFS_ROOT(zfsvfs->z_vfs, LK_EXCLUSIVE, &rvp) == 0);
255 VERIFY(0 == sa_lookup(VTOZ(rvp)->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs),
256 &crtime, sizeof (crtime)));
257 ZFS_TIME_DECODE(&zcp->zc_cmtime, crtime);
261 * We're only faking the fact that we have a root of a filesystem for
262 * the sake of the GFS interfaces. Undo the flag manipulation it did
265 vp->v_vflag &= ~VV_ROOT;
267 zfsvfs->z_ctldir = vp;
273 * Destroy the '.zfs' directory. Only called when the filesystem is unmounted.
274 * There might still be more references if we were force unmounted, but only
275 * new zfs_inactive() calls can occur and they don't reference .zfs
278 zfsctl_destroy(zfsvfs_t *zfsvfs)
280 VN_RELE(zfsvfs->z_ctldir);
281 zfsvfs->z_ctldir = NULL;
285 * Given a root znode, retrieve the associated .zfs directory.
286 * Add a hold to the vnode and return it.
289 zfsctl_root(znode_t *zp)
291 ASSERT(zfs_has_ctldir(zp));
292 VN_HOLD(zp->z_zfsvfs->z_ctldir);
293 return (zp->z_zfsvfs->z_ctldir);
297 * Common open routine. Disallow any write access.
301 zfsctl_common_open(struct vop_open_args *ap)
303 int flags = ap->a_mode;
312 * Common close routine. Nothing to do here.
316 zfsctl_common_close(struct vop_close_args *ap)
322 * Common access routine. Disallow writes.
326 zfsctl_common_access(ap)
327 struct vop_access_args /* {
330 struct ucred *a_cred;
334 accmode_t accmode = ap->a_accmode;
337 if (flags & V_ACE_MASK) {
338 if (accmode & ACE_ALL_WRITE_PERMS)
342 if (accmode & VWRITE)
352 * Common getattr function. Fill in basic information.
355 zfsctl_common_getattr(vnode_t *vp, vattr_t *vap)
363 * We are a purely virtual object, so we have no
364 * blocksize or allocated blocks.
369 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
370 vap->va_mode = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP |
374 * We live in the now (for atime).
378 /* FreeBSD: Reset chflags(2) flags. */
384 zfsctl_common_fid(ap)
385 struct vop_fid_args /* {
390 vnode_t *vp = ap->a_vp;
391 fid_t *fidp = (void *)ap->a_fid;
392 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
393 zfsctl_node_t *zcp = vp->v_data;
394 uint64_t object = zcp->zc_id;
400 fidp->fid_len = SHORT_FID_LEN;
402 zfid = (zfid_short_t *)fidp;
404 zfid->zf_len = SHORT_FID_LEN;
406 for (i = 0; i < sizeof (zfid->zf_object); i++)
407 zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
409 /* .zfs znodes always have a generation number of 0 */
410 for (i = 0; i < sizeof (zfid->zf_gen); i++)
420 zfsctl_shares_fid(ap)
421 struct vop_fid_args /* {
426 vnode_t *vp = ap->a_vp;
427 fid_t *fidp = (void *)ap->a_fid;
428 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
434 if (zfsvfs->z_shares_dir == 0) {
439 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) {
440 error = VOP_FID(ZTOV(dzp), fidp);
449 zfsctl_common_reclaim(ap)
450 struct vop_reclaim_args /* {
455 vnode_t *vp = ap->a_vp;
458 * Destroy the vm object and flush associated pages.
460 vnode_destroy_vobject(vp);
468 * .zfs inode namespace
470 * We need to generate unique inode numbers for all files and directories
471 * within the .zfs pseudo-filesystem. We use the following scheme:
476 * .zfs/snapshot/<snap> objectid(snap)
479 #define ZFSCTL_INO_SNAP(id) (id)
482 * Get root directory attributes.
486 zfsctl_root_getattr(ap)
487 struct vop_getattr_args /* {
490 struct ucred *a_cred;
493 struct vnode *vp = ap->a_vp;
494 struct vattr *vap = ap->a_vap;
495 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
496 zfsctl_node_t *zcp = vp->v_data;
499 vap->va_nodeid = ZFSCTL_INO_ROOT;
500 vap->va_nlink = vap->va_size = NROOT_ENTRIES;
501 vap->va_mtime = vap->va_ctime = zcp->zc_cmtime;
502 vap->va_birthtime = vap->va_ctime;
504 zfsctl_common_getattr(vp, vap);
511 * Special case the handling of "..".
515 zfsctl_root_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp,
516 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
517 int *direntflags, pathname_t *realpnp)
519 zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data;
523 * No extended attributes allowed under .zfs
525 if (flags & LOOKUP_XATTR)
530 if (strcmp(nm, "..") == 0) {
531 err = VFS_ROOT(dvp->v_vfsp, LK_EXCLUSIVE, vpp);
535 err = gfs_vop_lookup(dvp, nm, vpp, pnp, flags, rdir,
536 cr, ct, direntflags, realpnp);
546 zfsctl_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
547 caller_context_t *ct)
550 * We only care about ACL_ENABLED so that libsec can
551 * display ACL correctly and not default to POSIX draft.
553 if (cmd == _PC_ACL_ENABLED) {
554 *valp = _ACL_ACE_ENABLED;
558 return (fs_pathconf(vp, cmd, valp, cr, ct));
563 static const fs_operation_def_t zfsctl_tops_root[] = {
564 { VOPNAME_OPEN, { .vop_open = zfsctl_common_open } },
565 { VOPNAME_CLOSE, { .vop_close = zfsctl_common_close } },
566 { VOPNAME_IOCTL, { .error = fs_inval } },
567 { VOPNAME_GETATTR, { .vop_getattr = zfsctl_root_getattr } },
568 { VOPNAME_ACCESS, { .vop_access = zfsctl_common_access } },
569 { VOPNAME_READDIR, { .vop_readdir = gfs_vop_readdir } },
570 { VOPNAME_LOOKUP, { .vop_lookup = zfsctl_root_lookup } },
571 { VOPNAME_SEEK, { .vop_seek = fs_seek } },
572 { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } },
573 { VOPNAME_PATHCONF, { .vop_pathconf = zfsctl_pathconf } },
574 { VOPNAME_FID, { .vop_fid = zfsctl_common_fid } },
580 * Special case the handling of "..".
584 zfsctl_freebsd_root_lookup(ap)
585 struct vop_lookup_args /* {
587 struct vnode **a_vpp;
588 struct componentname *a_cnp;
591 vnode_t *dvp = ap->a_dvp;
592 vnode_t **vpp = ap->a_vpp;
593 cred_t *cr = ap->a_cnp->cn_cred;
594 int flags = ap->a_cnp->cn_flags;
595 int nameiop = ap->a_cnp->cn_nameiop;
596 char nm[NAME_MAX + 1];
599 if ((flags & ISLASTCN) && (nameiop == RENAME || nameiop == CREATE))
602 ASSERT(ap->a_cnp->cn_namelen < sizeof(nm));
603 strlcpy(nm, ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen + 1);
605 err = zfsctl_root_lookup(dvp, nm, vpp, NULL, 0, NULL, cr, NULL, NULL, NULL);
606 if (err == 0 && (nm[0] != '.' || nm[1] != '\0'))
607 vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY);
611 static struct vop_vector zfsctl_ops_root = {
612 .vop_default = &default_vnodeops,
613 .vop_open = zfsctl_common_open,
614 .vop_close = zfsctl_common_close,
615 .vop_ioctl = VOP_EINVAL,
616 .vop_getattr = zfsctl_root_getattr,
617 .vop_access = zfsctl_common_access,
618 .vop_readdir = gfs_vop_readdir,
619 .vop_lookup = zfsctl_freebsd_root_lookup,
620 .vop_inactive = gfs_vop_inactive,
621 .vop_reclaim = zfsctl_common_reclaim,
623 .vop_pathconf = zfsctl_pathconf,
625 .vop_fid = zfsctl_common_fid,
629 zfsctl_snapshot_zname(vnode_t *vp, const char *name, int len, char *zname)
631 objset_t *os = ((zfsvfs_t *)((vp)->v_vfsp->vfs_data))->z_os;
633 if (snapshot_namecheck(name, NULL, NULL) != 0)
635 dmu_objset_name(os, zname);
636 if (strlen(zname) + 1 + strlen(name) >= len)
637 return (ENAMETOOLONG);
638 (void) strcat(zname, "@");
639 (void) strcat(zname, name);
644 zfsctl_unmount_snap(zfs_snapentry_t *sep, int fflags, cred_t *cr)
646 vnode_t *svp = sep->se_root;
649 ASSERT(vn_ismntpt(svp));
651 /* this will be dropped by dounmount() */
652 if ((error = vn_vfswlock(svp)) != 0)
657 error = dounmount(vn_mountedvfs(svp), fflags, cr);
664 * We can't use VN_RELE(), as that will try to invoke
665 * zfsctl_snapdir_inactive(), which would cause us to destroy
666 * the sd_lock mutex held by our caller.
668 ASSERT(svp->v_count == 1);
669 gfs_vop_inactive(svp, cr, NULL);
671 kmem_free(sep->se_name, strlen(sep->se_name) + 1);
672 kmem_free(sep, sizeof (zfs_snapentry_t));
676 return (dounmount(vn_mountedvfs(svp), fflags, curthread));
682 zfsctl_rename_snap(zfsctl_snapdir_t *sdp, zfs_snapentry_t *sep, const char *nm)
687 char newpath[MAXNAMELEN];
690 ASSERT(MUTEX_HELD(&sdp->sd_lock));
693 vfsp = vn_mountedvfs(sep->se_root);
694 ASSERT(vfsp != NULL);
699 * Change the name in the AVL tree.
701 avl_remove(&sdp->sd_snaps, sep);
702 kmem_free(sep->se_name, strlen(sep->se_name) + 1);
703 sep->se_name = kmem_alloc(strlen(nm) + 1, KM_SLEEP);
704 (void) strcpy(sep->se_name, nm);
705 VERIFY(avl_find(&sdp->sd_snaps, sep, &where) == NULL);
706 avl_insert(&sdp->sd_snaps, sep, where);
709 * Change the current mountpoint info:
710 * - update the tail of the mntpoint path
711 * - update the tail of the resource path
713 pathref = vfs_getmntpoint(vfsp);
714 (void) strncpy(newpath, refstr_value(pathref), sizeof (newpath));
715 VERIFY((tail = strrchr(newpath, '/')) != NULL);
717 ASSERT3U(strlen(newpath) + strlen(nm), <, sizeof (newpath));
718 (void) strcat(newpath, nm);
719 refstr_rele(pathref);
720 vfs_setmntpoint(vfsp, newpath, 0);
722 pathref = vfs_getresource(vfsp);
723 (void) strncpy(newpath, refstr_value(pathref), sizeof (newpath));
724 VERIFY((tail = strrchr(newpath, '@')) != NULL);
726 ASSERT3U(strlen(newpath) + strlen(nm), <, sizeof (newpath));
727 (void) strcat(newpath, nm);
728 refstr_rele(pathref);
729 vfs_setresource(vfsp, newpath, 0);
738 zfsctl_snapdir_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm,
739 cred_t *cr, caller_context_t *ct, int flags)
741 zfsctl_snapdir_t *sdp = sdvp->v_data;
742 zfs_snapentry_t search, *sep;
745 char from[MAXNAMELEN], to[MAXNAMELEN];
746 char real[MAXNAMELEN];
749 zfsvfs = sdvp->v_vfsp->vfs_data;
752 if ((flags & FIGNORECASE) || zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
753 err = dmu_snapshot_realname(zfsvfs->z_os, snm, real,
757 } else if (err != ENOTSUP) {
765 err = zfsctl_snapshot_zname(sdvp, snm, MAXNAMELEN, from);
767 err = zfsctl_snapshot_zname(tdvp, tnm, MAXNAMELEN, to);
769 err = zfs_secpolicy_rename_perms(from, to, cr);
774 * Cannot move snapshots out of the snapdir.
779 if (strcmp(snm, tnm) == 0)
782 mutex_enter(&sdp->sd_lock);
784 search.se_name = (char *)snm;
785 if ((sep = avl_find(&sdp->sd_snaps, &search, &where)) == NULL) {
786 mutex_exit(&sdp->sd_lock);
790 err = dmu_objset_rename(from, to, 0);
792 zfsctl_rename_snap(sdp, sep, tnm);
794 mutex_exit(&sdp->sd_lock);
803 zfsctl_snapdir_remove(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
804 caller_context_t *ct, int flags)
806 zfsctl_snapdir_t *sdp = dvp->v_data;
807 zfs_snapentry_t *sep;
808 zfs_snapentry_t search;
810 char snapname[MAXNAMELEN];
811 char real[MAXNAMELEN];
814 zfsvfs = dvp->v_vfsp->vfs_data;
817 if ((flags & FIGNORECASE) || zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
819 err = dmu_snapshot_realname(zfsvfs->z_os, name, real,
823 } else if (err != ENOTSUP) {
831 err = zfsctl_snapshot_zname(dvp, name, MAXNAMELEN, snapname);
833 err = zfs_secpolicy_destroy_perms(snapname, cr);
837 mutex_enter(&sdp->sd_lock);
839 search.se_name = name;
840 sep = avl_find(&sdp->sd_snaps, &search, NULL);
842 avl_remove(&sdp->sd_snaps, sep);
843 err = zfsctl_unmount_snap(sep, MS_FORCE, cr);
847 if (avl_find(&sdp->sd_snaps, sep, &where) == NULL)
848 avl_insert(&sdp->sd_snaps, sep, where);
850 err = dmu_objset_destroy(snapname, B_FALSE);
855 mutex_exit(&sdp->sd_lock);
862 * This creates a snapshot under '.zfs/snapshot'.
866 zfsctl_snapdir_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp,
867 cred_t *cr, caller_context_t *cc, int flags, vsecattr_t *vsecp)
869 zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data;
870 char name[MAXNAMELEN];
872 static enum symfollow follow = NO_FOLLOW;
873 static enum uio_seg seg = UIO_SYSSPACE;
875 if (snapshot_namecheck(dirname, NULL, NULL) != 0)
878 dmu_objset_name(zfsvfs->z_os, name);
882 err = zfs_secpolicy_snapshot_perms(name, cr);
887 err = dmu_objset_snapshot(name, dirname, NULL, NULL,
888 B_FALSE, B_FALSE, -1);
891 err = lookupnameat(dirname, seg, follow, NULL, vpp, dvp);
898 zfsctl_freebsd_snapdir_mkdir(ap)
899 struct vop_mkdir_args /* {
901 struct vnode **a_vpp;
902 struct componentname *a_cnp;
907 ASSERT(ap->a_cnp->cn_flags & SAVENAME);
909 return (zfsctl_snapdir_mkdir(ap->a_dvp, ap->a_cnp->cn_nameptr, NULL,
910 ap->a_vpp, ap->a_cnp->cn_cred, NULL, 0, NULL));
914 * Lookup entry point for the 'snapshot' directory. Try to open the
915 * snapshot if it exist, creating the pseudo filesystem vnode as necessary.
916 * Perform a mount of the associated dataset on top of the vnode.
920 zfsctl_snapdir_lookup(ap)
921 struct vop_lookup_args /* {
923 struct vnode **a_vpp;
924 struct componentname *a_cnp;
927 vnode_t *dvp = ap->a_dvp;
928 vnode_t **vpp = ap->a_vpp;
929 struct componentname *cnp = ap->a_cnp;
930 char nm[NAME_MAX + 1];
931 zfsctl_snapdir_t *sdp = dvp->v_data;
933 char snapname[MAXNAMELEN];
934 char real[MAXNAMELEN];
936 zfs_snapentry_t *sep, search;
937 size_t mountpoint_len;
939 zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data;
944 * No extended attributes allowed under .zfs
946 if (flags & LOOKUP_XATTR)
948 ASSERT(ap->a_cnp->cn_namelen < sizeof(nm));
949 strlcpy(nm, ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen + 1);
951 ASSERT(dvp->v_type == VDIR);
956 * If we get a recursive call, that means we got called
957 * from the domount() code while it was trying to look up the
958 * spec (which looks like a local path for zfs). We need to
959 * add some flag to domount() to tell it not to do this lookup.
961 if (MUTEX_HELD(&sdp->sd_lock))
966 if (gfs_lookup_dot(vpp, dvp, zfsvfs->z_ctldir, nm) == 0) {
971 if (flags & FIGNORECASE) {
972 boolean_t conflict = B_FALSE;
974 err = dmu_snapshot_realname(zfsvfs->z_os, nm, real,
975 MAXNAMELEN, &conflict);
977 strlcpy(nm, real, sizeof(nm));
978 } else if (err != ENOTSUP) {
984 (void) strlcpy(realpnp->pn_buf, nm,
985 realpnp->pn_bufsize);
986 if (conflict && direntflags)
987 *direntflags = ED_CASE_CONFLICT;
991 mutex_enter(&sdp->sd_lock);
992 search.se_name = (char *)nm;
993 if ((sep = avl_find(&sdp->sd_snaps, &search, &where)) != NULL) {
996 err = traverse(vpp, LK_EXCLUSIVE | LK_RETRY);
1000 } else if (*vpp == sep->se_root) {
1002 * The snapshot was unmounted behind our backs,
1003 * try to remount it.
1008 * VROOT was set during the traverse call. We need
1009 * to clear it since we're pretending to be part
1010 * of our parent's vfs.
1012 (*vpp)->v_flag &= ~VROOT;
1014 mutex_exit(&sdp->sd_lock);
1020 * The requested snapshot is not currently mounted, look it up.
1022 err = zfsctl_snapshot_zname(dvp, nm, MAXNAMELEN, snapname);
1024 mutex_exit(&sdp->sd_lock);
1027 * handle "ls *" or "?" in a graceful manner,
1028 * forcing EILSEQ to ENOENT.
1029 * Since shell ultimately passes "*" or "?" as name to lookup
1031 return (err == EILSEQ ? ENOENT : err);
1033 if (dmu_objset_hold(snapname, FTAG, &snap) != 0) {
1034 mutex_exit(&sdp->sd_lock);
1035 /* Translate errors and add SAVENAME when needed. */
1036 if ((cnp->cn_flags & ISLASTCN) && cnp->cn_nameiop == CREATE) {
1038 cnp->cn_flags |= SAVENAME;
1046 sep = kmem_alloc(sizeof (zfs_snapentry_t), KM_SLEEP);
1047 sep->se_name = kmem_alloc(strlen(nm) + 1, KM_SLEEP);
1048 (void) strcpy(sep->se_name, nm);
1049 *vpp = sep->se_root = zfsctl_snapshot_mknode(dvp, dmu_objset_id(snap));
1051 avl_insert(&sdp->sd_snaps, sep, where);
1053 dmu_objset_rele(snap, FTAG);
1055 mountpoint_len = strlen(dvp->v_vfsp->mnt_stat.f_mntonname) +
1056 strlen("/" ZFS_CTLDIR_NAME "/snapshot/") + strlen(nm) + 1;
1057 mountpoint = kmem_alloc(mountpoint_len, KM_SLEEP);
1058 (void) snprintf(mountpoint, mountpoint_len,
1059 "%s/" ZFS_CTLDIR_NAME "/snapshot/%s",
1060 dvp->v_vfsp->mnt_stat.f_mntonname, nm);
1061 err = mount_snapshot(curthread, vpp, "zfs", mountpoint, snapname, 0);
1062 kmem_free(mountpoint, mountpoint_len);
1065 * Fix up the root vnode mounted on .zfs/snapshot/<snapname>.
1067 * This is where we lie about our v_vfsp in order to
1068 * make .zfs/snapshot/<snapname> accessible over NFS
1069 * without requiring manual mounts of <snapname>.
1071 ASSERT(VTOZ(*vpp)->z_zfsvfs != zfsvfs);
1072 VTOZ(*vpp)->z_zfsvfs->z_parent = zfsvfs;
1074 mutex_exit(&sdp->sd_lock);
1083 zfsctl_shares_lookup(ap)
1084 struct vop_lookup_args /* {
1085 struct vnode *a_dvp;
1086 struct vnode **a_vpp;
1087 struct componentname *a_cnp;
1090 vnode_t *dvp = ap->a_dvp;
1091 vnode_t **vpp = ap->a_vpp;
1092 struct componentname *cnp = ap->a_cnp;
1093 zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data;
1094 char nm[NAME_MAX + 1];
1100 ASSERT(cnp->cn_namelen < sizeof(nm));
1101 strlcpy(nm, cnp->cn_nameptr, cnp->cn_namelen + 1);
1103 if (gfs_lookup_dot(vpp, dvp, zfsvfs->z_ctldir, nm) == 0) {
1108 if (zfsvfs->z_shares_dir == 0) {
1112 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0)
1113 error = VOP_LOOKUP(ZTOV(dzp), vpp, cnp);
1123 zfsctl_snapdir_readdir_cb(vnode_t *vp, void *dp, int *eofp,
1124 offset_t *offp, offset_t *nextp, void *data, int flags)
1126 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
1127 char snapname[MAXNAMELEN];
1128 uint64_t id, cookie;
1129 boolean_t case_conflict;
1135 error = dmu_snapshot_list_next(zfsvfs->z_os, MAXNAMELEN, snapname, &id,
1136 &cookie, &case_conflict);
1139 if (error == ENOENT) {
1146 if (flags & V_RDDIR_ENTFLAGS) {
1147 edirent_t *eodp = dp;
1149 (void) strcpy(eodp->ed_name, snapname);
1150 eodp->ed_ino = ZFSCTL_INO_SNAP(id);
1151 eodp->ed_eflags = case_conflict ? ED_CASE_CONFLICT : 0;
1153 struct dirent64 *odp = dp;
1155 (void) strcpy(odp->d_name, snapname);
1156 odp->d_ino = ZFSCTL_INO_SNAP(id);
1167 zfsctl_shares_readdir(ap)
1168 struct vop_readdir_args /* {
1171 struct ucred *a_cred;
1177 vnode_t *vp = ap->a_vp;
1178 uio_t *uiop = ap->a_uio;
1179 cred_t *cr = ap->a_cred;
1180 int *eofp = ap->a_eofflag;
1181 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
1187 if (zfsvfs->z_shares_dir == 0) {
1191 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) {
1192 vn_lock(ZTOV(dzp), LK_SHARED | LK_RETRY);
1193 error = VOP_READDIR(ZTOV(dzp), uiop, cr, eofp, ap->a_ncookies, ap->a_cookies);
1194 VN_URELE(ZTOV(dzp));
1205 * pvp is the '.zfs' directory (zfsctl_node_t).
1206 * Creates vp, which is '.zfs/snapshot' (zfsctl_snapdir_t).
1208 * This function is the callback to create a GFS vnode for '.zfs/snapshot'
1209 * when a lookup is performed on .zfs for "snapshot".
1212 zfsctl_mknode_snapdir(vnode_t *pvp)
1215 zfsctl_snapdir_t *sdp;
1217 vp = gfs_dir_create(sizeof (zfsctl_snapdir_t), pvp, pvp->v_vfsp,
1218 &zfsctl_ops_snapdir, NULL, NULL, MAXNAMELEN,
1219 zfsctl_snapdir_readdir_cb, NULL);
1221 sdp->sd_node.zc_id = ZFSCTL_INO_SNAPDIR;
1222 sdp->sd_node.zc_cmtime = ((zfsctl_node_t *)pvp->v_data)->zc_cmtime;
1223 mutex_init(&sdp->sd_lock, NULL, MUTEX_DEFAULT, NULL);
1224 avl_create(&sdp->sd_snaps, snapentry_compare,
1225 sizeof (zfs_snapentry_t), offsetof(zfs_snapentry_t, se_node));
1231 zfsctl_mknode_shares(vnode_t *pvp)
1236 vp = gfs_dir_create(sizeof (zfsctl_node_t), pvp, pvp->v_vfsp,
1237 &zfsctl_ops_shares, NULL, NULL, MAXNAMELEN,
1240 sdp->zc_cmtime = ((zfsctl_node_t *)pvp->v_data)->zc_cmtime;
1248 zfsctl_shares_getattr(ap)
1249 struct vop_getattr_args /* {
1251 struct vattr *a_vap;
1252 struct ucred *a_cred;
1253 struct thread *a_td;
1256 vnode_t *vp = ap->a_vp;
1257 vattr_t *vap = ap->a_vap;
1258 cred_t *cr = ap->a_cred;
1259 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
1264 if (zfsvfs->z_shares_dir == 0) {
1268 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) {
1269 vn_lock(ZTOV(dzp), LK_SHARED | LK_RETRY);
1270 error = VOP_GETATTR(ZTOV(dzp), vap, cr);
1271 VN_URELE(ZTOV(dzp));
1281 zfsctl_snapdir_getattr(ap)
1282 struct vop_getattr_args /* {
1284 struct vattr *a_vap;
1285 struct ucred *a_cred;
1288 vnode_t *vp = ap->a_vp;
1289 vattr_t *vap = ap->a_vap;
1290 zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data;
1291 zfsctl_snapdir_t *sdp = vp->v_data;
1294 zfsctl_common_getattr(vp, vap);
1295 vap->va_nodeid = gfs_file_inode(vp);
1296 vap->va_nlink = vap->va_size = avl_numnodes(&sdp->sd_snaps) + 2;
1297 vap->va_ctime = vap->va_mtime = dmu_objset_snap_cmtime(zfsvfs->z_os);
1298 vap->va_birthtime = vap->va_ctime;
1306 zfsctl_snapdir_inactive(ap)
1307 struct vop_inactive_args /* {
1309 struct thread *a_td;
1312 vnode_t *vp = ap->a_vp;
1313 zfsctl_snapdir_t *sdp = vp->v_data;
1314 zfs_snapentry_t *sep;
1317 * On forced unmount we have to free snapshots from here.
1319 mutex_enter(&sdp->sd_lock);
1320 while ((sep = avl_first(&sdp->sd_snaps)) != NULL) {
1321 avl_remove(&sdp->sd_snaps, sep);
1322 kmem_free(sep->se_name, strlen(sep->se_name) + 1);
1323 kmem_free(sep, sizeof (zfs_snapentry_t));
1325 mutex_exit(&sdp->sd_lock);
1326 gfs_dir_inactive(vp);
1327 ASSERT(avl_numnodes(&sdp->sd_snaps) == 0);
1328 mutex_destroy(&sdp->sd_lock);
1329 avl_destroy(&sdp->sd_snaps);
1330 kmem_free(sdp, sizeof (zfsctl_snapdir_t));
1336 static const fs_operation_def_t zfsctl_tops_snapdir[] = {
1337 { VOPNAME_OPEN, { .vop_open = zfsctl_common_open } },
1338 { VOPNAME_CLOSE, { .vop_close = zfsctl_common_close } },
1339 { VOPNAME_IOCTL, { .error = fs_inval } },
1340 { VOPNAME_GETATTR, { .vop_getattr = zfsctl_snapdir_getattr } },
1341 { VOPNAME_ACCESS, { .vop_access = zfsctl_common_access } },
1342 { VOPNAME_RENAME, { .vop_rename = zfsctl_snapdir_rename } },
1343 { VOPNAME_RMDIR, { .vop_rmdir = zfsctl_snapdir_remove } },
1344 { VOPNAME_MKDIR, { .vop_mkdir = zfsctl_snapdir_mkdir } },
1345 { VOPNAME_READDIR, { .vop_readdir = gfs_vop_readdir } },
1346 { VOPNAME_LOOKUP, { .vop_lookup = zfsctl_snapdir_lookup } },
1347 { VOPNAME_SEEK, { .vop_seek = fs_seek } },
1348 { VOPNAME_INACTIVE, { .vop_inactive = zfsctl_snapdir_inactive } },
1349 { VOPNAME_FID, { .vop_fid = zfsctl_common_fid } },
1353 static const fs_operation_def_t zfsctl_tops_shares[] = {
1354 { VOPNAME_OPEN, { .vop_open = zfsctl_common_open } },
1355 { VOPNAME_CLOSE, { .vop_close = zfsctl_common_close } },
1356 { VOPNAME_IOCTL, { .error = fs_inval } },
1357 { VOPNAME_GETATTR, { .vop_getattr = zfsctl_shares_getattr } },
1358 { VOPNAME_ACCESS, { .vop_access = zfsctl_common_access } },
1359 { VOPNAME_READDIR, { .vop_readdir = zfsctl_shares_readdir } },
1360 { VOPNAME_LOOKUP, { .vop_lookup = zfsctl_shares_lookup } },
1361 { VOPNAME_SEEK, { .vop_seek = fs_seek } },
1362 { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } },
1363 { VOPNAME_FID, { .vop_fid = zfsctl_shares_fid } },
1367 static struct vop_vector zfsctl_ops_snapdir = {
1368 .vop_default = &default_vnodeops,
1369 .vop_open = zfsctl_common_open,
1370 .vop_close = zfsctl_common_close,
1371 .vop_ioctl = VOP_EINVAL,
1372 .vop_getattr = zfsctl_snapdir_getattr,
1373 .vop_access = zfsctl_common_access,
1374 .vop_mkdir = zfsctl_freebsd_snapdir_mkdir,
1375 .vop_readdir = gfs_vop_readdir,
1376 .vop_lookup = zfsctl_snapdir_lookup,
1377 .vop_inactive = zfsctl_snapdir_inactive,
1378 .vop_reclaim = zfsctl_common_reclaim,
1379 .vop_fid = zfsctl_common_fid,
1382 static struct vop_vector zfsctl_ops_shares = {
1383 .vop_default = &default_vnodeops,
1384 .vop_open = zfsctl_common_open,
1385 .vop_close = zfsctl_common_close,
1386 .vop_ioctl = VOP_EINVAL,
1387 .vop_getattr = zfsctl_shares_getattr,
1388 .vop_access = zfsctl_common_access,
1389 .vop_readdir = zfsctl_shares_readdir,
1390 .vop_lookup = zfsctl_shares_lookup,
1391 .vop_inactive = gfs_vop_inactive,
1392 .vop_reclaim = zfsctl_common_reclaim,
1393 .vop_fid = zfsctl_shares_fid,
1398 * pvp is the GFS vnode '.zfs/snapshot'.
1400 * This creates a GFS node under '.zfs/snapshot' representing each
1401 * snapshot. This newly created GFS node is what we mount snapshot
1405 zfsctl_snapshot_mknode(vnode_t *pvp, uint64_t objset)
1410 vp = gfs_dir_create(sizeof (zfsctl_node_t), pvp, pvp->v_vfsp,
1411 &zfsctl_ops_snapshot, NULL, NULL, MAXNAMELEN, NULL, NULL);
1414 zcp->zc_id = objset;
1421 zfsctl_snapshot_inactive(ap)
1422 struct vop_inactive_args /* {
1424 struct thread *a_td;
1427 vnode_t *vp = ap->a_vp;
1428 cred_t *cr = ap->a_td->td_ucred;
1429 struct vop_inactive_args iap;
1430 zfsctl_snapdir_t *sdp;
1431 zfs_snapentry_t *sep, *next;
1435 if (vp->v_count > 0)
1438 VERIFY(gfs_dir_lookup(vp, "..", &dvp, cr, 0, NULL, NULL) == 0);
1442 if (!(locked = MUTEX_HELD(&sdp->sd_lock)))
1443 mutex_enter(&sdp->sd_lock);
1445 ASSERT(!vn_ismntpt(vp));
1447 sep = avl_first(&sdp->sd_snaps);
1448 while (sep != NULL) {
1449 next = AVL_NEXT(&sdp->sd_snaps, sep);
1451 if (sep->se_root == vp) {
1452 avl_remove(&sdp->sd_snaps, sep);
1453 kmem_free(sep->se_name, strlen(sep->se_name) + 1);
1454 kmem_free(sep, sizeof (zfs_snapentry_t));
1459 ASSERT(sep != NULL);
1462 mutex_exit(&sdp->sd_lock);
1467 * Dispose of the vnode for the snapshot mount point.
1468 * This is safe to do because once this entry has been removed
1469 * from the AVL tree, it can't be found again, so cannot become
1470 * "active". If we lookup the same name again we will end up
1471 * creating a new vnode.
1474 return (gfs_vop_inactive(&iap));
1478 zfsctl_traverse_begin(vnode_t **vpp, int lktype)
1482 /* Snapshot should be already mounted, but just in case. */
1483 if (vn_mountedvfs(*vpp) == NULL)
1485 return (traverse(vpp, lktype));
1489 zfsctl_traverse_end(vnode_t *vp, int err)
1499 zfsctl_snapshot_getattr(ap)
1500 struct vop_getattr_args /* {
1502 struct vattr *a_vap;
1503 struct ucred *a_cred;
1506 vnode_t *vp = ap->a_vp;
1509 err = zfsctl_traverse_begin(&vp, LK_SHARED | LK_RETRY);
1511 err = VOP_GETATTR(vp, ap->a_vap, ap->a_cred);
1512 zfsctl_traverse_end(vp, err);
1517 zfsctl_snapshot_fid(ap)
1518 struct vop_fid_args /* {
1523 vnode_t *vp = ap->a_vp;
1526 err = zfsctl_traverse_begin(&vp, LK_SHARED | LK_RETRY);
1528 err = VOP_VPTOFH(vp, (void *)ap->a_fid);
1529 zfsctl_traverse_end(vp, err);
1534 zfsctl_snapshot_lookup(ap)
1535 struct vop_lookup_args /* {
1536 struct vnode *a_dvp;
1537 struct vnode **a_vpp;
1538 struct componentname *a_cnp;
1541 vnode_t *dvp = ap->a_dvp;
1542 vnode_t **vpp = ap->a_vpp;
1543 struct componentname *cnp = ap->a_cnp;
1544 cred_t *cr = ap->a_cnp->cn_cred;
1545 zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data;
1548 if (cnp->cn_namelen != 2 || cnp->cn_nameptr[0] != '.' ||
1549 cnp->cn_nameptr[1] != '.') {
1553 ASSERT(dvp->v_type == VDIR);
1554 ASSERT(zfsvfs->z_ctldir != NULL);
1556 error = zfsctl_root_lookup(zfsvfs->z_ctldir, "snapshot", vpp,
1557 NULL, 0, NULL, cr, NULL, NULL, NULL);
1559 vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY);
1564 zfsctl_snapshot_vptocnp(struct vop_vptocnp_args *ap)
1566 zfsvfs_t *zfsvfs = ap->a_vp->v_vfsp->vfs_data;
1568 zfsctl_snapdir_t *sdp;
1569 zfs_snapentry_t *sep;
1572 ASSERT(zfsvfs->z_ctldir != NULL);
1573 error = zfsctl_root_lookup(zfsvfs->z_ctldir, "snapshot", &dvp,
1574 NULL, 0, NULL, kcred, NULL, NULL, NULL);
1579 mutex_enter(&sdp->sd_lock);
1580 sep = avl_first(&sdp->sd_snaps);
1581 while (sep != NULL) {
1585 sep = AVL_NEXT(&sdp->sd_snaps, sep);
1588 mutex_exit(&sdp->sd_lock);
1593 len = strlen(sep->se_name);
1594 *ap->a_buflen -= len;
1595 bcopy(sep->se_name, ap->a_buf + *ap->a_buflen, len);
1596 mutex_exit(&sdp->sd_lock);
1606 * These VP's should never see the light of day. They should always
1609 static struct vop_vector zfsctl_ops_snapshot = {
1610 .vop_default = &default_vnodeops,
1611 .vop_inactive = zfsctl_snapshot_inactive,
1612 .vop_lookup = zfsctl_snapshot_lookup,
1613 .vop_reclaim = zfsctl_common_reclaim,
1614 .vop_getattr = zfsctl_snapshot_getattr,
1615 .vop_fid = zfsctl_snapshot_fid,
1616 .vop_vptocnp = zfsctl_snapshot_vptocnp,
1620 zfsctl_lookup_objset(vfs_t *vfsp, uint64_t objsetid, zfsvfs_t **zfsvfsp)
1622 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1624 zfsctl_snapdir_t *sdp;
1626 zfs_snapentry_t *sep;
1629 ASSERT(zfsvfs->z_ctldir != NULL);
1630 error = zfsctl_root_lookup(zfsvfs->z_ctldir, "snapshot", &dvp,
1631 NULL, 0, NULL, kcred, NULL, NULL, NULL);
1636 mutex_enter(&sdp->sd_lock);
1637 sep = avl_first(&sdp->sd_snaps);
1638 while (sep != NULL) {
1641 if (zcp->zc_id == objsetid)
1644 sep = AVL_NEXT(&sdp->sd_snaps, sep);
1650 * Return the mounted root rather than the covered mount point.
1651 * Takes the GFS vnode at .zfs/snapshot/<snapshot objsetid>
1652 * and returns the ZFS vnode mounted on top of the GFS node.
1653 * This ZFS vnode is the root of the vfs for objset 'objsetid'.
1655 error = traverse(&vp, LK_SHARED | LK_RETRY);
1657 if (vp == sep->se_root)
1660 *zfsvfsp = VTOZ(vp)->z_zfsvfs;
1662 mutex_exit(&sdp->sd_lock);
1669 mutex_exit(&sdp->sd_lock);
1678 * Unmount any snapshots for the given filesystem. This is called from
1679 * zfs_umount() - if we have a ctldir, then go through and unmount all the
1683 zfsctl_umount_snapshots(vfs_t *vfsp, int fflags, cred_t *cr)
1685 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1687 zfsctl_snapdir_t *sdp;
1688 zfs_snapentry_t *sep, *next;
1691 ASSERT(zfsvfs->z_ctldir != NULL);
1692 error = zfsctl_root_lookup(zfsvfs->z_ctldir, "snapshot", &dvp,
1693 NULL, 0, NULL, cr, NULL, NULL, NULL);
1698 mutex_enter(&sdp->sd_lock);
1700 sep = avl_first(&sdp->sd_snaps);
1701 while (sep != NULL) {
1702 next = AVL_NEXT(&sdp->sd_snaps, sep);
1705 * If this snapshot is not mounted, then it must
1706 * have just been unmounted by somebody else, and
1707 * will be cleaned up by zfsctl_snapdir_inactive().
1709 if (vn_ismntpt(sep->se_root)) {
1710 error = zfsctl_unmount_snap(sep, fflags, cr);
1715 * Before reinserting snapshot to the tree,
1716 * check if it was actually removed. For example
1717 * when snapshot mount point is busy, we will
1718 * have an error here, but there will be no need
1719 * to reinsert snapshot.
1721 if (avl_find(&sdp->sd_snaps, sep, &where) == NULL)
1722 avl_insert(&sdp->sd_snaps, sep, where);
1729 mutex_exit(&sdp->sd_lock);