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