1 /* $NetBSD: vnode.h,v 1.21 2021/12/17 08:07:12 simonb Exp $ */
2
3 /*
4 * CDDL HEADER START
5 *
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License (the "License").
8 * You may not use this file except in compliance with the License.
9 *
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 *
21 * CDDL HEADER END
22 */
23 /*
24 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. 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 /*-
41 * Copyright (c) 2009 The NetBSD Foundation, Inc.
42 * All rights reserved.
43 *
44 * This code is derived from software contributed to The NetBSD Foundation
45 * by Andrew Doran.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
57 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
58 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
60 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
66 * POSSIBILITY OF SUCH DAMAGE.
67 */
68
69 /*-
70 * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
71 * All rights reserved.
72 *
73 * Redistribution and use in source and binary forms, with or without
74 * modification, are permitted provided that the following conditions
75 * are met:
76 * 1. Redistributions of source code must retain the above copyright
77 * notice, this list of conditions and the following disclaimer.
78 * 2. Redistributions in binary form must reproduce the above copyright
79 * notice, this list of conditions and the following disclaimer in the
80 * documentation and/or other materials provided with the distribution.
81 *
82 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
86 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * SUCH DAMAGE.
93 *
94 * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/vnode.h 308691 2016-11-15 18:22:50Z alc $
95 */
96
97 #ifndef _OPENSOLARIS_SYS_VNODE_H_
98 #define _OPENSOLARIS_SYS_VNODE_H_
99
100 #ifdef _KERNEL
101
102 struct vattr;
103 typedef struct vattr vattr_t;
104 typedef enum vtype vtype_t;
105
106 #include <sys/namei.h>
107 enum symfollow { NO_FOLLOW = NOFOLLOW };
108
109 /*
110 * We'll use the two-parameter FreeBSD VOP_UNLOCK() in ZFS code.
111 */
112
113 #define VOP_UNLOCK __hide_VOP_UNLOCK
114 #include_next <sys/vnode.h>
115 /* verify that the real definition is what we expect */
116 int __hide_VOP_UNLOCK(struct vnode *);
117 #undef VOP_UNLOCK
118
119 int VOP_UNLOCK(struct vnode *, int);
120
121 #include <sys/cred.h>
122 #include <sys/fcntl.h>
123 #include <sys/proc.h>
124 #include <sys/filedesc.h>
125 #include <sys/buf.h>
126
127 #include <sys/vfs_syscalls.h>
128
129 typedef int (**vnodeops_t)(void *);
130
131 #define vop_fid vop_vptofh
132 #define vop_fid_args vop_vptofh_args
133 #define a_fid a_fhp
134
135 #define v_object v_uobj
136
137 struct vop_vptofh_args {
138 struct vnode *a_vp;
139 struct fid *a_fid;
140 };
141
142 #define IS_XATTRDIR(vp) (0)
143
144 #define v_lock v_interlock
145
146 #define SAVENAME 0
147
148 int vn_is_readonly(vnode_t *);
149
150 #define vn_vfswlock(vp) (0)
151 #define vn_vfsunlock(vp) do { } while (0)
152 #define vn_ismntpt(vp) ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
153 #define vn_mountedvfs(vp) ((vp)->v_mountedhere)
154 #define vn_has_cached_data(vp) (((vp)->v_iflag & VI_PAGES) != 0)
155 #define vn_exists(vp) do { } while (0)
156 #define vn_invalid(vp) do { } while (0)
157 #define vn_free(vp) do { } while (0)
158 #define vn_renamepath(tdvp, svp, tnm, lentnm) do { } while (0)
159 #define vn_matchops(vp, vops) ((vp)->v_op == &(vops))
160
161 #define VN_HOLD(v) vref(v)
162 #define VN_RELE(v) \
163 do { \
164 if (vrefcnt(v) == 0) { \
165 printf("VN_RELE(%s,%d): %p unused\n", __FILE__, __LINE__, v); \
166 vprint("VN_RELE", (v)); \
167 panic("VN_RELE"); \
168 } else { \
169 vrele(v); \
170 } \
171 } while (/*CONSTCOND*/0)
172 #define VN_URELE(v) vput(v)
173 #undef VN_RELE_ASYNC
174 #define VN_RELE_ASYNC(vp, taskq) vrele_async((vp))
175 #define VN_RELE_CLEANER(vp, taskq) /* nothing */
176
177 #define vnevent_create(vp, ct) do { } while (0)
178 #define vnevent_link(vp, ct) do { } while (0)
179 #define vnevent_remove(vp, dvp, name, ct) do { } while (0)
180 #define vnevent_rmdir(vp, dvp, name, ct) do { } while (0)
181 #define vnevent_rename_src(vp, dvp, name, ct) do { } while (0)
182 #define vnevent_rename_dest(vp, dvp, name, ct) do { } while (0)
183 #define vnevent_rename_dest_dir(vp, ct) do { } while (0)
184
185 #define specvp(vp, rdev, type, cr) (VN_HOLD(vp), (vp))
186 #define MANDMODE(mode) (0)
187 #define MANDLOCK(vp, mode) (0)
188 #define chklock(vp, op, offset, size, mode, ct) (0)
189 #define cleanlocks(vp, pid, foo) do { } while (0)
190 #define cleanshares(vp, pid) do { } while (0)
191
192 /*
193 * We will use va_spare is place of Solaris' va_mask.
194 * This field is initialized in zfs_setattr().
195 */
196 #define va_mask va_spare
197 /* TODO: va_fileid is shorter than va_nodeid !!! */
198 #define va_nodeid va_fileid
199 /* TODO: This field needs conversion! */
200 #define va_nblocks va_bytes
201 #define va_blksize va_blocksize
202 #define va_seq va_gen
203
204 #define EXCL 0
205
206 #define ACCESSED (AT_ATIME)
207 #define STATE_CHANGED (AT_CTIME)
208 #define CONTENT_MODIFIED (AT_MTIME | AT_CTIME)
209
210 static inline void
vattr_init_mask(vattr_t * vap)211 vattr_init_mask(vattr_t *vap)
212 {
213
214 vap->va_mask = 0;
215
216 if (vap->va_type != VNON)
217 vap->va_mask |= AT_TYPE;
218 if (vap->va_uid != (uid_t)VNOVAL)
219 vap->va_mask |= AT_UID;
220 if (vap->va_gid != (gid_t)VNOVAL)
221 vap->va_mask |= AT_GID;
222 if (vap->va_size != (u_quad_t)VNOVAL)
223 vap->va_mask |= AT_SIZE;
224 if (vap->va_atime.tv_sec != VNOVAL)
225 vap->va_mask |= AT_ATIME;
226 if (vap->va_mtime.tv_sec != VNOVAL)
227 vap->va_mask |= AT_MTIME;
228 if (vap->va_mode != (mode_t)VNOVAL)
229 vap->va_mask |= AT_MODE;
230 if (vap->va_flags != VNOVAL)
231 vap->va_mask |= AT_XVATTR;
232 }
233
234 #define FCREAT O_CREAT
235 #define FTRUNC O_TRUNC
236 #define FSYNC FFSYNC
237 #define FOFFMAX 0x00
238
239 static inline int
zfs_vn_open(const char * pnamep,enum uio_seg seg,int filemode,int createmode,vnode_t ** vpp,enum create crwhy,mode_t umask)240 zfs_vn_open(const char *pnamep, enum uio_seg seg, int filemode, int createmode,
241 vnode_t **vpp, enum create crwhy, mode_t umask)
242 {
243 struct pathbuf *pb;
244 int error;
245
246 ASSERT(seg == UIO_SYSSPACE);
247 ASSERT((filemode & (FWRITE | FCREAT | FTRUNC | FOFFMAX)) != 0);
248 ASSERT(crwhy == CRCREAT);
249 ASSERT(umask == 0);
250
251 pb = pathbuf_create(pnamep);
252 error = vn_open(NULL, pb, 0, filemode, createmode, vpp, NULL, NULL);
253 if (error == 0) {
254 VOP_UNLOCK(*vpp, 0);
255 }
256 pathbuf_destroy(pb);
257 return (error);
258 }
259 #define vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask) \
260 zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
261
262 #define vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, umask, rootvn, unk) \
263 zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
264
265 #define RLIM64_INFINITY 0
266 static inline int
zfs_vn_rdwr(enum uio_rw rw,vnode_t * vp,caddr_t base,ssize_t len,offset_t offset,enum uio_seg seg,int ioflag,uint64_t ulimit,cred_t * cr,ssize_t * residp)267 zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
268 offset_t offset, enum uio_seg seg, int ioflag, uint64_t ulimit, cred_t *cr,
269 ssize_t *residp)
270 {
271 int error;
272 size_t resid;
273
274 ASSERT(rw == UIO_READ || rw == UIO_WRITE);
275 ASSERT(ioflag == 0);
276 ASSERT(ulimit == RLIM64_INFINITY);
277
278 ioflag = IO_UNIT;
279
280 error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr,
281 &resid, curlwp);
282 if (residp != NULL)
283 *residp = (ssize_t)resid;
284 return (error);
285 }
286 #define vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
287 zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
288
289 static inline int
zfs_vop_fsync(vnode_t * vp,int flag,cred_t * cr)290 zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
291 {
292 int error;
293
294 ASSERT(flag == FSYNC);
295
296 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
297 error = VOP_FSYNC(vp, cr, FSYNC_WAIT, 0, 0);
298 VOP_UNLOCK(vp, 0);
299 return (error);
300 }
301 #define VOP_FSYNC(vp, flag, cr, unk) zfs_vop_fsync((vp), (flag), (cr))
302
303 static inline int
zfs_vop_close(vnode_t * vp,int flag,int count,offset_t offset,cred_t * cr)304 zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
305 {
306
307 ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
308 ASSERT(count == 1);
309 ASSERT(offset == 0);
310
311 return (vn_close(vp, flag, cr));
312 }
313 #define VOP_CLOSE(vp, oflags, count, offset, cr, unk) \
314 zfs_vop_close((vp), (oflags), (count), (offset), (cr))
315
316 static inline int
zfs_vop_getattr(vnode_t * vp,vattr_t * ap,int flag,cred_t * cr)317 zfs_vop_getattr(vnode_t *vp, vattr_t *ap, int flag, cred_t *cr)
318 {
319 int error;
320
321 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
322 error = VOP_GETATTR(vp, ap, cr);
323 VOP_UNLOCK(vp, 0);
324 return (error);
325 }
326 #define VOP_GETATTR(vp, ap, flag, cr, unk) zfs_vop_getattr((vp), (ap), (flag), (cr))
327
328 static inline int
zfs_vop_seek(vnode_t * vp,off_t off,off_t * offp)329 zfs_vop_seek(vnode_t *vp, off_t off, off_t *offp)
330 {
331 int error;
332
333 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
334 error = VOP_SEEK(vp, off, *offp, CRED());
335 VOP_UNLOCK(vp, 0);
336 return (error);
337 }
338 #define VOP_SEEK(vp, off, offp, unk) zfs_vop_seek(vp, off, offp)
339
340 #define B_INVAL BC_INVAL
341
342 static inline int
zfs_vop_putpage(vnode_t * vp,off_t off,size_t len,int flag)343 zfs_vop_putpage(vnode_t *vp, off_t off, size_t len, int flag)
344 {
345 int nbflag;
346
347 nbflag = 0;
348 if (len == 0) {
349 nbflag |= PGO_ALLPAGES;
350 }
351 if ((flag & B_ASYNC) == 0) {
352 nbflag |= PGO_SYNCIO;
353 }
354 if ((flag & B_INVAL) != 0) {
355 nbflag |= PGO_FREE;
356 } else {
357 nbflag |= PGO_CLEANIT;
358 }
359
360 mutex_enter(vp->v_interlock);
361 return VOP_PUTPAGES(vp, off, len, nbflag);
362 }
363 #define VOP_PUTPAGE(vp, off, len, flag, cr, ct) zfs_vop_putpage((vp), (off), (len), (flag))
364
365 static inline int
vn_rename(char * from,char * to,enum uio_seg seg)366 vn_rename(char *from, char *to, enum uio_seg seg)
367 {
368
369 ASSERT(seg == UIO_SYSSPACE);
370
371 return (do_sys_rename(from, to, seg, 0));
372 }
373
374 static inline int
vn_remove(char * fnamep,enum uio_seg seg,enum rm dirflag)375 vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
376 {
377
378 ASSERT(seg == UIO_SYSSPACE);
379 ASSERT(dirflag == RMFILE);
380
381 return (do_sys_unlink(fnamep, seg));
382 }
383
384 /*
385 * VOP_ACCESS flags
386 */
387 #define V_APPEND 0x2 /* want to do append only check */
388
389 #define VV_NOSYNC 0
390
391 #define VI_LOCK(vp) mutex_enter((vp)->v_interlock)
392 #define VI_UNLOCK(vp) mutex_exit((vp)->v_interlock)
393
394 #define VATTR_NULL(x) vattr_null(x)
395
396 #define getnewvnode_reserve(x)
397 #define getnewvnode_drop_reserve()
398 #define cache_purge_negative(vp) cache_purge(vp)
399
400 #endif /* _KERNEL */
401
402 #endif /* _OPENSOLARIS_SYS_VNODE_H_ */
403