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