HAMMER 41B/Many: Cleanup.
[dragonfly.git] / sys / vfs / hammer / hammer.h
CommitLineData
8750964d 1/*
1f07f686 2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
8750964d
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 *
77062c8a 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.62 2008/05/06 00:21:07 dillon Exp $
8750964d
MD
35 */
36/*
37 * This header file contains structures used internally by the HAMMERFS
c60bb2c5 38 * implementation. See hammer_disk.h for on-disk structures.
8750964d
MD
39 */
40
427e5fc6
MD
41#include <sys/param.h>
42#include <sys/types.h>
43#include <sys/kernel.h>
42c7d26b 44#include <sys/conf.h>
427e5fc6 45#include <sys/systm.h>
8750964d
MD
46#include <sys/tree.h>
47#include <sys/malloc.h>
427e5fc6 48#include <sys/mount.h>
513ca7d7 49#include <sys/mountctl.h>
427e5fc6 50#include <sys/vnode.h>
42c7d26b 51#include <sys/proc.h>
427e5fc6 52#include <sys/globaldata.h>
66325755
MD
53#include <sys/lockf.h>
54#include <sys/buf.h>
8cd0a023 55#include <sys/queue.h>
66325755
MD
56#include <sys/globaldata.h>
57
58#include <sys/buf2.h>
855942b6 59#include <sys/signal2.h>
427e5fc6 60#include "hammer_disk.h"
8750964d 61#include "hammer_mount.h"
7dc57964 62#include "hammer_ioctl.h"
8750964d
MD
63
64#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
65
66MALLOC_DECLARE(M_HAMMER);
67
66325755
MD
68struct hammer_mount;
69
8750964d
MD
70/*
71 * Key structure used for custom RB tree inode lookups. This prototypes
72 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
73 */
74typedef struct hammer_inode_info {
513ca7d7 75 int64_t obj_id; /* (key) object identifier */
8750964d
MD
76 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
77} *hammer_inode_info_t;
78
b84de5af
MD
79typedef enum hammer_transaction_type {
80 HAMMER_TRANS_RO,
81 HAMMER_TRANS_STD,
82 HAMMER_TRANS_FLS
83} hammer_transaction_type_t;
84
66325755
MD
85/*
86 * HAMMER Transaction tracking
87 */
88struct hammer_transaction {
b84de5af 89 hammer_transaction_type_t type;
66325755
MD
90 struct hammer_mount *hmp;
91 hammer_tid_t tid;
b84de5af 92 hammer_tid_t time;
a89aec1b 93 struct hammer_volume *rootvol;
66325755
MD
94};
95
8cd0a023
MD
96typedef struct hammer_transaction *hammer_transaction_t;
97
66325755
MD
98/*
99 * HAMMER locks
100 */
427e5fc6 101struct hammer_lock {
0b075555 102 int refs; /* active references delay writes */
0b075555 103 int lockcount; /* lock count for exclusive/shared access */
427e5fc6
MD
104 int wanted;
105 struct thread *locktd;
8750964d
MD
106};
107
427e5fc6
MD
108static __inline int
109hammer_islocked(struct hammer_lock *lock)
110{
8cd0a023 111 return(lock->lockcount != 0);
427e5fc6
MD
112}
113
0b075555
MD
114static __inline int
115hammer_isactive(struct hammer_lock *lock)
116{
117 return(lock->refs != 0);
118}
119
427e5fc6
MD
120static __inline int
121hammer_islastref(struct hammer_lock *lock)
122{
123 return(lock->refs == 1);
124}
c60bb2c5 125
6a37e7e4 126/*
7aa3b8a6 127 * Return if we specifically own the lock exclusively.
6a37e7e4
MD
128 */
129static __inline int
7aa3b8a6 130hammer_lock_excl_owned(struct hammer_lock *lock, thread_t td)
6a37e7e4 131{
7aa3b8a6
MD
132 if (lock->lockcount > 0 && lock->locktd == td)
133 return(1);
134 return(0);
6a37e7e4
MD
135}
136
ec4e8497 137/*
1f07f686 138 * Flush state, used by various structures
ec4e8497 139 */
1f07f686
MD
140typedef enum hammer_inode_state {
141 HAMMER_FST_IDLE,
142 HAMMER_FST_SETUP,
143 HAMMER_FST_FLUSH
144} hammer_inode_state_t;
ec4e8497 145
1f07f686 146TAILQ_HEAD(hammer_record_list, hammer_record);
ec4e8497 147
0729c8c8
MD
148/*
149 * Cache object ids. A fixed number of objid cache structures are
150 * created to reserve object id's for newly created files in multiples
151 * of 100,000, localized to a particular directory, and recycled as
152 * needed. This allows parallel create operations in different
153 * directories to retain fairly localized object ids which in turn
154 * improves reblocking performance and layout.
155 */
156#define OBJID_CACHE_SIZE 128
157#define OBJID_CACHE_BULK 100000
158
159typedef struct hammer_objid_cache {
160 TAILQ_ENTRY(hammer_objid_cache) entry;
161 struct hammer_inode *dip;
162 hammer_tid_t next_tid;
163 int count;
164} *hammer_objid_cache_t;
165
8750964d 166/*
8cd0a023
MD
167 * Structure used to represent an inode in-memory.
168 *
169 * The record and data associated with an inode may be out of sync with
170 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
171 * clear).
172 *
173 * An inode may also hold a cache of unsynchronized records, used for
174 * database and directories only. Unsynchronized regular file data is
175 * stored in the buffer cache.
176 *
177 * NOTE: A file which is created and destroyed within the initial
178 * synchronization period can wind up not doing any disk I/O at all.
179 *
180 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
8750964d
MD
181 */
182struct hammer_ino_rb_tree;
183struct hammer_inode;
184RB_HEAD(hammer_ino_rb_tree, hammer_inode);
185RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
8cd0a023
MD
186 hammer_ino_rb_compare, hammer_inode_info_t);
187
188struct hammer_rec_rb_tree;
189struct hammer_record;
190RB_HEAD(hammer_rec_rb_tree, hammer_record);
191RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
192 hammer_rec_rb_compare, hammer_base_elm_t);
193
194TAILQ_HEAD(hammer_node_list, hammer_node);
8750964d
MD
195
196struct hammer_inode {
1f07f686
MD
197 RB_ENTRY(hammer_inode) rb_node;
198 hammer_inode_state_t flush_state;
199 int flush_group;
059819e3 200 TAILQ_ENTRY(hammer_inode) flush_entry;
1f07f686 201 struct hammer_record_list target_list; /* target of dependant recs */
b84de5af
MD
202 u_int64_t obj_id; /* (key) object identifier */
203 hammer_tid_t obj_asof; /* (key) snapshot or 0 */
204 struct hammer_mount *hmp;
0729c8c8 205 hammer_objid_cache_t objid_cache;
b84de5af
MD
206 int flags;
207 int error; /* flush error */
208 int cursor_ip_refs; /* sanity */
209 struct vnode *vp;
210 struct lockf advlock;
211 struct hammer_lock lock; /* sync copy interlock */
212 TAILQ_HEAD(, bio) bio_list; /* BIOs to flush out */
213 TAILQ_HEAD(, bio) bio_alt_list; /* BIOs to flush out */
214 off_t trunc_off;
215 struct hammer_inode_record ino_rec; /* in-memory cache */
216 struct hammer_inode_data ino_data; /* in-memory cache */
217 struct hammer_rec_rb_tree rec_tree; /* in-memory cache */
61aeeb33 218 struct hammer_node *cache[2]; /* search initiate cache */
b84de5af
MD
219
220 /*
221 * When a demark is created to synchronize an inode to
222 * disk, certain fields are copied so the front-end VOPs
223 * can continue to run in parallel with the synchronization
224 * occuring in the background.
225 */
226 int sync_flags; /* to-sync flags cache */
227 off_t sync_trunc_off; /* to-sync truncation */
228 struct hammer_inode_record sync_ino_rec;/* to-sync cache */
229 struct hammer_inode_data sync_ino_data; /* to-sync cache */
8750964d
MD
230};
231
8cd0a023
MD
232typedef struct hammer_inode *hammer_inode_t;
233
66325755
MD
234#define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
235
8cd0a023
MD
236#define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
237#define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */
238#define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
1f07f686 239#define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records */
8cd0a023 240#define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
a89aec1b 241#define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
869e8f55 242#define HAMMER_INODE_DELETED 0x0080 /* inode delete (backend) */
76376933 243#define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
d113fda1 244#define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
e8599db1 245#define HAMMER_INODE_VHELD 0x0400 /* vnode held on sync */
0a72edae 246#define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
f3b0f382 247#define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
b84de5af 248#define HAMMER_INODE_REFLUSH 0x2000 /* pipelined flush during flush */
1f07f686 249#define HAMMER_INODE_WRITE_ALT 0x4000 /* strategy writes to alt bioq */
059819e3 250#define HAMMER_INODE_FLUSHW 0x8000 /* Someone waiting for flush */
8cd0a023 251
b84de5af 252#define HAMMER_INODE_TRUNCATED 0x00010000
869e8f55 253#define HAMMER_INODE_DELETING 0x00020000 /* inode delete request (frontend)*/
4e17f465 254#define HAMMER_INODE_RESIGNAL 0x00040000 /* re-signal on re-flush */
19619882 255#define HAMMER_INODE_RESIGNAL 0x00040000 /* re-signal on re-flush */
b84de5af 256
0b075555 257#define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \
f3b0f382 258 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
1f07f686
MD
259 HAMMER_INODE_ITIMES|HAMMER_INODE_TRUNCATED|\
260 HAMMER_INODE_DELETING)
261
262#define HAMMER_INODE_MODMASK_NOXDIRTY \
263 (HAMMER_INODE_MODMASK & ~HAMMER_INODE_XDIRTY)
0b075555 264
8cd0a023 265#define HAMMER_MAX_INODE_CURSORS 4
66325755 266
f90dde4c 267#define HAMMER_FLUSH_SIGNAL 0x0001
4e17f465 268#define HAMMER_FLUSH_RECURSION 0x0002
f90dde4c 269
8750964d 270/*
1f07f686
MD
271 * Structure used to represent an unsynchronized record in-memory. These
272 * records typically represent directory entries. Only non-historical
273 * records are kept in-memory.
274 *
275 * Records are organized as a per-inode RB-Tree. If the inode is not
8cd0a023
MD
276 * on disk then neither are any records and the in-memory record tree
277 * represents the entire contents of the inode. If the inode is on disk
278 * then the on-disk B-Tree is scanned in parallel with the in-memory
279 * RB-Tree to synthesize the current state of the file.
280 *
1f07f686
MD
281 * Records are also used to enforce the ordering of directory create/delete
282 * operations. A new inode will not be flushed to disk unless its related
283 * directory entry is also being flushed at the same time. A directory entry
284 * will not be removed unless its related inode is also being removed at the
285 * same time.
8750964d 286 */
1f07f686 287typedef enum hammer_record_type {
e8599db1 288 HAMMER_MEM_RECORD_GENERAL, /* misc record */
1f07f686
MD
289 HAMMER_MEM_RECORD_ADD, /* positive memory cache record */
290 HAMMER_MEM_RECORD_DEL /* negative delete-on-disk record */
291} hammer_record_type_t;
292
8cd0a023
MD
293struct hammer_record {
294 RB_ENTRY(hammer_record) rb_node;
1f07f686
MD
295 TAILQ_ENTRY(hammer_record) target_entry;
296 hammer_inode_state_t flush_state;
297 int flush_group;
298 hammer_record_type_t type;
a89aec1b 299 struct hammer_lock lock;
8cd0a023 300 struct hammer_inode *ip;
1f07f686 301 struct hammer_inode *target_ip;
8cd0a023
MD
302 union hammer_record_ondisk rec;
303 union hammer_data_ondisk *data;
8cd0a023
MD
304 int flags;
305};
8750964d 306
8cd0a023
MD
307typedef struct hammer_record *hammer_record_t;
308
d36ec43b
MD
309/*
310 * Record flags. Note that FE can only be set by the frontend if the
311 * record has not been interlocked by the backend w/ BE.
312 */
8cd0a023
MD
313#define HAMMER_RECF_ALLOCDATA 0x0001
314#define HAMMER_RECF_ONRBTREE 0x0002
b84de5af 315#define HAMMER_RECF_DELETED_FE 0x0004 /* deleted (frontend) */
d36ec43b
MD
316#define HAMMER_RECF_DELETED_BE 0x0008 /* deleted (backend) */
317#define HAMMER_RECF_INBAND 0x0010
318#define HAMMER_RECF_INTERLOCK_BE 0x0020 /* backend interlock */
319#define HAMMER_RECF_WANTED 0x0040
1f07f686 320#define HAMMER_RECF_CONVERT_DELETE 0x0100 /* special case */
8cd0a023
MD
321
322/*
47197d71 323 * In-memory structures representing on-disk structures.
8cd0a023 324 */
8750964d 325struct hammer_volume;
427e5fc6 326struct hammer_buffer;
8cd0a023 327struct hammer_node;
e8599db1 328struct hammer_undo;
8750964d 329RB_HEAD(hammer_vol_rb_tree, hammer_volume);
427e5fc6 330RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 331RB_HEAD(hammer_nod_rb_tree, hammer_node);
e8599db1 332RB_HEAD(hammer_und_rb_tree, hammer_undo);
8750964d
MD
333
334RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
335 hammer_vol_rb_compare, int32_t);
427e5fc6 336RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
47197d71 337 hammer_buf_rb_compare, hammer_off_t);
8cd0a023 338RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
47197d71 339 hammer_nod_rb_compare, hammer_off_t);
e8599db1
MD
340RB_PROTOTYPE2(hammer_und_rb_tree, hammer_undo, rb_node,
341 hammer_und_rb_compare, hammer_off_t);
8750964d 342
66325755
MD
343/*
344 * IO management - embedded at the head of various in-memory structures
10a5d1ba
MD
345 *
346 * VOLUME - hammer_volume containing meta-data
347 * META_BUFFER - hammer_buffer containing meta-data
348 * DATA_BUFFER - hammer_buffer containing pure-data
349 *
350 * Dirty volume headers and dirty meta-data buffers are locked until the
351 * flusher can sequence them out. Dirty pure-data buffers can be written.
352 * Clean buffers can be passively released.
66325755 353 */
10a5d1ba
MD
354typedef enum hammer_io_type {
355 HAMMER_STRUCTURE_VOLUME,
356 HAMMER_STRUCTURE_META_BUFFER,
357 HAMMER_STRUCTURE_UNDO_BUFFER,
358 HAMMER_STRUCTURE_DATA_BUFFER
359} hammer_io_type_t;
66325755
MD
360
361union hammer_io_structure;
055f5ff8 362struct hammer_io;
66325755
MD
363
364struct worklist {
365 LIST_ENTRY(worklist) node;
366};
367
10a5d1ba
MD
368TAILQ_HEAD(hammer_io_list, hammer_io);
369typedef struct hammer_io_list *hammer_io_list_t;
055f5ff8 370
66325755 371struct hammer_io {
10a5d1ba
MD
372 struct worklist worklist;
373 struct hammer_lock lock;
374 enum hammer_io_type type;
375 struct hammer_mount *hmp;
376 TAILQ_ENTRY(hammer_io) mod_entry; /* list entry if modified */
377 hammer_io_list_t mod_list;
378 struct buf *bp;
379 int64_t offset;
380 int loading; /* loading/unloading interlock */
381 int modify_refs;
382
66325755
MD
383 u_int modified : 1; /* bp's data was modified */
384 u_int released : 1; /* bp released (w/ B_LOCKED set) */
055f5ff8
MD
385 u_int running : 1; /* bp write IO in progress */
386 u_int waiting : 1; /* someone is waiting on us */
b33e2cc0 387 u_int validated : 1; /* ondisk has been validated */
b58c6388
MD
388 u_int flush : 1; /* flush on last release */
389 u_int waitdep : 1; /* flush waits for dependancies */
66325755
MD
390};
391
8cd0a023
MD
392typedef struct hammer_io *hammer_io_t;
393
66325755 394/*
8cd0a023 395 * In-memory volume representing on-disk buffer
66325755 396 */
8750964d 397struct hammer_volume {
66325755 398 struct hammer_io io;
8750964d 399 RB_ENTRY(hammer_volume) rb_node;
47197d71 400 struct hammer_buf_rb_tree rb_bufs_root;
8750964d
MD
401 struct hammer_volume_ondisk *ondisk;
402 int32_t vol_no;
fbc6e32a 403 int64_t nblocks; /* note: special calculation for statfs */
47197d71
MD
404 int64_t buffer_base; /* base offset of buffer 0 */
405 hammer_off_t maxbuf_off; /* Maximum buffer offset */
c60bb2c5 406 char *vol_name;
8750964d 407 struct vnode *devvp;
427e5fc6 408 int vol_flags;
8750964d
MD
409};
410
8cd0a023
MD
411typedef struct hammer_volume *hammer_volume_t;
412
66325755 413/*
8cd0a023
MD
414 * In-memory buffer (other then volume, super-cluster, or cluster),
415 * representing an on-disk buffer.
66325755 416 */
427e5fc6 417struct hammer_buffer {
66325755 418 struct hammer_io io;
427e5fc6 419 RB_ENTRY(hammer_buffer) rb_node;
47197d71 420 void *ondisk;
427e5fc6 421 struct hammer_volume *volume;
34d829f7
MD
422 hammer_off_t zone2_offset;
423 hammer_off_t zoneX_offset;
8cd0a023 424 struct hammer_node_list clist;
66325755
MD
425};
426
8cd0a023
MD
427typedef struct hammer_buffer *hammer_buffer_t;
428
429/*
430 * In-memory B-Tree node, representing an on-disk B-Tree node.
431 *
432 * This is a hang-on structure which is backed by a hammer_buffer,
433 * indexed by a hammer_cluster, and used for fine-grained locking of
434 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
435 * can contain multiple nodes representing wildly disassociated portions
436 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
437 *
438 * This structure uses a cluster-relative index to reduce the number
439 * of layers required to access it, and also because all on-disk B-Tree
440 * references are cluster-relative offsets.
441 */
442struct hammer_node {
443 struct hammer_lock lock; /* node-by-node lock */
444 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
445 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
47197d71 446 hammer_off_t node_offset; /* full offset spec */
40043e7f 447 struct hammer_mount *hmp;
8cd0a023
MD
448 struct hammer_buffer *buffer; /* backing buffer */
449 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
450 struct hammer_node **cache1; /* passive cache(s) */
451 struct hammer_node **cache2;
b3deaf57 452 int flags;
740d8317 453 int loading; /* load interlock */
8cd0a023
MD
454};
455
b3deaf57
MD
456#define HAMMER_NODE_DELETED 0x0001
457#define HAMMER_NODE_FLUSH 0x0002
b3deaf57 458
8cd0a023
MD
459typedef struct hammer_node *hammer_node_t;
460
b33e2cc0
MD
461/*
462 * List of locked nodes.
463 */
464struct hammer_node_locklist {
465 struct hammer_node_locklist *next;
466 hammer_node_t node;
467};
468
469typedef struct hammer_node_locklist *hammer_node_locklist_t;
470
471
8cd0a023
MD
472/*
473 * Common I/O management structure - embedded in in-memory structures
474 * which are backed by filesystem buffers.
475 */
66325755
MD
476union hammer_io_structure {
477 struct hammer_io io;
478 struct hammer_volume volume;
66325755 479 struct hammer_buffer buffer;
8750964d
MD
480};
481
055f5ff8
MD
482typedef union hammer_io_structure *hammer_io_structure_t;
483
bf686dbe
MD
484/*
485 * Allocation holes are recorded for a short period of time in an attempt
486 * to use up the space.
487 */
488
489#define HAMMER_MAX_HOLES 8
490
491struct hammer_hole;
492
493struct hammer_holes {
494 TAILQ_HEAD(, hammer_hole) list;
495 int count;
496};
497
498typedef struct hammer_holes *hammer_holes_t;
499
500struct hammer_hole {
501 TAILQ_ENTRY(hammer_hole) entry;
502 hammer_off_t offset;
503 int bytes;
504};
505
506typedef struct hammer_hole *hammer_hole_t;
427e5fc6 507
8cd0a023
MD
508#include "hammer_cursor.h"
509
e8599db1
MD
510/*
511 * Undo history tracking
512 */
513#define HAMMER_MAX_UNDOS 256
514
515struct hammer_undo {
516 RB_ENTRY(hammer_undo) rb_node;
517 TAILQ_ENTRY(hammer_undo) lru_entry;
518 hammer_off_t offset;
519 int bytes;
520};
521
522typedef struct hammer_undo *hammer_undo_t;
523
8750964d
MD
524/*
525 * Internal hammer mount data structure
526 */
527struct hammer_mount {
528 struct mount *mp;
27ea2398 529 /*struct vnode *rootvp;*/
8750964d
MD
530 struct hammer_ino_rb_tree rb_inos_root;
531 struct hammer_vol_rb_tree rb_vols_root;
40043e7f 532 struct hammer_nod_rb_tree rb_nods_root;
e8599db1 533 struct hammer_und_rb_tree rb_undo_root;
8750964d 534 struct hammer_volume *rootvol;
47197d71
MD
535 struct hammer_base_elm root_btree_beg;
536 struct hammer_base_elm root_btree_end;
d26d0ae9 537 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
195c19a1
MD
538 int hflags;
539 int ronly;
540 int nvolumes;
d26d0ae9 541 int volume_iterator;
1f07f686
MD
542 int flusher_signal; /* flusher thread sequencer */
543 int flusher_act; /* currently active flush group */
544 int flusher_done; /* set to act when complete */
545 int flusher_next; /* next flush group */
4e17f465 546 int flusher_lock; /* lock sequencing of the next flush */
059819e3 547 int flusher_exiting;
c9b9e29d 548 hammer_off_t flusher_undo_start; /* UNDO window for flushes */
f90dde4c 549 int reclaim_count;
059819e3 550 thread_t flusher_td;
855942b6 551 u_int check_interrupt;
8750964d 552 uuid_t fsid;
66325755 553 udev_t fsid_udev;
10a5d1ba
MD
554 struct hammer_io_list volu_list; /* dirty undo buffers */
555 struct hammer_io_list undo_list; /* dirty undo buffers */
556 struct hammer_io_list data_list; /* dirty data buffers */
557 struct hammer_io_list meta_list; /* dirty meta bufs */
558 struct hammer_io_list lose_list; /* loose buffers */
559 int locked_dirty_count; /* meta/volu count */
f90dde4c 560 int io_running_count;
0729c8c8 561 int objid_cache_count;
7f7c1f84 562 hammer_tid_t asof;
b84de5af 563 hammer_off_t next_tid;
66325755 564 u_int32_t namekey_iterator;
f03c9cf4 565 hammer_off_t zone_limits[HAMMER_MAX_ZONES];
513ca7d7 566 struct netexport export;
9480ff55 567 struct hammer_lock sync_lock;
c9b9e29d 568 struct hammer_lock free_lock;
40043e7f 569 struct lock blockmap_lock;
0729c8c8 570 struct hammer_blockmap blockmap[HAMMER_MAX_ZONES];
e8599db1
MD
571 struct hammer_holes holes[HAMMER_MAX_ZONES];
572 struct hammer_undo undos[HAMMER_MAX_UNDOS];
573 int undo_alloc;
574 TAILQ_HEAD(, hammer_undo) undo_lru_list;
059819e3 575 TAILQ_HEAD(, hammer_inode) flush_list;
0729c8c8 576 TAILQ_HEAD(, hammer_objid_cache) objid_cache_list;
8750964d
MD
577};
578
8cd0a023 579typedef struct hammer_mount *hammer_mount_t;
8750964d 580
fbc6e32a
MD
581struct hammer_sync_info {
582 int error;
583 int waitfor;
584};
585
8750964d
MD
586#endif
587
588#if defined(_KERNEL)
589
590extern struct vop_ops hammer_vnode_vops;
7a04d74f
MD
591extern struct vop_ops hammer_spec_vops;
592extern struct vop_ops hammer_fifo_vops;
66325755 593extern struct bio_ops hammer_bioops;
427e5fc6 594
d5ef456e 595extern int hammer_debug_general;
77062c8a 596extern int hammer_debug_debug;
e8599db1 597extern int hammer_debug_inode;
7d683b0f 598extern int hammer_debug_locks;
b3deaf57 599extern int hammer_debug_btree;
d113fda1 600extern int hammer_debug_tid;
b33e2cc0 601extern int hammer_debug_recover;
46fe7ae1 602extern int hammer_debug_recover_faults;
b3deaf57
MD
603extern int hammer_count_inodes;
604extern int hammer_count_records;
605extern int hammer_count_record_datas;
606extern int hammer_count_volumes;
b3deaf57
MD
607extern int hammer_count_buffers;
608extern int hammer_count_nodes;
9480ff55
MD
609extern int hammer_count_dirtybufs;
610extern int hammer_limit_dirtybufs;
1f07f686 611extern int hammer_bio_count;
7d683b0f 612extern int64_t hammer_contention_count;
b3deaf57 613
8750964d
MD
614int hammer_vop_inactive(struct vop_inactive_args *);
615int hammer_vop_reclaim(struct vop_reclaim_args *);
e8599db1 616int hammer_get_vnode(struct hammer_inode *ip, struct vnode **vpp);
36f82b23 617struct hammer_inode *hammer_get_inode(hammer_transaction_t trans,
61aeeb33 618 struct hammer_node **cache,
d113fda1
MD
619 u_int64_t obj_id, hammer_tid_t asof, int flags,
620 int *errorp);
66325755
MD
621void hammer_put_inode(struct hammer_inode *ip);
622void hammer_put_inode_ref(struct hammer_inode *ip);
623
8cd0a023 624int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
a89aec1b 625int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
8cd0a023
MD
626int hammer_install_volume(hammer_mount_t hmp, const char *volname);
627
a89aec1b 628int hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip);
4e17f465 629int hammer_ip_first(hammer_cursor_t cursor);
a89aec1b 630int hammer_ip_next(hammer_cursor_t cursor);
40043e7f 631int hammer_ip_resolve_record_and_data(hammer_cursor_t cursor);
8cd0a023 632int hammer_ip_resolve_data(hammer_cursor_t cursor);
195c19a1 633int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid);
7dc57964 634int hammer_delete_at_cursor(hammer_cursor_t cursor, int64_t *stat_bytes);
b3deaf57 635int hammer_ip_check_directory_empty(hammer_transaction_t trans,
1f07f686 636 hammer_cursor_t parent_cursor, hammer_inode_t ip);
fbc6e32a 637int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
fbc6e32a 638
8cd0a023 639hammer_record_t
40043e7f 640 hammer_alloc_mem_record(hammer_inode_t ip);
d36ec43b 641void hammer_flush_record_done(hammer_record_t record, int error);
b84de5af 642void hammer_wait_mem_record(hammer_record_t record);
b3deaf57 643void hammer_rel_mem_record(hammer_record_t record);
b84de5af 644
6a37e7e4 645int hammer_cursor_up(hammer_cursor_t cursor);
8cd0a023 646int hammer_cursor_down(hammer_cursor_t cursor);
6a37e7e4
MD
647int hammer_cursor_upgrade(hammer_cursor_t cursor);
648void hammer_cursor_downgrade(hammer_cursor_t cursor);
32c90105
MD
649int hammer_cursor_seek(hammer_cursor_t cursor, hammer_node_t node,
650 int index);
8cd0a023
MD
651void hammer_lock_ex(struct hammer_lock *lock);
652int hammer_lock_ex_try(struct hammer_lock *lock);
653void hammer_lock_sh(struct hammer_lock *lock);
6a37e7e4
MD
654int hammer_lock_upgrade(struct hammer_lock *lock);
655void hammer_lock_downgrade(struct hammer_lock *lock);
427e5fc6 656void hammer_unlock(struct hammer_lock *lock);
66325755
MD
657void hammer_ref(struct hammer_lock *lock);
658void hammer_unref(struct hammer_lock *lock);
8cd0a023 659
66325755 660u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
661void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
662void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
663hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
7f7c1f84 664hammer_tid_t hammer_now_tid(void);
d113fda1 665hammer_tid_t hammer_str_to_tid(const char *str);
0729c8c8
MD
666hammer_tid_t hammer_alloc_objid(hammer_transaction_t trans, hammer_inode_t dip);
667void hammer_clear_objid(hammer_inode_t dip);
668void hammer_destroy_objid_cache(hammer_mount_t hmp);
8cd0a023 669
e8599db1
MD
670int hammer_enter_undo_history(hammer_mount_t hmp, hammer_off_t offset,
671 int bytes);
672void hammer_clear_undo_history(hammer_mount_t hmp);
66325755 673enum vtype hammer_get_vnode_type(u_int8_t obj_type);
6b4f890b 674int hammer_get_dtype(u_int8_t obj_type);
66325755
MD
675u_int8_t hammer_get_obj_type(enum vtype vtype);
676int64_t hammer_directory_namekey(void *name, int len);
427e5fc6 677
36f82b23 678int hammer_init_cursor(hammer_transaction_t trans, hammer_cursor_t cursor,
4e17f465
MD
679 struct hammer_node **cache, hammer_inode_t ip);
680int hammer_reinit_cursor(hammer_cursor_t cursor);
681void hammer_normalize_cursor(hammer_cursor_t cursor);
8cd0a023 682void hammer_done_cursor(hammer_cursor_t cursor);
6b4f890b 683void hammer_mem_done(hammer_cursor_t cursor);
8cd0a023
MD
684
685int hammer_btree_lookup(hammer_cursor_t cursor);
d26d0ae9 686int hammer_btree_first(hammer_cursor_t cursor);
32c90105 687int hammer_btree_last(hammer_cursor_t cursor);
8cd0a023
MD
688int hammer_btree_extract(hammer_cursor_t cursor, int flags);
689int hammer_btree_iterate(hammer_cursor_t cursor);
32c90105 690int hammer_btree_iterate_reverse(hammer_cursor_t cursor);
8cd0a023
MD
691int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
692int hammer_btree_delete(hammer_cursor_t cursor);
693int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
d26d0ae9 694int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
32c90105
MD
695int hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid);
696int hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid);
697
fe7678ee 698
b33e2cc0
MD
699int hammer_btree_lock_children(hammer_cursor_t cursor,
700 struct hammer_node_locklist **locklistp);
b33e2cc0 701
c0ade690
MD
702void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
703void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
8750964d 704
47197d71
MD
705void *hammer_bread(struct hammer_mount *hmp, hammer_off_t off,
706 int *errorp, struct hammer_buffer **bufferp);
707void *hammer_bnew(struct hammer_mount *hmp, hammer_off_t off,
708 int *errorp, struct hammer_buffer **bufferp);
8cd0a023
MD
709
710hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
4e17f465 711int hammer_dowrite(hammer_cursor_t cursor, hammer_inode_t ip,
059819e3 712 struct bio *bio);
427e5fc6 713
8cd0a023 714hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 715 int32_t vol_no, int *errorp);
47197d71
MD
716hammer_buffer_t hammer_get_buffer(hammer_mount_t hmp,
717 hammer_off_t buf_offset, int isnew, int *errorp);
b58c6388 718void hammer_uncache_buffer(struct hammer_mount *hmp, hammer_off_t off);
8cd0a023 719
fbc6e32a 720int hammer_ref_volume(hammer_volume_t volume);
8cd0a023
MD
721int hammer_ref_buffer(hammer_buffer_t buffer);
722void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
723
8cd0a023 724void hammer_rel_volume(hammer_volume_t volume, int flush);
8cd0a023
MD
725void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
726
513ca7d7
MD
727int hammer_vfs_export(struct mount *mp, int op,
728 const struct export_args *export);
19619882
MD
729hammer_node_t hammer_get_node(hammer_mount_t hmp, hammer_off_t node_offset,
730 int isnew, int *errorp);
740d8317 731void hammer_ref_node(hammer_node_t node);
055f5ff8
MD
732hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp,
733 struct hammer_node **cache, int *errorp);
8cd0a023 734void hammer_rel_node(hammer_node_t node);
36f82b23
MD
735void hammer_delete_node(hammer_transaction_t trans,
736 hammer_node_t node);
8cd0a023
MD
737void hammer_cache_node(hammer_node_t node,
738 struct hammer_node **cache);
739void hammer_uncache_node(struct hammer_node **cache);
740void hammer_flush_node(hammer_node_t node);
741
427e5fc6
MD
742void hammer_dup_buffer(struct hammer_buffer **bufferp,
743 struct hammer_buffer *buffer);
36f82b23
MD
744hammer_node_t hammer_alloc_btree(hammer_transaction_t trans, int *errorp);
745void *hammer_alloc_record(hammer_transaction_t trans,
bf686dbe 746 hammer_off_t *rec_offp, u_int16_t rec_type,
40043e7f
MD
747 struct hammer_buffer **rec_bufferp,
748 int32_t data_len, void **datap,
19619882 749 hammer_off_t *data_offp,
40043e7f 750 struct hammer_buffer **data_bufferp, int *errorp);
36f82b23 751void *hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
bf686dbe
MD
752 hammer_off_t *data_offsetp,
753 struct hammer_buffer **data_bufferp, int *errorp);
754
059819e3
MD
755int hammer_generate_undo(hammer_transaction_t trans, hammer_io_t io,
756 hammer_off_t zone1_offset, void *base, int len);
427e5fc6 757
66325755 758void hammer_put_volume(struct hammer_volume *volume, int flush);
66325755 759void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6 760
36f82b23
MD
761hammer_off_t hammer_freemap_alloc(hammer_transaction_t trans,
762 hammer_off_t owner, int *errorp);
763void hammer_freemap_free(hammer_transaction_t trans, hammer_off_t phys_offset,
c3be93f2 764 hammer_off_t owner, int *errorp);
36f82b23 765hammer_off_t hammer_blockmap_alloc(hammer_transaction_t trans, int zone,
40043e7f 766 int bytes, int *errorp);
36f82b23
MD
767void hammer_blockmap_free(hammer_transaction_t trans,
768 hammer_off_t bmap_off, int bytes);
bf686dbe
MD
769int hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t bmap_off,
770 int *curp, int *errorp);
40043e7f
MD
771hammer_off_t hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
772 int *errorp);
bf686dbe
MD
773hammer_off_t hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
774 int *errorp);
c9b9e29d 775int64_t hammer_undo_used(hammer_mount_t hmp);
1f07f686
MD
776int64_t hammer_undo_space(hammer_mount_t hmp);
777int64_t hammer_undo_max(hammer_mount_t hmp);
778
40043e7f 779
8cd0a023
MD
780void hammer_start_transaction(struct hammer_transaction *trans,
781 struct hammer_mount *hmp);
36f82b23
MD
782void hammer_simple_transaction(struct hammer_transaction *trans,
783 struct hammer_mount *hmp);
b84de5af
MD
784void hammer_start_transaction_fls(struct hammer_transaction *trans,
785 struct hammer_mount *hmp);
786void hammer_done_transaction(struct hammer_transaction *trans);
66325755
MD
787
788void hammer_modify_inode(struct hammer_transaction *trans,
8cd0a023 789 hammer_inode_t ip, int flags);
f90dde4c 790void hammer_flush_inode(hammer_inode_t ip, int flags);
b84de5af
MD
791void hammer_flush_inode_done(hammer_inode_t ip);
792void hammer_wait_inode(hammer_inode_t ip);
793
8cd0a023
MD
794int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
795 struct ucred *cred, struct hammer_inode *dip,
796 struct hammer_inode **ipp);
a89aec1b 797void hammer_rel_inode(hammer_inode_t ip, int flush);
1f07f686
MD
798int hammer_sync_inode(hammer_inode_t ip);
799void hammer_test_inode(hammer_inode_t ip);
e8599db1 800void hammer_inode_unloadable_check(hammer_inode_t ip, int getvp);
8cd0a023 801
a89aec1b 802int hammer_ip_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
803 hammer_inode_t dip, struct namecache *ncp,
804 hammer_inode_t nip);
a89aec1b 805int hammer_ip_del_directory(struct hammer_transaction *trans,
8cd0a023
MD
806 hammer_cursor_t cursor, hammer_inode_t dip,
807 hammer_inode_t ip);
7a04d74f
MD
808int hammer_ip_add_record(struct hammer_transaction *trans,
809 hammer_record_t record);
4e17f465
MD
810int hammer_ip_delete_range(hammer_cursor_t cursor, hammer_inode_t ip,
811 int64_t ran_beg, int64_t ran_end);
812int hammer_ip_delete_range_all(hammer_cursor_t cursor, hammer_inode_t ip,
813 int *countp);
814int hammer_ip_sync_data(hammer_cursor_t cursor, hammer_inode_t ip,
815 int64_t offset, void *data, int bytes);
36f82b23 816int hammer_ip_sync_record(hammer_transaction_t trans, hammer_record_t rec);
4e17f465 817int hammer_ip_sync_record_cursor(hammer_cursor_t cursor, hammer_record_t rec);
66325755 818
7dc57964
MD
819int hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
820 struct ucred *cred);
821
10a5d1ba
MD
822void hammer_io_init(hammer_io_t io, hammer_mount_t hmp,
823 enum hammer_io_type type);
824void hammer_io_reinit(hammer_io_t io, enum hammer_io_type type);
66325755
MD
825int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
826int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
b58c6388 827void hammer_io_release(struct hammer_io *io);
055f5ff8 828void hammer_io_flush(struct hammer_io *io);
8cd0a023 829int hammer_io_checkflush(hammer_io_t io);
61aeeb33 830void hammer_io_clear_modify(struct hammer_io *io);
055f5ff8 831void hammer_io_waitdep(struct hammer_io *io);
66325755 832
36f82b23
MD
833void hammer_modify_volume(hammer_transaction_t trans, hammer_volume_t volume,
834 void *base, int len);
835void hammer_modify_buffer(hammer_transaction_t trans, hammer_buffer_t buffer,
836 void *base, int len);
10a5d1ba
MD
837void hammer_modify_volume_done(hammer_volume_t volume);
838void hammer_modify_buffer_done(hammer_buffer_t buffer);
0b075555 839
36f82b23
MD
840int hammer_ioc_reblock(hammer_transaction_t trans, hammer_inode_t ip,
841 struct hammer_ioc_reblock *reblock);
bf686dbe
MD
842
843void hammer_init_holes(hammer_mount_t hmp, hammer_holes_t holes);
844void hammer_free_holes(hammer_mount_t hmp, hammer_holes_t holes);
855942b6 845int hammer_signal_check(hammer_mount_t hmp);
bf686dbe 846
059819e3
MD
847void hammer_flusher_create(hammer_mount_t hmp);
848void hammer_flusher_destroy(hammer_mount_t hmp);
849void hammer_flusher_sync(hammer_mount_t hmp);
850void hammer_flusher_async(hammer_mount_t hmp);
851
f90dde4c
MD
852int hammer_recover(hammer_mount_t hmp, hammer_volume_t rootvol);
853
19619882
MD
854void hammer_crc_set_blockmap(hammer_blockmap_t blockmap);
855void hammer_crc_set_volume(hammer_volume_ondisk_t ondisk);
856
857int hammer_crc_test_blockmap(hammer_blockmap_t blockmap);
858int hammer_crc_test_volume(hammer_volume_ondisk_t ondisk);
859int hammer_crc_test_record(hammer_record_ondisk_t ondisk);
860int hammer_crc_test_btree(hammer_node_ondisk_t ondisk);
77062c8a 861void hkprintf(const char *ctl, ...);
19619882 862
055f5ff8 863#endif
427e5fc6 864
8cd0a023 865static __inline void
36f82b23 866hammer_modify_node_noundo(hammer_transaction_t trans, hammer_node_t node)
bf686dbe 867{
36f82b23 868 hammer_modify_buffer(trans, node->buffer, NULL, 0);
bf686dbe
MD
869}
870
871static __inline void
36f82b23 872hammer_modify_node_all(hammer_transaction_t trans, struct hammer_node *node)
8cd0a023 873{
36f82b23
MD
874 hammer_modify_buffer(trans, node->buffer,
875 node->ondisk, sizeof(*node->ondisk));
427e5fc6
MD
876}
877
bf686dbe 878static __inline void
36f82b23
MD
879hammer_modify_node(hammer_transaction_t trans, hammer_node_t node,
880 void *base, int len)
bf686dbe 881{
19619882
MD
882 hammer_crc_t *crcptr;
883
bf686dbe
MD
884 KKASSERT((char *)base >= (char *)node->ondisk &&
885 (char *)base + len <=
886 (char *)node->ondisk + sizeof(*node->ondisk));
36f82b23 887 hammer_modify_buffer(trans, node->buffer, base, len);
19619882
MD
888 crcptr = &node->ondisk->crc;
889 hammer_modify_buffer(trans, node->buffer, crcptr, sizeof(hammer_crc_t));
890 --node->buffer->io.modify_refs; /* only want one ref */
bf686dbe
MD
891}
892
10a5d1ba
MD
893static __inline void
894hammer_modify_node_done(hammer_node_t node)
895{
19619882 896 node->ondisk->crc = crc32(&node->ondisk->crc + 1, HAMMER_BTREE_CRCSIZE);
10a5d1ba
MD
897 hammer_modify_buffer_done(node->buffer);
898}
899
19619882
MD
900static __inline void
901hammer_modify_record_noundo(hammer_transaction_t trans, hammer_buffer_t buffer,
902 hammer_record_ondisk_t rec __unused)
903{
904 hammer_modify_buffer(trans, buffer, NULL, 0);
905}
906
907static __inline void
908hammer_modify_record_all(hammer_transaction_t trans, hammer_buffer_t buffer,
909 hammer_record_ondisk_t rec)
910{
911 KKASSERT((char *)rec >= (char *)buffer->ondisk &&
912 (char *)(rec + 1) <= (char *)buffer->ondisk + HAMMER_BUFSIZE);
913 hammer_modify_buffer(trans, buffer, rec, sizeof(*rec));
914}
915
bf686dbe 916static __inline void
36f82b23 917hammer_modify_record(hammer_transaction_t trans, hammer_buffer_t buffer,
19619882
MD
918 hammer_record_ondisk_t rec, void *base, int len,
919 int dodelete)
bf686dbe
MD
920{
921 KKASSERT((char *)base >= (char *)buffer->ondisk &&
922 (char *)base + len <= (char *)buffer->ondisk + HAMMER_BUFSIZE);
19619882
MD
923 KKASSERT((char *)rec >= (char *)buffer->ondisk &&
924 (char *)(rec + 1) <= (char *)buffer->ondisk + HAMMER_BUFSIZE);
925
926 /*
927 * Due to undo overheads it is more efficient to just undo the whole
928 * record.
929 */
930 hammer_modify_buffer(trans, buffer, rec, sizeof(*rec));
931#if 0
36f82b23 932 hammer_modify_buffer(trans, buffer, base, len);
19619882
MD
933 hammer_modify_buffer(trans, buffer, &rec->base.rec_crc,
934 sizeof(rec->base.rec_crc));
935 --node->buffer->io.modify_refs; /* only want one ref */
936 if (dodelete) {
937 hammer_modify_buffer(trans, buffer, &rec->base.signature,
938 sizeof(rec->base.signature));
939 --node->buffer->io.modify_refs; /* only want one ref */
940 }
941#endif
bf686dbe
MD
942}
943
10a5d1ba 944static __inline void
19619882 945hammer_modify_record_done(hammer_buffer_t buffer, hammer_record_ondisk_t rec)
10a5d1ba 946{
19619882
MD
947 rec->base.rec_crc = crc32(&rec->base.rec_crc + 1,
948 HAMMER_RECORD_CRCSIZE);
10a5d1ba
MD
949 hammer_modify_buffer_done(buffer);
950}
951
e8599db1
MD
952#define hammer_modify_volume_field(trans, vol, field) \
953 hammer_modify_volume(trans, vol, &(vol)->ondisk->field, \
954 sizeof((vol)->ondisk->field))
955
c9b9e29d
MD
956#define hammer_modify_node_field(trans, node, field) \
957 hammer_modify_node(trans, node, &(node)->ondisk->field, \
958 sizeof((node)->ondisk->field))
959
19619882
MD
960#define hammer_modify_record_field(trans, buffer, rec, field, dodelete) \
961 hammer_modify_record(trans, buffer, rec, &(rec)->field, \
77062c8a 962 sizeof((rec)->field), dodelete)
e8599db1 963