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