pktgen: Unbreak compile
[dragonfly.git] / sys / vfs / hammer2 / hammer2_vnops.c
CommitLineData
e118c14f
MD
1/*
2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
703720e4
MD
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/fcntl.h>
39#include <sys/buf.h>
40#include <sys/proc.h>
41#include <sys/namei.h>
42#include <sys/mount.h>
43#include <sys/vnode.h>
f0206a67 44#include <sys/mountctl.h>
e028fa74 45#include <sys/dirent.h>
4e2004ea 46#include <sys/uio.h>
703720e4
MD
47
48#include "hammer2.h"
49
db71f61f
MD
50#define ZFOFFSET (-2LL)
51
4e2004ea
MD
52static int hammer2_read_file(hammer2_inode_t *ip, struct uio *uio,
53 int seqcount);
e2e9e2db
MD
54static int hammer2_write_file(hammer2_inode_t *ip, hammer2_chain_t **chainp,
55 struct uio *uio, int ioflag, int seqcount);
8cce658d
MD
56static hammer2_off_t hammer2_assign_physical(hammer2_inode_t *ip,
57 hammer2_key_t lbase, int lblksize, int *errorp);
58static void hammer2_extend_file(hammer2_inode_t *ip, hammer2_key_t nsize);
3ac6a319
MD
59static void hammer2_truncate_file(hammer2_inode_t *ip, hammer2_key_t nsize);
60
b2b78aaa
MD
61static __inline
62void
63hammer2_knote(struct vnode *vp, int flags)
64{
65 if (flags)
66 KNOTE(&vp->v_pollinfo.vpi_kqinfo.ki_note, flags);
67}
68
703720e4
MD
69/*
70 * Last reference to a vnode is going away but it is still cached.
71 */
e118c14f 72static
703720e4 73int
e118c14f 74hammer2_vop_inactive(struct vop_inactive_args *ap)
703720e4 75{
e2e9e2db
MD
76 hammer2_chain_t *chain;
77 hammer2_inode_t *ip;
703720e4 78 struct vnode *vp;
e118c14f 79#if 0
703720e4 80 struct hammer2_mount *hmp;
e118c14f 81#endif
703720e4 82
703720e4
MD
83 vp = ap->a_vp;
84 ip = VTOI(vp);
703720e4 85
df9ea374
MD
86 /*
87 * Degenerate case
88 */
89 if (ip == NULL) {
90 vrecycle(vp);
91 return (0);
92 }
93
214f4a77
MD
94 /*
95 * Detect updates to the embedded data which may be synchronized by
96 * the strategy code. Simply mark the inode modified so it gets
97 * picked up by our normal flush.
98 */
10252dc7 99 chain = hammer2_inode_lock_ex(ip);
476d2aad 100 if (ip->flags & HAMMER2_INODE_DIRTYEMBED) {
476d2aad 101 atomic_clear_int(&ip->flags, HAMMER2_INODE_DIRTYEMBED);
e2e9e2db 102 hammer2_chain_modify(ip->hmp, chain, 0);
214f4a77
MD
103 }
104
105 /*
106 * Check for deleted inodes and recycle immediately.
107 */
10252dc7
MD
108 if (chain && (chain->flags & HAMMER2_CHAIN_DELETED)) {
109 hammer2_inode_unlock_ex(ip, chain);
214f4a77 110 vrecycle(vp);
10252dc7
MD
111 } else {
112 hammer2_inode_unlock_ex(ip, chain);
214f4a77 113 }
703720e4
MD
114 return (0);
115}
116
117/*
118 * Reclaim a vnode so that it can be reused; after the inode is
119 * disassociated, the filesystem must manage it alone.
120 */
e118c14f 121static
703720e4 122int
e118c14f 123hammer2_vop_reclaim(struct vop_reclaim_args *ap)
703720e4 124{
e2e9e2db
MD
125 hammer2_chain_t *chain;
126 hammer2_inode_t *ip;
127 hammer2_mount_t *hmp;
b7926f31 128 struct vnode *vp;
703720e4 129
703720e4
MD
130 vp = ap->a_vp;
131 ip = VTOI(vp);
9c2e0de0
MD
132 if (ip == NULL)
133 return(0);
9c2e0de0 134 hmp = ip->hmp;
b7926f31 135
1c9f601e
MD
136 /*
137 * Set SUBMODIFIED so we can detect and propagate the DESTROYED
138 * bit in the flush code.
139 */
e2e9e2db 140 chain = hammer2_inode_lock_ex(ip);
703720e4 141 vp->v_data = NULL;
0e92b724 142 ip->vp = NULL;
10252dc7 143 if (chain->flags & HAMMER2_CHAIN_DELETED) {
e2e9e2db
MD
144 KKASSERT(chain->flags & HAMMER2_CHAIN_DELETED);
145 atomic_set_int(&chain->flags, HAMMER2_CHAIN_DESTROYED |
146 HAMMER2_CHAIN_SUBMODIFIED);
1c9f601e 147 }
e2e9e2db 148 hammer2_chain_flush(hmp, chain, 0);
476d2aad 149 if (ip->refs > 2) /* (our lock + vp ref) */
e2e9e2db 150 hammer2_inode_unlock_ex(ip, chain); /* unlock */
476d2aad 151 else
e2e9e2db
MD
152 hammer2_inode_put(ip, chain); /* unlock & disconnect */
153 hammer2_inode_drop(ip); /* vp ref */
54eb943b
MD
154
155 /*
156 * XXX handle background sync when ip dirty, kernel will no longer
157 * notify us regarding this inode because there is no longer a
158 * vnode attached to it.
159 */
703720e4
MD
160
161 return (0);
162}
163
e118c14f 164static
703720e4 165int
e118c14f 166hammer2_vop_fsync(struct vop_fsync_args *ap)
703720e4 167{
e2e9e2db
MD
168 hammer2_chain_t *chain;
169 hammer2_inode_t *ip;
170 hammer2_mount_t *hmp;
b7926f31
MD
171 struct vnode *vp;
172
173 vp = ap->a_vp;
174 ip = VTOI(vp);
175 hmp = ip->hmp;
176
e2e9e2db 177 chain = hammer2_inode_lock_ex(ip);
b7926f31 178 vfsync(vp, ap->a_waitfor, 1, NULL, NULL);
6ba3b984 179
214f4a77
MD
180 /*
181 * Detect updates to the embedded data which may be synchronized by
182 * the strategy code. Simply mark the inode modified so it gets
183 * picked up by our normal flush.
184 */
476d2aad
MD
185 if (ip->flags & HAMMER2_INODE_DIRTYEMBED) {
186 atomic_clear_int(&ip->flags, HAMMER2_INODE_DIRTYEMBED);
e2e9e2db 187 hammer2_chain_modify(hmp, chain, 0);
214f4a77
MD
188 }
189
6ba3b984
MD
190 /*
191 * Calling chain_flush here creates a lot of duplicative
192 * COW operations due to non-optimal vnode ordering.
193 *
194 * Only do it for an actual fsync() syscall. The other forms
195 * which call this function will eventually call chain_flush
196 * on the volume root as a catch-all, which is far more optimal.
197 */
10252dc7 198 atomic_clear_int(&ip->flags, HAMMER2_INODE_MODIFIED);
6ba3b984 199 if (ap->a_flags & VOP_FSYNC_SYSCALL)
e2e9e2db
MD
200 hammer2_chain_flush(hmp, chain, 0);
201 hammer2_inode_unlock_ex(ip, chain);
b7926f31 202 return (0);
703720e4
MD
203}
204
e118c14f 205static
703720e4 206int
e118c14f 207hammer2_vop_access(struct vop_access_args *ap)
703720e4 208{
37494cab 209 hammer2_inode_t *ip = VTOI(ap->a_vp);
e2e9e2db 210 hammer2_chain_t *chain;
476d2aad 211 hammer2_inode_data_t *ipdata;
37494cab
MD
212 uid_t uid;
213 gid_t gid;
214 int error;
215
e2e9e2db
MD
216 chain = hammer2_inode_lock_sh(ip);
217 ipdata = &chain->data->ipdata;
476d2aad
MD
218 uid = hammer2_to_unix_xid(&ipdata->uid);
219 gid = hammer2_to_unix_xid(&ipdata->gid);
220 error = vop_helper_access(ap, uid, gid, ipdata->mode, ipdata->uflags);
e2e9e2db 221 hammer2_inode_unlock_sh(ip, chain);
37494cab 222
37494cab 223 return (error);
703720e4
MD
224}
225
e118c14f 226static
703720e4 227int
e118c14f 228hammer2_vop_getattr(struct vop_getattr_args *ap)
703720e4 229{
476d2aad 230 hammer2_inode_data_t *ipdata;
e4e20f48 231 hammer2_pfsmount_t *pmp;
cd4b3d92 232 hammer2_inode_t *ip;
e2e9e2db 233 hammer2_chain_t *chain;
703720e4
MD
234 struct vnode *vp;
235 struct vattr *vap;
703720e4
MD
236
237 vp = ap->a_vp;
238 vap = ap->a_vap;
239
cd4b3d92 240 ip = VTOI(vp);
e4e20f48 241 pmp = ip->pmp;
cd4b3d92 242
e2e9e2db
MD
243 chain = hammer2_inode_lock_sh(ip);
244 ipdata = &chain->data->ipdata;
703720e4 245
e4e20f48 246 vap->va_fsid = pmp->mp->mnt_stat.f_fsid.val[0];
476d2aad
MD
247 vap->va_fileid = ipdata->inum;
248 vap->va_mode = ipdata->mode;
249 vap->va_nlink = ipdata->nlinks;
250 vap->va_uid = hammer2_to_unix_xid(&ipdata->uid);
251 vap->va_gid = hammer2_to_unix_xid(&ipdata->gid);
cd4b3d92
MD
252 vap->va_rmajor = 0;
253 vap->va_rminor = 0;
476d2aad 254 vap->va_size = ipdata->size;
df9ea374 255 vap->va_blocksize = HAMMER2_PBUFSIZE;
476d2aad
MD
256 vap->va_flags = ipdata->uflags;
257 hammer2_time_to_timespec(ipdata->ctime, &vap->va_ctime);
258 hammer2_time_to_timespec(ipdata->mtime, &vap->va_mtime);
259 hammer2_time_to_timespec(ipdata->mtime, &vap->va_atime);
cd4b3d92 260 vap->va_gen = 1;
866d5273 261 vap->va_bytes = vap->va_size; /* XXX */
e2e9e2db 262 vap->va_type = hammer2_get_vtype(chain);
cd4b3d92 263 vap->va_filerev = 0;
476d2aad
MD
264 vap->va_uid_uuid = ipdata->uid;
265 vap->va_gid_uuid = ipdata->gid;
cd4b3d92
MD
266 vap->va_vaflags = VA_UID_UUID_VALID | VA_GID_UUID_VALID |
267 VA_FSID_UUID_VALID;
703720e4 268
e2e9e2db 269 hammer2_inode_unlock_sh(ip, chain);
703720e4
MD
270
271 return (0);
272}
273
3ac6a319
MD
274static
275int
276hammer2_vop_setattr(struct vop_setattr_args *ap)
277{
476d2aad 278 hammer2_inode_data_t *ipdata;
e2e9e2db 279 hammer2_chain_t *chain;
3ac6a319 280 hammer2_inode_t *ip;
e2e9e2db 281 hammer2_mount_t *hmp;
3ac6a319
MD
282 struct vnode *vp;
283 struct vattr *vap;
284 int error;
285 int kflags = 0;
3ac6a319 286 int domtime = 0;
b2b78aaa 287 uint64_t ctime;
3ac6a319
MD
288
289 vp = ap->a_vp;
290 vap = ap->a_vap;
b2b78aaa 291 hammer2_update_time(&ctime);
3ac6a319
MD
292
293 ip = VTOI(vp);
294 hmp = ip->hmp;
295
296 if (hmp->ronly)
297 return(EROFS);
298
e2e9e2db
MD
299 chain = hammer2_inode_lock_ex(ip);
300 ipdata = &chain->data->ipdata;
3ac6a319
MD
301 error = 0;
302
303 if (vap->va_flags != VNOVAL) {
304 u_int32_t flags;
305
476d2aad 306 flags = ipdata->uflags;
3ac6a319 307 error = vop_helper_setattr_flags(&flags, vap->va_flags,
476d2aad 308 hammer2_to_unix_xid(&ipdata->uid),
3ac6a319
MD
309 ap->a_cred);
310 if (error == 0) {
476d2aad 311 if (ipdata->uflags != flags) {
e2e9e2db 312 hammer2_chain_modify(hmp, chain, 0);
476d2aad
MD
313 ipdata->uflags = flags;
314 ipdata->ctime = ctime;
3ac6a319
MD
315 kflags |= NOTE_ATTRIB;
316 }
476d2aad 317 if (ipdata->uflags & (IMMUTABLE | APPEND)) {
3ac6a319
MD
318 error = 0;
319 goto done;
320 }
321 }
b2b78aaa 322 goto done;
3ac6a319 323 }
476d2aad 324 if (ipdata->uflags & (IMMUTABLE | APPEND)) {
3ac6a319
MD
325 error = EPERM;
326 goto done;
327 }
b2b78aaa 328 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
476d2aad
MD
329 mode_t cur_mode = ipdata->mode;
330 uid_t cur_uid = hammer2_to_unix_xid(&ipdata->uid);
331 gid_t cur_gid = hammer2_to_unix_xid(&ipdata->gid);
b2b78aaa
MD
332 uuid_t uuid_uid;
333 uuid_t uuid_gid;
334
335 error = vop_helper_chown(ap->a_vp, vap->va_uid, vap->va_gid,
336 ap->a_cred,
337 &cur_uid, &cur_gid, &cur_mode);
338 if (error == 0) {
339 hammer2_guid_to_uuid(&uuid_uid, cur_uid);
340 hammer2_guid_to_uuid(&uuid_gid, cur_gid);
476d2aad
MD
341 if (bcmp(&uuid_uid, &ipdata->uid, sizeof(uuid_uid)) ||
342 bcmp(&uuid_gid, &ipdata->gid, sizeof(uuid_gid)) ||
343 ipdata->mode != cur_mode
b2b78aaa 344 ) {
e2e9e2db 345 hammer2_chain_modify(hmp, chain, 0);
476d2aad
MD
346 ipdata->uid = uuid_uid;
347 ipdata->gid = uuid_gid;
348 ipdata->mode = cur_mode;
349 ipdata->ctime = ctime;
b2b78aaa
MD
350 }
351 kflags |= NOTE_ATTRIB;
352 }
353 }
3ac6a319
MD
354
355 /*
356 * Resize the file
357 */
476d2aad 358 if (vap->va_size != VNOVAL && ipdata->size != vap->va_size) {
3ac6a319
MD
359 switch(vp->v_type) {
360 case VREG:
476d2aad 361 if (vap->va_size == ipdata->size)
3ac6a319 362 break;
476d2aad 363 if (vap->va_size < ipdata->size) {
3ac6a319 364 hammer2_truncate_file(ip, vap->va_size);
3ac6a319 365 } else {
8cce658d 366 hammer2_extend_file(ip, vap->va_size);
3ac6a319
MD
367 }
368 domtime = 1;
369 break;
370 default:
371 error = EINVAL;
372 goto done;
373 }
374 }
b2b78aaa
MD
375#if 0
376 /* atime not supported */
377 if (vap->va_atime.tv_sec != VNOVAL) {
e2e9e2db 378 hammer2_chain_modify(hmp, chain, 0);
476d2aad 379 ipdata->atime = hammer2_timespec_to_time(&vap->va_atime);
b2b78aaa
MD
380 kflags |= NOTE_ATTRIB;
381 }
382#endif
383 if (vap->va_mtime.tv_sec != VNOVAL) {
e2e9e2db 384 hammer2_chain_modify(hmp, chain, 0);
476d2aad 385 ipdata->mtime = hammer2_timespec_to_time(&vap->va_mtime);
b2b78aaa
MD
386 kflags |= NOTE_ATTRIB;
387 }
388 if (vap->va_mode != (mode_t)VNOVAL) {
476d2aad
MD
389 mode_t cur_mode = ipdata->mode;
390 uid_t cur_uid = hammer2_to_unix_xid(&ipdata->uid);
391 gid_t cur_gid = hammer2_to_unix_xid(&ipdata->gid);
b2b78aaa
MD
392
393 error = vop_helper_chmod(ap->a_vp, vap->va_mode, ap->a_cred,
394 cur_uid, cur_gid, &cur_mode);
476d2aad 395 if (error == 0 && ipdata->mode != cur_mode) {
e2e9e2db 396 hammer2_chain_modify(hmp, chain, 0);
476d2aad
MD
397 ipdata->mode = cur_mode;
398 ipdata->ctime = ctime;
b2b78aaa
MD
399 kflags |= NOTE_ATTRIB;
400 }
401 }
3ac6a319 402done:
e2e9e2db 403 hammer2_inode_unlock_ex(ip, chain);
3ac6a319
MD
404 return (error);
405}
406
e118c14f 407static
703720e4 408int
e118c14f 409hammer2_vop_readdir(struct vop_readdir_args *ap)
703720e4 410{
476d2aad 411 hammer2_inode_data_t *ipdata;
e028fa74
MD
412 hammer2_mount_t *hmp;
413 hammer2_inode_t *ip;
414 hammer2_inode_t *xip;
415 hammer2_chain_t *parent;
e2e9e2db 416 hammer2_chain_t *xparent;
e028fa74 417 hammer2_chain_t *chain;
476d2aad 418 hammer2_tid_t inum;
e028fa74
MD
419 hammer2_key_t lkey;
420 struct uio *uio;
421 off_t *cookies;
422 off_t saveoff;
423 int cookie_index;
424 int ncookies;
425 int error;
426 int dtype;
427 int r;
428
429 ip = VTOI(ap->a_vp);
430 hmp = ip->hmp;
431 uio = ap->a_uio;
432 saveoff = uio->uio_offset;
433
434 /*
435 * Setup cookies directory entry cookies if requested
436 */
437 if (ap->a_ncookies) {
438 ncookies = uio->uio_resid / 16 + 1;
439 if (ncookies > 1024)
440 ncookies = 1024;
441 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
442 } else {
443 ncookies = -1;
444 cookies = NULL;
445 }
446 cookie_index = 0;
447
e2e9e2db
MD
448 parent = hammer2_inode_lock_sh(ip);
449 ipdata = &parent->data->ipdata;
476d2aad 450
e028fa74
MD
451 /*
452 * Handle artificial entries. To ensure that only positive 64 bit
453 * quantities are returned to userland we always strip off bit 63.
454 * The hash code is designed such that codes 0x0000-0x7FFF are not
455 * used, allowing us to use these codes for articial entries.
456 *
457 * Entry 0 is used for '.' and entry 1 is used for '..'. Do not
458 * allow '..' to cross the mount point into (e.g.) the super-root.
459 */
460 error = 0;
37aa19df 461 chain = (void *)(intptr_t)-1; /* non-NULL for early goto done case */
e028fa74
MD
462
463 if (saveoff == 0) {
476d2aad
MD
464 inum = ipdata->inum & HAMMER2_DIRHASH_USERMSK;
465 r = vop_write_dirent(&error, uio, inum, DT_DIR, 1, ".");
e028fa74
MD
466 if (r)
467 goto done;
468 if (cookies)
469 cookies[cookie_index] = saveoff;
470 ++saveoff;
471 ++cookie_index;
472 if (cookie_index == ncookies)
473 goto done;
474 }
476d2aad 475
e028fa74 476 if (saveoff == 1) {
476d2aad
MD
477 /*
478 * Be careful with lockorder when accessing ".."
e2e9e2db
MD
479 *
480 * (parent is the current dir. xip is the parent dir).
476d2aad 481 */
e2e9e2db 482 inum = parent->data->ipdata.inum & HAMMER2_DIRHASH_USERMSK;
476d2aad 483 while (ip->pip != NULL && ip != ip->pmp->iroot) {
e028fa74 484 xip = ip->pip;
476d2aad 485 hammer2_inode_ref(xip);
e2e9e2db
MD
486 hammer2_inode_unlock_sh(ip, parent);
487 xparent = hammer2_inode_lock_sh(xip);
488 parent = hammer2_inode_lock_sh(ip);
476d2aad
MD
489 hammer2_inode_drop(xip);
490 if (xip == ip->pip) {
e2e9e2db 491 inum = xparent->data->ipdata.inum &
476d2aad 492 HAMMER2_DIRHASH_USERMSK;
e2e9e2db 493 hammer2_inode_unlock_sh(xip, xparent);
476d2aad
MD
494 break;
495 }
e2e9e2db 496 hammer2_inode_unlock_sh(xip, xparent);
476d2aad
MD
497 }
498 r = vop_write_dirent(&error, uio, inum, DT_DIR, 2, "..");
e028fa74
MD
499 if (r)
500 goto done;
501 if (cookies)
502 cookies[cookie_index] = saveoff;
503 ++saveoff;
504 ++cookie_index;
505 if (cookie_index == ncookies)
506 goto done;
507 }
508
509 lkey = saveoff | HAMMER2_DIRHASH_VISIBLE;
510
e2e9e2db
MD
511 /*
512 * parent is the inode chain, already locked for us. Don't
513 * double lock shared locks as this will screw up upgrades.
514 */
e028fa74 515 if (error) {
e028fa74
MD
516 goto done;
517 }
a0ed3c24
MD
518 chain = hammer2_chain_lookup(hmp, &parent, lkey, lkey,
519 HAMMER2_LOOKUP_SHARED);
37aa19df
MD
520 if (chain == NULL) {
521 chain = hammer2_chain_lookup(hmp, &parent,
a0ed3c24
MD
522 lkey, (hammer2_key_t)-1,
523 HAMMER2_LOOKUP_SHARED);
37aa19df 524 }
e028fa74 525 while (chain) {
c667909f 526 if (chain->bref.type == HAMMER2_BREF_TYPE_INODE) {
476d2aad 527 dtype = hammer2_get_dtype(chain);
c667909f
MD
528 saveoff = chain->bref.key & HAMMER2_DIRHASH_USERMSK;
529 r = vop_write_dirent(&error, uio,
476d2aad 530 chain->data->ipdata.inum &
c667909f 531 HAMMER2_DIRHASH_USERMSK,
476d2aad
MD
532 dtype,
533 chain->data->ipdata.name_len,
534 chain->data->ipdata.filename);
c667909f
MD
535 if (r)
536 break;
537 if (cookies)
538 cookies[cookie_index] = saveoff;
539 ++cookie_index;
540 } else {
541 /* XXX chain error */
542 kprintf("bad chain type readdir %d\n",
543 chain->bref.type);
544 }
995e78dc
MD
545
546 /*
547 * Keys may not be returned in order so once we have a
548 * placemarker (chain) the scan must allow the full range
549 * or some entries will be missed.
550 */
e028fa74 551 chain = hammer2_chain_next(hmp, &parent, chain,
99535653 552 HAMMER2_DIRHASH_VISIBLE,
a0ed3c24
MD
553 (hammer2_key_t)-1,
554 HAMMER2_LOOKUP_SHARED);
028a55bb
MD
555 if (chain) {
556 saveoff = (chain->bref.key &
557 HAMMER2_DIRHASH_USERMSK) + 1;
558 } else {
559 saveoff = (hammer2_key_t)-1;
560 }
561 if (cookie_index == ncookies)
562 break;
e028fa74 563 }
028a55bb 564 if (chain)
01eabad4 565 hammer2_chain_unlock(hmp, chain);
e028fa74 566done:
e2e9e2db 567 hammer2_inode_unlock_sh(ip, parent);
e028fa74
MD
568 if (ap->a_eofflag)
569 *ap->a_eofflag = (chain == NULL);
37aa19df 570 uio->uio_offset = saveoff & ~HAMMER2_DIRHASH_VISIBLE;
e028fa74
MD
571 if (error && cookie_index == 0) {
572 if (cookies) {
573 kfree(cookies, M_TEMP);
574 *ap->a_ncookies = 0;
575 *ap->a_cookies = NULL;
576 }
577 } else {
578 if (cookies) {
579 *ap->a_ncookies = cookie_index;
580 *ap->a_cookies = cookies;
581 }
582 }
583 return (error);
703720e4
MD
584}
585
4e2004ea
MD
586/*
587 * hammer2_vop_readlink { vp, uio, cred }
588 */
589static
590int
591hammer2_vop_readlink(struct vop_readlink_args *ap)
592{
593 struct vnode *vp;
594 hammer2_mount_t *hmp;
595 hammer2_inode_t *ip;
596 int error;
597
598 vp = ap->a_vp;
599 if (vp->v_type != VLNK)
600 return (EINVAL);
601 ip = VTOI(vp);
602 hmp = ip->hmp;
603
604 error = hammer2_read_file(ip, ap->a_uio, 0);
605 return (error);
606}
607
e118c14f 608static
703720e4 609int
e118c14f 610hammer2_vop_read(struct vop_read_args *ap)
703720e4 611{
db71f61f
MD
612 struct vnode *vp;
613 hammer2_mount_t *hmp;
614 hammer2_inode_t *ip;
db71f61f
MD
615 struct uio *uio;
616 int error;
617 int seqcount;
618 int bigread;
619
620 /*
621 * Read operations supported on this vnode?
622 */
623 vp = ap->a_vp;
624 if (vp->v_type != VREG)
625 return (EINVAL);
626
627 /*
628 * Misc
629 */
630 ip = VTOI(vp);
631 hmp = ip->hmp;
632 uio = ap->a_uio;
633 error = 0;
634
635 seqcount = ap->a_ioflag >> 16;
636 bigread = (uio->uio_resid > 100 * 1024 * 1024);
637
4e2004ea 638 error = hammer2_read_file(ip, uio, seqcount);
db71f61f 639 return (error);
47902fef 640}
703720e4 641
e118c14f 642static
47902fef 643int
e118c14f 644hammer2_vop_write(struct vop_write_args *ap)
47902fef 645{
e2e9e2db 646 hammer2_chain_t *chain;
db71f61f
MD
647 hammer2_mount_t *hmp;
648 hammer2_inode_t *ip;
e2e9e2db
MD
649 thread_t td;
650 struct vnode *vp;
db71f61f
MD
651 struct uio *uio;
652 int error;
db71f61f
MD
653 int seqcount;
654 int bigwrite;
655
656 /*
657 * Read operations supported on this vnode?
658 */
659 vp = ap->a_vp;
660 if (vp->v_type != VREG)
661 return (EINVAL);
662
663 /*
664 * Misc
665 */
666 ip = VTOI(vp);
667 hmp = ip->hmp;
668 uio = ap->a_uio;
669 error = 0;
db71f61f
MD
670 if (hmp->ronly)
671 return (EROFS);
672
673 seqcount = ap->a_ioflag >> 16;
674 bigwrite = (uio->uio_resid > 100 * 1024 * 1024);
675
676 /*
677 * Check resource limit
678 */
679 if (uio->uio_resid > 0 && (td = uio->uio_td) != NULL && td->td_proc &&
680 uio->uio_offset + uio->uio_resid >
681 td->td_proc->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
682 lwpsignal(td->td_proc, td->td_lwp, SIGXFSZ);
683 return (EFBIG);
684 }
685
686 bigwrite = (uio->uio_resid > 100 * 1024 * 1024);
687
688 /*
3ac6a319
MD
689 * ip must be locked if extending the file.
690 * ip must be locked to avoid racing a truncation.
8cce658d
MD
691 *
692 * ip must be marked modified, particularly because the write
693 * might wind up being copied into the embedded data area.
3ac6a319 694 */
e2e9e2db
MD
695 chain = hammer2_inode_lock_ex(ip);
696 error = hammer2_write_file(ip, &chain, uio, ap->a_ioflag, seqcount);
697 hammer2_inode_unlock_ex(ip, chain);
4e2004ea
MD
698 return (error);
699}
700
701/*
702 * Perform read operations on a file or symlink given an UNLOCKED
703 * inode and uio.
476d2aad
MD
704 *
705 * The passed ip is not locked.
4e2004ea
MD
706 */
707static
708int
709hammer2_read_file(hammer2_inode_t *ip, struct uio *uio, int seqcount)
710{
e2e9e2db
MD
711 hammer2_chain_t *chain;
712 hammer2_off_t size;
4e2004ea
MD
713 struct buf *bp;
714 int error;
715
716 error = 0;
717
718 /*
e2e9e2db
MD
719 * UIO read loop.
720 *
721 * We can't hold a shared lock on ip's chain across file bread's
722 * because the bread operation will itself obtain a shared lock,
723 * resulting in one thread holding 2 shared refs. This will deadlock
724 * against temporary lock upgrades. Temporary lock upgrades are
725 * needed to insert new chain structures into a parent's RB tree.
726 *
727 * We should be able to safely retain the shared lock on ip itself.
4e2004ea 728 */
e2e9e2db
MD
729 chain = hammer2_inode_lock_sh(ip);
730 size = chain->data->ipdata.size;
731 hammer2_chain_unlock(ip->hmp, chain);
732 chain = NULL;
733
734 while (uio->uio_resid > 0 && uio->uio_offset < size) {
8cce658d
MD
735 hammer2_key_t lbase;
736 hammer2_key_t leof;
737 int lblksize;
738 int loff;
4e2004ea
MD
739 int n;
740
8cce658d
MD
741 lblksize = hammer2_calc_logical(ip, uio->uio_offset,
742 &lbase, &leof);
4e2004ea 743
8cce658d 744 error = cluster_read(ip->vp, leof, lbase, lblksize,
6ba3b984
MD
745 uio->uio_resid, seqcount * BKVASIZE,
746 &bp);
8cce658d 747
4e2004ea
MD
748 if (error)
749 break;
8cce658d
MD
750 loff = (int)(uio->uio_offset - lbase);
751 n = lblksize - loff;
4e2004ea
MD
752 if (n > uio->uio_resid)
753 n = uio->uio_resid;
e2e9e2db
MD
754 if (n > size - uio->uio_offset)
755 n = (int)(size - uio->uio_offset);
4e2004ea 756 bp->b_flags |= B_AGE;
8cce658d 757 uiomove((char *)bp->b_data + loff, n, uio);
4e2004ea
MD
758 bqrelse(bp);
759 }
e2e9e2db 760 hammer2_inode_unlock_sh(ip, chain);
4e2004ea
MD
761 return (error);
762}
763
764/*
765 * Called with a locked (ip) to do the underlying write to a file or
766 * to build the symlink target.
767 */
768static
769int
e2e9e2db
MD
770hammer2_write_file(hammer2_inode_t *ip, hammer2_chain_t **chainp,
771 struct uio *uio,
1c9f601e 772 int ioflag, int seqcount)
4e2004ea 773{
476d2aad 774 hammer2_inode_data_t *ipdata;
8cce658d 775 hammer2_key_t old_eof;
4e2004ea
MD
776 struct buf *bp;
777 int kflags;
778 int error;
b2b78aaa 779 int modified = 0;
3ac6a319 780
4e2004ea
MD
781 /*
782 * Setup if append
783 */
476d2aad 784 ipdata = &ip->chain->data->ipdata;
4e2004ea 785 if (ioflag & IO_APPEND)
476d2aad 786 uio->uio_offset = ipdata->size;
4e2004ea
MD
787 kflags = 0;
788 error = 0;
3ac6a319 789
8cce658d
MD
790 /*
791 * Extend the file if necessary. If the write fails at some point
792 * we will truncate it back down to cover as much as we were able
793 * to write.
794 *
795 * Doing this now makes it easier to calculate buffer sizes in
796 * the loop.
797 */
476d2aad
MD
798 old_eof = ipdata->size;
799 if (uio->uio_offset + uio->uio_resid > ipdata->size) {
b2b78aaa 800 modified = 1;
8cce658d
MD
801 hammer2_extend_file(ip, uio->uio_offset + uio->uio_resid);
802 kflags |= NOTE_EXTEND;
803 }
804
3ac6a319
MD
805 /*
806 * UIO write loop
db71f61f
MD
807 */
808 while (uio->uio_resid > 0) {
8cce658d
MD
809 hammer2_key_t lbase;
810 hammer2_key_t leof;
db71f61f 811 int trivial;
8cce658d
MD
812 int lblksize;
813 int loff;
814 int n;
db71f61f
MD
815
816 /*
817 * Don't allow the buffer build to blow out the buffer
818 * cache.
819 */
a92f82c4
MD
820 if ((ioflag & IO_RECURSE) == 0) {
821 /*
822 * XXX should try to leave this unlocked through
823 * the whole loop
824 */
e2e9e2db 825 hammer2_inode_unlock_ex(ip, *chainp);
01eabad4 826 bwillwrite(HAMMER2_PBUFSIZE);
e2e9e2db
MD
827 *chainp = hammer2_inode_lock_ex(ip);
828 ipdata = &(*chainp)->data->ipdata; /* reload */
a92f82c4 829 }
db71f61f 830
8cce658d
MD
831 /* XXX bigwrite & signal check test */
832
db71f61f 833 /*
8cce658d
MD
834 * This nominally tells us how much we can cluster and
835 * what the logical buffer size needs to be. Currently
836 * we don't try to cluster the write and just handle one
837 * block at a time.
db71f61f 838 */
8cce658d
MD
839 lblksize = hammer2_calc_logical(ip, uio->uio_offset,
840 &lbase, &leof);
841 loff = (int)(uio->uio_offset - lbase);
842
843 /*
844 * Calculate bytes to copy this transfer and whether the
845 * copy completely covers the buffer or not.
846 */
847 trivial = 0;
848 n = lblksize - loff;
849 if (n > uio->uio_resid) {
850 n = uio->uio_resid;
476d2aad 851 if (uio->uio_offset + n == ipdata->size)
db71f61f 852 trivial = 1;
8cce658d
MD
853 } else if (loff == 0) {
854 trivial = 1;
db71f61f
MD
855 }
856
8cce658d
MD
857 /*
858 * Get the buffer
859 */
db71f61f
MD
860 if (uio->uio_segflg == UIO_NOCOPY) {
861 /*
862 * Issuing a write with the same data backing the
863 * buffer. Instantiate the buffer to collect the
864 * backing vm pages, then read-in any missing bits.
865 *
866 * This case is used by vop_stdputpages().
867 */
8cce658d 868 bp = getblk(ip->vp, lbase, lblksize, GETBLK_BHEAVY, 0);
db71f61f
MD
869 if ((bp->b_flags & B_CACHE) == 0) {
870 bqrelse(bp);
8cce658d 871 error = bread(ip->vp, lbase, lblksize, &bp);
db71f61f 872 }
8cce658d 873 } else if (trivial) {
db71f61f
MD
874 /*
875 * Even though we are entirely overwriting the buffer
876 * we may still have to zero it out to avoid a
877 * mmap/write visibility issue.
878 */
8cce658d 879 bp = getblk(ip->vp, lbase, lblksize, GETBLK_BHEAVY, 0);
db71f61f
MD
880 if ((bp->b_flags & B_CACHE) == 0)
881 vfs_bio_clrbuf(bp);
db71f61f
MD
882 } else {
883 /*
884 * Partial overwrite, read in any missing bits then
885 * replace the portion being written.
8cce658d
MD
886 *
887 * (The strategy code will detect zero-fill physical
888 * blocks for this case).
db71f61f 889 */
8cce658d 890 error = bread(ip->vp, lbase, lblksize, &bp);
db71f61f
MD
891 if (error == 0)
892 bheavy(bp);
893 }
894
8cce658d
MD
895 if (error) {
896 brelse(bp);
897 break;
db71f61f
MD
898 }
899
8cce658d
MD
900 /*
901 * We have to assign physical storage to the buffer we intend
902 * to dirty or write now to avoid deadlocks in the strategy
903 * code later.
904 *
905 * This can return NOOFFSET for inode-embedded data. The
906 * strategy code will take care of it in that case.
907 */
908 bp->b_bio2.bio_offset =
909 hammer2_assign_physical(ip, lbase, lblksize, &error);
db71f61f
MD
910 if (error) {
911 brelse(bp);
db71f61f
MD
912 break;
913 }
8cce658d
MD
914
915 /*
916 * Ok, copy the data in
917 */
e2e9e2db 918 hammer2_inode_unlock_ex(ip, *chainp);
8cce658d 919 error = uiomove(bp->b_data + loff, n, uio);
e2e9e2db
MD
920 *chainp = hammer2_inode_lock_ex(ip);
921 ipdata = &(*chainp)->data->ipdata; /* reload */
db71f61f 922 kflags |= NOTE_WRITE;
b2b78aaa 923 modified = 1;
8cce658d
MD
924
925 if (error) {
926 brelse(bp);
927 break;
928 }
929
b2b78aaa 930 /* XXX update ip_data.mtime */
db71f61f
MD
931
932 /*
933 * Once we dirty a buffer any cached offset becomes invalid.
1c9f601e
MD
934 *
935 * NOTE: For cluster_write() always use the trailing block
936 * size, which is HAMMER2_PBUFSIZE. lblksize is the
937 * eof-straddling blocksize and is incorrect.
db71f61f 938 */
db71f61f 939 bp->b_flags |= B_AGE;
4e2004ea 940 if (ioflag & IO_SYNC) {
db71f61f 941 bwrite(bp);
8cce658d 942 } else if ((ioflag & IO_DIRECT) && loff + n == lblksize) {
004f88b4
MD
943 if (bp->b_bcount == HAMMER2_PBUFSIZE)
944 bp->b_flags |= B_CLUSTEROK;
8cce658d 945 bdwrite(bp);
4e2004ea 946 } else if (ioflag & IO_ASYNC) {
db71f61f 947 bawrite(bp);
1c9f601e 948 } else if (hammer2_cluster_enable) {
004f88b4
MD
949 if (bp->b_bcount == HAMMER2_PBUFSIZE)
950 bp->b_flags |= B_CLUSTEROK;
1c9f601e 951 cluster_write(bp, leof, HAMMER2_PBUFSIZE, seqcount);
db71f61f 952 } else {
004f88b4
MD
953 if (bp->b_bcount == HAMMER2_PBUFSIZE)
954 bp->b_flags |= B_CLUSTEROK;
db71f61f
MD
955 bdwrite(bp);
956 }
957 }
8cce658d
MD
958
959 /*
960 * Cleanup. If we extended the file EOF but failed to write through
961 * the entire write is a failure and we have to back-up.
962 */
476d2aad 963 if (error && ipdata->size != old_eof) {
8cce658d 964 hammer2_truncate_file(ip, old_eof);
b2b78aaa 965 } else if (modified) {
e2e9e2db
MD
966 KKASSERT(ip->chain == *chainp);
967 hammer2_chain_modify(ip->hmp, *chainp, 0);
476d2aad 968 hammer2_update_time(&ipdata->mtime);
b2b78aaa
MD
969 }
970 hammer2_knote(ip->vp, kflags);
4e2004ea 971 return error;
703720e4
MD
972}
973
3ac6a319 974/*
8cce658d
MD
975 * Assign physical storage to a logical block.
976 *
977 * NOOFFSET is returned if the data is inode-embedded. In this case the
978 * strategy code will simply bcopy() the data into the inode.
28ee5f14
MD
979 *
980 * The inode's delta_dcount is adjusted.
8cce658d
MD
981 */
982static
983hammer2_off_t
984hammer2_assign_physical(hammer2_inode_t *ip, hammer2_key_t lbase,
985 int lblksize, int *errorp)
986{
987 hammer2_mount_t *hmp;
988 hammer2_chain_t *parent;
989 hammer2_chain_t *chain;
990 hammer2_off_t pbase;
991
8cce658d
MD
992 /*
993 * Locate the chain associated with lbase, return a locked chain.
994 * However, do not instantiate any data reference (which utilizes a
995 * device buffer) because we will be using direct IO via the
996 * logical buffer cache buffer.
997 */
5f6853df 998 hmp = ip->hmp;
5f6853df 999 *errorp = 0;
476d2aad 1000retry:
e2e9e2db 1001 parent = hammer2_inode_lock_ex(ip);
8cce658d
MD
1002 chain = hammer2_chain_lookup(hmp, &parent,
1003 lbase, lbase,
1004 HAMMER2_LOOKUP_NODATA);
1005
1006 if (chain == NULL) {
1007 /*
01eabad4
MD
1008 * We found a hole, create a new chain entry.
1009 *
1010 * NOTE: DATA chains are created without device backing
1011 * store (nor do we want any).
8cce658d
MD
1012 */
1013 chain = hammer2_chain_create(hmp, parent, NULL,
1014 lbase, HAMMER2_PBUFRADIX,
1015 HAMMER2_BREF_TYPE_DATA,
5f6853df
MD
1016 lblksize, errorp);
1017 if (chain == NULL) {
1018 KKASSERT(*errorp == EAGAIN); /* XXX */
e2e9e2db 1019 hammer2_inode_unlock_ex(ip, parent);
5f6853df
MD
1020 goto retry;
1021 }
1022
8cce658d 1023 pbase = chain->bref.data_off & ~HAMMER2_OFF_MASK_RADIX;
476d2aad 1024 /*ip->delta_dcount += lblksize;*/
8cce658d
MD
1025 } else {
1026 switch (chain->bref.type) {
1027 case HAMMER2_BREF_TYPE_INODE:
1028 /*
214f4a77
MD
1029 * The data is embedded in the inode. The
1030 * caller is responsible for marking the inode
1031 * modified and copying the data to the embedded
1032 * area.
8cce658d 1033 */
8cce658d
MD
1034 pbase = NOOFFSET;
1035 break;
1036 case HAMMER2_BREF_TYPE_DATA:
1037 if (chain->bytes != lblksize) {
1038 panic("hammer2_assign_physical: "
1039 "size mismatch %d/%d\n",
1040 lblksize, chain->bytes);
1041 }
01eabad4
MD
1042 hammer2_chain_modify(hmp, chain,
1043 HAMMER2_MODIFY_OPTDATA);
8cce658d
MD
1044 pbase = chain->bref.data_off & ~HAMMER2_OFF_MASK_RADIX;
1045 break;
1046 default:
1047 panic("hammer2_assign_physical: bad type");
1048 /* NOT REACHED */
1049 pbase = NOOFFSET;
1050 break;
1051 }
1052 }
1053
1054 if (chain)
01eabad4 1055 hammer2_chain_unlock(hmp, chain);
e2e9e2db 1056 hammer2_inode_unlock_ex(ip, parent);
8cce658d
MD
1057
1058 return (pbase);
1059}
1060
1061/*
1062 * Truncate the size of a file.
1063 *
476d2aad 1064 * This routine adjusts ipdata->size smaller, destroying any related
8cce658d
MD
1065 * data beyond the new EOF and potentially resizing the block straddling
1066 * the EOF.
1067 *
1068 * The inode must be locked.
3ac6a319
MD
1069 */
1070static
1071void
1072hammer2_truncate_file(hammer2_inode_t *ip, hammer2_key_t nsize)
1073{
476d2aad 1074 hammer2_inode_data_t *ipdata;
3ac6a319
MD
1075 hammer2_chain_t *parent;
1076 hammer2_chain_t *chain;
1077 hammer2_mount_t *hmp = ip->hmp;
8cce658d
MD
1078 hammer2_key_t lbase;
1079 hammer2_key_t leof;
1080 struct buf *bp;
1081 int loff;
3ac6a319 1082 int error;
8cce658d
MD
1083 int oblksize;
1084 int nblksize;
1085
476d2aad 1086 hammer2_chain_modify(hmp, ip->chain, 0);
8cce658d 1087 bp = NULL;
476d2aad 1088 ipdata = &ip->chain->data->ipdata;
3ac6a319
MD
1089
1090 /*
8cce658d
MD
1091 * Destroy any logical buffer cache buffers beyond the file EOF.
1092 *
1093 * We call nvtruncbuf() w/ trivial == 1 to prevent it from messing
1094 * around with the buffer straddling EOF, because we need to assign
1095 * a new physical offset to it.
3ac6a319
MD
1096 */
1097 if (ip->vp) {
1098 nvtruncbuf(ip->vp, nsize,
8cce658d
MD
1099 HAMMER2_PBUFSIZE, (int)nsize & HAMMER2_PBUFMASK,
1100 1);
3ac6a319 1101 }
3ac6a319
MD
1102
1103 /*
8cce658d 1104 * Setup for lookup/search
3ac6a319 1105 */
476d2aad 1106 parent = ip->chain;
01eabad4 1107 error = hammer2_chain_lock(hmp, parent, HAMMER2_RESOLVE_ALWAYS);
3ac6a319 1108 if (error) {
01eabad4 1109 hammer2_chain_unlock(hmp, parent);
3ac6a319
MD
1110 /* XXX error reporting */
1111 return;
1112 }
1113
1114 /*
8cce658d
MD
1115 * Handle the case where a chain/logical-buffer straddles the new
1116 * EOF. We told nvtruncbuf() above not to mess with the logical
1117 * buffer straddling the EOF because we need to reassign its storage
1118 * and can't let the strategy code do it for us.
3ac6a319 1119 */
8cce658d
MD
1120 loff = (int)nsize & HAMMER2_PBUFMASK;
1121 if (loff && ip->vp) {
1122 oblksize = hammer2_calc_logical(ip, nsize, &lbase, &leof);
1123 error = bread(ip->vp, lbase, oblksize, &bp);
1124 KKASSERT(error == 0);
1125 }
476d2aad 1126 ipdata->size = nsize;
8cce658d 1127 nblksize = hammer2_calc_logical(ip, nsize, &lbase, &leof);
3ac6a319 1128
866d5273 1129 /*
8cce658d
MD
1130 * Fixup the chain element. If we have a logical buffer in-hand
1131 * we don't want to create a conflicting device buffer.
866d5273 1132 */
8cce658d
MD
1133 if (loff && bp) {
1134 chain = hammer2_chain_lookup(hmp, &parent, lbase, lbase,
01eabad4 1135 HAMMER2_LOOKUP_NODATA);
8cce658d
MD
1136 if (chain) {
1137 allocbuf(bp, nblksize);
1138 switch(chain->bref.type) {
1139 case HAMMER2_BREF_TYPE_DATA:
28ee5f14 1140 hammer2_chain_resize(ip, chain,
9061bde5 1141 hammer2_allocsize(nblksize),
01eabad4 1142 HAMMER2_MODIFY_OPTDATA);
8cce658d
MD
1143 bzero(bp->b_data + loff, nblksize - loff);
1144 bp->b_bio2.bio_offset = chain->bref.data_off &
1145 HAMMER2_OFF_MASK;
1146 break;
1147 case HAMMER2_BREF_TYPE_INODE:
1148 bzero(bp->b_data + loff, nblksize - loff);
1149 bp->b_bio2.bio_offset = NOOFFSET;
1150 break;
1151 default:
1152 panic("hammer2_truncate_file: bad type");
1153 break;
1154 }
01eabad4 1155 hammer2_chain_unlock(hmp, chain);
004f88b4
MD
1156 if (bp->b_bcount == HAMMER2_PBUFSIZE)
1157 bp->b_flags |= B_CLUSTEROK;
8cce658d
MD
1158 bdwrite(bp);
1159 } else {
1160 /*
1161 * Destroy clean buffer w/ wrong buffer size. Retain
1162 * backing store.
1163 */
1164 bp->b_flags |= B_RELBUF;
1165 KKASSERT(bp->b_bio2.bio_offset == NOOFFSET);
1166 KKASSERT((bp->b_flags & B_DIRTY) == 0);
1167 bqrelse(bp);
1168 }
1169 } else if (loff) {
01eabad4
MD
1170 /*
1171 * WARNING: This utilizes a device buffer for the data.
1172 *
004f88b4
MD
1173 * This case should not occur because file truncations without
1174 * a vnode (and hence no logical buffer cache) should only
1175 * always truncate to 0-length.
01eabad4
MD
1176 */
1177 panic("hammer2_truncate_file: non-zero truncation, no-vnode");
004f88b4 1178#if 0
8cce658d
MD
1179 chain = hammer2_chain_lookup(hmp, &parent, lbase, lbase, 0);
1180 if (chain) {
1181 switch(chain->bref.type) {
1182 case HAMMER2_BREF_TYPE_DATA:
28ee5f14 1183 hammer2_chain_resize(ip, chain,
9061bde5 1184 hammer2_allocsize(nblksize),
01eabad4
MD
1185 0);
1186 hammer2_chain_modify(hmp, chain, 0);
8cce658d
MD
1187 bzero(chain->data->buf + loff, nblksize - loff);
1188 break;
1189 case HAMMER2_BREF_TYPE_INODE:
1190 if (loff < HAMMER2_EMBEDDED_BYTES) {
01eabad4 1191 hammer2_chain_modify(hmp, chain, 0);
8cce658d
MD
1192 bzero(chain->data->ipdata.u.data + loff,
1193 HAMMER2_EMBEDDED_BYTES - loff);
1194 }
1195 break;
1196 }
01eabad4 1197 hammer2_chain_unlock(hmp, chain);
3ac6a319 1198 }
004f88b4 1199#endif
3ac6a319
MD
1200 }
1201
866d5273 1202 /*
8cce658d
MD
1203 * Clean up any fragmentory VM pages now that we have properly
1204 * resized the straddling buffer. These pages are no longer
1205 * part of the buffer.
866d5273 1206 */
8cce658d
MD
1207 if (ip->vp) {
1208 nvtruncbuf(ip->vp, nsize,
1209 nblksize, (int)nsize & (nblksize - 1),
1210 1);
1211 }
866d5273 1212
8cce658d
MD
1213 /*
1214 * Destroy any physical blocks after the new EOF point.
1215 */
1216 lbase = (nsize + HAMMER2_PBUFMASK64) & ~HAMMER2_PBUFMASK64;
3ac6a319 1217 chain = hammer2_chain_lookup(hmp, &parent,
8cce658d 1218 lbase, (hammer2_key_t)-1,
5f6853df 1219 HAMMER2_LOOKUP_NODATA);
3ac6a319
MD
1220 while (chain) {
1221 /*
1222 * Degenerate embedded data case, nothing to loop on.
1223 */
8e12e3c9
MD
1224 if (chain->bref.type == HAMMER2_BREF_TYPE_INODE) {
1225 hammer2_chain_unlock(hmp, chain);
3ac6a319 1226 break;
8e12e3c9 1227 }
3ac6a319
MD
1228
1229 /*
1230 * Delete physical data blocks past the file EOF.
1231 */
1232 if (chain->bref.type == HAMMER2_BREF_TYPE_DATA) {
476d2aad 1233 /*ip->delta_dcount -= chain->bytes;*/
004f88b4 1234 hammer2_chain_delete(hmp, parent, chain, 0);
3ac6a319 1235 }
db0c2eb3 1236 /* XXX check parent if empty indirect block & delete */
3ac6a319 1237 chain = hammer2_chain_next(hmp, &parent, chain,
8cce658d 1238 lbase, (hammer2_key_t)-1,
5f6853df 1239 HAMMER2_LOOKUP_NODATA);
3ac6a319 1240 }
01eabad4 1241 hammer2_chain_unlock(hmp, parent);
3ac6a319
MD
1242}
1243
1244/*
8cce658d 1245 * Extend the size of a file. The inode must be locked.
866d5273 1246 *
8cce658d 1247 * We may have to resize the block straddling the old EOF.
3ac6a319
MD
1248 */
1249static
1250void
8cce658d 1251hammer2_extend_file(hammer2_inode_t *ip, hammer2_key_t nsize)
3ac6a319 1252{
476d2aad 1253 hammer2_inode_data_t *ipdata;
8cce658d
MD
1254 hammer2_mount_t *hmp;
1255 hammer2_chain_t *parent;
1256 hammer2_chain_t *chain;
3ac6a319 1257 struct buf *bp;
8cce658d
MD
1258 hammer2_key_t osize;
1259 hammer2_key_t obase;
1260 hammer2_key_t nbase;
1261 hammer2_key_t leof;
1262 int oblksize;
1263 int nblksize;
1264 int nradix;
3ac6a319
MD
1265 int error;
1266
8cce658d
MD
1267 KKASSERT(ip->vp);
1268 hmp = ip->hmp;
1269
476d2aad
MD
1270 hammer2_chain_modify(hmp, ip->chain, 0);
1271 ipdata = &ip->chain->data->ipdata;
8cce658d 1272
3ac6a319 1273 /*
8cce658d 1274 * Nothing to do if the direct-data case is still intact
3ac6a319 1275 */
476d2aad 1276 if ((ipdata->op_flags & HAMMER2_OPFLAG_DIRECTDATA) &&
8cce658d 1277 nsize <= HAMMER2_EMBEDDED_BYTES) {
476d2aad 1278 ipdata->size = nsize;
004f88b4 1279 nvextendbuf(ip->vp,
476d2aad 1280 ipdata->size, nsize,
004f88b4
MD
1281 0, HAMMER2_EMBEDDED_BYTES,
1282 0, (int)nsize,
1283 1);
8cce658d
MD
1284 return;
1285 }
1286
1287 /*
1288 * Calculate the blocksize at the original EOF and resize the block
1289 * if necessary. Adjust the file size in the inode.
1290 */
476d2aad 1291 osize = ipdata->size;
8cce658d 1292 oblksize = hammer2_calc_logical(ip, osize, &obase, &leof);
476d2aad 1293 ipdata->size = nsize;
8cce658d
MD
1294 nblksize = hammer2_calc_logical(ip, osize, &nbase, &leof);
1295
1296 /*
1297 * Do all required vnode operations, but do not mess with the
1298 * buffer straddling the orignal EOF.
1299 */
1300 nvextendbuf(ip->vp,
476d2aad 1301 ipdata->size, nsize,
8cce658d
MD
1302 0, nblksize,
1303 0, (int)nsize & HAMMER2_PBUFMASK,
1304 1);
1305
1306 /*
1307 * Early return if we have no more work to do.
1308 */
1309 if (obase == nbase && oblksize == nblksize &&
476d2aad 1310 (ipdata->op_flags & HAMMER2_OPFLAG_DIRECTDATA) == 0) {
8cce658d
MD
1311 return;
1312 }
1313
1314 /*
1315 * We have work to do, including possibly resizing the buffer
004f88b4 1316 * at the previous EOF point and turning off DIRECTDATA mode.
8cce658d
MD
1317 */
1318 bp = NULL;
1319 if (((int)osize & HAMMER2_PBUFMASK)) {
1320 error = bread(ip->vp, obase, oblksize, &bp);
3ac6a319 1321 KKASSERT(error == 0);
8cce658d
MD
1322
1323 if (obase != nbase) {
004f88b4
MD
1324 if (oblksize != HAMMER2_PBUFSIZE)
1325 allocbuf(bp, HAMMER2_PBUFSIZE);
8cce658d 1326 } else {
004f88b4
MD
1327 if (oblksize != nblksize)
1328 allocbuf(bp, nblksize);
8cce658d 1329 }
8cce658d
MD
1330 }
1331
1332 /*
1333 * Disable direct-data mode by loading up a buffer cache buffer
1334 * with the data, then converting the inode data area into the
1335 * inode indirect block array area.
1336 */
476d2aad
MD
1337 if (ipdata->op_flags & HAMMER2_OPFLAG_DIRECTDATA) {
1338 ipdata->op_flags &= ~HAMMER2_OPFLAG_DIRECTDATA;
1339 bzero(&ipdata->u.blockset, sizeof(ipdata->u.blockset));
3ac6a319 1340 }
866d5273
MD
1341
1342 /*
8cce658d 1343 * Resize the chain element at the old EOF.
866d5273 1344 */
8cce658d 1345 if (((int)osize & HAMMER2_PBUFMASK)) {
5f6853df 1346retry:
476d2aad 1347 parent = ip->chain;
01eabad4 1348 error = hammer2_chain_lock(hmp, parent, HAMMER2_RESOLVE_ALWAYS);
8cce658d
MD
1349 KKASSERT(error == 0);
1350
9061bde5 1351 nradix = hammer2_allocsize(nblksize);
8cce658d
MD
1352
1353 chain = hammer2_chain_lookup(hmp, &parent,
1354 obase, obase,
01eabad4 1355 HAMMER2_LOOKUP_NODATA);
8cce658d
MD
1356 if (chain == NULL) {
1357 chain = hammer2_chain_create(hmp, parent, NULL,
1358 obase, nblksize,
1359 HAMMER2_BREF_TYPE_DATA,
5f6853df
MD
1360 nblksize, &error);
1361 if (chain == NULL) {
1362 KKASSERT(error == EAGAIN);
1363 hammer2_chain_unlock(hmp, parent);
1364 goto retry;
1365 }
476d2aad 1366 /*ip->delta_dcount += nblksize;*/
8cce658d
MD
1367 } else {
1368 KKASSERT(chain->bref.type == HAMMER2_BREF_TYPE_DATA);
28ee5f14 1369 hammer2_chain_resize(ip, chain, nradix,
01eabad4 1370 HAMMER2_MODIFY_OPTDATA);
8cce658d
MD
1371 }
1372 bp->b_bio2.bio_offset = chain->bref.data_off &
1373 HAMMER2_OFF_MASK;
01eabad4 1374 hammer2_chain_unlock(hmp, chain);
004f88b4
MD
1375 if (bp->b_bcount == HAMMER2_PBUFSIZE)
1376 bp->b_flags |= B_CLUSTEROK;
8cce658d 1377 bdwrite(bp);
01eabad4 1378 hammer2_chain_unlock(hmp, parent);
3ac6a319
MD
1379 }
1380}
1381
e118c14f 1382static
703720e4 1383int
e118c14f 1384hammer2_vop_nresolve(struct vop_nresolve_args *ap)
703720e4 1385{
e2e9e2db 1386 hammer2_inode_t *ip;
37494cab
MD
1387 hammer2_inode_t *dip;
1388 hammer2_mount_t *hmp;
1389 hammer2_chain_t *parent;
1390 hammer2_chain_t *chain;
476d2aad 1391 hammer2_chain_t *ochain;
37494cab
MD
1392 struct namecache *ncp;
1393 const uint8_t *name;
1394 size_t name_len;
1395 hammer2_key_t lhc;
1396 int error = 0;
1397 struct vnode *vp;
1398
1399 dip = VTOI(ap->a_dvp);
1400 hmp = dip->hmp;
1401 ncp = ap->a_nch->ncp;
1402 name = ncp->nc_name;
1403 name_len = ncp->nc_nlen;
1404 lhc = hammer2_dirhash(name, name_len);
1405
1406 /*
1407 * Note: In DragonFly the kernel handles '.' and '..'.
1408 */
e2e9e2db 1409 parent = hammer2_inode_lock_sh(dip);
37494cab 1410 chain = hammer2_chain_lookup(hmp, &parent,
c667909f 1411 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
a0ed3c24 1412 HAMMER2_LOOKUP_SHARED);
37494cab
MD
1413 while (chain) {
1414 if (chain->bref.type == HAMMER2_BREF_TYPE_INODE &&
37494cab
MD
1415 name_len == chain->data->ipdata.name_len &&
1416 bcmp(name, chain->data->ipdata.filename, name_len) == 0) {
1417 break;
1418 }
1419 chain = hammer2_chain_next(hmp, &parent, chain,
c667909f 1420 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
a0ed3c24 1421 HAMMER2_LOOKUP_SHARED);
37494cab 1422 }
e2e9e2db 1423 hammer2_inode_unlock_sh(dip, parent);
37494cab 1424
e708f8b9
MD
1425 /*
1426 * If the inode represents a forwarding entry for a hardlink we have
1427 * to locate the actual inode. The original ip is saved for possible
1428 * deconsolidation. (ip) will only be set to non-NULL when we have
1429 * to locate the real file via a hardlink. ip will be referenced but
1430 * not locked in that situation. chain is passed in locked and
1431 * returned locked.
a0ed3c24
MD
1432 *
1433 * XXX what kind of chain lock?
e708f8b9 1434 */
476d2aad
MD
1435 ochain = NULL;
1436 if (chain && chain->data->ipdata.type == HAMMER2_OBJTYPE_HARDLINK) {
1437 error = hammer2_hardlink_find(dip, &chain, &ochain);
e708f8b9 1438 if (error) {
004f88b4 1439 kprintf("hammer2: unable to find hardlink\n");
e708f8b9
MD
1440 if (chain) {
1441 hammer2_chain_unlock(hmp, chain);
1442 chain = NULL;
1443 }
1444 goto failed;
1445 }
1446 }
1447
1448 /*
1449 * Deconsolidate any hardlink whos nlinks == 1. Ignore errors.
1450 * If an error occurs chain and ip are left alone.
a0ed3c24
MD
1451 *
1452 * XXX upgrade shared lock?
e708f8b9 1453 */
476d2aad 1454 if (ochain && chain && chain->data->ipdata.nlinks == 1 && !hmp->ronly) {
e708f8b9 1455 kprintf("hammer2: need to unconsolidate hardlink for %s\n",
476d2aad
MD
1456 chain->data->ipdata.filename);
1457 /* XXX retain shared lock on dip? (currently not held) */
1458 hammer2_hardlink_deconsolidate(dip, &chain, &ochain);
e708f8b9
MD
1459 }
1460
1461 /*
1462 * Acquire the related vnode
9bab8c22
MD
1463 *
1464 * NOTE: For error processing, only ENOENT resolves the namecache
1465 * entry to NULL, otherwise we just return the error and
1466 * leave the namecache unresolved.
10252dc7
MD
1467 *
1468 * NOTE: multiple hammer2_inode structures can be aliased to the
1469 * same chain element, for example for hardlinks. This
1470 * use case does not 'reattach' inode associations that
1471 * might already exist, but always allocates a new one.
e708f8b9 1472 */
37494cab 1473 if (chain) {
10252dc7 1474 ip = hammer2_inode_get(dip->hmp, dip->pmp, dip, chain);
e2e9e2db 1475 vp = hammer2_igetv(ip, &error);
37494cab
MD
1476 if (error == 0) {
1477 vn_unlock(vp);
1478 cache_setvp(ap->a_nch, vp);
9bab8c22 1479 } else if (error == ENOENT) {
f3843dc2 1480 cache_setvp(ap->a_nch, NULL);
37494cab 1481 }
e2e9e2db
MD
1482 /*
1483 * don't break the API, chain is locked shared so unlock
1484 * it separately even though unlock_ex() currently doesn't
1485 * care.
1486 */
1487 hammer2_inode_unlock_ex(ip, NULL);
01eabad4 1488 hammer2_chain_unlock(hmp, chain);
10252dc7
MD
1489
1490 /*
1491 * The vp should not be released until after we've disposed
1492 * of our locks, because it might cause vop_inactive() to
1493 * be called.
1494 */
1495 if (vp)
1496 vrele(vp);
37494cab
MD
1497 } else {
1498 error = ENOENT;
1499 cache_setvp(ap->a_nch, NULL);
1500 }
9bab8c22
MD
1501failed:
1502 KASSERT(error || ap->a_nch->ncp->nc_vp != NULL,
1503 ("resolve error %d/%p chain %p ap %p\n",
1504 error, ap->a_nch->ncp->nc_vp, chain, ap));
476d2aad
MD
1505 if (ochain)
1506 hammer2_chain_drop(hmp, ochain);
37494cab
MD
1507 return error;
1508}
1509
1510static
1511int
1512hammer2_vop_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
1513{
e2e9e2db 1514 hammer2_chain_t *chain;
37494cab
MD
1515 hammer2_inode_t *dip;
1516 hammer2_inode_t *ip;
1517 hammer2_mount_t *hmp;
1518 int error;
1519
1520 dip = VTOI(ap->a_dvp);
1521 hmp = dip->hmp;
1522
1523 if ((ip = dip->pip) == NULL) {
1524 *ap->a_vpp = NULL;
1525 return ENOENT;
1526 }
e2e9e2db 1527 chain = hammer2_inode_lock_ex(ip);
37494cab 1528 *ap->a_vpp = hammer2_igetv(ip, &error);
e2e9e2db 1529 hammer2_inode_unlock_ex(ip, chain);
37494cab
MD
1530
1531 return error;
1532}
1533
1534static
1535int
1536hammer2_vop_nmkdir(struct vop_nmkdir_args *ap)
1537{
e2e9e2db 1538 hammer2_chain_t *nchain;
37494cab
MD
1539 hammer2_mount_t *hmp;
1540 hammer2_inode_t *dip;
1541 hammer2_inode_t *nip;
1542 struct namecache *ncp;
1543 const uint8_t *name;
1544 size_t name_len;
1545 int error;
1546
1547 dip = VTOI(ap->a_dvp);
1548 hmp = dip->hmp;
db71f61f
MD
1549 if (hmp->ronly)
1550 return (EROFS);
1551
37494cab
MD
1552 ncp = ap->a_nch->ncp;
1553 name = ncp->nc_name;
1554 name_len = ncp->nc_nlen;
1555
e4e20f48 1556 error = hammer2_inode_create(dip, ap->a_vap, ap->a_cred,
e2e9e2db 1557 name, name_len, &nip, &nchain);
37494cab
MD
1558 if (error) {
1559 KKASSERT(nip == NULL);
1560 *ap->a_vpp = NULL;
1561 return error;
1562 }
1563 *ap->a_vpp = hammer2_igetv(nip, &error);
e2e9e2db 1564 hammer2_inode_unlock_ex(nip, nchain);
37494cab
MD
1565
1566 if (error == 0) {
1567 cache_setunresolved(ap->a_nch);
1568 cache_setvp(ap->a_nch, *ap->a_vpp);
1569 }
1570 return error;
703720e4
MD
1571}
1572
db71f61f
MD
1573/*
1574 * Return the largest contiguous physical disk range for the logical
1575 * request.
1576 *
1577 * (struct vnode *vp, off_t loffset, off_t *doffsetp, int *runp, int *runb)
1578 */
e118c14f 1579static
703720e4 1580int
e118c14f 1581hammer2_vop_bmap(struct vop_bmap_args *ap)
703720e4 1582{
db71f61f
MD
1583 struct vnode *vp;
1584 hammer2_mount_t *hmp;
1585 hammer2_inode_t *ip;
1586 hammer2_chain_t *parent;
1587 hammer2_chain_t *chain;
6ba3b984
MD
1588 hammer2_key_t lbeg;
1589 hammer2_key_t lend;
1590 hammer2_off_t pbeg;
1591 hammer2_off_t pbytes;
1592 hammer2_off_t array[HAMMER2_BMAP_COUNT][2];
1593 int loff;
1594 int ai;
db71f61f
MD
1595
1596 /*
1597 * Only supported on regular files
1598 *
1599 * Only supported for read operations (required for cluster_read).
1600 * The block allocation is delayed for write operations.
1601 */
1602 vp = ap->a_vp;
1603 if (vp->v_type != VREG)
1604 return (EOPNOTSUPP);
1605 if (ap->a_cmd != BUF_CMD_READ)
1606 return (EOPNOTSUPP);
1607
1608 ip = VTOI(vp);
1609 hmp = ip->hmp;
6ba3b984 1610 bzero(array, sizeof(array));
5b4a2132 1611
6ba3b984
MD
1612 /*
1613 * Calculate logical range
1614 */
1615 KKASSERT((ap->a_loffset & HAMMER2_LBUFMASK64) == 0);
1616 lbeg = ap->a_loffset & HAMMER2_OFF_MASK_HI;
1617 lend = lbeg + HAMMER2_BMAP_COUNT * HAMMER2_PBUFSIZE - 1;
1618 if (lend < lbeg)
1619 lend = lbeg;
1620 loff = ap->a_loffset & HAMMER2_OFF_MASK_LO;
db71f61f 1621
e2e9e2db 1622 parent = hammer2_inode_lock_sh(ip);
6ba3b984
MD
1623 chain = hammer2_chain_lookup(hmp, &parent,
1624 lbeg, lend,
a0ed3c24
MD
1625 HAMMER2_LOOKUP_NODATA |
1626 HAMMER2_LOOKUP_SHARED);
3ac6a319 1627 if (chain == NULL) {
3ac6a319 1628 *ap->a_doffsetp = ZFOFFSET;
e2e9e2db 1629 hammer2_inode_unlock_sh(ip, parent);
6ba3b984
MD
1630 return (0);
1631 }
1632
1633 while (chain) {
1634 if (chain->bref.type == HAMMER2_BREF_TYPE_DATA) {
1635 ai = (chain->bref.key - lbeg) / HAMMER2_PBUFSIZE;
1636 KKASSERT(ai >= 0 && ai < HAMMER2_BMAP_COUNT);
1637 array[ai][0] = chain->bref.data_off & HAMMER2_OFF_MASK;
1638 array[ai][1] = chain->bytes;
1639 }
1640 chain = hammer2_chain_next(hmp, &parent, chain,
1641 lbeg, lend,
a0ed3c24
MD
1642 HAMMER2_LOOKUP_NODATA |
1643 HAMMER2_LOOKUP_SHARED);
db71f61f 1644 }
e2e9e2db 1645 hammer2_inode_unlock_sh(ip, parent);
6ba3b984
MD
1646
1647 /*
1648 * If the requested loffset is not mappable physically we can't
1649 * bmap. The caller will have to access the file data via a
1650 * device buffer.
1651 */
1652 if (array[0][0] == 0 || array[0][1] < loff + HAMMER2_LBUFSIZE) {
1653 *ap->a_doffsetp = NOOFFSET;
1654 return (0);
1655 }
1656
1657 /*
1658 * Calculate the physical disk offset range for array[0]
1659 */
1660 pbeg = array[0][0] + loff;
1661 pbytes = array[0][1] - loff;
1662
1663 for (ai = 1; ai < HAMMER2_BMAP_COUNT; ++ai) {
1664 if (array[ai][0] != pbeg + pbytes)
1665 break;
1666 pbytes += array[ai][1];
1667 }
1668
1669 *ap->a_doffsetp = pbeg;
1670 if (ap->a_runp)
1671 *ap->a_runp = pbytes;
db71f61f 1672 return (0);
703720e4
MD
1673}
1674
e118c14f 1675static
703720e4 1676int
e118c14f 1677hammer2_vop_open(struct vop_open_args *ap)
703720e4 1678{
703720e4
MD
1679 return vop_stdopen(ap);
1680}
1681
37aa19df 1682/*
db0c2eb3 1683 * hammer2_vop_advlock { vp, id, op, fl, flags }
37aa19df
MD
1684 */
1685static
1686int
1687hammer2_vop_advlock(struct vop_advlock_args *ap)
1688{
1689 hammer2_inode_t *ip = VTOI(ap->a_vp);
e2e9e2db 1690 hammer2_chain_t *chain;
476d2aad 1691 hammer2_off_t size;
37aa19df 1692
e2e9e2db
MD
1693 chain = hammer2_inode_lock_sh(ip);
1694 size = chain->data->ipdata.size;
1695 hammer2_inode_unlock_sh(ip, chain);
476d2aad 1696 return (lf_advlock(ap, &ip->advlock, size));
37aa19df
MD
1697}
1698
1699
c667909f
MD
1700static
1701int
1702hammer2_vop_close(struct vop_close_args *ap)
1703{
1704 return vop_stdclose(ap);
1705}
1706
1707/*
db0c2eb3
MD
1708 * hammer2_vop_nlink { nch, dvp, vp, cred }
1709 *
e708f8b9 1710 * Create a hardlink from (vp) to {dvp, nch}.
db0c2eb3
MD
1711 */
1712static
1713int
1714hammer2_vop_nlink(struct vop_nlink_args *ap)
1715{
e708f8b9 1716 hammer2_inode_t *dip; /* target directory to create link in */
db0c2eb3 1717 hammer2_inode_t *ip; /* inode we are hardlinking to */
99535653 1718 hammer2_inode_t *oip;
db0c2eb3 1719 hammer2_mount_t *hmp;
e2e9e2db
MD
1720 hammer2_chain_t *chain;
1721 hammer2_chain_t *ochain;
db0c2eb3
MD
1722 struct namecache *ncp;
1723 const uint8_t *name;
1724 size_t name_len;
1725 int error;
1726
1727 dip = VTOI(ap->a_dvp);
1728 hmp = dip->hmp;
1729 if (hmp->ronly)
1730 return (EROFS);
1731
e708f8b9
MD
1732 /*
1733 * (ip) is the inode we are linking to.
1734 */
99535653 1735 ip = oip = VTOI(ap->a_vp);
476d2aad 1736 hammer2_inode_ref(ip);
db0c2eb3
MD
1737
1738 ncp = ap->a_nch->ncp;
1739 name = ncp->nc_name;
1740 name_len = ncp->nc_nlen;
1741
e708f8b9
MD
1742 /*
1743 * Create a consolidated real file for the hardlink, adjust (ip),
1744 * and move the nlinks lock if necessary. Tell the function to
1745 * bump the hardlink count on the consolidated file.
1746 */
99535653 1747 error = hammer2_hardlink_consolidate(&ip, dip);
e708f8b9
MD
1748 if (error)
1749 goto done;
1750
1751 /*
99535653
MD
1752 * If the consolidation changed ip to a HARDLINK pointer we have
1753 * to adjust the vnode to point to the actual ip.
28ee5f14
MD
1754 *
1755 * XXX this can race against concurrent vnode ops.
99535653
MD
1756 */
1757 if (oip != ip) {
10252dc7 1758 hammer2_inode_ref(ip); /* vp ref+ */
e2e9e2db
MD
1759 chain = hammer2_inode_lock_ex(ip);
1760 ochain = hammer2_inode_lock_ex(oip);
10252dc7
MD
1761 if (ip->vp) {
1762 KKASSERT(ip->vp == ap->a_vp);
1763 hammer2_inode_drop(ip); /* vp already ref'd */
1764 } else {
1765 ip->vp = ap->a_vp;
1766 ap->a_vp->v_data = ip;
1767 }
1768 if (oip->vp) {
1769 KKASSERT(oip->vp == ap->a_vp);
1770 oip->vp = NULL;
1771 hammer2_inode_drop(oip); /* vp ref- */
1772 }
e2e9e2db
MD
1773 hammer2_inode_unlock_ex(oip, ochain);
1774 hammer2_inode_unlock_ex(ip, chain);
99535653
MD
1775 }
1776
1777 /*
1778 * The act of connecting the existing (ip) will properly bump the
1779 * nlinks count. However, vp will incorrectly point at the old
1780 * inode which has now been turned into a OBJTYPE_HARDLINK pointer.
1781 *
1782 * We must reconnect the vp.
e708f8b9 1783 */
e708f8b9 1784 error = hammer2_inode_connect(dip, ip, name, name_len);
db0c2eb3
MD
1785 if (error == 0) {
1786 cache_setunresolved(ap->a_nch);
1787 cache_setvp(ap->a_nch, ap->a_vp);
1788 }
e708f8b9 1789done:
476d2aad 1790 hammer2_inode_drop(ip);
db0c2eb3
MD
1791 return error;
1792}
1793
1794/*
1795 * hammer2_vop_ncreate { nch, dvp, vpp, cred, vap }
c667909f
MD
1796 *
1797 * The operating system has already ensured that the directory entry
1798 * does not exist and done all appropriate namespace locking.
1799 */
1800static
1801int
1802hammer2_vop_ncreate(struct vop_ncreate_args *ap)
1803{
1804 hammer2_mount_t *hmp;
1805 hammer2_inode_t *dip;
1806 hammer2_inode_t *nip;
e2e9e2db 1807 hammer2_chain_t *nchain;
c667909f
MD
1808 struct namecache *ncp;
1809 const uint8_t *name;
1810 size_t name_len;
1811 int error;
1812
1813 dip = VTOI(ap->a_dvp);
1814 hmp = dip->hmp;
1815 if (hmp->ronly)
1816 return (EROFS);
1817
1818 ncp = ap->a_nch->ncp;
1819 name = ncp->nc_name;
1820 name_len = ncp->nc_nlen;
1821
e4e20f48 1822 error = hammer2_inode_create(dip, ap->a_vap, ap->a_cred,
e2e9e2db 1823 name, name_len, &nip, &nchain);
c667909f
MD
1824 if (error) {
1825 KKASSERT(nip == NULL);
1826 *ap->a_vpp = NULL;
1827 return error;
1828 }
1829 *ap->a_vpp = hammer2_igetv(nip, &error);
e2e9e2db 1830 hammer2_inode_unlock_ex(nip, nchain);
c667909f
MD
1831
1832 if (error == 0) {
1833 cache_setunresolved(ap->a_nch);
1834 cache_setvp(ap->a_nch, *ap->a_vpp);
1835 }
1836 return error;
1837}
1838
4e2004ea
MD
1839/*
1840 * hammer2_vop_nsymlink { nch, dvp, vpp, cred, vap, target }
1841 */
1842static
1843int
1844hammer2_vop_nsymlink(struct vop_nsymlink_args *ap)
1845{
1846 hammer2_mount_t *hmp;
1847 hammer2_inode_t *dip;
1848 hammer2_inode_t *nip;
e2e9e2db 1849 hammer2_chain_t *nchain;
4e2004ea
MD
1850 struct namecache *ncp;
1851 const uint8_t *name;
1852 size_t name_len;
1853 int error;
1854
1855 dip = VTOI(ap->a_dvp);
1856 hmp = dip->hmp;
1857 if (hmp->ronly)
1858 return (EROFS);
1859
1860 ncp = ap->a_nch->ncp;
1861 name = ncp->nc_name;
1862 name_len = ncp->nc_nlen;
1863
1864 ap->a_vap->va_type = VLNK; /* enforce type */
1865
e4e20f48 1866 error = hammer2_inode_create(dip, ap->a_vap, ap->a_cred,
e2e9e2db 1867 name, name_len, &nip, &nchain);
4e2004ea
MD
1868 if (error) {
1869 KKASSERT(nip == NULL);
1870 *ap->a_vpp = NULL;
1871 return error;
1872 }
1873 *ap->a_vpp = hammer2_igetv(nip, &error);
1874
1875 /*
1876 * Build the softlink (~like file data) and finalize the namecache.
1877 */
1878 if (error == 0) {
1879 size_t bytes;
1880 struct uio auio;
1881 struct iovec aiov;
476d2aad 1882 hammer2_inode_data_t *nipdata;
4e2004ea 1883
e2e9e2db 1884 nipdata = &nchain->data->ipdata;
4e2004ea
MD
1885 bytes = strlen(ap->a_target);
1886
1887 if (bytes <= HAMMER2_EMBEDDED_BYTES) {
476d2aad 1888 KKASSERT(nipdata->op_flags &
4e2004ea 1889 HAMMER2_OPFLAG_DIRECTDATA);
476d2aad
MD
1890 bcopy(ap->a_target, nipdata->u.data, bytes);
1891 nipdata->size = bytes;
4e2004ea
MD
1892 } else {
1893 bzero(&auio, sizeof(auio));
1894 bzero(&aiov, sizeof(aiov));
1895 auio.uio_iov = &aiov;
1896 auio.uio_segflg = UIO_SYSSPACE;
1897 auio.uio_rw = UIO_WRITE;
1898 auio.uio_resid = bytes;
1899 auio.uio_iovcnt = 1;
1900 auio.uio_td = curthread;
1901 aiov.iov_base = ap->a_target;
1902 aiov.iov_len = bytes;
e2e9e2db
MD
1903 error = hammer2_write_file(nip, &nchain,
1904 &auio, IO_APPEND, 0);
4e2004ea
MD
1905 /* XXX handle error */
1906 error = 0;
1907 }
1908 }
e2e9e2db 1909 hammer2_inode_unlock_ex(nip, nchain);
4e2004ea
MD
1910
1911 /*
1912 * Finalize namecache
1913 */
1914 if (error == 0) {
1915 cache_setunresolved(ap->a_nch);
1916 cache_setvp(ap->a_nch, *ap->a_vpp);
1917 /* hammer2_knote(ap->a_dvp, NOTE_WRITE); */
1918 }
1919 return error;
1920}
1921
1922/*
1923 * hammer2_vop_nremove { nch, dvp, cred }
1924 */
1925static
1926int
1927hammer2_vop_nremove(struct vop_nremove_args *ap)
1928{
1929 hammer2_inode_t *dip;
1930 hammer2_mount_t *hmp;
1931 struct namecache *ncp;
1932 const uint8_t *name;
1933 size_t name_len;
1934 int error;
1935
1936 dip = VTOI(ap->a_dvp);
1937 hmp = dip->hmp;
1938 if (hmp->ronly)
1939 return(EROFS);
1940
1941 ncp = ap->a_nch->ncp;
1942 name = ncp->nc_name;
1943 name_len = ncp->nc_nlen;
1944
004f88b4 1945 error = hammer2_unlink_file(dip, name, name_len, 0, NULL);
4e2004ea 1946 if (error == 0) {
3fc4c63d 1947 cache_unlink(ap->a_nch);
4e2004ea
MD
1948 }
1949 return (error);
1950}
1951
1952/*
1953 * hammer2_vop_nrmdir { nch, dvp, cred }
1954 */
1955static
1956int
1957hammer2_vop_nrmdir(struct vop_nrmdir_args *ap)
1958{
1959 hammer2_inode_t *dip;
1960 hammer2_mount_t *hmp;
1961 struct namecache *ncp;
1962 const uint8_t *name;
1963 size_t name_len;
1964 int error;
1965
1966 dip = VTOI(ap->a_dvp);
1967 hmp = dip->hmp;
1968 if (hmp->ronly)
1969 return(EROFS);
1970
1971 ncp = ap->a_nch->ncp;
1972 name = ncp->nc_name;
1973 name_len = ncp->nc_nlen;
1974
004f88b4 1975 error = hammer2_unlink_file(dip, name, name_len, 1, NULL);
4e2004ea 1976 if (error == 0) {
3fc4c63d 1977 cache_unlink(ap->a_nch);
4e2004ea
MD
1978 }
1979 return (error);
1980}
1981
6934ae32
MD
1982/*
1983 * hammer2_vop_nrename { fnch, tnch, fdvp, tdvp, cred }
1984 */
4e2004ea
MD
1985static
1986int
1987hammer2_vop_nrename(struct vop_nrename_args *ap)
1988{
6934ae32
MD
1989 struct namecache *fncp;
1990 struct namecache *tncp;
1991 hammer2_inode_t *fdip;
1992 hammer2_inode_t *tdip;
1993 hammer2_inode_t *ip;
e2e9e2db 1994 hammer2_chain_t *chain;
6934ae32
MD
1995 hammer2_mount_t *hmp;
1996 const uint8_t *fname;
1997 size_t fname_len;
1998 const uint8_t *tname;
1999 size_t tname_len;
2000 int error;
2001
2002 if (ap->a_fdvp->v_mount != ap->a_tdvp->v_mount)
2003 return(EXDEV);
2004 if (ap->a_fdvp->v_mount != ap->a_fnch->ncp->nc_vp->v_mount)
2005 return(EXDEV);
2006
2007 fdip = VTOI(ap->a_fdvp); /* source directory */
2008 tdip = VTOI(ap->a_tdvp); /* target directory */
2009
2010 hmp = fdip->hmp; /* check read-only filesystem */
2011 if (hmp->ronly)
2012 return(EROFS);
2013
2014 fncp = ap->a_fnch->ncp; /* entry name in source */
2015 fname = fncp->nc_name;
2016 fname_len = fncp->nc_nlen;
2017
2018 tncp = ap->a_tnch->ncp; /* entry name in target */
2019 tname = tncp->nc_name;
2020 tname_len = tncp->nc_nlen;
2021
e708f8b9
MD
2022 /*
2023 * ip is the inode being removed. If this is a hardlink then
2024 * ip represents the actual file and not the hardlink marker.
2025 */
2026 ip = VTOI(fncp->nc_vp);
6934ae32
MD
2027
2028 /*
2029 * Keep a tight grip on the inode as removing it should disconnect
2030 * it and we don't want to destroy it.
222d9e22
MD
2031 *
2032 * NOTE: To avoid deadlocks we cannot lock (ip) while we are
e708f8b9
MD
2033 * unlinking elements from their directories. Locking
2034 * the nlinks field does not lock the whole inode.
6934ae32 2035 */
476d2aad 2036 hammer2_inode_ref(ip);
6934ae32
MD
2037
2038 /*
2039 * Remove target if it exists
2040 */
004f88b4 2041 error = hammer2_unlink_file(tdip, tname, tname_len, -1, NULL);
6934ae32
MD
2042 if (error && error != ENOENT)
2043 goto done;
2044 cache_setunresolved(ap->a_tnch);
6934ae32
MD
2045
2046 /*
99535653
MD
2047 * Disconnect (fdip, fname) from the source directory. This will
2048 * disconnect (ip) if it represents a direct file. If (ip) represents
2049 * a hardlink the HARDLINK pointer object will be removed but the
2050 * hardlink will stay intact.
e708f8b9
MD
2051 *
2052 * If (ip) is already hardlinked we have to resolve to a consolidated
2053 * file but we do not bump the nlinks count. (ip) must hold the nlinks
2054 * lock & ref for the operation. If the consolidated file has been
2055 * relocated (ip) will be adjusted and the related nlinks lock moved
2056 * along with it.
2057 *
2058 * If (ip) does not have multiple links we can just copy the physical
2059 * contents of the inode.
6934ae32 2060 */
e2e9e2db 2061 chain = hammer2_inode_lock_sh(ip);
10252dc7 2062 hammer2_chain_ref(hmp, chain); /* for unlink file */
e2e9e2db
MD
2063 if (chain->data->ipdata.nlinks > 1) {
2064 hammer2_inode_unlock_sh(ip, chain);
99535653 2065 error = hammer2_hardlink_consolidate(&ip, tdip);
e708f8b9
MD
2066 if (error)
2067 goto done;
476d2aad 2068 } else {
e2e9e2db 2069 hammer2_inode_unlock_sh(ip, chain);
e708f8b9 2070 }
10252dc7 2071 /* chain ref still intact */
5f6853df
MD
2072
2073 /*
2074 * NOTE! Because we are retaining (ip) the unlink can fail with
2075 * an EAGAIN.
2076 */
2077 for (;;) {
10252dc7 2078 error = hammer2_unlink_file(fdip, fname, fname_len, -1, chain);
5f6853df
MD
2079 if (error != EAGAIN)
2080 break;
2081 kprintf("hammer2_vop_nrename: unlink race %s\n", fname);
2082 tsleep(fdip, 0, "h2renr", 1);
2083 }
10252dc7 2084 hammer2_chain_drop(hmp, chain); /* drop temporary ref */
6934ae32
MD
2085 if (error)
2086 goto done;
2087
6934ae32
MD
2088 /*
2089 * Reconnect ip to target directory.
1c9f601e
MD
2090 *
2091 * WARNING: chain locks can lock buffer cache buffers, to avoid
2092 * deadlocks we want to unlock before issuing a cache_*()
2093 * op (that might have to lock a vnode).
6934ae32 2094 */
db0c2eb3 2095 error = hammer2_inode_connect(tdip, ip, tname, tname_len);
6934ae32
MD
2096 if (error == 0) {
2097 cache_rename(ap->a_fnch, ap->a_tnch);
2098 }
222d9e22 2099done:
476d2aad 2100 hammer2_inode_drop(ip);
6934ae32
MD
2101
2102 return (error);
4e2004ea
MD
2103}
2104
db71f61f
MD
2105static int hammer2_strategy_read(struct vop_strategy_args *ap);
2106static int hammer2_strategy_write(struct vop_strategy_args *ap);
2107
e118c14f 2108static
703720e4 2109int
e118c14f 2110hammer2_vop_strategy(struct vop_strategy_args *ap)
703720e4 2111{
703720e4
MD
2112 struct bio *biop;
2113 struct buf *bp;
703720e4
MD
2114 int error;
2115
703720e4
MD
2116 biop = ap->a_bio;
2117 bp = biop->bio_buf;
703720e4
MD
2118
2119 switch(bp->b_cmd) {
9c2e0de0 2120 case BUF_CMD_READ:
db71f61f 2121 error = hammer2_strategy_read(ap);
01eabad4 2122 ++hammer2_iod_file_read;
db71f61f 2123 break;
9c2e0de0 2124 case BUF_CMD_WRITE:
db71f61f 2125 error = hammer2_strategy_write(ap);
01eabad4 2126 ++hammer2_iod_file_write;
db71f61f 2127 break;
703720e4
MD
2128 default:
2129 bp->b_error = error = EINVAL;
2130 bp->b_flags |= B_ERROR;
2131 biodone(biop);
2132 break;
2133 }
2134
2135 return (error);
2136}
2137
db71f61f
MD
2138static
2139int
2140hammer2_strategy_read(struct vop_strategy_args *ap)
2141{
2142 struct buf *bp;
2143 struct bio *bio;
2144 struct bio *nbio;
2145 hammer2_mount_t *hmp;
2146 hammer2_inode_t *ip;
2147 hammer2_chain_t *parent;
2148 hammer2_chain_t *chain;
8cce658d 2149 hammer2_key_t lbase;
db71f61f
MD
2150
2151 bio = ap->a_bio;
2152 bp = bio->bio_buf;
2153 ip = VTOI(ap->a_vp);
2154 hmp = ip->hmp;
2155 nbio = push_bio(bio);
2156
8cce658d 2157 lbase = bio->bio_offset;
866d5273 2158 chain = NULL;
8cce658d 2159 KKASSERT(((int)lbase & HAMMER2_PBUFMASK) == 0);
db71f61f 2160
866d5273
MD
2161 /*
2162 * We must characterize the logical->physical translation if it
2163 * has not already been cached.
2164 *
2165 * Physical data references < LBUFSIZE are never cached. This
2166 * includes both small-block allocations and inode-embedded data.
2167 */
2168 if (nbio->bio_offset == NOOFFSET) {
e2e9e2db 2169 parent = hammer2_inode_lock_sh(ip);
c667909f 2170
8cce658d 2171 chain = hammer2_chain_lookup(hmp, &parent, lbase, lbase,
a0ed3c24
MD
2172 HAMMER2_LOOKUP_NODATA |
2173 HAMMER2_LOOKUP_SHARED);
3ac6a319
MD
2174 if (chain == NULL) {
2175 /*
2176 * Data is zero-fill
2177 */
2178 nbio->bio_offset = ZFOFFSET;
3ac6a319
MD
2179 } else if (chain->bref.type == HAMMER2_BREF_TYPE_INODE) {
2180 /*
8cce658d 2181 * Data is embedded in the inode (do nothing)
3ac6a319 2182 */
3ac6a319 2183 KKASSERT(chain == parent);
01eabad4 2184 hammer2_chain_unlock(hmp, chain);
866d5273
MD
2185 } else if (chain->bref.type == HAMMER2_BREF_TYPE_DATA) {
2186 /*
2187 * Data is on-media
866d5273 2188 */
8cce658d
MD
2189 KKASSERT(bp->b_bcount == chain->bytes);
2190 nbio->bio_offset = chain->bref.data_off &
2191 HAMMER2_OFF_MASK;
01eabad4 2192 hammer2_chain_unlock(hmp, chain);
8cce658d 2193 KKASSERT(nbio->bio_offset != 0);
db71f61f 2194 } else {
3ac6a319 2195 panic("hammer2_strategy_read: unknown bref type");
db71f61f 2196 }
e2e9e2db 2197 hammer2_inode_unlock_sh(ip, parent);
db71f61f 2198 }
866d5273 2199
8e12e3c9
MD
2200 if (hammer2_debug & 0x0020) {
2201 kprintf("read %016jx %016jx\n",
2202 bio->bio_offset, nbio->bio_offset);
2203 }
2204
866d5273 2205 if (nbio->bio_offset == ZFOFFSET) {
3ac6a319 2206 /*
866d5273 2207 * Data is zero-fill
3ac6a319
MD
2208 */
2209 bp->b_resid = 0;
2210 bp->b_error = 0;
8cce658d 2211 bzero(bp->b_data, bp->b_bcount);
3ac6a319 2212 biodone(nbio);
866d5273 2213 } else if (nbio->bio_offset != NOOFFSET) {
3ac6a319 2214 /*
8cce658d 2215 * Forward direct IO to the device
3ac6a319 2216 */
866d5273 2217 vn_strategy(hmp->devvp, nbio);
8cce658d 2218 } else {
866d5273 2219 /*
8cce658d 2220 * Data is embedded in inode.
866d5273 2221 */
8cce658d
MD
2222 bcopy(chain->data->ipdata.u.data, bp->b_data,
2223 HAMMER2_EMBEDDED_BYTES);
2224 bzero(bp->b_data + HAMMER2_EMBEDDED_BYTES,
2225 bp->b_bcount - HAMMER2_EMBEDDED_BYTES);
db71f61f
MD
2226 bp->b_resid = 0;
2227 bp->b_error = 0;
db71f61f 2228 biodone(nbio);
db71f61f
MD
2229 }
2230 return (0);
2231}
2232
2233static
2234int
2235hammer2_strategy_write(struct vop_strategy_args *ap)
2236{
2237 struct buf *bp;
2238 struct bio *bio;
2239 struct bio *nbio;
2240 hammer2_mount_t *hmp;
2241 hammer2_inode_t *ip;
db71f61f
MD
2242
2243 bio = ap->a_bio;
2244 bp = bio->bio_buf;
2245 ip = VTOI(ap->a_vp);
2246 hmp = ip->hmp;
2247 nbio = push_bio(bio);
2248
8cce658d
MD
2249 KKASSERT((bio->bio_offset & HAMMER2_PBUFMASK64) == 0);
2250 KKASSERT(nbio->bio_offset != 0 && nbio->bio_offset != ZFOFFSET);
db71f61f 2251
8cce658d 2252 if (nbio->bio_offset == NOOFFSET) {
3ac6a319 2253 /*
8cce658d 2254 * Must be embedded in the inode.
476d2aad
MD
2255 *
2256 * Because the inode is dirty, the chain must exist whether
2257 * the inode is locked or not. XXX
3ac6a319 2258 */
8cce658d 2259 KKASSERT(bio->bio_offset == 0);
476d2aad
MD
2260 KKASSERT(ip->chain && ip->chain->data);
2261 bcopy(bp->b_data, ip->chain->data->ipdata.u.data,
2262 HAMMER2_EMBEDDED_BYTES);
8cce658d
MD
2263 bp->b_resid = 0;
2264 bp->b_error = 0;
2265 biodone(nbio);
214f4a77
MD
2266
2267 /*
2910a90c 2268 * This special flag does not follow the normal MODIFY rules
214f4a77
MD
2269 * because we might deadlock on ip. Instead we depend on
2270 * VOP_FSYNC() to detect the case.
2271 */
476d2aad 2272 atomic_set_int(&ip->flags, HAMMER2_INODE_DIRTYEMBED);
8cce658d 2273 } else {
3ac6a319 2274 /*
8cce658d 2275 * Forward direct IO to the device
3ac6a319 2276 */
8cce658d 2277 vn_strategy(hmp->devvp, nbio);
a92f82c4 2278 }
db71f61f
MD
2279 return (0);
2280}
2281
2910a90c
MD
2282/*
2283 * hammer2_vop_ioctl { vp, command, data, fflag, cred }
2284 */
2285static
2286int
2287hammer2_vop_ioctl(struct vop_ioctl_args *ap)
2288{
2289 hammer2_mount_t *hmp;
2290 hammer2_inode_t *ip;
2291 int error;
2292
2293 ip = VTOI(ap->a_vp);
2294 hmp = ip->hmp;
2295
2296 error = hammer2_ioctl(ip, ap->a_command, (void *)ap->a_data,
2297 ap->a_fflag, ap->a_cred);
2298 return (error);
2299}
2300
e118c14f 2301static
f0206a67 2302int
e118c14f 2303hammer2_vop_mountctl(struct vop_mountctl_args *ap)
f0206a67
VS
2304{
2305 struct mount *mp;
e4e20f48 2306 hammer2_pfsmount_t *pmp;
f0206a67
VS
2307 int rc;
2308
2309 switch (ap->a_op) {
2310 case (MOUNTCTL_SET_EXPORT):
2311 mp = ap->a_head.a_ops->head.vv_mount;
e4e20f48 2312 pmp = MPTOPMP(mp);
f0206a67
VS
2313
2314 if (ap->a_ctllen != sizeof(struct export_args))
2315 rc = (EINVAL);
2316 else
e4e20f48 2317 rc = vfs_export(mp, &pmp->export,
10c5dee0 2318 (const struct export_args *)ap->a_ctl);
f0206a67
VS
2319 break;
2320 default:
2321 rc = vop_stdmountctl(ap);
2322 break;
2323 }
2324 return (rc);
2325}
2326
703720e4
MD
2327struct vop_ops hammer2_vnode_vops = {
2328 .vop_default = vop_defaultop,
e118c14f 2329 .vop_fsync = hammer2_vop_fsync,
703720e4
MD
2330 .vop_getpages = vop_stdgetpages,
2331 .vop_putpages = vop_stdputpages,
e118c14f 2332 .vop_access = hammer2_vop_access,
37aa19df 2333 .vop_advlock = hammer2_vop_advlock,
c667909f 2334 .vop_close = hammer2_vop_close,
db0c2eb3 2335 .vop_nlink = hammer2_vop_nlink,
c667909f 2336 .vop_ncreate = hammer2_vop_ncreate,
4e2004ea
MD
2337 .vop_nsymlink = hammer2_vop_nsymlink,
2338 .vop_nremove = hammer2_vop_nremove,
2339 .vop_nrmdir = hammer2_vop_nrmdir,
2340 .vop_nrename = hammer2_vop_nrename,
e118c14f 2341 .vop_getattr = hammer2_vop_getattr,
3ac6a319 2342 .vop_setattr = hammer2_vop_setattr,
e118c14f 2343 .vop_readdir = hammer2_vop_readdir,
4e2004ea 2344 .vop_readlink = hammer2_vop_readlink,
5b4a2132
MD
2345 .vop_getpages = vop_stdgetpages,
2346 .vop_putpages = vop_stdputpages,
e118c14f
MD
2347 .vop_read = hammer2_vop_read,
2348 .vop_write = hammer2_vop_write,
2349 .vop_open = hammer2_vop_open,
2350 .vop_inactive = hammer2_vop_inactive,
2351 .vop_reclaim = hammer2_vop_reclaim,
2352 .vop_nresolve = hammer2_vop_nresolve,
37494cab
MD
2353 .vop_nlookupdotdot = hammer2_vop_nlookupdotdot,
2354 .vop_nmkdir = hammer2_vop_nmkdir,
2910a90c 2355 .vop_ioctl = hammer2_vop_ioctl,
e118c14f
MD
2356 .vop_mountctl = hammer2_vop_mountctl,
2357 .vop_bmap = hammer2_vop_bmap,
2358 .vop_strategy = hammer2_vop_strategy,
703720e4
MD
2359};
2360
2361struct vop_ops hammer2_spec_vops = {
2362
2363};
2364
2365struct vop_ops hammer2_fifo_vops = {
2366
2367};