1 /* 2 * Copyright (c) 2011-2015 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthew Dillon <dillon@dragonflybsd.org> 6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 3. Neither the name of The DragonFly Project nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific, prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 /* 37 * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES 38 * 39 * This header file contains structures used internally by the HAMMER2 40 * implementation. See hammer2_disk.h for on-disk structures. 41 * 42 * There is an in-memory representation of all on-media data structure. 43 * Almost everything is represented by a hammer2_chain structure in-memory. 44 * Other higher-level structures typically map to chains. 45 * 46 * A great deal of data is accessed simply via its buffer cache buffer, 47 * which is mapped for the duration of the chain's lock. Hammer2 must 48 * implement its own buffer cache layer on top of the system layer to 49 * allow for different threads to lock different sub-block-sized buffers. 50 * 51 * When modifications are made to a chain a new filesystem block must be 52 * allocated. Multiple modifications do not typically allocate new blocks 53 * until the current block has been flushed. Flushes do not block the 54 * front-end unless the front-end operation crosses the current inode being 55 * flushed. 56 * 57 * The in-memory representation may remain cached (for example in order to 58 * placemark clustering locks) even after the related data has been 59 * detached. 60 */ 61 62 #ifndef _VFS_HAMMER2_HAMMER2_H_ 63 #define _VFS_HAMMER2_HAMMER2_H_ 64 65 #include <sys/param.h> 66 #include <sys/types.h> 67 #include <sys/kernel.h> 68 #include <sys/conf.h> 69 #include <sys/systm.h> 70 #include <sys/tree.h> 71 #include <sys/malloc.h> 72 #include <sys/mount.h> 73 #include <sys/vnode.h> 74 #include <sys/proc.h> 75 #include <sys/mountctl.h> 76 #include <sys/priv.h> 77 #include <sys/stat.h> 78 #include <sys/thread.h> 79 #include <sys/globaldata.h> 80 #include <sys/lockf.h> 81 #include <sys/buf.h> 82 #include <sys/queue.h> 83 #include <sys/limits.h> 84 #include <sys/dmsg.h> 85 #include <sys/mutex.h> 86 #include <sys/kern_syscall.h> 87 88 #include <sys/signal2.h> 89 #include <sys/buf2.h> 90 #include <sys/mutex2.h> 91 #include <sys/thread2.h> 92 93 #include "hammer2_disk.h" 94 #include "hammer2_mount.h" 95 #include "hammer2_ioctl.h" 96 97 struct hammer2_io; 98 struct hammer2_iocb; 99 struct hammer2_chain; 100 struct hammer2_cluster; 101 struct hammer2_inode; 102 struct hammer2_dev; 103 struct hammer2_pfs; 104 struct hammer2_span; 105 struct hammer2_state; 106 struct hammer2_msg; 107 struct hammer2_thread; 108 union hammer2_xop; 109 110 /* 111 * Mutex and lock shims. Hammer2 requires support for asynchronous and 112 * abortable locks, and both exclusive and shared spinlocks. Normal 113 * synchronous non-abortable locks can be substituted for spinlocks. 114 */ 115 typedef mtx_t hammer2_mtx_t; 116 typedef mtx_link_t hammer2_mtx_link_t; 117 typedef mtx_state_t hammer2_mtx_state_t; 118 119 typedef struct spinlock hammer2_spin_t; 120 121 #define hammer2_mtx_ex mtx_lock_ex_quick 122 #define hammer2_mtx_sh mtx_lock_sh_quick 123 #define hammer2_mtx_unlock mtx_unlock 124 #define hammer2_mtx_owned mtx_owned 125 #define hammer2_mtx_init mtx_init 126 #define hammer2_mtx_temp_release mtx_lock_temp_release 127 #define hammer2_mtx_temp_restore mtx_lock_temp_restore 128 #define hammer2_mtx_refs mtx_lockrefs 129 130 #define hammer2_spin_init spin_init 131 #define hammer2_spin_sh spin_lock_shared 132 #define hammer2_spin_ex spin_lock 133 #define hammer2_spin_unsh spin_unlock_shared 134 #define hammer2_spin_unex spin_unlock 135 136 TAILQ_HEAD(hammer2_xop_list, hammer2_xop_head); 137 138 typedef struct hammer2_xop_list hammer2_xop_list_t; 139 140 141 /* 142 * General lock support 143 */ 144 static __inline 145 int 146 hammer2_mtx_upgrade(hammer2_mtx_t *mtx) 147 { 148 int wasexclusive; 149 150 if (mtx_islocked_ex(mtx)) { 151 wasexclusive = 1; 152 } else { 153 mtx_unlock(mtx); 154 mtx_lock_ex_quick(mtx); 155 wasexclusive = 0; 156 } 157 return wasexclusive; 158 } 159 160 /* 161 * Downgrade an inode lock from exclusive to shared only if the inode 162 * lock was previously shared. If the inode lock was previously exclusive, 163 * this is a NOP. 164 */ 165 static __inline 166 void 167 hammer2_mtx_downgrade(hammer2_mtx_t *mtx, int wasexclusive) 168 { 169 if (wasexclusive == 0) 170 mtx_downgrade(mtx); 171 } 172 173 /* 174 * The xid tracks internal transactional updates. 175 * 176 * XXX fix-me, really needs to be 64-bits 177 */ 178 typedef uint32_t hammer2_xid_t; 179 180 #define HAMMER2_XID_MIN 0x00000000U 181 #define HAMMER2_XID_MAX 0x7FFFFFFFU 182 183 /* 184 * The chain structure tracks a portion of the media topology from the 185 * root (volume) down. Chains represent volumes, inodes, indirect blocks, 186 * data blocks, and freemap nodes and leafs. 187 * 188 * The chain structure utilizes a simple singly-homed topology and the 189 * chain's in-memory topology will move around as the chains do, due mainly 190 * to renames and indirect block creation. 191 * 192 * Block Table Updates 193 * 194 * Block table updates for insertions and updates are delayed until the 195 * flush. This allows us to avoid having to modify the parent chain 196 * all the way to the root. 197 * 198 * Block table deletions are performed immediately (modifying the parent 199 * in the process) because the flush code uses the chain structure to 200 * track delayed updates and the chain will be (likely) gone or moved to 201 * another location in the topology after a deletion. 202 * 203 * A prior iteration of the code tried to keep the relationship intact 204 * on deletes by doing a delete-duplicate operation on the chain, but 205 * it added way too much complexity to the codebase. 206 * 207 * Flush Synchronization 208 * 209 * The flush code must flush modified chains bottom-up. Because chain 210 * structures can shift around and are NOT topologically stable, 211 * modified chains are independently indexed for the flush. As the flush 212 * runs it modifies (or further modifies) and updates the parents, 213 * propagating the flush all the way to the volume root. 214 * 215 * Modifying front-end operations can occur during a flush but will block 216 * in two cases: (1) when the front-end tries to operate on the inode 217 * currently in the midst of being flushed and (2) if the front-end 218 * crosses an inode currently being flushed (such as during a rename). 219 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and 220 * the flusher is currently working on "a/b/c", the rename will block 221 * temporarily in order to ensure that "x" exists in one place or the 222 * other. 223 * 224 * Meta-data statistics are updated by the flusher. The front-end will 225 * make estimates but meta-data must be fully synchronized only during a 226 * flush in order to ensure that it remains correct across a crash. 227 * 228 * Multiple flush synchronizations can theoretically be in-flight at the 229 * same time but the implementation is not coded to handle the case and 230 * currently serializes them. 231 * 232 * Snapshots: 233 * 234 * Snapshots currently require the subdirectory tree being snapshotted 235 * to be flushed. The snapshot then creates a new super-root inode which 236 * copies the flushed blockdata of the directory or file that was 237 * snapshotted. 238 * 239 * RBTREE NOTES: 240 * 241 * - Note that the radix tree runs in powers of 2 only so sub-trees 242 * cannot straddle edges. 243 */ 244 RB_HEAD(hammer2_chain_tree, hammer2_chain); 245 TAILQ_HEAD(h2_flush_list, hammer2_chain); 246 TAILQ_HEAD(h2_core_list, hammer2_chain); 247 TAILQ_HEAD(h2_iocb_list, hammer2_iocb); 248 249 #define CHAIN_CORE_DELETE_BMAP_ENTRIES \ 250 (HAMMER2_PBUFSIZE / sizeof(hammer2_blockref_t) / sizeof(uint32_t)) 251 252 /* 253 * Core topology for chain (embedded in chain). Protected by a spinlock. 254 */ 255 struct hammer2_chain_core { 256 hammer2_spin_t spin; 257 struct hammer2_chain_tree rbtree; /* sub-chains */ 258 int live_zero; /* blockref array opt */ 259 u_int live_count; /* live (not deleted) chains in tree */ 260 u_int chain_count; /* live + deleted chains under core */ 261 int generation; /* generation number (inserts only) */ 262 }; 263 264 typedef struct hammer2_chain_core hammer2_chain_core_t; 265 266 RB_HEAD(hammer2_io_tree, hammer2_io); 267 268 /* 269 * IOCB - IO callback (into chain, cluster, or manual request) 270 */ 271 struct hammer2_iocb { 272 TAILQ_ENTRY(hammer2_iocb) entry; 273 void (*callback)(struct hammer2_iocb *iocb); 274 struct hammer2_io *dio; 275 struct hammer2_cluster *cluster; 276 struct hammer2_chain *chain; 277 void *ptr; 278 off_t lbase; 279 int lsize; 280 uint32_t flags; 281 int error; 282 }; 283 284 typedef struct hammer2_iocb hammer2_iocb_t; 285 286 #define HAMMER2_IOCB_INTERLOCK 0x00000001 287 #define HAMMER2_IOCB_ONQ 0x00000002 288 #define HAMMER2_IOCB_DONE 0x00000004 289 #define HAMMER2_IOCB_INPROG 0x00000008 290 #define HAMMER2_IOCB_UNUSED10 0x00000010 291 #define HAMMER2_IOCB_QUICK 0x00010000 292 #define HAMMER2_IOCB_ZERO 0x00020000 293 #define HAMMER2_IOCB_READ 0x00040000 294 #define HAMMER2_IOCB_WAKEUP 0x00080000 295 296 /* 297 * DIO - Management structure wrapping system buffer cache. 298 * 299 * Used for multiple purposes including concurrent management 300 * if small requests by chains into larger DIOs. 301 */ 302 struct hammer2_io { 303 RB_ENTRY(hammer2_io) rbnode; /* indexed by device offset */ 304 struct h2_iocb_list iocbq; 305 struct spinlock spin; 306 struct hammer2_dev *hmp; 307 struct buf *bp; 308 off_t pbase; 309 int psize; 310 int refs; 311 int act; /* activity */ 312 }; 313 314 typedef struct hammer2_io hammer2_io_t; 315 316 #define HAMMER2_DIO_INPROG 0x80000000 /* bio in progress */ 317 #define HAMMER2_DIO_GOOD 0x40000000 /* dio->bp is stable */ 318 #define HAMMER2_DIO_WAITING 0x20000000 /* (old) */ 319 #define HAMMER2_DIO_DIRTY 0x10000000 /* flush on last drop */ 320 321 #define HAMMER2_DIO_MASK 0x0FFFFFFF 322 323 /* 324 * Primary chain structure keeps track of the topology in-memory. 325 */ 326 struct hammer2_chain { 327 hammer2_mtx_t lock; 328 hammer2_chain_core_t core; 329 RB_ENTRY(hammer2_chain) rbnode; /* live chain(s) */ 330 hammer2_blockref_t bref; 331 struct hammer2_chain *parent; 332 struct hammer2_state *state; /* if active cache msg */ 333 struct hammer2_dev *hmp; 334 struct hammer2_pfs *pmp; /* A PFS or super-root (spmp) */ 335 336 hammer2_io_t *dio; /* physical data buffer */ 337 u_int bytes; /* physical data size */ 338 u_int flags; 339 u_int refs; 340 u_int lockcnt; 341 int error; /* on-lock data error state */ 342 343 hammer2_media_data_t *data; /* data pointer shortcut */ 344 TAILQ_ENTRY(hammer2_chain) flush_node; /* flush list */ 345 }; 346 347 typedef struct hammer2_chain hammer2_chain_t; 348 349 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2); 350 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp); 351 352 /* 353 * Special notes on flags: 354 * 355 * INITIAL - This flag allows a chain to be created and for storage to 356 * be allocated without having to immediately instantiate the 357 * related buffer. The data is assumed to be all-zeros. It 358 * is primarily used for indirect blocks. 359 * 360 * MODIFIED - The chain's media data has been modified. Prevents chain 361 * free on lastdrop if still in the topology. 362 * 363 * UPDATE - Chain might not be modified but parent blocktable needs 364 * an update. Prevents chain free on lastdrop if still in 365 * the topology. 366 * 367 * FICTITIOUS - Faked chain as a placeholder for an error condition. This 368 * chain is unsuitable for I/O. 369 * 370 * BMAPPED - Indicates that the chain is present in the parent blockmap. 371 * 372 * BMAPUPD - Indicates that the chain is present but needs to be updated 373 * in the parent blockmap. 374 */ 375 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */ 376 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */ 377 #define HAMMER2_CHAIN_DESTROY 0x00000004 378 #define HAMMER2_CHAIN_DEDUP 0x00000008 /* used as dedup src */ 379 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */ 380 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */ 381 #define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */ 382 #define HAMMER2_CHAIN_DEFERRED 0x00000080 /* flush depth defer */ 383 #define HAMMER2_CHAIN_UNUSED000001000 0x00000100 384 #define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */ 385 #define HAMMER2_CHAIN_FICTITIOUS 0x00000400 /* unsuitable for I/O */ 386 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */ 387 #define HAMMER2_CHAIN_DELAYED 0x00001000 /* delayed flush */ 388 #define HAMMER2_CHAIN_COUNTEDBREFS 0x00002000 /* block table stats */ 389 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */ 390 #define HAMMER2_CHAIN_UNUSED00008000 0x00008000 391 #define HAMMER2_CHAIN_EMBEDDED 0x00010000 /* embedded data */ 392 #define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */ 393 #define HAMMER2_CHAIN_BMAPPED 0x00040000 /* present in blkmap */ 394 #define HAMMER2_CHAIN_BMAPUPD 0x00080000 /* +needs updating */ 395 #define HAMMER2_CHAIN_IOINPROG 0x00100000 /* I/O interlock */ 396 #define HAMMER2_CHAIN_IOSIGNAL 0x00200000 /* I/O interlock */ 397 #define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */ 398 399 #define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \ 400 HAMMER2_CHAIN_UPDATE | \ 401 HAMMER2_CHAIN_ONFLUSH) 402 403 /* 404 * Hammer2 error codes, used by chain->error and cluster->error. The error 405 * code is typically set on-lock unless no I/O was requested, and set on 406 * I/O otherwise. If set for a cluster it generally means that the cluster 407 * code could not find a valid copy to present. 408 * 409 * IO - An I/O error occurred 410 * CHECK - I/O succeeded but did not match the check code 411 * INCOMPLETE - A cluster is not complete enough to use, or 412 * a chain cannot be loaded because its parent has an error. 413 * 414 * NOTE: API allows callers to check zero/non-zero to determine if an error 415 * condition exists. 416 * 417 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily 418 * NULL on other errors. Check chain->error, not chain->data. 419 */ 420 #define HAMMER2_ERROR_NONE 0 421 #define HAMMER2_ERROR_IO 1 /* device I/O error */ 422 #define HAMMER2_ERROR_CHECK 2 /* check code mismatch */ 423 #define HAMMER2_ERROR_INCOMPLETE 3 /* incomplete cluster */ 424 #define HAMMER2_ERROR_DEPTH 4 /* temporary depth limit */ 425 426 /* 427 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next() 428 * 429 * NOTES: 430 * NOLOCK - Input and output chains are referenced only and not 431 * locked. Output chain might be temporarily locked 432 * internally. 433 * 434 * NODATA - Asks that the chain->data not be resolved in order 435 * to avoid I/O. 436 * 437 * NODIRECT - Prevents a lookup of offset 0 in an inode from returning 438 * the inode itself if the inode is in DIRECTDATA mode 439 * (i.e. file is <= 512 bytes). Used by the synchronization 440 * code to prevent confusion. 441 * 442 * SHARED - The input chain is expected to be locked shared, 443 * and the output chain is locked shared. 444 * 445 * MATCHIND - Allows an indirect block / freemap node to be returned 446 * when the passed key range matches the radix. Remember 447 * that key_end is inclusive (e.g. {0x000,0xFFF}, 448 * not {0x000,0x1000}). 449 * 450 * (Cannot be used for remote or cluster ops). 451 * 452 * ALLNODES - Allows NULL focus. 453 * 454 * ALWAYS - Always resolve the data. If ALWAYS and NODATA are both 455 * missing, bulk file data is not resolved but inodes and 456 * other meta-data will. 457 * 458 * NOUNLOCK - Used by hammer2_chain_next() to leave the lock on 459 * the input chain intact. The chain is still dropped. 460 * This allows the caller to add a reference to the chain 461 * and retain it in a locked state (used by the 462 * XOP/feed/collect code). 463 */ 464 #define HAMMER2_LOOKUP_NOLOCK 0x00000001 /* ref only */ 465 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */ 466 #define HAMMER2_LOOKUP_NODIRECT 0x00000004 /* no offset=0 DD */ 467 #define HAMMER2_LOOKUP_SHARED 0x00000100 468 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */ 469 #define HAMMER2_LOOKUP_ALLNODES 0x00000400 /* allow NULL focus */ 470 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */ 471 #define HAMMER2_LOOKUP_NOUNLOCK 0x00001000 /* leave lock intact */ 472 473 /* 474 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize() 475 * 476 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT 477 * blocks in the INITIAL-create state. 478 */ 479 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */ 480 #define HAMMER2_MODIFY_NO_MODIFY_TID 0x00000004 481 #define HAMMER2_MODIFY_UNUSED0008 0x00000008 482 483 /* 484 * Flags passed to hammer2_chain_lock() 485 * 486 * NOTE: RDONLY is set to optimize cluster operations when *no* modifications 487 * will be made to either the cluster being locked or any underlying 488 * cluster. It allows the cluster to lock and access data for a subset 489 * of available nodes instead of all available nodes. 490 */ 491 #define HAMMER2_RESOLVE_NEVER 1 492 #define HAMMER2_RESOLVE_MAYBE 2 493 #define HAMMER2_RESOLVE_ALWAYS 3 494 #define HAMMER2_RESOLVE_MASK 0x0F 495 496 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */ 497 #define HAMMER2_RESOLVE_UNUSED20 0x20 498 #define HAMMER2_RESOLVE_RDONLY 0x40 /* higher level op flag */ 499 500 /* 501 * Flags passed to hammer2_chain_delete() 502 */ 503 #define HAMMER2_DELETE_PERMANENT 0x0001 504 505 /* 506 * Flags passed to hammer2_chain_insert() or hammer2_chain_rename() 507 */ 508 #define HAMMER2_INSERT_PFSROOT 0x0004 509 510 /* 511 * Flags passed to hammer2_chain_delete_duplicate() 512 */ 513 #define HAMMER2_DELDUP_RECORE 0x0001 514 515 /* 516 * Cluster different types of storage together for allocations 517 */ 518 #define HAMMER2_FREECACHE_INODE 0 519 #define HAMMER2_FREECACHE_INDIR 1 520 #define HAMMER2_FREECACHE_DATA 2 521 #define HAMMER2_FREECACHE_UNUSED3 3 522 #define HAMMER2_FREECACHE_TYPES 4 523 524 /* 525 * hammer2_freemap_alloc() block preference 526 */ 527 #define HAMMER2_OFF_NOPREF ((hammer2_off_t)-1) 528 529 /* 530 * BMAP read-ahead maximum parameters 531 */ 532 #define HAMMER2_BMAP_COUNT 16 /* max bmap read-ahead */ 533 #define HAMMER2_BMAP_BYTES (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT) 534 535 /* 536 * hammer2_freemap_adjust() 537 */ 538 #define HAMMER2_FREEMAP_DORECOVER 1 539 #define HAMMER2_FREEMAP_DOMAYFREE 2 540 #define HAMMER2_FREEMAP_DOREALFREE 3 541 542 /* 543 * HAMMER2 cluster - A set of chains representing the same entity. 544 * 545 * hammer2_cluster typically represents a temporary set of representitive 546 * chains. The one exception is that a hammer2_cluster is embedded in 547 * hammer2_inode. This embedded cluster is ONLY used to track the 548 * representitive chains and cannot be directly locked. 549 * 550 * A cluster is usually temporary (and thus per-thread) for locking purposes, 551 * allowing us to embed the asynchronous storage required for cluster 552 * operations in the cluster itself and adjust the state and status without 553 * having to worry too much about SMP issues. 554 * 555 * The exception is the cluster embedded in the hammer2_inode structure. 556 * This is used to cache the cluster state on an inode-by-inode basis. 557 * Individual hammer2_chain structures not incorporated into clusters might 558 * also stick around to cache miscellanious elements. 559 * 560 * Because the cluster is a 'working copy' and is usually subject to cluster 561 * quorum rules, it is quite possible for us to end up with an insufficient 562 * number of live chains to execute an operation. If an insufficient number 563 * of chains remain in a working copy, the operation may have to be 564 * downgraded, retried, stall until the requisit number of chains are 565 * available, or possibly even error out depending on the mount type. 566 * 567 * A cluster's focus is set when it is locked. The focus can only be set 568 * to a chain still part of the synchronized set. 569 */ 570 #define HAMMER2_MAXCLUSTER 8 571 #define HAMMER2_XOPFIFO 16 572 #define HAMMER2_XOPFIFO_MASK (HAMMER2_XOPFIFO - 1) 573 #define HAMMER2_XOPGROUPS 16 574 #define HAMMER2_XOPGROUPS_MASK (HAMMER2_XOPGROUPS - 1) 575 #define HAMMER2_XOPMASK_VOP 0x80000000U 576 577 struct hammer2_cluster_item { 578 hammer2_chain_t *chain; 579 int cache_index; 580 int error; 581 uint32_t flags; 582 }; 583 584 typedef struct hammer2_cluster_item hammer2_cluster_item_t; 585 586 /* 587 * INVALID - Invalid for focus, i.e. not part of synchronized set. 588 * Once set, this bit is sticky across operations. 589 * 590 * FEMOD - Indicates that front-end modifying operations can 591 * mess with this entry and MODSYNC will copy also 592 * effect it. 593 */ 594 #define HAMMER2_CITEM_INVALID 0x00000001 595 #define HAMMER2_CITEM_FEMOD 0x00000002 596 #define HAMMER2_CITEM_NULL 0x00000004 597 598 struct hammer2_cluster { 599 int refs; /* track for deallocation */ 600 int ddflag; 601 struct hammer2_pfs *pmp; 602 uint32_t flags; 603 int nchains; 604 int error; /* error code valid on lock */ 605 int focus_index; 606 hammer2_iocb_t iocb; 607 hammer2_chain_t *focus; /* current focus (or mod) */ 608 hammer2_cluster_item_t array[HAMMER2_MAXCLUSTER]; 609 }; 610 611 typedef struct hammer2_cluster hammer2_cluster_t; 612 613 /* 614 * WRHARD - Hard mounts can write fully synchronized 615 * RDHARD - Hard mounts can read fully synchronized 616 * UNHARD - Unsynchronized masters present 617 * NOHARD - No masters visible 618 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER 619 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE 620 * UNSOFT - Unsynchronized slaves present 621 * NOSOFT - No slaves visible 622 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote). 623 * MSYNCED - All masters are fully synchronized 624 * SSYNCED - All known local slaves are fully synchronized to masters 625 * 626 * All available masters are always incorporated. All PFSs belonging to a 627 * cluster (master, slave, copy, whatever) always try to synchronize the 628 * total number of known masters in the PFSs root inode. 629 * 630 * A cluster might have access to many slaves, copies, or caches, but we 631 * have a limited number of cluster slots. Any such elements which are 632 * directly mounted from block device(s) will always be incorporated. Note 633 * that SSYNCED only applies to such elements which are directly mounted, 634 * not to any remote slaves, copies, or caches that could be available. These 635 * bits are used to monitor and drive our synchronization threads. 636 * 637 * When asking the question 'is any data accessible at all', then a simple 638 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of 639 * these bits are set the object can be read with certain caveats: 640 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized. 641 * and RDSLAVE - not authoritative, has some data but it could be old or 642 * incomplete. 643 * 644 * When both soft and hard mounts are available, data will be read and written 645 * via the soft mount only. But all might be in the cluster because 646 * background synchronization threads still need to do their work. 647 */ 648 #define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode struct */ 649 #define HAMMER2_CLUSTER_UNUSED2 0x00000002 650 #define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */ 651 #define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */ 652 #define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */ 653 #define HAMMER2_CLUSTER_UNHARD 0x00000400 /* unsynchronized masters */ 654 #define HAMMER2_CLUSTER_NOHARD 0x00000800 /* no masters visible */ 655 #define HAMMER2_CLUSTER_WRSOFT 0x00001000 /* soft-mount can write */ 656 #define HAMMER2_CLUSTER_RDSOFT 0x00002000 /* soft-mount can read */ 657 #define HAMMER2_CLUSTER_UNSOFT 0x00004000 /* unsynchronized slaves */ 658 #define HAMMER2_CLUSTER_NOSOFT 0x00008000 /* no slaves visible */ 659 #define HAMMER2_CLUSTER_MSYNCED 0x00010000 /* all masters synchronized */ 660 #define HAMMER2_CLUSTER_SSYNCED 0x00020000 /* known slaves synchronized */ 661 662 #define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \ 663 HAMMER2_CLUSTER_RDSOFT | \ 664 HAMMER2_CLUSTER_RDSLAVE) 665 666 #define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \ 667 HAMMER2_CLUSTER_RDSOFT) 668 669 #define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \ 670 HAMMER2_CLUSTER_WRSOFT) 671 672 #define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \ 673 HAMMER2_CLUSTER_RDHARD | \ 674 HAMMER2_CLUSTER_WRSOFT | \ 675 HAMMER2_CLUSTER_RDSOFT | \ 676 HAMMER2_CLUSTER_MSYNCED | \ 677 HAMMER2_CLUSTER_SSYNCED) 678 679 /* 680 * Helper functions (cluster must be locked for flags to be valid). 681 */ 682 static __inline 683 int 684 hammer2_cluster_rdok(hammer2_cluster_t *cluster) 685 { 686 return (cluster->flags & HAMMER2_CLUSTER_RDOK); 687 } 688 689 static __inline 690 int 691 hammer2_cluster_wrok(hammer2_cluster_t *cluster) 692 { 693 return (cluster->flags & HAMMER2_CLUSTER_WROK); 694 } 695 696 RB_HEAD(hammer2_inode_tree, hammer2_inode); 697 698 /* 699 * A hammer2 inode. 700 * 701 * NOTE: The inode-embedded cluster is never used directly for I/O (since 702 * it may be shared). Instead it will be replicated-in and synchronized 703 * back out if changed. 704 */ 705 struct hammer2_inode { 706 RB_ENTRY(hammer2_inode) rbnode; /* inumber lookup (HL) */ 707 hammer2_mtx_t lock; /* inode lock */ 708 struct hammer2_pfs *pmp; /* PFS mount */ 709 struct hammer2_inode *pip; /* parent inode */ 710 struct vnode *vp; 711 struct spinlock cluster_spin; /* update cluster */ 712 hammer2_cluster_t cluster; 713 struct lockf advlock; 714 u_int flags; 715 u_int refs; /* +vpref, +flushref */ 716 uint8_t comp_heuristic; 717 hammer2_inode_meta_t meta; /* copy of meta-data */ 718 hammer2_off_t osize; 719 }; 720 721 typedef struct hammer2_inode hammer2_inode_t; 722 723 /* 724 * MODIFIED - Inode is in a modified state, ip->meta may have changes. 725 * RESIZED - Inode truncated (any) or inode extended beyond 726 * EMBEDDED_BYTES. 727 */ 728 #define HAMMER2_INODE_MODIFIED 0x0001 729 #define HAMMER2_INODE_SROOT 0x0002 /* kmalloc special case */ 730 #define HAMMER2_INODE_RENAME_INPROG 0x0004 731 #define HAMMER2_INODE_ONRBTREE 0x0008 732 #define HAMMER2_INODE_RESIZED 0x0010 /* requires inode_fsync */ 733 #define HAMMER2_INODE_ISDELETED 0x0020 /* deleted, not in ihidden */ 734 #define HAMMER2_INODE_ISUNLINKED 0x0040 735 #define HAMMER2_INODE_METAGOOD 0x0080 /* inode meta-data good */ 736 #define HAMMER2_INODE_ONSIDEQ 0x0100 /* on side processing queue */ 737 738 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2); 739 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp, 740 hammer2_tid_t); 741 742 /* 743 * inode-unlink side-structure 744 */ 745 struct hammer2_inode_sideq { 746 TAILQ_ENTRY(hammer2_inode_sideq) entry; 747 hammer2_inode_t *ip; 748 }; 749 TAILQ_HEAD(h2_sideq_list, hammer2_inode_sideq); 750 751 typedef struct hammer2_inode_sideq hammer2_inode_sideq_t; 752 753 /* 754 * Transaction management sub-structure under hammer2_pfs 755 */ 756 struct hammer2_trans { 757 uint32_t flags; 758 uint32_t sync_wait; 759 }; 760 761 typedef struct hammer2_trans hammer2_trans_t; 762 763 #define HAMMER2_TRANS_ISFLUSH 0x80000000 /* flush code */ 764 #define HAMMER2_TRANS_BUFCACHE 0x40000000 /* bio strategy */ 765 #define HAMMER2_TRANS_PREFLUSH 0x20000000 /* preflush state */ 766 #define HAMMER2_TRANS_FPENDING 0x10000000 /* flush pending */ 767 #define HAMMER2_TRANS_WAITING 0x08000000 /* someone waiting */ 768 #define HAMMER2_TRANS_MASK 0x00FFFFFF /* count mask */ 769 770 #define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-MINIORADIX */ 771 #define HAMMER2_FREEMAP_HEUR_TYPES 8 772 #define HAMMER2_FREEMAP_HEUR_SIZE (HAMMER2_FREEMAP_HEUR_NRADIX * \ 773 HAMMER2_FREEMAP_HEUR_TYPES) 774 775 #define HAMMER2_DEDUP_HEUR_SIZE 65536 776 #define HAMMER2_DEDUP_HEUR_MASK (HAMMER2_DEDUP_HEUR_SIZE - 1) 777 778 #define HAMMER2_FLUSH_TOP 0x0001 779 #define HAMMER2_FLUSH_ALL 0x0002 780 781 782 /* 783 * Hammer2 support thread element. 784 * 785 * Potentially many support threads can hang off of hammer2, primarily 786 * off the hammer2_pfs structure. Typically: 787 * 788 * td x Nodes A synchronization thread for each node. 789 * td x Nodes x workers Worker threads for frontend operations. 790 * td x 1 Bioq thread for logical buffer writes. 791 * 792 * In addition, the synchronization thread(s) associated with the 793 * super-root PFS (spmp) for a node is responsible for automatic bulkfree 794 * and dedup scans. 795 */ 796 struct hammer2_thread { 797 struct hammer2_pfs *pmp; 798 hammer2_xop_list_t *xopq; /* points into pmp->xopq[] */ 799 thread_t td; 800 uint32_t flags; 801 int depth; 802 int clindex; /* cluster element index */ 803 int repidx; 804 struct lock lk; /* thread control lock */ 805 }; 806 807 typedef struct hammer2_thread hammer2_thread_t; 808 809 #define HAMMER2_THREAD_UNMOUNTING 0x0001 /* unmount request */ 810 #define HAMMER2_THREAD_DEV 0x0002 /* related to dev, not pfs */ 811 #define HAMMER2_THREAD_UNUSED04 0x0004 812 #define HAMMER2_THREAD_REMASTER 0x0008 /* remaster request */ 813 #define HAMMER2_THREAD_STOP 0x0010 /* exit request */ 814 #define HAMMER2_THREAD_FREEZE 0x0020 /* force idle */ 815 #define HAMMER2_THREAD_FROZEN 0x0040 /* restart */ 816 817 /* 818 * Support structure for dedup heuristic. 819 */ 820 struct hammer2_dedup { 821 hammer2_off_t data_off; 822 uint32_t data_crc; 823 uint32_t ticks; 824 }; 825 826 typedef struct hammer2_dedup hammer2_dedup_t; 827 828 /* 829 * hammer2_xop - container for VOP/XOP operation (allocated, not on stack). 830 * 831 * This structure is used to distribute a VOP operation across multiple 832 * nodes. It provides a rendezvous for concurrent node execution and 833 * can be detached from the frontend operation to allow the frontend to 834 * return early. 835 * 836 * This structure also sequences operations on up to three inodes. 837 */ 838 typedef void (*hammer2_xop_func_t)(union hammer2_xop *xop, int clidx); 839 840 struct hammer2_xop_fifo { 841 TAILQ_ENTRY(hammer2_xop_head) entry; 842 hammer2_chain_t *array[HAMMER2_XOPFIFO]; 843 int errors[HAMMER2_XOPFIFO]; 844 int ri; 845 int wi; 846 int flags; 847 }; 848 849 typedef struct hammer2_xop_fifo hammer2_xop_fifo_t; 850 851 #define HAMMER2_XOP_FIFO_RUN 0x0001 852 853 struct hammer2_xop_head { 854 hammer2_xop_func_t func; 855 hammer2_tid_t mtid; 856 struct hammer2_inode *ip1; 857 struct hammer2_inode *ip2; 858 struct hammer2_inode *ip3; 859 uint32_t check_counter; 860 uint32_t run_mask; 861 uint32_t chk_mask; 862 int state; 863 int error; 864 hammer2_key_t collect_key; 865 char *name1; 866 size_t name1_len; 867 char *name2; 868 size_t name2_len; 869 hammer2_xop_fifo_t collect[HAMMER2_MAXCLUSTER]; 870 hammer2_cluster_t cluster; /* help collections */ 871 }; 872 873 typedef struct hammer2_xop_head hammer2_xop_head_t; 874 875 struct hammer2_xop_ipcluster { 876 hammer2_xop_head_t head; 877 }; 878 879 struct hammer2_xop_strategy { 880 hammer2_xop_head_t head; 881 hammer2_key_t lbase; 882 int finished; 883 hammer2_mtx_t lock; 884 struct bio *bio; 885 }; 886 887 struct hammer2_xop_readdir { 888 hammer2_xop_head_t head; 889 hammer2_key_t lkey; 890 }; 891 892 struct hammer2_xop_nresolve { 893 hammer2_xop_head_t head; 894 hammer2_key_t lhc; /* if name is NULL used lhc */ 895 }; 896 897 struct hammer2_xop_nlink { 898 hammer2_xop_head_t head; 899 int nlinks_delta; 900 }; 901 902 struct hammer2_xop_unlink { 903 hammer2_xop_head_t head; 904 int isdir; 905 int dopermanent; 906 }; 907 908 struct hammer2_xop_nrename { 909 hammer2_xop_head_t head; 910 hammer2_tid_t lhc; 911 int ip_key; 912 }; 913 914 struct hammer2_xop_scanlhc { 915 hammer2_xop_head_t head; 916 hammer2_key_t lhc; 917 }; 918 919 struct hammer2_xop_scanall { 920 hammer2_xop_head_t head; 921 hammer2_key_t key_beg; /* inclusive */ 922 hammer2_key_t key_end; /* inclusive */ 923 }; 924 925 struct hammer2_xop_lookup { 926 hammer2_xop_head_t head; 927 hammer2_key_t lhc; 928 }; 929 930 struct hammer2_xop_create { 931 hammer2_xop_head_t head; 932 hammer2_inode_meta_t meta; /* initial metadata */ 933 hammer2_key_t lhc; 934 int flags; 935 }; 936 937 struct hammer2_xop_destroy { 938 hammer2_xop_head_t head; 939 }; 940 941 struct hammer2_xop_fsync { 942 hammer2_xop_head_t head; 943 hammer2_inode_meta_t meta; 944 hammer2_off_t osize; 945 u_int ipflags; 946 int clear_directdata; 947 }; 948 949 struct hammer2_xop_unlinkall { 950 hammer2_xop_head_t head; 951 hammer2_key_t key_beg; 952 hammer2_key_t key_end; 953 }; 954 955 struct hammer2_xop_connect { 956 hammer2_xop_head_t head; 957 hammer2_key_t lhc; 958 }; 959 960 struct hammer2_xop_flush { 961 hammer2_xop_head_t head; 962 }; 963 964 typedef struct hammer2_xop_readdir hammer2_xop_readdir_t; 965 typedef struct hammer2_xop_nresolve hammer2_xop_nresolve_t; 966 typedef struct hammer2_xop_nlink hammer2_xop_nlink_t; 967 typedef struct hammer2_xop_unlink hammer2_xop_unlink_t; 968 typedef struct hammer2_xop_nrename hammer2_xop_nrename_t; 969 typedef struct hammer2_xop_ipcluster hammer2_xop_ipcluster_t; 970 typedef struct hammer2_xop_strategy hammer2_xop_strategy_t; 971 typedef struct hammer2_xop_create hammer2_xop_create_t; 972 typedef struct hammer2_xop_destroy hammer2_xop_destroy_t; 973 typedef struct hammer2_xop_fsync hammer2_xop_fsync_t; 974 typedef struct hammer2_xop_unlinkall hammer2_xop_unlinkall_t; 975 typedef struct hammer2_xop_scanlhc hammer2_xop_scanlhc_t; 976 typedef struct hammer2_xop_scanall hammer2_xop_scanall_t; 977 typedef struct hammer2_xop_lookup hammer2_xop_lookup_t; 978 typedef struct hammer2_xop_connect hammer2_xop_connect_t; 979 typedef struct hammer2_xop_flush hammer2_xop_flush_t; 980 981 union hammer2_xop { 982 hammer2_xop_head_t head; 983 hammer2_xop_ipcluster_t xop_ipcluster; 984 hammer2_xop_readdir_t xop_readdir; 985 hammer2_xop_nresolve_t xop_nresolve; 986 hammer2_xop_nlink_t xop_nlink; 987 hammer2_xop_unlink_t xop_unlink; 988 hammer2_xop_nrename_t xop_nrename; 989 hammer2_xop_strategy_t xop_strategy; 990 hammer2_xop_create_t xop_create; 991 hammer2_xop_destroy_t xop_destroy; 992 hammer2_xop_fsync_t xop_fsync; 993 hammer2_xop_unlinkall_t xop_unlinkall; 994 hammer2_xop_scanlhc_t xop_scanlhc; 995 hammer2_xop_scanall_t xop_scanall; 996 hammer2_xop_lookup_t xop_lookup; 997 hammer2_xop_flush_t xop_flush; 998 hammer2_xop_connect_t xop_connect; 999 }; 1000 1001 typedef union hammer2_xop hammer2_xop_t; 1002 1003 /* 1004 * hammer2_xop_group - Manage XOP support threads. 1005 */ 1006 struct hammer2_xop_group { 1007 hammer2_thread_t thrs[HAMMER2_MAXCLUSTER]; 1008 }; 1009 1010 typedef struct hammer2_xop_group hammer2_xop_group_t; 1011 1012 /* 1013 * flags to hammer2_xop_collect() 1014 */ 1015 #define HAMMER2_XOP_COLLECT_NOWAIT 0x00000001 1016 #define HAMMER2_XOP_COLLECT_WAITALL 0x00000002 1017 1018 /* 1019 * flags to hammer2_xop_alloc() 1020 * 1021 * MODIFYING - This is a modifying transaction, allocate a mtid. 1022 */ 1023 #define HAMMER2_XOP_MODIFYING 0x00000001 1024 1025 /* 1026 * Global (per partition) management structure, represents a hard block 1027 * device. Typically referenced by hammer2_chain structures when applicable. 1028 * Typically not used for network-managed elements. 1029 * 1030 * Note that a single hammer2_dev can be indirectly tied to multiple system 1031 * mount points. There is no direct relationship. System mounts are 1032 * per-cluster-id, not per-block-device, and a single hard mount might contain 1033 * many PFSs and those PFSs might combine together in various ways to form 1034 * the set of available clusters. 1035 */ 1036 struct hammer2_dev { 1037 struct vnode *devvp; /* device vnode */ 1038 int ronly; /* read-only mount */ 1039 int mount_count; /* number of actively mounted PFSs */ 1040 TAILQ_ENTRY(hammer2_dev) mntentry; /* hammer2_mntlist */ 1041 1042 struct malloc_type *mchain; 1043 int nipstacks; 1044 int maxipstacks; 1045 kdmsg_iocom_t iocom; /* volume-level dmsg interface */ 1046 struct spinlock io_spin; /* iotree access */ 1047 struct hammer2_io_tree iotree; 1048 int iofree_count; 1049 hammer2_chain_t vchain; /* anchor chain (topology) */ 1050 hammer2_chain_t fchain; /* anchor chain (freemap) */ 1051 struct spinlock list_spin; 1052 struct h2_flush_list flushq; /* flush seeds */ 1053 struct hammer2_pfs *spmp; /* super-root pmp for transactions */ 1054 struct lock bulklk; /* bulkfree lock */ 1055 struct lock vollk; /* lockmgr lock */ 1056 hammer2_off_t heur_freemap[HAMMER2_FREEMAP_HEUR_SIZE]; 1057 hammer2_dedup_t heur_dedup[HAMMER2_DEDUP_HEUR_SIZE]; 1058 int volhdrno; /* last volhdrno written */ 1059 char devrepname[64]; /* for kprintf */ 1060 hammer2_volume_data_t voldata; 1061 hammer2_volume_data_t volsync; /* synchronized voldata */ 1062 }; 1063 1064 typedef struct hammer2_dev hammer2_dev_t; 1065 1066 /* 1067 * Helper functions (cluster must be locked for flags to be valid). 1068 */ 1069 static __inline 1070 int 1071 hammer2_chain_rdok(hammer2_chain_t *chain) 1072 { 1073 return (chain->error == 0); 1074 } 1075 1076 static __inline 1077 int 1078 hammer2_chain_wrok(hammer2_chain_t *chain) 1079 { 1080 return (chain->error == 0 && chain->hmp->ronly == 0); 1081 } 1082 1083 /* 1084 * Per-cluster management structure. This structure will be tied to a 1085 * system mount point if the system is mounting the PFS, but is also used 1086 * to manage clusters encountered during the super-root scan or received 1087 * via LNK_SPANs that might not be mounted. 1088 * 1089 * This structure is also used to represent the super-root that hangs off 1090 * of a hard mount point. The super-root is not really a cluster element. 1091 * In this case the spmp_hmp field will be non-NULL. It's just easier to do 1092 * this than to special case super-root manipulation in the hammer2_chain* 1093 * code as being only hammer2_dev-related. 1094 * 1095 * pfs_mode and pfs_nmasters are rollup fields which critically describes 1096 * how elements of the cluster act on the cluster. pfs_mode is only applicable 1097 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to 1098 * how many masters have been configured for a cluster and is always 1099 * applicable. pfs_types[] is an array with 1:1 correspondance to the 1100 * iroot cluster and describes the PFS types of the nodes making up the 1101 * cluster. 1102 * 1103 * WARNING! Portions of this structure have deferred initialization. In 1104 * particular, if not mounted there will be no ihidden or wthread. 1105 * umounted network PFSs will also be missing iroot and numerous 1106 * other fields will not be initialized prior to mount. 1107 * 1108 * Synchronization threads are chain-specific and only applicable 1109 * to local hard PFS entries. A hammer2_pfs structure may contain 1110 * more than one when multiple hard PFSs are present on the local 1111 * machine which require synchronization monitoring. Most PFSs 1112 * (such as snapshots) are 1xMASTER PFSs which do not need a 1113 * synchronization thread. 1114 * 1115 * WARNING! The chains making up pfs->iroot's cluster are accounted for in 1116 * hammer2_dev->mount_count when the pfs is associated with a mount 1117 * point. 1118 */ 1119 struct hammer2_pfs { 1120 struct mount *mp; 1121 TAILQ_ENTRY(hammer2_pfs) mntentry; /* hammer2_pfslist */ 1122 uuid_t pfs_clid; 1123 hammer2_dev_t *spmp_hmp; /* only if super-root pmp */ 1124 hammer2_inode_t *iroot; /* PFS root inode */ 1125 hammer2_inode_t *ihidden; /* PFS hidden directory */ 1126 uint8_t pfs_types[HAMMER2_MAXCLUSTER]; 1127 char *pfs_names[HAMMER2_MAXCLUSTER]; 1128 hammer2_dev_t *pfs_hmps[HAMMER2_MAXCLUSTER]; 1129 hammer2_trans_t trans; 1130 struct lock lock; /* PFS lock for certain ops */ 1131 struct lock lock_nlink; /* rename and nlink lock */ 1132 struct netexport export; /* nfs export */ 1133 int ronly; /* read-only mount */ 1134 struct malloc_type *minode; 1135 struct malloc_type *mmsg; 1136 struct spinlock inum_spin; /* inumber lookup */ 1137 struct hammer2_inode_tree inum_tree; /* (not applicable to spmp) */ 1138 hammer2_tid_t modify_tid; /* modify transaction id */ 1139 hammer2_tid_t inode_tid; /* inode allocator */ 1140 uint8_t pfs_nmasters; /* total masters */ 1141 uint8_t pfs_mode; /* operating mode PFSMODE */ 1142 uint8_t unused01; 1143 uint8_t unused02; 1144 int xop_iterator; 1145 long inmem_inodes; 1146 uint32_t inmem_dirty_chains; 1147 int count_lwinprog; /* logical write in prog */ 1148 struct spinlock list_spin; 1149 struct h2_sideq_list sideq; /* last-close dirty/unlink */ 1150 hammer2_thread_t sync_thrs[HAMMER2_MAXCLUSTER]; 1151 uint32_t cluster_flags; /* cached cluster flags */ 1152 int has_xop_threads; 1153 struct spinlock xop_spin; /* xop sequencer */ 1154 hammer2_xop_group_t xop_groups[HAMMER2_XOPGROUPS]; 1155 hammer2_xop_list_t xopq[HAMMER2_MAXCLUSTER]; 1156 }; 1157 1158 typedef struct hammer2_pfs hammer2_pfs_t; 1159 1160 #define HAMMER2_DIRTYCHAIN_WAITING 0x80000000 1161 #define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF 1162 1163 #define HAMMER2_LWINPROG_WAITING 0x80000000 1164 #define HAMMER2_LWINPROG_WAITING0 0x40000000 1165 #define HAMMER2_LWINPROG_MASK 0x3FFFFFFF 1166 1167 /* 1168 * hammer2_cluster_check 1169 */ 1170 #define HAMMER2_CHECK_NULL 0x00000001 1171 1172 /* 1173 * Bulkscan 1174 */ 1175 #define HAMMER2_BULK_ABORT 0x00000001 1176 1177 /* 1178 * Misc 1179 */ 1180 #if defined(_KERNEL) 1181 1182 MALLOC_DECLARE(M_HAMMER2); 1183 1184 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data) 1185 #define ITOV(ip) ((ip)->vp) 1186 1187 /* 1188 * Currently locked chains retain the locked buffer cache buffer for 1189 * indirect blocks, and indirect blocks can be one of two sizes. The 1190 * device buffer has to match the case to avoid deadlocking recursive 1191 * chains that might otherwise try to access different offsets within 1192 * the same device buffer. 1193 */ 1194 static __inline 1195 int 1196 hammer2_devblkradix(int radix) 1197 { 1198 #if 0 1199 if (radix <= HAMMER2_LBUFRADIX) { 1200 return (HAMMER2_LBUFRADIX); 1201 } else { 1202 return (HAMMER2_PBUFRADIX); 1203 } 1204 #endif 1205 return (HAMMER2_PBUFRADIX); 1206 } 1207 1208 /* 1209 * XXX almost time to remove this. DIO uses PBUFSIZE exclusively now. 1210 */ 1211 static __inline 1212 size_t 1213 hammer2_devblksize(size_t bytes) 1214 { 1215 #if 0 1216 if (bytes <= HAMMER2_LBUFSIZE) { 1217 return(HAMMER2_LBUFSIZE); 1218 } else { 1219 KKASSERT(bytes <= HAMMER2_PBUFSIZE && 1220 (bytes ^ (bytes - 1)) == ((bytes << 1) - 1)); 1221 return (HAMMER2_PBUFSIZE); 1222 } 1223 #endif 1224 return (HAMMER2_PBUFSIZE); 1225 } 1226 1227 1228 static __inline 1229 hammer2_pfs_t * 1230 MPTOPMP(struct mount *mp) 1231 { 1232 return ((hammer2_pfs_t *)mp->mnt_data); 1233 } 1234 1235 #define LOCKSTART int __nlocks = curthread->td_locks 1236 #define LOCKENTER (++curthread->td_locks) 1237 #define LOCKEXIT (--curthread->td_locks) 1238 #define LOCKSTOP KKASSERT(curthread->td_locks == __nlocks) 1239 1240 extern struct vop_ops hammer2_vnode_vops; 1241 extern struct vop_ops hammer2_spec_vops; 1242 extern struct vop_ops hammer2_fifo_vops; 1243 1244 extern int hammer2_debug; 1245 extern int hammer2_cluster_enable; 1246 extern int hammer2_hardlink_enable; 1247 extern int hammer2_flush_pipe; 1248 extern int hammer2_synchronous_flush; 1249 extern int hammer2_dio_count; 1250 extern long hammer2_limit_dirty_chains; 1251 extern long hammer2_count_modified_chains; 1252 extern long hammer2_iod_file_read; 1253 extern long hammer2_iod_meta_read; 1254 extern long hammer2_iod_indr_read; 1255 extern long hammer2_iod_fmap_read; 1256 extern long hammer2_iod_volu_read; 1257 extern long hammer2_iod_file_write; 1258 extern long hammer2_iod_file_wembed; 1259 extern long hammer2_iod_file_wzero; 1260 extern long hammer2_iod_file_wdedup; 1261 extern long hammer2_iod_meta_write; 1262 extern long hammer2_iod_indr_write; 1263 extern long hammer2_iod_fmap_write; 1264 extern long hammer2_iod_volu_write; 1265 extern long hammer2_ioa_file_read; 1266 extern long hammer2_ioa_meta_read; 1267 extern long hammer2_ioa_indr_read; 1268 extern long hammer2_ioa_fmap_read; 1269 extern long hammer2_ioa_volu_read; 1270 extern long hammer2_ioa_file_write; 1271 extern long hammer2_ioa_meta_write; 1272 extern long hammer2_ioa_indr_write; 1273 extern long hammer2_ioa_fmap_write; 1274 extern long hammer2_ioa_volu_write; 1275 1276 extern struct objcache *cache_buffer_read; 1277 extern struct objcache *cache_buffer_write; 1278 extern struct objcache *cache_xops; 1279 1280 /* 1281 * hammer2_subr.c 1282 */ 1283 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size)) 1284 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc)) 1285 1286 int hammer2_signal_check(time_t *timep); 1287 const char *hammer2_error_str(int error); 1288 1289 void hammer2_inode_lock(hammer2_inode_t *ip, int how); 1290 void hammer2_inode_unlock(hammer2_inode_t *ip); 1291 hammer2_chain_t *hammer2_inode_chain(hammer2_inode_t *ip, int clindex, int how); 1292 hammer2_chain_t *hammer2_inode_chain_and_parent(hammer2_inode_t *ip, 1293 int clindex, hammer2_chain_t **parentp, int how); 1294 hammer2_mtx_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip); 1295 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip, 1296 hammer2_mtx_state_t ostate); 1297 int hammer2_inode_lock_upgrade(hammer2_inode_t *ip); 1298 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, int); 1299 1300 void hammer2_dev_exlock(hammer2_dev_t *hmp); 1301 void hammer2_dev_shlock(hammer2_dev_t *hmp); 1302 void hammer2_dev_unlock(hammer2_dev_t *hmp); 1303 1304 int hammer2_get_dtype(const hammer2_inode_data_t *ipdata); 1305 int hammer2_get_vtype(uint8_t type); 1306 u_int8_t hammer2_get_obj_type(enum vtype vtype); 1307 void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts); 1308 u_int64_t hammer2_timespec_to_time(const struct timespec *ts); 1309 u_int32_t hammer2_to_unix_xid(const uuid_t *uuid); 1310 void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid); 1311 void hammer2_trans_manage_init(hammer2_pfs_t *pmp); 1312 1313 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len); 1314 int hammer2_getradix(size_t bytes); 1315 1316 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff, 1317 hammer2_key_t *lbasep, hammer2_key_t *leofp); 1318 int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase); 1319 void hammer2_update_time(uint64_t *timep); 1320 void hammer2_adjreadcounter(hammer2_blockref_t *bref, size_t bytes); 1321 1322 /* 1323 * hammer2_inode.c 1324 */ 1325 struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp); 1326 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfs_t *pmp, 1327 hammer2_tid_t inum); 1328 hammer2_inode_t *hammer2_inode_get(hammer2_pfs_t *pmp, hammer2_inode_t *dip, 1329 hammer2_cluster_t *cluster, int idx); 1330 void hammer2_inode_free(hammer2_inode_t *ip); 1331 void hammer2_inode_ref(hammer2_inode_t *ip); 1332 void hammer2_inode_drop(hammer2_inode_t *ip); 1333 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip, 1334 hammer2_cluster_t *cluster); 1335 void hammer2_inode_repoint_one(hammer2_inode_t *ip, hammer2_cluster_t *cluster, 1336 int idx); 1337 void hammer2_inode_modify(hammer2_inode_t *ip); 1338 void hammer2_inode_run_sideq(hammer2_pfs_t *pmp); 1339 1340 hammer2_inode_t *hammer2_inode_create(hammer2_inode_t *dip, 1341 struct vattr *vap, struct ucred *cred, 1342 const uint8_t *name, size_t name_len, hammer2_key_t lhc, 1343 hammer2_key_t inum, uint8_t type, uint8_t target_type, 1344 int flags, int *errorp); 1345 int hammer2_inode_connect(hammer2_inode_t *dip, hammer2_inode_t *ip, 1346 const char *name, size_t name_len, 1347 hammer2_key_t lhc); 1348 hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip, 1349 hammer2_inode_t *tdip); 1350 void hammer2_inode_chain_sync(hammer2_inode_t *ip); 1351 int hammer2_inode_unlink_finisher(hammer2_inode_t *ip, int isopen); 1352 void hammer2_inode_install_hidden(hammer2_pfs_t *pmp); 1353 1354 /* 1355 * hammer2_chain.c 1356 */ 1357 void hammer2_voldata_lock(hammer2_dev_t *hmp); 1358 void hammer2_voldata_unlock(hammer2_dev_t *hmp); 1359 void hammer2_voldata_modify(hammer2_dev_t *hmp); 1360 hammer2_chain_t *hammer2_chain_alloc(hammer2_dev_t *hmp, 1361 hammer2_pfs_t *pmp, 1362 hammer2_blockref_t *bref); 1363 void hammer2_chain_core_init(hammer2_chain_t *chain); 1364 void hammer2_chain_ref(hammer2_chain_t *chain); 1365 void hammer2_chain_drop(hammer2_chain_t *chain); 1366 void hammer2_chain_lock(hammer2_chain_t *chain, int how); 1367 void hammer2_chain_push_shared_lock(hammer2_chain_t *chain); 1368 void hammer2_chain_pull_shared_lock(hammer2_chain_t *chain); 1369 void hammer2_chain_load_data(hammer2_chain_t *chain); 1370 const hammer2_media_data_t *hammer2_chain_rdata(hammer2_chain_t *chain); 1371 hammer2_media_data_t *hammer2_chain_wdata(hammer2_chain_t *chain); 1372 int hammer2_chain_snapshot(hammer2_chain_t *chain, hammer2_ioc_pfs_t *pmp, 1373 hammer2_tid_t mtid); 1374 1375 int hammer2_chain_hardlink_find(hammer2_inode_t *dip, 1376 hammer2_chain_t **parentp, 1377 hammer2_chain_t **chainp, 1378 int flags); 1379 void hammer2_chain_modify(hammer2_chain_t *chain, hammer2_tid_t mtid, 1380 hammer2_off_t dedup_off, int flags); 1381 void hammer2_chain_modify_ip(hammer2_inode_t *ip, hammer2_chain_t *chain, 1382 hammer2_tid_t mtid, int flags); 1383 void hammer2_chain_resize(hammer2_inode_t *ip, hammer2_chain_t *parent, 1384 hammer2_chain_t *chain, 1385 hammer2_tid_t mtid, hammer2_off_t dedup_off, 1386 int nradix, int flags); 1387 void hammer2_chain_unlock(hammer2_chain_t *chain); 1388 void hammer2_chain_wait(hammer2_chain_t *chain); 1389 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation, 1390 hammer2_blockref_t *bref); 1391 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags); 1392 void hammer2_chain_lookup_done(hammer2_chain_t *parent); 1393 hammer2_chain_t *hammer2_chain_getparent(hammer2_chain_t **parentp, int how); 1394 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp, 1395 hammer2_key_t *key_nextp, 1396 hammer2_key_t key_beg, hammer2_key_t key_end, 1397 int *cache_indexp, int flags); 1398 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp, 1399 hammer2_chain_t *chain, 1400 hammer2_key_t *key_nextp, 1401 hammer2_key_t key_beg, hammer2_key_t key_end, 1402 int *cache_indexp, int flags); 1403 hammer2_blockref_t *hammer2_chain_scan(hammer2_chain_t *parent, 1404 hammer2_chain_t **chainp, 1405 hammer2_blockref_t *bref, 1406 int *firstp, int *cache_indexp, int flags); 1407 1408 int hammer2_chain_create(hammer2_chain_t **parentp, 1409 hammer2_chain_t **chainp, hammer2_pfs_t *pmp, 1410 hammer2_key_t key, int keybits, 1411 int type, size_t bytes, hammer2_tid_t mtid, 1412 hammer2_off_t dedup_off, int flags); 1413 void hammer2_chain_rename(hammer2_blockref_t *bref, 1414 hammer2_chain_t **parentp, 1415 hammer2_chain_t *chain, 1416 hammer2_tid_t mtid, int flags); 1417 void hammer2_chain_delete(hammer2_chain_t *parent, hammer2_chain_t *chain, 1418 hammer2_tid_t mtid, int flags); 1419 void hammer2_chain_setflush(hammer2_chain_t *chain); 1420 void hammer2_chain_countbrefs(hammer2_chain_t *chain, 1421 hammer2_blockref_t *base, int count); 1422 hammer2_chain_t *hammer2_chain_bulksnap(hammer2_chain_t *chain); 1423 void hammer2_chain_bulkdrop(hammer2_chain_t *copy); 1424 1425 void hammer2_chain_setcheck(hammer2_chain_t *chain, void *bdata); 1426 int hammer2_chain_testcheck(hammer2_chain_t *chain, void *bdata); 1427 1428 1429 void hammer2_pfs_memory_wait(hammer2_pfs_t *pmp); 1430 void hammer2_pfs_memory_inc(hammer2_pfs_t *pmp); 1431 void hammer2_pfs_memory_wakeup(hammer2_pfs_t *pmp); 1432 1433 void hammer2_base_delete(hammer2_chain_t *chain, 1434 hammer2_blockref_t *base, int count, 1435 int *cache_indexp, hammer2_chain_t *child); 1436 void hammer2_base_insert(hammer2_chain_t *chain, 1437 hammer2_blockref_t *base, int count, 1438 int *cache_indexp, hammer2_chain_t *child); 1439 1440 /* 1441 * hammer2_flush.c 1442 */ 1443 void hammer2_flush(hammer2_chain_t *chain, int istop); 1444 void hammer2_flush_quick(hammer2_dev_t *hmp); 1445 void hammer2_delayed_flush(hammer2_chain_t *chain); 1446 1447 /* 1448 * hammer2_trans.c 1449 */ 1450 void hammer2_trans_init(hammer2_pfs_t *pmp, uint32_t flags); 1451 hammer2_tid_t hammer2_trans_sub(hammer2_pfs_t *pmp); 1452 void hammer2_trans_clear_preflush(hammer2_pfs_t *pmp); 1453 void hammer2_trans_done(hammer2_pfs_t *pmp); 1454 hammer2_tid_t hammer2_trans_newinum(hammer2_pfs_t *pmp); 1455 void hammer2_trans_assert_strategy(hammer2_pfs_t *pmp); 1456 1457 /* 1458 * hammer2_ioctl.c 1459 */ 1460 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data, 1461 int fflag, struct ucred *cred); 1462 1463 /* 1464 * hammer2_io.c 1465 */ 1466 void hammer2_io_putblk(hammer2_io_t **diop); 1467 void hammer2_io_cleanup(hammer2_dev_t *hmp, struct hammer2_io_tree *tree); 1468 char *hammer2_io_data(hammer2_io_t *dio, off_t lbase); 1469 hammer2_io_t *hammer2_io_getquick(hammer2_dev_t *hmp, off_t lbase, int lsize); 1470 void hammer2_io_getblk(hammer2_dev_t *hmp, off_t lbase, int lsize, 1471 hammer2_iocb_t *iocb); 1472 void hammer2_io_complete(hammer2_iocb_t *iocb); 1473 void hammer2_io_callback(struct bio *bio); 1474 void hammer2_iocb_wait(hammer2_iocb_t *iocb); 1475 int hammer2_io_new(hammer2_dev_t *hmp, off_t lbase, int lsize, 1476 hammer2_io_t **diop); 1477 int hammer2_io_newnz(hammer2_dev_t *hmp, off_t lbase, int lsize, 1478 hammer2_io_t **diop); 1479 int hammer2_io_newq(hammer2_dev_t *hmp, off_t lbase, int lsize, 1480 hammer2_io_t **diop); 1481 int hammer2_io_bread(hammer2_dev_t *hmp, off_t lbase, int lsize, 1482 hammer2_io_t **diop); 1483 void hammer2_io_bawrite(hammer2_io_t **diop); 1484 void hammer2_io_bdwrite(hammer2_io_t **diop); 1485 int hammer2_io_bwrite(hammer2_io_t **diop); 1486 int hammer2_io_isdirty(hammer2_io_t *dio); 1487 void hammer2_io_setdirty(hammer2_io_t *dio); 1488 void hammer2_io_setinval(hammer2_io_t *dio, u_int bytes); 1489 void hammer2_io_brelse(hammer2_io_t **diop); 1490 void hammer2_io_bqrelse(hammer2_io_t **diop); 1491 1492 /* 1493 * hammer2_thread.c 1494 */ 1495 void hammer2_thr_create(hammer2_thread_t *thr, hammer2_pfs_t *pmp, 1496 const char *id, int clindex, int repidx, 1497 void (*func)(void *arg)); 1498 void hammer2_thr_delete(hammer2_thread_t *thr); 1499 void hammer2_thr_remaster(hammer2_thread_t *thr); 1500 void hammer2_thr_freeze_async(hammer2_thread_t *thr); 1501 void hammer2_thr_freeze(hammer2_thread_t *thr); 1502 void hammer2_thr_unfreeze(hammer2_thread_t *thr); 1503 int hammer2_thr_break(hammer2_thread_t *thr); 1504 void hammer2_primary_xops_thread(void *arg); 1505 1506 /* 1507 * hammer2_thread.c (XOP API) 1508 */ 1509 void hammer2_xop_group_init(hammer2_pfs_t *pmp, hammer2_xop_group_t *xgrp); 1510 void *hammer2_xop_alloc(hammer2_inode_t *ip, int flags); 1511 void hammer2_xop_setname(hammer2_xop_head_t *xop, 1512 const char *name, size_t name_len); 1513 void hammer2_xop_setname2(hammer2_xop_head_t *xop, 1514 const char *name, size_t name_len); 1515 void hammer2_xop_setip2(hammer2_xop_head_t *xop, hammer2_inode_t *ip2); 1516 void hammer2_xop_setip3(hammer2_xop_head_t *xop, hammer2_inode_t *ip3); 1517 void hammer2_xop_reinit(hammer2_xop_head_t *xop); 1518 void hammer2_xop_helper_create(hammer2_pfs_t *pmp); 1519 void hammer2_xop_helper_cleanup(hammer2_pfs_t *pmp); 1520 void hammer2_xop_start(hammer2_xop_head_t *xop, hammer2_xop_func_t func); 1521 void hammer2_xop_start_except(hammer2_xop_head_t *xop, hammer2_xop_func_t func, 1522 int notidx); 1523 int hammer2_xop_collect(hammer2_xop_head_t *xop, int flags); 1524 void hammer2_xop_retire(hammer2_xop_head_t *xop, uint32_t mask); 1525 int hammer2_xop_active(hammer2_xop_head_t *xop); 1526 int hammer2_xop_feed(hammer2_xop_head_t *xop, hammer2_chain_t *chain, 1527 int clindex, int error); 1528 1529 /* 1530 * hammer2_synchro.c 1531 */ 1532 void hammer2_primary_sync_thread(void *arg); 1533 1534 /* 1535 * XOP backends in hammer2_xops.c, primarily for VNOPS. Other XOP backends 1536 * may be integrated into other source files. 1537 */ 1538 void hammer2_xop_ipcluster(hammer2_xop_t *xop, int clidx); 1539 void hammer2_xop_readdir(hammer2_xop_t *xop, int clidx); 1540 void hammer2_xop_nresolve(hammer2_xop_t *xop, int clidx); 1541 void hammer2_xop_unlink(hammer2_xop_t *xop, int clidx); 1542 void hammer2_xop_nrename(hammer2_xop_t *xop, int clidx); 1543 void hammer2_xop_nlink(hammer2_xop_t *xop, int clidx); 1544 void hammer2_xop_scanlhc(hammer2_xop_t *xop, int clidx); 1545 void hammer2_xop_scanall(hammer2_xop_t *xop, int clidx); 1546 void hammer2_xop_lookup(hammer2_xop_t *xop, int clidx); 1547 void hammer2_inode_xop_create(hammer2_xop_t *xop, int clidx); 1548 void hammer2_inode_xop_destroy(hammer2_xop_t *xop, int clidx); 1549 void hammer2_inode_xop_chain_sync(hammer2_xop_t *xop, int clidx); 1550 void hammer2_inode_xop_unlinkall(hammer2_xop_t *xop, int clidx); 1551 void hammer2_inode_xop_connect(hammer2_xop_t *xop, int clidx); 1552 void hammer2_inode_xop_flush(hammer2_xop_t *xop, int clidx); 1553 1554 /* 1555 * hammer2_msgops.c 1556 */ 1557 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg); 1558 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg); 1559 1560 /* 1561 * hammer2_vfsops.c 1562 */ 1563 void hammer2_volconf_update(hammer2_dev_t *hmp, int index); 1564 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp, char pfx); 1565 int hammer2_vfs_sync(struct mount *mp, int waitflags); 1566 hammer2_pfs_t *hammer2_pfsalloc(hammer2_chain_t *chain, 1567 const hammer2_inode_data_t *ripdata, 1568 hammer2_tid_t modify_tid); 1569 1570 void hammer2_lwinprog_ref(hammer2_pfs_t *pmp); 1571 void hammer2_lwinprog_drop(hammer2_pfs_t *pmp); 1572 void hammer2_lwinprog_wait(hammer2_pfs_t *pmp, int pipe); 1573 1574 /* 1575 * hammer2_freemap.c 1576 */ 1577 int hammer2_freemap_alloc(hammer2_chain_t *chain, size_t bytes); 1578 void hammer2_freemap_adjust(hammer2_dev_t *hmp, 1579 hammer2_blockref_t *bref, int how); 1580 1581 /* 1582 * hammer2_cluster.c 1583 */ 1584 uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster); 1585 const hammer2_media_data_t *hammer2_cluster_rdata(hammer2_cluster_t *cluster); 1586 hammer2_media_data_t *hammer2_cluster_wdata(hammer2_cluster_t *cluster); 1587 hammer2_cluster_t *hammer2_cluster_from_chain(hammer2_chain_t *chain); 1588 void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref); 1589 hammer2_cluster_t *hammer2_cluster_alloc(hammer2_pfs_t *pmp, 1590 hammer2_blockref_t *bref); 1591 void hammer2_cluster_ref(hammer2_cluster_t *cluster); 1592 void hammer2_cluster_drop(hammer2_cluster_t *cluster); 1593 void hammer2_cluster_lock(hammer2_cluster_t *cluster, int how); 1594 int hammer2_cluster_check(hammer2_cluster_t *cluster, hammer2_key_t lokey, 1595 int flags); 1596 void hammer2_cluster_resolve(hammer2_cluster_t *cluster); 1597 void hammer2_cluster_forcegood(hammer2_cluster_t *cluster); 1598 hammer2_cluster_t *hammer2_cluster_copy(hammer2_cluster_t *ocluster); 1599 void hammer2_cluster_unlock(hammer2_cluster_t *cluster); 1600 1601 int hammer2_bulkfree_pass(hammer2_dev_t *hmp, 1602 struct hammer2_ioc_bulkfree *bfi); 1603 1604 /* 1605 * hammer2_iocom.c 1606 */ 1607 void hammer2_iocom_init(hammer2_dev_t *hmp); 1608 void hammer2_iocom_uninit(hammer2_dev_t *hmp); 1609 void hammer2_cluster_reconnect(hammer2_dev_t *hmp, struct file *fp); 1610 1611 /* 1612 * hammer2_strategy.c 1613 */ 1614 int hammer2_vop_strategy(struct vop_strategy_args *ap); 1615 int hammer2_vop_bmap(struct vop_bmap_args *ap); 1616 void hammer2_write_thread(void *arg); 1617 void hammer2_bioq_sync(hammer2_pfs_t *pmp); 1618 void hammer2_dedup_clear(hammer2_dev_t *hmp); 1619 1620 #endif /* !_KERNEL */ 1621 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */ 1622