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