author | George Wilson <George.Wilson@Sun.COM> |
Wed, 19 May 2010 22:59:13 -0700 | |
changeset 12450 | c77e20e4e046 |
parent 12079 | 13822b941977 |
child 12906 | 3ca11e9f39b7 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1512 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
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. |
|
12 |
* |
|
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] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
12079
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
22 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
789 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* ZFS control directory (a.k.a. ".zfs") |
|
27 |
* |
|
28 |
* This directory provides a common location for all ZFS meta-objects. |
|
29 |
* Currently, this is only the 'snapshot' directory, but this may expand in the |
|
30 |
* future. The elements are built using the GFS primitives, as the hierarchy |
|
31 |
* does not actually exist on disk. |
|
32 |
* |
|
33 |
* For 'snapshot', we don't want to have all snapshots always mounted, because |
|
34 |
* this would take up a huge amount of space in /etc/mnttab. We have three |
|
35 |
* types of objects: |
|
36 |
* |
|
37 |
* ctldir ------> snapshotdir -------> snapshot |
|
38 |
* | |
|
39 |
* | |
|
40 |
* V |
|
41 |
* mounted fs |
|
42 |
* |
|
43 |
* The 'snapshot' node contains just enough information to lookup '..' and act |
|
44 |
* as a mountpoint for the snapshot. Whenever we lookup a specific snapshot, we |
|
45 |
* perform an automount of the underlying filesystem and return the |
|
46 |
* corresponding vnode. |
|
47 |
* |
|
48 |
* All mounts are handled automatically by the kernel, but unmounts are |
|
49 |
* (currently) handled from user land. The main reason is that there is no |
|
50 |
* reliable way to auto-unmount the filesystem when it's "no longer in use". |
|
51 |
* When the user unmounts a filesystem, we call zfsctl_unmount(), which |
|
52 |
* unmounts any snapshots within the snapshot directory. |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
53 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
54 |
* The '.zfs', '.zfs/snapshot', and all directories created under |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
55 |
* '.zfs/snapshot' (ie: '.zfs/snapshot/<snapname>') are all GFS nodes and |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
56 |
* share the same vfs_t as the head filesystem (what '.zfs' lives under). |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
57 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
58 |
* File systems mounted ontop of the GFS nodes '.zfs/snapshot/<snapname>' |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
59 |
* (ie: snapshots) are ZFS nodes and have their own unique vfs_t. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
60 |
* However, vnodes within these mounted on file systems have their v_vfsp |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
61 |
* fields set to the head filesystem to make NFS happy (see |
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
62 |
* zfsctl_snapdir_lookup()). We VFS_HOLD the head filesystem's vfs_t |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
63 |
* so that it cannot be freed until all snapshots have been unmounted. |
789 | 64 |
*/ |
65 |
||
66 |
#include <fs/fs_subr.h> |
|
67 |
#include <sys/zfs_ctldir.h> |
|
68 |
#include <sys/zfs_ioctl.h> |
|
69 |
#include <sys/zfs_vfsops.h> |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
70 |
#include <sys/vfs_opreg.h> |
789 | 71 |
#include <sys/gfs.h> |
72 |
#include <sys/stat.h> |
|
73 |
#include <sys/dmu.h> |
|
4543 | 74 |
#include <sys/dsl_deleg.h> |
789 | 75 |
#include <sys/mount.h> |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
76 |
#include <sys/sunddi.h> |
789 | 77 |
|
6658
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
78 |
#include "zfs_namecheck.h" |
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
79 |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
80 |
typedef struct zfsctl_node { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
81 |
gfs_dir_t zc_gfs_private; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
82 |
uint64_t zc_id; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
83 |
timestruc_t zc_cmtime; /* ctime and mtime, always the same */ |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
84 |
} zfsctl_node_t; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
85 |
|
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
86 |
typedef struct zfsctl_snapdir { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
87 |
zfsctl_node_t sd_node; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
88 |
kmutex_t sd_lock; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
89 |
avl_tree_t sd_snaps; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
90 |
} zfsctl_snapdir_t; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
91 |
|
789 | 92 |
typedef struct { |
93 |
char *se_name; |
|
94 |
vnode_t *se_root; |
|
95 |
avl_node_t se_node; |
|
96 |
} zfs_snapentry_t; |
|
97 |
||
98 |
static int |
|
99 |
snapentry_compare(const void *a, const void *b) |
|
100 |
{ |
|
101 |
const zfs_snapentry_t *sa = a; |
|
102 |
const zfs_snapentry_t *sb = b; |
|
103 |
int ret = strcmp(sa->se_name, sb->se_name); |
|
104 |
||
105 |
if (ret < 0) |
|
106 |
return (-1); |
|
107 |
else if (ret > 0) |
|
108 |
return (1); |
|
109 |
else |
|
110 |
return (0); |
|
111 |
} |
|
112 |
||
113 |
vnodeops_t *zfsctl_ops_root; |
|
114 |
vnodeops_t *zfsctl_ops_snapdir; |
|
115 |
vnodeops_t *zfsctl_ops_snapshot; |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
116 |
vnodeops_t *zfsctl_ops_shares; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
117 |
vnodeops_t *zfsctl_ops_shares_dir; |
789 | 118 |
|
119 |
static const fs_operation_def_t zfsctl_tops_root[]; |
|
120 |
static const fs_operation_def_t zfsctl_tops_snapdir[]; |
|
121 |
static const fs_operation_def_t zfsctl_tops_snapshot[]; |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
122 |
static const fs_operation_def_t zfsctl_tops_shares[]; |
789 | 123 |
|
124 |
static vnode_t *zfsctl_mknode_snapdir(vnode_t *); |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
125 |
static vnode_t *zfsctl_mknode_shares(vnode_t *); |
789 | 126 |
static vnode_t *zfsctl_snapshot_mknode(vnode_t *, uint64_t objset); |
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
127 |
static int zfsctl_unmount_snap(zfs_snapentry_t *, int, cred_t *); |
789 | 128 |
|
129 |
static gfs_opsvec_t zfsctl_opsvec[] = { |
|
130 |
{ ".zfs", zfsctl_tops_root, &zfsctl_ops_root }, |
|
131 |
{ ".zfs/snapshot", zfsctl_tops_snapdir, &zfsctl_ops_snapdir }, |
|
132 |
{ ".zfs/snapshot/vnode", zfsctl_tops_snapshot, &zfsctl_ops_snapshot }, |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
133 |
{ ".zfs/shares", zfsctl_tops_shares, &zfsctl_ops_shares_dir }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
134 |
{ ".zfs/shares/vnode", zfsctl_tops_shares, &zfsctl_ops_shares }, |
789 | 135 |
{ NULL } |
136 |
}; |
|
137 |
||
138 |
/* |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
139 |
* Root directory elements. We only have two entries |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
140 |
* snapshot and shares. |
789 | 141 |
*/ |
142 |
static gfs_dirent_t zfsctl_root_entries[] = { |
|
143 |
{ "snapshot", zfsctl_mknode_snapdir, GFS_CACHE_VNODE }, |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
144 |
{ "shares", zfsctl_mknode_shares, GFS_CACHE_VNODE }, |
789 | 145 |
{ NULL } |
146 |
}; |
|
147 |
||
148 |
/* include . and .. in the calculation */ |
|
149 |
#define NROOT_ENTRIES ((sizeof (zfsctl_root_entries) / \ |
|
150 |
sizeof (gfs_dirent_t)) + 1) |
|
151 |
||
152 |
||
153 |
/* |
|
154 |
* Initialize the various GFS pieces we'll need to create and manipulate .zfs |
|
155 |
* directories. This is called from the ZFS init routine, and initializes the |
|
156 |
* vnode ops vectors that we'll be using. |
|
157 |
*/ |
|
158 |
void |
|
159 |
zfsctl_init(void) |
|
160 |
{ |
|
161 |
VERIFY(gfs_make_opsvec(zfsctl_opsvec) == 0); |
|
162 |
} |
|
163 |
||
164 |
void |
|
165 |
zfsctl_fini(void) |
|
166 |
{ |
|
167 |
/* |
|
168 |
* Remove vfsctl vnode ops |
|
169 |
*/ |
|
170 |
if (zfsctl_ops_root) |
|
171 |
vn_freevnodeops(zfsctl_ops_root); |
|
172 |
if (zfsctl_ops_snapdir) |
|
173 |
vn_freevnodeops(zfsctl_ops_snapdir); |
|
174 |
if (zfsctl_ops_snapshot) |
|
175 |
vn_freevnodeops(zfsctl_ops_snapshot); |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
176 |
if (zfsctl_ops_shares) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
177 |
vn_freevnodeops(zfsctl_ops_shares); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
178 |
if (zfsctl_ops_shares_dir) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
179 |
vn_freevnodeops(zfsctl_ops_shares_dir); |
789 | 180 |
|
181 |
zfsctl_ops_root = NULL; |
|
182 |
zfsctl_ops_snapdir = NULL; |
|
183 |
zfsctl_ops_snapshot = NULL; |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
184 |
zfsctl_ops_shares = NULL; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
185 |
zfsctl_ops_shares_dir = NULL; |
789 | 186 |
} |
187 |
||
12079
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
188 |
boolean_t |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
189 |
zfsctl_is_node(vnode_t *vp) |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
190 |
{ |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
191 |
return (vn_matchops(vp, zfsctl_ops_root) || |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
192 |
vn_matchops(vp, zfsctl_ops_snapdir) || |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
193 |
vn_matchops(vp, zfsctl_ops_snapshot) || |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
194 |
vn_matchops(vp, zfsctl_ops_shares) || |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
195 |
vn_matchops(vp, zfsctl_ops_shares_dir)); |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
196 |
|
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
197 |
} |
13822b941977
6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11935
diff
changeset
|
198 |
|
789 | 199 |
/* |
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
200 |
* Return the inode number associated with the 'snapshot' or |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
201 |
* 'shares' directory. |
789 | 202 |
*/ |
203 |
/* ARGSUSED */ |
|
204 |
static ino64_t |
|
205 |
zfsctl_root_inode_cb(vnode_t *vp, int index) |
|
206 |
{ |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
207 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
208 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
209 |
ASSERT(index <= 2); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
210 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
211 |
if (index == 0) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
212 |
return (ZFSCTL_INO_SNAPDIR); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
213 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
214 |
return (zfsvfs->z_shares_dir); |
789 | 215 |
} |
216 |
||
217 |
/* |
|
218 |
* Create the '.zfs' directory. This directory is cached as part of the VFS |
|
219 |
* structure. This results in a hold on the vfs_t. The code in zfs_umount() |
|
220 |
* therefore checks against a vfs_count of 2 instead of 1. This reference |
|
221 |
* is removed when the ctldir is destroyed in the unmount. |
|
222 |
*/ |
|
223 |
void |
|
224 |
zfsctl_create(zfsvfs_t *zfsvfs) |
|
225 |
{ |
|
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
226 |
vnode_t *vp, *rvp; |
789 | 227 |
zfsctl_node_t *zcp; |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10373
diff
changeset
|
228 |
uint64_t crtime[2]; |
789 | 229 |
|
230 |
ASSERT(zfsvfs->z_ctldir == NULL); |
|
231 |
||
232 |
vp = gfs_root_create(sizeof (zfsctl_node_t), zfsvfs->z_vfs, |
|
233 |
zfsctl_ops_root, ZFSCTL_INO_ROOT, zfsctl_root_entries, |
|
234 |
zfsctl_root_inode_cb, MAXNAMELEN, NULL, NULL); |
|
235 |
zcp = vp->v_data; |
|
236 |
zcp->zc_id = ZFSCTL_INO_ROOT; |
|
237 |
||
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
238 |
VERIFY(VFS_ROOT(zfsvfs->z_vfs, &rvp) == 0); |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10373
diff
changeset
|
239 |
VERIFY(0 == sa_lookup(VTOZ(rvp)->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs), |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10373
diff
changeset
|
240 |
&crtime, sizeof (crtime))); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10373
diff
changeset
|
241 |
ZFS_TIME_DECODE(&zcp->zc_cmtime, crtime); |
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
242 |
VN_RELE(rvp); |
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
243 |
|
789 | 244 |
/* |
245 |
* We're only faking the fact that we have a root of a filesystem for |
|
246 |
* the sake of the GFS interfaces. Undo the flag manipulation it did |
|
247 |
* for us. |
|
248 |
*/ |
|
249 |
vp->v_flag &= ~(VROOT | VNOCACHE | VNOMAP | VNOSWAP | VNOMOUNT); |
|
250 |
||
251 |
zfsvfs->z_ctldir = vp; |
|
252 |
} |
|
253 |
||
254 |
/* |
|
1298 | 255 |
* Destroy the '.zfs' directory. Only called when the filesystem is unmounted. |
256 |
* There might still be more references if we were force unmounted, but only |
|
257 |
* new zfs_inactive() calls can occur and they don't reference .zfs |
|
789 | 258 |
*/ |
259 |
void |
|
260 |
zfsctl_destroy(zfsvfs_t *zfsvfs) |
|
261 |
{ |
|
262 |
VN_RELE(zfsvfs->z_ctldir); |
|
263 |
zfsvfs->z_ctldir = NULL; |
|
264 |
} |
|
265 |
||
266 |
/* |
|
267 |
* Given a root znode, retrieve the associated .zfs directory. |
|
268 |
* Add a hold to the vnode and return it. |
|
269 |
*/ |
|
270 |
vnode_t * |
|
271 |
zfsctl_root(znode_t *zp) |
|
272 |
{ |
|
273 |
ASSERT(zfs_has_ctldir(zp)); |
|
274 |
VN_HOLD(zp->z_zfsvfs->z_ctldir); |
|
275 |
return (zp->z_zfsvfs->z_ctldir); |
|
276 |
} |
|
277 |
||
278 |
/* |
|
279 |
* Common open routine. Disallow any write access. |
|
280 |
*/ |
|
281 |
/* ARGSUSED */ |
|
282 |
static int |
|
5331 | 283 |
zfsctl_common_open(vnode_t **vpp, int flags, cred_t *cr, caller_context_t *ct) |
789 | 284 |
{ |
285 |
if (flags & FWRITE) |
|
286 |
return (EACCES); |
|
287 |
||
288 |
return (0); |
|
289 |
} |
|
290 |
||
291 |
/* |
|
292 |
* Common close routine. Nothing to do here. |
|
293 |
*/ |
|
294 |
/* ARGSUSED */ |
|
295 |
static int |
|
296 |
zfsctl_common_close(vnode_t *vpp, int flags, int count, offset_t off, |
|
5331 | 297 |
cred_t *cr, caller_context_t *ct) |
789 | 298 |
{ |
299 |
return (0); |
|
300 |
} |
|
301 |
||
302 |
/* |
|
303 |
* Common access routine. Disallow writes. |
|
304 |
*/ |
|
305 |
/* ARGSUSED */ |
|
306 |
static int |
|
5331 | 307 |
zfsctl_common_access(vnode_t *vp, int mode, int flags, cred_t *cr, |
308 |
caller_context_t *ct) |
|
789 | 309 |
{ |
8547
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
310 |
if (flags & V_ACE_MASK) { |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
311 |
if (mode & ACE_ALL_WRITE_PERMS) |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
312 |
return (EACCES); |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
313 |
} else { |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
314 |
if (mode & VWRITE) |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
315 |
return (EACCES); |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
316 |
} |
789 | 317 |
|
318 |
return (0); |
|
319 |
} |
|
320 |
||
321 |
/* |
|
322 |
* Common getattr function. Fill in basic information. |
|
323 |
*/ |
|
324 |
static void |
|
325 |
zfsctl_common_getattr(vnode_t *vp, vattr_t *vap) |
|
326 |
{ |
|
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
327 |
timestruc_t now; |
789 | 328 |
|
329 |
vap->va_uid = 0; |
|
330 |
vap->va_gid = 0; |
|
331 |
vap->va_rdev = 0; |
|
332 |
/* |
|
10373
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
333 |
* We are a purely virtual object, so we have no |
789 | 334 |
* blocksize or allocated blocks. |
335 |
*/ |
|
336 |
vap->va_blksize = 0; |
|
337 |
vap->va_nblocks = 0; |
|
338 |
vap->va_seq = 0; |
|
339 |
vap->va_fsid = vp->v_vfsp->vfs_dev; |
|
340 |
vap->va_mode = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | |
|
341 |
S_IROTH | S_IXOTH; |
|
342 |
vap->va_type = VDIR; |
|
343 |
/* |
|
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
344 |
* We live in the now (for atime). |
789 | 345 |
*/ |
346 |
gethrestime(&now); |
|
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
347 |
vap->va_atime = now; |
789 | 348 |
} |
349 |
||
5331 | 350 |
/*ARGSUSED*/ |
789 | 351 |
static int |
5331 | 352 |
zfsctl_common_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct) |
789 | 353 |
{ |
354 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
|
355 |
zfsctl_node_t *zcp = vp->v_data; |
|
356 |
uint64_t object = zcp->zc_id; |
|
357 |
zfid_short_t *zfid; |
|
358 |
int i; |
|
359 |
||
360 |
ZFS_ENTER(zfsvfs); |
|
361 |
||
362 |
if (fidp->fid_len < SHORT_FID_LEN) { |
|
363 |
fidp->fid_len = SHORT_FID_LEN; |
|
1512 | 364 |
ZFS_EXIT(zfsvfs); |
789 | 365 |
return (ENOSPC); |
366 |
} |
|
367 |
||
368 |
zfid = (zfid_short_t *)fidp; |
|
369 |
||
370 |
zfid->zf_len = SHORT_FID_LEN; |
|
371 |
||
372 |
for (i = 0; i < sizeof (zfid->zf_object); i++) |
|
373 |
zfid->zf_object[i] = (uint8_t)(object >> (8 * i)); |
|
374 |
||
375 |
/* .zfs znodes always have a generation number of 0 */ |
|
376 |
for (i = 0; i < sizeof (zfid->zf_gen); i++) |
|
377 |
zfid->zf_gen[i] = 0; |
|
378 |
||
379 |
ZFS_EXIT(zfsvfs); |
|
380 |
return (0); |
|
381 |
} |
|
382 |
||
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
383 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
384 |
/*ARGSUSED*/ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
385 |
static int |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
386 |
zfsctl_shares_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
387 |
{ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
388 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
389 |
znode_t *dzp; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
390 |
int error; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
391 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
392 |
ZFS_ENTER(zfsvfs); |
9030
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
393 |
|
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
394 |
if (zfsvfs->z_shares_dir == 0) { |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
395 |
ZFS_EXIT(zfsvfs); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
396 |
return (ENOTSUP); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
397 |
} |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
398 |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
399 |
if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) { |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
400 |
error = VOP_FID(ZTOV(dzp), fidp, ct); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
401 |
VN_RELE(ZTOV(dzp)); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
402 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
403 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
404 |
ZFS_EXIT(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
405 |
return (error); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
406 |
} |
789 | 407 |
/* |
408 |
* .zfs inode namespace |
|
409 |
* |
|
410 |
* We need to generate unique inode numbers for all files and directories |
|
411 |
* within the .zfs pseudo-filesystem. We use the following scheme: |
|
412 |
* |
|
413 |
* ENTRY ZFSCTL_INODE |
|
414 |
* .zfs 1 |
|
415 |
* .zfs/snapshot 2 |
|
416 |
* .zfs/snapshot/<snap> objectid(snap) |
|
417 |
*/ |
|
418 |
||
419 |
#define ZFSCTL_INO_SNAP(id) (id) |
|
420 |
||
421 |
/* |
|
422 |
* Get root directory attributes. |
|
423 |
*/ |
|
424 |
/* ARGSUSED */ |
|
425 |
static int |
|
5331 | 426 |
zfsctl_root_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, |
427 |
caller_context_t *ct) |
|
789 | 428 |
{ |
429 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
|
10373
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
430 |
zfsctl_node_t *zcp = vp->v_data; |
789 | 431 |
|
432 |
ZFS_ENTER(zfsvfs); |
|
433 |
vap->va_nodeid = ZFSCTL_INO_ROOT; |
|
434 |
vap->va_nlink = vap->va_size = NROOT_ENTRIES; |
|
10373
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
435 |
vap->va_mtime = vap->va_ctime = zcp->zc_cmtime; |
789 | 436 |
|
437 |
zfsctl_common_getattr(vp, vap); |
|
438 |
ZFS_EXIT(zfsvfs); |
|
439 |
||
440 |
return (0); |
|
441 |
} |
|
442 |
||
443 |
/* |
|
444 |
* Special case the handling of "..". |
|
445 |
*/ |
|
446 |
/* ARGSUSED */ |
|
447 |
int |
|
448 |
zfsctl_root_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp, |
|
5331 | 449 |
int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, |
450 |
int *direntflags, pathname_t *realpnp) |
|
789 | 451 |
{ |
452 |
zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data; |
|
453 |
int err; |
|
454 |
||
5331 | 455 |
/* |
456 |
* No extended attributes allowed under .zfs |
|
457 |
*/ |
|
458 |
if (flags & LOOKUP_XATTR) |
|
459 |
return (EINVAL); |
|
460 |
||
789 | 461 |
ZFS_ENTER(zfsvfs); |
462 |
||
463 |
if (strcmp(nm, "..") == 0) { |
|
464 |
err = VFS_ROOT(dvp->v_vfsp, vpp); |
|
465 |
} else { |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
466 |
err = gfs_vop_lookup(dvp, nm, vpp, pnp, flags, rdir, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
467 |
cr, ct, direntflags, realpnp); |
789 | 468 |
} |
469 |
||
470 |
ZFS_EXIT(zfsvfs); |
|
471 |
||
472 |
return (err); |
|
473 |
} |
|
474 |
||
8547
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
475 |
static int |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
476 |
zfsctl_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr, |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
477 |
caller_context_t *ct) |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
478 |
{ |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
479 |
/* |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
480 |
* We only care about ACL_ENABLED so that libsec can |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
481 |
* display ACL correctly and not default to POSIX draft. |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
482 |
*/ |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
483 |
if (cmd == _PC_ACL_ENABLED) { |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
484 |
*valp = _ACL_ACE_ENABLED; |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
485 |
return (0); |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
486 |
} |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
487 |
|
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
488 |
return (fs_pathconf(vp, cmd, valp, cr, ct)); |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
489 |
} |
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
490 |
|
789 | 491 |
static const fs_operation_def_t zfsctl_tops_root[] = { |
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
492 |
{ VOPNAME_OPEN, { .vop_open = zfsctl_common_open } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
493 |
{ VOPNAME_CLOSE, { .vop_close = zfsctl_common_close } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
494 |
{ VOPNAME_IOCTL, { .error = fs_inval } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
495 |
{ VOPNAME_GETATTR, { .vop_getattr = zfsctl_root_getattr } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
496 |
{ VOPNAME_ACCESS, { .vop_access = zfsctl_common_access } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
497 |
{ VOPNAME_READDIR, { .vop_readdir = gfs_vop_readdir } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
498 |
{ VOPNAME_LOOKUP, { .vop_lookup = zfsctl_root_lookup } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
499 |
{ VOPNAME_SEEK, { .vop_seek = fs_seek } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
500 |
{ VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } }, |
8547
bcc7b46e5ff7
6792884 Vista clients cannot access .zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
7229
diff
changeset
|
501 |
{ VOPNAME_PATHCONF, { .vop_pathconf = zfsctl_pathconf } }, |
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
502 |
{ VOPNAME_FID, { .vop_fid = zfsctl_common_fid } }, |
789 | 503 |
{ NULL } |
504 |
}; |
|
505 |
||
506 |
static int |
|
507 |
zfsctl_snapshot_zname(vnode_t *vp, const char *name, int len, char *zname) |
|
508 |
{ |
|
509 |
objset_t *os = ((zfsvfs_t *)((vp)->v_vfsp->vfs_data))->z_os; |
|
510 |
||
6658
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
511 |
if (snapshot_namecheck(name, NULL, NULL) != 0) |
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
512 |
return (EILSEQ); |
789 | 513 |
dmu_objset_name(os, zname); |
1154 | 514 |
if (strlen(zname) + 1 + strlen(name) >= len) |
515 |
return (ENAMETOOLONG); |
|
789 | 516 |
(void) strcat(zname, "@"); |
517 |
(void) strcat(zname, name); |
|
518 |
return (0); |
|
519 |
} |
|
520 |
||
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
521 |
static int |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
522 |
zfsctl_unmount_snap(zfs_snapentry_t *sep, int fflags, cred_t *cr) |
789 | 523 |
{ |
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
524 |
vnode_t *svp = sep->se_root; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
525 |
int error; |
789 | 526 |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
527 |
ASSERT(vn_ismntpt(svp)); |
789 | 528 |
|
529 |
/* this will be dropped by dounmount() */ |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
530 |
if ((error = vn_vfswlock(svp)) != 0) |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
531 |
return (error); |
789 | 532 |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
533 |
VN_HOLD(svp); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
534 |
error = dounmount(vn_mountedvfs(svp), fflags, cr); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
535 |
if (error) { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
536 |
VN_RELE(svp); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
537 |
return (error); |
1589
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
538 |
} |
9214
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
539 |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
540 |
/* |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
541 |
* We can't use VN_RELE(), as that will try to invoke |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
542 |
* zfsctl_snapdir_inactive(), which would cause us to destroy |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
543 |
* the sd_lock mutex held by our caller. |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
544 |
*/ |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
545 |
ASSERT(svp->v_count == 1); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
546 |
gfs_vop_inactive(svp, cr, NULL); |
789 | 547 |
|
548 |
kmem_free(sep->se_name, strlen(sep->se_name) + 1); |
|
549 |
kmem_free(sep, sizeof (zfs_snapentry_t)); |
|
550 |
||
551 |
return (0); |
|
552 |
} |
|
553 |
||
1154 | 554 |
static void |
789 | 555 |
zfsctl_rename_snap(zfsctl_snapdir_t *sdp, zfs_snapentry_t *sep, const char *nm) |
556 |
{ |
|
557 |
avl_index_t where; |
|
558 |
vfs_t *vfsp; |
|
559 |
refstr_t *pathref; |
|
560 |
char newpath[MAXNAMELEN]; |
|
561 |
char *tail; |
|
562 |
||
563 |
ASSERT(MUTEX_HELD(&sdp->sd_lock)); |
|
564 |
ASSERT(sep != NULL); |
|
565 |
||
566 |
vfsp = vn_mountedvfs(sep->se_root); |
|
567 |
ASSERT(vfsp != NULL); |
|
568 |
||
1154 | 569 |
vfs_lock_wait(vfsp); |
789 | 570 |
|
571 |
/* |
|
572 |
* Change the name in the AVL tree. |
|
573 |
*/ |
|
574 |
avl_remove(&sdp->sd_snaps, sep); |
|
575 |
kmem_free(sep->se_name, strlen(sep->se_name) + 1); |
|
576 |
sep->se_name = kmem_alloc(strlen(nm) + 1, KM_SLEEP); |
|
577 |
(void) strcpy(sep->se_name, nm); |
|
578 |
VERIFY(avl_find(&sdp->sd_snaps, sep, &where) == NULL); |
|
579 |
avl_insert(&sdp->sd_snaps, sep, where); |
|
580 |
||
581 |
/* |
|
582 |
* Change the current mountpoint info: |
|
583 |
* - update the tail of the mntpoint path |
|
584 |
* - update the tail of the resource path |
|
585 |
*/ |
|
586 |
pathref = vfs_getmntpoint(vfsp); |
|
2417 | 587 |
(void) strncpy(newpath, refstr_value(pathref), sizeof (newpath)); |
588 |
VERIFY((tail = strrchr(newpath, '/')) != NULL); |
|
589 |
*(tail+1) = '\0'; |
|
590 |
ASSERT3U(strlen(newpath) + strlen(nm), <, sizeof (newpath)); |
|
789 | 591 |
(void) strcat(newpath, nm); |
592 |
refstr_rele(pathref); |
|
593 |
vfs_setmntpoint(vfsp, newpath); |
|
594 |
||
595 |
pathref = vfs_getresource(vfsp); |
|
2417 | 596 |
(void) strncpy(newpath, refstr_value(pathref), sizeof (newpath)); |
597 |
VERIFY((tail = strrchr(newpath, '@')) != NULL); |
|
598 |
*(tail+1) = '\0'; |
|
599 |
ASSERT3U(strlen(newpath) + strlen(nm), <, sizeof (newpath)); |
|
789 | 600 |
(void) strcat(newpath, nm); |
601 |
refstr_rele(pathref); |
|
602 |
vfs_setresource(vfsp, newpath); |
|
603 |
||
604 |
vfs_unlock(vfsp); |
|
605 |
} |
|
606 |
||
5331 | 607 |
/*ARGSUSED*/ |
789 | 608 |
static int |
609 |
zfsctl_snapdir_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, |
|
5331 | 610 |
cred_t *cr, caller_context_t *ct, int flags) |
789 | 611 |
{ |
612 |
zfsctl_snapdir_t *sdp = sdvp->v_data; |
|
613 |
zfs_snapentry_t search, *sep; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
614 |
zfsvfs_t *zfsvfs; |
789 | 615 |
avl_index_t where; |
616 |
char from[MAXNAMELEN], to[MAXNAMELEN]; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
617 |
char real[MAXNAMELEN]; |
789 | 618 |
int err; |
619 |
||
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
620 |
zfsvfs = sdvp->v_vfsp->vfs_data; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
621 |
ZFS_ENTER(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
622 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
623 |
if ((flags & FIGNORECASE) || zfsvfs->z_case == ZFS_CASE_INSENSITIVE) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
624 |
err = dmu_snapshot_realname(zfsvfs->z_os, snm, real, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
625 |
MAXNAMELEN, NULL); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
626 |
if (err == 0) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
627 |
snm = real; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
628 |
} else if (err != ENOTSUP) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
629 |
ZFS_EXIT(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
630 |
return (err); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
631 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
632 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
633 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
634 |
ZFS_EXIT(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
635 |
|
1154 | 636 |
err = zfsctl_snapshot_zname(sdvp, snm, MAXNAMELEN, from); |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
637 |
if (!err) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
638 |
err = zfsctl_snapshot_zname(tdvp, tnm, MAXNAMELEN, to); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
639 |
if (!err) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
640 |
err = zfs_secpolicy_rename_perms(from, to, cr); |
1154 | 641 |
if (err) |
642 |
return (err); |
|
4543 | 643 |
|
789 | 644 |
/* |
645 |
* Cannot move snapshots out of the snapdir. |
|
646 |
*/ |
|
647 |
if (sdvp != tdvp) |
|
648 |
return (EINVAL); |
|
649 |
||
650 |
if (strcmp(snm, tnm) == 0) |
|
651 |
return (0); |
|
652 |
||
653 |
mutex_enter(&sdp->sd_lock); |
|
654 |
||
655 |
search.se_name = (char *)snm; |
|
1154 | 656 |
if ((sep = avl_find(&sdp->sd_snaps, &search, &where)) == NULL) { |
657 |
mutex_exit(&sdp->sd_lock); |
|
658 |
return (ENOENT); |
|
789 | 659 |
} |
660 |
||
4007 | 661 |
err = dmu_objset_rename(from, to, B_FALSE); |
1154 | 662 |
if (err == 0) |
663 |
zfsctl_rename_snap(sdp, sep, tnm); |
|
789 | 664 |
|
665 |
mutex_exit(&sdp->sd_lock); |
|
666 |
||
667 |
return (err); |
|
668 |
} |
|
669 |
||
670 |
/* ARGSUSED */ |
|
671 |
static int |
|
5331 | 672 |
zfsctl_snapdir_remove(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr, |
673 |
caller_context_t *ct, int flags) |
|
789 | 674 |
{ |
675 |
zfsctl_snapdir_t *sdp = dvp->v_data; |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
676 |
zfs_snapentry_t *sep; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
677 |
zfs_snapentry_t search; |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
678 |
zfsvfs_t *zfsvfs; |
789 | 679 |
char snapname[MAXNAMELEN]; |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
680 |
char real[MAXNAMELEN]; |
789 | 681 |
int err; |
682 |
||
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
683 |
zfsvfs = dvp->v_vfsp->vfs_data; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
684 |
ZFS_ENTER(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
685 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
686 |
if ((flags & FIGNORECASE) || zfsvfs->z_case == ZFS_CASE_INSENSITIVE) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
687 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
688 |
err = dmu_snapshot_realname(zfsvfs->z_os, name, real, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
689 |
MAXNAMELEN, NULL); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
690 |
if (err == 0) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
691 |
name = real; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
692 |
} else if (err != ENOTSUP) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
693 |
ZFS_EXIT(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
694 |
return (err); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
695 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
696 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
697 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
698 |
ZFS_EXIT(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
699 |
|
1154 | 700 |
err = zfsctl_snapshot_zname(dvp, name, MAXNAMELEN, snapname); |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
701 |
if (!err) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
702 |
err = zfs_secpolicy_destroy_perms(snapname, cr); |
1154 | 703 |
if (err) |
704 |
return (err); |
|
4543 | 705 |
|
789 | 706 |
mutex_enter(&sdp->sd_lock); |
707 |
||
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
708 |
search.se_name = name; |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
709 |
sep = avl_find(&sdp->sd_snaps, &search, NULL); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
710 |
if (sep) { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
711 |
avl_remove(&sdp->sd_snaps, sep); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
712 |
err = zfsctl_unmount_snap(sep, MS_FORCE, cr); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
713 |
if (err) |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
714 |
avl_add(&sdp->sd_snaps, sep); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
715 |
else |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
9355
diff
changeset
|
716 |
err = dmu_objset_destroy(snapname, B_FALSE); |
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
717 |
} else { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
718 |
err = ENOENT; |
789 | 719 |
} |
720 |
||
721 |
mutex_exit(&sdp->sd_lock); |
|
722 |
||
723 |
return (err); |
|
724 |
} |
|
725 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
726 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
727 |
* This creates a snapshot under '.zfs/snapshot'. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
728 |
*/ |
4543 | 729 |
/* ARGSUSED */ |
730 |
static int |
|
731 |
zfsctl_snapdir_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, |
|
5331 | 732 |
cred_t *cr, caller_context_t *cc, int flags, vsecattr_t *vsecp) |
4543 | 733 |
{ |
734 |
zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data; |
|
735 |
char name[MAXNAMELEN]; |
|
736 |
int err; |
|
737 |
static enum symfollow follow = NO_FOLLOW; |
|
738 |
static enum uio_seg seg = UIO_SYSSPACE; |
|
739 |
||
6658
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
740 |
if (snapshot_namecheck(dirname, NULL, NULL) != 0) |
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
741 |
return (EILSEQ); |
468e12a53baf
6700649 zfs_ctldir snapshot creation issues with CIFS clients
marks
parents:
6492
diff
changeset
|
742 |
|
4543 | 743 |
dmu_objset_name(zfsvfs->z_os, name); |
744 |
||
745 |
*vpp = NULL; |
|
746 |
||
747 |
err = zfs_secpolicy_snapshot_perms(name, cr); |
|
748 |
if (err) |
|
749 |
return (err); |
|
750 |
||
751 |
if (err == 0) { |
|
9355
09928982c591
6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9214
diff
changeset
|
752 |
err = dmu_objset_snapshot(name, dirname, NULL, B_FALSE); |
4543 | 753 |
if (err) |
754 |
return (err); |
|
755 |
err = lookupnameat(dirname, seg, follow, NULL, vpp, dvp); |
|
756 |
} |
|
757 |
||
758 |
return (err); |
|
759 |
} |
|
760 |
||
789 | 761 |
/* |
762 |
* Lookup entry point for the 'snapshot' directory. Try to open the |
|
763 |
* snapshot if it exist, creating the pseudo filesystem vnode as necessary. |
|
764 |
* Perform a mount of the associated dataset on top of the vnode. |
|
765 |
*/ |
|
766 |
/* ARGSUSED */ |
|
767 |
static int |
|
768 |
zfsctl_snapdir_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp, |
|
5331 | 769 |
int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, |
770 |
int *direntflags, pathname_t *realpnp) |
|
789 | 771 |
{ |
772 |
zfsctl_snapdir_t *sdp = dvp->v_data; |
|
773 |
objset_t *snap; |
|
774 |
char snapname[MAXNAMELEN]; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
775 |
char real[MAXNAMELEN]; |
789 | 776 |
char *mountpoint; |
777 |
zfs_snapentry_t *sep, search; |
|
778 |
struct mounta margs; |
|
779 |
vfs_t *vfsp; |
|
780 |
size_t mountpoint_len; |
|
781 |
avl_index_t where; |
|
782 |
zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data; |
|
783 |
int err; |
|
784 |
||
5331 | 785 |
/* |
786 |
* No extended attributes allowed under .zfs |
|
787 |
*/ |
|
788 |
if (flags & LOOKUP_XATTR) |
|
789 |
return (EINVAL); |
|
790 |
||
789 | 791 |
ASSERT(dvp->v_type == VDIR); |
792 |
||
793 |
/* |
|
794 |
* If we get a recursive call, that means we got called |
|
795 |
* from the domount() code while it was trying to look up the |
|
796 |
* spec (which looks like a local path for zfs). We need to |
|
797 |
* add some flag to domount() to tell it not to do this lookup. |
|
798 |
*/ |
|
799 |
if (MUTEX_HELD(&sdp->sd_lock)) |
|
800 |
return (ENOENT); |
|
801 |
||
802 |
ZFS_ENTER(zfsvfs); |
|
803 |
||
9214
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
804 |
if (gfs_lookup_dot(vpp, dvp, zfsvfs->z_ctldir, nm) == 0) { |
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
805 |
ZFS_EXIT(zfsvfs); |
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
806 |
return (0); |
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
807 |
} |
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
808 |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
809 |
if (flags & FIGNORECASE) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
810 |
boolean_t conflict = B_FALSE; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
811 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
812 |
err = dmu_snapshot_realname(zfsvfs->z_os, nm, real, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
813 |
MAXNAMELEN, &conflict); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
814 |
if (err == 0) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
815 |
nm = real; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
816 |
} else if (err != ENOTSUP) { |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
817 |
ZFS_EXIT(zfsvfs); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
818 |
return (err); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
819 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
820 |
if (realpnp) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
821 |
(void) strlcpy(realpnp->pn_buf, nm, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
822 |
realpnp->pn_bufsize); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
823 |
if (conflict && direntflags) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
824 |
*direntflags = ED_CASE_CONFLICT; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
825 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
826 |
|
789 | 827 |
mutex_enter(&sdp->sd_lock); |
828 |
search.se_name = (char *)nm; |
|
829 |
if ((sep = avl_find(&sdp->sd_snaps, &search, &where)) != NULL) { |
|
830 |
*vpp = sep->se_root; |
|
831 |
VN_HOLD(*vpp); |
|
1589
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
832 |
err = traverse(vpp); |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
833 |
if (err) { |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
834 |
VN_RELE(*vpp); |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
835 |
*vpp = NULL; |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
836 |
} else if (*vpp == sep->se_root) { |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
837 |
/* |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
838 |
* The snapshot was unmounted behind our backs, |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
839 |
* try to remount it. |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
840 |
*/ |
789 | 841 |
goto domount; |
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
842 |
} else { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
843 |
/* |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
844 |
* VROOT was set during the traverse call. We need |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
845 |
* to clear it since we're pretending to be part |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
846 |
* of our parent's vfs. |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
847 |
*/ |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
848 |
(*vpp)->v_flag &= ~VROOT; |
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
849 |
} |
789 | 850 |
mutex_exit(&sdp->sd_lock); |
851 |
ZFS_EXIT(zfsvfs); |
|
1589
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
852 |
return (err); |
789 | 853 |
} |
854 |
||
855 |
/* |
|
856 |
* The requested snapshot is not currently mounted, look it up. |
|
857 |
*/ |
|
1154 | 858 |
err = zfsctl_snapshot_zname(dvp, nm, MAXNAMELEN, snapname); |
859 |
if (err) { |
|
860 |
mutex_exit(&sdp->sd_lock); |
|
861 |
ZFS_EXIT(zfsvfs); |
|
7229
7836e02dc984
6731778 'ls *' in empty zfs snapshot directory returns EILSEQ vs. ENOENT we get in other empty directories
marks
parents:
6689
diff
changeset
|
862 |
/* |
7836e02dc984
6731778 'ls *' in empty zfs snapshot directory returns EILSEQ vs. ENOENT we get in other empty directories
marks
parents:
6689
diff
changeset
|
863 |
* handle "ls *" or "?" in a graceful manner, |
7836e02dc984
6731778 'ls *' in empty zfs snapshot directory returns EILSEQ vs. ENOENT we get in other empty directories
marks
parents:
6689
diff
changeset
|
864 |
* forcing EILSEQ to ENOENT. |
7836e02dc984
6731778 'ls *' in empty zfs snapshot directory returns EILSEQ vs. ENOENT we get in other empty directories
marks
parents:
6689
diff
changeset
|
865 |
* Since shell ultimately passes "*" or "?" as name to lookup |
7836e02dc984
6731778 'ls *' in empty zfs snapshot directory returns EILSEQ vs. ENOENT we get in other empty directories
marks
parents:
6689
diff
changeset
|
866 |
*/ |
7836e02dc984
6731778 'ls *' in empty zfs snapshot directory returns EILSEQ vs. ENOENT we get in other empty directories
marks
parents:
6689
diff
changeset
|
867 |
return (err == EILSEQ ? ENOENT : err); |
1154 | 868 |
} |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
869 |
if (dmu_objset_hold(snapname, FTAG, &snap) != 0) { |
789 | 870 |
mutex_exit(&sdp->sd_lock); |
871 |
ZFS_EXIT(zfsvfs); |
|
872 |
return (ENOENT); |
|
873 |
} |
|
874 |
||
875 |
sep = kmem_alloc(sizeof (zfs_snapentry_t), KM_SLEEP); |
|
876 |
sep->se_name = kmem_alloc(strlen(nm) + 1, KM_SLEEP); |
|
877 |
(void) strcpy(sep->se_name, nm); |
|
878 |
*vpp = sep->se_root = zfsctl_snapshot_mknode(dvp, dmu_objset_id(snap)); |
|
879 |
avl_insert(&sdp->sd_snaps, sep, where); |
|
880 |
||
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
881 |
dmu_objset_rele(snap, FTAG); |
789 | 882 |
domount: |
883 |
mountpoint_len = strlen(refstr_value(dvp->v_vfsp->vfs_mntpt)) + |
|
884 |
strlen("/.zfs/snapshot/") + strlen(nm) + 1; |
|
885 |
mountpoint = kmem_alloc(mountpoint_len, KM_SLEEP); |
|
886 |
(void) snprintf(mountpoint, mountpoint_len, "%s/.zfs/snapshot/%s", |
|
887 |
refstr_value(dvp->v_vfsp->vfs_mntpt), nm); |
|
888 |
||
889 |
margs.spec = snapname; |
|
890 |
margs.dir = mountpoint; |
|
891 |
margs.flags = MS_SYSSPACE | MS_NOMNTTAB; |
|
892 |
margs.fstype = "zfs"; |
|
893 |
margs.dataptr = NULL; |
|
894 |
margs.datalen = 0; |
|
895 |
margs.optptr = NULL; |
|
896 |
margs.optlen = 0; |
|
897 |
||
898 |
err = domount("zfs", &margs, *vpp, kcred, &vfsp); |
|
899 |
kmem_free(mountpoint, mountpoint_len); |
|
900 |
||
816
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
901 |
if (err == 0) { |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
902 |
/* |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
903 |
* Return the mounted root rather than the covered mount point. |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
904 |
* Takes the GFS vnode at .zfs/snapshot/<snapname> and returns |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
905 |
* the ZFS vnode mounted on top of the GFS node. This ZFS |
9214
8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy
Chris Kirby <chris.kirby@sun.com>
parents:
9030
diff
changeset
|
906 |
* vnode is the root of the newly created vfsp. |
816
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
907 |
*/ |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
908 |
VFS_RELE(vfsp); |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
909 |
err = traverse(vpp); |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
910 |
} |
789 | 911 |
|
816
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
912 |
if (err == 0) { |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
913 |
/* |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
914 |
* Fix up the root vnode mounted on .zfs/snapshot/<snapname>. |
4736
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4543
diff
changeset
|
915 |
* |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4543
diff
changeset
|
916 |
* This is where we lie about our v_vfsp in order to |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
917 |
* make .zfs/snapshot/<snapname> accessible over NFS |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
918 |
* without requiring manual mounts of <snapname>. |
816
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
919 |
*/ |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
920 |
ASSERT(VTOZ(*vpp)->z_zfsvfs != zfsvfs); |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
921 |
VTOZ(*vpp)->z_zfsvfs->z_parent = zfsvfs; |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
922 |
(*vpp)->v_vfsp = zfsvfs->z_vfs; |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
923 |
(*vpp)->v_flag &= ~VROOT; |
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
924 |
} |
789 | 925 |
mutex_exit(&sdp->sd_lock); |
926 |
ZFS_EXIT(zfsvfs); |
|
927 |
||
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
928 |
/* |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
929 |
* If we had an error, drop our hold on the vnode and |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
930 |
* zfsctl_snapshot_inactive() will clean up. |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
931 |
*/ |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
932 |
if (err) { |
816
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
933 |
VN_RELE(*vpp); |
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
934 |
*vpp = NULL; |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
935 |
} |
816
4a2d51f7b961
6344201 Assertion failed: err == 0 (0x1 == 0x0), file: ../../common/fs/zfs/zfs_ctldir.c, line: 659
maybee
parents:
789
diff
changeset
|
936 |
return (err); |
789 | 937 |
} |
938 |
||
939 |
/* ARGSUSED */ |
|
940 |
static int |
|
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
941 |
zfsctl_shares_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
942 |
int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
943 |
int *direntflags, pathname_t *realpnp) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
944 |
{ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
945 |
zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
946 |
znode_t *dzp; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
947 |
int error; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
948 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
949 |
ZFS_ENTER(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
950 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
951 |
if (gfs_lookup_dot(vpp, dvp, zfsvfs->z_ctldir, nm) == 0) { |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
952 |
ZFS_EXIT(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
953 |
return (0); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
954 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
955 |
|
9030
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
956 |
if (zfsvfs->z_shares_dir == 0) { |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
957 |
ZFS_EXIT(zfsvfs); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
958 |
return (ENOTSUP); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
959 |
} |
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
960 |
if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
961 |
error = VOP_LOOKUP(ZTOV(dzp), nm, vpp, pnp, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
962 |
flags, rdir, cr, ct, direntflags, realpnp); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
963 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
964 |
VN_RELE(ZTOV(dzp)); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
965 |
ZFS_EXIT(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
966 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
967 |
return (error); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
968 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
969 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
970 |
/* ARGSUSED */ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
971 |
static int |
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
972 |
zfsctl_snapdir_readdir_cb(vnode_t *vp, void *dp, int *eofp, |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
973 |
offset_t *offp, offset_t *nextp, void *data, int flags) |
789 | 974 |
{ |
975 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
|
976 |
char snapname[MAXNAMELEN]; |
|
977 |
uint64_t id, cookie; |
|
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
978 |
boolean_t case_conflict; |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
979 |
int error; |
789 | 980 |
|
981 |
ZFS_ENTER(zfsvfs); |
|
982 |
||
983 |
cookie = *offp; |
|
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
984 |
error = dmu_snapshot_list_next(zfsvfs->z_os, MAXNAMELEN, snapname, &id, |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
985 |
&cookie, &case_conflict); |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
986 |
if (error) { |
789 | 987 |
ZFS_EXIT(zfsvfs); |
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
988 |
if (error == ENOENT) { |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
989 |
*eofp = 1; |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
990 |
return (0); |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
991 |
} |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
992 |
return (error); |
789 | 993 |
} |
994 |
||
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
995 |
if (flags & V_RDDIR_ENTFLAGS) { |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
996 |
edirent_t *eodp = dp; |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
997 |
|
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
998 |
(void) strcpy(eodp->ed_name, snapname); |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
999 |
eodp->ed_ino = ZFSCTL_INO_SNAP(id); |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1000 |
eodp->ed_eflags = case_conflict ? ED_CASE_CONFLICT : 0; |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1001 |
} else { |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1002 |
struct dirent64 *odp = dp; |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1003 |
|
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1004 |
(void) strcpy(odp->d_name, snapname); |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1005 |
odp->d_ino = ZFSCTL_INO_SNAP(id); |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5331
diff
changeset
|
1006 |
} |
789 | 1007 |
*nextp = cookie; |
1008 |
||
1009 |
ZFS_EXIT(zfsvfs); |
|
1010 |
||
1011 |
return (0); |
|
1012 |
} |
|
1013 |
||
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1014 |
/* ARGSUSED */ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1015 |
static int |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1016 |
zfsctl_shares_readdir(vnode_t *vp, uio_t *uiop, cred_t *cr, int *eofp, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1017 |
caller_context_t *ct, int flags) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1018 |
{ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1019 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1020 |
znode_t *dzp; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1021 |
int error; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1022 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1023 |
ZFS_ENTER(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1024 |
|
9030
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1025 |
if (zfsvfs->z_shares_dir == 0) { |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1026 |
ZFS_EXIT(zfsvfs); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1027 |
return (ENOTSUP); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1028 |
} |
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1029 |
if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) { |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1030 |
error = VOP_READDIR(ZTOV(dzp), uiop, cr, eofp, ct, flags); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1031 |
VN_RELE(ZTOV(dzp)); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1032 |
} else { |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1033 |
*eofp = 1; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1034 |
error = ENOENT; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1035 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1036 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1037 |
ZFS_EXIT(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1038 |
return (error); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1039 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1040 |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1041 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1042 |
* pvp is the '.zfs' directory (zfsctl_node_t). |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1043 |
* Creates vp, which is '.zfs/snapshot' (zfsctl_snapdir_t). |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1044 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1045 |
* This function is the callback to create a GFS vnode for '.zfs/snapshot' |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1046 |
* when a lookup is performed on .zfs for "snapshot". |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1047 |
*/ |
789 | 1048 |
vnode_t * |
1049 |
zfsctl_mknode_snapdir(vnode_t *pvp) |
|
1050 |
{ |
|
1051 |
vnode_t *vp; |
|
1052 |
zfsctl_snapdir_t *sdp; |
|
1053 |
||
1054 |
vp = gfs_dir_create(sizeof (zfsctl_snapdir_t), pvp, |
|
1055 |
zfsctl_ops_snapdir, NULL, NULL, MAXNAMELEN, |
|
1056 |
zfsctl_snapdir_readdir_cb, NULL); |
|
1057 |
sdp = vp->v_data; |
|
1058 |
sdp->sd_node.zc_id = ZFSCTL_INO_SNAPDIR; |
|
1571
5aae3c7637de
6349516 surprise: .zfs & .zfs/snapshot keep changing
ek110237
parents:
1566
diff
changeset
|
1059 |
sdp->sd_node.zc_cmtime = ((zfsctl_node_t *)pvp->v_data)->zc_cmtime; |
789 | 1060 |
mutex_init(&sdp->sd_lock, NULL, MUTEX_DEFAULT, NULL); |
1061 |
avl_create(&sdp->sd_snaps, snapentry_compare, |
|
1062 |
sizeof (zfs_snapentry_t), offsetof(zfs_snapentry_t, se_node)); |
|
1063 |
return (vp); |
|
1064 |
} |
|
1065 |
||
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1066 |
vnode_t * |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1067 |
zfsctl_mknode_shares(vnode_t *pvp) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1068 |
{ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1069 |
vnode_t *vp; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1070 |
zfsctl_node_t *sdp; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1071 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1072 |
vp = gfs_dir_create(sizeof (zfsctl_node_t), pvp, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1073 |
zfsctl_ops_shares, NULL, NULL, MAXNAMELEN, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1074 |
NULL, NULL); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1075 |
sdp = vp->v_data; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1076 |
sdp->zc_cmtime = ((zfsctl_node_t *)pvp->v_data)->zc_cmtime; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1077 |
return (vp); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1078 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1079 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1080 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1081 |
/* ARGSUSED */ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1082 |
static int |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1083 |
zfsctl_shares_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1084 |
caller_context_t *ct) |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1085 |
{ |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1086 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1087 |
znode_t *dzp; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1088 |
int error; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1089 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1090 |
ZFS_ENTER(zfsvfs); |
9030
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1091 |
if (zfsvfs->z_shares_dir == 0) { |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1092 |
ZFS_EXIT(zfsvfs); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1093 |
return (ENOTSUP); |
243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
8845
diff
changeset
|
1094 |
} |
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1095 |
if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) { |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1096 |
error = VOP_GETATTR(ZTOV(dzp), vap, flags, cr, ct); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1097 |
VN_RELE(ZTOV(dzp)); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1098 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1099 |
ZFS_EXIT(zfsvfs); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1100 |
return (error); |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1101 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1102 |
|
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1103 |
} |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1104 |
|
789 | 1105 |
/* ARGSUSED */ |
1106 |
static int |
|
5331 | 1107 |
zfsctl_snapdir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, |
1108 |
caller_context_t *ct) |
|
789 | 1109 |
{ |
1110 |
zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; |
|
1111 |
zfsctl_snapdir_t *sdp = vp->v_data; |
|
1112 |
||
1113 |
ZFS_ENTER(zfsvfs); |
|
1114 |
zfsctl_common_getattr(vp, vap); |
|
1115 |
vap->va_nodeid = gfs_file_inode(vp); |
|
1116 |
vap->va_nlink = vap->va_size = avl_numnodes(&sdp->sd_snaps) + 2; |
|
10373
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1117 |
vap->va_ctime = vap->va_mtime = dmu_objset_snap_cmtime(zfsvfs->z_os); |
789 | 1118 |
ZFS_EXIT(zfsvfs); |
1119 |
||
1120 |
return (0); |
|
1121 |
} |
|
1122 |
||
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1123 |
/* ARGSUSED */ |
789 | 1124 |
static void |
5331 | 1125 |
zfsctl_snapdir_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct) |
789 | 1126 |
{ |
1127 |
zfsctl_snapdir_t *sdp = vp->v_data; |
|
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1128 |
void *private; |
789 | 1129 |
|
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1130 |
private = gfs_dir_inactive(vp); |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1131 |
if (private != NULL) { |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1132 |
ASSERT(avl_numnodes(&sdp->sd_snaps) == 0); |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1133 |
mutex_destroy(&sdp->sd_lock); |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1134 |
avl_destroy(&sdp->sd_snaps); |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1135 |
kmem_free(private, sizeof (zfsctl_snapdir_t)); |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1136 |
} |
789 | 1137 |
} |
1138 |
||
1139 |
static const fs_operation_def_t zfsctl_tops_snapdir[] = { |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1140 |
{ VOPNAME_OPEN, { .vop_open = zfsctl_common_open } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1141 |
{ VOPNAME_CLOSE, { .vop_close = zfsctl_common_close } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1142 |
{ VOPNAME_IOCTL, { .error = fs_inval } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1143 |
{ VOPNAME_GETATTR, { .vop_getattr = zfsctl_snapdir_getattr } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1144 |
{ VOPNAME_ACCESS, { .vop_access = zfsctl_common_access } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1145 |
{ VOPNAME_RENAME, { .vop_rename = zfsctl_snapdir_rename } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1146 |
{ VOPNAME_RMDIR, { .vop_rmdir = zfsctl_snapdir_remove } }, |
4543 | 1147 |
{ VOPNAME_MKDIR, { .vop_mkdir = zfsctl_snapdir_mkdir } }, |
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1148 |
{ VOPNAME_READDIR, { .vop_readdir = gfs_vop_readdir } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1149 |
{ VOPNAME_LOOKUP, { .vop_lookup = zfsctl_snapdir_lookup } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1150 |
{ VOPNAME_SEEK, { .vop_seek = fs_seek } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1151 |
{ VOPNAME_INACTIVE, { .vop_inactive = zfsctl_snapdir_inactive } }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1152 |
{ VOPNAME_FID, { .vop_fid = zfsctl_common_fid } }, |
789 | 1153 |
{ NULL } |
1154 |
}; |
|
1155 |
||
8845
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1156 |
static const fs_operation_def_t zfsctl_tops_shares[] = { |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1157 |
{ VOPNAME_OPEN, { .vop_open = zfsctl_common_open } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1158 |
{ VOPNAME_CLOSE, { .vop_close = zfsctl_common_close } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1159 |
{ VOPNAME_IOCTL, { .error = fs_inval } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1160 |
{ VOPNAME_GETATTR, { .vop_getattr = zfsctl_shares_getattr } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1161 |
{ VOPNAME_ACCESS, { .vop_access = zfsctl_common_access } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1162 |
{ VOPNAME_READDIR, { .vop_readdir = zfsctl_shares_readdir } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1163 |
{ VOPNAME_LOOKUP, { .vop_lookup = zfsctl_shares_lookup } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1164 |
{ VOPNAME_SEEK, { .vop_seek = fs_seek } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1165 |
{ VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1166 |
{ VOPNAME_FID, { .vop_fid = zfsctl_shares_fid } }, |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1167 |
{ NULL } |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1168 |
}; |
91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents:
8547
diff
changeset
|
1169 |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1170 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1171 |
* pvp is the GFS vnode '.zfs/snapshot'. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1172 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1173 |
* This creates a GFS node under '.zfs/snapshot' representing each |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1174 |
* snapshot. This newly created GFS node is what we mount snapshot |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1175 |
* vfs_t's ontop of. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1176 |
*/ |
789 | 1177 |
static vnode_t * |
1178 |
zfsctl_snapshot_mknode(vnode_t *pvp, uint64_t objset) |
|
1179 |
{ |
|
1180 |
vnode_t *vp; |
|
1181 |
zfsctl_node_t *zcp; |
|
1182 |
||
1183 |
vp = gfs_dir_create(sizeof (zfsctl_node_t), pvp, |
|
1184 |
zfsctl_ops_snapshot, NULL, NULL, MAXNAMELEN, NULL, NULL); |
|
1185 |
zcp = vp->v_data; |
|
1186 |
zcp->zc_id = objset; |
|
1187 |
||
1188 |
return (vp); |
|
1189 |
} |
|
1190 |
||
1191 |
static void |
|
5331 | 1192 |
zfsctl_snapshot_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct) |
789 | 1193 |
{ |
1194 |
zfsctl_snapdir_t *sdp; |
|
1195 |
zfs_snapentry_t *sep, *next; |
|
1196 |
vnode_t *dvp; |
|
1197 |
||
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6068
diff
changeset
|
1198 |
VERIFY(gfs_dir_lookup(vp, "..", &dvp, cr, 0, NULL, NULL) == 0); |
789 | 1199 |
sdp = dvp->v_data; |
1200 |
||
1201 |
mutex_enter(&sdp->sd_lock); |
|
1202 |
||
1203 |
if (vp->v_count > 1) { |
|
1204 |
mutex_exit(&sdp->sd_lock); |
|
1205 |
return; |
|
1206 |
} |
|
1207 |
ASSERT(!vn_ismntpt(vp)); |
|
1208 |
||
1209 |
sep = avl_first(&sdp->sd_snaps); |
|
1210 |
while (sep != NULL) { |
|
1211 |
next = AVL_NEXT(&sdp->sd_snaps, sep); |
|
1212 |
||
1213 |
if (sep->se_root == vp) { |
|
1214 |
avl_remove(&sdp->sd_snaps, sep); |
|
1215 |
kmem_free(sep->se_name, strlen(sep->se_name) + 1); |
|
1216 |
kmem_free(sep, sizeof (zfs_snapentry_t)); |
|
1217 |
break; |
|
1218 |
} |
|
1219 |
sep = next; |
|
1220 |
} |
|
1221 |
ASSERT(sep != NULL); |
|
1222 |
||
1223 |
mutex_exit(&sdp->sd_lock); |
|
1224 |
VN_RELE(dvp); |
|
1225 |
||
1566
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1226 |
/* |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1227 |
* Dispose of the vnode for the snapshot mount point. |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1228 |
* This is safe to do because once this entry has been removed |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1229 |
* from the AVL tree, it can't be found again, so cannot become |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1230 |
* "active". If we lookup the same name again we will end up |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1231 |
* creating a new vnode. |
93e41df9efa5
6355162 'zfs restore -d' should not succeed upon a volume
maybee
parents:
1512
diff
changeset
|
1232 |
*/ |
5331 | 1233 |
gfs_vop_inactive(vp, cr, ct); |
789 | 1234 |
} |
1235 |
||
1236 |
||
1237 |
/* |
|
1238 |
* These VP's should never see the light of day. They should always |
|
1239 |
* be covered. |
|
1240 |
*/ |
|
1241 |
static const fs_operation_def_t zfsctl_tops_snapshot[] = { |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
2676
diff
changeset
|
1242 |
VOPNAME_INACTIVE, { .vop_inactive = zfsctl_snapshot_inactive }, |
789 | 1243 |
NULL, NULL |
1244 |
}; |
|
1245 |
||
1246 |
int |
|
1247 |
zfsctl_lookup_objset(vfs_t *vfsp, uint64_t objsetid, zfsvfs_t **zfsvfsp) |
|
1248 |
{ |
|
1249 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
1250 |
vnode_t *dvp, *vp; |
|
1251 |
zfsctl_snapdir_t *sdp; |
|
1252 |
zfsctl_node_t *zcp; |
|
1253 |
zfs_snapentry_t *sep; |
|
1254 |
int error; |
|
1255 |
||
1256 |
ASSERT(zfsvfs->z_ctldir != NULL); |
|
1257 |
error = zfsctl_root_lookup(zfsvfs->z_ctldir, "snapshot", &dvp, |
|
5331 | 1258 |
NULL, 0, NULL, kcred, NULL, NULL, NULL); |
789 | 1259 |
if (error != 0) |
1260 |
return (error); |
|
1261 |
sdp = dvp->v_data; |
|
1262 |
||
1263 |
mutex_enter(&sdp->sd_lock); |
|
1264 |
sep = avl_first(&sdp->sd_snaps); |
|
1265 |
while (sep != NULL) { |
|
1266 |
vp = sep->se_root; |
|
1267 |
zcp = vp->v_data; |
|
1268 |
if (zcp->zc_id == objsetid) |
|
1269 |
break; |
|
1270 |
||
1271 |
sep = AVL_NEXT(&sdp->sd_snaps, sep); |
|
1272 |
} |
|
1273 |
||
1274 |
if (sep != NULL) { |
|
1275 |
VN_HOLD(vp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1276 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1277 |
* Return the mounted root rather than the covered mount point. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1278 |
* Takes the GFS vnode at .zfs/snapshot/<snapshot objsetid> |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1279 |
* and returns the ZFS vnode mounted on top of the GFS node. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1280 |
* This ZFS vnode is the root of the vfs for objset 'objsetid'. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4736
diff
changeset
|
1281 |
*/ |
789 | 1282 |
error = traverse(&vp); |
1589
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
1283 |
if (error == 0) { |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
1284 |
if (vp == sep->se_root) |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
1285 |
error = EINVAL; |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
1286 |
else |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
1287 |
*zfsvfsp = VTOZ(vp)->z_zfsvfs; |
64c230a17c47
6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents:
1572
diff
changeset
|
1288 |
} |
1572
0469a7fd3981
6390579 panic: recursive mutex_enter, at zfs:zfsctl_snapshot_inactive
nd150628
parents:
1571
diff
changeset
|
1289 |
mutex_exit(&sdp->sd_lock); |
789 | 1290 |
VN_RELE(vp); |
1291 |
} else { |
|
1292 |
error = EINVAL; |
|
1572
0469a7fd3981
6390579 panic: recursive mutex_enter, at zfs:zfsctl_snapshot_inactive
nd150628
parents:
1571
diff
changeset
|
1293 |
mutex_exit(&sdp->sd_lock); |
789 | 1294 |
} |
1295 |
||
1296 |
VN_RELE(dvp); |
|
1297 |
||
1298 |
return (error); |
|
1299 |
} |
|
1300 |
||
1301 |
/* |
|
1302 |
* Unmount any snapshots for the given filesystem. This is called from |
|
1303 |
* zfs_umount() - if we have a ctldir, then go through and unmount all the |
|
1304 |
* snapshots. |
|
1305 |
*/ |
|
1306 |
int |
|
1307 |
zfsctl_umount_snapshots(vfs_t *vfsp, int fflags, cred_t *cr) |
|
1308 |
{ |
|
1309 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1310 |
vnode_t *dvp; |
789 | 1311 |
zfsctl_snapdir_t *sdp; |
1312 |
zfs_snapentry_t *sep, *next; |
|
1313 |
int error; |
|
1314 |
||
1315 |
ASSERT(zfsvfs->z_ctldir != NULL); |
|
1316 |
error = zfsctl_root_lookup(zfsvfs->z_ctldir, "snapshot", &dvp, |
|
5331 | 1317 |
NULL, 0, NULL, cr, NULL, NULL, NULL); |
789 | 1318 |
if (error != 0) |
1319 |
return (error); |
|
1320 |
sdp = dvp->v_data; |
|
1321 |
||
1322 |
mutex_enter(&sdp->sd_lock); |
|
1323 |
||
1324 |
sep = avl_first(&sdp->sd_snaps); |
|
1325 |
while (sep != NULL) { |
|
1326 |
next = AVL_NEXT(&sdp->sd_snaps, sep); |
|
1327 |
||
1328 |
/* |
|
1329 |
* If this snapshot is not mounted, then it must |
|
1330 |
* have just been unmounted by somebody else, and |
|
1331 |
* will be cleaned up by zfsctl_snapdir_inactive(). |
|
1332 |
*/ |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1333 |
if (vn_ismntpt(sep->se_root)) { |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1334 |
avl_remove(&sdp->sd_snaps, sep); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1335 |
error = zfsctl_unmount_snap(sep, fflags, cr); |
789 | 1336 |
if (error) { |
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1337 |
avl_add(&sdp->sd_snaps, sep); |
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1338 |
break; |
789 | 1339 |
} |
1340 |
} |
|
1341 |
sep = next; |
|
1342 |
} |
|
6068
44728d72cfec
6564619 panic after a filesystem with snapshots that have files open was destroyed or umounted
ck153898
parents:
5663
diff
changeset
|
1343 |
|
789 | 1344 |
mutex_exit(&sdp->sd_lock); |
1345 |
VN_RELE(dvp); |
|
1346 |
||
1347 |
return (error); |
|
1348 |
} |