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