Use the new vop_stdpathconf() instead of rolling our own.
[dragonfly.git] / sys / vfs / hammer / hammer_vnops.c
CommitLineData
427e5fc6 1/*
b84de5af 2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
427e5fc6
MD
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
64950f31 34 * $DragonFly: src/sys/vfs/hammer/hammer_vnops.c,v 1.100 2008/09/28 05:04:21 dillon Exp $
427e5fc6
MD
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/fcntl.h>
41#include <sys/namecache.h>
42#include <sys/vnode.h>
43#include <sys/lockf.h>
44#include <sys/event.h>
45#include <sys/stat.h>
b3deaf57 46#include <sys/dirent.h>
c0ade690 47#include <vm/vm_extern.h>
7a04d74f 48#include <vfs/fifofs/fifo.h>
427e5fc6
MD
49#include "hammer.h"
50
51/*
52 * USERFS VNOPS
53 */
54/*static int hammer_vop_vnoperate(struct vop_generic_args *);*/
66325755
MD
55static int hammer_vop_fsync(struct vop_fsync_args *);
56static int hammer_vop_read(struct vop_read_args *);
57static int hammer_vop_write(struct vop_write_args *);
58static int hammer_vop_access(struct vop_access_args *);
59static int hammer_vop_advlock(struct vop_advlock_args *);
60static int hammer_vop_close(struct vop_close_args *);
61static int hammer_vop_ncreate(struct vop_ncreate_args *);
62static int hammer_vop_getattr(struct vop_getattr_args *);
63static int hammer_vop_nresolve(struct vop_nresolve_args *);
64static int hammer_vop_nlookupdotdot(struct vop_nlookupdotdot_args *);
65static int hammer_vop_nlink(struct vop_nlink_args *);
66static int hammer_vop_nmkdir(struct vop_nmkdir_args *);
67static int hammer_vop_nmknod(struct vop_nmknod_args *);
68static int hammer_vop_open(struct vop_open_args *);
66325755
MD
69static int hammer_vop_print(struct vop_print_args *);
70static int hammer_vop_readdir(struct vop_readdir_args *);
71static int hammer_vop_readlink(struct vop_readlink_args *);
72static int hammer_vop_nremove(struct vop_nremove_args *);
73static int hammer_vop_nrename(struct vop_nrename_args *);
74static int hammer_vop_nrmdir(struct vop_nrmdir_args *);
75static int hammer_vop_setattr(struct vop_setattr_args *);
76static int hammer_vop_strategy(struct vop_strategy_args *);
a99b9ea2 77static int hammer_vop_bmap(struct vop_bmap_args *ap);
66325755
MD
78static int hammer_vop_nsymlink(struct vop_nsymlink_args *);
79static int hammer_vop_nwhiteout(struct vop_nwhiteout_args *);
7dc57964 80static int hammer_vop_ioctl(struct vop_ioctl_args *);
513ca7d7 81static int hammer_vop_mountctl(struct vop_mountctl_args *);
427e5fc6 82
7a04d74f
MD
83static int hammer_vop_fifoclose (struct vop_close_args *);
84static int hammer_vop_fiforead (struct vop_read_args *);
85static int hammer_vop_fifowrite (struct vop_write_args *);
86
87static int hammer_vop_specclose (struct vop_close_args *);
88static int hammer_vop_specread (struct vop_read_args *);
89static int hammer_vop_specwrite (struct vop_write_args *);
90
427e5fc6
MD
91struct vop_ops hammer_vnode_vops = {
92 .vop_default = vop_defaultop,
93 .vop_fsync = hammer_vop_fsync,
c0ade690
MD
94 .vop_getpages = vop_stdgetpages,
95 .vop_putpages = vop_stdputpages,
427e5fc6
MD
96 .vop_read = hammer_vop_read,
97 .vop_write = hammer_vop_write,
98 .vop_access = hammer_vop_access,
99 .vop_advlock = hammer_vop_advlock,
100 .vop_close = hammer_vop_close,
101 .vop_ncreate = hammer_vop_ncreate,
102 .vop_getattr = hammer_vop_getattr,
103 .vop_inactive = hammer_vop_inactive,
104 .vop_reclaim = hammer_vop_reclaim,
105 .vop_nresolve = hammer_vop_nresolve,
106 .vop_nlookupdotdot = hammer_vop_nlookupdotdot,
107 .vop_nlink = hammer_vop_nlink,
108 .vop_nmkdir = hammer_vop_nmkdir,
109 .vop_nmknod = hammer_vop_nmknod,
110 .vop_open = hammer_vop_open,
64950f31 111 .vop_pathconf = vop_stdpathconf,
427e5fc6
MD
112 .vop_print = hammer_vop_print,
113 .vop_readdir = hammer_vop_readdir,
114 .vop_readlink = hammer_vop_readlink,
115 .vop_nremove = hammer_vop_nremove,
116 .vop_nrename = hammer_vop_nrename,
117 .vop_nrmdir = hammer_vop_nrmdir,
118 .vop_setattr = hammer_vop_setattr,
a99b9ea2 119 .vop_bmap = hammer_vop_bmap,
427e5fc6
MD
120 .vop_strategy = hammer_vop_strategy,
121 .vop_nsymlink = hammer_vop_nsymlink,
7dc57964 122 .vop_nwhiteout = hammer_vop_nwhiteout,
513ca7d7
MD
123 .vop_ioctl = hammer_vop_ioctl,
124 .vop_mountctl = hammer_vop_mountctl
427e5fc6
MD
125};
126
7a04d74f
MD
127struct vop_ops hammer_spec_vops = {
128 .vop_default = spec_vnoperate,
129 .vop_fsync = hammer_vop_fsync,
130 .vop_read = hammer_vop_specread,
131 .vop_write = hammer_vop_specwrite,
132 .vop_access = hammer_vop_access,
133 .vop_close = hammer_vop_specclose,
134 .vop_getattr = hammer_vop_getattr,
135 .vop_inactive = hammer_vop_inactive,
136 .vop_reclaim = hammer_vop_reclaim,
137 .vop_setattr = hammer_vop_setattr
138};
139
140struct vop_ops hammer_fifo_vops = {
141 .vop_default = fifo_vnoperate,
142 .vop_fsync = hammer_vop_fsync,
143 .vop_read = hammer_vop_fiforead,
144 .vop_write = hammer_vop_fifowrite,
145 .vop_access = hammer_vop_access,
146 .vop_close = hammer_vop_fifoclose,
147 .vop_getattr = hammer_vop_getattr,
148 .vop_inactive = hammer_vop_inactive,
149 .vop_reclaim = hammer_vop_reclaim,
150 .vop_setattr = hammer_vop_setattr
151};
152
0832c9bb
MD
153#ifdef DEBUG_TRUNCATE
154struct hammer_inode *HammerTruncIp;
155#endif
156
b84de5af 157static int hammer_dounlink(hammer_transaction_t trans, struct nchandle *nch,
d7e278bb
MD
158 struct vnode *dvp, struct ucred *cred,
159 int flags, int isdir);
8cd0a023
MD
160static int hammer_vop_strategy_read(struct vop_strategy_args *ap);
161static int hammer_vop_strategy_write(struct vop_strategy_args *ap);
162
427e5fc6
MD
163#if 0
164static
165int
166hammer_vop_vnoperate(struct vop_generic_args *)
167{
168 return (VOCALL(&hammer_vnode_vops, ap));
169}
170#endif
171
66325755
MD
172/*
173 * hammer_vop_fsync { vp, waitfor }
ddfdf542
MD
174 *
175 * fsync() an inode to disk and wait for it to be completely committed
176 * such that the information would not be undone if a crash occured after
177 * return.
66325755 178 */
427e5fc6
MD
179static
180int
66325755 181hammer_vop_fsync(struct vop_fsync_args *ap)
427e5fc6 182{
b84de5af 183 hammer_inode_t ip = VTOI(ap->a_vp);
c0ade690 184
7a61b85d 185 ++hammer_count_fsyncs;
e8599db1 186 vfsync(ap->a_vp, ap->a_waitfor, 1, NULL, NULL);
af209b0f 187 hammer_flush_inode(ip, HAMMER_FLUSH_SIGNAL);
b424ca30
MD
188 if (ap->a_waitfor == MNT_WAIT) {
189 vn_unlock(ap->a_vp);
b84de5af 190 hammer_wait_inode(ip);
b424ca30
MD
191 vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
192 }
059819e3 193 return (ip->error);
427e5fc6
MD
194}
195
66325755
MD
196/*
197 * hammer_vop_read { vp, uio, ioflag, cred }
198 */
427e5fc6
MD
199static
200int
66325755 201hammer_vop_read(struct vop_read_args *ap)
427e5fc6 202{
66325755 203 struct hammer_transaction trans;
c0ade690 204 hammer_inode_t ip;
66325755
MD
205 off_t offset;
206 struct buf *bp;
207 struct uio *uio;
208 int error;
209 int n;
8cd0a023 210 int seqcount;
4a2796f3
MD
211 int ioseqcount;
212 int blksize;
66325755
MD
213
214 if (ap->a_vp->v_type != VREG)
215 return (EINVAL);
216 ip = VTOI(ap->a_vp);
217 error = 0;
4a2796f3
MD
218 uio = ap->a_uio;
219
220 /*
221 * Allow the UIO's size to override the sequential heuristic.
222 */
223 blksize = hammer_blocksize(uio->uio_offset);
224 seqcount = (uio->uio_resid + (blksize - 1)) / blksize;
225 ioseqcount = ap->a_ioflag >> 16;
226 if (seqcount < ioseqcount)
227 seqcount = ioseqcount;
66325755 228
8cd0a023 229 hammer_start_transaction(&trans, ip->hmp);
66325755
MD
230
231 /*
4a2796f3
MD
232 * Access the data typically in HAMMER_BUFSIZE blocks via the
233 * buffer cache, but HAMMER may use a variable block size based
234 * on the offset.
66325755 235 */
11ad5ade 236 while (uio->uio_resid > 0 && uio->uio_offset < ip->ino_data.size) {
4a2796f3
MD
237 int64_t base_offset;
238 int64_t file_limit;
239
240 blksize = hammer_blocksize(uio->uio_offset);
241 offset = (int)uio->uio_offset & (blksize - 1);
242 base_offset = uio->uio_offset - offset;
243
1b0ab2c3 244 if (hammer_cluster_enable) {
4a2796f3
MD
245 /*
246 * Use file_limit to prevent cluster_read() from
247 * creating buffers of the wrong block size past
248 * the demarc.
249 */
250 file_limit = ip->ino_data.size;
251 if (base_offset < HAMMER_XDEMARC &&
252 file_limit > HAMMER_XDEMARC) {
253 file_limit = HAMMER_XDEMARC;
254 }
255 error = cluster_read(ap->a_vp,
256 file_limit, base_offset,
257 blksize, MAXPHYS,
258 seqcount, &bp);
a99b9ea2 259 } else {
4a2796f3 260 error = bread(ap->a_vp, base_offset, blksize, &bp);
a99b9ea2 261 }
66325755 262 if (error) {
4a2796f3 263 kprintf("error %d\n", error);
66325755
MD
264 brelse(bp);
265 break;
266 }
7bc5b8c2 267
c0ade690 268 /* bp->b_flags |= B_CLUSTEROK; temporarily disabled */
4a2796f3 269 n = blksize - offset;
66325755
MD
270 if (n > uio->uio_resid)
271 n = uio->uio_resid;
11ad5ade
MD
272 if (n > ip->ino_data.size - uio->uio_offset)
273 n = (int)(ip->ino_data.size - uio->uio_offset);
66325755 274 error = uiomove((char *)bp->b_data + offset, n, uio);
7bc5b8c2
MD
275
276 /* data has a lower priority then meta-data */
277 bp->b_flags |= B_AGE;
66325755 278 bqrelse(bp);
af209b0f
MD
279 if (error)
280 break;
ce0138a6 281 hammer_stats_file_read += n;
66325755 282 }
b84de5af
MD
283 if ((ip->flags & HAMMER_INODE_RO) == 0 &&
284 (ip->hmp->mp->mnt_flag & MNT_NOATIME) == 0) {
bcac4bbb 285 ip->ino_data.atime = trans.time;
ddfdf542 286 hammer_modify_inode(ip, HAMMER_INODE_ATIME);
b84de5af
MD
287 }
288 hammer_done_transaction(&trans);
66325755 289 return (error);
427e5fc6
MD
290}
291
66325755
MD
292/*
293 * hammer_vop_write { vp, uio, ioflag, cred }
294 */
427e5fc6
MD
295static
296int
66325755 297hammer_vop_write(struct vop_write_args *ap)
427e5fc6 298{
66325755
MD
299 struct hammer_transaction trans;
300 struct hammer_inode *ip;
4a2796f3 301 hammer_mount_t hmp;
66325755 302 struct uio *uio;
4a2796f3 303 int offset;
47637bff 304 off_t base_offset;
66325755
MD
305 struct buf *bp;
306 int error;
307 int n;
c0ade690 308 int flags;
4a2796f3 309 int delta;
cb51be26 310 int seqcount;
66325755
MD
311
312 if (ap->a_vp->v_type != VREG)
313 return (EINVAL);
314 ip = VTOI(ap->a_vp);
4a2796f3 315 hmp = ip->hmp;
66325755 316 error = 0;
cb51be26 317 seqcount = ap->a_ioflag >> 16;
66325755 318
d113fda1
MD
319 if (ip->flags & HAMMER_INODE_RO)
320 return (EROFS);
321
66325755
MD
322 /*
323 * Create a transaction to cover the operations we perform.
324 */
4a2796f3 325 hammer_start_transaction(&trans, hmp);
66325755
MD
326 uio = ap->a_uio;
327
328 /*
329 * Check append mode
330 */
331 if (ap->a_ioflag & IO_APPEND)
11ad5ade 332 uio->uio_offset = ip->ino_data.size;
66325755
MD
333
334 /*
af209b0f
MD
335 * Check for illegal write offsets. Valid range is 0...2^63-1.
336 *
337 * NOTE: the base_off assignment is required to work around what
338 * I consider to be a GCC-4 optimization bug.
66325755 339 */
af209b0f
MD
340 if (uio->uio_offset < 0) {
341 hammer_done_transaction(&trans);
342 return (EFBIG);
343 }
344 base_offset = uio->uio_offset + uio->uio_resid; /* work around gcc-4 */
345 if (uio->uio_resid > 0 && base_offset <= 0) {
b84de5af 346 hammer_done_transaction(&trans);
66325755 347 return (EFBIG);
9c448776 348 }
66325755
MD
349
350 /*
4a2796f3
MD
351 * Access the data typically in HAMMER_BUFSIZE blocks via the
352 * buffer cache, but HAMMER may use a variable block size based
353 * on the offset.
66325755
MD
354 */
355 while (uio->uio_resid > 0) {
d5ef456e 356 int fixsize = 0;
4a2796f3
MD
357 int blksize;
358 int blkmask;
d5ef456e 359
93291532 360 if ((error = hammer_checkspace(hmp, HAMMER_CHKSPC_WRITE)) != 0)
e63644f0
MD
361 break;
362
a9d52b76
MD
363 blksize = hammer_blocksize(uio->uio_offset);
364
059819e3 365 /*
4a2796f3
MD
366 * Do not allow HAMMER to blow out the buffer cache. Very
367 * large UIOs can lockout other processes due to bwillwrite()
368 * mechanics.
47637bff 369 *
df301614
MD
370 * The hammer inode is not locked during these operations.
371 * The vnode is locked which can interfere with the pageout
372 * daemon for non-UIO_NOCOPY writes but should not interfere
373 * with the buffer cache. Even so, we cannot afford to
374 * allow the pageout daemon to build up too many dirty buffer
375 * cache buffers.
376 */
e4a5ff06 377 /*if (((int)uio->uio_offset & (blksize - 1)) == 0)*/
df301614
MD
378 bwillwrite(blksize);
379
380 /*
e4a5ff06
MD
381 * Do not allow HAMMER to blow out system memory by
382 * accumulating too many records. Records are so well
383 * decoupled from the buffer cache that it is possible
384 * for userland to push data out to the media via
385 * direct-write, but build up the records queued to the
386 * backend faster then the backend can flush them out.
387 * HAMMER has hit its write limit but the frontend has
388 * no pushback to slow it down.
059819e3 389 */
df301614 390 if (hmp->rsv_recs > hammer_limit_recs / 2) {
4a2796f3 391 /*
df301614 392 * Get the inode on the flush list
4a2796f3 393 */
df301614
MD
394 if (ip->rsv_recs >= 64)
395 hammer_flush_inode(ip, HAMMER_FLUSH_SIGNAL);
396 else if (ip->rsv_recs >= 16)
397 hammer_flush_inode(ip, 0);
4a2796f3
MD
398
399 /*
df301614
MD
400 * Keep the flusher going if the system keeps
401 * queueing records.
4a2796f3 402 */
df301614
MD
403 delta = hmp->count_newrecords -
404 hmp->last_newrecords;
405 if (delta < 0 || delta > hammer_limit_recs / 2) {
406 hmp->last_newrecords = hmp->count_newrecords;
407 hammer_sync_hmp(hmp, MNT_NOWAIT);
4a2796f3
MD
408 }
409
df301614
MD
410 /*
411 * If we have gotten behind start slowing
412 * down the writers.
413 */
414 delta = (hmp->rsv_recs - hammer_limit_recs) *
415 hz / hammer_limit_recs;
416 if (delta > 0)
417 tsleep(&trans, 0, "hmrslo", delta);
059819e3
MD
418 }
419
4a2796f3
MD
420 /*
421 * Calculate the blocksize at the current offset and figure
422 * out how much we can actually write.
423 */
4a2796f3
MD
424 blkmask = blksize - 1;
425 offset = (int)uio->uio_offset & blkmask;
426 base_offset = uio->uio_offset & ~(int64_t)blkmask;
427 n = blksize - offset;
d5ef456e
MD
428 if (n > uio->uio_resid)
429 n = uio->uio_resid;
11ad5ade 430 if (uio->uio_offset + n > ip->ino_data.size) {
d5ef456e
MD
431 vnode_pager_setsize(ap->a_vp, uio->uio_offset + n);
432 fixsize = 1;
433 }
434
c0ade690
MD
435 if (uio->uio_segflg == UIO_NOCOPY) {
436 /*
437 * Issuing a write with the same data backing the
438 * buffer. Instantiate the buffer to collect the
439 * backing vm pages, then read-in any missing bits.
440 *
441 * This case is used by vop_stdputpages().
442 */
47637bff 443 bp = getblk(ap->a_vp, base_offset,
4a2796f3 444 blksize, GETBLK_BHEAVY, 0);
c0ade690
MD
445 if ((bp->b_flags & B_CACHE) == 0) {
446 bqrelse(bp);
47637bff 447 error = bread(ap->a_vp, base_offset,
4a2796f3 448 blksize, &bp);
c0ade690 449 }
4a2796f3 450 } else if (offset == 0 && uio->uio_resid >= blksize) {
c0ade690 451 /*
a5fddc16
MD
452 * Even though we are entirely overwriting the buffer
453 * we may still have to zero it out to avoid a
454 * mmap/write visibility issue.
c0ade690 455 */
4a2796f3 456 bp = getblk(ap->a_vp, base_offset, blksize, GETBLK_BHEAVY, 0);
a5fddc16
MD
457 if ((bp->b_flags & B_CACHE) == 0)
458 vfs_bio_clrbuf(bp);
47637bff 459 } else if (base_offset >= ip->ino_data.size) {
c0ade690 460 /*
a5fddc16
MD
461 * If the base offset of the buffer is beyond the
462 * file EOF, we don't have to issue a read.
c0ade690 463 */
47637bff 464 bp = getblk(ap->a_vp, base_offset,
4a2796f3 465 blksize, GETBLK_BHEAVY, 0);
66325755
MD
466 vfs_bio_clrbuf(bp);
467 } else {
c0ade690
MD
468 /*
469 * Partial overwrite, read in any missing bits then
470 * replace the portion being written.
471 */
4a2796f3 472 error = bread(ap->a_vp, base_offset, blksize, &bp);
d5ef456e
MD
473 if (error == 0)
474 bheavy(bp);
66325755 475 }
47637bff 476 if (error == 0) {
4a2796f3 477 error = uiomove((char *)bp->b_data + offset,
47637bff
MD
478 n, uio);
479 }
d5ef456e
MD
480
481 /*
482 * If we screwed up we have to undo any VM size changes we
483 * made.
484 */
66325755
MD
485 if (error) {
486 brelse(bp);
d5ef456e 487 if (fixsize) {
11ad5ade 488 vtruncbuf(ap->a_vp, ip->ino_data.size,
4a2796f3 489 hammer_blocksize(ip->ino_data.size));
d5ef456e 490 }
66325755
MD
491 break;
492 }
ce0138a6 493 hammer_stats_file_write += n;
c0ade690 494 /* bp->b_flags |= B_CLUSTEROK; temporarily disabled */
11ad5ade
MD
495 if (ip->ino_data.size < uio->uio_offset) {
496 ip->ino_data.size = uio->uio_offset;
497 flags = HAMMER_INODE_DDIRTY;
498 vnode_pager_setsize(ap->a_vp, ip->ino_data.size);
c0ade690 499 } else {
d113fda1 500 flags = 0;
66325755 501 }
11ad5ade 502 ip->ino_data.mtime = trans.time;
ddfdf542 503 flags |= HAMMER_INODE_MTIME | HAMMER_INODE_BUFS;
47637bff 504 hammer_modify_inode(ip, flags);
32c90105 505
1b0ab2c3
MD
506 /*
507 * Once we dirty the buffer any cached zone-X offset
508 * becomes invalid. HAMMER NOTE: no-history mode cannot
509 * allow overwriting over the same data sector unless
510 * we provide UNDOs for the old data, which we don't.
511 */
512 bp->b_bio2.bio_offset = NOOFFSET;
513
47637bff
MD
514 /*
515 * Final buffer disposition.
516 */
cb51be26 517 bp->b_flags |= B_AGE;
66325755
MD
518 if (ap->a_ioflag & IO_SYNC) {
519 bwrite(bp);
520 } else if (ap->a_ioflag & IO_DIRECT) {
66325755 521 bawrite(bp);
4a2796f3
MD
522 } else {
523 bdwrite(bp);
524 }
66325755 525 }
b84de5af 526 hammer_done_transaction(&trans);
66325755 527 return (error);
427e5fc6
MD
528}
529
66325755
MD
530/*
531 * hammer_vop_access { vp, mode, cred }
532 */
427e5fc6
MD
533static
534int
66325755 535hammer_vop_access(struct vop_access_args *ap)
427e5fc6 536{
66325755
MD
537 struct hammer_inode *ip = VTOI(ap->a_vp);
538 uid_t uid;
539 gid_t gid;
540 int error;
541
ce0138a6 542 ++hammer_stats_file_iopsr;
66325755
MD
543 uid = hammer_to_unix_xid(&ip->ino_data.uid);
544 gid = hammer_to_unix_xid(&ip->ino_data.gid);
545
546 error = vop_helper_access(ap, uid, gid, ip->ino_data.mode,
547 ip->ino_data.uflags);
548 return (error);
427e5fc6
MD
549}
550
66325755
MD
551/*
552 * hammer_vop_advlock { vp, id, op, fl, flags }
553 */
427e5fc6
MD
554static
555int
66325755 556hammer_vop_advlock(struct vop_advlock_args *ap)
427e5fc6 557{
4a2796f3 558 hammer_inode_t ip = VTOI(ap->a_vp);
66325755 559
11ad5ade 560 return (lf_advlock(ap, &ip->advlock, ip->ino_data.size));
427e5fc6
MD
561}
562
66325755
MD
563/*
564 * hammer_vop_close { vp, fflag }
565 */
427e5fc6
MD
566static
567int
66325755 568hammer_vop_close(struct vop_close_args *ap)
427e5fc6 569{
21fde338 570 /*hammer_inode_t ip = VTOI(ap->a_vp);*/
a89aec1b 571 return (vop_stdclose(ap));
427e5fc6
MD
572}
573
66325755
MD
574/*
575 * hammer_vop_ncreate { nch, dvp, vpp, cred, vap }
576 *
577 * The operating system has already ensured that the directory entry
578 * does not exist and done all appropriate namespace locking.
579 */
427e5fc6
MD
580static
581int
66325755 582hammer_vop_ncreate(struct vop_ncreate_args *ap)
427e5fc6 583{
66325755
MD
584 struct hammer_transaction trans;
585 struct hammer_inode *dip;
586 struct hammer_inode *nip;
587 struct nchandle *nch;
588 int error;
589
590 nch = ap->a_nch;
591 dip = VTOI(ap->a_dvp);
592
d113fda1
MD
593 if (dip->flags & HAMMER_INODE_RO)
594 return (EROFS);
93291532 595 if ((error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_CREATE)) != 0)
e63644f0 596 return (error);
d113fda1 597
66325755
MD
598 /*
599 * Create a transaction to cover the operations we perform.
600 */
8cd0a023 601 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 602 ++hammer_stats_file_iopsw;
66325755
MD
603
604 /*
605 * Create a new filesystem object of the requested type. The
b84de5af
MD
606 * returned inode will be referenced and shared-locked to prevent
607 * it from being moved to the flusher.
66325755 608 */
8cd0a023 609
5a930e66 610 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred,
ea434b6f 611 dip, NULL, &nip);
66325755 612 if (error) {
77062c8a 613 hkprintf("hammer_create_inode error %d\n", error);
b84de5af 614 hammer_done_transaction(&trans);
66325755
MD
615 *ap->a_vpp = NULL;
616 return (error);
617 }
66325755
MD
618
619 /*
620 * Add the new filesystem object to the directory. This will also
621 * bump the inode's link count.
622 */
5a930e66
MD
623 error = hammer_ip_add_directory(&trans, dip,
624 nch->ncp->nc_name, nch->ncp->nc_nlen,
625 nip);
0b075555 626 if (error)
77062c8a 627 hkprintf("hammer_ip_add_directory error %d\n", error);
66325755
MD
628
629 /*
630 * Finish up.
631 */
632 if (error) {
a89aec1b 633 hammer_rel_inode(nip, 0);
b84de5af 634 hammer_done_transaction(&trans);
66325755
MD
635 *ap->a_vpp = NULL;
636 } else {
e8599db1 637 error = hammer_get_vnode(nip, ap->a_vpp);
b84de5af 638 hammer_done_transaction(&trans);
a89aec1b
MD
639 hammer_rel_inode(nip, 0);
640 if (error == 0) {
641 cache_setunresolved(ap->a_nch);
642 cache_setvp(ap->a_nch, *ap->a_vpp);
643 }
66325755
MD
644 }
645 return (error);
427e5fc6
MD
646}
647
66325755
MD
648/*
649 * hammer_vop_getattr { vp, vap }
98f7132d
MD
650 *
651 * Retrieve an inode's attribute information. When accessing inodes
652 * historically we fake the atime field to ensure consistent results.
653 * The atime field is stored in the B-Tree element and allowed to be
654 * updated without cycling the element.
66325755 655 */
427e5fc6
MD
656static
657int
66325755 658hammer_vop_getattr(struct vop_getattr_args *ap)
427e5fc6 659{
66325755
MD
660 struct hammer_inode *ip = VTOI(ap->a_vp);
661 struct vattr *vap = ap->a_vap;
662
a56cb012
MD
663 /*
664 * We want the fsid to be different when accessing a filesystem
665 * with different as-of's so programs like diff don't think
666 * the files are the same.
667 *
668 * We also want the fsid to be the same when comparing snapshots,
669 * or when comparing mirrors (which might be backed by different
670 * physical devices). HAMMER fsids are based on the PFS's
671 * shared_uuid field.
672 *
673 * XXX there is a chance of collision here. The va_fsid reported
674 * by stat is different from the more involved fsid used in the
675 * mount structure.
c82af904 676 */
ce0138a6 677 ++hammer_stats_file_iopsr;
a56cb012
MD
678 vap->va_fsid = ip->pfsm->fsid_udev ^ (u_int32_t)ip->obj_asof ^
679 (u_int32_t)(ip->obj_asof >> 32);
680
11ad5ade 681 vap->va_fileid = ip->ino_leaf.base.obj_id;
66325755 682 vap->va_mode = ip->ino_data.mode;
11ad5ade 683 vap->va_nlink = ip->ino_data.nlinks;
66325755
MD
684 vap->va_uid = hammer_to_unix_xid(&ip->ino_data.uid);
685 vap->va_gid = hammer_to_unix_xid(&ip->ino_data.gid);
686 vap->va_rmajor = 0;
687 vap->va_rminor = 0;
11ad5ade 688 vap->va_size = ip->ino_data.size;
bcac4bbb 689
f437a2ab
MD
690 /*
691 * Special case for @@PFS softlinks. The actual size of the
692 * expanded softlink is "@@0x%016llx:%05d" == 26 bytes.
693 */
694 if (ip->ino_data.obj_type == HAMMER_OBJTYPE_SOFTLINK &&
695 ip->ino_data.size == 10 &&
696 ip->obj_asof == HAMMER_MAX_TID &&
697 ip->obj_localization == 0 &&
698 strncmp(ip->ino_data.ext.symlink, "@@PFS", 5) == 0) {
699 vap->va_size = 26;
700 }
701
bcac4bbb
MD
702 /*
703 * We must provide a consistent atime and mtime for snapshots
704 * so people can do a 'tar cf - ... | md5' on them and get
705 * consistent results.
706 */
707 if (ip->flags & HAMMER_INODE_RO) {
ddfdf542
MD
708 hammer_time_to_timespec(ip->ino_data.ctime, &vap->va_atime);
709 hammer_time_to_timespec(ip->ino_data.ctime, &vap->va_mtime);
bcac4bbb 710 } else {
ddfdf542
MD
711 hammer_time_to_timespec(ip->ino_data.atime, &vap->va_atime);
712 hammer_time_to_timespec(ip->ino_data.mtime, &vap->va_mtime);
bcac4bbb 713 }
ddfdf542 714 hammer_time_to_timespec(ip->ino_data.ctime, &vap->va_ctime);
66325755
MD
715 vap->va_flags = ip->ino_data.uflags;
716 vap->va_gen = 1; /* hammer inums are unique for all time */
bf686dbe 717 vap->va_blocksize = HAMMER_BUFSIZE;
4a2796f3
MD
718 if (ip->ino_data.size >= HAMMER_XDEMARC) {
719 vap->va_bytes = (ip->ino_data.size + HAMMER_XBUFMASK64) &
720 ~HAMMER_XBUFMASK64;
721 } else if (ip->ino_data.size > HAMMER_BUFSIZE / 2) {
722 vap->va_bytes = (ip->ino_data.size + HAMMER_BUFMASK64) &
723 ~HAMMER_BUFMASK64;
724 } else {
725 vap->va_bytes = (ip->ino_data.size + 15) & ~15;
726 }
64950f31 727
11ad5ade 728 vap->va_type = hammer_get_vnode_type(ip->ino_data.obj_type);
66325755 729 vap->va_filerev = 0; /* XXX */
4a2796f3 730 /* mtime uniquely identifies any adjustments made to the file XXX */
11ad5ade 731 vap->va_fsmid = ip->ino_data.mtime;
66325755
MD
732 vap->va_uid_uuid = ip->ino_data.uid;
733 vap->va_gid_uuid = ip->ino_data.gid;
734 vap->va_fsid_uuid = ip->hmp->fsid;
735 vap->va_vaflags = VA_UID_UUID_VALID | VA_GID_UUID_VALID |
736 VA_FSID_UUID_VALID;
7a04d74f 737
11ad5ade 738 switch (ip->ino_data.obj_type) {
7a04d74f
MD
739 case HAMMER_OBJTYPE_CDEV:
740 case HAMMER_OBJTYPE_BDEV:
741 vap->va_rmajor = ip->ino_data.rmajor;
742 vap->va_rminor = ip->ino_data.rminor;
743 break;
744 default:
745 break;
746 }
66325755 747 return(0);
427e5fc6
MD
748}
749
66325755
MD
750/*
751 * hammer_vop_nresolve { nch, dvp, cred }
752 *
753 * Locate the requested directory entry.
754 */
427e5fc6
MD
755static
756int
66325755 757hammer_vop_nresolve(struct vop_nresolve_args *ap)
427e5fc6 758{
36f82b23 759 struct hammer_transaction trans;
66325755 760 struct namecache *ncp;
7f7c1f84
MD
761 hammer_inode_t dip;
762 hammer_inode_t ip;
763 hammer_tid_t asof;
8cd0a023 764 struct hammer_cursor cursor;
66325755
MD
765 struct vnode *vp;
766 int64_t namekey;
767 int error;
7f7c1f84
MD
768 int i;
769 int nlen;
d113fda1 770 int flags;
a56cb012 771 int ispfs;
adf01747 772 int64_t obj_id;
ddfdf542 773 u_int32_t localization;
7f7c1f84
MD
774
775 /*
776 * Misc initialization, plus handle as-of name extensions. Look for
777 * the '@@' extension. Note that as-of files and directories cannot
778 * be modified.
7f7c1f84
MD
779 */
780 dip = VTOI(ap->a_dvp);
781 ncp = ap->a_nch->ncp;
782 asof = dip->obj_asof;
783 nlen = ncp->nc_nlen;
ea434b6f 784 flags = dip->flags & HAMMER_INODE_RO;
a56cb012 785 ispfs = 0;
7f7c1f84 786
36f82b23 787 hammer_simple_transaction(&trans, dip->hmp);
ce0138a6 788 ++hammer_stats_file_iopsr;
36f82b23 789
7f7c1f84
MD
790 for (i = 0; i < nlen; ++i) {
791 if (ncp->nc_name[i] == '@' && ncp->nc_name[i+1] == '@') {
ea434b6f
MD
792 asof = hammer_str_to_tid(ncp->nc_name + i + 2,
793 &ispfs, &localization);
794 if (asof != HAMMER_MAX_TID)
795 flags |= HAMMER_INODE_RO;
7f7c1f84
MD
796 break;
797 }
798 }
799 nlen = i;
66325755 800
ea434b6f
MD
801 /*
802 * If this is a PFS softlink we dive into the PFS
803 */
804 if (ispfs && nlen == 0) {
805 ip = hammer_get_inode(&trans, dip, HAMMER_OBJID_ROOT,
806 asof, localization,
807 flags, &error);
808 if (error == 0) {
809 error = hammer_get_vnode(ip, &vp);
810 hammer_rel_inode(ip, 0);
811 } else {
812 vp = NULL;
813 }
814 if (error == 0) {
815 vn_unlock(vp);
816 cache_setvp(ap->a_nch, vp);
817 vrele(vp);
818 }
819 goto done;
820 }
821
d113fda1
MD
822 /*
823 * If there is no path component the time extension is relative to
824 * dip.
825 */
826 if (nlen == 0) {
bcac4bbb 827 ip = hammer_get_inode(&trans, dip, dip->obj_id,
ddfdf542
MD
828 asof, dip->obj_localization,
829 flags, &error);
d113fda1 830 if (error == 0) {
e8599db1 831 error = hammer_get_vnode(ip, &vp);
d113fda1
MD
832 hammer_rel_inode(ip, 0);
833 } else {
834 vp = NULL;
835 }
836 if (error == 0) {
837 vn_unlock(vp);
838 cache_setvp(ap->a_nch, vp);
839 vrele(vp);
840 }
36f82b23 841 goto done;
d113fda1
MD
842 }
843
8cd0a023
MD
844 /*
845 * Calculate the namekey and setup the key range for the scan. This
846 * works kinda like a chained hash table where the lower 32 bits
847 * of the namekey synthesize the chain.
848 *
849 * The key range is inclusive of both key_beg and key_end.
850 */
7f7c1f84 851 namekey = hammer_directory_namekey(ncp->nc_name, nlen);
66325755 852
bcac4bbb 853 error = hammer_init_cursor(&trans, &cursor, &dip->cache[1], dip);
5a930e66
MD
854 cursor.key_beg.localization = dip->obj_localization +
855 HAMMER_LOCALIZE_MISC;
8cd0a023
MD
856 cursor.key_beg.obj_id = dip->obj_id;
857 cursor.key_beg.key = namekey;
d5530d22 858 cursor.key_beg.create_tid = 0;
8cd0a023
MD
859 cursor.key_beg.delete_tid = 0;
860 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
861 cursor.key_beg.obj_type = 0;
66325755 862
8cd0a023
MD
863 cursor.key_end = cursor.key_beg;
864 cursor.key_end.key |= 0xFFFFFFFFULL;
d5530d22
MD
865 cursor.asof = asof;
866 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
66325755
MD
867
868 /*
8cd0a023 869 * Scan all matching records (the chain), locate the one matching
a89aec1b 870 * the requested path component.
8cd0a023
MD
871 *
872 * The hammer_ip_*() functions merge in-memory records with on-disk
873 * records for the purposes of the search.
66325755 874 */
6a37e7e4 875 obj_id = 0;
43c665ae 876 localization = HAMMER_DEF_LOCALIZATION;
6a37e7e4 877
4e17f465 878 if (error == 0) {
4e17f465
MD
879 error = hammer_ip_first(&cursor);
880 while (error == 0) {
881 error = hammer_ip_resolve_data(&cursor);
882 if (error)
883 break;
11ad5ade
MD
884 if (nlen == cursor.leaf->data_len - HAMMER_ENTRY_NAME_OFF &&
885 bcmp(ncp->nc_name, cursor.data->entry.name, nlen) == 0) {
886 obj_id = cursor.data->entry.obj_id;
ddfdf542 887 localization = cursor.data->entry.localization;
4e17f465
MD
888 break;
889 }
890 error = hammer_ip_next(&cursor);
66325755
MD
891 }
892 }
6a37e7e4 893 hammer_done_cursor(&cursor);
66325755 894 if (error == 0) {
bcac4bbb 895 ip = hammer_get_inode(&trans, dip, obj_id,
ddfdf542
MD
896 asof, localization,
897 flags, &error);
7f7c1f84 898 if (error == 0) {
e8599db1 899 error = hammer_get_vnode(ip, &vp);
7f7c1f84
MD
900 hammer_rel_inode(ip, 0);
901 } else {
902 vp = NULL;
903 }
66325755
MD
904 if (error == 0) {
905 vn_unlock(vp);
906 cache_setvp(ap->a_nch, vp);
907 vrele(vp);
908 }
909 } else if (error == ENOENT) {
910 cache_setvp(ap->a_nch, NULL);
911 }
36f82b23 912done:
b84de5af 913 hammer_done_transaction(&trans);
66325755 914 return (error);
427e5fc6
MD
915}
916
66325755
MD
917/*
918 * hammer_vop_nlookupdotdot { dvp, vpp, cred }
919 *
920 * Locate the parent directory of a directory vnode.
921 *
922 * dvp is referenced but not locked. *vpp must be returned referenced and
923 * locked. A parent_obj_id of 0 does not necessarily indicate that we are
924 * at the root, instead it could indicate that the directory we were in was
925 * removed.
42c7d26b
MD
926 *
927 * NOTE: as-of sequences are not linked into the directory structure. If
928 * we are at the root with a different asof then the mount point, reload
929 * the same directory with the mount point's asof. I'm not sure what this
930 * will do to NFS. We encode ASOF stamps in NFS file handles so it might not
931 * get confused, but it hasn't been tested.
66325755 932 */
427e5fc6
MD
933static
934int
66325755 935hammer_vop_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
427e5fc6 936{
36f82b23 937 struct hammer_transaction trans;
66325755 938 struct hammer_inode *dip;
d113fda1 939 struct hammer_inode *ip;
42c7d26b 940 int64_t parent_obj_id;
5a930e66 941 u_int32_t parent_obj_localization;
42c7d26b 942 hammer_tid_t asof;
d113fda1 943 int error;
66325755
MD
944
945 dip = VTOI(ap->a_dvp);
42c7d26b 946 asof = dip->obj_asof;
5a930e66
MD
947
948 /*
949 * Whos are parent? This could be the root of a pseudo-filesystem
950 * whos parent is in another localization domain.
951 */
42c7d26b 952 parent_obj_id = dip->ino_data.parent_obj_id;
5a930e66
MD
953 if (dip->obj_id == HAMMER_OBJID_ROOT)
954 parent_obj_localization = dip->ino_data.ext.obj.parent_obj_localization;
955 else
956 parent_obj_localization = dip->obj_localization;
42c7d26b
MD
957
958 if (parent_obj_id == 0) {
959 if (dip->obj_id == HAMMER_OBJID_ROOT &&
960 asof != dip->hmp->asof) {
961 parent_obj_id = dip->obj_id;
962 asof = dip->hmp->asof;
963 *ap->a_fakename = kmalloc(19, M_TEMP, M_WAITOK);
964 ksnprintf(*ap->a_fakename, 19, "0x%016llx",
965 dip->obj_asof);
966 } else {
967 *ap->a_vpp = NULL;
968 return ENOENT;
969 }
66325755 970 }
d113fda1 971
36f82b23 972 hammer_simple_transaction(&trans, dip->hmp);
ce0138a6 973 ++hammer_stats_file_iopsr;
36f82b23 974
bcac4bbb 975 ip = hammer_get_inode(&trans, dip, parent_obj_id,
5a930e66 976 asof, parent_obj_localization,
ddfdf542 977 dip->flags, &error);
36f82b23 978 if (ip) {
e8599db1 979 error = hammer_get_vnode(ip, ap->a_vpp);
36f82b23
MD
980 hammer_rel_inode(ip, 0);
981 } else {
d113fda1 982 *ap->a_vpp = NULL;
d113fda1 983 }
b84de5af 984 hammer_done_transaction(&trans);
d113fda1 985 return (error);
427e5fc6
MD
986}
987
66325755
MD
988/*
989 * hammer_vop_nlink { nch, dvp, vp, cred }
990 */
427e5fc6
MD
991static
992int
66325755 993hammer_vop_nlink(struct vop_nlink_args *ap)
427e5fc6 994{
66325755
MD
995 struct hammer_transaction trans;
996 struct hammer_inode *dip;
997 struct hammer_inode *ip;
998 struct nchandle *nch;
999 int error;
1000
f437a2ab
MD
1001 if (ap->a_dvp->v_mount != ap->a_vp->v_mount)
1002 return(EXDEV);
1003
66325755
MD
1004 nch = ap->a_nch;
1005 dip = VTOI(ap->a_dvp);
1006 ip = VTOI(ap->a_vp);
1007
f437a2ab
MD
1008 if (dip->obj_localization != ip->obj_localization)
1009 return(EXDEV);
1010
d113fda1
MD
1011 if (dip->flags & HAMMER_INODE_RO)
1012 return (EROFS);
1013 if (ip->flags & HAMMER_INODE_RO)
1014 return (EROFS);
93291532 1015 if ((error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_CREATE)) != 0)
e63644f0 1016 return (error);
d113fda1 1017
66325755
MD
1018 /*
1019 * Create a transaction to cover the operations we perform.
1020 */
8cd0a023 1021 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1022 ++hammer_stats_file_iopsw;
66325755
MD
1023
1024 /*
1025 * Add the filesystem object to the directory. Note that neither
1026 * dip nor ip are referenced or locked, but their vnodes are
1027 * referenced. This function will bump the inode's link count.
1028 */
5a930e66
MD
1029 error = hammer_ip_add_directory(&trans, dip,
1030 nch->ncp->nc_name, nch->ncp->nc_nlen,
1031 ip);
66325755
MD
1032
1033 /*
1034 * Finish up.
1035 */
b84de5af 1036 if (error == 0) {
6b4f890b
MD
1037 cache_setunresolved(nch);
1038 cache_setvp(nch, ap->a_vp);
66325755 1039 }
b84de5af 1040 hammer_done_transaction(&trans);
66325755 1041 return (error);
427e5fc6
MD
1042}
1043
66325755
MD
1044/*
1045 * hammer_vop_nmkdir { nch, dvp, vpp, cred, vap }
1046 *
1047 * The operating system has already ensured that the directory entry
1048 * does not exist and done all appropriate namespace locking.
1049 */
427e5fc6
MD
1050static
1051int
66325755 1052hammer_vop_nmkdir(struct vop_nmkdir_args *ap)
427e5fc6 1053{
66325755
MD
1054 struct hammer_transaction trans;
1055 struct hammer_inode *dip;
1056 struct hammer_inode *nip;
1057 struct nchandle *nch;
1058 int error;
1059
1060 nch = ap->a_nch;
1061 dip = VTOI(ap->a_dvp);
1062
d113fda1
MD
1063 if (dip->flags & HAMMER_INODE_RO)
1064 return (EROFS);
93291532 1065 if ((error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_CREATE)) != 0)
e63644f0 1066 return (error);
d113fda1 1067
66325755
MD
1068 /*
1069 * Create a transaction to cover the operations we perform.
1070 */
8cd0a023 1071 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1072 ++hammer_stats_file_iopsw;
66325755
MD
1073
1074 /*
1075 * Create a new filesystem object of the requested type. The
8cd0a023 1076 * returned inode will be referenced but not locked.
66325755 1077 */
5a930e66 1078 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred,
ea434b6f 1079 dip, NULL, &nip);
66325755 1080 if (error) {
77062c8a 1081 hkprintf("hammer_mkdir error %d\n", error);
b84de5af 1082 hammer_done_transaction(&trans);
66325755
MD
1083 *ap->a_vpp = NULL;
1084 return (error);
1085 }
66325755
MD
1086 /*
1087 * Add the new filesystem object to the directory. This will also
1088 * bump the inode's link count.
1089 */
5a930e66
MD
1090 error = hammer_ip_add_directory(&trans, dip,
1091 nch->ncp->nc_name, nch->ncp->nc_nlen,
1092 nip);
0b075555 1093 if (error)
77062c8a 1094 hkprintf("hammer_mkdir (add) error %d\n", error);
66325755
MD
1095
1096 /*
1097 * Finish up.
1098 */
1099 if (error) {
a89aec1b 1100 hammer_rel_inode(nip, 0);
66325755
MD
1101 *ap->a_vpp = NULL;
1102 } else {
e8599db1 1103 error = hammer_get_vnode(nip, ap->a_vpp);
a89aec1b
MD
1104 hammer_rel_inode(nip, 0);
1105 if (error == 0) {
1106 cache_setunresolved(ap->a_nch);
1107 cache_setvp(ap->a_nch, *ap->a_vpp);
1108 }
66325755 1109 }
b84de5af 1110 hammer_done_transaction(&trans);
66325755 1111 return (error);
427e5fc6
MD
1112}
1113
66325755
MD
1114/*
1115 * hammer_vop_nmknod { nch, dvp, vpp, cred, vap }
1116 *
1117 * The operating system has already ensured that the directory entry
1118 * does not exist and done all appropriate namespace locking.
1119 */
427e5fc6
MD
1120static
1121int
66325755 1122hammer_vop_nmknod(struct vop_nmknod_args *ap)
427e5fc6 1123{
66325755
MD
1124 struct hammer_transaction trans;
1125 struct hammer_inode *dip;
1126 struct hammer_inode *nip;
1127 struct nchandle *nch;
1128 int error;
1129
1130 nch = ap->a_nch;
1131 dip = VTOI(ap->a_dvp);
1132
d113fda1
MD
1133 if (dip->flags & HAMMER_INODE_RO)
1134 return (EROFS);
93291532 1135 if ((error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_CREATE)) != 0)
e63644f0 1136 return (error);
d113fda1 1137
66325755
MD
1138 /*
1139 * Create a transaction to cover the operations we perform.
1140 */
8cd0a023 1141 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1142 ++hammer_stats_file_iopsw;
66325755
MD
1143
1144 /*
1145 * Create a new filesystem object of the requested type. The
8cd0a023 1146 * returned inode will be referenced but not locked.
5a930e66
MD
1147 *
1148 * If mknod specifies a directory a pseudo-fs is created.
66325755 1149 */
5a930e66 1150 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred,
ea434b6f 1151 dip, NULL, &nip);
66325755 1152 if (error) {
b84de5af 1153 hammer_done_transaction(&trans);
66325755
MD
1154 *ap->a_vpp = NULL;
1155 return (error);
1156 }
66325755
MD
1157
1158 /*
1159 * Add the new filesystem object to the directory. This will also
1160 * bump the inode's link count.
1161 */
5a930e66
MD
1162 error = hammer_ip_add_directory(&trans, dip,
1163 nch->ncp->nc_name, nch->ncp->nc_nlen,
1164 nip);
66325755
MD
1165
1166 /*
1167 * Finish up.
1168 */
1169 if (error) {
a89aec1b 1170 hammer_rel_inode(nip, 0);
66325755
MD
1171 *ap->a_vpp = NULL;
1172 } else {
e8599db1 1173 error = hammer_get_vnode(nip, ap->a_vpp);
a89aec1b
MD
1174 hammer_rel_inode(nip, 0);
1175 if (error == 0) {
1176 cache_setunresolved(ap->a_nch);
1177 cache_setvp(ap->a_nch, *ap->a_vpp);
1178 }
66325755 1179 }
b84de5af 1180 hammer_done_transaction(&trans);
66325755 1181 return (error);
427e5fc6
MD
1182}
1183
66325755
MD
1184/*
1185 * hammer_vop_open { vp, mode, cred, fp }
1186 */
427e5fc6
MD
1187static
1188int
66325755 1189hammer_vop_open(struct vop_open_args *ap)
427e5fc6 1190{
9f5097dc
MD
1191 hammer_inode_t ip;
1192
ce0138a6 1193 ++hammer_stats_file_iopsr;
9f5097dc
MD
1194 ip = VTOI(ap->a_vp);
1195
1196 if ((ap->a_mode & FWRITE) && (ip->flags & HAMMER_INODE_RO))
d113fda1 1197 return (EROFS);
a89aec1b 1198 return(vop_stdopen(ap));
427e5fc6
MD
1199}
1200
66325755
MD
1201/*
1202 * hammer_vop_print { vp }
1203 */
427e5fc6
MD
1204static
1205int
66325755 1206hammer_vop_print(struct vop_print_args *ap)
427e5fc6
MD
1207{
1208 return EOPNOTSUPP;
1209}
1210
66325755 1211/*
6b4f890b 1212 * hammer_vop_readdir { vp, uio, cred, *eofflag, *ncookies, off_t **cookies }
66325755 1213 */
427e5fc6
MD
1214static
1215int
66325755 1216hammer_vop_readdir(struct vop_readdir_args *ap)
427e5fc6 1217{
36f82b23 1218 struct hammer_transaction trans;
6b4f890b
MD
1219 struct hammer_cursor cursor;
1220 struct hammer_inode *ip;
1221 struct uio *uio;
6b4f890b
MD
1222 hammer_base_elm_t base;
1223 int error;
1224 int cookie_index;
1225 int ncookies;
1226 off_t *cookies;
1227 off_t saveoff;
1228 int r;
ea434b6f 1229 int dtype;
6b4f890b 1230
ce0138a6 1231 ++hammer_stats_file_iopsr;
6b4f890b
MD
1232 ip = VTOI(ap->a_vp);
1233 uio = ap->a_uio;
b3deaf57
MD
1234 saveoff = uio->uio_offset;
1235
1236 if (ap->a_ncookies) {
1237 ncookies = uio->uio_resid / 16 + 1;
1238 if (ncookies > 1024)
1239 ncookies = 1024;
1240 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
1241 cookie_index = 0;
1242 } else {
1243 ncookies = -1;
1244 cookies = NULL;
1245 cookie_index = 0;
1246 }
1247
36f82b23
MD
1248 hammer_simple_transaction(&trans, ip->hmp);
1249
b3deaf57
MD
1250 /*
1251 * Handle artificial entries
1252 */
1253 error = 0;
1254 if (saveoff == 0) {
1255 r = vop_write_dirent(&error, uio, ip->obj_id, DT_DIR, 1, ".");
1256 if (r)
1257 goto done;
1258 if (cookies)
1259 cookies[cookie_index] = saveoff;
1260 ++saveoff;
1261 ++cookie_index;
1262 if (cookie_index == ncookies)
1263 goto done;
1264 }
1265 if (saveoff == 1) {
1266 if (ip->ino_data.parent_obj_id) {
1267 r = vop_write_dirent(&error, uio,
1268 ip->ino_data.parent_obj_id,
1269 DT_DIR, 2, "..");
1270 } else {
1271 r = vop_write_dirent(&error, uio,
1272 ip->obj_id, DT_DIR, 2, "..");
1273 }
1274 if (r)
1275 goto done;
1276 if (cookies)
1277 cookies[cookie_index] = saveoff;
1278 ++saveoff;
1279 ++cookie_index;
1280 if (cookie_index == ncookies)
1281 goto done;
1282 }
6b4f890b
MD
1283
1284 /*
1285 * Key range (begin and end inclusive) to scan. Directory keys
1286 * directly translate to a 64 bit 'seek' position.
1287 */
bcac4bbb 1288 hammer_init_cursor(&trans, &cursor, &ip->cache[1], ip);
5a930e66
MD
1289 cursor.key_beg.localization = ip->obj_localization +
1290 HAMMER_LOCALIZE_MISC;
6b4f890b 1291 cursor.key_beg.obj_id = ip->obj_id;
d5530d22 1292 cursor.key_beg.create_tid = 0;
6b4f890b
MD
1293 cursor.key_beg.delete_tid = 0;
1294 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1295 cursor.key_beg.obj_type = 0;
b3deaf57 1296 cursor.key_beg.key = saveoff;
6b4f890b
MD
1297
1298 cursor.key_end = cursor.key_beg;
1299 cursor.key_end.key = HAMMER_MAX_KEY;
d5530d22
MD
1300 cursor.asof = ip->obj_asof;
1301 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
6b4f890b 1302
4e17f465 1303 error = hammer_ip_first(&cursor);
6b4f890b
MD
1304
1305 while (error == 0) {
11ad5ade 1306 error = hammer_ip_resolve_data(&cursor);
6b4f890b
MD
1307 if (error)
1308 break;
11ad5ade 1309 base = &cursor.leaf->base;
6b4f890b 1310 saveoff = base->key;
11ad5ade 1311 KKASSERT(cursor.leaf->data_len > HAMMER_ENTRY_NAME_OFF);
6b4f890b 1312
7a04d74f
MD
1313 if (base->obj_id != ip->obj_id)
1314 panic("readdir: bad record at %p", cursor.node);
1315
ea434b6f
MD
1316 /*
1317 * Convert pseudo-filesystems into softlinks
1318 */
1319 dtype = hammer_get_dtype(cursor.leaf->base.obj_type);
6b4f890b 1320 r = vop_write_dirent(
11ad5ade 1321 &error, uio, cursor.data->entry.obj_id,
ea434b6f 1322 dtype,
11ad5ade
MD
1323 cursor.leaf->data_len - HAMMER_ENTRY_NAME_OFF ,
1324 (void *)cursor.data->entry.name);
6b4f890b
MD
1325 if (r)
1326 break;
1327 ++saveoff;
1328 if (cookies)
1329 cookies[cookie_index] = base->key;
1330 ++cookie_index;
1331 if (cookie_index == ncookies)
1332 break;
1333 error = hammer_ip_next(&cursor);
1334 }
1335 hammer_done_cursor(&cursor);
1336
b3deaf57 1337done:
b84de5af 1338 hammer_done_transaction(&trans);
36f82b23 1339
6b4f890b
MD
1340 if (ap->a_eofflag)
1341 *ap->a_eofflag = (error == ENOENT);
6b4f890b
MD
1342 uio->uio_offset = saveoff;
1343 if (error && cookie_index == 0) {
b3deaf57
MD
1344 if (error == ENOENT)
1345 error = 0;
6b4f890b
MD
1346 if (cookies) {
1347 kfree(cookies, M_TEMP);
1348 *ap->a_ncookies = 0;
1349 *ap->a_cookies = NULL;
1350 }
1351 } else {
7a04d74f
MD
1352 if (error == ENOENT)
1353 error = 0;
6b4f890b
MD
1354 if (cookies) {
1355 *ap->a_ncookies = cookie_index;
1356 *ap->a_cookies = cookies;
1357 }
1358 }
1359 return(error);
427e5fc6
MD
1360}
1361
66325755
MD
1362/*
1363 * hammer_vop_readlink { vp, uio, cred }
1364 */
427e5fc6
MD
1365static
1366int
66325755 1367hammer_vop_readlink(struct vop_readlink_args *ap)
427e5fc6 1368{
36f82b23 1369 struct hammer_transaction trans;
7a04d74f
MD
1370 struct hammer_cursor cursor;
1371 struct hammer_inode *ip;
ea434b6f
MD
1372 char buf[32];
1373 u_int32_t localization;
1374 hammer_pseudofs_inmem_t pfsm;
7a04d74f
MD
1375 int error;
1376
1377 ip = VTOI(ap->a_vp);
36f82b23 1378
2f85fa4d
MD
1379 /*
1380 * Shortcut if the symlink data was stuffed into ino_data.
ea434b6f 1381 *
842e7a70
MD
1382 * Also expand special "@@PFS%05d" softlinks (expansion only
1383 * occurs for non-historical (current) accesses made from the
1384 * primary filesystem).
2f85fa4d
MD
1385 */
1386 if (ip->ino_data.size <= HAMMER_INODE_BASESYMLEN) {
ea434b6f
MD
1387 char *ptr;
1388 int bytes;
1389
1390 ptr = ip->ino_data.ext.symlink;
1391 bytes = (int)ip->ino_data.size;
842e7a70
MD
1392 if (bytes == 10 &&
1393 ip->obj_asof == HAMMER_MAX_TID &&
1394 ip->obj_localization == 0 &&
1395 strncmp(ptr, "@@PFS", 5) == 0) {
ea434b6f
MD
1396 hammer_simple_transaction(&trans, ip->hmp);
1397 bcopy(ptr + 5, buf, 5);
1398 buf[5] = 0;
1399 localization = strtoul(buf, NULL, 10) << 16;
1400 pfsm = hammer_load_pseudofs(&trans, localization,
1401 &error);
1402 if (error == 0) {
4c038e17
MD
1403 if (pfsm->pfsd.mirror_flags &
1404 HAMMER_PFSD_SLAVE) {
1405 ksnprintf(buf, sizeof(buf),
1406 "@@0x%016llx:%05d",
1407 pfsm->pfsd.sync_end_tid,
1408 localization >> 16);
1409 } else {
1410 ksnprintf(buf, sizeof(buf),
1411 "@@0x%016llx:%05d",
1412 HAMMER_MAX_TID,
1413 localization >> 16);
1414 }
ea434b6f
MD
1415 ptr = buf;
1416 bytes = strlen(buf);
1417 }
1418 if (pfsm)
1419 hammer_rel_pseudofs(trans.hmp, pfsm);
1420 hammer_done_transaction(&trans);
1421 }
1422 error = uiomove(ptr, bytes, ap->a_uio);
2f85fa4d
MD
1423 return(error);
1424 }
36f82b23 1425
2f85fa4d
MD
1426 /*
1427 * Long version
1428 */
1429 hammer_simple_transaction(&trans, ip->hmp);
ce0138a6 1430 ++hammer_stats_file_iopsr;
bcac4bbb 1431 hammer_init_cursor(&trans, &cursor, &ip->cache[1], ip);
7a04d74f
MD
1432
1433 /*
1434 * Key range (begin and end inclusive) to scan. Directory keys
1435 * directly translate to a 64 bit 'seek' position.
1436 */
5a930e66
MD
1437 cursor.key_beg.localization = ip->obj_localization +
1438 HAMMER_LOCALIZE_MISC;
7a04d74f 1439 cursor.key_beg.obj_id = ip->obj_id;
d5530d22 1440 cursor.key_beg.create_tid = 0;
7a04d74f
MD
1441 cursor.key_beg.delete_tid = 0;
1442 cursor.key_beg.rec_type = HAMMER_RECTYPE_FIX;
1443 cursor.key_beg.obj_type = 0;
1444 cursor.key_beg.key = HAMMER_FIXKEY_SYMLINK;
d5530d22
MD
1445 cursor.asof = ip->obj_asof;
1446 cursor.flags |= HAMMER_CURSOR_ASOF;
7a04d74f 1447
45a014dc 1448 error = hammer_ip_lookup(&cursor);
7a04d74f
MD
1449 if (error == 0) {
1450 error = hammer_ip_resolve_data(&cursor);
1451 if (error == 0) {
11ad5ade
MD
1452 KKASSERT(cursor.leaf->data_len >=
1453 HAMMER_SYMLINK_NAME_OFF);
1454 error = uiomove(cursor.data->symlink.name,
1455 cursor.leaf->data_len -
1456 HAMMER_SYMLINK_NAME_OFF,
7a04d74f
MD
1457 ap->a_uio);
1458 }
1459 }
1460 hammer_done_cursor(&cursor);
b84de5af 1461 hammer_done_transaction(&trans);
7a04d74f 1462 return(error);
427e5fc6
MD
1463}
1464
66325755
MD
1465/*
1466 * hammer_vop_nremove { nch, dvp, cred }
1467 */
427e5fc6
MD
1468static
1469int
66325755 1470hammer_vop_nremove(struct vop_nremove_args *ap)
427e5fc6 1471{
b84de5af 1472 struct hammer_transaction trans;
e63644f0 1473 struct hammer_inode *dip;
b84de5af
MD
1474 int error;
1475
e63644f0
MD
1476 dip = VTOI(ap->a_dvp);
1477
1478 if (hammer_nohistory(dip) == 0 &&
93291532 1479 (error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_REMOVE)) != 0) {
e63644f0
MD
1480 return (error);
1481 }
1482
1483 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1484 ++hammer_stats_file_iopsw;
d7e278bb 1485 error = hammer_dounlink(&trans, ap->a_nch, ap->a_dvp, ap->a_cred, 0, 0);
b84de5af
MD
1486 hammer_done_transaction(&trans);
1487
1488 return (error);
427e5fc6
MD
1489}
1490
66325755
MD
1491/*
1492 * hammer_vop_nrename { fnch, tnch, fdvp, tdvp, cred }
1493 */
427e5fc6
MD
1494static
1495int
66325755 1496hammer_vop_nrename(struct vop_nrename_args *ap)
427e5fc6 1497{
8cd0a023
MD
1498 struct hammer_transaction trans;
1499 struct namecache *fncp;
1500 struct namecache *tncp;
1501 struct hammer_inode *fdip;
1502 struct hammer_inode *tdip;
1503 struct hammer_inode *ip;
1504 struct hammer_cursor cursor;
8cd0a023 1505 int64_t namekey;
11ad5ade 1506 int nlen, error;
8cd0a023 1507
f437a2ab
MD
1508 if (ap->a_fdvp->v_mount != ap->a_tdvp->v_mount)
1509 return(EXDEV);
1510 if (ap->a_fdvp->v_mount != ap->a_fnch->ncp->nc_vp->v_mount)
1511 return(EXDEV);
1512
8cd0a023
MD
1513 fdip = VTOI(ap->a_fdvp);
1514 tdip = VTOI(ap->a_tdvp);
1515 fncp = ap->a_fnch->ncp;
1516 tncp = ap->a_tnch->ncp;
b3deaf57
MD
1517 ip = VTOI(fncp->nc_vp);
1518 KKASSERT(ip != NULL);
d113fda1 1519
f437a2ab
MD
1520 if (fdip->obj_localization != tdip->obj_localization)
1521 return(EXDEV);
1522 if (fdip->obj_localization != ip->obj_localization)
1523 return(EXDEV);
1524
d113fda1
MD
1525 if (fdip->flags & HAMMER_INODE_RO)
1526 return (EROFS);
1527 if (tdip->flags & HAMMER_INODE_RO)
1528 return (EROFS);
1529 if (ip->flags & HAMMER_INODE_RO)
1530 return (EROFS);
93291532 1531 if ((error = hammer_checkspace(fdip->hmp, HAMMER_CHKSPC_CREATE)) != 0)
e63644f0 1532 return (error);
d113fda1 1533
8cd0a023 1534 hammer_start_transaction(&trans, fdip->hmp);
ce0138a6 1535 ++hammer_stats_file_iopsw;
8cd0a023
MD
1536
1537 /*
b3deaf57
MD
1538 * Remove tncp from the target directory and then link ip as
1539 * tncp. XXX pass trans to dounlink
42c7d26b
MD
1540 *
1541 * Force the inode sync-time to match the transaction so it is
1542 * in-sync with the creation of the target directory entry.
8cd0a023 1543 */
d7e278bb
MD
1544 error = hammer_dounlink(&trans, ap->a_tnch, ap->a_tdvp,
1545 ap->a_cred, 0, -1);
42c7d26b 1546 if (error == 0 || error == ENOENT) {
5a930e66
MD
1547 error = hammer_ip_add_directory(&trans, tdip,
1548 tncp->nc_name, tncp->nc_nlen,
1549 ip);
42c7d26b
MD
1550 if (error == 0) {
1551 ip->ino_data.parent_obj_id = tdip->obj_id;
47637bff 1552 hammer_modify_inode(ip, HAMMER_INODE_DDIRTY);
42c7d26b
MD
1553 }
1554 }
b3deaf57
MD
1555 if (error)
1556 goto failed; /* XXX */
8cd0a023
MD
1557
1558 /*
1559 * Locate the record in the originating directory and remove it.
1560 *
1561 * Calculate the namekey and setup the key range for the scan. This
1562 * works kinda like a chained hash table where the lower 32 bits
1563 * of the namekey synthesize the chain.
1564 *
1565 * The key range is inclusive of both key_beg and key_end.
1566 */
1567 namekey = hammer_directory_namekey(fncp->nc_name, fncp->nc_nlen);
6a37e7e4 1568retry:
bcac4bbb 1569 hammer_init_cursor(&trans, &cursor, &fdip->cache[1], fdip);
5a930e66
MD
1570 cursor.key_beg.localization = fdip->obj_localization +
1571 HAMMER_LOCALIZE_MISC;
8cd0a023
MD
1572 cursor.key_beg.obj_id = fdip->obj_id;
1573 cursor.key_beg.key = namekey;
d5530d22 1574 cursor.key_beg.create_tid = 0;
8cd0a023
MD
1575 cursor.key_beg.delete_tid = 0;
1576 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1577 cursor.key_beg.obj_type = 0;
1578
1579 cursor.key_end = cursor.key_beg;
1580 cursor.key_end.key |= 0xFFFFFFFFULL;
d5530d22
MD
1581 cursor.asof = fdip->obj_asof;
1582 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
8cd0a023
MD
1583
1584 /*
1585 * Scan all matching records (the chain), locate the one matching
a89aec1b 1586 * the requested path component.
8cd0a023
MD
1587 *
1588 * The hammer_ip_*() functions merge in-memory records with on-disk
1589 * records for the purposes of the search.
1590 */
4e17f465 1591 error = hammer_ip_first(&cursor);
a89aec1b 1592 while (error == 0) {
8cd0a023
MD
1593 if (hammer_ip_resolve_data(&cursor) != 0)
1594 break;
11ad5ade
MD
1595 nlen = cursor.leaf->data_len - HAMMER_ENTRY_NAME_OFF;
1596 KKASSERT(nlen > 0);
1597 if (fncp->nc_nlen == nlen &&
1598 bcmp(fncp->nc_name, cursor.data->entry.name, nlen) == 0) {
8cd0a023
MD
1599 break;
1600 }
a89aec1b 1601 error = hammer_ip_next(&cursor);
8cd0a023 1602 }
8cd0a023
MD
1603
1604 /*
1605 * If all is ok we have to get the inode so we can adjust nlinks.
6a37e7e4
MD
1606 *
1607 * WARNING: hammer_ip_del_directory() may have to terminate the
1608 * cursor to avoid a recursion. It's ok to call hammer_done_cursor()
1609 * twice.
8cd0a023 1610 */
9944ae54 1611 if (error == 0)
6a37e7e4 1612 error = hammer_ip_del_directory(&trans, &cursor, fdip, ip);
b84de5af
MD
1613
1614 /*
1615 * XXX A deadlock here will break rename's atomicy for the purposes
1616 * of crash recovery.
1617 */
1618 if (error == EDEADLK) {
b84de5af 1619 hammer_done_cursor(&cursor);
b84de5af
MD
1620 goto retry;
1621 }
1622
1623 /*
1624 * Cleanup and tell the kernel that the rename succeeded.
1625 */
c0ade690 1626 hammer_done_cursor(&cursor);
6a37e7e4
MD
1627 if (error == 0)
1628 cache_rename(ap->a_fnch, ap->a_tnch);
b84de5af 1629
b3deaf57 1630failed:
b84de5af 1631 hammer_done_transaction(&trans);
8cd0a023 1632 return (error);
427e5fc6
MD
1633}
1634
66325755
MD
1635/*
1636 * hammer_vop_nrmdir { nch, dvp, cred }
1637 */
427e5fc6
MD
1638static
1639int
66325755 1640hammer_vop_nrmdir(struct vop_nrmdir_args *ap)
427e5fc6 1641{
b84de5af 1642 struct hammer_transaction trans;
e63644f0 1643 struct hammer_inode *dip;
b84de5af
MD
1644 int error;
1645
e63644f0
MD
1646 dip = VTOI(ap->a_dvp);
1647
1648 if (hammer_nohistory(dip) == 0 &&
93291532 1649 (error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_REMOVE)) != 0) {
e63644f0
MD
1650 return (error);
1651 }
1652
1653 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1654 ++hammer_stats_file_iopsw;
d7e278bb 1655 error = hammer_dounlink(&trans, ap->a_nch, ap->a_dvp, ap->a_cred, 0, 1);
b84de5af
MD
1656 hammer_done_transaction(&trans);
1657
1658 return (error);
427e5fc6
MD
1659}
1660
66325755
MD
1661/*
1662 * hammer_vop_setattr { vp, vap, cred }
1663 */
427e5fc6
MD
1664static
1665int
66325755 1666hammer_vop_setattr(struct vop_setattr_args *ap)
427e5fc6 1667{
8cd0a023
MD
1668 struct hammer_transaction trans;
1669 struct vattr *vap;
1670 struct hammer_inode *ip;
1671 int modflags;
1672 int error;
d5ef456e 1673 int truncating;
4a2796f3
MD
1674 int blksize;
1675 int64_t aligned_size;
8cd0a023 1676 u_int32_t flags;
8cd0a023
MD
1677
1678 vap = ap->a_vap;
1679 ip = ap->a_vp->v_data;
1680 modflags = 0;
1681
1682 if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)
1683 return(EROFS);
d113fda1
MD
1684 if (ip->flags & HAMMER_INODE_RO)
1685 return (EROFS);
e63644f0 1686 if (hammer_nohistory(ip) == 0 &&
93291532 1687 (error = hammer_checkspace(ip->hmp, HAMMER_CHKSPC_REMOVE)) != 0) {
e63644f0
MD
1688 return (error);
1689 }
8cd0a023
MD
1690
1691 hammer_start_transaction(&trans, ip->hmp);
ce0138a6 1692 ++hammer_stats_file_iopsw;
8cd0a023
MD
1693 error = 0;
1694
1695 if (vap->va_flags != VNOVAL) {
1696 flags = ip->ino_data.uflags;
1697 error = vop_helper_setattr_flags(&flags, vap->va_flags,
1698 hammer_to_unix_xid(&ip->ino_data.uid),
1699 ap->a_cred);
1700 if (error == 0) {
1701 if (ip->ino_data.uflags != flags) {
1702 ip->ino_data.uflags = flags;
1703 modflags |= HAMMER_INODE_DDIRTY;
1704 }
1705 if (ip->ino_data.uflags & (IMMUTABLE | APPEND)) {
1706 error = 0;
1707 goto done;
1708 }
1709 }
1710 goto done;
1711 }
1712 if (ip->ino_data.uflags & (IMMUTABLE | APPEND)) {
1713 error = EPERM;
1714 goto done;
1715 }
7538695e
MD
1716 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
1717 mode_t cur_mode = ip->ino_data.mode;
1718 uid_t cur_uid = hammer_to_unix_xid(&ip->ino_data.uid);
1719 gid_t cur_gid = hammer_to_unix_xid(&ip->ino_data.gid);
1720 uuid_t uuid_uid;
1721 uuid_t uuid_gid;
1722
1723 error = vop_helper_chown(ap->a_vp, vap->va_uid, vap->va_gid,
1724 ap->a_cred,
1725 &cur_uid, &cur_gid, &cur_mode);
1726 if (error == 0) {
1727 hammer_guid_to_uuid(&uuid_uid, cur_uid);
1728 hammer_guid_to_uuid(&uuid_gid, cur_gid);
1729 if (bcmp(&uuid_uid, &ip->ino_data.uid,
1730 sizeof(uuid_uid)) ||
1731 bcmp(&uuid_gid, &ip->ino_data.gid,
1732 sizeof(uuid_gid)) ||
1733 ip->ino_data.mode != cur_mode
1734 ) {
1735 ip->ino_data.uid = uuid_uid;
1736 ip->ino_data.gid = uuid_gid;
1737 ip->ino_data.mode = cur_mode;
1738 }
8cd0a023
MD
1739 modflags |= HAMMER_INODE_DDIRTY;
1740 }
1741 }
11ad5ade 1742 while (vap->va_size != VNOVAL && ip->ino_data.size != vap->va_size) {
8cd0a023
MD
1743 switch(ap->a_vp->v_type) {
1744 case VREG:
11ad5ade 1745 if (vap->va_size == ip->ino_data.size)
d5ef456e 1746 break;
b84de5af
MD
1747 /*
1748 * XXX break atomicy, we can deadlock the backend
1749 * if we do not release the lock. Probably not a
1750 * big deal here.
1751 */
4a2796f3 1752 blksize = hammer_blocksize(vap->va_size);
11ad5ade 1753 if (vap->va_size < ip->ino_data.size) {
4a2796f3 1754 vtruncbuf(ap->a_vp, vap->va_size, blksize);
d5ef456e
MD
1755 truncating = 1;
1756 } else {
c0ade690 1757 vnode_pager_setsize(ap->a_vp, vap->va_size);
d5ef456e 1758 truncating = 0;
c0ade690 1759 }
11ad5ade
MD
1760 ip->ino_data.size = vap->va_size;
1761 modflags |= HAMMER_INODE_DDIRTY;
d5ef456e 1762
b84de5af
MD
1763 /*
1764 * on-media truncation is cached in the inode until
1765 * the inode is synchronized.
1766 */
d5ef456e 1767 if (truncating) {
47637bff 1768 hammer_ip_frontend_trunc(ip, vap->va_size);
0832c9bb
MD
1769#ifdef DEBUG_TRUNCATE
1770 if (HammerTruncIp == NULL)
1771 HammerTruncIp = ip;
1772#endif
b84de5af
MD
1773 if ((ip->flags & HAMMER_INODE_TRUNCATED) == 0) {
1774 ip->flags |= HAMMER_INODE_TRUNCATED;
1775 ip->trunc_off = vap->va_size;
0832c9bb
MD
1776#ifdef DEBUG_TRUNCATE
1777 if (ip == HammerTruncIp)
1778 kprintf("truncate1 %016llx\n", ip->trunc_off);
1779#endif
b84de5af
MD
1780 } else if (ip->trunc_off > vap->va_size) {
1781 ip->trunc_off = vap->va_size;
0832c9bb
MD
1782#ifdef DEBUG_TRUNCATE
1783 if (ip == HammerTruncIp)
1784 kprintf("truncate2 %016llx\n", ip->trunc_off);
1785#endif
1786 } else {
1787#ifdef DEBUG_TRUNCATE
1788 if (ip == HammerTruncIp)
1789 kprintf("truncate3 %016llx (ignored)\n", vap->va_size);
1790#endif
b84de5af 1791 }
d5ef456e 1792 }
b84de5af 1793
d5ef456e
MD
1794 /*
1795 * If truncating we have to clean out a portion of
b84de5af
MD
1796 * the last block on-disk. We do this in the
1797 * front-end buffer cache.
d5ef456e 1798 */
4a2796f3
MD
1799 aligned_size = (vap->va_size + (blksize - 1)) &
1800 ~(int64_t)(blksize - 1);
b84de5af 1801 if (truncating && vap->va_size < aligned_size) {
d5ef456e
MD
1802 struct buf *bp;
1803 int offset;
1804
4a2796f3 1805 aligned_size -= blksize;
47637bff 1806
4a2796f3 1807 offset = (int)vap->va_size & (blksize - 1);
47637bff 1808 error = bread(ap->a_vp, aligned_size,
4a2796f3 1809 blksize, &bp);
47637bff 1810 hammer_ip_frontend_trunc(ip, aligned_size);
d5ef456e
MD
1811 if (error == 0) {
1812 bzero(bp->b_data + offset,
4a2796f3 1813 blksize - offset);
1b0ab2c3
MD
1814 /* must de-cache direct-io offset */
1815 bp->b_bio2.bio_offset = NOOFFSET;
d5ef456e
MD
1816 bdwrite(bp);
1817 } else {
47637bff 1818 kprintf("ERROR %d\n", error);
d5ef456e
MD
1819 brelse(bp);
1820 }
1821 }
76376933 1822 break;
8cd0a023 1823 case VDATABASE:
b84de5af
MD
1824 if ((ip->flags & HAMMER_INODE_TRUNCATED) == 0) {
1825 ip->flags |= HAMMER_INODE_TRUNCATED;
1826 ip->trunc_off = vap->va_size;
1827 } else if (ip->trunc_off > vap->va_size) {
1828 ip->trunc_off = vap->va_size;
1829 }
47637bff 1830 hammer_ip_frontend_trunc(ip, vap->va_size);
11ad5ade
MD
1831 ip->ino_data.size = vap->va_size;
1832 modflags |= HAMMER_INODE_DDIRTY;
8cd0a023
MD
1833 break;
1834 default:
1835 error = EINVAL;
1836 goto done;
1837 }
d26d0ae9 1838 break;
8cd0a023
MD
1839 }
1840 if (vap->va_atime.tv_sec != VNOVAL) {
bcac4bbb 1841 ip->ino_data.atime =
ddfdf542
MD
1842 hammer_timespec_to_time(&vap->va_atime);
1843 modflags |= HAMMER_INODE_ATIME;
8cd0a023
MD
1844 }
1845 if (vap->va_mtime.tv_sec != VNOVAL) {
11ad5ade 1846 ip->ino_data.mtime =
ddfdf542
MD
1847 hammer_timespec_to_time(&vap->va_mtime);
1848 modflags |= HAMMER_INODE_MTIME;
8cd0a023
MD
1849 }
1850 if (vap->va_mode != (mode_t)VNOVAL) {
7538695e
MD
1851 mode_t cur_mode = ip->ino_data.mode;
1852 uid_t cur_uid = hammer_to_unix_xid(&ip->ino_data.uid);
1853 gid_t cur_gid = hammer_to_unix_xid(&ip->ino_data.gid);
1854
1855 error = vop_helper_chmod(ap->a_vp, vap->va_mode, ap->a_cred,
1856 cur_uid, cur_gid, &cur_mode);
1857 if (error == 0 && ip->ino_data.mode != cur_mode) {
1858 ip->ino_data.mode = cur_mode;
8cd0a023
MD
1859 modflags |= HAMMER_INODE_DDIRTY;
1860 }
1861 }
1862done:
b84de5af 1863 if (error == 0)
47637bff 1864 hammer_modify_inode(ip, modflags);
b84de5af 1865 hammer_done_transaction(&trans);
8cd0a023 1866 return (error);
427e5fc6
MD
1867}
1868
66325755
MD
1869/*
1870 * hammer_vop_nsymlink { nch, dvp, vpp, cred, vap, target }
1871 */
427e5fc6
MD
1872static
1873int
66325755 1874hammer_vop_nsymlink(struct vop_nsymlink_args *ap)
427e5fc6 1875{
7a04d74f
MD
1876 struct hammer_transaction trans;
1877 struct hammer_inode *dip;
1878 struct hammer_inode *nip;
1879 struct nchandle *nch;
1880 hammer_record_t record;
1881 int error;
1882 int bytes;
1883
1884 ap->a_vap->va_type = VLNK;
1885
1886 nch = ap->a_nch;
1887 dip = VTOI(ap->a_dvp);
1888
d113fda1
MD
1889 if (dip->flags & HAMMER_INODE_RO)
1890 return (EROFS);
93291532 1891 if ((error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_CREATE)) != 0)
e63644f0 1892 return (error);
d113fda1 1893
7a04d74f
MD
1894 /*
1895 * Create a transaction to cover the operations we perform.
1896 */
1897 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1898 ++hammer_stats_file_iopsw;
7a04d74f
MD
1899
1900 /*
1901 * Create a new filesystem object of the requested type. The
1902 * returned inode will be referenced but not locked.
1903 */
1904
5a930e66 1905 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred,
ea434b6f 1906 dip, NULL, &nip);
7a04d74f 1907 if (error) {
b84de5af 1908 hammer_done_transaction(&trans);
7a04d74f
MD
1909 *ap->a_vpp = NULL;
1910 return (error);
1911 }
1912
7a04d74f
MD
1913 /*
1914 * Add a record representing the symlink. symlink stores the link
1915 * as pure data, not a string, and is no \0 terminated.
1916 */
1917 if (error == 0) {
7a04d74f
MD
1918 bytes = strlen(ap->a_target);
1919
2f85fa4d
MD
1920 if (bytes <= HAMMER_INODE_BASESYMLEN) {
1921 bcopy(ap->a_target, nip->ino_data.ext.symlink, bytes);
1922 } else {
1923 record = hammer_alloc_mem_record(nip, bytes);
1924 record->type = HAMMER_MEM_RECORD_GENERAL;
1925
5a930e66
MD
1926 record->leaf.base.localization = nip->obj_localization +
1927 HAMMER_LOCALIZE_MISC;
2f85fa4d
MD
1928 record->leaf.base.key = HAMMER_FIXKEY_SYMLINK;
1929 record->leaf.base.rec_type = HAMMER_RECTYPE_FIX;
1930 record->leaf.data_len = bytes;
1931 KKASSERT(HAMMER_SYMLINK_NAME_OFF == 0);
1932 bcopy(ap->a_target, record->data->symlink.name, bytes);
1933 error = hammer_ip_add_record(&trans, record);
1934 }
42c7d26b
MD
1935
1936 /*
1937 * Set the file size to the length of the link.
1938 */
1939 if (error == 0) {
11ad5ade 1940 nip->ino_data.size = bytes;
47637bff 1941 hammer_modify_inode(nip, HAMMER_INODE_DDIRTY);
42c7d26b 1942 }
7a04d74f 1943 }
1f07f686 1944 if (error == 0)
5a930e66
MD
1945 error = hammer_ip_add_directory(&trans, dip, nch->ncp->nc_name,
1946 nch->ncp->nc_nlen, nip);
7a04d74f
MD
1947
1948 /*
1949 * Finish up.
1950 */
1951 if (error) {
1952 hammer_rel_inode(nip, 0);
7a04d74f
MD
1953 *ap->a_vpp = NULL;
1954 } else {
e8599db1 1955 error = hammer_get_vnode(nip, ap->a_vpp);
7a04d74f
MD
1956 hammer_rel_inode(nip, 0);
1957 if (error == 0) {
1958 cache_setunresolved(ap->a_nch);
1959 cache_setvp(ap->a_nch, *ap->a_vpp);
1960 }
1961 }
b84de5af 1962 hammer_done_transaction(&trans);
7a04d74f 1963 return (error);
427e5fc6
MD
1964}
1965
66325755
MD
1966/*
1967 * hammer_vop_nwhiteout { nch, dvp, cred, flags }
1968 */
427e5fc6
MD
1969static
1970int
66325755 1971hammer_vop_nwhiteout(struct vop_nwhiteout_args *ap)
427e5fc6 1972{
b84de5af 1973 struct hammer_transaction trans;
e63644f0 1974 struct hammer_inode *dip;
b84de5af
MD
1975 int error;
1976
e63644f0
MD
1977 dip = VTOI(ap->a_dvp);
1978
1979 if (hammer_nohistory(dip) == 0 &&
93291532 1980 (error = hammer_checkspace(dip->hmp, HAMMER_CHKSPC_CREATE)) != 0) {
e63644f0
MD
1981 return (error);
1982 }
1983
1984 hammer_start_transaction(&trans, dip->hmp);
ce0138a6 1985 ++hammer_stats_file_iopsw;
b84de5af 1986 error = hammer_dounlink(&trans, ap->a_nch, ap->a_dvp,
d7e278bb 1987 ap->a_cred, ap->a_flags, -1);
b84de5af
MD
1988 hammer_done_transaction(&trans);
1989
1990 return (error);
427e5fc6
MD
1991}
1992
7dc57964
MD
1993/*
1994 * hammer_vop_ioctl { vp, command, data, fflag, cred }
1995 */
1996static
1997int
1998hammer_vop_ioctl(struct vop_ioctl_args *ap)
1999{
2000 struct hammer_inode *ip = ap->a_vp->v_data;
2001
ce0138a6 2002 ++hammer_stats_file_iopsr;
7dc57964
MD
2003 return(hammer_ioctl(ip, ap->a_command, ap->a_data,
2004 ap->a_fflag, ap->a_cred));
2005}
2006
513ca7d7
MD
2007static
2008int
2009hammer_vop_mountctl(struct vop_mountctl_args *ap)
2010{
2011 struct mount *mp;
2012 int error;
2013
2014 mp = ap->a_head.a_ops->head.vv_mount;
2015
2016 switch(ap->a_op) {
2017 case MOUNTCTL_SET_EXPORT:
2018 if (ap->a_ctllen != sizeof(struct export_args))
2019 error = EINVAL;
b424ca30
MD
2020 else
2021 error = hammer_vfs_export(mp, ap->a_op,
513ca7d7
MD
2022 (const struct export_args *)ap->a_ctl);
2023 break;
2024 default:
2025 error = journal_mountctl(ap);
2026 break;
2027 }
2028 return(error);
2029}
2030
66325755
MD
2031/*
2032 * hammer_vop_strategy { vp, bio }
8cd0a023
MD
2033 *
2034 * Strategy call, used for regular file read & write only. Note that the
2035 * bp may represent a cluster.
2036 *
2037 * To simplify operation and allow better optimizations in the future,
2038 * this code does not make any assumptions with regards to buffer alignment
2039 * or size.
66325755 2040 */
427e5fc6
MD
2041static
2042int
66325755 2043hammer_vop_strategy(struct vop_strategy_args *ap)
427e5fc6 2044{
8cd0a023
MD
2045 struct buf *bp;
2046 int error;
2047
2048 bp = ap->a_bio->bio_buf;
2049
2050 switch(bp->b_cmd) {
2051 case BUF_CMD_READ:
2052 error = hammer_vop_strategy_read(ap);
2053 break;
2054 case BUF_CMD_WRITE:
2055 error = hammer_vop_strategy_write(ap);
2056 break;
2057 default:
059819e3
MD
2058 bp->b_error = error = EINVAL;
2059 bp->b_flags |= B_ERROR;
2060 biodone(ap->a_bio);
8cd0a023
MD
2061 break;
2062 }
8cd0a023 2063 return (error);
427e5fc6
MD
2064}
2065
8cd0a023
MD
2066/*
2067 * Read from a regular file. Iterate the related records and fill in the
2068 * BIO/BUF. Gaps are zero-filled.
2069 *
2070 * The support code in hammer_object.c should be used to deal with mixed
2071 * in-memory and on-disk records.
2072 *
4a2796f3
MD
2073 * NOTE: Can be called from the cluster code with an oversized buf.
2074 *
8cd0a023
MD
2075 * XXX atime update
2076 */
2077static
2078int
2079hammer_vop_strategy_read(struct vop_strategy_args *ap)
2080{
36f82b23
MD
2081 struct hammer_transaction trans;
2082 struct hammer_inode *ip;
8cd0a023 2083 struct hammer_cursor cursor;
8cd0a023 2084 hammer_base_elm_t base;
4a2796f3 2085 hammer_off_t disk_offset;
8cd0a023 2086 struct bio *bio;
a99b9ea2 2087 struct bio *nbio;
8cd0a023
MD
2088 struct buf *bp;
2089 int64_t rec_offset;
a89aec1b 2090 int64_t ran_end;
195c19a1 2091 int64_t tmp64;
8cd0a023
MD
2092 int error;
2093 int boff;
2094 int roff;
2095 int n;
2096
2097 bio = ap->a_bio;
2098 bp = bio->bio_buf;
36f82b23 2099 ip = ap->a_vp->v_data;
8cd0a023 2100
a99b9ea2
MD
2101 /*
2102 * The zone-2 disk offset may have been set by the cluster code via
4a2796f3 2103 * a BMAP operation, or else should be NOOFFSET.
a99b9ea2 2104 *
4a2796f3 2105 * Checking the high bits for a match against zone-2 should suffice.
a99b9ea2
MD
2106 */
2107 nbio = push_bio(bio);
6aeaa7bd 2108 if ((nbio->bio_offset & HAMMER_OFF_ZONE_MASK) ==
1b0ab2c3
MD
2109 HAMMER_ZONE_LARGE_DATA) {
2110 error = hammer_io_direct_read(ip->hmp, nbio, NULL);
a99b9ea2
MD
2111 return (error);
2112 }
2113
2114 /*
4a2796f3
MD
2115 * Well, that sucked. Do it the hard way. If all the stars are
2116 * aligned we may still be able to issue a direct-read.
a99b9ea2 2117 */
36f82b23 2118 hammer_simple_transaction(&trans, ip->hmp);
47637bff 2119 hammer_init_cursor(&trans, &cursor, &ip->cache[1], ip);
8cd0a023
MD
2120
2121 /*
2122 * Key range (begin and end inclusive) to scan. Note that the key's
c0ade690
MD
2123 * stored in the actual records represent BASE+LEN, not BASE. The
2124 * first record containing bio_offset will have a key > bio_offset.
8cd0a023 2125 */
5a930e66
MD
2126 cursor.key_beg.localization = ip->obj_localization +
2127 HAMMER_LOCALIZE_MISC;
8cd0a023 2128 cursor.key_beg.obj_id = ip->obj_id;
d5530d22 2129 cursor.key_beg.create_tid = 0;
8cd0a023 2130 cursor.key_beg.delete_tid = 0;
8cd0a023 2131 cursor.key_beg.obj_type = 0;
c0ade690 2132 cursor.key_beg.key = bio->bio_offset + 1;
d5530d22 2133 cursor.asof = ip->obj_asof;
bf3b416b 2134 cursor.flags |= HAMMER_CURSOR_ASOF;
8cd0a023
MD
2135
2136 cursor.key_end = cursor.key_beg;
11ad5ade 2137 KKASSERT(ip->ino_data.obj_type == HAMMER_OBJTYPE_REGFILE);
b84de5af 2138#if 0
11ad5ade 2139 if (ip->ino_data.obj_type == HAMMER_OBJTYPE_DBFILE) {
a89aec1b
MD
2140 cursor.key_beg.rec_type = HAMMER_RECTYPE_DB;
2141 cursor.key_end.rec_type = HAMMER_RECTYPE_DB;
2142 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
b84de5af
MD
2143 } else
2144#endif
2145 {
c0ade690 2146 ran_end = bio->bio_offset + bp->b_bufsize;
a89aec1b
MD
2147 cursor.key_beg.rec_type = HAMMER_RECTYPE_DATA;
2148 cursor.key_end.rec_type = HAMMER_RECTYPE_DATA;
195c19a1
MD
2149 tmp64 = ran_end + MAXPHYS + 1; /* work-around GCC-4 bug */
2150 if (tmp64 < ran_end)
a89aec1b
MD
2151 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
2152 else
7f7c1f84 2153 cursor.key_end.key = ran_end + MAXPHYS + 1;
a89aec1b 2154 }
d26d0ae9 2155 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE;
8cd0a023 2156
4e17f465 2157 error = hammer_ip_first(&cursor);
8cd0a023
MD
2158 boff = 0;
2159
a89aec1b 2160 while (error == 0) {
47637bff
MD
2161 /*
2162 * Get the base file offset of the record. The key for
2163 * data records is (base + bytes) rather then (base).
2164 */
11ad5ade 2165 base = &cursor.leaf->base;
11ad5ade 2166 rec_offset = base->key - cursor.leaf->data_len;
8cd0a023 2167
66325755 2168 /*
a89aec1b 2169 * Calculate the gap, if any, and zero-fill it.
1fef775e
MD
2170 *
2171 * n is the offset of the start of the record verses our
2172 * current seek offset in the bio.
66325755 2173 */
8cd0a023
MD
2174 n = (int)(rec_offset - (bio->bio_offset + boff));
2175 if (n > 0) {
a89aec1b
MD
2176 if (n > bp->b_bufsize - boff)
2177 n = bp->b_bufsize - boff;
8cd0a023
MD
2178 bzero((char *)bp->b_data + boff, n);
2179 boff += n;
2180 n = 0;
66325755 2181 }
8cd0a023
MD
2182
2183 /*
2184 * Calculate the data offset in the record and the number
2185 * of bytes we can copy.
a89aec1b 2186 *
1fef775e
MD
2187 * There are two degenerate cases. First, boff may already
2188 * be at bp->b_bufsize. Secondly, the data offset within
2189 * the record may exceed the record's size.
8cd0a023
MD
2190 */
2191 roff = -n;
b84de5af 2192 rec_offset += roff;
11ad5ade 2193 n = cursor.leaf->data_len - roff;
1fef775e
MD
2194 if (n <= 0) {
2195 kprintf("strategy_read: bad n=%d roff=%d\n", n, roff);
2196 n = 0;
2197 } else if (n > bp->b_bufsize - boff) {
8cd0a023 2198 n = bp->b_bufsize - boff;
1fef775e 2199 }
059819e3 2200
b84de5af 2201 /*
47637bff
MD
2202 * Deal with cached truncations. This cool bit of code
2203 * allows truncate()/ftruncate() to avoid having to sync
2204 * the file.
2205 *
2206 * If the frontend is truncated then all backend records are
2207 * subject to the frontend's truncation.
2208 *
2209 * If the backend is truncated then backend records on-disk
2210 * (but not in-memory) are subject to the backend's
2211 * truncation. In-memory records owned by the backend
2212 * represent data written after the truncation point on the
2213 * backend and must not be truncated.
2214 *
2215 * Truncate operations deal with frontend buffer cache
2216 * buffers and frontend-owned in-memory records synchronously.
b84de5af 2217 */
47637bff
MD
2218 if (ip->flags & HAMMER_INODE_TRUNCATED) {
2219 if (hammer_cursor_ondisk(&cursor) ||
2220 cursor.iprec->flush_state == HAMMER_FST_FLUSH) {
2221 if (ip->trunc_off <= rec_offset)
2222 n = 0;
2223 else if (ip->trunc_off < rec_offset + n)
2224 n = (int)(ip->trunc_off - rec_offset);
2225 }
2226 }
2227 if (ip->sync_flags & HAMMER_INODE_TRUNCATED) {
2228 if (hammer_cursor_ondisk(&cursor)) {
2229 if (ip->sync_trunc_off <= rec_offset)
2230 n = 0;
2231 else if (ip->sync_trunc_off < rec_offset + n)
2232 n = (int)(ip->sync_trunc_off - rec_offset);
2233 }
2234 }
b84de5af
MD
2235
2236 /*
47637bff
MD
2237 * Try to issue a direct read into our bio if possible,
2238 * otherwise resolve the element data into a hammer_buffer
2239 * and copy.
4a2796f3
MD
2240 *
2241 * The buffer on-disk should be zerod past any real
2242 * truncation point, but may not be for any synthesized
2243 * truncation point from above.
b84de5af 2244 */
1b0ab2c3 2245 disk_offset = cursor.leaf->data_offset + roff;
4a2796f3 2246 if (boff == 0 && n == bp->b_bufsize &&
1b0ab2c3
MD
2247 hammer_cursor_ondisk(&cursor) &&
2248 (disk_offset & HAMMER_BUFMASK) == 0) {
2249 KKASSERT((disk_offset & HAMMER_OFF_ZONE_MASK) ==
2250 HAMMER_ZONE_LARGE_DATA);
4a2796f3 2251 nbio->bio_offset = disk_offset;
1b0ab2c3
MD
2252 error = hammer_io_direct_read(trans.hmp, nbio,
2253 cursor.leaf);
47637bff
MD
2254 goto done;
2255 } else if (n) {
2256 error = hammer_ip_resolve_data(&cursor);
2257 if (error == 0) {
2258 bcopy((char *)cursor.data + roff,
2259 (char *)bp->b_data + boff, n);
2260 }
b84de5af 2261 }
47637bff
MD
2262 if (error)
2263 break;
2264
2265 /*
2266 * Iterate until we have filled the request.
2267 */
2268 boff += n;
8cd0a023 2269 if (boff == bp->b_bufsize)
66325755 2270 break;
a89aec1b 2271 error = hammer_ip_next(&cursor);
66325755
MD
2272 }
2273
2274 /*
8cd0a023 2275 * There may have been a gap after the last record
66325755 2276 */
8cd0a023
MD
2277 if (error == ENOENT)
2278 error = 0;
2279 if (error == 0 && boff != bp->b_bufsize) {
7f7c1f84 2280 KKASSERT(boff < bp->b_bufsize);
8cd0a023
MD
2281 bzero((char *)bp->b_data + boff, bp->b_bufsize - boff);
2282 /* boff = bp->b_bufsize; */
2283 }
2284 bp->b_resid = 0;
059819e3
MD
2285 bp->b_error = error;
2286 if (error)
2287 bp->b_flags |= B_ERROR;
2288 biodone(ap->a_bio);
47637bff
MD
2289
2290done:
2291 if (cursor.node)
bcac4bbb 2292 hammer_cache_node(&ip->cache[1], cursor.node);
47637bff
MD
2293 hammer_done_cursor(&cursor);
2294 hammer_done_transaction(&trans);
8cd0a023
MD
2295 return(error);
2296}
2297
a99b9ea2
MD
2298/*
2299 * BMAP operation - used to support cluster_read() only.
2300 *
2301 * (struct vnode *vp, off_t loffset, off_t *doffsetp, int *runp, int *runb)
2302 *
2303 * This routine may return EOPNOTSUPP if the opration is not supported for
2304 * the specified offset. The contents of the pointer arguments do not
2305 * need to be initialized in that case.
2306 *
2307 * If a disk address is available and properly aligned return 0 with
2308 * *doffsetp set to the zone-2 address, and *runp / *runb set appropriately
2309 * to the run-length relative to that offset. Callers may assume that
2310 * *doffsetp is valid if 0 is returned, even if *runp is not sufficiently
2311 * large, so return EOPNOTSUPP if it is not sufficiently large.
2312 */
2313static
2314int
2315hammer_vop_bmap(struct vop_bmap_args *ap)
2316{
2317 struct hammer_transaction trans;
2318 struct hammer_inode *ip;
2319 struct hammer_cursor cursor;
2320 hammer_base_elm_t base;
2321 int64_t rec_offset;
2322 int64_t ran_end;
2323 int64_t tmp64;
2324 int64_t base_offset;
2325 int64_t base_disk_offset;
2326 int64_t last_offset;
2327 hammer_off_t last_disk_offset;
2328 hammer_off_t disk_offset;
2329 int rec_len;
2330 int error;
4a2796f3 2331 int blksize;
a99b9ea2 2332
ce0138a6 2333 ++hammer_stats_file_iopsr;
a99b9ea2
MD
2334 ip = ap->a_vp->v_data;
2335
2336 /*
2337 * We can only BMAP regular files. We can't BMAP database files,
2338 * directories, etc.
2339 */
2340 if (ip->ino_data.obj_type != HAMMER_OBJTYPE_REGFILE)
2341 return(EOPNOTSUPP);
2342
2343 /*
2344 * bmap is typically called with runp/runb both NULL when used
2345 * for writing. We do not support BMAP for writing atm.
2346 */
4a2796f3 2347 if (ap->a_cmd != BUF_CMD_READ)
a99b9ea2
MD
2348 return(EOPNOTSUPP);
2349
2350 /*
2351 * Scan the B-Tree to acquire blockmap addresses, then translate
2352 * to raw addresses.
2353 */
2354 hammer_simple_transaction(&trans, ip->hmp);
cb51be26
MD
2355#if 0
2356 kprintf("bmap_beg %016llx ip->cache %p\n", ap->a_loffset, ip->cache[1]);
2357#endif
a99b9ea2
MD
2358 hammer_init_cursor(&trans, &cursor, &ip->cache[1], ip);
2359
2360 /*
2361 * Key range (begin and end inclusive) to scan. Note that the key's
2362 * stored in the actual records represent BASE+LEN, not BASE. The
2363 * first record containing bio_offset will have a key > bio_offset.
2364 */
5a930e66
MD
2365 cursor.key_beg.localization = ip->obj_localization +
2366 HAMMER_LOCALIZE_MISC;
a99b9ea2
MD
2367 cursor.key_beg.obj_id = ip->obj_id;
2368 cursor.key_beg.create_tid = 0;
2369 cursor.key_beg.delete_tid = 0;
2370 cursor.key_beg.obj_type = 0;
2371 if (ap->a_runb)
2372 cursor.key_beg.key = ap->a_loffset - MAXPHYS + 1;
2373 else
2374 cursor.key_beg.key = ap->a_loffset + 1;
2375 if (cursor.key_beg.key < 0)
2376 cursor.key_beg.key = 0;
2377 cursor.asof = ip->obj_asof;
bf3b416b 2378 cursor.flags |= HAMMER_CURSOR_ASOF;
a99b9ea2
MD
2379
2380 cursor.key_end = cursor.key_beg;
2381 KKASSERT(ip->ino_data.obj_type == HAMMER_OBJTYPE_REGFILE);
2382
2383 ran_end = ap->a_loffset + MAXPHYS;
2384 cursor.key_beg.rec_type = HAMMER_RECTYPE_DATA;
2385 cursor.key_end.rec_type = HAMMER_RECTYPE_DATA;
2386 tmp64 = ran_end + MAXPHYS + 1; /* work-around GCC-4 bug */
2387 if (tmp64 < ran_end)
2388 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
2389 else
2390 cursor.key_end.key = ran_end + MAXPHYS + 1;
2391
2392 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE;
2393
2394 error = hammer_ip_first(&cursor);
2395 base_offset = last_offset = 0;
2396 base_disk_offset = last_disk_offset = 0;
2397
2398 while (error == 0) {
2399 /*
2400 * Get the base file offset of the record. The key for
2401 * data records is (base + bytes) rather then (base).
4a2796f3
MD
2402 *
2403 * NOTE: rec_offset + rec_len may exceed the end-of-file.
2404 * The extra bytes should be zero on-disk and the BMAP op
2405 * should still be ok.
a99b9ea2
MD
2406 */
2407 base = &cursor.leaf->base;
2408 rec_offset = base->key - cursor.leaf->data_len;
2409 rec_len = cursor.leaf->data_len;
2410
2411 /*
4a2796f3
MD
2412 * Incorporate any cached truncation.
2413 *
2414 * NOTE: Modifications to rec_len based on synthesized
2415 * truncation points remove the guarantee that any extended
2416 * data on disk is zero (since the truncations may not have
2417 * taken place on-media yet).
a99b9ea2
MD
2418 */
2419 if (ip->flags & HAMMER_INODE_TRUNCATED) {
2420 if (hammer_cursor_ondisk(&cursor) ||
2421 cursor.iprec->flush_state == HAMMER_FST_FLUSH) {
2422 if (ip->trunc_off <= rec_offset)
2423 rec_len = 0;
2424 else if (ip->trunc_off < rec_offset + rec_len)
2425 rec_len = (int)(ip->trunc_off - rec_offset);
2426 }
2427 }
2428 if (ip->sync_flags & HAMMER_INODE_TRUNCATED) {
2429 if (hammer_cursor_ondisk(&cursor)) {
2430 if (ip->sync_trunc_off <= rec_offset)
2431 rec_len = 0;
2432 else if (ip->sync_trunc_off < rec_offset + rec_len)
2433 rec_len = (int)(ip->sync_trunc_off - rec_offset);
2434 }
2435 }
2436
2437 /*
2438 * Accumulate information. If we have hit a discontiguous
2439 * block reset base_offset unless we are already beyond the
2440 * requested offset. If we are, that's it, we stop.
2441 */
a99b9ea2
MD
2442 if (error)
2443 break;
1b0ab2c3
MD
2444 if (hammer_cursor_ondisk(&cursor)) {
2445 disk_offset = cursor.leaf->data_offset;
2446 if (rec_offset != last_offset ||
2447 disk_offset != last_disk_offset) {
2448 if (rec_offset > ap->a_loffset)
2449 break;
2450 base_offset = rec_offset;
2451 base_disk_offset = disk_offset;
2452 }
2453 last_offset = rec_offset + rec_len;
2454 last_disk_offset = disk_offset + rec_len;
a99b9ea2 2455 }
a99b9ea2
MD
2456 error = hammer_ip_next(&cursor);
2457 }
2458
2459#if 0
2460 kprintf("BMAP %016llx: %016llx - %016llx\n",
2461 ap->a_loffset, base_offset, last_offset);
2462 kprintf("BMAP %16s: %016llx - %016llx\n",
2463 "", base_disk_offset, last_disk_offset);
2464#endif
2465
cb51be26 2466 if (cursor.node) {
bcac4bbb 2467 hammer_cache_node(&ip->cache[1], cursor.node);
cb51be26
MD
2468#if 0
2469 kprintf("bmap_end2 %016llx ip->cache %p\n", ap->a_loffset, ip->cache[1]);
2470#endif
2471 }
a99b9ea2
MD
2472 hammer_done_cursor(&cursor);
2473 hammer_done_transaction(&trans);
2474
4a2796f3
MD
2475 /*
2476 * If we couldn't find any records or the records we did find were
2477 * all behind the requested offset, return failure. A forward
2478 * truncation can leave a hole w/ no on-disk records.
2479 */
2480 if (last_offset == 0 || last_offset < ap->a_loffset)
2481 return (EOPNOTSUPP);
2482
2483 /*
2484 * Figure out the block size at the requested offset and adjust
2485 * our limits so the cluster_read() does not create inappropriately
2486 * sized buffer cache buffers.
2487 */
2488 blksize = hammer_blocksize(ap->a_loffset);
2489 if (hammer_blocksize(base_offset) != blksize) {
2490 base_offset = hammer_blockdemarc(base_offset, ap->a_loffset);
2491 }
2492 if (last_offset != ap->a_loffset &&
2493 hammer_blocksize(last_offset - 1) != blksize) {
2494 last_offset = hammer_blockdemarc(ap->a_loffset,
2495 last_offset - 1);
2496 }
2497
2498 /*
2499 * Returning EOPNOTSUPP simply prevents the direct-IO optimization
2500 * from occuring.
2501 */
2502 disk_offset = base_disk_offset + (ap->a_loffset - base_offset);
2503
1b0ab2c3
MD
2504 if ((disk_offset & HAMMER_OFF_ZONE_MASK) != HAMMER_ZONE_LARGE_DATA) {
2505 /*
2506 * Only large-data zones can be direct-IOd
2507 */
2508 error = EOPNOTSUPP;
2509 } else if ((disk_offset & HAMMER_BUFMASK) ||
2510 (last_offset - ap->a_loffset) < blksize) {
2511 /*
2512 * doffsetp is not aligned or the forward run size does
2513 * not cover a whole buffer, disallow the direct I/O.
2514 */
a99b9ea2
MD
2515 error = EOPNOTSUPP;
2516 } else {
1b0ab2c3
MD
2517 /*
2518 * We're good.
2519 */
4a2796f3
MD
2520 *ap->a_doffsetp = disk_offset;
2521 if (ap->a_runb) {
2522 *ap->a_runb = ap->a_loffset - base_offset;
2523 KKASSERT(*ap->a_runb >= 0);
a99b9ea2 2524 }
4a2796f3
MD
2525 if (ap->a_runp) {
2526 *ap->a_runp = last_offset - ap->a_loffset;
2527 KKASSERT(*ap->a_runp >= 0);
2528 }
2529 error = 0;
a99b9ea2
MD
2530 }
2531 return(error);
2532}
2533
8cd0a023 2534/*
059819e3 2535 * Write to a regular file. Because this is a strategy call the OS is
bcac4bbb 2536 * trying to actually get data onto the media.
8cd0a023
MD
2537 */
2538static
2539int
2540hammer_vop_strategy_write(struct vop_strategy_args *ap)
2541{
47637bff 2542 hammer_record_t record;
af209b0f 2543 hammer_mount_t hmp;
8cd0a023
MD
2544 hammer_inode_t ip;
2545 struct bio *bio;
2546 struct buf *bp;
a7e9bef1 2547 int blksize;
0832c9bb
MD
2548 int bytes;
2549 int error;
8cd0a023
MD
2550
2551 bio = ap->a_bio;
2552 bp = bio->bio_buf;
2553 ip = ap->a_vp->v_data;
af209b0f 2554 hmp = ip->hmp;
d113fda1 2555
a7e9bef1
MD
2556 blksize = hammer_blocksize(bio->bio_offset);
2557 KKASSERT(bp->b_bufsize == blksize);
4a2796f3 2558
059819e3
MD
2559 if (ip->flags & HAMMER_INODE_RO) {
2560 bp->b_error = EROFS;
2561 bp->b_flags |= B_ERROR;
2562 biodone(ap->a_bio);
2563 return(EROFS);
2564 }
b84de5af 2565
29ce0677
MD
2566 /*
2567 * Interlock with inode destruction (no in-kernel or directory
2568 * topology visibility). If we queue new IO while trying to
2569 * destroy the inode we can deadlock the vtrunc call in
2570 * hammer_inode_unloadable_check().
35a49944
MD
2571 *
2572 * Besides, there's no point flushing a bp associated with an
2573 * inode that is being destroyed on-media and has no kernel
2574 * references.
29ce0677 2575 */
35a49944
MD
2576 if ((ip->flags | ip->sync_flags) &
2577 (HAMMER_INODE_DELETING|HAMMER_INODE_DELETED)) {
29ce0677
MD
2578 bp->b_resid = 0;
2579 biodone(ap->a_bio);
2580 return(0);
2581 }
2582
b84de5af 2583 /*
a99b9ea2
MD
2584 * Reserve space and issue a direct-write from the front-end.
2585 * NOTE: The direct_io code will hammer_bread/bcopy smaller
2586 * allocations.
47637bff 2587 *
a99b9ea2
MD
2588 * An in-memory record will be installed to reference the storage
2589 * until the flusher can get to it.
47637bff
MD
2590 *
2591 * Since we own the high level bio the front-end will not try to
0832c9bb 2592 * do a direct-read until the write completes.
a99b9ea2
MD
2593 *
2594 * NOTE: The only time we do not reserve a full-sized buffers
2595 * worth of data is if the file is small. We do not try to
2596 * allocate a fragment (from the small-data zone) at the end of
2597 * an otherwise large file as this can lead to wildly separated
2598 * data.
47637bff 2599 */
0832c9bb
MD
2600 KKASSERT((bio->bio_offset & HAMMER_BUFMASK) == 0);
2601 KKASSERT(bio->bio_offset < ip->ino_data.size);
a99b9ea2 2602 if (bio->bio_offset || ip->ino_data.size > HAMMER_BUFSIZE / 2)
4a2796f3 2603 bytes = bp->b_bufsize;
b84de5af 2604 else
a99b9ea2 2605 bytes = ((int)ip->ino_data.size + 15) & ~15;
0832c9bb
MD
2606
2607 record = hammer_ip_add_bulk(ip, bio->bio_offset, bp->b_data,
2608 bytes, &error);
2609 if (record) {
1b0ab2c3 2610 hammer_io_direct_write(hmp, record, bio);
4a2796f3
MD
2611 if (ip->rsv_recs > 1 && hmp->rsv_recs > hammer_limit_recs)
2612 hammer_flush_inode(ip, 0);
0832c9bb 2613 } else {
a99b9ea2 2614 bp->b_bio2.bio_offset = NOOFFSET;
0832c9bb
MD
2615 bp->b_error = error;
2616 bp->b_flags |= B_ERROR;
2617 biodone(ap->a_bio);
2618 }
0832c9bb 2619 return(error);
059819e3
MD
2620}
2621
8cd0a023
MD
2622/*
2623 * dounlink - disconnect a directory entry
2624 *
2625 * XXX whiteout support not really in yet
2626 */
2627static int
b84de5af 2628hammer_dounlink(hammer_transaction_t trans, struct nchandle *nch,
d7e278bb
MD
2629 struct vnode *dvp, struct ucred *cred,
2630 int flags, int isdir)
8cd0a023 2631{
8cd0a023
MD
2632 struct namecache *ncp;
2633 hammer_inode_t dip;
2634 hammer_inode_t ip;
8cd0a023 2635 struct hammer_cursor cursor;
8cd0a023 2636 int64_t namekey;
11ad5ade 2637 int nlen, error;
8cd0a023
MD
2638
2639 /*
2640 * Calculate the namekey and setup the key range for the scan. This
2641 * works kinda like a chained hash table where the lower 32 bits
2642 * of the namekey synthesize the chain.
2643 *
2644 * The key range is inclusive of both key_beg and key_end.
2645 */
2646 dip = VTOI(dvp);
2647 ncp = nch->ncp;
d113fda1
MD
2648
2649 if (dip->flags & HAMMER_INODE_RO)
2650 return (EROFS);
2651
6a37e7e4
MD
2652 namekey = hammer_directory_namekey(ncp->nc_name, ncp->nc_nlen);
2653retry:
bcac4bbb 2654 hammer_init_cursor(trans, &cursor, &dip->cache[1], dip);
5a930e66
MD
2655 cursor.key_beg.localization = dip->obj_localization +
2656 HAMMER_LOCALIZE_MISC;
8cd0a023
MD
2657 cursor.key_beg.obj_id = dip->obj_id;
2658 cursor.key_beg.key = namekey;
d5530d22 2659 cursor.key_beg.create_tid = 0;
8cd0a023
MD
2660 cursor.key_beg.delete_tid = 0;
2661 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
2662 cursor.key_beg.obj_type = 0;
2663
2664 cursor.key_end = cursor.key_beg;
2665 cursor.key_end.key |= 0xFFFFFFFFULL;
d5530d22
MD
2666 cursor.asof = dip->obj_asof;
2667 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
8cd0a023 2668
8cd0a023
MD
2669 /*
2670 * Scan all matching records (the chain), locate the one matching
2671 * the requested path component. info->last_error contains the
2672 * error code on search termination and could be 0, ENOENT, or
2673 * something else.
2674 *
2675 * The hammer_ip_*() functions merge in-memory records with on-disk
2676 * records for the purposes of the search.
2677 */
4e17f465
MD
2678 error = hammer_ip_first(&cursor);
2679
a89aec1b
MD
2680 while (error == 0) {
2681 error = hammer_ip_resolve_data(&cursor);
2682 if (error)
66325755 2683 break;
11ad5ade
MD
2684 nlen = cursor.leaf->data_len - HAMMER_ENTRY_NAME_OFF;
2685 KKASSERT(nlen > 0);
2686 if (ncp->nc_nlen == nlen &&
2687 bcmp(ncp->nc_name, cursor.data->entry.name, nlen) == 0) {
66325755
MD
2688 break;
2689 }
a89aec1b 2690 error = hammer_ip_next(&cursor);
66325755 2691 }
8cd0a023
MD
2692
2693 /*
2694 * If all is ok we have to get the inode so we can adjust nlinks.
269c5eab
MD
2695 * To avoid a deadlock with the flusher we must release the inode
2696 * lock on the directory when acquiring the inode for the entry.
b3deaf57
MD
2697 *
2698 * If the target is a directory, it must be empty.
8cd0a023 2699 */
66325755 2700 if (error == 0) {
269c5eab 2701 hammer_unlock(&cursor.ip->lock);
bcac4bbb 2702 ip = hammer_get_inode(trans, dip, cursor.data->entry.obj_id,
ddfdf542
MD
2703 dip->hmp->asof,
2704 cursor.data->entry.localization,
2705 0, &error);
269c5eab 2706 hammer_lock_sh(&cursor.ip->lock);
46fe7ae1 2707 if (error == ENOENT) {
11ad5ade 2708 kprintf("obj_id %016llx\n", cursor.data->entry.obj_id);
10a5d1ba 2709 Debugger("ENOENT unlinking object that should exist");
46fe7ae1 2710 }
1f07f686 2711
d7e278bb
MD
2712 /*
2713 * If isdir >= 0 we validate that the entry is or is not a
2714 * directory. If isdir < 0 we don't care.
2715 */
2716 if (error == 0 && isdir >= 0) {
2717 if (isdir &&
2718 ip->ino_data.obj_type != HAMMER_OBJTYPE_DIRECTORY) {
2719 error = ENOTDIR;
2720 } else if (isdir == 0 &&
2721 ip->ino_data.obj_type == HAMMER_OBJTYPE_DIRECTORY) {
2722 error = EISDIR;
2723 }
2724 }
2725
1f07f686
MD
2726 /*
2727 * If we are trying to remove a directory the directory must
2728 * be empty.
2729 *
2730 * WARNING: hammer_ip_check_directory_empty() may have to
2731 * terminate the cursor to avoid a deadlock. It is ok to
2732 * call hammer_done_cursor() twice.
2733 */
11ad5ade 2734 if (error == 0 && ip->ino_data.obj_type ==
b3deaf57 2735 HAMMER_OBJTYPE_DIRECTORY) {
98f7132d 2736 error = hammer_ip_check_directory_empty(trans, ip);
b3deaf57 2737 }
1f07f686 2738
6a37e7e4 2739 /*
1f07f686
MD
2740 * Delete the directory entry.
2741 *
6a37e7e4 2742 * WARNING: hammer_ip_del_directory() may have to terminate
1f07f686 2743 * the cursor to avoid a deadlock. It is ok to call
6a37e7e4
MD
2744 * hammer_done_cursor() twice.
2745 */
b84de5af 2746 if (error == 0) {
b84de5af
MD
2747 error = hammer_ip_del_directory(trans, &cursor,
2748 dip, ip);
b84de5af 2749 }
269c5eab 2750 hammer_done_cursor(&cursor);
8cd0a023
MD
2751 if (error == 0) {
2752 cache_setunresolved(nch);
2753 cache_setvp(nch, NULL);
2754 /* XXX locking */
2755 if (ip->vp)
2756 cache_inval_vp(ip->vp, CINV_DESTROY);
2757 }
af209b0f
MD
2758 if (ip)
2759 hammer_rel_inode(ip, 0);
269c5eab
MD
2760 } else {
2761 hammer_done_cursor(&cursor);
66325755 2762 }
6a37e7e4
MD
2763 if (error == EDEADLK)
2764 goto retry;
9c448776 2765
66325755 2766 return (error);
66325755
MD
2767}
2768
7a04d74f
MD
2769/************************************************************************
2770 * FIFO AND SPECFS OPS *
2771 ************************************************************************
2772 *
2773 */
2774
2775static int
2776hammer_vop_fifoclose (struct vop_close_args *ap)
2777{
2778 /* XXX update itimes */
2779 return (VOCALL(&fifo_vnode_vops, &ap->a_head));
2780}
2781
2782static int
2783hammer_vop_fiforead (struct vop_read_args *ap)
2784{
2785 int error;
2786
2787 error = VOCALL(&fifo_vnode_vops, &ap->a_head);
2788 /* XXX update access time */
2789 return (error);
2790}
2791
2792static int
2793hammer_vop_fifowrite (struct vop_write_args *ap)
2794{
2795 int error;
2796
2797 error = VOCALL(&fifo_vnode_vops, &ap->a_head);
2798 /* XXX update access time */
2799 return (error);
2800}
2801
2802static int
2803hammer_vop_specclose (struct vop_close_args *ap)
2804{
2805 /* XXX update itimes */
2806 return (VOCALL(&spec_vnode_vops, &ap->a_head));
2807}
2808
2809static int
2810hammer_vop_specread (struct vop_read_args *ap)
2811{
2812 /* XXX update access time */
2813 return (VOCALL(&spec_vnode_vops, &ap->a_head));
2814}
2815
2816static int
2817hammer_vop_specwrite (struct vop_write_args *ap)
2818{
2819 /* XXX update last change time */
2820 return (VOCALL(&spec_vnode_vops, &ap->a_head));
2821}
2822