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