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