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