1 /* 2 * Copyright (c) 2011-2013 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 * This header file contains structures used internally by the HAMMER2 38 * implementation. See hammer2_disk.h for on-disk structures. 39 */ 40 41 #ifndef _VFS_HAMMER2_HAMMER2_H_ 42 #define _VFS_HAMMER2_HAMMER2_H_ 43 44 #include <sys/param.h> 45 #include <sys/types.h> 46 #include <sys/kernel.h> 47 #include <sys/conf.h> 48 #include <sys/systm.h> 49 #include <sys/tree.h> 50 #include <sys/malloc.h> 51 #include <sys/mount.h> 52 #include <sys/vnode.h> 53 #include <sys/proc.h> 54 #include <sys/mountctl.h> 55 #include <sys/priv.h> 56 #include <sys/stat.h> 57 #include <sys/thread.h> 58 #include <sys/globaldata.h> 59 #include <sys/lockf.h> 60 #include <sys/buf.h> 61 #include <sys/queue.h> 62 #include <sys/limits.h> 63 #include <sys/buf2.h> 64 #include <sys/signal2.h> 65 #include <sys/dmsg.h> 66 67 #include "hammer2_disk.h" 68 #include "hammer2_mount.h" 69 #include "hammer2_ioctl.h" 70 #include "hammer2_ccms.h" 71 72 struct hammer2_chain; 73 struct hammer2_inode; 74 struct hammer2_mount; 75 struct hammer2_pfsmount; 76 struct hammer2_span; 77 struct hammer2_state; 78 struct hammer2_msg; 79 80 /* 81 * The chain structure tracks blockref recursions all the way to the root 82 * volume. These consist of indirect blocks, inodes, and eventually the 83 * volume header itself. 84 * 85 * In situations where a duplicate is needed to represent different snapshots 86 * or flush points a new chain will be allocated but associated with the 87 * same shared chain_core. The RBTREE is contained in the shared chain_core 88 * and entries in the RBTREE are versioned. 89 * 90 * Duplication can occur whenever a chain must be modified. Note that 91 * a deletion is not considered a modification. 92 * 93 * (a) General modifications at data leafs 94 * (b) When a chain is resized 95 * (c) When a chain's blockref array is updated 96 * (d) When a chain is renamed 97 * (e) When a chain is moved (when an indirect block is split) 98 * 99 * Advantages: 100 * 101 * (1) Fully coherent snapshots can be taken without requiring 102 * a pre-flush, resulting in extremely fast (sub-millisecond) 103 * snapshots. 104 * 105 * (2) Multiple synchronization points can be in-flight at the same 106 * time, representing multiple snapshots or flushes. 107 * 108 * (3) The algorithms needed to keep track of everything are actually 109 * not that complex. 110 * 111 * Special Considerations: 112 * 113 * A chain is ref-counted on a per-chain basis, but the chain's lock 114 * is associated with the shared chain_core and is not per-chain. 115 * 116 * Each chain is representative of a filesystem topology. Even 117 * though the shared chain_core's are effectively multi-homed, the 118 * chain structure is not. 119 * 120 * chain->parent is a stable pointer and can be iterated without locking 121 * as long as either the chain or *any* deep child under the chain 122 * is held. 123 */ 124 RB_HEAD(hammer2_chain_tree, hammer2_chain); 125 TAILQ_HEAD(flush_deferral_list, hammer2_chain); 126 127 struct hammer2_chain_core { 128 struct ccms_cst cst; 129 struct hammer2_chain_tree rbtree; 130 struct hammer2_chain *first_parent; 131 u_int sharecnt; 132 u_int flags; 133 }; 134 135 typedef struct hammer2_chain_core hammer2_chain_core_t; 136 137 #define HAMMER2_CORE_INDIRECT 0x0001 138 139 struct hammer2_chain { 140 RB_ENTRY(hammer2_chain) rbnode; 141 hammer2_blockref_t bref; 142 hammer2_chain_core_t *core; 143 hammer2_chain_core_t *above; 144 struct hammer2_chain *next_parent; 145 struct hammer2_state *state; /* if active cache msg */ 146 struct hammer2_mount *hmp; 147 #if 0 148 struct hammer2_chain *duplink; /* duplication link */ 149 #endif 150 151 hammer2_tid_t modify_tid; /* snapshot/flush filter */ 152 hammer2_tid_t delete_tid; 153 struct buf *bp; /* physical data buffer */ 154 u_int bytes; /* physical data size */ 155 int index; /* blockref index in parent */ 156 u_int flags; 157 u_int refs; 158 u_int lockcnt; 159 hammer2_media_data_t *data; /* data pointer shortcut */ 160 TAILQ_ENTRY(hammer2_chain) flush_node; /* flush deferral list */ 161 }; 162 163 typedef struct hammer2_chain hammer2_chain_t; 164 165 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2); 166 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp); 167 168 /* 169 * Special notes on flags: 170 * 171 * INITIAL - This flag allows a chain to be created and for storage to 172 * be allocated without having to immediately instantiate the 173 * related buffer. The data is assumed to be all-zeros. It 174 * is primarily used for indirect blocks. 175 * 176 * MOVED - A modified chain becomes MOVED after it flushes. A chain 177 * can also become MOVED if it is moved within the topology 178 * (even if not modified). 179 * 180 */ 181 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */ 182 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */ 183 #define HAMMER2_CHAIN_DIRTYBP 0x00000004 /* dirty on unlock */ 184 #define HAMMER2_CHAIN_SUBMODIFIED 0x00000008 /* recursive flush */ 185 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */ 186 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */ 187 #define HAMMER2_CHAIN_FLUSHED 0x00000040 /* flush on unlock */ 188 #define HAMMER2_CHAIN_MOVED 0x00000080 /* bref changed */ 189 #define HAMMER2_CHAIN_IOFLUSH 0x00000100 /* bawrite on put */ 190 #define HAMMER2_CHAIN_DEFERRED 0x00000200 /* on a deferral list */ 191 #define HAMMER2_CHAIN_DESTROYED 0x00000400 /* destroying inode */ 192 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */ 193 #define HAMMER2_CHAIN_RECYCLE 0x00001000 /* force recycle */ 194 #define HAMMER2_CHAIN_MOUNTED 0x00002000 /* PFS is mounted */ 195 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */ 196 #define HAMMER2_CHAIN_SNAPSHOT 0x00008000 /* snapshot special */ 197 #define HAMMER2_CHAIN_EMBEDDED 0x00010000 /* embedded data */ 198 199 /* 200 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next() 201 * 202 * NOTE: MATCHIND allows an indirect block / freemap node to be returned 203 * when the passed key range matches the radix. Remember that key_end 204 * is inclusive (e.g. {0x000,0xFFF}, not {0x000,0x1000}). 205 */ 206 #define HAMMER2_LOOKUP_NOLOCK 0x00000001 /* ref only */ 207 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */ 208 #define HAMMER2_LOOKUP_SHARED 0x00000100 209 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 210 #define HAMMER2_LOOKUP_FREEMAP 0x00000400 /* freemap base */ 211 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */ 212 213 /* 214 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize() 215 * 216 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT 217 * blocks in the INITIAL-create state. 218 */ 219 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */ 220 #define HAMMER2_MODIFY_NO_MODIFY_TID 0x00000004 221 #define HAMMER2_MODIFY_ASSERTNOCOPY 0x00000008 222 #define HAMMER2_MODIFY_NOREALLOC 0x00000010 223 224 /* 225 * Flags passed to hammer2_chain_lock() 226 */ 227 #define HAMMER2_RESOLVE_NEVER 1 228 #define HAMMER2_RESOLVE_MAYBE 2 229 #define HAMMER2_RESOLVE_ALWAYS 3 230 #define HAMMER2_RESOLVE_MASK 0x0F 231 232 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */ 233 #define HAMMER2_RESOLVE_NOREF 0x20 /* already ref'd on lock */ 234 235 /* 236 * Flags passed to hammer2_chain_delete_duplicate() 237 */ 238 #define HAMMER2_DELDUP_RECORE 0x0001 239 240 /* 241 * Cluster different types of storage together for allocations 242 */ 243 #define HAMMER2_FREECACHE_INODE 0 244 #define HAMMER2_FREECACHE_INDIR 1 245 #define HAMMER2_FREECACHE_DATA 2 246 #define HAMMER2_FREECACHE_UNUSED3 3 247 #define HAMMER2_FREECACHE_TYPES 4 248 249 /* 250 * hammer2_freemap_alloc() block preference 251 */ 252 #define HAMMER2_OFF_NOPREF ((hammer2_off_t)-1) 253 254 /* 255 * BMAP read-ahead maximum parameters 256 */ 257 #define HAMMER2_BMAP_COUNT 16 /* max bmap read-ahead */ 258 #define HAMMER2_BMAP_BYTES (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT) 259 260 /* 261 * Misc 262 */ 263 #define HAMMER2_FLUSH_DEPTH_LIMIT 40 /* stack recursion limit */ 264 265 /* 266 * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES 267 * 268 * There is an in-memory representation of all on-media data structure. 269 * 270 * When accessed read-only the data will be mapped to the related buffer 271 * cache buffer. 272 * 273 * When accessed read-write (marked modified) a kmalloc()'d copy of the 274 * is created which can then be modified. The copy is destroyed when a 275 * filesystem block is allocated to replace it. 276 * 277 * Active inodes (those with vnodes attached) will maintain the kmalloc()'d 278 * copy for both the read-only and the read-write case. The combination of 279 * (bp) and (data) determines whether (data) was allocated or not. 280 * 281 * The in-memory representation may remain cached (for example in order to 282 * placemark clustering locks) even after the related data has been 283 * detached. 284 */ 285 286 RB_HEAD(hammer2_inode_tree, hammer2_inode); 287 288 /* 289 * A hammer2 inode. 290 * 291 * NOTE: The inode's attribute CST which is also used to lock the inode 292 * is embedded in the chain (chain.cst) and aliased w/ attr_cst. 293 */ 294 struct hammer2_inode { 295 RB_ENTRY(hammer2_inode) rbnode; /* inumber lookup (HL) */ 296 ccms_cst_t topo_cst; /* directory topology cst */ 297 struct hammer2_pfsmount *pmp; /* PFS mount */ 298 struct hammer2_inode *pip; /* parent inode */ 299 struct vnode *vp; 300 hammer2_chain_t *chain; /* NOTE: rehomed on rename */ 301 struct lockf advlock; 302 hammer2_tid_t inum; 303 u_int flags; 304 u_int refs; /* +vpref, +flushref */ 305 }; 306 307 typedef struct hammer2_inode hammer2_inode_t; 308 309 #define HAMMER2_INODE_MODIFIED 0x0001 310 #define HAMMER2_INODE_SROOT 0x0002 /* kmalloc special case */ 311 #define HAMMER2_INODE_RENAME_INPROG 0x0004 312 #define HAMMER2_INODE_ONRBTREE 0x0008 313 314 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2); 315 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp, 316 hammer2_tid_t); 317 318 /* 319 * A hammer2 transaction and flush sequencing structure. 320 * 321 * This global structure is tied into hammer2_mount and is used 322 * to sequence modifying operations and flushes. 323 * 324 * (a) Any modifying operations with sync_tid >= flush_tid will stall until 325 * all modifying operating with sync_tid < flush_tid complete. 326 * 327 * The flush related to flush_tid stalls until all modifying operations 328 * with sync_tid < flush_tid complete. 329 * 330 * (b) Once unstalled, modifying operations with sync_tid > flush_tid are 331 * allowed to run. All modifications cause modify/duplicate operations 332 * to occur on the related chains. Note that most INDIRECT blocks will 333 * be unaffected because the modifications just overload the RBTREE 334 * structurally instead of actually modifying the indirect blocks. 335 * 336 * (c) The actual flush unstalls and RUNS CONCURRENTLY with (b), but only 337 * utilizes the chain structures with sync_tid <= flush_tid. The 338 * flush will modify related indirect blocks and inodes in-place 339 * (rather than duplicate) since the adjustments are compatible with 340 * (b)'s RBTREE overloading 341 * 342 * SPECIAL NOTE: Inode modifications have to also propagate along any 343 * modify/duplicate chains. File writes detect the flush 344 * and force out the conflicting buffer cache buffer(s) 345 * before reusing them. 346 * 347 * (d) Snapshots can be made instantly but must be flushed and disconnected 348 * from their duplicative source before they can be mounted. This is 349 * because while H2's on-media structure supports forks, its in-memory 350 * structure only supports very simple forking for background flushing 351 * purposes. 352 * 353 * TODO: Flush merging. When fsync() is called on multiple discrete files 354 * concurrently there is no reason to stall the second fsync. 355 * The final flush that reaches to root can cover both fsync()s. 356 * 357 * The chains typically terminate as they fly onto the disk. The flush 358 * ultimately reaches the volume header. 359 */ 360 struct hammer2_trans { 361 TAILQ_ENTRY(hammer2_trans) entry; 362 struct hammer2_pfsmount *pmp; 363 hammer2_tid_t sync_tid; 364 thread_t td; /* pointer */ 365 int flags; 366 int blocked; 367 uint8_t inodes_created; 368 uint8_t dummy[7]; 369 }; 370 371 typedef struct hammer2_trans hammer2_trans_t; 372 373 #define HAMMER2_TRANS_ISFLUSH 0x0001 374 #define HAMMER2_TRANS_RESTRICTED 0x0002 /* snapshot flush restrict */ 375 376 /* 377 * XXX 378 */ 379 struct hammer2_freecache { 380 hammer2_off_t bulk; 381 hammer2_off_t single; 382 }; 383 384 typedef struct hammer2_freecache hammer2_freecache_t; 385 386 /* 387 * Global (per device) mount structure for device (aka vp->v_mount->hmp) 388 */ 389 TAILQ_HEAD(hammer2_trans_queue, hammer2_trans); 390 391 struct hammer2_mount { 392 struct vnode *devvp; /* device vnode */ 393 int ronly; /* read-only mount */ 394 int pmp_count; /* PFS mounts backed by us */ 395 TAILQ_ENTRY(hammer2_mount) mntentry; /* hammer2_mntlist */ 396 397 struct malloc_type *mchain; 398 int nipstacks; 399 int maxipstacks; 400 hammer2_chain_t vchain; /* anchor chain */ 401 hammer2_chain_t fchain; /* freemap chain special */ 402 hammer2_chain_t *schain; /* super-root */ 403 hammer2_inode_t *sroot; /* super-root inode */ 404 struct lock alloclk; /* lockmgr lock */ 405 struct lock voldatalk; /* lockmgr lock */ 406 struct hammer2_trans_queue transq; /* all in-progress transactions */ 407 hammer2_trans_t *curflush; /* current flush in progress */ 408 hammer2_tid_t topo_flush_tid; /* currently synchronizing flush pt */ 409 hammer2_tid_t free_flush_tid; /* currently synchronizing flush pt */ 410 hammer2_off_t heur_freemap[HAMMER2_MAX_RADIX+1]; 411 int flushcnt; /* #of flush trans on the list */ 412 413 int volhdrno; /* last volhdrno written */ 414 hammer2_volume_data_t voldata; 415 hammer2_volume_data_t volsync; /* synchronized voldata */ 416 hammer2_freecache_t freecache[HAMMER2_FREECACHE_TYPES] 417 [HAMMER2_MAX_RADIX+1]; 418 }; 419 420 typedef struct hammer2_mount hammer2_mount_t; 421 422 /* 423 * HAMMER2 cluster - a device/root associated with a PFS. 424 * 425 * A PFS may have several hammer2_cluster's associated with it. 426 */ 427 struct hammer2_cluster { 428 struct hammer2_mount *hmp; /* device global mount */ 429 hammer2_chain_t *rchain; /* PFS root chain */ 430 }; 431 432 typedef struct hammer2_cluster hammer2_cluster_t; 433 434 /* 435 * HAMMER2 PFS mount point structure (aka vp->v_mount->mnt_data). 436 * 437 * This structure represents a cluster mount and not necessarily a 438 * PFS under a specific device mount (HMP). The distinction is important 439 * because the elements backing a cluster mount can change on the fly. 440 */ 441 struct hammer2_pfsmount { 442 struct mount *mp; /* kernel mount */ 443 hammer2_cluster_t *mount_cluster; 444 hammer2_cluster_t *cluster; 445 hammer2_inode_t *iroot; /* PFS root inode */ 446 hammer2_off_t inode_count; /* copy of inode_count */ 447 ccms_domain_t ccms_dom; 448 struct netexport export; /* nfs export */ 449 int ronly; /* read-only mount */ 450 struct malloc_type *minode; 451 struct malloc_type *mmsg; 452 kdmsg_iocom_t iocom; 453 struct spinlock inum_spin; /* inumber lookup */ 454 struct hammer2_inode_tree inum_tree; 455 }; 456 457 typedef struct hammer2_pfsmount hammer2_pfsmount_t; 458 459 struct hammer2_cbinfo { 460 hammer2_chain_t *chain; 461 void (*func)(hammer2_chain_t *, struct buf *, char *, void *); 462 void *arg; 463 size_t boff; 464 }; 465 466 typedef struct hammer2_cbinfo hammer2_cbinfo_t; 467 468 #if defined(_KERNEL) 469 470 MALLOC_DECLARE(M_HAMMER2); 471 472 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data) 473 #define ITOV(ip) ((ip)->vp) 474 475 static __inline 476 int 477 hammer2_devblkradix(int radix) 478 { 479 int cluster_radix; 480 481 if (radix <= HAMMER2_LBUFRADIX) 482 cluster_radix = HAMMER2_LBUFRADIX; 483 else 484 cluster_radix = HAMMER2_PBUFRADIX; 485 return(cluster_radix); 486 } 487 488 static __inline 489 size_t 490 hammer2_devblksize(size_t bytes) 491 { 492 if (bytes <= HAMMER2_LBUFSIZE) { 493 return(HAMMER2_LBUFSIZE); 494 } else { 495 KKASSERT(bytes <= HAMMER2_PBUFSIZE && 496 (bytes ^ (bytes - 1)) == ((bytes << 1) - 1)); 497 return(bytes); 498 } 499 } 500 501 502 static __inline 503 hammer2_pfsmount_t * 504 MPTOPMP(struct mount *mp) 505 { 506 return ((hammer2_pfsmount_t *)mp->mnt_data); 507 } 508 509 static __inline 510 hammer2_mount_t * 511 MPTOHMP(struct mount *mp) 512 { 513 return (((hammer2_pfsmount_t *)mp->mnt_data)->cluster->hmp); 514 } 515 516 static __inline 517 int 518 hammer2_chain_refactor_test(hammer2_chain_t *chain, int traverse_hlink) 519 { 520 if ((chain->flags & HAMMER2_CHAIN_DELETED) && 521 chain->next_parent && 522 (chain->next_parent->flags & HAMMER2_CHAIN_SNAPSHOT) == 0) { 523 return (1); 524 } 525 if (traverse_hlink && 526 chain->bref.type == HAMMER2_BREF_TYPE_INODE && 527 chain->data->ipdata.type == HAMMER2_OBJTYPE_HARDLINK && 528 chain->next_parent && 529 (chain->next_parent->flags & HAMMER2_CHAIN_SNAPSHOT) == 0) { 530 return(1); 531 } 532 533 return (0); 534 } 535 536 extern struct vop_ops hammer2_vnode_vops; 537 extern struct vop_ops hammer2_spec_vops; 538 extern struct vop_ops hammer2_fifo_vops; 539 540 extern int hammer2_debug; 541 extern int hammer2_cluster_enable; 542 extern int hammer2_hardlink_enable; 543 extern long hammer2_iod_file_read; 544 extern long hammer2_iod_meta_read; 545 extern long hammer2_iod_indr_read; 546 extern long hammer2_iod_fmap_read; 547 extern long hammer2_iod_volu_read; 548 extern long hammer2_iod_file_write; 549 extern long hammer2_iod_meta_write; 550 extern long hammer2_iod_indr_write; 551 extern long hammer2_iod_fmap_write; 552 extern long hammer2_iod_volu_write; 553 extern long hammer2_ioa_file_read; 554 extern long hammer2_ioa_meta_read; 555 extern long hammer2_ioa_indr_read; 556 extern long hammer2_ioa_fmap_read; 557 extern long hammer2_ioa_volu_read; 558 extern long hammer2_ioa_file_write; 559 extern long hammer2_ioa_meta_write; 560 extern long hammer2_ioa_indr_write; 561 extern long hammer2_ioa_fmap_write; 562 extern long hammer2_ioa_volu_write; 563 564 /* 565 * hammer2_subr.c 566 */ 567 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size)) 568 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc)) 569 570 hammer2_chain_t *hammer2_inode_lock_ex(hammer2_inode_t *ip); 571 hammer2_chain_t *hammer2_inode_lock_sh(hammer2_inode_t *ip); 572 void hammer2_inode_unlock_ex(hammer2_inode_t *ip, hammer2_chain_t *chain); 573 void hammer2_inode_unlock_sh(hammer2_inode_t *ip, hammer2_chain_t *chain); 574 void hammer2_voldata_lock(hammer2_mount_t *hmp); 575 void hammer2_voldata_unlock(hammer2_mount_t *hmp, int modify); 576 ccms_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip); 577 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip, ccms_state_t ostate); 578 ccms_state_t hammer2_inode_lock_upgrade(hammer2_inode_t *ip); 579 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, ccms_state_t ostate); 580 581 void hammer2_mount_exlock(hammer2_mount_t *hmp); 582 void hammer2_mount_shlock(hammer2_mount_t *hmp); 583 void hammer2_mount_unlock(hammer2_mount_t *hmp); 584 585 int hammer2_get_dtype(hammer2_chain_t *chain); 586 int hammer2_get_vtype(hammer2_chain_t *chain); 587 u_int8_t hammer2_get_obj_type(enum vtype vtype); 588 void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts); 589 u_int64_t hammer2_timespec_to_time(struct timespec *ts); 590 u_int32_t hammer2_to_unix_xid(uuid_t *uuid); 591 void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid); 592 593 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len); 594 int hammer2_getradix(size_t bytes); 595 596 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff, 597 hammer2_key_t *lbasep, hammer2_key_t *leofp); 598 void hammer2_update_time(uint64_t *timep); 599 600 /* 601 * hammer2_inode.c 602 */ 603 struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp); 604 605 void hammer2_inode_lock_nlinks(hammer2_inode_t *ip); 606 void hammer2_inode_unlock_nlinks(hammer2_inode_t *ip); 607 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfsmount_t *pmp, 608 hammer2_tid_t inum); 609 hammer2_inode_t *hammer2_inode_get(hammer2_pfsmount_t *pmp, 610 hammer2_inode_t *dip, hammer2_chain_t *chain); 611 void hammer2_inode_free(hammer2_inode_t *ip); 612 void hammer2_inode_ref(hammer2_inode_t *ip); 613 void hammer2_inode_drop(hammer2_inode_t *ip); 614 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip, 615 hammer2_chain_t *chain); 616 617 hammer2_inode_t *hammer2_inode_create(hammer2_trans_t *trans, 618 hammer2_inode_t *dip, 619 struct vattr *vap, struct ucred *cred, 620 const uint8_t *name, size_t name_len, 621 hammer2_chain_t **chainp, int *errorp); 622 int hammer2_inode_connect(hammer2_trans_t *trans, int hlink, 623 hammer2_inode_t *dip, hammer2_chain_t **chainp, 624 const uint8_t *name, size_t name_len); 625 hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip, 626 hammer2_inode_t *tdip); 627 628 int hammer2_unlink_file(hammer2_trans_t *trans, hammer2_inode_t *dip, 629 const uint8_t *name, size_t name_len, int isdir, 630 int *hlinkp); 631 int hammer2_hardlink_consolidate(hammer2_trans_t *trans, hammer2_inode_t *ip, 632 hammer2_chain_t **chainp, 633 hammer2_inode_t *tdip, int linkcnt); 634 int hammer2_hardlink_deconsolidate(hammer2_trans_t *trans, hammer2_inode_t *dip, 635 hammer2_chain_t **chainp, hammer2_chain_t **ochainp); 636 int hammer2_hardlink_find(hammer2_inode_t *dip, 637 hammer2_chain_t **chainp, hammer2_chain_t **ochainp); 638 639 /* 640 * hammer2_chain.c 641 */ 642 void hammer2_modify_volume(hammer2_mount_t *hmp); 643 hammer2_chain_t *hammer2_chain_alloc(hammer2_mount_t *hmp, 644 hammer2_trans_t *trans, 645 hammer2_blockref_t *bref); 646 void hammer2_chain_core_alloc(hammer2_chain_t *chain, 647 hammer2_chain_core_t *core); 648 void hammer2_chain_ref(hammer2_chain_t *chain); 649 void hammer2_chain_drop(hammer2_chain_t *chain); 650 int hammer2_chain_lock(hammer2_chain_t *chain, int how); 651 void hammer2_chain_load_async(hammer2_chain_t *chain, 652 void (*func)(hammer2_chain_t *, struct buf *, 653 char *, void *), 654 void *arg); 655 void hammer2_chain_moved(hammer2_chain_t *chain); 656 void hammer2_chain_modify(hammer2_trans_t *trans, 657 hammer2_chain_t **chainp, int flags); 658 hammer2_inode_data_t *hammer2_chain_modify_ip(hammer2_trans_t *trans, 659 hammer2_inode_t *ip, hammer2_chain_t **chainp, 660 int flags); 661 void hammer2_chain_resize(hammer2_trans_t *trans, hammer2_inode_t *ip, 662 struct buf *bp, 663 hammer2_chain_t *parent, 664 hammer2_chain_t **chainp, 665 int nradix, int flags); 666 void hammer2_chain_unlock(hammer2_chain_t *chain); 667 void hammer2_chain_wait(hammer2_chain_t *chain); 668 hammer2_chain_t *hammer2_chain_find(hammer2_chain_t *parent, int index); 669 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int index, 670 int flags); 671 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags); 672 void hammer2_chain_lookup_done(hammer2_chain_t *parent); 673 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp, 674 hammer2_key_t key_beg, hammer2_key_t key_end, 675 int flags); 676 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp, 677 hammer2_chain_t *chain, 678 hammer2_key_t key_beg, hammer2_key_t key_end, 679 int flags); 680 int hammer2_chain_create(hammer2_trans_t *trans, 681 hammer2_chain_t **parentp, 682 hammer2_chain_t **chainp, 683 hammer2_key_t key, int keybits, 684 int type, size_t bytes); 685 void hammer2_chain_duplicate(hammer2_trans_t *trans, hammer2_chain_t *parent, 686 int i, 687 hammer2_chain_t **chainp, 688 hammer2_blockref_t *bref); 689 int hammer2_chain_snapshot(hammer2_trans_t *trans, hammer2_inode_t *ip, 690 hammer2_ioc_pfs_t *pfs); 691 void hammer2_chain_delete(hammer2_trans_t *trans, hammer2_chain_t *chain); 692 void hammer2_chain_delete_duplicate(hammer2_trans_t *trans, 693 hammer2_chain_t **chainp, int flags); 694 void hammer2_chain_flush(hammer2_trans_t *trans, hammer2_chain_t *chain); 695 void hammer2_chain_commit(hammer2_trans_t *trans, hammer2_chain_t *chain); 696 void hammer2_chain_setsubmod(hammer2_trans_t *trans, hammer2_chain_t *chain); 697 698 /* 699 * hammer2_trans.c 700 */ 701 void hammer2_trans_init(hammer2_trans_t *trans, 702 hammer2_pfsmount_t *pmp, int flags); 703 void hammer2_trans_done(hammer2_trans_t *trans); 704 705 /* 706 * hammer2_ioctl.c 707 */ 708 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data, 709 int fflag, struct ucred *cred); 710 711 /* 712 * hammer2_msgops.c 713 */ 714 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg); 715 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg); 716 717 /* 718 * hammer2_vfsops.c 719 */ 720 void hammer2_clusterctl_wakeup(kdmsg_iocom_t *iocom); 721 void hammer2_volconf_update(hammer2_pfsmount_t *pmp, int index); 722 void hammer2_cluster_reconnect(hammer2_pfsmount_t *pmp, struct file *fp); 723 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp); 724 725 /* 726 * hammer2_freemap.c 727 */ 728 int hammer2_freemap_alloc(hammer2_trans_t *trans, hammer2_mount_t *hmp, 729 hammer2_blockref_t *bref, size_t bytes); 730 void hammer2_freemap_free(hammer2_mount_t *hmp, hammer2_off_t data_off, 731 int type); 732 733 #endif /* !_KERNEL */ 734 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */ 735