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