| 1 | /* |
| 2 | * Copyright (c) 2007 The DragonFly Project. All rights reserved. |
| 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 | * |
| 34 | * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.25 2008/01/17 05:06:09 dillon Exp $ |
| 35 | */ |
| 36 | /* |
| 37 | * This header file contains structures used internally by the HAMMERFS |
| 38 | * implementation. See hammer_disk.h for on-disk structures. |
| 39 | */ |
| 40 | |
| 41 | #include <sys/param.h> |
| 42 | #include <sys/types.h> |
| 43 | #include <sys/kernel.h> |
| 44 | #include <sys/systm.h> |
| 45 | #include <sys/tree.h> |
| 46 | #include <sys/malloc.h> |
| 47 | #include <sys/mount.h> |
| 48 | #include <sys/vnode.h> |
| 49 | #include <sys/globaldata.h> |
| 50 | #include <sys/lockf.h> |
| 51 | #include <sys/buf.h> |
| 52 | #include <sys/queue.h> |
| 53 | #include <sys/globaldata.h> |
| 54 | |
| 55 | #include <sys/buf2.h> |
| 56 | #include "hammer_alist.h" |
| 57 | #include "hammer_disk.h" |
| 58 | #include "hammer_mount.h" |
| 59 | |
| 60 | #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) |
| 61 | |
| 62 | MALLOC_DECLARE(M_HAMMER); |
| 63 | |
| 64 | struct hammer_mount; |
| 65 | |
| 66 | /* |
| 67 | * Key structure used for custom RB tree inode lookups. This prototypes |
| 68 | * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info). |
| 69 | */ |
| 70 | typedef struct hammer_inode_info { |
| 71 | u_int64_t obj_id; /* (key) object identifier */ |
| 72 | hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */ |
| 73 | } *hammer_inode_info_t; |
| 74 | |
| 75 | /* |
| 76 | * HAMMER Transaction tracking |
| 77 | */ |
| 78 | struct hammer_transaction { |
| 79 | struct hammer_mount *hmp; |
| 80 | hammer_tid_t tid; |
| 81 | struct hammer_volume *rootvol; |
| 82 | }; |
| 83 | |
| 84 | typedef struct hammer_transaction *hammer_transaction_t; |
| 85 | |
| 86 | /* |
| 87 | * HAMMER locks |
| 88 | */ |
| 89 | struct hammer_lock { |
| 90 | int refs; /* active references delay writes */ |
| 91 | int lockcount; /* lock count for exclusive/shared access */ |
| 92 | int wanted; |
| 93 | struct thread *locktd; |
| 94 | }; |
| 95 | |
| 96 | static __inline int |
| 97 | hammer_islocked(struct hammer_lock *lock) |
| 98 | { |
| 99 | return(lock->lockcount != 0); |
| 100 | } |
| 101 | |
| 102 | static __inline int |
| 103 | hammer_isactive(struct hammer_lock *lock) |
| 104 | { |
| 105 | return(lock->refs != 0); |
| 106 | } |
| 107 | |
| 108 | static __inline int |
| 109 | hammer_islastref(struct hammer_lock *lock) |
| 110 | { |
| 111 | return(lock->refs == 1); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Structure used to represent an inode in-memory. |
| 116 | * |
| 117 | * The record and data associated with an inode may be out of sync with |
| 118 | * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag |
| 119 | * clear). |
| 120 | * |
| 121 | * An inode may also hold a cache of unsynchronized records, used for |
| 122 | * database and directories only. Unsynchronized regular file data is |
| 123 | * stored in the buffer cache. |
| 124 | * |
| 125 | * NOTE: A file which is created and destroyed within the initial |
| 126 | * synchronization period can wind up not doing any disk I/O at all. |
| 127 | * |
| 128 | * Finally, an inode may cache numerous disk-referencing B-Tree cursors. |
| 129 | */ |
| 130 | struct hammer_ino_rb_tree; |
| 131 | struct hammer_inode; |
| 132 | RB_HEAD(hammer_ino_rb_tree, hammer_inode); |
| 133 | RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node, |
| 134 | hammer_ino_rb_compare, hammer_inode_info_t); |
| 135 | |
| 136 | struct hammer_rec_rb_tree; |
| 137 | struct hammer_record; |
| 138 | RB_HEAD(hammer_rec_rb_tree, hammer_record); |
| 139 | RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node, |
| 140 | hammer_rec_rb_compare, hammer_base_elm_t); |
| 141 | |
| 142 | TAILQ_HEAD(hammer_node_list, hammer_node); |
| 143 | |
| 144 | struct hammer_inode { |
| 145 | RB_ENTRY(hammer_inode) rb_node; |
| 146 | u_int64_t obj_id; /* (key) object identifier */ |
| 147 | hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */ |
| 148 | hammer_tid_t last_tid; /* last modified tid (for fsync) */ |
| 149 | struct hammer_mount *hmp; |
| 150 | int flags; |
| 151 | struct vnode *vp; |
| 152 | struct lockf advlock; |
| 153 | struct hammer_lock lock; |
| 154 | struct hammer_inode_record ino_rec; |
| 155 | struct hammer_inode_data ino_data; |
| 156 | struct hammer_rec_rb_tree rec_tree; /* red-black record tree */ |
| 157 | struct hammer_node *cache[2]; /* search initiate cache */ |
| 158 | }; |
| 159 | |
| 160 | typedef struct hammer_inode *hammer_inode_t; |
| 161 | |
| 162 | #define VTOI(vp) ((struct hammer_inode *)(vp)->v_data) |
| 163 | |
| 164 | #define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */ |
| 165 | #define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */ |
| 166 | #define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */ |
| 167 | #define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records present */ |
| 168 | #define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */ |
| 169 | #define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */ |
| 170 | #define HAMMER_INODE_DELETED 0x0080 /* inode ready for deletion */ |
| 171 | #define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */ |
| 172 | #define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */ |
| 173 | #define HAMMER_INODE_GONE 0x0400 /* delete flushed out */ |
| 174 | #define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */ |
| 175 | #define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */ |
| 176 | |
| 177 | #define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \ |
| 178 | HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \ |
| 179 | HAMMER_INODE_ITIMES|HAMMER_INODE_DELETED) |
| 180 | |
| 181 | #define HAMMER_MAX_INODE_CURSORS 4 |
| 182 | |
| 183 | /* |
| 184 | * Structure used to represent an unsynchronized record in-memory. This |
| 185 | * structure is orgranized in a per-inode RB-tree. If the inode is not |
| 186 | * on disk then neither are any records and the in-memory record tree |
| 187 | * represents the entire contents of the inode. If the inode is on disk |
| 188 | * then the on-disk B-Tree is scanned in parallel with the in-memory |
| 189 | * RB-Tree to synthesize the current state of the file. |
| 190 | * |
| 191 | * Only current (delete_tid == 0) unsynchronized records are kept in-memory. |
| 192 | */ |
| 193 | struct hammer_record { |
| 194 | RB_ENTRY(hammer_record) rb_node; |
| 195 | struct hammer_lock lock; |
| 196 | struct hammer_inode *ip; |
| 197 | union hammer_record_ondisk rec; |
| 198 | union hammer_data_ondisk *data; |
| 199 | int flags; |
| 200 | }; |
| 201 | |
| 202 | typedef struct hammer_record *hammer_record_t; |
| 203 | |
| 204 | #define HAMMER_RECF_ALLOCDATA 0x0001 |
| 205 | #define HAMMER_RECF_ONRBTREE 0x0002 |
| 206 | #define HAMMER_RECF_DELETED 0x0004 |
| 207 | #define HAMMER_RECF_EMBEDDED_DATA 0x0008 |
| 208 | #define HAMMER_RECF_SYNCING 0x0010 |
| 209 | |
| 210 | /* |
| 211 | * Structures used to internally represent a volume and a cluster |
| 212 | */ |
| 213 | struct hammer_volume; |
| 214 | struct hammer_cluster; |
| 215 | struct hammer_supercl; |
| 216 | struct hammer_buffer; |
| 217 | struct hammer_node; |
| 218 | RB_HEAD(hammer_vol_rb_tree, hammer_volume); |
| 219 | RB_HEAD(hammer_clu_rb_tree, hammer_cluster); |
| 220 | RB_HEAD(hammer_scl_rb_tree, hammer_supercl); |
| 221 | RB_HEAD(hammer_buf_rb_tree, hammer_buffer); |
| 222 | RB_HEAD(hammer_nod_rb_tree, hammer_node); |
| 223 | |
| 224 | RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node, |
| 225 | hammer_vol_rb_compare, int32_t); |
| 226 | RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node, |
| 227 | hammer_clu_rb_compare, int32_t); |
| 228 | RB_PROTOTYPE2(hammer_scl_rb_tree, hammer_supercl, rb_node, |
| 229 | hammer_scl_rb_compare, int32_t); |
| 230 | RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node, |
| 231 | hammer_buf_rb_compare, int32_t); |
| 232 | RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node, |
| 233 | hammer_nod_rb_compare, int32_t); |
| 234 | |
| 235 | /* |
| 236 | * IO management - embedded at the head of various in-memory structures |
| 237 | */ |
| 238 | enum hammer_io_type { HAMMER_STRUCTURE_VOLUME, |
| 239 | HAMMER_STRUCTURE_SUPERCL, |
| 240 | HAMMER_STRUCTURE_CLUSTER, |
| 241 | HAMMER_STRUCTURE_BUFFER }; |
| 242 | |
| 243 | union hammer_io_structure; |
| 244 | struct hammer_io; |
| 245 | |
| 246 | struct worklist { |
| 247 | LIST_ENTRY(worklist) node; |
| 248 | }; |
| 249 | |
| 250 | TAILQ_HEAD(hammer_io_list, hammer_io); |
| 251 | |
| 252 | struct hammer_io { |
| 253 | struct worklist worklist; |
| 254 | struct hammer_lock lock; |
| 255 | enum hammer_io_type type; |
| 256 | struct buf *bp; |
| 257 | int64_t offset; |
| 258 | TAILQ_ENTRY(hammer_io) entry; /* based on modified flag */ |
| 259 | struct hammer_io_list *entry_list; |
| 260 | struct hammer_io_list deplist; |
| 261 | u_int modified : 1; /* bp's data was modified */ |
| 262 | u_int released : 1; /* bp released (w/ B_LOCKED set) */ |
| 263 | u_int running : 1; /* bp write IO in progress */ |
| 264 | u_int waiting : 1; /* someone is waiting on us */ |
| 265 | }; |
| 266 | |
| 267 | typedef struct hammer_io *hammer_io_t; |
| 268 | |
| 269 | /* |
| 270 | * In-memory volume representing on-disk buffer |
| 271 | */ |
| 272 | struct hammer_volume { |
| 273 | struct hammer_io io; |
| 274 | RB_ENTRY(hammer_volume) rb_node; |
| 275 | struct hammer_clu_rb_tree rb_clus_root; |
| 276 | struct hammer_scl_rb_tree rb_scls_root; |
| 277 | struct hammer_volume_ondisk *ondisk; |
| 278 | struct hammer_alist_live alist; |
| 279 | int32_t vol_no; |
| 280 | int32_t vol_clsize; |
| 281 | int32_t clu_iterator; /* cluster allocation iterator */ |
| 282 | int64_t nblocks; /* note: special calculation for statfs */ |
| 283 | int64_t cluster_base; /* base offset of cluster 0 */ |
| 284 | char *vol_name; |
| 285 | struct vnode *devvp; |
| 286 | struct hammer_mount *hmp; |
| 287 | int vol_flags; |
| 288 | }; |
| 289 | |
| 290 | typedef struct hammer_volume *hammer_volume_t; |
| 291 | |
| 292 | /* |
| 293 | * In-memory super-cluster representing on-disk buffer |
| 294 | */ |
| 295 | struct hammer_supercl { |
| 296 | struct hammer_io io; |
| 297 | RB_ENTRY(hammer_supercl) rb_node; |
| 298 | struct hammer_supercl_ondisk *ondisk; |
| 299 | struct hammer_volume *volume; |
| 300 | struct hammer_alist_live alist; |
| 301 | int32_t scl_no; |
| 302 | }; |
| 303 | |
| 304 | typedef struct hammer_supercl *hammer_supercl_t; |
| 305 | |
| 306 | /* |
| 307 | * In-memory cluster representing on-disk buffer |
| 308 | * |
| 309 | * The cluster's indexing range is cached in hammer_cluster, separate |
| 310 | * from the ondisk info in order to allow cursors to point to it. |
| 311 | */ |
| 312 | struct hammer_cluster { |
| 313 | struct hammer_io io; |
| 314 | RB_ENTRY(hammer_cluster) rb_node; |
| 315 | struct hammer_buf_rb_tree rb_bufs_root; |
| 316 | struct hammer_cluster_ondisk *ondisk; |
| 317 | struct hammer_volume *volume; |
| 318 | struct hammer_alist_live alist_master; |
| 319 | struct hammer_alist_live alist_btree; |
| 320 | struct hammer_alist_live alist_record; |
| 321 | struct hammer_alist_live alist_mdata; |
| 322 | struct hammer_nod_rb_tree rb_nods_root; /* cursors in cluster */ |
| 323 | struct hammer_base_elm clu_btree_beg; /* copy of on-disk info */ |
| 324 | struct hammer_base_elm clu_btree_end; /* copy of on-disk info */ |
| 325 | int32_t clu_no; |
| 326 | }; |
| 327 | |
| 328 | typedef struct hammer_cluster *hammer_cluster_t; |
| 329 | |
| 330 | /* |
| 331 | * In-memory buffer (other then volume, super-cluster, or cluster), |
| 332 | * representing an on-disk buffer. |
| 333 | */ |
| 334 | struct hammer_buffer { |
| 335 | struct hammer_io io; |
| 336 | RB_ENTRY(hammer_buffer) rb_node; |
| 337 | hammer_fsbuf_ondisk_t ondisk; |
| 338 | struct hammer_volume *volume; |
| 339 | struct hammer_cluster *cluster; |
| 340 | int32_t buf_no; |
| 341 | u_int64_t buf_type; |
| 342 | struct hammer_alist_live alist; |
| 343 | struct hammer_node_list clist; |
| 344 | }; |
| 345 | |
| 346 | typedef struct hammer_buffer *hammer_buffer_t; |
| 347 | |
| 348 | /* |
| 349 | * In-memory B-Tree node, representing an on-disk B-Tree node. |
| 350 | * |
| 351 | * This is a hang-on structure which is backed by a hammer_buffer, |
| 352 | * indexed by a hammer_cluster, and used for fine-grained locking of |
| 353 | * B-Tree nodes in order to properly control lock ordering. A hammer_buffer |
| 354 | * can contain multiple nodes representing wildly disassociated portions |
| 355 | * of the B-Tree so locking cannot be done on a buffer-by-buffer basis. |
| 356 | * |
| 357 | * This structure uses a cluster-relative index to reduce the number |
| 358 | * of layers required to access it, and also because all on-disk B-Tree |
| 359 | * references are cluster-relative offsets. |
| 360 | */ |
| 361 | struct hammer_node { |
| 362 | struct hammer_lock lock; /* node-by-node lock */ |
| 363 | TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */ |
| 364 | RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */ |
| 365 | int32_t node_offset; /* cluster-rel offset */ |
| 366 | struct hammer_cluster *cluster; |
| 367 | struct hammer_buffer *buffer; /* backing buffer */ |
| 368 | hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */ |
| 369 | struct hammer_node **cache1; /* passive cache(s) */ |
| 370 | struct hammer_node **cache2; |
| 371 | int flags; |
| 372 | }; |
| 373 | |
| 374 | #define HAMMER_NODE_DELETED 0x0001 |
| 375 | #define HAMMER_NODE_FLUSH 0x0002 |
| 376 | |
| 377 | typedef struct hammer_node *hammer_node_t; |
| 378 | |
| 379 | /* |
| 380 | * Common I/O management structure - embedded in in-memory structures |
| 381 | * which are backed by filesystem buffers. |
| 382 | */ |
| 383 | union hammer_io_structure { |
| 384 | struct hammer_io io; |
| 385 | struct hammer_volume volume; |
| 386 | struct hammer_supercl supercl; |
| 387 | struct hammer_cluster cluster; |
| 388 | struct hammer_buffer buffer; |
| 389 | }; |
| 390 | |
| 391 | typedef union hammer_io_structure *hammer_io_structure_t; |
| 392 | |
| 393 | #define HAMFS_CLUSTER_DIRTY 0x0001 |
| 394 | |
| 395 | #include "hammer_cursor.h" |
| 396 | |
| 397 | /* |
| 398 | * Internal hammer mount data structure |
| 399 | */ |
| 400 | struct hammer_mount { |
| 401 | struct mount *mp; |
| 402 | /*struct vnode *rootvp;*/ |
| 403 | struct hammer_ino_rb_tree rb_inos_root; |
| 404 | struct hammer_vol_rb_tree rb_vols_root; |
| 405 | struct hammer_volume *rootvol; |
| 406 | struct hammer_cluster *rootcl; |
| 407 | char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */ |
| 408 | int hflags; |
| 409 | int ronly; |
| 410 | int nvolumes; |
| 411 | int volume_iterator; |
| 412 | uuid_t fsid; |
| 413 | udev_t fsid_udev; |
| 414 | hammer_tid_t asof; |
| 415 | u_int32_t namekey_iterator; |
| 416 | }; |
| 417 | |
| 418 | typedef struct hammer_mount *hammer_mount_t; |
| 419 | |
| 420 | struct hammer_sync_info { |
| 421 | int error; |
| 422 | int waitfor; |
| 423 | }; |
| 424 | |
| 425 | #endif |
| 426 | |
| 427 | #if defined(_KERNEL) |
| 428 | |
| 429 | extern struct vop_ops hammer_vnode_vops; |
| 430 | extern struct vop_ops hammer_spec_vops; |
| 431 | extern struct vop_ops hammer_fifo_vops; |
| 432 | extern struct hammer_alist_config Buf_alist_config; |
| 433 | extern struct hammer_alist_config Vol_normal_alist_config; |
| 434 | extern struct hammer_alist_config Vol_super_alist_config; |
| 435 | extern struct hammer_alist_config Supercl_alist_config; |
| 436 | extern struct hammer_alist_config Clu_master_alist_config; |
| 437 | extern struct hammer_alist_config Clu_slave_alist_config; |
| 438 | extern struct bio_ops hammer_bioops; |
| 439 | |
| 440 | extern int hammer_debug_btree; |
| 441 | extern int hammer_debug_tid; |
| 442 | extern int hammer_count_inodes; |
| 443 | extern int hammer_count_records; |
| 444 | extern int hammer_count_record_datas; |
| 445 | extern int hammer_count_volumes; |
| 446 | extern int hammer_count_supercls; |
| 447 | extern int hammer_count_clusters; |
| 448 | extern int hammer_count_buffers; |
| 449 | extern int hammer_count_nodes; |
| 450 | extern int hammer_count_spikes; |
| 451 | |
| 452 | int hammer_vop_inactive(struct vop_inactive_args *); |
| 453 | int hammer_vop_reclaim(struct vop_reclaim_args *); |
| 454 | int hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp); |
| 455 | int hammer_get_vnode(struct hammer_inode *ip, int lktype, |
| 456 | struct vnode **vpp); |
| 457 | struct hammer_inode *hammer_get_inode(hammer_mount_t hmp, |
| 458 | struct hammer_node **cache, |
| 459 | u_int64_t obj_id, hammer_tid_t asof, int flags, |
| 460 | int *errorp); |
| 461 | void hammer_put_inode(struct hammer_inode *ip); |
| 462 | void hammer_put_inode_ref(struct hammer_inode *ip); |
| 463 | |
| 464 | int hammer_unload_inode(hammer_inode_t ip, void *data); |
| 465 | int hammer_unload_volume(hammer_volume_t volume, void *data __unused); |
| 466 | int hammer_unload_supercl(hammer_supercl_t supercl, void *data __unused); |
| 467 | int hammer_unload_cluster(hammer_cluster_t cluster, void *data __unused); |
| 468 | void hammer_update_syncid(hammer_cluster_t cluster, hammer_tid_t tid); |
| 469 | int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused); |
| 470 | int hammer_install_volume(hammer_mount_t hmp, const char *volname); |
| 471 | |
| 472 | int hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip); |
| 473 | int hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip); |
| 474 | int hammer_ip_next(hammer_cursor_t cursor); |
| 475 | int hammer_ip_resolve_data(hammer_cursor_t cursor); |
| 476 | int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid); |
| 477 | int hammer_ip_check_directory_empty(hammer_transaction_t trans, |
| 478 | hammer_inode_t ip); |
| 479 | int hammer_sync_hmp(hammer_mount_t hmp, int waitfor); |
| 480 | int hammer_sync_volume(hammer_volume_t volume, void *data); |
| 481 | int hammer_sync_cluster(hammer_cluster_t cluster, void *data); |
| 482 | int hammer_sync_buffer(hammer_buffer_t buffer, void *data); |
| 483 | |
| 484 | hammer_record_t |
| 485 | hammer_alloc_mem_record(hammer_inode_t ip); |
| 486 | void hammer_rel_mem_record(hammer_record_t record); |
| 487 | |
| 488 | int hammer_cursor_up(hammer_cursor_t cursor, int nonblock); |
| 489 | int hammer_cursor_toroot(hammer_cursor_t cursor); |
| 490 | int hammer_cursor_down(hammer_cursor_t cursor); |
| 491 | |
| 492 | void hammer_lock_ex(struct hammer_lock *lock); |
| 493 | int hammer_lock_ex_try(struct hammer_lock *lock); |
| 494 | void hammer_lock_sh(struct hammer_lock *lock); |
| 495 | void hammer_unlock(struct hammer_lock *lock); |
| 496 | void hammer_ref(struct hammer_lock *lock); |
| 497 | void hammer_unref(struct hammer_lock *lock); |
| 498 | void hammer_downgrade(struct hammer_lock *lock); |
| 499 | |
| 500 | u_int32_t hammer_to_unix_xid(uuid_t *uuid); |
| 501 | void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid); |
| 502 | void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts); |
| 503 | hammer_tid_t hammer_timespec_to_transid(struct timespec *ts); |
| 504 | hammer_tid_t hammer_alloc_tid(hammer_transaction_t trans); |
| 505 | hammer_tid_t hammer_now_tid(void); |
| 506 | hammer_tid_t hammer_str_to_tid(const char *str); |
| 507 | hammer_tid_t hammer_alloc_recid(hammer_transaction_t trans); |
| 508 | |
| 509 | enum vtype hammer_get_vnode_type(u_int8_t obj_type); |
| 510 | int hammer_get_dtype(u_int8_t obj_type); |
| 511 | u_int8_t hammer_get_obj_type(enum vtype vtype); |
| 512 | int64_t hammer_directory_namekey(void *name, int len); |
| 513 | |
| 514 | int hammer_init_cursor_hmp(hammer_cursor_t cursor, struct hammer_node **cache, hammer_mount_t hmp); |
| 515 | int hammer_init_cursor_cluster(hammer_cursor_t cursor, hammer_cluster_t cluster); |
| 516 | |
| 517 | void hammer_done_cursor(hammer_cursor_t cursor); |
| 518 | void hammer_mem_done(hammer_cursor_t cursor); |
| 519 | |
| 520 | int hammer_btree_lookup(hammer_cursor_t cursor); |
| 521 | int hammer_btree_first(hammer_cursor_t cursor); |
| 522 | int hammer_btree_extract(hammer_cursor_t cursor, int flags); |
| 523 | int hammer_btree_iterate(hammer_cursor_t cursor); |
| 524 | int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm); |
| 525 | int hammer_btree_insert_cluster(hammer_cursor_t cursor, |
| 526 | hammer_cluster_t cluster, int32_t rec_offset); |
| 527 | int hammer_btree_delete(hammer_cursor_t cursor); |
| 528 | int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2); |
| 529 | int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key); |
| 530 | void hammer_make_base_inclusive(hammer_base_elm_t key); |
| 531 | |
| 532 | void hammer_print_btree_node(hammer_node_ondisk_t ondisk); |
| 533 | void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i); |
| 534 | |
| 535 | void *hammer_bread(struct hammer_cluster *cluster, int32_t cloff, |
| 536 | u_int64_t buf_type, int *errorp, |
| 537 | struct hammer_buffer **bufferp); |
| 538 | |
| 539 | hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp); |
| 540 | hammer_cluster_t hammer_get_root_cluster(hammer_mount_t hmp, int *errorp); |
| 541 | |
| 542 | hammer_volume_t hammer_get_volume(hammer_mount_t hmp, |
| 543 | int32_t vol_no, int *errorp); |
| 544 | hammer_supercl_t hammer_get_supercl(hammer_volume_t volume, int32_t scl_no, |
| 545 | int *errorp, hammer_alloc_state_t isnew); |
| 546 | hammer_cluster_t hammer_get_cluster(hammer_volume_t volume, int32_t clu_no, |
| 547 | int *errorp, hammer_alloc_state_t isnew); |
| 548 | hammer_buffer_t hammer_get_buffer(hammer_cluster_t cluster, |
| 549 | int32_t buf_no, u_int64_t buf_type, int *errorp); |
| 550 | |
| 551 | int hammer_ref_volume(hammer_volume_t volume); |
| 552 | int hammer_ref_cluster(hammer_cluster_t cluster); |
| 553 | int hammer_ref_buffer(hammer_buffer_t buffer); |
| 554 | void hammer_flush_buffer_nodes(hammer_buffer_t buffer); |
| 555 | |
| 556 | void hammer_rel_volume(hammer_volume_t volume, int flush); |
| 557 | void hammer_rel_supercl(hammer_supercl_t supercl, int flush); |
| 558 | void hammer_rel_cluster(hammer_cluster_t cluster, int flush); |
| 559 | void hammer_rel_buffer(hammer_buffer_t buffer, int flush); |
| 560 | |
| 561 | hammer_node_t hammer_get_node(hammer_cluster_t cluster, |
| 562 | int32_t node_offset, int *errorp); |
| 563 | int hammer_ref_node(hammer_node_t node); |
| 564 | hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp, |
| 565 | struct hammer_node **cache, int *errorp); |
| 566 | void hammer_rel_node(hammer_node_t node); |
| 567 | void hammer_cache_node(hammer_node_t node, |
| 568 | struct hammer_node **cache); |
| 569 | void hammer_uncache_node(struct hammer_node **cache); |
| 570 | void hammer_flush_node(hammer_node_t node); |
| 571 | |
| 572 | void hammer_dup_buffer(struct hammer_buffer **bufferp, |
| 573 | struct hammer_buffer *buffer); |
| 574 | void hammer_dup_cluster(struct hammer_cluster **clusterp, |
| 575 | struct hammer_cluster *cluster); |
| 576 | hammer_cluster_t hammer_alloc_cluster(hammer_mount_t hmp, |
| 577 | hammer_cluster_t cluster_hint, int *errorp); |
| 578 | void hammer_init_cluster(hammer_cluster_t cluster, |
| 579 | hammer_base_elm_t left_bound, |
| 580 | hammer_base_elm_t right_bound); |
| 581 | hammer_node_t hammer_alloc_btree(struct hammer_cluster *cluster, int *errorp); |
| 582 | void *hammer_alloc_data(struct hammer_cluster *cluster, int32_t bytes, |
| 583 | int *errorp, struct hammer_buffer **bufferp); |
| 584 | void *hammer_alloc_record(struct hammer_cluster *cluster, |
| 585 | int *errorp, struct hammer_buffer **bufferp); |
| 586 | void hammer_initbuffer(hammer_alist_t live, hammer_fsbuf_head_t head, |
| 587 | u_int64_t type); |
| 588 | void hammer_free_data_ptr(struct hammer_buffer *buffer, |
| 589 | void *data, int bytes); |
| 590 | void hammer_free_record_ptr(struct hammer_buffer *buffer, |
| 591 | union hammer_record_ondisk *rec); |
| 592 | void hammer_free_cluster(hammer_cluster_t cluster); |
| 593 | void hammer_free_btree(struct hammer_cluster *cluster, int32_t bclu_offset); |
| 594 | void hammer_free_data(struct hammer_cluster *cluster, int32_t bclu_offset, |
| 595 | int32_t bytes); |
| 596 | void hammer_free_record(struct hammer_cluster *cluster, int32_t bclu_offset); |
| 597 | |
| 598 | void hammer_put_volume(struct hammer_volume *volume, int flush); |
| 599 | void hammer_put_supercl(struct hammer_supercl *supercl, int flush); |
| 600 | void hammer_put_cluster(struct hammer_cluster *cluster, int flush); |
| 601 | void hammer_put_buffer(struct hammer_buffer *buffer, int flush); |
| 602 | |
| 603 | void hammer_init_alist_config(void); |
| 604 | |
| 605 | void hammer_start_transaction(struct hammer_transaction *trans, |
| 606 | struct hammer_mount *hmp); |
| 607 | void hammer_start_transaction_tid(struct hammer_transaction *trans, |
| 608 | struct hammer_mount *hmp, hammer_tid_t tid); |
| 609 | void hammer_commit_transaction(struct hammer_transaction *trans); |
| 610 | void hammer_abort_transaction(struct hammer_transaction *trans); |
| 611 | |
| 612 | void hammer_modify_inode(struct hammer_transaction *trans, |
| 613 | hammer_inode_t ip, int flags); |
| 614 | int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap, |
| 615 | struct ucred *cred, struct hammer_inode *dip, |
| 616 | struct hammer_inode **ipp); |
| 617 | void hammer_rel_inode(hammer_inode_t ip, int flush); |
| 618 | int hammer_sync_inode(hammer_inode_t ip, int waitfor, int handle_delete); |
| 619 | |
| 620 | int hammer_ip_add_directory(struct hammer_transaction *trans, |
| 621 | hammer_inode_t dip, struct namecache *ncp, |
| 622 | hammer_inode_t nip); |
| 623 | int hammer_ip_del_directory(struct hammer_transaction *trans, |
| 624 | hammer_cursor_t cursor, hammer_inode_t dip, |
| 625 | hammer_inode_t ip); |
| 626 | int hammer_ip_add_record(struct hammer_transaction *trans, |
| 627 | hammer_record_t record); |
| 628 | int hammer_ip_delete_range(struct hammer_transaction *trans, |
| 629 | hammer_inode_t ip, int64_t ran_beg, int64_t ran_end, |
| 630 | struct hammer_cursor **spikep); |
| 631 | int hammer_ip_delete_range_all(struct hammer_transaction *trans, |
| 632 | hammer_inode_t ip); |
| 633 | int hammer_ip_sync_data(struct hammer_transaction *trans, |
| 634 | hammer_inode_t ip, int64_t offset, |
| 635 | void *data, int bytes, struct hammer_cursor **spikep); |
| 636 | int hammer_ip_sync_record(hammer_record_t rec, struct hammer_cursor **spikep); |
| 637 | int hammer_write_record(hammer_cursor_t cursor, hammer_record_ondisk_t rec, |
| 638 | void *data, int cursor_flags); |
| 639 | |
| 640 | void hammer_load_spike(hammer_cursor_t cursor, struct hammer_cursor **spikep); |
| 641 | int hammer_spike(struct hammer_cursor **spikep); |
| 642 | int hammer_recover(struct hammer_cluster *cluster); |
| 643 | |
| 644 | void hammer_io_init(hammer_io_t io, enum hammer_io_type type); |
| 645 | int hammer_io_read(struct vnode *devvp, struct hammer_io *io); |
| 646 | int hammer_io_new(struct vnode *devvp, struct hammer_io *io); |
| 647 | void hammer_io_release(struct hammer_io *io, int flush); |
| 648 | void hammer_io_flush(struct hammer_io *io); |
| 649 | int hammer_io_checkflush(hammer_io_t io); |
| 650 | void hammer_io_notify_cluster(hammer_cluster_t cluster); |
| 651 | void hammer_io_clear_modify(struct hammer_io *io); |
| 652 | void hammer_io_waitdep(struct hammer_io *io); |
| 653 | |
| 654 | void hammer_modify_volume(hammer_volume_t volume); |
| 655 | void hammer_modify_supercl(hammer_supercl_t supercl); |
| 656 | void hammer_modify_cluster(hammer_cluster_t cluster); |
| 657 | void hammer_modify_buffer(hammer_buffer_t buffer); |
| 658 | |
| 659 | #endif |
| 660 | |
| 661 | static __inline void |
| 662 | hammer_modify_node(struct hammer_node *node) |
| 663 | { |
| 664 | hammer_modify_buffer(node->buffer); |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | * Return the cluster-relative byte offset of an element within a buffer |
| 669 | */ |
| 670 | static __inline int |
| 671 | hammer_bclu_offset(struct hammer_buffer *buffer, void *ptr) |
| 672 | { |
| 673 | int bclu_offset; |
| 674 | |
| 675 | bclu_offset = buffer->buf_no * HAMMER_BUFSIZE + |
| 676 | ((char *)ptr - (char *)buffer->ondisk); |
| 677 | return(bclu_offset); |
| 678 | } |
| 679 | |