4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
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
22 /*
23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2016 Joyent, Inc.
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 #ifndef _SYS_VNODE_H
41 #define _SYS_VNODE_H
42
43 #include <sys/types.h>
44 #include <sys/t_lock.h>
204 * v_filocks
205 *
206 * IMPORTANT NOTE:
207 *
208 * The following vnode fields are considered public and may safely be
209 * accessed by file systems or other consumers:
210 *
211 * v_lock
212 * v_flag
213 * v_count
214 * v_data
215 * v_vfsp
216 * v_stream
217 * v_type
218 * v_rdev
219 *
220 * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD.
221 * In particular, file systems should not access other fields; they may
222 * change or even be removed. The functionality which was once provided
223 * by these fields is available through vn_* functions.
224 *
225 * VNODE PATH THEORY:
226 * In each vnode, the v_path field holds a cached version of the canonical
227 * filesystem path which that node represents. Because vnodes lack contextual
228 * information about their own name or position in the VFS hierarchy, this path
229 * must be calculated when the vnode is instantiated by operations such as
230 * fop_create, fop_lookup, or fop_mkdir. During said operations, both the
231 * parent vnode (and its cached v_path) and future name are known, so the
232 * v_path of the resulting object can easily be set.
233 *
234 * The caching nature of v_path is complicated in the face of directory
235 * renames. Filesystem drivers are responsible for calling vn_renamepath when
236 * a fop_rename operation succeeds. While the v_path on the renamed vnode will
237 * be updated, existing children of the directory (direct, or at deeper levels)
238 * will now possess v_path caches which are stale.
239 *
240 * It is expensive (and for non-directories, impossible) to recalculate stale
241 * v_path entries during operations such as vnodetopath. The best time during
242 * which to correct such wrongs is the same as when v_path is first
243 * initialized: during fop_create/fop_lookup/fop_mkdir/etc, where adequate
244 * context is available to generate the current path.
245 *
246 * In order to quickly detect stale v_path entries (without full lookup
247 * verification) to trigger a v_path update, the v_path_stamp field has been
248 * added to vnode_t. As part of successful fop_create/fop_lookup/fop_mkdir
249 * operations, where the name and parent vnode are available, the following
250 * rules are used to determine updates to the child:
251 *
252 * 1. If the parent lacks a v_path, clear any existing v_path and v_path_stamp
253 * on the child. Until the parent v_path is refreshed to a valid state, the
254 * child v_path must be considered invalid too.
255 *
256 * 2. If the child lacks a v_path (implying v_path_stamp == 0), it inherits the
257 * v_path_stamp value from its parent and its v_path is updated.
258 *
259 * 3. If the child v_path_stamp is less than v_path_stamp in the parent, it is
260 * an indication that the child v_path is stale. The v_path is updated and
261 * v_path_stamp in the child is set to the current hrtime().
262 *
263 * It does _not_ inherit the parent v_path_stamp in order to propagate the
264 * the time of v_path invalidation through the directory structure. This
265 * prevents concurrent invalidations (operating with a now-incorrect v_path)
266 * at deeper levels in the tree from persisting.
267 *
268 * 4. If the child v_path_stamp is greater or equal to the parent, no action
269 * needs to be taken.
270 *
271 * Note that fop_rename operations do not follow this ruleset. They perform an
272 * explicit update of v_path and v_path_stamp (setting it to the current time)
273 *
274 * With these constraints in place, v_path invalidations and updates should
275 * proceed in a timely manner as vnodes are accessed. While there still are
276 * limited cases where vnodetopath operations will fail, the risk is minimized.
277 */
278
279 struct fem_head; /* from fem.h */
280
281 typedef struct vnode {
282 kmutex_t v_lock; /* protects vnode fields */
283 uint_t v_flag; /* vnode flags (see below) */
284 uint_t v_count; /* reference count */
285 void *v_data; /* private data for fs */
286 struct vfs *v_vfsp; /* ptr to containing VFS */
287 struct stdata *v_stream; /* associated stream */
288 enum vtype v_type; /* vnode type */
289 dev_t v_rdev; /* device (VCHR, VBLK) */
290
291 /* PRIVATE FIELDS BELOW - DO NOT USE */
292
293 struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */
294 struct vnodeops *v_op; /* vnode operations */
295 struct page *v_pages; /* vnode pages list */
296 struct filock *v_filocks; /* ptr to filock list */
297 struct shrlocklist *v_shrlocks; /* ptr to shrlock list */
298 krwlock_t v_nbllock; /* sync for NBMAND locks */
299 kcondvar_t v_cv; /* synchronize locking */
300 void *v_locality; /* hook for locality info */
301 struct fem_head *v_femhead; /* fs monitoring */
302 char *v_path; /* cached path */
303 hrtime_t v_path_stamp; /* timestamp for cached path */
304 uint_t v_rdcnt; /* open for read count (VREG only) */
305 uint_t v_wrcnt; /* open for write count (VREG only) */
306 u_longlong_t v_mmap_read; /* mmap read count */
307 u_longlong_t v_mmap_write; /* mmap write count */
308 void *v_mpssdata; /* info for large page mappings */
309 void *v_fopdata; /* list of file ops event watches */
310 kmutex_t v_vsd_lock; /* protects v_vsd field */
311 struct vsd_node *v_vsd; /* vnode specific data */
312 struct vnode *v_xattrdir; /* unnamed extended attr dir (GFS) */
313 uint_t v_count_dnlc; /* dnlc reference count */
314 } vnode_t;
315
316 #define IS_DEVVP(vp) \
317 ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
318
319 #define VNODE_ALIGN 64
320 /* Count of low-order 0 bits in a vnode *, based on size and alignment. */
321 #if defined(_LP64)
322 #define VNODE_ALIGN_LOG2 8
323 #else
1330 enum rm dirflag);
1331 int vn_compare(vnode_t *vp1, vnode_t *vp2);
1332 int vn_vfswlock(struct vnode *vp);
1333 int vn_vfswlock_wait(struct vnode *vp);
1334 int vn_vfsrlock(struct vnode *vp);
1335 int vn_vfsrlock_wait(struct vnode *vp);
1336 void vn_vfsunlock(struct vnode *vp);
1337 int vn_vfswlock_held(struct vnode *vp);
1338 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr);
1339 vnode_t *makespecvp(dev_t dev, vtype_t type);
1340 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
1341 void vn_vfslocks_rele(vn_vfslocks_entry_t *);
1342 boolean_t vn_is_reparse(vnode_t *, cred_t *, caller_context_t *);
1343
1344 void vn_copypath(struct vnode *src, struct vnode *dst);
1345 void vn_setpath_str(struct vnode *vp, const char *str, size_t len);
1346 void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp,
1347 const char *path, size_t plen);
1348 void vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len);
1349
1350 /* Private vnode manipulation functions */
1351 void vn_clearpath(vnode_t *, hrtime_t);
1352 void vn_updatepath(vnode_t *, vnode_t *, const char *);
1353
1354
1355 /* Vnode event notification */
1356 void vnevent_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *);
1357 void vnevent_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *);
1358 void vnevent_remove(vnode_t *, vnode_t *, char *, caller_context_t *);
1359 void vnevent_rmdir(vnode_t *, vnode_t *, char *, caller_context_t *);
1360 void vnevent_create(vnode_t *, caller_context_t *);
1361 void vnevent_link(vnode_t *, caller_context_t *);
1362 void vnevent_rename_dest_dir(vnode_t *, vnode_t *, char *,
1363 caller_context_t *ct);
1364 void vnevent_mountedover(vnode_t *, caller_context_t *);
1365 void vnevent_truncate(vnode_t *, caller_context_t *);
1366 int vnevent_support(vnode_t *, caller_context_t *);
1367 void vnevent_pre_rename_src(vnode_t *, vnode_t *, char *,
1368 caller_context_t *);
1369 void vnevent_pre_rename_dest(vnode_t *, vnode_t *, char *,
1370 caller_context_t *);
1371 void vnevent_pre_rename_dest_dir(vnode_t *, vnode_t *, char *,
1372 caller_context_t *);
1373 void vnevent_resize(vnode_t *, caller_context_t *);
1374
1383 * Extensible vnode attribute (xva) routines:
1384 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
1385 * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
1386 */
1387 void xva_init(xvattr_t *);
1388 xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */
1389
1390 void xattr_init(void); /* Initialize vnodeops for xattrs */
1391
1392 /* GFS tunnel for xattrs */
1393 int xattr_dir_lookup(vnode_t *, vnode_t **, int, cred_t *);
1394
1395 /* Reparse Point */
1396 void reparse_point_init(void);
1397
1398 /* Context identification */
1399 u_longlong_t fs_new_caller_id();
1400
1401 int vn_vmpss_usepageio(vnode_t *);
1402
1403 /* Empty v_path placeholder */
1404 extern char *vn_vpath_empty;
1405
1406 /*
1407 * Needed for use of IS_VMODSORT() in kernel.
1408 */
1409 extern uint_t pvn_vmodsort_supported;
1410
1411 #define VN_HOLD(vp) { \
1412 mutex_enter(&(vp)->v_lock); \
1413 (vp)->v_count++; \
1414 mutex_exit(&(vp)->v_lock); \
1415 }
1416
1417 #define VN_RELE(vp) { \
1418 vn_rele(vp); \
1419 }
1420
1421 #define VN_RELE_ASYNC(vp, taskq) { \
1422 vn_rele_async(vp, taskq); \
1423 }
1424
1425 #define VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev) { \
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
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
22 /*
23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 #ifndef _SYS_VNODE_H
41 #define _SYS_VNODE_H
42
43 #include <sys/types.h>
44 #include <sys/t_lock.h>
204 * v_filocks
205 *
206 * IMPORTANT NOTE:
207 *
208 * The following vnode fields are considered public and may safely be
209 * accessed by file systems or other consumers:
210 *
211 * v_lock
212 * v_flag
213 * v_count
214 * v_data
215 * v_vfsp
216 * v_stream
217 * v_type
218 * v_rdev
219 *
220 * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD.
221 * In particular, file systems should not access other fields; they may
222 * change or even be removed. The functionality which was once provided
223 * by these fields is available through vn_* functions.
224 */
225
226 struct fem_head; /* from fem.h */
227
228 typedef struct vnode {
229 kmutex_t v_lock; /* protects vnode fields */
230 uint_t v_flag; /* vnode flags (see below) */
231 uint_t v_count; /* reference count */
232 void *v_data; /* private data for fs */
233 struct vfs *v_vfsp; /* ptr to containing VFS */
234 struct stdata *v_stream; /* associated stream */
235 enum vtype v_type; /* vnode type */
236 dev_t v_rdev; /* device (VCHR, VBLK) */
237
238 /* PRIVATE FIELDS BELOW - DO NOT USE */
239
240 struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */
241 struct vnodeops *v_op; /* vnode operations */
242 struct page *v_pages; /* vnode pages list */
243 struct filock *v_filocks; /* ptr to filock list */
244 struct shrlocklist *v_shrlocks; /* ptr to shrlock list */
245 krwlock_t v_nbllock; /* sync for NBMAND locks */
246 kcondvar_t v_cv; /* synchronize locking */
247 void *v_locality; /* hook for locality info */
248 struct fem_head *v_femhead; /* fs monitoring */
249 char *v_path; /* cached path */
250 uint_t v_rdcnt; /* open for read count (VREG only) */
251 uint_t v_wrcnt; /* open for write count (VREG only) */
252 u_longlong_t v_mmap_read; /* mmap read count */
253 u_longlong_t v_mmap_write; /* mmap write count */
254 void *v_mpssdata; /* info for large page mappings */
255 void *v_fopdata; /* list of file ops event watches */
256 kmutex_t v_vsd_lock; /* protects v_vsd field */
257 struct vsd_node *v_vsd; /* vnode specific data */
258 struct vnode *v_xattrdir; /* unnamed extended attr dir (GFS) */
259 uint_t v_count_dnlc; /* dnlc reference count */
260 } vnode_t;
261
262 #define IS_DEVVP(vp) \
263 ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
264
265 #define VNODE_ALIGN 64
266 /* Count of low-order 0 bits in a vnode *, based on size and alignment. */
267 #if defined(_LP64)
268 #define VNODE_ALIGN_LOG2 8
269 #else
1276 enum rm dirflag);
1277 int vn_compare(vnode_t *vp1, vnode_t *vp2);
1278 int vn_vfswlock(struct vnode *vp);
1279 int vn_vfswlock_wait(struct vnode *vp);
1280 int vn_vfsrlock(struct vnode *vp);
1281 int vn_vfsrlock_wait(struct vnode *vp);
1282 void vn_vfsunlock(struct vnode *vp);
1283 int vn_vfswlock_held(struct vnode *vp);
1284 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr);
1285 vnode_t *makespecvp(dev_t dev, vtype_t type);
1286 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
1287 void vn_vfslocks_rele(vn_vfslocks_entry_t *);
1288 boolean_t vn_is_reparse(vnode_t *, cred_t *, caller_context_t *);
1289
1290 void vn_copypath(struct vnode *src, struct vnode *dst);
1291 void vn_setpath_str(struct vnode *vp, const char *str, size_t len);
1292 void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp,
1293 const char *path, size_t plen);
1294 void vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len);
1295
1296 /* Vnode event notification */
1297 void vnevent_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *);
1298 void vnevent_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *);
1299 void vnevent_remove(vnode_t *, vnode_t *, char *, caller_context_t *);
1300 void vnevent_rmdir(vnode_t *, vnode_t *, char *, caller_context_t *);
1301 void vnevent_create(vnode_t *, caller_context_t *);
1302 void vnevent_link(vnode_t *, caller_context_t *);
1303 void vnevent_rename_dest_dir(vnode_t *, vnode_t *, char *,
1304 caller_context_t *ct);
1305 void vnevent_mountedover(vnode_t *, caller_context_t *);
1306 void vnevent_truncate(vnode_t *, caller_context_t *);
1307 int vnevent_support(vnode_t *, caller_context_t *);
1308 void vnevent_pre_rename_src(vnode_t *, vnode_t *, char *,
1309 caller_context_t *);
1310 void vnevent_pre_rename_dest(vnode_t *, vnode_t *, char *,
1311 caller_context_t *);
1312 void vnevent_pre_rename_dest_dir(vnode_t *, vnode_t *, char *,
1313 caller_context_t *);
1314 void vnevent_resize(vnode_t *, caller_context_t *);
1315
1324 * Extensible vnode attribute (xva) routines:
1325 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
1326 * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
1327 */
1328 void xva_init(xvattr_t *);
1329 xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */
1330
1331 void xattr_init(void); /* Initialize vnodeops for xattrs */
1332
1333 /* GFS tunnel for xattrs */
1334 int xattr_dir_lookup(vnode_t *, vnode_t **, int, cred_t *);
1335
1336 /* Reparse Point */
1337 void reparse_point_init(void);
1338
1339 /* Context identification */
1340 u_longlong_t fs_new_caller_id();
1341
1342 int vn_vmpss_usepageio(vnode_t *);
1343
1344 /*
1345 * Needed for use of IS_VMODSORT() in kernel.
1346 */
1347 extern uint_t pvn_vmodsort_supported;
1348
1349 #define VN_HOLD(vp) { \
1350 mutex_enter(&(vp)->v_lock); \
1351 (vp)->v_count++; \
1352 mutex_exit(&(vp)->v_lock); \
1353 }
1354
1355 #define VN_RELE(vp) { \
1356 vn_rele(vp); \
1357 }
1358
1359 #define VN_RELE_ASYNC(vp, taskq) { \
1360 vn_rele_async(vp, taskq); \
1361 }
1362
1363 #define VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev) { \
|