xref: /dragonfly/sbin/hammer2/hammer2.8 (revision 556932ec)
1.\" Copyright (c) 2015-2023 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 2, 2021
34.Dt HAMMER2 8
35.Os
36.Sh NAME
37.Nm hammer2
38.Nd hammer2 file system utility
39.Sh SYNOPSIS
40.Nm
41.Fl h
42.Nm
43.Op Fl d
44.Op Fl s Ar path
45.Op Fl t Ar type
46.Op Fl u Ar uuid
47.Op Fl m Ar mem
48.Ar command
49.Op Ar argument ...
50.Sh DESCRIPTION
51The
52.Nm
53utility provides miscellaneous support functions for a
54HAMMER2 file system.
55.Pp
56The options are as follows:
57.Bl -tag -width indent
58.It Fl d
59Enables debug mode.
60It can be specified more than once to enable additional debugging messages.
61In some directives it may cause
62.Nm
63to run in foreground instead of being daemonized.
64.It Fl s Ar path
65Specify the path to a mounted HAMMER2 filesystem.
66At least one PFS on a HAMMER2 filesystem must be mounted for the system
67to act on all PFSs managed by it.
68Every HAMMER2 filesystem typically has a PFS called "LOCAL" for this purpose.
69.It Fl t Ar type
70Specify the type when creating, upgrading, or downgrading a PFS.
71Supported types are MASTER, SLAVE, SOFT_MASTER, SOFT_SLAVE, CACHE, and DUMMY.
72If not specified the pfs-create directive will default to MASTER if no
73UUID is specified, and SLAVE if a UUID is specified.
74.It Fl u Ar uuid
75Specify the cluster UUID when creating a PFS.
76If not specified, a unique, random UUID will be generated.
77Note that every PFS also has a unique pfs_id which is always generated
78and cannot be overridden with an option.
79The { pfs_clid, pfs_fsid } tuple uniquely identifies a component of a cluster.
80.It Fl m Ar mem
81Specify how much tracking memory to use for certain directives.
82At the moment, this option is only applicable to the
83.Cm bulkfree
84directive, allowing it to operate in fewer passes when given more memory.
85A nominal value for a 4TB drive with a ton of stuff on it would be around
86a gigabyte '-m 1g'.
87.El
88.Pp
89.Nm
90directives are as shown below.
91Note that most directives require you to either be CD'd into a hammer2
92filesystem, specify a path to a mounted hammer2 filesystem via the
93.Fl s
94option, or specify a path after the directive.
95It depends on the directive.
96All hammer2 filesystem have a PFS called "LOCAL" which is typically mounted
97locally on the host in order to be able to issue commands for other PFSs
98on the filesystem.
99The mount also enables PFS configuration scanning for that filesystem.
100.Bl -tag -width indent
101.\" ==== cleanup ====
102.It Cm cleanup Op path
103Perform manual cleanup passes on paths or all mounted partitions.
104.\" ==== connect ====
105.It Cm connect Ar target
106Add a cluster link entry to the volume header.
107The volume header can support up to 255 link entries.
108This feature is not currently used.
109.\" ==== destroy ====
110.It Cm destroy Ar path...
111Destroy the specified directory entry in a hammer2 filesystem.
112This bypasses
113all normal checks and will unconditionally destroy the directory entry.
114The underlying inode is not checked and, if it does exist, its nlinks count
115is not decremented.
116This directive should only be used to destroy a corrupted directory entry
117which no longer has a working inode.
118.Pp
119Note that this command may desynchronize the system namecache for the
120specified entry.
121If this happens, you may have to unmount and remount the filesystem.
122.\" ==== destroy-inum ====
123.It Cm destroy-inum Ar path...
124Destroy the specified inode in a hammer2 filesystem.
125.\" ==== disconnect ====
126.It Cm disconnect Ar target
127Delete a cluster link entry from the volume header.
128This feature is not currently used.
129.\" ==== emergency-mode-enable ===
130.It Cm emergency-mode-enable Ar target
131Flag emergency operations mode in the filesystem.
132This mode may be used
133as a last resort to delete files and directories from a full filesystem.
134Inode creation, file writes, and certain meta-data cleanups are disallowed
135while emergency mode is active.
136File and directory removal and mode/attr setting is still allowed.
137This mode is extremely dangerous and should only be used as a last resort.
138.Pp
139This mode allows the filesystem to modify blocks in-place when it is unable
140to allocate a copy.
141Thus it is possible to chflags and remove files and
142directories even when the filesystem is completely full.
143However, there is a price.
144This mode of operation WILL LIKELY CORRUPT ANY SNAPSHOTS related
145to this filesystem.
146The filesystem will report this condition if it encounters
147it but if you are forced to use this mode to fix a filesystem full condition
148your snapshots can get a bit dicey.
149It is usually safest to delete any related snapshots when using this mode.
150.Pp
151You can detect whether related snapshots have been corrupted by running
152a bulkfree pass and checking the console output for reported CRC errors.
153If no errors are reported, your snapshots are fine.
154If errors are reported
155you should delete related snapshots until bulkfree reports no further errors.
156.Pp
157The emergency mode will also make meta-data updates unsafe due to the lack of
158copy-on-write, causing potential harm if the system unexpectedly panics or
159loses power.
160GREAT CARE MUST BE TAKEN WHILE THIS MODE IS ACTIVE.
161.Bl -enum
162.It
163Determine that you are unable to recover space with normal file and directory
164removal commands due to
165.Er ENOSPC
166errors being returned by 'rm', or through the
167removal of snapshots (if any).  The 'bulkfree' directive must be issued to
168scan the filesystem and free up the actual space, then check with 'df'.
169Continue if you still have insufficient space and are unable to remove items
170normally.
171.It
172If you need any related snapshots, this is a good time to copy them elsewhere.
173.It
174Idle or kill any processes trying to use the filesystem.
175.It
176Issue the emergency-mode-enable directive on the filesystem.
177Once enabled, run 'sync' to update any dirty inodes which may still
178be dirty due to not being able to flush.
179Please remember that this
180directive is a LAST RESORT, is dangerous, and will likely corrupt any
181other snapshots you have based on the filesystem you are removing files
182from.
183.It
184Remove file trees as necessary with 'rm -rf' to free space, being cognizant
185of any warnings issued by the kernel on the console (via 'dmesg') while
186doing so.
187.It
188Issue the 'bulkfree' directive to actually free the space and check that
189sufficient space has been freed with 'df'.
190.It
191If bulkfree reports CHECK errors, or if you have snapshots and insufficient
192space has been freed, you will need to delete snapshots.
193Re-run bulkfree and delete snapshots until no errors are reported.
194.It
195Issue the emergency-mode-disable directive when done.
196It might also be a
197good idea to reboot after using this mode, but theoretically you should not
198have to.
199.It
200Restore services using the filesystem.
201.El
202.\" ==== emergency-mode-disable ===
203.It Cm emergency-mode-disable Ar target
204Turn off the emergency operations mode on a filesystem, restoring normal
205operation.
206.\" ==== growfs ====
207.It Cm growfs Op fspath...
208After resizing the disk partition you can issue this command on a
209mounted hammer2 filesystem to grow into the new space in the partition.
210This command is run on a live hammer2 filesystem.
211.\" ==== info ====
212.It Cm info Op devpath...
213Access and print the status and super-root entries for all HAMMER2
214partitions found in /dev/serno or the specified device path(s).
215The partitions do not have to be mounted.
216Note that only mounted partitions will be under active management.
217This is accomplished by mounting at least one PFS within the partition.
218Typically at least the @LOCAL PFS is mounted.
219.\" ==== mountall ====
220.It Cm mountall Op devpath...
221This directive mounts the @LOCAL PFS on all HAMMER2 partitions found
222in /dev/serno, or the specified device path(s).
223The partitions are mounted as /var/hammer2/LOCAL.<id>.
224Mounts are executed in the background and this command will wait a
225limited amount of time for the mounts to complete before returning.
226.\" ==== status ====
227.It Cm status Op path...
228Dump a list of all cluster link entries configured in the volume header.
229.\" ==== hash ====
230.It Cm hash Op filename...
231Compute and print the directory hash for any number of filenames.
232.\" ==== dhash ====
233.It Cm dhash Op filename...
234Compute and print the data hash for long directory entry for any number of
235filenames.
236.\" ==== pfs-list ====
237.It Cm pfs-list Op path...
238List all PFSs associated with all mounted hammer2 storage devices.
239The list may be restricted to a particular filesystem using
240.Fl s Ar mount .
241.Pp
242Note that hammer2 PFSs associated with storage devices which have not been
243mounted in any fashion will not be listed.
244At least one hammer2 label must be mounted for the PFSs on that device to be
245visible.
246.\" ==== pfs-clid ====
247.It Cm pfs-clid Ar label
248Print the cluster id for a PFS specified by name.
249.\" ==== pfs-fsid ====
250.It Cm pfs-fsid Ar label
251Print the unique filesystem id for a PFS specified by name.
252.\" ==== pfs-create ====
253.It Cm pfs-create Ar label
254Create a local PFS on the mounted HAMMER2 filesystem represented
255by the current directory, or specified via
256.Fl s Ar mount .
257If no UUID is specified the pfs-type defaults to MASTER.
258If a UUID is specified via the
259.Fl u
260option the pfs-type defaults to SLAVE.
261Other types can be specified with the
262.Fl t
263option.
264.Pp
265If you wish to add a MASTER to an existing cluster, you must first add it as
266a SLAVE and then upgrade it to MASTER to properly synchronize it.
267.Pp
268The DUMMY pfs-type is used to tie network-accessible clusters into the local
269machine when no local storage is desired.
270This type should be used on minimal H2 partitions or entirely in ram for
271netboot-centric systems to provide a tie-in point for the mount command,
272or on more complex systems where you need to also access network-centric
273clusters.
274.Pp
275The CACHE or SLAVE pfs-type is typically used when the main store is on
276the network but local storage is desired to improve performance.
277SLAVE is also used when a backup is desired.
278.Pp
279Generally speaking, you can mount any PFS element of a cluster in order to
280access the cluster via the full cluster protocol.
281There are two exceptions.
282If you mount a SOFT_SLAVE or a SOFT_MASTER then soft quorum semantics are
283employed... the soft slave or soft master's current state will always be used
284and the quorum protocol will not be used.
285The soft PFS will still be
286synchronized to masters in the background when available.
287Also, you can use
288.Sq mount -o local
289to mount ONLY a local HAMMER2 PFS and
290not run any network or quorum protocols for the mount.
291All such mounts except for a SOFT_MASTER mount will be read-only.
292Other than that, you will be mounting the whole cluster when you mount any
293PFS within the cluster.
294.Pp
295DUMMY - Create a PFS skeleton intended to be the mount point for a
296more complex cluster, probably one that is entirely network based.
297No data will be synchronized to this PFS so it is suitable for use
298in a network boot image or memory filesystem.
299This allows you to create placeholders for mount points on your local
300disk, SSD, or memory disk.
301.Pp
302CACHE - Create a PFS for caching portions of the cluster piecemeal.
303This is similar to a SLAVE but does not synchronize the entire contents of
304the cluster to the PFS.
305Elements found in the CACHE PFS which are validated against the cluster
306will be read, presumably a faster access than having to go to the cluster.
307Only local CACHEs will be updated.
308Network-accessible CACHE PFSs might be read but will not be written to.
309If you have a large hard-drive-based cluster you can set up localized
310SSD CACHE PFSs to improve performance.
311.Pp
312SLAVE - Create a PFS which maintains synchronization with and provides a
313read-only copy of the cluster.
314HAMMER2 will prioritize local SLAVEs for data retrieval after validating
315their transaction id against the cluster.
316The difference between a CACHE and a SLAVE is that the SLAVE is synchronized
317to a full copy of the cluster and thus can serve as a backup or be staged
318for use as a MASTER later on.
319.Pp
320SOFT_SLAVE - Create a PFS which maintains synchronization with and provides
321a read-only copy of the cluster.
322This is one of the special mount cases.
323A SOFT_SLAVE will synchronize with
324the cluster when the cluster is available, but can still be accessed when
325the cluster is not available.
326.Pp
327MASTER - Create a PFS which will hold a master copy of the cluster.
328If you create several MASTER PFSs with the same cluster id you are
329effectively creating a multi-master cluster and causing a quorum and
330cache coherency protocol to be used to validate operations.
331The total number of masters is stored in each PFSs making up the cluster.
332Filesystem operations will stall for normal mounts if a quorum cannot be
333obtained to validate the operation.
334MASTER nodes which go offline and return later will synchronize in the
335background.
336Note that when adding a MASTER to an existing cluster you must add the
337new PFS as a SLAVE and then upgrade it to a MASTER.
338.Pp
339SOFT_MASTER - Create a PFS which maintains synchronization with and provides
340a read-write copy of the cluster.
341This is one of the special mount cases.
342A SOFT_MASTER will synchronize with
343the cluster when the cluster is available, but can still be read AND written
344to even when the cluster is not available.
345Modifications made to a SOFT_MASTER will be automatically flushed to the
346cluster when it becomes accessible again, and vise-versa.
347Manual intervention may be required if a conflict occurs during
348synchronization.
349.\" ==== pfs-delete ====
350.It Cm pfs-delete Op label...
351Destroy a PFS by name.
352All hammer2 mount points will be checked, however this directive will refuse to
353delete a PFS whos name is duplicated on multiple mount points.
354A specific mount point may be specified to restrict the deletion via the
355.Fl s Ar mount
356option.
357.\" ==== recover ====
358.It Cm recover Ar media Ar path Ar destdir
359Recover a file or directory tree by scanning the raw media partition,
360with minimal requirements for an intact topology.  The results are written
361to the destination directory.
362.Pp
363The recovery path can be anchored at (any) root by prefixing it with a "/".
364If not anchored, any matching sub-tree will be recovered and combined into
365one place on the destination (not as separate sub-trees since that requires
366topological knowledge that might not be available).  Roots include all
367PFS roots and snapshot roots, as well as disconnected roots from COW updates
368(aka to be able to undelete a file or directory sub-tree).
369.Pp
370The path may specify a directory or file to restore.  Note that if you
371specify something like ".cshrc", then all ".cshrc" files found in the
372entire filesystem will be recovered.
373.Pp
374This function is meant for catastrophic recovery or corrupted media or
375recovery for deleted files that are not otherwise available in snapshots.
376All possible versions of files will be recovered and suffixed as "*.%05d"
377with an iterator.
378.Pp
379The hammer2 recovery function is not meant to generate a fully operational
380filesystem in the target directory.  All files will be versioned and contain
381iteration suffixes.  Many files and sub-directory trees may wind up glommed
382together in one place.  However, this function will recover mtime, ownership,
383group, modes, and flags.  Recovered files are fully validated and any missing
384data will cause the file to be renamed with a ".corrupted" suffix.
385.\" ==== recover-relaxed ====
386.It Cm recover-relaxed Ar media Ar path Ar destdir
387This version of the recover directive relaxes bref checks.  Under normal
388operation, only brefs with check codes are allowed because we get too many
389false hits otherwise.  In relaxed mode, bref's with the check code disabled
390are also allowed.
391.Pp
392You should only need to use the relaxed version if you have turned off
393CRCs on the files you want to recover.
394.\" ==== recover-file ====
395.It Cm recover-file Ar media Ar path Ar destdir
396This version of recover is the normal strict-mode recover but explicitly
397indicates that the path being recovered is a regular file and not a
398directory.  Prevents junk recursions when entries corresponding to the
399last path element appear to be directories.
400.\" ==== snapshot ====
401.It Cm snapshot Ar path Op label
402Create a snapshot of a directory.
403The snapshot will be created on the same hammer2 storage device as the
404directory.
405This can only be used on a local PFS, and is only really useful if the PFS
406contains a complete copy of what you desire to snapshot so that typically
407means a local MASTER, SOFT_MASTER, SLAVE, or SOFT_SLAVE must be present.
408Snapshots are created simply by flushing a PFS mount to disk and then copying
409the directory inode to the PFS.
410The topology is snapshotted without having to be copied or scanned and
411take no additional space.
412However, bulkfree scans may take longer.
413Snapshots are effectively separate from the cluster they came from
414and can be used as a starting point for a new cluster.
415So unless you build a new cluster from the snapshot, it will stay local
416to the machine it was made on.
417.Pp
418Snapshots can be maintained automatically with
419.Xr periodic 8 .
420See
421.Xr periodic.conf 5
422for details of enabling and configuring the functionality.
423.\" ==== snapshot-debug ====
424.It Cm snapshot-debug Ar path Op label
425Snapshot without filesystem sync.
426.\" ==== service ====
427.It Cm service
428Start the
429.Nm
430service daemon.
431This daemon is also automatically started when you run
432.Xr mount_hammer2 8 .
433The hammer2 service daemon handles incoming TCP connections and maintains
434outgoing TCP connections.
435It will interconnect available services on the
436machine (e.g. hammer2 mounts and xdisks) to the network.
437.\" ==== stat ====
438.It Cm stat Op path...
439Print the inode statistics, compression, and other meta-data associated
440with a list of paths.
441.\" ==== leaf ====
442.It Cm leaf
443XXX
444.\" ==== shell ====
445.It Cm shell Op host
446Start a debug shell to the local hammer2 service daemon via the DMSG protocol.
447.\" ==== debugspan ====
448.It Cm debugspan Ar target
449(do not use)
450.\" ==== rsainit ====
451.It Cm rsainit Op path
452Create the
453.Pa /etc/hammer2
454directory and initialize a public/private keypair in that directory for
455use by the network cluster protocols.
456.\" ==== show ====
457.It Cm show Ar devpath
458Dump the radix tree for the HAMMER2 filesystem by scanning a
459block device directly.
460No mount is required.
461.\" ==== freemap ====
462.It Cm freemap Ar devpath
463Dump the freemap tree for the HAMMER2 filesystem by scanning a
464block device directly.
465No mount is required.
466.\" ==== volhdr ====
467.It Cm volhdr Ar devpath
468Dump the volume header for the HAMMER2 filesystem by scanning a
469block device directly.
470No mount is required.
471.\" ==== volume-list ====
472.It Cm volume-list Op path...
473List all volumes associated with all mounted hammer2 storage devices.
474The list may be restricted to a particular filesystem using
475.Fl s Ar mount .
476.Pp
477Note that hammer2 volumes associated with storage devices which have not been
478mounted in any fashion will not be listed.
479At least one hammer2 label must be mounted for the volumes on that device to be
480visible.
481.\" ==== setcomp ====
482.It Cm setcomp Ar mode[:level] Ar path...
483Set the compression mode as specified for any newly created elements at or
484under the path if not overridden by deeper elements.
485Available modes are none, autozero, lz4, or zlib.
486When zlib is used the compression level can be set.
487The default will be 6 which is the best trade-off between performance and
488time.
489.Pp
490newfs_hammer2 will set the default compression to lz4 which prioritizes
491speed over performance.
492Also note that HAMMER2 contains a heuristic and will not attempt to
493compress every block if it detects a sufficient amount of uncompressable
494data.
495.Pp
496Hammer2 compression is only effective when it can reduce the size of dataset
497(typically a 64KB block) by one or more powers of 2.  A 64K block which
498only compresses to 40K will not yield any storage improvement.
499.Pp
500Generally speaking you do not want to set the compression mode to
501.Sq none ,
502as this will cause blocks of all-zeros to be written as all-zero blocks,
503instead of holes.
504The
505.Sq autozero
506compression mode detects blocks of all-zeros
507and writes them as holes.
508.\" ==== setcheck ====
509.It Cm setcheck Ar check Ar path...
510Set the check code as specified for any newly created elements at or under
511the path if not overridden by deeper elements.
512Available codes are default, disabled, crc32, xxhash64, or sha192.
513.Pp
514Normally HAMMER2 does not overwrite data blocks on the media in order to ensure
515snapshot integrity.
516Replacement data blocks will be reallocated.
517However, if the compression mode is set to
518.Sq none
519and the check code is set to
520.Sq disabled
521HAMMER2 will overwrite data on the media in-place.
522In this mode of operation,
523snapshots will not be able to snapshot the data against later changes
524made to the file, and de-duplication will no longer function on any
525data related to the file.
526However, you can still recover the most recent data from previously
527taken snapshots if you accidentally remove the file.
528.\" ==== clrcheck ====
529.It Cm clrcheck Op path...
530Clear the check code override for the specified paths.
531Overrides may still be present in deeper elements.
532.\" ==== setcrc32 ====
533.It Cm setcrc32 Op path...
534Set the check code to the ISCSI 32-bit CRC for any newly created elements
535at or under the path if not overridden by deeper elements.
536.\" ==== setxxhash64 ====
537.It Cm setxxhash64 Op path...
538Set the check code to XXHASH64, a fast 64-bit hash
539.\" ==== setsha192 ====
540.It Cm setsha192 Op path...
541Set the check code to SHA192 for any newly created elements at or under
542the path if not overridden by deeper elements.
543.\" ==== bulkfree ====
544.It Cm bulkfree Ar path
545Run a bulkfree pass on a HAMMER2 mount.
546You can specify any PFS for the mount, the bulkfree pass is run on the
547entire partition.
548Note that it takes two passes to actually free space.
549By default this directive will use up to 1/16 physical memory to track
550the freemap.
551The amount of memory used may be overridden with the
552.Op Fl m Ar mem
553option.
554.\" ==== printinode ====
555.It Cm printinode Ar path
556Dump inode.
557.\" ==== dumpchain ====
558.It Cm dumpchain Op path Op chnflags
559Dump in-memory chain topology.
560.El
561.Sh SYSCTLS
562.Bl -tag -width indent
563.It Va vfs.hammer2.dedup_enable "(default on)"
564Enables live de-duplication.
565Any recently read data that is on-media
566(already synchronized to media) is tested against pending writes for
567compatibility.
568If a match is found, the write will reference the
569existing on-media data instead of writing new data.
570.It Va vfs.hammer2.always_compress "(default off)"
571This disables the H2 compression heuristic and forces H2 to always
572try to compress data blocks, even if they look uncompressable.
573Enabling this option reduces performance but has higher de-duplication
574repeatability.
575.It Va vfs.hammer2.cluster_data_read "(default 4)"
576.It Va vfs.hammer2.cluster_meta_read "(default 1)"
577Set the amount of read-ahead clustering to perform on data and meta-data
578blocks.
579.It Va vfs.hammer2.cluster_write "(default 0)"
580Set the amount of write-behind clustering to perform in buffers.
581Each buffer represents 64KB.
582The default is 4 and higher values typically do not improve performance.
583A value of 0 disables clustered writes.
584This variable applies to the underlying media device, not to logical
585file writes, so it should not interfere with temporary file optimization.
586Generally speaking you want this enabled to generate smoothly pipelined
587writes to the media.
588.It Va vfs.hammer2.bulkfree_tps "(default 5000)"
589Set bulkfree's maximum scan rate.
590This is primarily intended to limit
591I/O utilization on SSDs and CPU utilization when the meta-data is mostly
592cached in memory.
593.El
594.Sh SETTING UP /etc/hammer2
595The
596.Sq rsainit
597directive will create the
598.Pa /etc/hammer2
599directory with appropriate permissions and also generate a public key
600pair in this directory for the machine.
601These files will be
602.Pa rsa.pub
603and
604.Pa rsa.prv
605and needless to say, the private key shouldn't leave the host.
606.Pp
607The service daemon will also scan the
608.Pa /etc/hammer2/autoconn
609file which contains a list of hosts which it will automatically maintain
610connections to to form your cluster.
611The service daemon will automatically reconnect on any failure and will
612also monitor the file for changes.
613.Pp
614When the service daemon receives a connection it expects to find a
615public key for that connection in a file in
616.Pa /etc/hammer2/remote/
617called
618.Pa <IPADDR>.pub .
619You normally copy the
620.Pa rsa.pub
621key from the host in question to this file.
622The IP address must match exactly or the connection will not be allowed.
623.Pp
624If you want to use an unencrypted connection you can create empty,
625dummy files in the remote directory in the form
626.Pa <IPADDR>.none .
627We do not recommend using unencrypted connections.
628.Sh CLUSTER SERVICES
629Currently there are two services which use the cluster network infrastructure,
630HAMMER2 mounts and XDISK.
631Any HAMMER2 mount will make all PFSs for that filesystem available to the
632cluster.
633And if the XDISK kernel module is loaded, the hammer2 service daemon will make
634your machine's block devices available to the cluster (you must load the
635xdisk.ko kernel module before starting the hammer2 service).
636They will show up as
637.Pa /dev/xa*
638and
639.Pa /dev/serno/*
640devices on the remote machines making up the cluster.
641Remote block devices are just what they appear to be... direct access to a
642block device on a remote machine.
643If the link goes down remote accesses
644will stall until it comes back up again, then automatically requeue any
645pending I/O and resume as if nothing happened.
646However, if the server hosting the physical disks crashes or is rebooted,
647any remote opens to its devices will see a permanent I/O failure requiring a
648close and open sequence to re-establish.
649The latter is necessary because the server's drives might not have committed
650the data before the crash, but had already acknowledged the transfer.
651.Pp
652Data commits work exactly the same as they do for real block devices.
653The originater must issue a BUF_CMD_FLUSH.
654.Sh ADDING A NEW MASTER TO A CLUSTER
655When you
656.Xr newfs_hammer2 8
657a HAMMER2 filesystem or use the
658.Sq pfs-create
659directive on one already mounted
660to create a new PFS, with no special options, you wind up with a PFS
661typed as a MASTER and a unique cluster UUID, but because there is only one
662PFS for that cluster (for each PFS you create via pfs-create), it will
663act just like a normal filesystem would act and does not require any special
664protocols to operate.
665.Pp
666If you use the
667.Sq pfs-create
668directive along with the
669.Fl u
670option to specify a cluster UUID that already exists in the cluster,
671you are adding a PFS to an existing cluster and this can trigger a whole
672series of events in the background.
673When you specify the
674.Fl u
675option in a
676.Sq pfs-create ,
677.Nm
678will by default create a SLAVE PFS.
679In fact, this is what must be created first even if you want to add a new
680MASTER to your cluster.
681.Pp
682The most common action a system admin will want to take is to upgrade or
683downgrade a PFS.
684A new MASTER can be added to the cluster by upgrading an existing SLAVE
685to MASTER.
686A MASTER can be removed from the cluster by downgrading it to a SLAVE.
687Upgrades and downgrades will put nodes in the cluster in a transition state
688until the operation is complete.
689For downgrades the transition state is fleeting unless one or more other
690masters has not acknowledged the change.
691For upgrades a background synchronization process must complete before the
692transition can be said to be complete, and the node remains (really) a SLAVE
693until that transition is complete.
694.Sh USE CASES FOR A SOFT_MASTER
695The SOFT_MASTER PFS type is a special type which must be specifically
696mounted by a machine.
697It is a R/W mount which does not use the quorum protocol and is not
698cache coherent with the cluster, but which synchronizes from the cluster
699and allows modifying operations which will synchronize to the cluster.
700The most common case is to use a SOFT_MASTER PFS in a laptop allowing you
701to work on your laptop when you are on the road and not connected to
702your main servers, and for the laptop to synchronize when a connection is
703available.
704.Sh USE CASES FOR A SOFT_SLAVE
705A SOFT_SLAVE PFS type is a special type which must be specifically mounted
706by a machine.
707It is a RO mount which does not use the quorum protocol and is not
708cache coherent with the cluster.
709It will receive synchronization from
710the cluster when network connectivity is available but will not stall if
711network connectivity is lost.
712.Sh FSYNC FLUSH MODES
713TODO.
714.Sh RESTORING FROM A SNAPSHOT BACKUP
715TODO.
716.Sh PERFORMANCE TUNING
717Because HAMMER2 implements compression, decompression, and dedup natively,
718it always double-buffers file data.
719This means that the file data is
720cached via the device vnode (in compressed / dedupped-form) and the same
721data is also cached by the file vnode (in decompressed / non-dedupped form).
722.Pp
723While HAMMER2 will try to age the logical file buffers on its, some
724additional performance tuning may be necessary for optimal operation
725whether swapcache is used or not.
726Our recommendation is to reduce the
727number of vnodes (and thus also the logical buffer cache behind the
728vnodes) that the system caches via the
729.Va kern.maxvnodes
730sysctl.
731.Pp
732Too-large a value will result in excessive double-caching and can cause
733unnecessary read disk I/O.
734We recommend a number between 25000 and 250000 vnodes, depending on your
735use case.
736Keep in mind that even though the vnode cache is smaller, this will make
737room for a great deal more device-level buffer caching which can encompasses
738far more data and meta-data than the vnode-level caching.
739.Sh ENVIRONMENT
740TODO.
741.Sh FILES
742.Bl -tag -width ".It Pa <fs>/abc/defghi/<name>" -compact
743.It Pa /etc/hammer2/
744.It Pa /etc/hammer2/rsa.pub
745.It Pa /etc/hammer2/rsa.prv
746.It Pa /etc/hammer2/autoconn
747.It Pa /etc/hammer2/remote/<IP>.pub
748.It Pa /etc/hammer2/remote/<IP>.none
749.El
750.Sh EXIT STATUS
751.Ex -std
752.Sh SEE ALSO
753.Xr xdisk 4 ,
754.Xr periodic.conf 5 ,
755.Xr mount_hammer2 8 ,
756.Xr mount_null 8 ,
757.Xr newfs_hammer2 8 ,
758.Xr swapcache 8 ,
759.Xr sysctl 8
760.Sh HISTORY
761The
762.Nm
763utility first appeared in
764.Dx 4.1 .
765.Sh AUTHORS
766.An Matthew Dillon Aq Mt dillon@backplane.com
767