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