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