1 /* 2 * Copyright (c) 2011-2018 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 #ifdef _KERNEL 66 #include <sys/param.h> 67 #endif 68 #include <sys/types.h> 69 #ifdef _KERNEL 70 #include <sys/kernel.h> 71 #endif 72 #include <sys/conf.h> 73 #ifdef _KERNEL 74 #include <sys/systm.h> 75 #endif 76 #include <sys/diskslice.h> 77 #include <sys/tree.h> 78 #include <sys/malloc.h> 79 #include <sys/mount.h> 80 #include <sys/vnode.h> 81 #include <sys/proc.h> 82 #include <sys/priv.h> 83 #include <sys/stat.h> 84 #include <sys/thread.h> 85 #include <sys/lockf.h> 86 #include <sys/buf.h> 87 #include <sys/queue.h> 88 #include <sys/limits.h> 89 #include <sys/dmsg.h> 90 #include <sys/mutex.h> 91 #include <sys/lock.h> 92 #include <sys/file.h> 93 #include <sys/objcache.h> 94 95 #ifdef _KERNEL 96 #include <sys/signal2.h> 97 #include <sys/buf2.h> 98 #include <sys/mutex2.h> 99 #include <sys/spinlock2.h> 100 #endif 101 102 #include "hammer2_xxhash.h" 103 #include "hammer2_disk.h" 104 #include "hammer2_mount.h" 105 #include "hammer2_ioctl.h" 106 107 struct hammer2_io; 108 struct hammer2_chain; 109 struct hammer2_inode; 110 struct hammer2_depend; 111 struct hammer2_dev; 112 struct hammer2_pfs; 113 union hammer2_xop; 114 115 /* 116 * Mutex and lock shims. Hammer2 requires support for asynchronous and 117 * abortable locks, and both exclusive and shared spinlocks. Normal 118 * synchronous non-abortable locks can be substituted for spinlocks. 119 */ 120 typedef mtx_t hammer2_mtx_t; 121 typedef mtx_state_t hammer2_mtx_state_t; 122 123 typedef struct spinlock hammer2_spin_t; 124 125 #define hammer2_mtx_ex mtx_lock_ex_quick 126 #define hammer2_mtx_ex_try mtx_lock_ex_try 127 #define hammer2_mtx_sh mtx_lock_sh_quick 128 #define hammer2_mtx_sh_again mtx_lock_sh_again 129 #define hammer2_mtx_sh_try mtx_lock_sh_try 130 #define hammer2_mtx_unlock mtx_unlock 131 #define hammer2_mtx_upgrade_try mtx_upgrade_try 132 #define hammer2_mtx_downgrade mtx_downgrade 133 #define hammer2_mtx_owned mtx_owned 134 #define hammer2_mtx_init mtx_init 135 #define hammer2_mtx_temp_release mtx_lock_temp_release 136 #define hammer2_mtx_temp_restore mtx_lock_temp_restore 137 #define hammer2_mtx_refs mtx_lockrefs 138 139 #define hammer2_spin_init spin_init 140 #define hammer2_spin_sh spin_lock_shared 141 #define hammer2_spin_ex spin_lock 142 #define hammer2_spin_unsh spin_unlock_shared 143 #define hammer2_spin_unex spin_unlock 144 #define hammer2_spin_lock_update spin_lock_update 145 #define hammer2_spin_unlock_update spin_unlock_update 146 147 TAILQ_HEAD(hammer2_xop_list, hammer2_xop_head); 148 TAILQ_HEAD(hammer2_chain_list, hammer2_chain); 149 150 typedef struct hammer2_xop_list hammer2_xop_list_t; 151 152 /* 153 * Cap the dynamic calculation for the maximum number of dirty 154 * chains and dirty inodes allowed. 155 */ 156 #define HAMMER2_LIMIT_DIRTY_CHAINS (1024*1024) 157 #define HAMMER2_LIMIT_DIRTY_INODES (65536) 158 159 /* 160 * The chain structure tracks a portion of the media topology from the 161 * root (volume) down. Chains represent volumes, inodes, indirect blocks, 162 * data blocks, and freemap nodes and leafs. 163 * 164 * The chain structure utilizes a simple singly-homed topology and the 165 * chain's in-memory topology will move around as the chains do, due mainly 166 * to renames and indirect block creation. 167 * 168 * Block Table Updates 169 * 170 * Block table updates for insertions and updates are delayed until the 171 * flush. This allows us to avoid having to modify the parent chain 172 * all the way to the root. 173 * 174 * Block table deletions are performed immediately (modifying the parent 175 * in the process) because the flush code uses the chain structure to 176 * track delayed updates and the chain will be (likely) gone or moved to 177 * another location in the topology after a deletion. 178 * 179 * A prior iteration of the code tried to keep the relationship intact 180 * on deletes by doing a delete-duplicate operation on the chain, but 181 * it added way too much complexity to the codebase. 182 * 183 * Flush Synchronization 184 * 185 * The flush code must flush modified chains bottom-up. Because chain 186 * structures can shift around and are NOT topologically stable, 187 * modified chains are independently indexed for the flush. As the flush 188 * runs it modifies (or further modifies) and updates the parents, 189 * propagating the flush all the way to the volume root. 190 * 191 * Modifying front-end operations can occur during a flush but will block 192 * in two cases: (1) when the front-end tries to operate on the inode 193 * currently in the midst of being flushed and (2) if the front-end 194 * crosses an inode currently being flushed (such as during a rename). 195 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and 196 * the flusher is currently working on "a/b/c", the rename will block 197 * temporarily in order to ensure that "x" exists in one place or the 198 * other. 199 * 200 * Meta-data statistics are updated by the flusher. The front-end will 201 * make estimates but meta-data must be fully synchronized only during a 202 * flush in order to ensure that it remains correct across a crash. 203 * 204 * Multiple flush synchronizations can theoretically be in-flight at the 205 * same time but the implementation is not coded to handle the case and 206 * currently serializes them. 207 * 208 * Snapshots: 209 * 210 * Snapshots currently require the subdirectory tree being snapshotted 211 * to be flushed. The snapshot then creates a new super-root inode which 212 * copies the flushed blockdata of the directory or file that was 213 * snapshotted. 214 * 215 * Radix tree NOTES: 216 * 217 * - Note that the radix tree runs in powers of 2 only so sub-trees 218 * cannot straddle edges. 219 */ 220 RB_HEAD(hammer2_chain_tree, hammer2_chain); 221 222 struct hammer2_reptrack { 223 hammer2_spin_t spin; 224 struct hammer2_reptrack *next; 225 struct hammer2_chain *chain; 226 }; 227 228 /* 229 * Core topology for chain (embedded in chain). Protected by a spinlock. 230 */ 231 struct hammer2_chain_core { 232 hammer2_spin_t spin; 233 struct hammer2_reptrack *reptrack; 234 struct hammer2_chain_tree rbtree; /* sub-chains */ 235 int live_zero; /* blockref array opt */ 236 u_int live_count; /* live (not deleted) chains in tree */ 237 u_int chain_count; /* live + deleted chains under core */ 238 int generation; /* generation number (inserts only) */ 239 }; 240 241 typedef struct hammer2_chain_core hammer2_chain_core_t; 242 243 RB_HEAD(hammer2_io_tree, hammer2_io); 244 245 /* 246 * DIO - Management structure wrapping system buffer cache. 247 * 248 * HAMMER2 uses an I/O abstraction that allows it to cache and manipulate 249 * fixed-sized filesystem buffers frontend by variable-sized hammer2_chain 250 * structures. 251 */ 252 /* #define HAMMER2_IO_DEBUG */ 253 254 #ifdef HAMMER2_IO_DEBUG 255 #define HAMMER2_IO_DEBUG_ARGS , const char *file, int line 256 #define HAMMER2_IO_DEBUG_CALL , file, line 257 #define HAMMER2_IO_DEBUG_COUNT 2048 258 #define HAMMER2_IO_DEBUG_MASK (HAMMER2_IO_DEBUG_COUNT - 1) 259 #else 260 #define HAMMER2_IO_DEBUG_ARGS 261 #define HAMMER2_IO_DEBUG_CALL 262 #endif 263 264 struct hammer2_io { 265 RB_ENTRY(hammer2_io) rbnode; /* indexed by device offset */ 266 struct hammer2_dev *hmp; 267 struct vnode *devvp; 268 struct buf *bp; 269 off_t dbase; /* offset of devvp within volumes */ 270 off_t pbase; 271 uint64_t refs; 272 int psize; 273 int act; /* activity */ 274 int btype; /* approximate BREF_TYPE_* */ 275 int ticks; 276 int error; 277 #ifdef HAMMER2_IO_DEBUG 278 int debug_index; 279 #else 280 int unused01; 281 #endif 282 uint64_t dedup_valid; /* valid for dedup operation */ 283 uint64_t dedup_alloc; /* allocated / de-dupable */ 284 #ifdef HAMMER2_IO_DEBUG 285 const char *debug_file[HAMMER2_IO_DEBUG_COUNT]; 286 void *debug_td[HAMMER2_IO_DEBUG_COUNT]; 287 int debug_line[HAMMER2_IO_DEBUG_COUNT]; 288 uint64_t debug_refs[HAMMER2_IO_DEBUG_COUNT]; 289 #endif 290 }; 291 292 typedef struct hammer2_io hammer2_io_t; 293 294 #define HAMMER2_DIO_INPROG 0x8000000000000000LLU /* bio in progress */ 295 #define HAMMER2_DIO_GOOD 0x4000000000000000LLU /* dio->bp is stable */ 296 #define HAMMER2_DIO_WAITING 0x2000000000000000LLU /* wait on INPROG */ 297 #define HAMMER2_DIO_DIRTY 0x1000000000000000LLU /* flush last drop */ 298 #define HAMMER2_DIO_FLUSH 0x0800000000000000LLU /* immediate flush */ 299 300 #define HAMMER2_DIO_MASK 0x00FFFFFFFFFFFFFFLLU 301 302 /* 303 * Primary chain structure keeps track of the topology in-memory. 304 */ 305 struct hammer2_chain { 306 hammer2_mtx_t lock; 307 hammer2_chain_core_t core; 308 RB_ENTRY(hammer2_chain) rbnode; /* live chain(s) */ 309 hammer2_blockref_t bref; 310 struct hammer2_chain *parent; 311 struct hammer2_dev *hmp; 312 struct hammer2_pfs *pmp; /* A PFS or super-root (spmp) */ 313 314 struct lock diolk; /* xop focus interlock */ 315 hammer2_io_t *dio; /* physical data buffer */ 316 hammer2_media_data_t *data; /* data pointer shortcut */ 317 u_int bytes; /* physical data size */ 318 u_int flags; 319 u_int refs; 320 u_int lockcnt; 321 int error; /* on-lock data error state */ 322 int cache_index; /* heur speeds up lookup */ 323 324 TAILQ_ENTRY(hammer2_chain) lru_node; /* 0-refs LRU */ 325 }; 326 327 typedef struct hammer2_chain hammer2_chain_t; 328 329 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2); 330 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp); 331 332 /* 333 * Special notes on flags: 334 * 335 * INITIAL - This flag allows a chain to be created and for storage to 336 * be allocated without having to immediately instantiate the 337 * related buffer. The data is assumed to be all-zeros. It 338 * is primarily used for indirect blocks. 339 * 340 * MODIFIED - The chain's media data has been modified. Prevents chain 341 * free on lastdrop if still in the topology. 342 * 343 * UPDATE - Chain might not be modified but parent blocktable needs 344 * an update. Prevents chain free on lastdrop if still in 345 * the topology. 346 * 347 * BLKMAPPED - Indicates that the chain is present in the parent blockmap. 348 * 349 * BLKMAPUPD - Indicates that the chain is present but needs to be updated 350 * in the parent blockmap. 351 */ 352 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */ 353 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */ 354 #define HAMMER2_CHAIN_DESTROY 0x00000004 355 #define HAMMER2_CHAIN_DEDUPABLE 0x00000008 /* registered w/dedup */ 356 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */ 357 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */ 358 #define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */ 359 #define HAMMER2_CHAIN_NOTTESTED 0x00000080 /* crc not generated */ 360 #define HAMMER2_CHAIN_TESTEDGOOD 0x00000100 /* crc tested good */ 361 #define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */ 362 #define HAMMER2_CHAIN_UNUSED0400 0x00000400 363 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */ 364 #define HAMMER2_CHAIN_UNUSED1000 0x00001000 365 #define HAMMER2_CHAIN_COUNTEDBREFS 0x00002000 /* block table stats */ 366 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */ 367 #define HAMMER2_CHAIN_ONLRU 0x00008000 /* on LRU list */ 368 #define HAMMER2_CHAIN_UNUSED10000 0x00010000 369 #define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */ 370 #define HAMMER2_CHAIN_BLKMAPPED 0x00040000 /* present in blkmap */ 371 #define HAMMER2_CHAIN_BLKMAPUPD 0x00080000 /* +needs updating */ 372 #define HAMMER2_CHAIN_IOINPROG 0x00100000 /* I/O interlock */ 373 #define HAMMER2_CHAIN_IOSIGNAL 0x00200000 /* I/O interlock */ 374 #define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */ 375 #define HAMMER2_CHAIN_HINT_LEAF_COUNT 0x00800000 /* redo leaf count */ 376 #define HAMMER2_CHAIN_LRUHINT 0x01000000 /* was reused */ 377 378 #define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \ 379 HAMMER2_CHAIN_UPDATE | \ 380 HAMMER2_CHAIN_ONFLUSH | \ 381 HAMMER2_CHAIN_DESTROY) 382 383 /* 384 * Hammer2 error codes, used by chain->error and cluster->error. The error 385 * code is typically set on-lock unless no I/O was requested, and set on 386 * I/O otherwise. If set for a cluster it generally means that the cluster 387 * code could not find a valid copy to present. 388 * 389 * All H2 error codes are flags and can be accumulated by ORing them 390 * together. 391 * 392 * IO - An I/O error occurred 393 * CHECK - I/O succeeded but did not match the check code 394 * INCOMPLETE - A cluster is not complete enough to use, or 395 * a chain cannot be loaded because its parent has an error. 396 * 397 * NOTE: API allows callers to check zero/non-zero to determine if an error 398 * condition exists. 399 * 400 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily 401 * NULL on other errors. Check chain->error, not chain->data. 402 */ 403 #define HAMMER2_ERROR_NONE 0 /* no error (must be 0) */ 404 #define HAMMER2_ERROR_EIO 0x00000001 /* device I/O error */ 405 #define HAMMER2_ERROR_CHECK 0x00000002 /* check code error */ 406 #define HAMMER2_ERROR_INCOMPLETE 0x00000004 /* incomplete cluster */ 407 #define HAMMER2_ERROR_DEPTH 0x00000008 /* tmp depth limit */ 408 #define HAMMER2_ERROR_BADBREF 0x00000010 /* illegal bref */ 409 #define HAMMER2_ERROR_ENOSPC 0x00000020 /* allocation failure */ 410 #define HAMMER2_ERROR_ENOENT 0x00000040 /* entry not found */ 411 #define HAMMER2_ERROR_ENOTEMPTY 0x00000080 /* dir not empty */ 412 #define HAMMER2_ERROR_EAGAIN 0x00000100 /* retry */ 413 #define HAMMER2_ERROR_ENOTDIR 0x00000200 /* not directory */ 414 #define HAMMER2_ERROR_EISDIR 0x00000400 /* is directory */ 415 #define HAMMER2_ERROR_EINPROGRESS 0x00000800 /* already running */ 416 #define HAMMER2_ERROR_ABORTED 0x00001000 /* aborted operation */ 417 #define HAMMER2_ERROR_EOF 0x00002000 /* end of scan */ 418 #define HAMMER2_ERROR_EINVAL 0x00004000 /* catch-all */ 419 #define HAMMER2_ERROR_EEXIST 0x00008000 /* entry exists */ 420 #define HAMMER2_ERROR_EDEADLK 0x00010000 421 #define HAMMER2_ERROR_ESRCH 0x00020000 422 #define HAMMER2_ERROR_ETIMEDOUT 0x00040000 423 424 /* 425 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next() 426 * 427 * NOTES: 428 * NODATA - Asks that the chain->data not be resolved in order 429 * to avoid I/O. 430 * 431 * NODIRECT - Prevents a lookup of offset 0 in an inode from returning 432 * the inode itself if the inode is in DIRECTDATA mode 433 * (i.e. file is <= 512 bytes). Used by the synchronization 434 * code to prevent confusion. 435 * 436 * SHARED - The input chain is expected to be locked shared, 437 * and the output chain is locked shared. 438 * 439 * MATCHIND - Allows an indirect block / freemap node to be returned 440 * when the passed key range matches the radix. Remember 441 * that key_end is inclusive (e.g. {0x000,0xFFF}, 442 * not {0x000,0x1000}). 443 * 444 * (Cannot be used for remote or cluster ops). 445 * 446 * ALWAYS - Always resolve the data. If ALWAYS and NODATA are both 447 * missing, bulk file data is not resolved but inodes and 448 * other meta-data will. 449 */ 450 #define HAMMER2_LOOKUP_UNUSED0001 0x00000001 451 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */ 452 #define HAMMER2_LOOKUP_NODIRECT 0x00000004 /* no offset=0 DD */ 453 #define HAMMER2_LOOKUP_SHARED 0x00000100 454 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */ 455 #define HAMMER2_LOOKUP_UNUSED0400 0x00000400 456 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */ 457 #define HAMMER2_LOOKUP_UNUSED1000 0x00001000 458 459 /* 460 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize() 461 * 462 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT 463 * blocks in the INITIAL-create state. 464 */ 465 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */ 466 467 /* 468 * Flags passed to hammer2_chain_lock() 469 * 470 * NOTE: RDONLY is set to optimize cluster operations when *no* modifications 471 * will be made to either the cluster being locked or any underlying 472 * cluster. It allows the cluster to lock and access data for a subset 473 * of available nodes instead of all available nodes. 474 * 475 * NOTE: NONBLOCK is only used for hammer2_chain_repparent() and getparent(), 476 * other functions (e.g. hammer2_chain_lookup(), etc) can't handle its 477 * operation. 478 */ 479 #define HAMMER2_RESOLVE_NEVER 1 480 #define HAMMER2_RESOLVE_MAYBE 2 481 #define HAMMER2_RESOLVE_ALWAYS 3 482 #define HAMMER2_RESOLVE_MASK 0x0F 483 484 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */ 485 #define HAMMER2_RESOLVE_LOCKAGAIN 0x20 /* another shared lock */ 486 #define HAMMER2_RESOLVE_UNUSED40 0x40 487 #define HAMMER2_RESOLVE_NONBLOCK 0x80 /* non-blocking */ 488 489 /* 490 * Flags passed to hammer2_chain_delete() 491 */ 492 #define HAMMER2_DELETE_PERMANENT 0x0001 493 494 /* 495 * Flags passed to hammer2_chain_insert() or hammer2_chain_rename() 496 * or hammer2_chain_create(). 497 */ 498 #define HAMMER2_INSERT_PFSROOT 0x0004 499 #define HAMMER2_INSERT_SAMEPARENT 0x0008 500 501 /* 502 * hammer2_freemap_adjust() 503 */ 504 #define HAMMER2_FREEMAP_DORECOVER 1 505 #if 0 506 #define HAMMER2_FREEMAP_DOMAYFREE 2 507 #define HAMMER2_FREEMAP_DOREALFREE 3 508 #endif 509 510 /* 511 * HAMMER2 cluster - A set of chains representing the same entity. 512 * 513 * hammer2_cluster typically represents a temporary set of representitive 514 * chains. The one exception is that a hammer2_cluster is embedded in 515 * hammer2_inode. This embedded cluster is ONLY used to track the 516 * representitive chains and cannot be directly locked. 517 * 518 * A cluster is usually temporary (and thus per-thread) for locking purposes, 519 * allowing us to embed the asynchronous storage required for cluster 520 * operations in the cluster itself and adjust the state and status without 521 * having to worry too much about SMP issues. 522 * 523 * The exception is the cluster embedded in the hammer2_inode structure. 524 * This is used to cache the cluster state on an inode-by-inode basis. 525 * Individual hammer2_chain structures not incorporated into clusters might 526 * also stick around to cache miscellanious elements. 527 * 528 * Because the cluster is a 'working copy' and is usually subject to cluster 529 * quorum rules, it is quite possible for us to end up with an insufficient 530 * number of live chains to execute an operation. If an insufficient number 531 * of chains remain in a working copy, the operation may have to be 532 * downgraded, retried, stall until the requisit number of chains are 533 * available, or possibly even error out depending on the mount type. 534 * 535 * A cluster's focus is set when it is locked. The focus can only be set 536 * to a chain still part of the synchronized set. 537 */ 538 #define HAMMER2_XOPFIFO 16 539 #define HAMMER2_XOPFIFO_MASK (HAMMER2_XOPFIFO - 1) 540 #define HAMMER2_XOPTHREADS_MIN 32 541 #define HAMMER2_XOPGROUPS_MIN 4 542 543 #define HAMMER2_MAXCLUSTER 8 544 #define HAMMER2_XOPMASK_CLUSTER ((uint64_t)((1LLU << HAMMER2_MAXCLUSTER) - 1)) 545 #define HAMMER2_XOPMASK_VOP ((uint64_t)0x0000000080000000LLU) 546 #define HAMMER2_XOPMASK_FIFOW ((uint64_t)0x0000000040000000LLU) 547 #define HAMMER2_XOPMASK_WAIT ((uint64_t)0x0000000020000000LLU) 548 #define HAMMER2_XOPMASK_FEED ((uint64_t)0x0000000100000000LLU) 549 550 #define HAMMER2_XOPMASK_ALLDONE (HAMMER2_XOPMASK_VOP | HAMMER2_XOPMASK_CLUSTER) 551 552 struct hammer2_cluster_item { 553 hammer2_chain_t *chain; 554 int error; 555 uint32_t flags; 556 }; 557 558 typedef struct hammer2_cluster_item hammer2_cluster_item_t; 559 560 /* 561 * INVALID - Invalid for focus, i.e. not part of synchronized set. 562 * Once set, this bit is sticky across operations. 563 * 564 * FEMOD - Indicates that front-end modifying operations can 565 * mess with this entry and MODSYNC will copy also 566 * effect it. 567 */ 568 #define HAMMER2_CITEM_INVALID 0x00000001 569 #define HAMMER2_CITEM_FEMOD 0x00000002 570 #define HAMMER2_CITEM_NULL 0x00000004 571 572 struct hammer2_cluster { 573 int refs; /* track for deallocation */ 574 int ddflag; 575 struct hammer2_pfs *pmp; 576 uint32_t flags; 577 int nchains; 578 int error; /* error code valid on lock */ 579 int focus_index; 580 hammer2_chain_t *focus; /* current focus (or mod) */ 581 hammer2_cluster_item_t array[HAMMER2_MAXCLUSTER]; 582 }; 583 584 typedef struct hammer2_cluster hammer2_cluster_t; 585 586 /* 587 * WRHARD - Hard mounts can write fully synchronized 588 * RDHARD - Hard mounts can read fully synchronized 589 * UNHARD - Unsynchronized masters present 590 * NOHARD - No masters visible 591 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER 592 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE 593 * UNSOFT - Unsynchronized slaves present 594 * NOSOFT - No slaves visible 595 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote). 596 * MSYNCED - All masters are fully synchronized 597 * SSYNCED - All known local slaves are fully synchronized to masters 598 * 599 * All available masters are always incorporated. All PFSs belonging to a 600 * cluster (master, slave, copy, whatever) always try to synchronize the 601 * total number of known masters in the PFSs root inode. 602 * 603 * A cluster might have access to many slaves, copies, or caches, but we 604 * have a limited number of cluster slots. Any such elements which are 605 * directly mounted from block device(s) will always be incorporated. Note 606 * that SSYNCED only applies to such elements which are directly mounted, 607 * not to any remote slaves, copies, or caches that could be available. These 608 * bits are used to monitor and drive our synchronization threads. 609 * 610 * When asking the question 'is any data accessible at all', then a simple 611 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of 612 * these bits are set the object can be read with certain caveats: 613 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized. 614 * and RDSLAVE - not authoritative, has some data but it could be old or 615 * incomplete. 616 * 617 * When both soft and hard mounts are available, data will be read and written 618 * via the soft mount only. But all might be in the cluster because 619 * background synchronization threads still need to do their work. 620 */ 621 #define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode struct */ 622 #define HAMMER2_CLUSTER_UNUSED2 0x00000002 623 #define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */ 624 #define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */ 625 #define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */ 626 #define HAMMER2_CLUSTER_UNHARD 0x00000400 /* unsynchronized masters */ 627 #define HAMMER2_CLUSTER_NOHARD 0x00000800 /* no masters visible */ 628 #define HAMMER2_CLUSTER_WRSOFT 0x00001000 /* soft-mount can write */ 629 #define HAMMER2_CLUSTER_RDSOFT 0x00002000 /* soft-mount can read */ 630 #define HAMMER2_CLUSTER_UNSOFT 0x00004000 /* unsynchronized slaves */ 631 #define HAMMER2_CLUSTER_NOSOFT 0x00008000 /* no slaves visible */ 632 #define HAMMER2_CLUSTER_MSYNCED 0x00010000 /* all masters synchronized */ 633 #define HAMMER2_CLUSTER_SSYNCED 0x00020000 /* known slaves synchronized */ 634 635 #define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \ 636 HAMMER2_CLUSTER_RDSOFT | \ 637 HAMMER2_CLUSTER_RDSLAVE) 638 #if 0 639 #define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \ 640 HAMMER2_CLUSTER_RDSOFT) 641 642 #define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \ 643 HAMMER2_CLUSTER_WRSOFT) 644 #endif 645 #define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \ 646 HAMMER2_CLUSTER_RDHARD | \ 647 HAMMER2_CLUSTER_WRSOFT | \ 648 HAMMER2_CLUSTER_RDSOFT | \ 649 HAMMER2_CLUSTER_MSYNCED | \ 650 HAMMER2_CLUSTER_SSYNCED) 651 652 RB_HEAD(hammer2_inode_tree, hammer2_inode); /* ip->rbnode */ 653 TAILQ_HEAD(inoq_head, hammer2_inode); /* ip->entry */ 654 TAILQ_HEAD(depq_head, hammer2_depend); /* depend->entry */ 655 656 struct hammer2_depend { 657 TAILQ_ENTRY(hammer2_depend) entry; 658 struct inoq_head sideq; 659 long count; 660 int pass2; 661 int unused01; 662 }; 663 664 typedef struct hammer2_depend hammer2_depend_t; 665 666 /* 667 * A hammer2 inode. 668 * 669 * NOTE: The inode-embedded cluster is never used directly for I/O (since 670 * it may be shared). Instead it will be replicated-in and synchronized 671 * back out if changed. 672 */ 673 struct hammer2_inode { 674 RB_ENTRY(hammer2_inode) rbnode; /* inumber lookup (HL) */ 675 TAILQ_ENTRY(hammer2_inode) entry; /* SYNCQ/SIDEQ */ 676 hammer2_depend_t *depend; /* non-NULL if SIDEQ */ 677 hammer2_depend_t depend_static; /* (in-place allocation) */ 678 hammer2_mtx_t lock; /* inode lock */ 679 hammer2_mtx_t truncate_lock; /* prevent truncates */ 680 struct hammer2_pfs *pmp; /* PFS mount */ 681 struct vnode *vp; 682 hammer2_spin_t cluster_spin; /* update cluster */ 683 hammer2_cluster_t cluster; 684 struct lockf advlock; 685 u_int flags; 686 u_int refs; /* +vpref, +flushref */ 687 int ihash; /* xop worker distribution */ 688 uint8_t comp_heuristic; 689 hammer2_inode_meta_t meta; /* copy of meta-data */ 690 hammer2_off_t osize; 691 }; 692 693 typedef struct hammer2_inode hammer2_inode_t; 694 695 /* 696 * MODIFIED - Inode is in a modified state, ip->meta may have changes. 697 * RESIZED - Inode truncated (any) or inode extended beyond 698 * EMBEDDED_BYTES. 699 * 700 * SYNCQ - Inode is included in the current filesystem sync. The 701 * DELETING and CREATING flags will be acted upon. 702 * 703 * SIDEQ - Inode has likely been disconnected from the vnode topology 704 * and so is not visible to the vnode-based filesystem syncer 705 * code, but is dirty and must be included in the next 706 * filesystem sync. These inodes are moved to the SYNCQ at 707 * the time the sync occurs. 708 * 709 * Inodes are not placed on this queue simply because they have 710 * become dirty, if a vnode is attached. 711 * 712 * DELETING - Inode is flagged for deletion during the next filesystem 713 * sync. That is, the inode's chain is currently connected 714 * and must be deleting during the current or next fs sync. 715 * 716 * CREATING - Inode is flagged for creation during the next filesystem 717 * sync. That is, the inode's chain topology exists (so 718 * kernel buffer flushes can occur), but is currently 719 * disconnected and must be inserted during the current or 720 * next fs sync. If the DELETING flag is also set, the 721 * topology can be thrown away instead. 722 * 723 * If an inode that is already part of the current filesystem sync is 724 * modified by the frontend, including by buffer flushes, the inode lock 725 * code detects the SYNCQ flag and moves the inode to the head of the 726 * flush-in-progress, then blocks until the flush has gotten past it. 727 */ 728 #define HAMMER2_INODE_MODIFIED 0x0001 729 #define HAMMER2_INODE_UNUSED0002 0x0002 730 #define HAMMER2_INODE_UNUSED0004 0x0004 731 #define HAMMER2_INODE_ONRBTREE 0x0008 732 #define HAMMER2_INODE_RESIZED 0x0010 /* requires inode_chain_sync */ 733 #define HAMMER2_INODE_UNUSED0020 0x0020 734 #define HAMMER2_INODE_ISUNLINKED 0x0040 735 #define HAMMER2_INODE_UNUSED0080 0x0080 736 #define HAMMER2_INODE_SIDEQ 0x0100 /* on side processing queue */ 737 #define HAMMER2_INODE_NOSIDEQ 0x0200 /* disable sideq operation */ 738 #define HAMMER2_INODE_DIRTYDATA 0x0400 /* interlocks inode flush */ 739 #define HAMMER2_INODE_SYNCQ 0x0800 /* sync interlock, sequenced */ 740 #define HAMMER2_INODE_DELETING 0x1000 /* sync interlock, chain topo */ 741 #define HAMMER2_INODE_CREATING 0x2000 /* sync interlock, chain topo */ 742 #define HAMMER2_INODE_SYNCQ_WAKEUP 0x4000 /* sync interlock wakeup */ 743 #define HAMMER2_INODE_SYNCQ_PASS2 0x8000 /* force retry delay */ 744 745 #define HAMMER2_INODE_DIRTY (HAMMER2_INODE_MODIFIED | \ 746 HAMMER2_INODE_DIRTYDATA | \ 747 HAMMER2_INODE_DELETING | \ 748 HAMMER2_INODE_CREATING) 749 750 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2); 751 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp, 752 hammer2_tid_t); 753 754 /* 755 * Transaction management sub-structure under hammer2_pfs 756 */ 757 struct hammer2_trans { 758 uint32_t flags; 759 uint32_t sync_wait; 760 }; 761 762 typedef struct hammer2_trans hammer2_trans_t; 763 764 #define HAMMER2_TRANS_ISFLUSH 0x80000000 /* flush code */ 765 #define HAMMER2_TRANS_BUFCACHE 0x40000000 /* bio strategy */ 766 #define HAMMER2_TRANS_SIDEQ 0x20000000 /* run sideq */ 767 #define HAMMER2_TRANS_UNUSED10 0x10000000 768 #define HAMMER2_TRANS_WAITING 0x08000000 /* someone waiting */ 769 #define HAMMER2_TRANS_RESCAN 0x04000000 /* rescan sideq */ 770 #define HAMMER2_TRANS_MASK 0x00FFFFFF /* count mask */ 771 772 #define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-LBUFRADIX */ 773 #define HAMMER2_FREEMAP_HEUR_TYPES 8 774 #define HAMMER2_FREEMAP_HEUR_SIZE (HAMMER2_FREEMAP_HEUR_NRADIX * \ 775 HAMMER2_FREEMAP_HEUR_TYPES) 776 777 #define HAMMER2_DEDUP_HEUR_SIZE (65536 * 4) 778 #define HAMMER2_DEDUP_HEUR_MASK (HAMMER2_DEDUP_HEUR_SIZE - 1) 779 780 #define HAMMER2_FLUSH_TOP 0x0001 781 #define HAMMER2_FLUSH_ALL 0x0002 782 #define HAMMER2_FLUSH_INODE_STOP 0x0004 /* stop at sub-inode */ 783 #define HAMMER2_FLUSH_FSSYNC 0x0008 /* part of filesystem sync */ 784 785 786 /* 787 * Hammer2 support thread element. 788 * 789 * Potentially many support threads can hang off of hammer2, primarily 790 * off the hammer2_pfs structure. Typically: 791 * 792 * td x Nodes A synchronization thread for each node. 793 * td x Nodes x workers Worker threads for frontend operations. 794 * td x 1 Bioq thread for logical buffer writes. 795 * 796 * In addition, the synchronization thread(s) associated with the 797 * super-root PFS (spmp) for a node is responsible for automatic bulkfree 798 * and dedup scans. 799 */ 800 struct hammer2_thread { 801 struct hammer2_pfs *pmp; 802 struct hammer2_dev *hmp; 803 hammer2_xop_list_t xopq; 804 thread_t td; 805 uint32_t flags; 806 int clindex; /* cluster element index */ 807 int repidx; 808 char *scratch; /* MAXPHYS */ 809 }; 810 811 typedef struct hammer2_thread hammer2_thread_t; 812 813 #define HAMMER2_THREAD_UNMOUNTING 0x0001 /* unmount request */ 814 #define HAMMER2_THREAD_DEV 0x0002 /* related to dev, not pfs */ 815 #define HAMMER2_THREAD_WAITING 0x0004 /* thread in idle tsleep */ 816 #define HAMMER2_THREAD_REMASTER 0x0008 /* remaster request */ 817 #define HAMMER2_THREAD_STOP 0x0010 /* exit request */ 818 #define HAMMER2_THREAD_FREEZE 0x0020 /* force idle */ 819 #define HAMMER2_THREAD_FROZEN 0x0040 /* thread is frozen */ 820 #define HAMMER2_THREAD_XOPQ 0x0080 /* work pending */ 821 #define HAMMER2_THREAD_STOPPED 0x0100 /* thread has stopped */ 822 #define HAMMER2_THREAD_UNFREEZE 0x0200 823 824 #define HAMMER2_THREAD_WAKEUP_MASK (HAMMER2_THREAD_UNMOUNTING | \ 825 HAMMER2_THREAD_REMASTER | \ 826 HAMMER2_THREAD_STOP | \ 827 HAMMER2_THREAD_FREEZE | \ 828 HAMMER2_THREAD_XOPQ) 829 830 /* 831 * Support structure for dedup heuristic. 832 */ 833 struct hammer2_dedup { 834 hammer2_off_t data_off; 835 uint64_t data_crc; 836 uint32_t ticks; 837 uint32_t saved_error; 838 }; 839 840 typedef struct hammer2_dedup hammer2_dedup_t; 841 842 /* 843 * hammer2_xop - container for VOP/XOP operation (allocated, not on stack). 844 * 845 * This structure is used to distribute a VOP operation across multiple 846 * nodes. It provides a rendezvous for concurrent node execution and 847 * can be detached from the frontend operation to allow the frontend to 848 * return early. 849 * 850 * This structure also sequences operations on up to three inodes. 851 */ 852 typedef void (*hammer2_xop_func_t)(union hammer2_xop *xop, void *scratch, 853 int clindex); 854 855 struct hammer2_xop_desc { 856 hammer2_xop_func_t storage_func; /* local storage function */ 857 hammer2_xop_func_t dmsg_dispatch; /* dmsg dispatch function */ 858 hammer2_xop_func_t dmsg_process; /* dmsg processing function */ 859 const char *id; 860 }; 861 862 typedef struct hammer2_xop_desc hammer2_xop_desc_t; 863 864 struct hammer2_xop_fifo { 865 TAILQ_ENTRY(hammer2_xop_head) entry; 866 hammer2_chain_t *array[HAMMER2_XOPFIFO]; 867 int errors[HAMMER2_XOPFIFO]; 868 int ri; 869 int wi; 870 int flags; 871 hammer2_thread_t *thr; 872 }; 873 874 typedef struct hammer2_xop_fifo hammer2_xop_fifo_t; 875 876 #define HAMMER2_XOP_FIFO_RUN 0x0001 877 #define HAMMER2_XOP_FIFO_STALL 0x0002 878 879 struct hammer2_xop_head { 880 hammer2_xop_desc_t *desc; 881 hammer2_tid_t mtid; 882 struct hammer2_inode *ip1; 883 struct hammer2_inode *ip2; 884 struct hammer2_inode *ip3; 885 struct hammer2_inode *ip4; 886 uint64_t run_mask; 887 uint64_t chk_mask; 888 int flags; 889 int state; 890 int error; 891 hammer2_key_t collect_key; 892 char *name1; 893 size_t name1_len; 894 char *name2; 895 size_t name2_len; 896 hammer2_xop_fifo_t collect[HAMMER2_MAXCLUSTER]; 897 hammer2_cluster_t cluster; /* help collections */ 898 hammer2_io_t *focus_dio; 899 }; 900 901 typedef struct hammer2_xop_head hammer2_xop_head_t; 902 903 struct hammer2_xop_ipcluster { 904 hammer2_xop_head_t head; 905 }; 906 907 struct hammer2_xop_strategy { 908 hammer2_xop_head_t head; 909 hammer2_key_t lbase; 910 int finished; 911 hammer2_mtx_t lock; 912 struct bio *bio; 913 }; 914 915 struct hammer2_xop_readdir { 916 hammer2_xop_head_t head; 917 hammer2_key_t lkey; 918 }; 919 920 struct hammer2_xop_nresolve { 921 hammer2_xop_head_t head; 922 hammer2_key_t lhc; /* if name is NULL used lhc */ 923 }; 924 925 struct hammer2_xop_unlink { 926 hammer2_xop_head_t head; 927 int isdir; 928 int dopermanent; 929 }; 930 931 #define H2DOPERM_PERMANENT 0x01 932 #define H2DOPERM_FORCE 0x02 933 #define H2DOPERM_IGNINO 0x04 934 935 struct hammer2_xop_nrename { 936 hammer2_xop_head_t head; 937 hammer2_tid_t lhc; 938 int ip_key; 939 }; 940 941 struct hammer2_xop_scanlhc { 942 hammer2_xop_head_t head; 943 hammer2_key_t lhc; 944 }; 945 946 struct hammer2_xop_scanall { 947 hammer2_xop_head_t head; 948 hammer2_key_t key_beg; /* inclusive */ 949 hammer2_key_t key_end; /* inclusive */ 950 int resolve_flags; 951 int lookup_flags; 952 }; 953 954 struct hammer2_xop_lookup { 955 hammer2_xop_head_t head; 956 hammer2_key_t lhc; 957 }; 958 959 struct hammer2_xop_mkdirent { 960 hammer2_xop_head_t head; 961 hammer2_dirent_head_t dirent; 962 hammer2_key_t lhc; 963 }; 964 965 struct hammer2_xop_create { 966 hammer2_xop_head_t head; 967 hammer2_inode_meta_t meta; /* initial metadata */ 968 hammer2_key_t lhc; 969 int flags; 970 }; 971 972 struct hammer2_xop_destroy { 973 hammer2_xop_head_t head; 974 }; 975 976 struct hammer2_xop_fsync { 977 hammer2_xop_head_t head; 978 hammer2_inode_meta_t meta; 979 hammer2_off_t osize; 980 u_int ipflags; 981 int clear_directdata; 982 }; 983 984 struct hammer2_xop_unlinkall { 985 hammer2_xop_head_t head; 986 hammer2_key_t key_beg; 987 hammer2_key_t key_end; 988 }; 989 990 struct hammer2_xop_connect { 991 hammer2_xop_head_t head; 992 hammer2_key_t lhc; 993 }; 994 995 struct hammer2_xop_flush { 996 hammer2_xop_head_t head; 997 }; 998 999 typedef struct hammer2_xop_readdir hammer2_xop_readdir_t; 1000 typedef struct hammer2_xop_nresolve hammer2_xop_nresolve_t; 1001 typedef struct hammer2_xop_unlink hammer2_xop_unlink_t; 1002 typedef struct hammer2_xop_nrename hammer2_xop_nrename_t; 1003 typedef struct hammer2_xop_ipcluster hammer2_xop_ipcluster_t; 1004 typedef struct hammer2_xop_strategy hammer2_xop_strategy_t; 1005 typedef struct hammer2_xop_mkdirent hammer2_xop_mkdirent_t; 1006 typedef struct hammer2_xop_create hammer2_xop_create_t; 1007 typedef struct hammer2_xop_destroy hammer2_xop_destroy_t; 1008 typedef struct hammer2_xop_fsync hammer2_xop_fsync_t; 1009 typedef struct hammer2_xop_unlinkall hammer2_xop_unlinkall_t; 1010 typedef struct hammer2_xop_scanlhc hammer2_xop_scanlhc_t; 1011 typedef struct hammer2_xop_scanall hammer2_xop_scanall_t; 1012 typedef struct hammer2_xop_lookup hammer2_xop_lookup_t; 1013 typedef struct hammer2_xop_connect hammer2_xop_connect_t; 1014 typedef struct hammer2_xop_flush hammer2_xop_flush_t; 1015 1016 union hammer2_xop { 1017 hammer2_xop_head_t head; 1018 hammer2_xop_ipcluster_t xop_ipcluster; 1019 hammer2_xop_readdir_t xop_readdir; 1020 hammer2_xop_nresolve_t xop_nresolve; 1021 hammer2_xop_unlink_t xop_unlink; 1022 hammer2_xop_nrename_t xop_nrename; 1023 hammer2_xop_strategy_t xop_strategy; 1024 hammer2_xop_mkdirent_t xop_mkdirent; 1025 hammer2_xop_create_t xop_create; 1026 hammer2_xop_destroy_t xop_destroy; 1027 hammer2_xop_fsync_t xop_fsync; 1028 hammer2_xop_unlinkall_t xop_unlinkall; 1029 hammer2_xop_scanlhc_t xop_scanlhc; 1030 hammer2_xop_scanall_t xop_scanall; 1031 hammer2_xop_lookup_t xop_lookup; 1032 hammer2_xop_flush_t xop_flush; 1033 hammer2_xop_connect_t xop_connect; 1034 }; 1035 1036 typedef union hammer2_xop hammer2_xop_t; 1037 1038 /* 1039 * hammer2_xop_group - Manage XOP support threads. 1040 */ 1041 struct hammer2_xop_group { 1042 hammer2_thread_t thrs[HAMMER2_MAXCLUSTER]; 1043 }; 1044 1045 typedef struct hammer2_xop_group hammer2_xop_group_t; 1046 1047 /* 1048 * flags to hammer2_xop_collect() 1049 */ 1050 #define HAMMER2_XOP_COLLECT_NOWAIT 0x00000001 1051 #define HAMMER2_XOP_COLLECT_WAITALL 0x00000002 1052 1053 /* 1054 * flags to hammer2_xop_alloc() 1055 * 1056 * MODIFYING - This is a modifying transaction, allocate a mtid. 1057 */ 1058 #define HAMMER2_XOP_MODIFYING 0x00000001 1059 #define HAMMER2_XOP_STRATEGY 0x00000002 1060 #define HAMMER2_XOP_INODE_STOP 0x00000004 1061 #define HAMMER2_XOP_VOLHDR 0x00000008 1062 #define HAMMER2_XOP_FSSYNC 0x00000010 1063 1064 /* 1065 * Device vnode management structure 1066 */ 1067 struct hammer2_devvp { 1068 TAILQ_ENTRY(hammer2_devvp) entry; 1069 struct vnode *devvp; /* device vnode */ 1070 char *path; /* device vnode path */ 1071 int open; /* 1 if devvp open */ 1072 }; 1073 1074 typedef struct hammer2_devvp hammer2_devvp_t; 1075 1076 TAILQ_HEAD(hammer2_devvp_list, hammer2_devvp); 1077 1078 typedef struct hammer2_devvp_list hammer2_devvp_list_t; 1079 1080 /* 1081 * Volume management structure 1082 */ 1083 struct hammer2_volume { 1084 hammer2_devvp_t *dev; /* device vnode management */ 1085 int id; /* volume id */ 1086 hammer2_off_t offset; /* offset within volumes */ 1087 hammer2_off_t size; /* volume size */ 1088 }; 1089 1090 typedef struct hammer2_volume hammer2_volume_t; 1091 1092 /* 1093 * Global (per partition) management structure, represents a hard block 1094 * device. Typically referenced by hammer2_chain structures when applicable. 1095 * Typically not used for network-managed elements. 1096 * 1097 * Note that a single hammer2_dev can be indirectly tied to multiple system 1098 * mount points. There is no direct relationship. System mounts are 1099 * per-cluster-id, not per-block-device, and a single hard mount might contain 1100 * many PFSs and those PFSs might combine together in various ways to form 1101 * the set of available clusters. 1102 */ 1103 struct hammer2_dev { 1104 struct vnode *devvp; /* device vnode for root volume */ 1105 int ronly; /* read-only mount */ 1106 int mount_count; /* number of actively mounted PFSs */ 1107 TAILQ_ENTRY(hammer2_dev) mntentry; /* hammer2_mntlist */ 1108 1109 struct malloc_type *mchain_obj; 1110 struct malloc_type *mio_obj; 1111 struct malloc_type *mmsg; 1112 kdmsg_iocom_t iocom; /* volume-level dmsg interface */ 1113 hammer2_spin_t io_spin; /* iotree, iolruq access */ 1114 struct hammer2_io_tree iotree; 1115 int iofree_count; 1116 int freemap_relaxed; 1117 hammer2_chain_t vchain; /* anchor chain (topology) */ 1118 hammer2_chain_t fchain; /* anchor chain (freemap) */ 1119 hammer2_spin_t list_spin; 1120 struct hammer2_pfs *spmp; /* super-root pmp for transactions */ 1121 struct lock vollk; /* lockmgr lock */ 1122 struct lock bulklk; /* bulkfree operation lock */ 1123 struct lock bflock; /* bulk-free manual function lock */ 1124 hammer2_off_t heur_freemap[HAMMER2_FREEMAP_HEUR_SIZE]; 1125 hammer2_dedup_t heur_dedup[HAMMER2_DEDUP_HEUR_SIZE]; 1126 int volhdrno; /* last volhdrno written */ 1127 uint32_t hflags; /* HMNT2 flags applicable to device */ 1128 hammer2_off_t free_reserved; /* nominal free reserved */ 1129 hammer2_off_t total_size; /* total size of volumes */ 1130 int nvolumes; /* total number of volumes */ 1131 hammer2_thread_t bfthr; /* bulk-free thread */ 1132 char devrepname[64]; /* for kprintf */ 1133 hammer2_volume_data_t voldata; 1134 hammer2_volume_data_t volsync; /* synchronized voldata */ 1135 1136 hammer2_devvp_list_t devvpl; /* list of device vnodes including *devvp */ 1137 hammer2_volume_t volumes[HAMMER2_MAX_VOLUMES]; /* list of volumes */ 1138 }; 1139 1140 typedef struct hammer2_dev hammer2_dev_t; 1141 1142 /* 1143 * Per-cluster management structure. This structure will be tied to a 1144 * system mount point if the system is mounting the PFS, but is also used 1145 * to manage clusters encountered during the super-root scan or received 1146 * via LNK_SPANs that might not be mounted. 1147 * 1148 * This structure is also used to represent the super-root that hangs off 1149 * of a hard mount point. The super-root is not really a cluster element. 1150 * In this case the spmp_hmp field will be non-NULL. It's just easier to do 1151 * this than to special case super-root manipulation in the hammer2_chain* 1152 * code as being only hammer2_dev-related. 1153 * 1154 * pfs_mode and pfs_nmasters are rollup fields which critically describes 1155 * how elements of the cluster act on the cluster. pfs_mode is only applicable 1156 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to 1157 * how many masters have been configured for a cluster and is always 1158 * applicable. pfs_types[] is an array with 1:1 correspondance to the 1159 * iroot cluster and describes the PFS types of the nodes making up the 1160 * cluster. 1161 * 1162 * WARNING! Portions of this structure have deferred initialization. In 1163 * particular, if not mounted there will be no wthread. 1164 * umounted network PFSs will also be missing iroot and numerous 1165 * other fields will not be initialized prior to mount. 1166 * 1167 * Synchronization threads are chain-specific and only applicable 1168 * to local hard PFS entries. A hammer2_pfs structure may contain 1169 * more than one when multiple hard PFSs are present on the local 1170 * machine which require synchronization monitoring. Most PFSs 1171 * (such as snapshots) are 1xMASTER PFSs which do not need a 1172 * synchronization thread. 1173 * 1174 * WARNING! The chains making up pfs->iroot's cluster are accounted for in 1175 * hammer2_dev->mount_count when the pfs is associated with a mount 1176 * point. 1177 */ 1178 struct hammer2_pfs { 1179 struct mount *mp; 1180 TAILQ_ENTRY(hammer2_pfs) mntentry; /* hammer2_pfslist */ 1181 uuid_t pfs_clid; 1182 hammer2_dev_t *spmp_hmp; /* only if super-root pmp */ 1183 hammer2_dev_t *force_local; /* only if 'local' mount */ 1184 hammer2_inode_t *iroot; /* PFS root inode */ 1185 uint8_t pfs_types[HAMMER2_MAXCLUSTER]; 1186 char *pfs_names[HAMMER2_MAXCLUSTER]; 1187 hammer2_dev_t *pfs_hmps[HAMMER2_MAXCLUSTER]; 1188 hammer2_blockset_t pfs_iroot_blocksets[HAMMER2_MAXCLUSTER]; 1189 hammer2_trans_t trans; 1190 struct lock lock; /* PFS lock for certain ops */ 1191 struct netexport export; /* nfs export */ 1192 int unused00; 1193 int ronly; /* read-only mount */ 1194 int hflags; /* pfs-specific mount flags */ 1195 struct malloc_type *minode_obj; 1196 hammer2_spin_t inum_spin; /* inumber lookup */ 1197 struct hammer2_inode_tree inum_tree; /* (not applicable to spmp) */ 1198 long inum_count; /* #of inodes in inum_tree */ 1199 hammer2_spin_t lru_spin; /* inumber lookup */ 1200 struct hammer2_chain_list lru_list; /* basis for LRU tests */ 1201 int lru_count; /* #of chains on LRU */ 1202 int flags; 1203 hammer2_tid_t modify_tid; /* modify transaction id */ 1204 hammer2_tid_t inode_tid; /* inode allocator */ 1205 uint8_t pfs_nmasters; /* total masters */ 1206 uint8_t pfs_mode; /* operating mode PFSMODE */ 1207 uint8_t unused01; 1208 uint8_t unused02; 1209 int free_ticks; /* free_* calculations */ 1210 long inmem_inodes; 1211 hammer2_off_t free_reserved; 1212 hammer2_off_t free_nominal; 1213 uint32_t inmem_dirty_chains; 1214 int count_lwinprog; /* logical write in prog */ 1215 hammer2_spin_t list_spin; 1216 struct inoq_head syncq; /* SYNCQ flagged inodes */ 1217 struct depq_head depq; /* SIDEQ flagged inodes */ 1218 long sideq_count; /* total inodes on depq */ 1219 hammer2_thread_t sync_thrs[HAMMER2_MAXCLUSTER]; 1220 uint32_t cluster_flags; /* cached cluster flags */ 1221 int has_xop_threads; 1222 hammer2_spin_t xop_spin; /* xop sequencer */ 1223 hammer2_xop_group_t *xop_groups; 1224 }; 1225 1226 typedef struct hammer2_pfs hammer2_pfs_t; 1227 1228 TAILQ_HEAD(hammer2_pfslist, hammer2_pfs); 1229 1230 /* 1231 * pmp->flags 1232 */ 1233 #define HAMMER2_PMPF_SPMP 0x00000001 1234 #define HAMMER2_PMPF_EMERG 0x00000002 /* Emergency delete mode */ 1235 1236 /* 1237 * NOTE: The LRU list contains at least all the chains with refs == 0 1238 * that can be recycled, and may contain additional chains which 1239 * cannot. 1240 */ 1241 #define HAMMER2_LRU_LIMIT 4096 1242 1243 #define HAMMER2_DIRTYCHAIN_WAITING 0x80000000 1244 #define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF 1245 1246 #define HAMMER2_LWINPROG_WAITING 0x80000000 1247 #define HAMMER2_LWINPROG_WAITING0 0x40000000 1248 #define HAMMER2_LWINPROG_MASK 0x3FFFFFFF 1249 1250 /* 1251 * hammer2_cluster_check 1252 */ 1253 #define HAMMER2_CHECK_NULL 0x00000001 1254 1255 /* 1256 * Misc 1257 */ 1258 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) 1259 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data) 1260 #endif 1261 1262 #if defined(_KERNEL) 1263 1264 #ifdef MALLOC_DECLARE 1265 MALLOC_DECLARE(M_HAMMER2); 1266 #endif 1267 1268 static __inline 1269 hammer2_pfs_t * 1270 MPTOPMP(struct mount *mp) 1271 { 1272 return ((hammer2_pfs_t *)mp->mnt_data); 1273 } 1274 1275 #define HAMMER2_DEDUP_FRAG (HAMMER2_PBUFSIZE / 64) 1276 #define HAMMER2_DEDUP_FRAGRADIX (HAMMER2_PBUFRADIX - 6) 1277 1278 static __inline 1279 uint64_t 1280 hammer2_dedup_mask(hammer2_io_t *dio, hammer2_off_t data_off, u_int bytes) 1281 { 1282 int bbeg; 1283 int bits; 1284 uint64_t mask; 1285 1286 bbeg = (int)((data_off & ~HAMMER2_OFF_MASK_RADIX) - dio->pbase) >> 1287 HAMMER2_DEDUP_FRAGRADIX; 1288 bits = (int)((bytes + (HAMMER2_DEDUP_FRAG - 1)) >> 1289 HAMMER2_DEDUP_FRAGRADIX); 1290 if (bbeg + bits == 64) 1291 mask = (uint64_t)-1; 1292 else 1293 mask = ((uint64_t)1 << (bbeg + bits)) - 1; 1294 1295 mask &= ~(((uint64_t)1 << bbeg) - 1); 1296 1297 return mask; 1298 } 1299 1300 static __inline 1301 int 1302 hammer2_error_to_errno(int error) 1303 { 1304 if (error) { 1305 if (error & HAMMER2_ERROR_EIO) 1306 error = EIO; 1307 else if (error & HAMMER2_ERROR_CHECK) 1308 error = EDOM; 1309 else if (error & HAMMER2_ERROR_ABORTED) 1310 error = EINTR; 1311 else if (error & HAMMER2_ERROR_BADBREF) 1312 error = EIO; 1313 else if (error & HAMMER2_ERROR_ENOSPC) 1314 error = ENOSPC; 1315 else if (error & HAMMER2_ERROR_ENOENT) 1316 error = ENOENT; 1317 else if (error & HAMMER2_ERROR_ENOTEMPTY) 1318 error = ENOTEMPTY; 1319 else if (error & HAMMER2_ERROR_EAGAIN) 1320 error = EAGAIN; 1321 else if (error & HAMMER2_ERROR_ENOTDIR) 1322 error = ENOTDIR; 1323 else if (error & HAMMER2_ERROR_EISDIR) 1324 error = EISDIR; 1325 else if (error & HAMMER2_ERROR_EINPROGRESS) 1326 error = EINPROGRESS; 1327 else if (error & HAMMER2_ERROR_EEXIST) 1328 error = EEXIST; 1329 else if (error & HAMMER2_ERROR_EINVAL) 1330 error = EINVAL; 1331 else if (error & HAMMER2_ERROR_EDEADLK) 1332 error = EDEADLK; 1333 else if (error & HAMMER2_ERROR_ESRCH) 1334 error = ESRCH; 1335 else if (error & HAMMER2_ERROR_ETIMEDOUT) 1336 error = ETIMEDOUT; 1337 else 1338 error = EDOM; 1339 } 1340 return error; 1341 } 1342 1343 static __inline 1344 int 1345 hammer2_errno_to_error(int error) 1346 { 1347 switch(error) { 1348 case 0: 1349 return 0; 1350 case EIO: 1351 return HAMMER2_ERROR_EIO; 1352 case EDOM: 1353 return HAMMER2_ERROR_CHECK; 1354 case EINTR: 1355 return HAMMER2_ERROR_ABORTED; 1356 //case EIO: 1357 // return HAMMER2_ERROR_BADBREF; 1358 case ENOSPC: 1359 return HAMMER2_ERROR_ENOSPC; 1360 case ENOENT: 1361 return HAMMER2_ERROR_ENOENT; 1362 case ENOTEMPTY: 1363 return HAMMER2_ERROR_ENOTEMPTY; 1364 case EAGAIN: 1365 return HAMMER2_ERROR_EAGAIN; 1366 case ENOTDIR: 1367 return HAMMER2_ERROR_ENOTDIR; 1368 case EISDIR: 1369 return HAMMER2_ERROR_EISDIR; 1370 case EINPROGRESS: 1371 return HAMMER2_ERROR_EINPROGRESS; 1372 case EEXIST: 1373 return HAMMER2_ERROR_EEXIST; 1374 case EINVAL: 1375 return HAMMER2_ERROR_EINVAL; 1376 case EDEADLK: 1377 return HAMMER2_ERROR_EDEADLK; 1378 case ESRCH: 1379 return HAMMER2_ERROR_ESRCH; 1380 case ETIMEDOUT: 1381 return HAMMER2_ERROR_ETIMEDOUT; 1382 default: 1383 return HAMMER2_ERROR_EINVAL; 1384 } 1385 } 1386 1387 1388 extern struct vop_ops hammer2_vnode_vops; 1389 extern struct vop_ops hammer2_spec_vops; 1390 extern struct vop_ops hammer2_fifo_vops; 1391 extern struct hammer2_pfslist hammer2_pfslist; 1392 extern struct lock hammer2_mntlk; 1393 1394 extern int hammer2_aux_flags; 1395 extern int hammer2_debug; 1396 extern int hammer2_xop_nthreads; 1397 extern int hammer2_xop_sgroups; 1398 extern int hammer2_xop_xgroups; 1399 extern int hammer2_xop_xbase; 1400 extern int hammer2_xop_mod; 1401 extern long hammer2_debug_inode; 1402 extern int hammer2_cluster_meta_read; 1403 extern int hammer2_cluster_data_read; 1404 extern int hammer2_cluster_write; 1405 extern int hammer2_dedup_enable; 1406 extern int hammer2_always_compress; 1407 extern int hammer2_flush_pipe; 1408 extern int hammer2_dio_count; 1409 extern int hammer2_dio_limit; 1410 extern int hammer2_bulkfree_tps; 1411 extern int hammer2_spread_workers; 1412 extern int hammer2_limit_saved_depth; 1413 extern long hammer2_chain_allocs; 1414 extern long hammer2_limit_saved_chains; 1415 extern long hammer2_limit_dirty_chains; 1416 extern long hammer2_limit_dirty_inodes; 1417 extern long hammer2_count_modified_chains; 1418 extern long hammer2_iod_file_read; 1419 extern long hammer2_iod_meta_read; 1420 extern long hammer2_iod_indr_read; 1421 extern long hammer2_iod_fmap_read; 1422 extern long hammer2_iod_volu_read; 1423 extern long hammer2_iod_file_write; 1424 extern long hammer2_iod_file_wembed; 1425 extern long hammer2_iod_file_wzero; 1426 extern long hammer2_iod_file_wdedup; 1427 extern long hammer2_iod_meta_write; 1428 extern long hammer2_iod_indr_write; 1429 extern long hammer2_iod_fmap_write; 1430 extern long hammer2_iod_volu_write; 1431 1432 extern long hammer2_process_icrc32; 1433 extern long hammer2_process_xxhash64; 1434 1435 extern struct objcache *cache_buffer_read; 1436 extern struct objcache *cache_buffer_write; 1437 extern struct objcache *cache_xops; 1438 1439 /* 1440 * hammer2_subr.c 1441 */ 1442 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size)) 1443 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc)) 1444 1445 int hammer2_signal_check(time_t *timep); 1446 const char *hammer2_error_str(int error); 1447 const char *hammer2_bref_type_str(int btype); 1448 1449 int hammer2_get_dtype(uint8_t type); 1450 int hammer2_get_vtype(uint8_t type); 1451 uint8_t hammer2_get_obj_type(enum vtype vtype); 1452 void hammer2_time_to_timespec(uint64_t xtime, struct timespec *ts); 1453 uint64_t hammer2_timespec_to_time(const struct timespec *ts); 1454 uint32_t hammer2_to_unix_xid(const uuid_t *uuid); 1455 void hammer2_guid_to_uuid(uuid_t *uuid, uint32_t guid); 1456 1457 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len); 1458 int hammer2_getradix(size_t bytes); 1459 1460 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff, 1461 hammer2_key_t *lbasep, hammer2_key_t *leofp); 1462 int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase); 1463 void hammer2_update_time(uint64_t *timep); 1464 void hammer2_adjreadcounter(int btype, size_t bytes); 1465 void hammer2_adjwritecounter(int btype, size_t bytes); 1466 1467 /* 1468 * hammer2_inode.c 1469 */ 1470 struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp); 1471 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfs_t *pmp, 1472 hammer2_tid_t inum); 1473 hammer2_inode_t *hammer2_inode_get(hammer2_pfs_t *pmp, 1474 hammer2_xop_head_t *xop, hammer2_tid_t inum, int idx); 1475 void hammer2_inode_ref(hammer2_inode_t *ip); 1476 void hammer2_inode_drop(hammer2_inode_t *ip); 1477 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_cluster_t *cluster); 1478 void hammer2_inode_repoint_one(hammer2_inode_t *ip, hammer2_cluster_t *cluster, 1479 int idx); 1480 hammer2_key_t hammer2_inode_data_count(const hammer2_inode_t *ip); 1481 hammer2_key_t hammer2_inode_inode_count(const hammer2_inode_t *ip); 1482 void hammer2_inode_modify(hammer2_inode_t *ip); 1483 void hammer2_inode_delayed_sideq(hammer2_inode_t *ip); 1484 void hammer2_inode_lock(hammer2_inode_t *ip, int how); 1485 void hammer2_inode_lock4(hammer2_inode_t *ip1, hammer2_inode_t *ip2, 1486 hammer2_inode_t *ip3, hammer2_inode_t *ip4); 1487 void hammer2_inode_unlock(hammer2_inode_t *ip); 1488 void hammer2_inode_depend(hammer2_inode_t *ip1, hammer2_inode_t *ip2); 1489 hammer2_chain_t *hammer2_inode_chain(hammer2_inode_t *ip, int clindex, int how); 1490 hammer2_chain_t *hammer2_inode_chain_and_parent(hammer2_inode_t *ip, 1491 int clindex, hammer2_chain_t **parentp, int how); 1492 hammer2_mtx_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip); 1493 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip, 1494 hammer2_mtx_state_t ostate); 1495 int hammer2_inode_lock_upgrade(hammer2_inode_t *ip); 1496 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, int); 1497 1498 hammer2_inode_t *hammer2_inode_create_normal(hammer2_inode_t *pip, 1499 struct vattr *vap, struct ucred *cred, 1500 hammer2_key_t inum, int *errorp); 1501 hammer2_inode_t *hammer2_inode_create_pfs(hammer2_pfs_t *spmp, 1502 const uint8_t *name, size_t name_len, 1503 int *errorp); 1504 int hammer2_inode_chain_ins(hammer2_inode_t *ip); 1505 int hammer2_inode_chain_des(hammer2_inode_t *ip); 1506 int hammer2_inode_chain_sync(hammer2_inode_t *ip); 1507 int hammer2_inode_chain_flush(hammer2_inode_t *ip, int flags); 1508 int hammer2_inode_unlink_finisher(hammer2_inode_t *ip, struct vnode **vpp); 1509 void hammer2_inode_vprecycle(struct vnode *vp); 1510 int hammer2_dirent_create(hammer2_inode_t *dip, const char *name, 1511 size_t name_len, hammer2_key_t inum, uint8_t type); 1512 1513 /* 1514 * hammer2_chain.c 1515 */ 1516 hammer2_chain_t *hammer2_chain_alloc(hammer2_dev_t *hmp, 1517 hammer2_pfs_t *pmp, 1518 hammer2_blockref_t *bref); 1519 void hammer2_chain_core_init(hammer2_chain_t *chain); 1520 void hammer2_chain_ref(hammer2_chain_t *chain); 1521 void hammer2_chain_ref_hold(hammer2_chain_t *chain); 1522 void hammer2_chain_drop(hammer2_chain_t *chain); 1523 void hammer2_chain_drop_unhold(hammer2_chain_t *chain); 1524 void hammer2_chain_unhold(hammer2_chain_t *chain); 1525 void hammer2_chain_rehold(hammer2_chain_t *chain); 1526 int hammer2_chain_lock(hammer2_chain_t *chain, int how); 1527 void hammer2_chain_lock_unhold(hammer2_chain_t *chain, int how); 1528 void hammer2_chain_load_data(hammer2_chain_t *chain); 1529 1530 int hammer2_chain_inode_find(hammer2_pfs_t *pmp, hammer2_key_t inum, 1531 int clindex, int flags, 1532 hammer2_chain_t **parentp, 1533 hammer2_chain_t **chainp); 1534 int hammer2_chain_modify(hammer2_chain_t *chain, hammer2_tid_t mtid, 1535 hammer2_off_t dedup_off, int flags); 1536 int hammer2_chain_modify_ip(hammer2_inode_t *ip, hammer2_chain_t *chain, 1537 hammer2_tid_t mtid, int flags); 1538 int hammer2_chain_resize(hammer2_chain_t *chain, 1539 hammer2_tid_t mtid, hammer2_off_t dedup_off, 1540 int nradix, int flags); 1541 void hammer2_chain_unlock(hammer2_chain_t *chain); 1542 void hammer2_chain_unlock_hold(hammer2_chain_t *chain); 1543 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation, 1544 hammer2_blockref_t *bref, int how); 1545 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags); 1546 void hammer2_chain_lookup_done(hammer2_chain_t *parent); 1547 hammer2_chain_t *hammer2_chain_getparent(hammer2_chain_t *chain, int flags); 1548 hammer2_chain_t *hammer2_chain_repparent(hammer2_chain_t **chainp, int flags); 1549 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp, 1550 hammer2_key_t *key_nextp, 1551 hammer2_key_t key_beg, hammer2_key_t key_end, 1552 int *errorp, int flags); 1553 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp, 1554 hammer2_chain_t *chain, 1555 hammer2_key_t *key_nextp, 1556 hammer2_key_t key_beg, hammer2_key_t key_end, 1557 int *errorp, int flags); 1558 int hammer2_chain_scan(hammer2_chain_t *parent, 1559 hammer2_chain_t **chainp, 1560 hammer2_blockref_t *bref, 1561 int *firstp, int flags); 1562 1563 int hammer2_chain_create(hammer2_chain_t **parentp, hammer2_chain_t **chainp, 1564 hammer2_dev_t *hmp, hammer2_pfs_t *pmp, 1565 int methods, hammer2_key_t key, int keybits, 1566 int type, size_t bytes, hammer2_tid_t mtid, 1567 hammer2_off_t dedup_off, int flags); 1568 void hammer2_chain_rename(hammer2_chain_t **parentp, 1569 hammer2_chain_t *chain, 1570 hammer2_tid_t mtid, int flags); 1571 int hammer2_chain_delete(hammer2_chain_t *parent, hammer2_chain_t *chain, 1572 hammer2_tid_t mtid, int flags); 1573 int hammer2_chain_indirect_maintenance(hammer2_chain_t *parent, 1574 hammer2_chain_t *chain); 1575 void hammer2_chain_setflush(hammer2_chain_t *chain); 1576 void hammer2_chain_countbrefs(hammer2_chain_t *chain, 1577 hammer2_blockref_t *base, int count); 1578 hammer2_chain_t *hammer2_chain_bulksnap(hammer2_dev_t *hmp); 1579 void hammer2_chain_bulkdrop(hammer2_chain_t *copy); 1580 1581 void hammer2_chain_setcheck(hammer2_chain_t *chain, void *bdata); 1582 int hammer2_chain_testcheck(hammer2_chain_t *chain, void *bdata); 1583 int hammer2_chain_dirent_test(hammer2_chain_t *chain, const char *name, 1584 size_t name_len); 1585 1586 void hammer2_base_delete(hammer2_chain_t *parent, 1587 hammer2_blockref_t *base, int count, 1588 hammer2_chain_t *chain, 1589 hammer2_blockref_t *obref); 1590 void hammer2_base_insert(hammer2_chain_t *parent, 1591 hammer2_blockref_t *base, int count, 1592 hammer2_chain_t *chain, 1593 hammer2_blockref_t *elm); 1594 1595 /* 1596 * hammer2_flush.c 1597 */ 1598 void hammer2_trans_manage_init(hammer2_pfs_t *pmp); 1599 int hammer2_flush(hammer2_chain_t *chain, int istop); 1600 void hammer2_trans_init(hammer2_pfs_t *pmp, uint32_t flags); 1601 void hammer2_trans_setflags(hammer2_pfs_t *pmp, uint32_t flags); 1602 void hammer2_trans_clearflags(hammer2_pfs_t *pmp, uint32_t flags); 1603 hammer2_tid_t hammer2_trans_sub(hammer2_pfs_t *pmp); 1604 void hammer2_trans_done(hammer2_pfs_t *pmp, uint32_t flags); 1605 hammer2_tid_t hammer2_trans_newinum(hammer2_pfs_t *pmp); 1606 void hammer2_trans_assert_strategy(hammer2_pfs_t *pmp); 1607 1608 /* 1609 * hammer2_ioctl.c 1610 */ 1611 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data, 1612 int fflag, struct ucred *cred); 1613 1614 /* 1615 * hammer2_io.c 1616 */ 1617 void hammer2_io_inval(hammer2_io_t *dio, hammer2_off_t data_off, u_int bytes); 1618 void hammer2_io_cleanup(hammer2_dev_t *hmp, struct hammer2_io_tree *tree); 1619 char *hammer2_io_data(hammer2_io_t *dio, off_t lbase); 1620 void hammer2_io_bkvasync(hammer2_io_t *dio); 1621 void hammer2_io_dedup_set(hammer2_dev_t *hmp, hammer2_blockref_t *bref); 1622 void hammer2_io_dedup_delete(hammer2_dev_t *hmp, uint8_t btype, 1623 hammer2_off_t data_off, u_int bytes); 1624 void hammer2_io_dedup_assert(hammer2_dev_t *hmp, hammer2_off_t data_off, 1625 u_int bytes); 1626 int hammer2_io_new(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize, 1627 hammer2_io_t **diop); 1628 int hammer2_io_newnz(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize, 1629 hammer2_io_t **diop); 1630 int _hammer2_io_bread(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize, 1631 hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1632 void hammer2_io_setdirty(hammer2_io_t *dio); 1633 1634 hammer2_io_t *_hammer2_io_getblk(hammer2_dev_t *hmp, int btype, off_t lbase, 1635 int lsize, int op HAMMER2_IO_DEBUG_ARGS); 1636 hammer2_io_t *_hammer2_io_getquick(hammer2_dev_t *hmp, off_t lbase, 1637 int lsize HAMMER2_IO_DEBUG_ARGS); 1638 void _hammer2_io_putblk(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1639 int _hammer2_io_bwrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1640 void _hammer2_io_bawrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1641 void _hammer2_io_bdwrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1642 void _hammer2_io_brelse(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1643 void _hammer2_io_bqrelse(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS); 1644 void _hammer2_io_ref(hammer2_io_t *dio HAMMER2_IO_DEBUG_ARGS); 1645 1646 #ifndef HAMMER2_IO_DEBUG 1647 1648 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \ 1649 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op)) 1650 #define hammer2_io_getquick(hmp, lbase, lsize) \ 1651 _hammer2_io_getquick((hmp), (lbase), (lsize)) 1652 #define hammer2_io_putblk(diop) \ 1653 _hammer2_io_putblk(diop) 1654 #define hammer2_io_bwrite(diop) \ 1655 _hammer2_io_bwrite((diop)) 1656 #define hammer2_io_bawrite(diop) \ 1657 _hammer2_io_bawrite((diop)) 1658 #define hammer2_io_bdwrite(diop) \ 1659 _hammer2_io_bdwrite((diop)) 1660 #define hammer2_io_brelse(diop) \ 1661 _hammer2_io_brelse((diop)) 1662 #define hammer2_io_bqrelse(diop) \ 1663 _hammer2_io_bqrelse((diop)) 1664 #define hammer2_io_ref(dio) \ 1665 _hammer2_io_ref((dio)) 1666 1667 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \ 1668 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop)) 1669 1670 #else 1671 1672 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \ 1673 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op), \ 1674 __FILE__, __LINE__) 1675 1676 #define hammer2_io_getquick(hmp, lbase, lsize) \ 1677 _hammer2_io_getquick((hmp), (lbase), (lsize), __FILE__, __LINE__) 1678 1679 #define hammer2_io_putblk(diop) \ 1680 _hammer2_io_putblk(diop, __FILE__, __LINE__) 1681 1682 #define hammer2_io_bwrite(diop) \ 1683 _hammer2_io_bwrite((diop), __FILE__, __LINE__) 1684 #define hammer2_io_bawrite(diop) \ 1685 _hammer2_io_bawrite((diop), __FILE__, __LINE__) 1686 #define hammer2_io_bdwrite(diop) \ 1687 _hammer2_io_bdwrite((diop), __FILE__, __LINE__) 1688 #define hammer2_io_brelse(diop) \ 1689 _hammer2_io_brelse((diop), __FILE__, __LINE__) 1690 #define hammer2_io_bqrelse(diop) \ 1691 _hammer2_io_bqrelse((diop), __FILE__, __LINE__) 1692 #define hammer2_io_ref(dio) \ 1693 _hammer2_io_ref((dio), __FILE__, __LINE__) 1694 1695 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \ 1696 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop), \ 1697 __FILE__, __LINE__) 1698 1699 #endif 1700 1701 /* 1702 * hammer2_admin.c 1703 */ 1704 void hammer2_thr_signal(hammer2_thread_t *thr, uint32_t flags); 1705 void hammer2_thr_signal2(hammer2_thread_t *thr, 1706 uint32_t pflags, uint32_t nflags); 1707 void hammer2_thr_wait(hammer2_thread_t *thr, uint32_t flags); 1708 void hammer2_thr_wait_neg(hammer2_thread_t *thr, uint32_t flags); 1709 int hammer2_thr_wait_any(hammer2_thread_t *thr, uint32_t flags, int timo); 1710 void hammer2_thr_create(hammer2_thread_t *thr, 1711 hammer2_pfs_t *pmp, hammer2_dev_t *hmp, 1712 const char *id, int clindex, int repidx, 1713 void (*func)(void *arg)); 1714 void hammer2_thr_delete(hammer2_thread_t *thr); 1715 void hammer2_thr_remaster(hammer2_thread_t *thr); 1716 void hammer2_thr_freeze_async(hammer2_thread_t *thr); 1717 void hammer2_thr_freeze(hammer2_thread_t *thr); 1718 void hammer2_thr_unfreeze(hammer2_thread_t *thr); 1719 int hammer2_thr_break(hammer2_thread_t *thr); 1720 void hammer2_primary_xops_thread(void *arg); 1721 1722 /* 1723 * hammer2_thread.c (XOP API) 1724 */ 1725 void *hammer2_xop_alloc(hammer2_inode_t *ip, int flags); 1726 void hammer2_xop_setname(hammer2_xop_head_t *xop, 1727 const char *name, size_t name_len); 1728 void hammer2_xop_setname2(hammer2_xop_head_t *xop, 1729 const char *name, size_t name_len); 1730 size_t hammer2_xop_setname_inum(hammer2_xop_head_t *xop, hammer2_key_t inum); 1731 void hammer2_xop_setip2(hammer2_xop_head_t *xop, hammer2_inode_t *ip2); 1732 void hammer2_xop_setip3(hammer2_xop_head_t *xop, hammer2_inode_t *ip3); 1733 void hammer2_xop_setip4(hammer2_xop_head_t *xop, hammer2_inode_t *ip4); 1734 void hammer2_xop_reinit(hammer2_xop_head_t *xop); 1735 void hammer2_xop_helper_create(hammer2_pfs_t *pmp); 1736 void hammer2_xop_helper_cleanup(hammer2_pfs_t *pmp); 1737 void hammer2_xop_start(hammer2_xop_head_t *xop, hammer2_xop_desc_t *desc); 1738 void hammer2_xop_start_except(hammer2_xop_head_t *xop, hammer2_xop_desc_t *desc, 1739 int notidx); 1740 int hammer2_xop_collect(hammer2_xop_head_t *xop, int flags); 1741 void hammer2_xop_retire(hammer2_xop_head_t *xop, uint64_t mask); 1742 int hammer2_xop_active(hammer2_xop_head_t *xop); 1743 int hammer2_xop_feed(hammer2_xop_head_t *xop, hammer2_chain_t *chain, 1744 int clindex, int error); 1745 1746 /* 1747 * hammer2_synchro.c 1748 */ 1749 void hammer2_primary_sync_thread(void *arg); 1750 1751 /* 1752 * XOP backends in hammer2_xops.c, primarily for VNOPS. Other XOP backends 1753 * may be integrated into other source files. 1754 */ 1755 void hammer2_xop_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex); 1756 void hammer2_xop_readdir(hammer2_xop_t *xop, void *scratch, int clindex); 1757 void hammer2_xop_nresolve(hammer2_xop_t *xop, void *scratch, int clindex); 1758 void hammer2_xop_unlink(hammer2_xop_t *xop, void *scratch, int clindex); 1759 void hammer2_xop_nrename(hammer2_xop_t *xop, void *scratch, int clindex); 1760 void hammer2_xop_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex); 1761 void hammer2_xop_scanall(hammer2_xop_t *xop, void *scratch, int clindex); 1762 void hammer2_xop_lookup(hammer2_xop_t *xop, void *scratch, int clindex); 1763 void hammer2_xop_delete(hammer2_xop_t *xop, void *scratch, int clindex); 1764 void hammer2_xop_inode_mkdirent(hammer2_xop_t *xop, void *scratch, int clindex); 1765 void hammer2_xop_inode_create(hammer2_xop_t *xop, void *scratch, int clindex); 1766 void hammer2_xop_inode_create_det(hammer2_xop_t *xop, 1767 void *scratch, int clindex); 1768 void hammer2_xop_inode_create_ins(hammer2_xop_t *xop, 1769 void *scratch, int clindex); 1770 void hammer2_xop_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex); 1771 void hammer2_xop_inode_chain_sync(hammer2_xop_t *xop, void *scratch, 1772 int clindex); 1773 void hammer2_xop_inode_unlinkall(hammer2_xop_t *xop, void *scratch, 1774 int clindex); 1775 void hammer2_xop_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex); 1776 void hammer2_xop_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex); 1777 void hammer2_xop_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex); 1778 void hammer2_xop_strategy_write(hammer2_xop_t *xop, void *scratch, int clindex); 1779 1780 void hammer2_dmsg_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex); 1781 void hammer2_dmsg_readdir(hammer2_xop_t *xop, void *scratch, int clindex); 1782 void hammer2_dmsg_nresolve(hammer2_xop_t *xop, void *scratch, int clindex); 1783 void hammer2_dmsg_unlink(hammer2_xop_t *xop, void *scratch, int clindex); 1784 void hammer2_dmsg_nrename(hammer2_xop_t *xop, void *scratch, int clindex); 1785 void hammer2_dmsg_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex); 1786 void hammer2_dmsg_scanall(hammer2_xop_t *xop, void *scratch, int clindex); 1787 void hammer2_dmsg_lookup(hammer2_xop_t *xop, void *scratch, int clindex); 1788 void hammer2_dmsg_inode_mkdirent(hammer2_xop_t *xop, void *scratch, 1789 int clindex); 1790 void hammer2_dmsg_inode_create(hammer2_xop_t *xop, void *scratch, int clindex); 1791 void hammer2_dmsg_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex); 1792 void hammer2_dmsg_inode_chain_sync(hammer2_xop_t *xop, void *scratch, 1793 int clindex); 1794 void hammer2_dmsg_inode_unlinkall(hammer2_xop_t *xop, void *scratch, 1795 int clindex); 1796 void hammer2_dmsg_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex); 1797 void hammer2_dmsg_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex); 1798 void hammer2_dmsg_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex); 1799 void hammer2_dmsg_strategy_write(hammer2_xop_t *xop, void *scratch, 1800 int clindex); 1801 1802 void hammer2_rmsg_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex); 1803 void hammer2_rmsg_readdir(hammer2_xop_t *xop, void *scratch, int clindex); 1804 void hammer2_rmsg_nresolve(hammer2_xop_t *xop, void *scratch, int clindex); 1805 void hammer2_rmsg_unlink(hammer2_xop_t *xop, void *scratch, int clindex); 1806 void hammer2_rmsg_nrename(hammer2_xop_t *xop, void *scratch, int clindex); 1807 void hammer2_rmsg_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex); 1808 void hammer2_rmsg_scanall(hammer2_xop_t *xop, void *scratch, int clindex); 1809 void hammer2_rmsg_lookup(hammer2_xop_t *xop, void *scratch, int clindex); 1810 void hammer2_rmsg_inode_mkdirent(hammer2_xop_t *xop, void *scratch, 1811 int clindex); 1812 void hammer2_rmsg_inode_create(hammer2_xop_t *xop, void *scratch, int clindex); 1813 void hammer2_rmsg_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex); 1814 void hammer2_rmsg_inode_chain_sync(hammer2_xop_t *xop, void *scratch, 1815 int clindex); 1816 void hammer2_rmsg_inode_unlinkall(hammer2_xop_t *xop, void *scratch, 1817 int clindex); 1818 void hammer2_rmsg_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex); 1819 void hammer2_rmsg_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex); 1820 void hammer2_rmsg_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex); 1821 void hammer2_rmsg_strategy_write(hammer2_xop_t *xop, void *scratch, 1822 int clindex); 1823 1824 extern hammer2_xop_desc_t hammer2_ipcluster_desc; 1825 extern hammer2_xop_desc_t hammer2_readdir_desc; 1826 extern hammer2_xop_desc_t hammer2_nresolve_desc; 1827 extern hammer2_xop_desc_t hammer2_unlink_desc; 1828 extern hammer2_xop_desc_t hammer2_nrename_desc; 1829 extern hammer2_xop_desc_t hammer2_scanlhc_desc; 1830 extern hammer2_xop_desc_t hammer2_scanall_desc; 1831 extern hammer2_xop_desc_t hammer2_lookup_desc; 1832 extern hammer2_xop_desc_t hammer2_delete_desc; 1833 extern hammer2_xop_desc_t hammer2_inode_mkdirent_desc; 1834 extern hammer2_xop_desc_t hammer2_inode_create_desc; 1835 extern hammer2_xop_desc_t hammer2_inode_create_det_desc; 1836 extern hammer2_xop_desc_t hammer2_inode_create_ins_desc; 1837 extern hammer2_xop_desc_t hammer2_inode_destroy_desc; 1838 extern hammer2_xop_desc_t hammer2_inode_chain_sync_desc; 1839 extern hammer2_xop_desc_t hammer2_inode_unlinkall_desc; 1840 extern hammer2_xop_desc_t hammer2_inode_connect_desc; 1841 extern hammer2_xop_desc_t hammer2_inode_flush_desc; 1842 extern hammer2_xop_desc_t hammer2_strategy_read_desc; 1843 extern hammer2_xop_desc_t hammer2_strategy_write_desc; 1844 1845 /* 1846 * hammer2_msgops.c 1847 */ 1848 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg); 1849 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg); 1850 1851 /* 1852 * hammer2_vfsops.c 1853 */ 1854 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int bi, int *countp, 1855 char pfx, u_int flags); 1856 int hammer2_vfs_sync(struct mount *mp, int waitflags); 1857 int hammer2_vfs_sync_pmp(hammer2_pfs_t *pmp, int waitfor); 1858 int hammer2_vfs_enospace(hammer2_inode_t *ip, off_t bytes, struct ucred *cred); 1859 1860 hammer2_pfs_t *hammer2_pfsalloc(hammer2_chain_t *chain, 1861 const hammer2_inode_data_t *ripdata, 1862 hammer2_tid_t modify_tid, 1863 hammer2_dev_t *force_local); 1864 void hammer2_pfsdealloc(hammer2_pfs_t *pmp, int clindex, int destroying); 1865 int hammer2_vfs_vget(struct mount *mp, struct vnode *dvp, 1866 ino_t ino, struct vnode **vpp); 1867 1868 void hammer2_lwinprog_ref(hammer2_pfs_t *pmp); 1869 void hammer2_lwinprog_drop(hammer2_pfs_t *pmp); 1870 void hammer2_lwinprog_wait(hammer2_pfs_t *pmp, int pipe); 1871 1872 void hammer2_pfs_memory_wait(hammer2_pfs_t *pmp); 1873 void hammer2_pfs_memory_inc(hammer2_pfs_t *pmp); 1874 void hammer2_pfs_memory_wakeup(hammer2_pfs_t *pmp, int count); 1875 1876 void hammer2_voldata_lock(hammer2_dev_t *hmp); 1877 void hammer2_voldata_unlock(hammer2_dev_t *hmp); 1878 void hammer2_voldata_modify(hammer2_dev_t *hmp); 1879 1880 /* 1881 * hammer2_freemap.c 1882 */ 1883 int hammer2_freemap_alloc(hammer2_chain_t *chain, size_t bytes); 1884 void hammer2_freemap_adjust(hammer2_dev_t *hmp, 1885 hammer2_blockref_t *bref, int how); 1886 1887 /* 1888 * hammer2_cluster.c 1889 */ 1890 uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster); 1891 void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref); 1892 void hammer2_cluster_ref(hammer2_cluster_t *cluster); 1893 void hammer2_cluster_drop(hammer2_cluster_t *cluster); 1894 void hammer2_cluster_unhold(hammer2_cluster_t *cluster); 1895 void hammer2_cluster_rehold(hammer2_cluster_t *cluster); 1896 void hammer2_cluster_lock(hammer2_cluster_t *cluster, int how); 1897 int hammer2_cluster_check(hammer2_cluster_t *cluster, hammer2_key_t lokey, 1898 int flags); 1899 void hammer2_cluster_forcegood(hammer2_cluster_t *cluster); 1900 void hammer2_cluster_unlock(hammer2_cluster_t *cluster); 1901 1902 void hammer2_bulkfree_init(hammer2_dev_t *hmp); 1903 void hammer2_bulkfree_uninit(hammer2_dev_t *hmp); 1904 int hammer2_bulkfree_pass(hammer2_dev_t *hmp, hammer2_chain_t *vchain, 1905 struct hammer2_ioc_bulkfree *bfi); 1906 void hammer2_dummy_xop_from_chain(hammer2_xop_head_t *xop, 1907 hammer2_chain_t *chain); 1908 1909 /* 1910 * hammer2_iocom.c 1911 */ 1912 void hammer2_iocom_init(hammer2_dev_t *hmp); 1913 void hammer2_iocom_uninit(hammer2_dev_t *hmp); 1914 void hammer2_cluster_reconnect(hammer2_dev_t *hmp, struct file *fp); 1915 void hammer2_volconf_update(hammer2_dev_t *hmp, int index); 1916 1917 /* 1918 * hammer2_strategy.c 1919 */ 1920 int hammer2_vop_strategy(struct vop_strategy_args *ap); 1921 int hammer2_vop_bmap(struct vop_bmap_args *ap); 1922 void hammer2_bioq_sync(hammer2_pfs_t *pmp); 1923 void hammer2_dedup_record(hammer2_chain_t *chain, hammer2_io_t *dio, 1924 const char *data); 1925 void hammer2_dedup_clear(hammer2_dev_t *hmp); 1926 1927 /* 1928 * hammer2_ondisk.c 1929 */ 1930 int hammer2_open_devvp(const hammer2_devvp_list_t *devvpl, int ronly); 1931 int hammer2_close_devvp(const hammer2_devvp_list_t *devvpl, int ronly); 1932 int hammer2_init_devvp(const char *blkdevs, int rootmount, 1933 hammer2_devvp_list_t *devvpl); 1934 void hammer2_cleanup_devvp(hammer2_devvp_list_t *devvpl); 1935 int hammer2_init_volumes(struct mount *mp, const hammer2_devvp_list_t *devvpl, 1936 hammer2_volume_t *volumes, 1937 hammer2_volume_data_t *rootvoldata, 1938 int *rootvolzone, 1939 struct vnode **rootvoldevvp); 1940 hammer2_volume_t *hammer2_get_volume(hammer2_dev_t *hmp, hammer2_off_t offset); 1941 1942 /* 1943 * More complex inlines 1944 */ 1945 1946 #define hammer2_xop_gdata(xop) _hammer2_xop_gdata((xop), __FILE__, __LINE__) 1947 1948 static __inline 1949 const hammer2_media_data_t * 1950 _hammer2_xop_gdata(hammer2_xop_head_t *xop, const char *file, int line) 1951 { 1952 hammer2_chain_t *focus; 1953 const void *data; 1954 1955 focus = xop->cluster.focus; 1956 if (focus->dio) { 1957 lockmgr(&focus->diolk, LK_SHARED); 1958 if ((xop->focus_dio = focus->dio) != NULL) { 1959 _hammer2_io_ref(xop->focus_dio HAMMER2_IO_DEBUG_CALL); 1960 hammer2_io_bkvasync(xop->focus_dio); 1961 } 1962 data = focus->data; 1963 lockmgr(&focus->diolk, LK_RELEASE); 1964 } else { 1965 data = focus->data; 1966 } 1967 1968 return data; 1969 } 1970 1971 #define hammer2_xop_pdata(xop) _hammer2_xop_pdata((xop), __FILE__, __LINE__) 1972 1973 static __inline 1974 void 1975 _hammer2_xop_pdata(hammer2_xop_head_t *xop, const char *file, int line) 1976 { 1977 if (xop->focus_dio) 1978 _hammer2_io_putblk(&xop->focus_dio HAMMER2_IO_DEBUG_CALL); 1979 } 1980 1981 static __inline 1982 void 1983 hammer2_knote(struct vnode *vp, int flags) 1984 { 1985 if (flags) 1986 KNOTE(&vp->v_pollinfo.vpi_kqinfo.ki_note, flags); 1987 } 1988 1989 #endif /* !_KERNEL */ 1990 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */ 1991