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