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