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