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