1.\" Copyright (c) 2007 The DragonFly Project. All rights reserved. 2.\" 3.\" This code is derived from software contributed to The DragonFly Project 4.\" by Matthew Dillon <dillon@backplane.com> 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in 14.\" the documentation and/or other materials provided with the 15.\" distribution. 16.\" 3. Neither the name of The DragonFly Project nor the names of its 17.\" contributors may be used to endorse or promote products derived 18.\" from this software without specific, prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 26.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.Dd April 16, 2017 34.Dt HAMMER 8 35.Os 36.Sh NAME 37.Nm hammer 38.Nd HAMMER file system utility 39.Sh SYNOPSIS 40.Nm 41.Fl h 42.Nm 43.Op Fl 2ABFqrvXy 44.Op Fl b Ar bandwidth 45.Op Fl C Ar cachesize Ns Op Ns Cm \&: Ns Ar readahead 46.Op Fl R Ar restrictcmd 47.Op Fl T Ar restrictpath 48.Op Fl c Ar cyclefile 49.Op Fl e Ar scoreboardfile 50.Op Fl f Ar blkdevs 51.\" .Op Fl s Ar linkpath 52.Op Fl i Ar delay 53.Op Fl p Ar ssh-port 54.Op Fl S Ar splitsize 55.Op Fl t Ar seconds 56.Op Fl m Ar memlimit 57.Ar command 58.Op Ar argument ... 59.Sh DESCRIPTION 60This manual page documents the 61.Nm 62utility which provides miscellaneous functions related to managing a 63.Nm HAMMER 64file system. 65For a general introduction to the 66.Nm HAMMER 67file system, its features, and 68examples on how to set up and maintain one, see 69.Xr HAMMER 5 . 70.Pp 71The options are as follows: 72.Bl -tag -width indent 73.It Fl 2 74Tell the mirror commands to use a 2-way protocol, which allows 75automatic negotiation of transaction id ranges. 76This option is automatically enabled by the 77.Cm mirror-copy 78command. 79.It Fl A 80Make per PFS commands perform on all PFSs if possible. 81If the command supports this option, it targets all PFSs of the 82.Nm HAMMER 83filesystem that the 84.Ar filesystem 85argument (of that command) belongs to. 86Currently 87.Cm rebalance , 88.Cm reblock , 89.Cm reblock-btree , 90.Cm reblock-inodes , 91.Cm reblock-dirs 92and 93.Cm reblock-data 94commands support this option. 95If the command does not support this option, it does nothing. 96.It Fl B 97Bulk transfer. 98.Cm Mirror-stream 99will not attempt to break-up large initial bulk transfers into smaller 100pieces. 101This can save time but if the link is lost in the middle of the 102initial bulk transfer you will have to start over from scratch. 103For more information see the 104.Fl S 105option. 106.It Fl b Ar bandwidth 107Specify a bandwidth limit in bytes per second for mirroring streams. 108This option is typically used to prevent batch mirroring operations from 109loading down the machine. 110The bandwidth may be suffixed with 111.Cm k , m , 112or 113.Cm g 114to specify values in kilobytes, megabytes, and gigabytes per second. 115If no suffix is specified, bytes per second is assumed. 116.Pp 117Unfortunately this is only applicable to the pre-compression bandwidth 118when compression is used, so a better solution would probably be to 119use a 120.Xr ipfw 8 121pipe or a 122.Xr pf 4 123queue. 124.It Fl C Ar cachesize Ns Op Ns Cm \&: Ns Ar readahead 125Set the memory cache size for any raw 126.Tn I/O . 127The default is 16MB. 128A suffix of 129.Cm k 130for kilobytes and 131.Cm m 132for megabytes is allowed, 133else the cache size is specified in bytes. 134.Pp 135The read-behind/read-ahead defaults to 4 136.Nm HAMMER 137blocks. 138.Pp 139This option is typically only used with diagnostic commands 140as kernel-supported commands will use the kernel's buffer cache. 141.It Fl R Ar restrictcmd 142This option is used by hammer ssh-remote to restrict the command later 143on in the argument list. Multiple commands may be specified, separated 144by a comma (all one argument). 145.It Fl T Ar restrictpath 146This option is used by hammer ssh-remote to restrict the filesystem path 147specified later on in the argument list. 148.It Fl c Ar cyclefile 149When pruning, rebalancing or reblocking you can tell the utility 150to start at the object id stored in the specified file. 151If the file does not exist 152.Nm 153will start at the beginning. 154If 155.Nm 156is told to run for a specific period of time 157.Pq Fl t 158and is unable to complete the operation it will write out 159the current object id so the next run can pick up where it left off. 160If 161.Nm 162runs to completion it will delete 163.Ar cyclefile . 164.It Fl e Ar scoreboardfile 165Update scoreboard file with progress, primarily used by mirror-stream. 166.It Fl F 167Force operation. 168E.g.\& 169.Cm cleanup 170will not check that time period has elapsed if this option is given. 171.It Fl f Ar blkdevs 172Specify the volumes making up a 173.Nm HAMMER 174file system. 175.Ar Blkdevs 176is a colon-separated list of devices, each specifying a 177.Nm HAMMER 178volume. 179.It Fl h 180Show usage. 181.It Fl i Ar delay 182Specify delay in seconds for 183.Cm mirror-read-stream . 184When maintaining a streaming mirroring this option specifies the 185minimum delay after a batch ends before the next batch is allowed 186to start. 187The default is five seconds. 188.It Fl m Ar memlimit 189Specify the maximum amount of memory 190.Nm 191will allocate during a dedup pass. 192Specify a suffix 'm', 'g', or 't' for megabytes, gigabytes, or terabytes. 193By default 194.Nm 195will allocate up to 1G of ram to hold CRC/SHA tables while running dedup. 196When the limit is reached the dedup code restricts the range of CRCs to 197keep memory use within bounds and runs multiple passes as necessary until 198the entire filesystem has been deduped. 199.It Fl p Ar ssh-port 200Pass the 201.Fl p Ar ssh-port 202option to 203.Xr ssh 1 204when using a remote 205specification for the source and/or destination. 206.It Fl q 207Decrease verboseness. 208May be specified multiple times. 209.It Fl r 210Specify recursion for those commands which support it. 211.It Fl S Ar splitsize 212Specify the bulk splitup size in bytes for mirroring streams. 213When a 214.Cm mirror-stream 215is first started 216.Nm 217will do an initial run-through of the data to calculate good 218transaction ids to cut up the bulk transfers, creating 219restart points in case the stream is interrupted. 220If we don't do this and the stream is interrupted it might 221have to start all over again. 222The default is a 223.Ar splitsize 224of 4GB. 225.Pp 226At the moment the run-through is disk-bandwidth-heavy but some 227future version will limit the run-through to just the B-Tree 228records and not the record data. 229.Pp 230The splitsize may be suffixed with 231.Cm k , m , 232or 233.Cm g 234to specify values in kilobytes, megabytes, or gigabytes. 235If no suffix is specified, bytes is assumed. 236.Pp 237When mirroring very large filesystems the minimum recommended 238split size is 4GB. 239A small split size may wind up generating a great deal of overhead 240but very little actual incremental data and is not recommended. 241.It Fl t Ar seconds 242Specify timeout in seconds. 243When pruning, rebalancing, reblocking or mirror-reading 244you can tell the utility to stop after a certain period of time. 245A value of 0 means unlimited. 246This option is used along with the 247.Fl c Ar cyclefile 248option to prune, rebalance or reblock incrementally. 249.It Fl v 250Increase verboseness. 251May be specified multiple times. 252.It Fl X 253Enable compression for any remote ssh specifications. 254This option is typically used with the mirroring directives. 255.It Fl y 256Force 257.Dq yes 258for interactive questions. 259.El 260.Pp 261The commands are as follows: 262.Bl -tag -width indent 263.\" ==== synctid ==== 264.It Cm synctid Ar filesystem Op Cm quick 265Generate a guaranteed, formal 64-bit transaction id representing the 266current state of the specified 267.Nm HAMMER 268file system. 269The file system will be synced to the media. 270.Pp 271If the 272.Cm quick 273keyword is specified the file system will be soft-synced, meaning that a 274crash might still undo the state of the file system as of the transaction 275id returned but any new modifications will occur after the returned 276transaction id as expected. 277.Pp 278This operation does not create a snapshot. 279It is meant to be used 280to track temporary fine-grained changes to a subset of files and 281will only remain valid for 282.Ql @@ 283access purposes for the 284.Cm prune-min 285period configured for the PFS. 286If you desire a real snapshot then the 287.Cm snapq 288directive may be what you are looking for. 289.\" ==== bstats ==== 290.It Cm bstats Op Ar interval 291Output 292.Nm HAMMER 293B-Tree statistics until interrupted. 294Pause 295.Ar interval 296seconds between each display. 297The default interval is one second. 298.\" ==== iostats ==== 299.It Cm iostats Op Ar interval 300Output 301.Nm HAMMER 302.Tn I/O 303statistics until interrupted. 304Pause 305.Ar interval 306seconds between each display. 307The default interval is one second. 308.\" ==== stats ==== 309.It Cm stats Op Ar interval 310Output 311.Nm HAMMER 312B-Tree and 313.Tn I/O 314statistics until interrupted. 315Pause 316.Ar interval 317seconds between each display. 318The default interval is one second. 319.\" ==== history ==== 320.It Cm history Ns Oo Cm @ Ns Ar offset Ns Oo Cm \&, Ns Ar length Oc Oc Ar path Ns Oo Cm @ Ns Ar offset Ns Oo Cm \&, Ns Ar length Oc Oc Ar ... 321Show the modification history for inode and data of 322.Nm HAMMER 323files. 324If 325.Ar offset 326is given history is shown for data block at given offset, 327otherwise history is shown for inode. 328If 329.Fl v 330is specified 331.Ar length 332data bytes at given offset are dumped for each version, 333default is 32. 334.Pp 335For each 336.Ar path 337this directive shows object id and sync status, 338and for each object version it shows transaction id and time stamp. 339Files has to exist for this directive to be applicable, 340to track inodes which has been deleted or renamed see 341.Xr undo 1 . 342.Pp 343Different 344.Ar offset 345and 346.Ar length 347can be used for each 348.Ar path 349by specifying 350.Ar offset 351and 352.Ar length 353for each 354.Ar path . 355.\" ==== blockmap ==== 356.It Cm blockmap 357Dump the blockmap for the file system. 358The 359.Nm HAMMER 360blockmap is two-layer 361blockmap representing the maximum possible file system size of 1 Exabyte. 362Needless to say the second layer is only present for blocks which exist. 363.Nm HAMMER Ns 's 364blockmap represents 8-Megabyte blocks, called big-blocks. 365Each big-block has an append 366point, a free byte count, and a typed zone id which allows content to be 367reverse engineered to some degree. 368.Pp 369In 370.Nm HAMMER 371allocations are essentially appended to a selected big-block using 372the append offset and deducted from the free byte count. 373When space is freed the free byte count is adjusted but 374.Nm HAMMER 375does not track holes in big-blocks for reallocation. 376A big-block must be completely freed, either 377through normal file system operations or through reblocking, before 378it can be reused. 379.Pp 380Data blocks can be shared by deducting the space used from the free byte 381count for each shared references. 382This means the free byte count can legally go negative. 383.Pp 384This command needs the 385.Fl f Ar blkdevs 386option. 387.\" ==== checkmap ==== 388.It Cm checkmap 389Check the blockmap allocation count. 390.Nm 391will scan the freemap, B-Tree, UNDO/REDO FIFO, then collect allocation information, 392and construct a blockmap in-memory. 393It will then check that blockmap against the on-disk blockmap. 394.Pp 395This command needs the 396.Fl f Ar blkdevs 397option. 398.\" ==== show ==== 399.It Cm show Op Ar localization Ns Op Cm \&: Ns Ar object_id Ns Op Cm \&: Ns Ar rec_type Ns Op Cm \&: Ns Ar key Ns Op Cm \&: Ns Ar create_tid 400Dump the B-Tree. 401By default this command will validate all B-Tree 402linkages and CRCs, including data CRCs, and will report the most verbose 403information it can dig up. 404Any errors will show up with a 405.Ql B 406in column 1 along with various 407other error flags. 408.Pp 409If you specify 410.Ar localization 411or 412.Ar localization Ns Cm \&: Ns Ar object_id 413or 414.Ar localization Ns Cm \&: Ns Ar object_id Ns Cm \&: Ns Ar rec_type 415or 416.Ar localization Ns Cm \&: Ns Ar object_id Ns Cm \&: Ns Ar rec_type Ns Cm \&: Ns Ar key 417or 418.Ar localization Ns Cm \&: Ns Ar object_id Ns Cm \&: Ns Ar rec_type Ns Cm \&: Ns Ar key Ns Cm \&: Ns Ar create_tid 419the dump will 420search for the key printing nodes as it recurses down, and then 421will iterate forwards. 422These fields are specified in HEX. 423Note that the PFS id is the top 16 bits of the 32-bit localization 424field so PFS#1 would be 00010000. 425.Pp 426If you use 427.Fl q 428the command will report less information about the inode contents. 429.Pp 430If you use 431.Fl qq 432the command will not report the content of the inode or other typed 433data at all. 434.Pp 435If you use 436.Fl qqq 437the command will not report volume header information, big-block fill 438ratios, mirror transaction ids, or report or check data CRCs. 439B-Tree CRCs and linkages are still checked. 440.Pp 441This command needs the 442.Fl f Ar blkdevs 443option. 444.\" ==== show-undo ==== 445.It Cm show-undo 446.Nm ( HAMMER 447VERSION 4+) 448Dump the UNDO/REDO map. 449.Pp 450This command needs the 451.Fl f Ar blkdevs 452option. 453.\" .It Ar blockmap 454.\" Dump the B-Tree, record, large-data, and small-data blockmaps, showing 455.\" physical block assignments and free space percentages. 456.\" ==== ssh-remote ==== 457.It Cm ssh-remote Ar command Ar targetdir 458Used in a ssh authorized_keys line such as 459command="/sbin/hammer ssh-remote mirror-read /fubarmount" ... to allow 460mirror-read or mirror-write access to a particular subdirectory tree. 461This way you do not have to give shell access to the remote box. 462.Nm 463will obtain the original command line from the SSH_ORIGINAL_COMMAND 464environment variable, validate it against the restriction, and then 465re-exec hammer with the validated arguments. 466.Pp 467The remote hammer command does not allow the 468.Fl c 469or 470.Fl f 471options to be passed in. 472.\" ==== recover ==== 473.It Cm recover Ar targetdir Op Cm full|quick 474Recover data from a corrupted 475.Nm HAMMER 476filesystem. 477This is a low level command which operates on the filesystem image and 478attempts to locate and recover files from a corrupted filesystem. 479The entire image is scanned linearly looking for B-Tree nodes. 480Any node 481found which passes its CRC test is scanned for file, inode, and directory 482fragments and the target directory is populated with the resulting data. 483files and directories in the target directory are initially named after 484the object id and are renamed as fragmentary information is processed. 485.Pp 486This command keeps track of filename/object_id translations and may eat a 487considerably amount of memory while operating. 488.Pp 489This command is literally the last line of defense when it comes to 490recovering data from a dead filesystem. 491.Pp 492If the 493.Cm full 494keyword is specified, this command scans all the big-blocks within the 495entire image, regardless of whether big-blocks contain active data or meta-data. 496By default, it linearly scans only up to the last big-block that contains 497active data or meta-data, if such big-block is detectable. 498.Pp 499If the 500.Cm quick 501keyword is specified, this command only scans big-blocks that contain 502B-Tree nodes and associated records, without linearly scanning the entire image. 503This may speed up the recovery process provided that big-blocks for 504B-Tree nodes are not corrupted. 505.Pp 506This command needs the 507.Fl f Ar blkdevs 508option. 509.\" ==== strip ==== 510.It Cm strip 511Strip 512.Nm HAMMER 513filesystem volume header and other meta-data by overwriting them with irrelevant data. 514.Nm HAMMER 515volumes need to be unmounted. 516.Pp 517This is a fast way to make 518.Nm HAMMER 519filesystem unmountable and unrecoverable. 520After running this command, 521.Nm HAMMER 522filesystem data is no longer recoverable using 523.Cm recover 524command, although the data still exists within the volumes. 525As safety measure the 526.Fl y 527flag have no effect on this directive. 528.Pp 529This command needs the 530.Fl f Ar blkdevs 531option. 532.\" ==== namekey1 ==== 533.It Cm namekey1 Ar filename 534Generate a 535.Nm HAMMER 53664-bit directory hash for the specified file name, using 537the original directory hash algorithm in version 1 of the file system. 538The low 32 bits are used as an iterator for hash collisions and will be 539output as 0. 540.\" ==== namekey2 ==== 541.It Cm namekey2 Ar filename 542Generate a 543.Nm HAMMER 54464-bit directory hash for the specified file name, using 545the new directory hash algorithm in version 2 of the file system. 546The low 32 bits are still used as an iterator but will start out containing 547part of the hash key. 548.\" ==== namekey32 ==== 549.It Cm namekey32 Ar filename 550Generate the top 32 bits of a 551.Nm HAMMER 55264 bit directory hash for the specified file name. 553.\" ==== info ==== 554.It Cm info Ar dirpath ... 555Show extended information about all 556.Nm HAMMER 557file systems mounted in the system or the one mounted in 558.Ar dirpath 559when this argument is specified. 560.Pp 561The information is divided into sections: 562.Bl -tag -width indent 563.It Volume identification 564General information, like the label of the 565.Nm HAMMER 566filesystem, the number of volumes it contains, the FSID, and the 567.Nm HAMMER 568version being used. 569.It Big-block information 570Big-block statistics, such as total, used, reserved and free big-blocks. 571.It Space information 572Information about space used on the filesystem. 573Currently total size, used, reserved and free space are displayed. 574.It PFS information 575Basic information about the PFSs currently present on a 576.Nm HAMMER 577filesystem. 578.Pp 579.Dq PFS ID 580is the ID of the PFS, with 0 being the root PFS. 581.Dq Snaps 582is the current snapshot count on the PFS. 583.Dq Mounted on 584displays the mount point of the PFS is currently mounted on (if any). 585.El 586.\" ==== cleanup ==== 587.It Cm cleanup Op Ar filesystem ... 588This is a meta-command which executes snapshot, prune, rebalance, dedup 589and reblock commands on the specified 590.Nm HAMMER 591file systems. 592If no 593.Ar filesystem 594is specified this command will clean-up all 595.Nm HAMMER 596file systems in use, including PFS's. 597To do this it will scan all 598.Nm HAMMER 599and 600.Nm null 601mounts, extract PFS id's, and clean-up each PFS found. 602.Pp 603This command will access a snapshots 604directory and a configuration file for each 605.Ar filesystem , 606creating them if necessary. 607.Bl -tag -width indent 608.It Nm HAMMER No version 2- 609The configuration file is 610.Pa config 611in the snapshots directory which defaults to 612.Pa <pfs>/snapshots . 613.It Nm HAMMER No version 3+ 614The configuration file is saved in file system meta-data, see 615.Nm 616.Cm config . 617The snapshots directory defaults to 618.Pa /var/hammer/<pfs> 619.Pa ( /var/hammer/root 620for root mount). 621.El 622.Pp 623The format of the configuration file is: 624.Bd -literal -offset indent 625snapshots <period> <retention-time> [any] 626prune <period> <max-runtime> 627rebalance <period> <max-runtime> 628dedup <period> <max-runtime> 629reblock <period> <max-runtime> 630recopy <period> <max-runtime> 631.Ed 632.Pp 633Defaults are: 634.Bd -literal -offset indent 635snapshots 1d 60d # 0d 0d for PFS /tmp, /var/tmp, /usr/obj 636prune 1d 5m 637rebalance 1d 5m 638#dedup 1d 5m # not enabled by default 639reblock 1d 5m 640recopy 30d 10m 641.Ed 642.Pp 643Time is given with a suffix of 644.Cm d , 645.Cm h , 646.Cm m 647or 648.Cm s 649meaning day, hour, minute and second. 650.Pp 651If the 652.Cm snapshots 653directive has a period of 0 and a retention time of 0 654then snapshot generation is disabled, removal of old snapshots are 655disabled, and prunes will use 656.Cm prune-everything . 657.Pp 658If the 659.Cm snapshots 660directive has a period of 0 but a non-zero retention time 661then this command will not create any new snapshots but will remove old 662snapshots it finds based on the retention time. 663This form should be 664used on PFS masters where you are generating your own snapshot softlinks 665manually and on PFS slaves when all you wish to do is prune away existing 666snapshots inherited via the mirroring stream. 667.Pp 668By default only snapshots in the form 669.Ql snap- Ns Ar yyyymmdd Ns Op - Ns Ar HHMM 670are processed. 671If the 672.Cm any 673directive is specified as a third argument on the 674.Cm snapshots 675config line then any softlink of the form 676.Ql *- Ns Ar yyyymmdd Ns Op - Ns Ar HHMM 677or 678.Ql *. Ns Ar yyyymmdd Ns Op - Ns Ar HHMM 679will be processed. 680.Pp 681A period of 0 for prune, rebalance, dedup, reblock or recopy disables the directive. 682A max-runtime of 0 means unlimited. 683.Pp 684If period hasn't passed since the previous 685.Cm cleanup 686run nothing is done. 687For example a day has passed when midnight is passed (localtime). 688If the 689.Fl F 690flag is given the period is ignored. 691By default, 692.Dx 693is set up to run 694.Nm Cm cleanup 695nightly via 696.Xr periodic 8 . 697.Pp 698The default configuration file will create a daily snapshot, do a daily 699pruning, rebalancing, deduping and reblocking run and a monthly recopy run. 700Reblocking is defragmentation with a level of 95%, 701and recopy is full defragmentation. 702.Pp 703By default prune, dedup and rebalance operations are time limited to 5 minutes, 704and reblock operations to a bit over 5 minutes, 705and recopy operations to a bit over 10 minutes. 706Reblocking and recopy runs are each broken down into four separate functions: 707B-Tree, inodes, dirs and data. 708Each function is time limited to the time given in the configuration file, 709but the B-Tree, inodes and dirs functions usually does not take very long time, 710full defragmentation is always used for these three functions. 711Also note that this directive will by default disable snapshots on 712the following PFS's: 713.Pa /tmp , 714.Pa /var/tmp 715and 716.Pa /usr/obj . 717.Pp 718The defaults may be adjusted by modifying the configuration file. 719The pruning and reblocking commands automatically maintain a cyclefile 720for incremental operation. 721If you interrupt (^C) the program the cyclefile will be updated, 722but a sub-command 723may continue to run in the background for a few seconds until the 724.Nm HAMMER 725ioctl detects the interrupt. 726The 727.Cm snapshots 728PFS option can be set to use another location for the snapshots directory. 729.Pp 730Work on this command is still in progress. 731Expected additions: 732An ability to remove snapshots dynamically as the 733file system becomes full. 734.\" ==== abort-cleanup ==== 735.It Cm abort-cleanup 736This command will terminate all active 737.Cm cleanup 738processes. 739.\" ==== config ==== 740.It Cm config Op Ar filesystem Op Ar configfile 741.Nm ( HAMMER 742VERSION 3+) 743Show or change configuration for 744.Ar filesystem . 745If zero or one arguments are specified this function dumps the current 746configuration file to stdout. 747Zero arguments specifies the PFS containing the current directory. 748This configuration file is stored in file system meta-data. 749If two arguments are specified this function installs a new configuration file 750.Ar configfile . 751.Pp 752In 753.Nm HAMMER 754versions less than 3 the configuration file is by default stored in 755.Pa <pfs>/snapshots/config , 756but in all later versions the configuration file is stored in file system 757meta-data. 758.\" ==== viconfig ==== 759.It Cm viconfig Op Ar filesystem 760.Nm ( HAMMER 761VERSION 3+) 762Edit the configuration file and reinstall into file system meta-data when done. 763Zero arguments specifies the PFS containing the current directory. 764.\" ==== volume-add ==== 765.It Cm volume-add Ar device Ar filesystem 766Add volume 767.Ar device 768to 769.Ar filesystem . 770This will format 771.Ar device 772and add all of its space to 773.Ar filesystem . 774A 775.Nm HAMMER 776file system can use up to 256 volumes. 777.Pp 778.Em NOTE! 779All existing data contained on 780.Ar device 781will be destroyed by this operation! 782If 783.Ar device 784contains a valid 785.Nm HAMMER 786file system, formatting will be denied. 787You can overcome this sanity check by using 788.Xr dd 1 789to erase the beginning sectors of the device. 790.Pp 791Remember that you have to specify 792.Ar device , 793together with any other device that make up the file system, 794colon-separated to 795.Pa /etc/fstab 796and 797.Xr mount_hammer 8 . 798If 799.Ar filesystem 800is root file system, also remember to add 801.Ar device 802to 803.Va vfs.root.mountfrom 804in 805.Pa /boot/loader.conf , 806see 807.Xr loader 8 . 808.\" ==== volume-del ==== 809.It Cm volume-del Ar device Ar filesystem 810Remove volume 811.Ar device 812from 813.Ar filesystem . 814.Pp 815Remember that you have to remove 816.Ar device 817from the colon-separated list in 818.Pa /etc/fstab 819and 820.Xr mount_hammer 8 . 821If 822.Ar filesystem 823is root file system, also remember to remove 824.Ar device 825from 826.Va vfs.root.mountfrom 827in 828.Pa /boot/loader.conf , 829see 830.Xr loader 8 . 831.Pp 832It is not possible to remove the 833.Ar root-volume 834as it contains 835.Ar filesystem 836meta data such as 837.Nm HAMMER Ns 's 838layer1 blockmap and UNDO/REDO FIFO. 839.Pp 840This command may 841.Cm reblock 842filesystem before it attempts to remove the volume if the volume is not empty. 843.\" ==== volume-list ==== 844.It Cm volume-list Ar filesystem 845List the volumes that make up 846.Ar filesystem . 847If -v is specified the command shows volume number for each volume as well as 848.Ar root-volume 849information. 850.\" ==== volume-blkdevs ==== 851.It Cm volume-blkdevs Ar filesystem 852List the volumes that make up 853.Ar filesystem 854in 855.Ar blkdevs 856format. 857.\" ==== snapshot ==== 858.It Cm snapshot Oo Ar filesystem Oc Ar snapshot-dir 859.It Cm snapshot Ar filesystem Ar snapshot-dir Op Ar note 860Take a snapshot of the file system either explicitly given by 861.Ar filesystem 862or implicitly derived from the 863.Ar snapshot-dir 864argument and creates a symlink in the directory provided by 865.Ar snapshot-dir 866pointing to the snapshot. 867If 868.Ar snapshot-dir 869is not a directory, it is assumed to be a format string passed to 870.Xr strftime 3 871with the current time as parameter. 872If 873.Ar snapshot-dir 874refers to an existing directory, a default format string of 875.Ql snap-%Y%m%d-%H%M 876is assumed and used as name for the newly created symlink. 877.Pp 878Snapshot is a per PFS operation, so each PFS in a 879.Nm HAMMER 880file system have to be snapshot separately. 881.Pp 882Example, assuming that 883.Pa /mysnapshots 884is on file system 885.Pa / 886and that 887.Pa /obj 888and 889.Pa /usr 890are file systems on their own, the following invocations: 891.Bd -literal -offset indent 892hammer snapshot /mysnapshots 893 894hammer snapshot /mysnapshots/%Y-%m-%d 895 896hammer snapshot /obj /mysnapshots/obj-%Y-%m-%d 897 898hammer snapshot /usr /my/snaps/usr "note" 899.Ed 900.Pp 901Would create symlinks similar to: 902.Bd -literal -offset indent 903/mysnapshots/snap-20080627-1210 -> /@@0x10d2cd05b7270d16 904 905/mysnapshots/2008-06-27 -> /@@0x10d2cd05b7270d16 906 907/mysnapshots/obj-2008-06-27 -> /obj@@0x10d2cd05b7270d16 908 909/my/snaps/usr/snap-20080627-1210 -> /usr@@0x10d2cd05b7270d16 910.Ed 911.Pp 912When run on a 913.Nm HAMMER 914version 3+ file system the snapshot is also recorded in file system meta-data 915along with the optional 916.Ar note . 917See the 918.Cm snapls 919directive. 920.\" ==== snap* ==== 921.It Cm snap Ar path Op Ar note 922.Nm ( HAMMER 923VERSION 3+) 924Create a snapshot for the PFS containing 925.Ar path 926and create a snapshot softlink. 927If the path specified is a 928directory a standard snapshot softlink will be created in the directory. 929The snapshot softlink points to the base of the mounted PFS. 930.It Cm snaplo Ar path Op Ar note 931.Nm ( HAMMER 932VERSION 3+) 933Create a snapshot for the PFS containing 934.Ar path 935and create a snapshot softlink. 936If the path specified is a 937directory a standard snapshot softlink will be created in the directory. 938The snapshot softlink points into the directory it is contained in. 939.It Cm snapq Ar dir Op Ar note 940.Nm ( HAMMER 941VERSION 3+) 942Create a snapshot for the PFS containing the specified directory but do 943not create a softlink. 944Instead output a path which can be used to access 945the directory via the snapshot. 946.Pp 947An absolute or relative path may be specified. 948The path will be used as-is as a prefix in the path output to stdout. 949As with the other 950snap and snapshot directives the snapshot transaction id will be registered 951in the file system meta-data. 952.It Cm snaprm Ar path Ar ... 953.It Cm snaprm Ar transaction_id Ar ... 954.It Cm snaprm Ar filesystem Ar transaction_id Ar ... 955.Nm ( HAMMER 956VERSION 3+) 957Remove a snapshot given its softlink or transaction id. 958If specifying a transaction id 959the snapshot is removed from file system meta-data but you are responsible 960for removing any related softlinks. 961.Pp 962If a softlink path is specified the filesystem and transaction id 963is derived from the contents of the softlink. 964If just a transaction id is specified it is assumed to be a snapshot in the 965.Nm HAMMER 966filesystem you are currently chdir'd into. 967You can also specify the filesystem and transaction id explicitly. 968.It Cm snapls Op Ar path ... 969.Nm ( HAMMER 970VERSION 3+) 971Dump the snapshot meta-data for PFSs containing each 972.Ar path 973listing all available snapshots and their notes. 974If no arguments are specified snapshots for the PFS containing the 975current directory are listed. 976This is the definitive list of snapshots for the file system. 977.\" ==== prune ==== 978.It Cm prune Ar softlink-dir 979Prune the file system based on previously created snapshot softlinks. 980Pruning is the act of deleting file system history. 981The 982.Cm prune 983command will delete file system history such that 984the file system state is retained for the given snapshots, 985and all history after the latest snapshot. 986By setting the per PFS parameter 987.Cm prune-min , 988history is guaranteed to be saved at least this time interval. 989All other history is deleted. 990.Pp 991The target directory is expected to contain softlinks pointing to 992snapshots of the file systems you wish to retain. 993The directory is scanned non-recursively and the mount points and 994transaction ids stored in the softlinks are extracted and sorted. 995The file system is then explicitly pruned according to what is found. 996Cleaning out portions of the file system is as simple as removing a 997snapshot softlink and then running the 998.Cm prune 999command. 1000.Pp 1001As a safety measure pruning only occurs if one or more softlinks are found 1002containing the 1003.Ql @@ 1004snapshot id extension. 1005Currently the scanned softlink directory must contain softlinks pointing 1006to a single 1007.Nm HAMMER 1008mount. 1009The softlinks may specify absolute or relative paths. 1010Softlinks must use 20-character 1011.Ql @@0x%016llx 1012transaction ids, as might be returned from 1013.Nm Cm synctid Ar filesystem . 1014.Pp 1015Pruning is a per PFS operation, so each PFS in a 1016.Nm HAMMER 1017file system have to be pruned separately. 1018.Pp 1019Note that pruning a file system may not immediately free-up space, 1020though typically some space will be freed if a large number of records are 1021pruned out. 1022The file system must be reblocked to completely recover all available space. 1023.Pp 1024Example, lets say your that you didn't set 1025.Cm prune-min , 1026and snapshot directory contains the following links: 1027.Bd -literal -offset indent 1028lrwxr-xr-x 1 root wheel 29 May 31 17:57 snap1 -> 1029/usr/obj/@@0x10d2cd05b7270d16 1030 1031lrwxr-xr-x 1 root wheel 29 May 31 17:58 snap2 -> 1032/usr/obj/@@0x10d2cd13f3fde98f 1033 1034lrwxr-xr-x 1 root wheel 29 May 31 17:59 snap3 -> 1035/usr/obj/@@0x10d2cd222adee364 1036.Ed 1037.Pp 1038If you were to run the 1039.Cm prune 1040command on this directory, then the 1041.Nm HAMMER 1042.Pa /usr/obj 1043mount will be pruned to retain the above three snapshots. 1044In addition, history for modifications made to the file system older than 1045the oldest snapshot will be destroyed and history for potentially fine-grained 1046modifications made to the file system more recently than the most recent 1047snapshot will be retained. 1048.Pp 1049If you then delete the 1050.Pa snap2 1051softlink and rerun the 1052.Cm prune 1053command, 1054history for modifications pertaining to that snapshot would be destroyed. 1055.Pp 1056In 1057.Nm HAMMER 1058file system versions 3+ this command also scans the snapshots stored 1059in the file system meta-data and includes them in the prune. 1060.\" ==== prune-everything ==== 1061.It Cm prune-everything Ar filesystem 1062Remove all historical records from 1063.Ar filesystem . 1064Use this directive with caution on PFSs where you intend to use history. 1065.Pp 1066This command does not remove snapshot softlinks but will delete all 1067snapshots recorded in file system meta-data (for file system version 3+). 1068The user is responsible for deleting any softlinks. 1069.Pp 1070Pruning is a per PFS operation, so each PFS in a 1071.Nm HAMMER 1072file system have to be pruned separately. 1073.\" ==== rebalance ==== 1074.It Cm rebalance Ar filesystem Op Ar saturation_percentage 1075Rebalance the B-Tree, nodes with small number of 1076elements will be combined and element counts will be smoothed out 1077between nodes. 1078.Pp 1079The saturation percentage is between 50% and 100%. 1080The default is 85% (the 1081.Sq % 1082suffix is not needed). 1083.Pp 1084Rebalancing is a per PFS operation, so each PFS in a 1085.Nm HAMMER 1086file system have to be rebalanced separately. 1087.\" ==== dedup ==== 1088.It Cm dedup Ar filesystem 1089.Nm ( HAMMER 1090VERSION 5+) 1091Perform offline (post-process) deduplication. 1092Deduplication occurs at 1093the block level, currently only data blocks of the same size can be 1094deduped, metadata blocks can not. 1095The hash function used for comparing 1096data blocks is CRC-32 (CRCs are computed anyways as part of 1097.Nm HAMMER 1098data integrity features, so there's no additional overhead). 1099Since CRC is a weak hash function a byte-by-byte comparison is done 1100before actual deduping. 1101In case of a CRC collision (two data blocks have the same CRC 1102but different contents) the checksum is upgraded to SHA-256. 1103.Pp 1104Currently 1105.Nm HAMMER 1106reblocker may partially blow up (re-expand) dedup (reblocker's normal 1107operation is to reallocate every record, so it's possible for deduped 1108blocks to be re-expanded back). 1109.Pp 1110Deduplication is a per PFS operation, so each PFS in a 1111.Nm HAMMER 1112file system have to be deduped separately. 1113This also 1114means that if you have duplicated data in two different PFSs that data 1115won't be deduped, however the addition of such feature is planned. 1116.Pp 1117The 1118.Fl m Ar memlimit 1119option should be used to limit memory use during the dedup run if the 1120default 1G limit is too much for the machine. 1121.\" ==== dedup-simulate ==== 1122.It Cm dedup-simulate Ar filesystem 1123Shows potential space savings (simulated dedup ratio) one can get after 1124running 1125.Cm dedup 1126command. 1127If the estimated dedup ratio is greater than 1.00 you will see 1128dedup space savings. 1129Remember that this is an estimated number, in 1130practice real dedup ratio will be slightly smaller because of 1131.Nm HAMMER 1132big-block underflows, B-Tree locking issues and other factors. 1133.Pp 1134Note that deduplication currently works only on bulk data so if you 1135try to run 1136.Cm dedup-simulate 1137or 1138.Cm dedup 1139commands on a PFS that contains metadata only (directory entries, 1140softlinks) you will get a 0.00 dedup ratio. 1141.Pp 1142The 1143.Fl m Ar memlimit 1144option should be used to limit memory use during the dedup run if the 1145default 1G limit is too much for the machine. 1146.\" ==== reblock* ==== 1147.It Cm reblock Ar filesystem Op Ar fill_percentage 1148.It Cm reblock-btree Ar filesystem Op Ar fill_percentage 1149.It Cm reblock-inodes Ar filesystem Op Ar fill_percentage 1150.It Cm reblock-dirs Ar filesystem Op Ar fill_percentage 1151.It Cm reblock-data Ar filesystem Op Ar fill_percentage 1152Attempt to defragment and free space for reuse by reblocking a live 1153.Nm HAMMER 1154file system. 1155Big-blocks cannot be reused by 1156.Nm HAMMER 1157until they are completely free. 1158This command also has the effect of reordering all elements, effectively 1159defragmenting the file system. 1160.Pp 1161The default fill percentage is 100% and will cause the file system to be 1162completely defragmented. 1163All specified element types will be reallocated and rewritten. 1164If you wish to quickly free up space instead try specifying 1165a smaller fill percentage, such as 90% or 80% (the 1166.Sq % 1167suffix is not needed). 1168.Pp 1169Since this command may rewrite the entire contents of the disk it is 1170best to do it incrementally from a 1171.Xr cron 8 1172job along with the 1173.Fl c Ar cyclefile 1174and 1175.Fl t Ar seconds 1176options to limit the run time. 1177The file system would thus be defragmented over long period of time. 1178.Pp 1179It is recommended that separate invocations be used for each data type. 1180B-Tree nodes, inodes, and directories are typically the most important 1181elements needing defragmentation. 1182Data can be defragmented over a longer period of time. 1183.Pp 1184Reblocking is a per PFS operation, so each PFS in a 1185.Nm HAMMER 1186file system have to be reblocked separately. 1187.\" ==== pfs-status ==== 1188.It Cm pfs-status Ar dirpath ... 1189Retrieve the mirroring configuration parameters for the specified 1190.Nm HAMMER 1191file systems or pseudo-filesystems (PFS's). 1192.\" ==== pfs-master ==== 1193.It Cm pfs-master Ar dirpath Op Ar options 1194Create a pseudo-filesystem (PFS) inside a 1195.Nm HAMMER 1196file system. 1197Up to 65536 PFSs can be created. 1198Each PFS uses an independent inode numbering space making it suitable 1199for replication. 1200.Pp 1201The 1202.Cm pfs-master 1203directive creates a PFS that you can read, write, and use as a mirroring 1204source. 1205.Pp 1206A PFS can only be truly destroyed with the 1207.Cm pfs-destroy 1208directive. 1209Removing the softlink will not destroy the underlying PFS. 1210.Pp 1211A PFS can only be created in the root PFS, 1212not in a PFS created by 1213.Cm pfs-master 1214or 1215.Cm pfs-slave . 1216.Pp 1217It is recommended that 1218.Ar dirpath 1219is of the form 1220.Pa <fs>/pfs/<name> 1221(i.e.\& located in 1222.Pa PFS 1223directory at root of 1224.Nm HAMMER 1225file system). 1226.Pp 1227It is recommended to use a 1228.Nm null 1229mount to access a PFS, except for root PFS, for more information see 1230.Xr HAMMER 5 . 1231.\" ==== pfs-slave ==== 1232.It Cm pfs-slave Ar dirpath Op Ar options 1233Create a pseudo-filesystem (PFS) inside a 1234.Nm HAMMER 1235file system. 1236Up to 65536 PFSs can be created. 1237Each PFS uses an independent inode numbering space making it suitable 1238for replication. 1239.Pp 1240The 1241.Cm pfs-slave 1242directive creates a PFS that you can use as a mirroring source or target. 1243You will not be able to access a slave PFS until you have completed the 1244first mirroring operation with it as the target (its root directory will 1245not exist until then). 1246.Pp 1247Access to the pfs-slave via the special softlink, as described in the 1248.Sx PSEUDO-FILESYSTEM (PFS) NOTES 1249below, allows 1250.Nm HAMMER 1251to 1252dynamically modify the snapshot transaction id by returning a dynamic result 1253from 1254.Xr readlink 2 1255calls. 1256.Pp 1257A PFS can only be truly destroyed with the 1258.Cm pfs-destroy 1259directive. 1260Removing the softlink will not destroy the underlying PFS. 1261.Pp 1262A PFS can only be created in the root PFS, 1263not in a PFS created by 1264.Cm pfs-master 1265or 1266.Cm pfs-slave . 1267.Pp 1268It is recommended that 1269.Ar dirpath 1270is of the form 1271.Pa <fs>/pfs/<name> 1272(i.e.\& located in 1273.Pa PFS 1274directory at root of 1275.Nm HAMMER 1276file system). 1277.Pp 1278It is recommended to use a 1279.Nm null 1280mount to access a PFS, except for root PFS, for more information see 1281.Xr HAMMER 5 . 1282.\" ==== pfs-update ==== 1283.It Cm pfs-update Ar dirpath Op Ar options 1284Update the configuration parameters for an existing 1285.Nm HAMMER 1286file system or pseudo-filesystem. 1287Options that may be specified: 1288.Bl -tag -width indent 1289.It Cm sync-beg-tid= Ns Ar 0x16llx 1290This is the automatic snapshot access starting transaction id for 1291mirroring slaves. 1292This parameter is normally updated automatically by the 1293.Cm mirror-write 1294directive. 1295.Pp 1296It is important to note that accessing a mirroring slave 1297with a transaction id greater than the last fully synchronized transaction 1298id can result in an unreliable snapshot since you will be accessing 1299data that is still undergoing synchronization. 1300.Pp 1301Manually modifying this field is dangerous and can result in a broken mirror. 1302.It Cm sync-end-tid= Ns Ar 0x16llx 1303This is the current synchronization point for mirroring slaves. 1304This parameter is normally updated automatically by the 1305.Cm mirror-write 1306directive. 1307.Pp 1308Manually modifying this field is dangerous and can result in a broken mirror. 1309.It Cm shared-uuid= Ns Ar uuid 1310Set the shared UUID for this file system. 1311All mirrors must have the same shared UUID. 1312For safety purposes the 1313.Cm mirror-write 1314directives will refuse to operate on a target with a different shared UUID. 1315.Pp 1316Changing the shared UUID on an existing, non-empty mirroring target, 1317including an empty but not completely pruned target, 1318can lead to corruption of the mirroring target. 1319.It Cm unique-uuid= Ns Ar uuid 1320Set the unique UUID for this file system. 1321This UUID should not be used anywhere else, 1322even on exact copies of the file system. 1323.It Cm label= Ns Ar string 1324Set a descriptive label for this file system. 1325.It Cm snapshots= Ns Ar string 1326Specify the snapshots directory which 1327.Nm 1328.Cm cleanup 1329will use to manage this PFS. 1330.Bl -tag -width indent 1331.It Nm HAMMER No version 2- 1332The snapshots directory does not need to be configured for 1333PFS masters and will default to 1334.Pa <pfs>/snapshots . 1335.Pp 1336PFS slaves are mirroring slaves so you cannot configure a snapshots 1337directory on the slave itself to be managed by the slave's machine. 1338In fact, the slave will likely have a 1339.Pa snapshots 1340sub-directory mirrored 1341from the master, but that directory contains the configuration the master 1342is using for its copy of the file system, not the configuration that we 1343want to use for our slave. 1344.Pp 1345It is recommended that 1346.Pa <fs>/var/slaves/<name> 1347be configured for a PFS slave, where 1348.Pa <fs> 1349is the base 1350.Nm HAMMER 1351file system, and 1352.Pa <name> 1353is an appropriate label. 1354.It Nm HAMMER No version 3+ 1355The snapshots directory does not need to be configured for PFS masters or 1356slaves. 1357The snapshots directory defaults to 1358.Pa /var/hammer/<pfs> 1359.Pa ( /var/hammer/root 1360for root mount). 1361.El 1362.Pp 1363You can control snapshot retention on your slave independent of the master. 1364.It Cm snapshots-clear 1365Zero out the 1366.Cm snapshots 1367directory path for this PFS. 1368.It Cm prune-min= Ns Ar N Ns Cm d 1369.It Cm prune-min= Ns Oo Ar N Ns Cm d/ Oc Ns \ 1370Ar hh Ns Op Cm \&: Ns Ar mm Ns Op Cm \&: Ns Ar ss 1371Set the minimum fine-grained data retention period. 1372.Nm HAMMER 1373always retains fine-grained history up to the most recent snapshot. 1374You can extend the retention period further by specifying a non-zero 1375pruning minimum. 1376Any snapshot softlinks within the retention period are ignored 1377for the purposes of pruning (i.e.\& the fine grained history is retained). 1378Number of days, hours, minutes and seconds are given as 1379.Ar N , hh , mm 1380and 1381.Ar ss . 1382.Pp 1383Because the transaction id in the snapshot softlink cannot be used 1384to calculate a timestamp, 1385.Nm HAMMER 1386uses the earlier of the 1387.Fa st_ctime 1388or 1389.Fa st_mtime 1390field of the softlink to 1391determine which snapshots fall within the retention period. 1392Users must be sure to retain one of these two fields when manipulating 1393the softlink. 1394.El 1395.\" ==== pfs-upgrade ==== 1396.It Cm pfs-upgrade Ar dirpath 1397Upgrade a PFS from slave to master operation. 1398The PFS will be rolled back to the current end synchronization transaction id 1399(removing any partial synchronizations), and will then become writable. 1400.Pp 1401.Em WARNING! 1402.Nm HAMMER 1403currently supports only single masters and using 1404this command can easily result in file system corruption 1405if you don't know what you are doing. 1406.Pp 1407This directive will refuse to run if any programs have open descriptors 1408in the PFS, including programs chdir'd into the PFS. 1409.\" ==== pfs-downgrade ==== 1410.It Cm pfs-downgrade Ar dirpath 1411Downgrade a master PFS from master to slave operation. 1412The PFS becomes read-only and access will be locked to its 1413.Cm sync-end-tid . 1414.Pp 1415This directive will refuse to run if any programs have open descriptors 1416in the PFS, including programs chdir'd into the PFS. 1417.\" ==== pfs-destroy ==== 1418.It Cm pfs-destroy Ar dirpath 1419This permanently destroys a PFS. 1420.Pp 1421This directive will refuse to run if any programs have open descriptors 1422in the PFS, including programs chdir'd into the PFS. 1423As safety measure the 1424.Fl y 1425flag have no effect on this directive. 1426.\" ==== mirror-read ==== 1427.It Cm mirror-read Ar filesystem Op Ar begin-tid 1428Generate a mirroring stream to stdout. 1429The stream ends when the transaction id space has been exhausted. 1430.Ar filesystem 1431may be a master or slave PFS. 1432.\" ==== mirror-read-stream ==== 1433.It Cm mirror-read-stream Ar filesystem Op Ar begin-tid 1434Generate a mirroring stream to stdout. 1435Upon completion the stream is paused until new data is synced to the 1436.Ar filesystem , 1437then resumed. 1438Operation continues until the pipe is broken. 1439See the 1440.Cm mirror-stream 1441command for more details. 1442.\" ==== mirror-write ==== 1443.It Cm mirror-write Ar filesystem 1444Take a mirroring stream on stdin. 1445.Ar filesystem 1446must be a slave PFS. 1447.Pp 1448This command will fail if the 1449.Cm shared-uuid 1450configuration field for the two file systems do not match. 1451See the 1452.Cm mirror-copy 1453command for more details. 1454.Pp 1455If the target PFS does not exist this command will ask you whether 1456you want to create a compatible PFS slave for the target or not. 1457.\" ==== mirror-dump ==== 1458.It Ar mirror-dump Ar [header] 1459A 1460.Cm mirror-read 1461can be piped into a 1462.Cm mirror-dump 1463to dump an ASCII representation of the mirroring stream. 1464If the keyword 1465.Ar header 1466is specified, only the header information is shown. 1467.\" ==== mirror-copy ==== 1468.\".It Cm mirror-copy Ar [[user@]host:]filesystem [[user@]host:]filesystem 1469.It Cm mirror-copy \ 1470Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem \ 1471Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem 1472This is a shortcut which pipes a 1473.Cm mirror-read 1474command to a 1475.Cm mirror-write 1476command. 1477If a remote host specification is made the program forks a 1478.Xr ssh 1 1479(or other program as specified by the 1480.Ev HAMMER_RSH 1481environment variable) and execs the 1482.Cm mirror-read 1483and/or 1484.Cm mirror-write 1485on the appropriate host. 1486The source may be a master or slave PFS, and the target must be a slave PFS. 1487.Pp 1488This command also establishes full duplex communication and turns on 1489the 2-way protocol feature 1490.Fl ( 2 ) 1491which automatically negotiates transaction id 1492ranges without having to use a cyclefile. 1493If the operation completes successfully the target PFS's 1494.Cm sync-end-tid 1495will be updated. 1496Note that you must re-chdir into the target PFS to see the updated information. 1497If you do not you will still be in the previous snapshot. 1498.Pp 1499If the target PFS does not exist this command will ask you whether 1500you want to create a compatible PFS slave for the target or not. 1501.\" ==== mirror-stream ==== 1502.\".It Cm mirror-stream Ar [[user@]host:]filesystem [[user@]host:]filesystem 1503.It Cm mirror-stream \ 1504Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem \ 1505Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem 1506This is a shortcut which pipes a 1507.Cm mirror-read-stream 1508command to a 1509.Cm mirror-write 1510command. 1511This command works similarly to 1512.Cm mirror-copy 1513but does not exit after the initial mirroring completes. 1514The mirroring operation will resume as changes continue to be made to the 1515source. 1516The command is commonly used with 1517.Fl i Ar delay 1518and 1519.Fl b Ar bandwidth 1520options to keep the mirroring target in sync with the source on a continuing 1521basis. 1522.Pp 1523If the pipe is broken the command will automatically retry after sleeping 1524for a short while. 1525The time slept will be 15 seconds plus the time given in the 1526.Fl i 1527option. 1528.Pp 1529This command also detects the initial-mirroring case and spends some 1530time scanning the B-Tree to find good break points, allowing the initial 1531bulk mirroring operation to be broken down into 4GB pieces. 1532This means that the user can kill and restart the operation and it will 1533not have to start from scratch once it has gotten past the first chunk. 1534The 1535.Fl S 1536option may be used to change the size of pieces and the 1537.Fl B 1538option may be used to disable this feature and perform an initial bulk 1539transfer instead. 1540.\" ==== version ==== 1541.It Cm version Ar filesystem 1542This command returns the 1543.Nm HAMMER 1544file system version for the specified 1545.Ar filesystem 1546as well as the range of versions supported in the kernel. 1547The 1548.Fl q 1549option may be used to remove the summary at the end. 1550.\" ==== version-upgrade ==== 1551.It Cm version-upgrade Ar filesystem Ar version Op Cm force 1552Upgrade the 1553.Nm HAMMER 1554.Ar filesystem 1555to the specified 1556.Ar version . 1557Once upgraded a file system may not be downgraded. 1558If you wish to upgrade a file system to a version greater or equal to the 1559work-in-progress (WIP) version number you must specify the 1560.Cm force 1561directive. 1562Use of WIP versions should be relegated to testing and may require wiping 1563the file system as development progresses, even though the WIP version might 1564not change. 1565.Pp 1566.Em NOTE! 1567This command operates on the entire 1568.Nm HAMMER 1569file system and is not a per PFS operation. 1570All PFS's will be affected. 1571.Bl -tag -width indent 1572.It 1 1573.Dx 2.0 1574default version, first 1575.Nm HAMMER 1576release. 1577.It 2 1578.Dx 2.3 . 1579New directory entry layout. 1580This version is using a new directory hash key. 1581.It 3 1582.Dx 2.5 . 1583New snapshot management, using file system meta-data for saving 1584configuration file and snapshots (transaction ids etc.). 1585Also default snapshots directory has changed. 1586.It 4 1587.Dx 2.6 1588default version. 1589New undo/redo/flush, giving 1590.Nm HAMMER 1591a much faster sync and fsync. 1592.It 5 1593.Dx 2.9 . 1594Deduplication support. 1595.It 6 1596.Dx 2.9 . 1597Directory hash ALG1. 1598Tends to maintain inode number / directory name entry ordering better 1599for files after minor renaming. 1600.It 7 1601.Dx 4.8 . 1602Use the ISCSI crc32 algorithm instead of our custom polynomial. This makes 1603it easier to use faster cpu implementation of the crc algorithm. CPU 1604overhead is reduced but performance is unlikely to be impacted a whole lot. 1605.El 1606.El 1607.Sh PSEUDO-FILESYSTEM (PFS) NOTES 1608The root of a PFS is not hooked into the primary 1609.Nm HAMMER 1610file system as a directory. 1611Instead, 1612.Nm HAMMER 1613creates a special softlink called 1614.Ql @@PFS%05d 1615(exactly 10 characters long) in the primary 1616.Nm HAMMER 1617file system. 1618.Nm HAMMER 1619then modifies the contents of the softlink as read by 1620.Xr readlink 2 , 1621and thus what you see with an 1622.Nm ls 1623command or if you were to 1624.Nm cd 1625into the link. 1626If the PFS is a master the link reflects the current state of the PFS. 1627If the PFS is a slave the link reflects the last completed snapshot, and the 1628contents of the link will change when the next snapshot is completed, and 1629so forth. 1630.Pp 1631The 1632.Nm 1633utility employs numerous safeties to reduce user foot-shooting. 1634The 1635.Cm mirror-copy 1636directive requires that the target be configured as a slave and that the 1637.Cm shared-uuid 1638field of the mirroring source and target match. 1639The 1640.Cm pfs-master 1641and 1642.Cm pfs-slave 1643directives require that the PFS softlink be created under the main 1644.Nm 1645filesystem mount. You may only access PFS softlinks via the main 1646.Nm 1647filesystem mount. 1648.Sh DOUBLE_BUFFER MODE 1649There is a limit to the number of vnodes the kernel can cache, and because 1650file buffers are associated with a vnode the related data cache can get 1651blown away when operating on large numbers of files even if the system has 1652sufficient memory to hold the file data. 1653.Pp 1654If you turn on 1655.Nm HAMMER Ns 's 1656double buffer mode by setting the 1657.Xr sysctl 8 1658node 1659.Va vfs.hammer.double_buffer 1660to 1 1661.Nm HAMMER 1662will cache file data via the block device and copy it into the per-file 1663buffers as needed. The data will be double-cached at least until the 1664buffer cache throws away the file buffer. 1665This mode is typically used in conjunction with 1666.Xr swapcache 8 1667when 1668.Va vm.swapcache.data_enable 1669is turned on in order to prevent unnecessary re-caching of file data 1670due to vnode recycling. 1671The swapcache will save the cached VM pages related to 1672.Nm HAMMER Ns 's 1673block 1674device (which doesn't recycle unless you umount the filesystem) instead 1675of the cached VM pages backing the file vnodes. 1676.Pp 1677Double buffering is normally desirable when working with large filesystems, 1678particularly when swapcache is used. 1679The swapcache can only back active VM objects, including the block device, 1680and large filesystems often have far more inodes than the kernel can support. 1681In addition, when using this mode, you may wish to reduce the 1682.Va kern.maxvnodes 1683setting for the system to force the system to do less caching of logical 1684file buffers and more caching of device buffers, since the device buffers 1685are backing the logical file buffers. 1686.Sh UPGRADE INSTRUCTIONS HAMMER V1 TO V2 1687This upgrade changes the way directory entries are stored. 1688It is possible to upgrade a V1 file system to V2 in place, but 1689directories created prior to the upgrade will continue to use 1690the old layout. 1691.Pp 1692Note that the slave mirroring code in the target kernel had bugs in 1693V1 which can create an incompatible root directory on the slave. 1694Do not mix a 1695.Nm HAMMER 1696master created after the upgrade with a 1697.Nm HAMMER 1698slave created prior to the upgrade. 1699.Pp 1700Any directories created after upgrading will use a new layout. 1701.Sh UPGRADE INSTRUCTIONS HAMMER V2 TO V3 1702This upgrade adds meta-data elements to the B-Tree. 1703It is possible to upgrade a V2 file system to V3 in place. 1704After issuing the upgrade be sure to run a 1705.Nm 1706.Cm cleanup 1707to perform post-upgrade tasks. 1708.Pp 1709After making this upgrade running a 1710.Nm 1711.Cm cleanup 1712will move the 1713.Pa <pfs>/snapshots 1714directory for each PFS mount into 1715.Pa /var/hammer/<pfs> . 1716A 1717.Nm HAMMER 1718root mount will migrate 1719.Pa /snapshots 1720into 1721.Pa /var/hammer/root . 1722Migration occurs only once and only if you have not specified 1723a snapshots directory in the PFS configuration. 1724If you have specified a snapshots directory in the PFS configuration no 1725automatic migration will occur. 1726.Pp 1727For slaves, if you desire, you can migrate your snapshots 1728config to the new location manually and then clear the 1729snapshot directory configuration in the slave PFS. 1730The new snapshots hierarchy is designed to work with 1731both master and slave PFSs equally well. 1732.Pp 1733In addition, the old config file will be moved to file system meta-data, 1734editable via the new 1735.Nm 1736.Cm viconfig 1737directive. 1738The old config file will be deleted. 1739Migration occurs only once. 1740.Pp 1741The V3 file system has new 1742.Cm snap* 1743directives for creating snapshots. 1744All snapshot directives, including the original, will create 1745meta-data entries for the snapshots and the pruning code will 1746automatically incorporate these entries into its list and 1747expire them the same way it expires softlinks. 1748If you by accident blow away your snapshot softlinks you can use the 1749.Cm snapls 1750directive to get a definitive list from the file system meta-data and 1751regenerate them from that list. 1752.Pp 1753.Em WARNING! 1754If you are using 1755.Nm 1756to backup file systems your scripts may be using the 1757.Cm synctid 1758directive to generate transaction ids. 1759This directive does not create a snapshot. 1760You will have to modify your scripts to use the 1761.Cm snapq 1762directive to generate the linkbuf for the softlink you create, or 1763use one of the other 1764.Cm snap* 1765directives. 1766The older 1767.Cm snapshot 1768directive will continue to work as expected and in V3 it will also 1769record the snapshot transaction id in file system meta-data. 1770You may also want to make use of the new 1771.Ar note 1772tag for the meta-data. 1773.Pp 1774.Em WARNING! 1775If you used to remove snapshot softlinks with 1776.Nm rm 1777you should probably start using the 1778.Cm snaprm 1779directive instead to also remove the related meta-data. 1780The pruning code scans the meta-data so just removing the 1781softlink is not sufficient. 1782.Sh UPGRADE INSTRUCTIONS HAMMER V3 TO V4 1783This upgrade changes undo/flush, giving faster sync. 1784It is possible to upgrade a V3 file system to V4 in place. 1785This upgrade reformats the UNDO/REDO FIFO (typically 1GB), 1786so upgrade might take a minute or two depending. 1787.Pp 1788Version 4 allows the UNDO/REDO FIFO to be flushed without also having 1789to flush the volume header, removing 2 of the 4 disk syncs typically 1790required for an 1791.Fn fsync 1792and removing 1 of the 2 disk syncs typically 1793required for a flush sequence. 1794Version 4 also implements the REDO log (see 1795.Sx FSYNC FLUSH MODES 1796below) which is capable 1797of fsync()ing with either one disk flush or zero disk flushes. 1798.Sh UPGRADE INSTRUCTIONS HAMMER V4 TO V5 1799This upgrade brings in deduplication support. 1800It is possible to upgrade a V4 file system to V5 in place. 1801Technically it makes the layer2 1802.Va bytes_free 1803field a signed value instead of unsigned, allowing it to go negative. 1804A version 5 filesystem is required for dedup operation. 1805.Sh UPGRADE INSTRUCTIONS HAMMER V5 TO V6 1806It is possible to upgrade a V5 file system to V6 in place. 1807.Sh UPGRADE INSTRUCTIONS HAMMER V6 TO V7 1808It is possible to upgrade a V6 file system to V7 in place. 1809After upgrading any new files will use the new, faster CRC. 1810You can convert all existing files to use the new CRC by issuing 1811a full reblock via 'hammer reblock <fs>'. 1812You only have to do this once. 1813.Sh FSYNC FLUSH MODES 1814.Nm HAMMER 1815implements five different fsync flush modes via the 1816.Va vfs.hammer.fsync_mode 1817sysctl, for 1818.Nm HAMMER 1819version 4+ file systems. 1820.Pp 1821As of 1822.Dx 2.6 1823fsync mode 3 is set by default. 1824REDO operation and recovery is enabled by default. 1825.Bl -tag -width indent 1826.It mode 0 1827Full synchronous fsync semantics without REDO. 1828.Pp 1829.Nm HAMMER 1830will not generate REDOs. 1831A 1832.Fn fsync 1833will completely sync 1834the data and meta-data and double-flush the FIFO, including 1835issuing two disk synchronization commands. 1836The data is guaranteed 1837to be on the media as of when 1838.Fn fsync 1839returns. 1840Needless to say, this is slow. 1841.It mode 1 1842Relaxed asynchronous fsync semantics without REDO. 1843.Pp 1844This mode works the same as mode 0 except the last disk synchronization 1845command is not issued. 1846It is faster than mode 0 but not even remotely 1847close to the speed you get with mode 2 or mode 3. 1848.Pp 1849Note that there is no chance of meta-data corruption when using this 1850mode, it simply means that the data you wrote and then 1851.Fn fsync Ns 'd 1852might not have made it to the media if the storage system crashes at a bad 1853time. 1854.It mode 2 1855Full synchronous fsync semantics using REDO. 1856NOTE: If not running a 1857.Nm HAMMER 1858version 4 filesystem or later mode 0 is silently used. 1859.Pp 1860.Nm HAMMER 1861will generate REDOs in the UNDO/REDO FIFO based on a heuristic. 1862If this is sufficient to satisfy the 1863.Fn fsync 1864operation the blocks will be written out and 1865.Nm HAMMER 1866will wait for the I/Os to complete, 1867and then followup with a disk sync command to guarantee the data 1868is on the media before returning. 1869This is slower than mode 3 and can result in significant disk or 1870SSDs overheads, though not as bad as mode 0 or mode 1. 1871.It mode 3 1872Relaxed asynchronous fsync semantics using REDO. 1873NOTE: If not running a 1874.Nm HAMMER 1875version 4 filesystem or later mode 1 is silently used. 1876.Pp 1877.Nm HAMMER 1878will generate REDOs in the UNDO/REDO FIFO based on a heuristic. 1879If this is sufficient to satisfy the 1880.Fn fsync 1881operation the blocks 1882will be written out and 1883.Nm HAMMER 1884will wait for the I/Os to complete, 1885but will 1886.Em NOT 1887issue a disk synchronization command. 1888.Pp 1889Note that there is no chance of meta-data corruption when using this 1890mode, it simply means that the data you wrote and then 1891.Fn fsync Ns 'd 1892might 1893not have made it to the media if the storage system crashes at a bad 1894time. 1895.Pp 1896This mode is the fastest production fsyncing mode available. 1897This mode is equivalent to how the UFS fsync in the 1898.Bx Ns s 1899operates. 1900.It mode 4 1901fsync is ignored. 1902.Pp 1903Calls to 1904.Fn fsync 1905will be ignored. 1906This mode is primarily designed 1907for testing and should not be used on a production system. 1908.El 1909.Sh RESTORING FROM A SNAPSHOT BACKUP 1910You restore a snapshot by copying it over to live, but there is a caveat. 1911The mtime and atime fields for files accessed via a snapshot is locked 1912to the ctime in order to keep the snapshot consistent, because neither 1913mtime nor atime changes roll any history. 1914.Pp 1915In order to avoid unnecessary copying it is recommended that you use 1916.Nm cpdup 1917.Fl VV 1918.Fl v 1919when doing the copyback. 1920Also make sure you traverse the snapshot softlink by appending a ".", 1921as in "<snapshotpath>/.", and you match up the directory properly. 1922.Sh RESTORING A PFS FROM A MIRROR 1923A PFS can be restored from a mirror with 1924.Cm mirror-copy . 1925.Cm config 1926data must be copied separately. 1927At last the PFS can be upgraded to master using 1928.Cm pfs-upgrade . 1929.Pp 1930It is not possible to restore the root PFS by using mirroring, 1931as the root PFS is always a master PFS. 1932A normal copy (e.g.\& using 1933.Xr cpdup 1 ) 1934must be done, ignoring history. 1935If history is important, old root PFS can me restored to a new PFS, and 1936important directories/files can be 1937.Nm null 1938mounted to the new PFS. 1939.Sh ENVIRONMENT 1940The following environment variables affect the execution of 1941.Nm : 1942.Bl -tag -width ".Ev EDITOR" 1943.It Ev EDITOR 1944The editor program specified in the variable 1945.Ev EDITOR 1946will be invoked instead of the default editor, which is 1947.Xr vi 1 . 1948.It Ev HAMMER_RSH 1949The command specified in the variable 1950.Ev HAMMER_RSH 1951will be used to initiate remote operations for the mirror-copy and 1952mirror-stream commands instead of the default command, which is 1953.Xr ssh 1 . 1954The program will be invoked via 1955.Xr execvp 3 1956using a typical 1957.Xr rsh 1 1958style 1959.Cm -l user host <remote-command> 1960command line. 1961.It Ev VISUAL 1962Same effect as 1963.Ev EDITOR 1964variable. 1965.El 1966.Sh FILES 1967.Bl -tag -width ".It Pa <fs>/var/slaves/<name>" -compact 1968.It Pa <pfs>/snapshots 1969default per PFS snapshots directory 1970.Nm ( HAMMER 1971VERSION 2-) 1972.It Pa /var/hammer/<pfs> 1973default per PFS snapshots directory (not root) 1974.Nm ( HAMMER 1975VERSION 3+) 1976.It Pa /var/hammer/root 1977default snapshots directory for root directory 1978.Nm ( HAMMER 1979VERSION 3+) 1980.It Pa <snapshots>/config 1981per PFS 1982.Nm 1983.Cm cleanup 1984configuration file 1985.Nm ( HAMMER 1986VERSION 2-) 1987.It Pa <fs>/var/slaves/<name> 1988recommended slave PFS snapshots directory 1989.Nm ( HAMMER 1990VERSION 2-) 1991.It Pa <fs>/pfs 1992recommended PFS directory 1993.El 1994.Sh EXIT STATUS 1995.Ex -std 1996.Sh SEE ALSO 1997.Xr ssh 1 , 1998.Xr undo 1 , 1999.Xr HAMMER 5 , 2000.Xr periodic.conf 5 , 2001.Xr loader 8 , 2002.Xr mount_hammer 8 , 2003.Xr mount_null 8 , 2004.Xr newfs_hammer 8 , 2005.Xr swapcache 8 , 2006.Xr sysctl 8 2007.Sh HISTORY 2008The 2009.Nm 2010utility first appeared in 2011.Dx 1.11 . 2012.Sh AUTHORS 2013.An Matthew Dillon Aq Mt dillon@backplane.com 2014