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