2 * Copyright (c) 2011 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Antonio Huete <tuxillo@quantumachine.net>
6 * by Matthew Dillon <dillon@backplane.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #include <sys/queue.h>
41 #include <sys/param.h>
43 #include <vfs/hammer/hammer_disk.h>
44 #include <vfs/hammer/hammer_ioctl.h>
48 #define HAMMER_BUFLISTS 64
49 #define HAMMER_BUFLISTMASK (HAMMER_BUFLISTS - 1)
50 #define HAMMER_BUFINFO_READAHEAD 0x0001
52 * WARNING: Do not make the SNAPSHOTS_BASE "/var/snapshots" because
53 * it will interfere with the older HAMMER VERS < 3 snapshots directory
56 #define SNAPSHOTS_BASE "/var/hammer" /* HAMMER VERS >= 3 */
59 #define SERIALBUF_SIZE (512 * 1024)
60 #define RD_HSIZE 32768
61 #define RD_HMASK (RD_HSIZE - 1)
63 #define DICTF_MADEDIR 0x01
64 #define DICTF_MADEFILE 0x02
65 #define DICTF_PARENT 0x04 /* parent attached for real */
66 #define DICTF_TRAVERSED 0x80
67 #define FLAG_TOOFARLEFT 0x0001
68 #define FLAG_TOOFARRIGHT 0x0002
69 #define FLAG_BADTYPE 0x0004
70 #define FLAG_BADCHILDPARENT 0x0008
71 #define FLAG_BADMIRRORTID 0x0010
74 * Hammer information system structures
76 struct libhammer_head {
82 typedef struct libhammer_snapinfo {
83 struct libhammer_head head; /* Additional error and flags */
85 TAILQ_ENTRY(libhammer_snapinfo) entries;
90 } *libhammer_snapinfo_t;
92 typedef struct libhammer_pfsinfo {
93 struct libhammer_head head; /* Additional error and flags */
95 uint32_t snapcount; /* Snapshot count */
96 u_int32_t version; /* HAMMER version */
97 char *mountedon; /* Mount path of the PFS */
98 int ismaster; /* Is a PFS master */
99 int pfs_id; /* PFS ID number */
100 int mirror_flags; /* Misc flags */
101 char snapshots[64]; /* softlink dir for pruning */
102 uuid_t unique_uuid; /* unique uuid of this master/slave */
103 TAILQ_ENTRY(libhammer_pfsinfo) entries;
104 TAILQ_HEAD(snaplist, libhammer_snapinfo) list_snap;
105 hammer_tid_t beg_tid; /* Earliest TID with full history */
106 hammer_tid_t end_tid; /* Current synchronisation TID */
109 } *libhammer_pfsinfo_t;
111 typedef struct libhammer_fsinfo {
112 struct libhammer_head head; /* Additional error and flags */
114 char vol_name[TXTLEN]; /* Volume name */
115 uuid_t vol_fsid; /* Filesystem UUID */
116 int version; /* HAMMER version */
117 int nvolumes; /* Number of volumes */
118 int64_t inodes; /* no. of inodes */
119 int64_t bigblocks; /* Total big blocks */
120 int64_t freebigblocks; /* Free big blocks */
121 int64_t rsvbigblocks; /* Reserved big blocks */
123 TAILQ_HEAD(pfslist, libhammer_pfsinfo) list_pseudo;
124 } *libhammer_fsinfo_t;
126 struct libhammer_btree_stats {
136 struct libhammer_io_stats {
142 int64_t file_iop_writes;
143 int64_t file_iop_reads;
144 int64_t inode_flushes;
149 * Function prototypes
152 libhammer_fsinfo_t libhammer_get_fsinfo(const char *);
153 void libhammer_free_fsinfo(libhammer_fsinfo_t);
155 int libhammer_stats_redo(int64_t *);
156 int libhammer_stats_undo(int64_t *);
157 int libhammer_stats_commits(int64_t *);
158 int libhammer_stats_inode_flushes(int64_t *);
159 int libhammer_stats_disk_write(int64_t *);
160 int libhammer_stats_disk_read(int64_t *);
161 int libhammer_stats_file_iopsw(int64_t *);
162 int libhammer_stats_file_iopsr(int64_t *);
163 int libhammer_stats_file_write(int64_t *);
164 int libhammer_stats_file_read(int64_t *);
165 int libhammer_stats_record_iterations(int64_t *);
166 int libhammer_stats_root_iterations(int64_t *);
167 int libhammer_stats_btree_iterations(int64_t *);
168 int libhammer_stats_btree_splits(int64_t *);
169 int libhammer_stats_btree_elements(int64_t *);
170 int libhammer_stats_btree_deletes(int64_t *);
171 int libhammer_stats_btree_inserts(int64_t *);
172 int libhammer_stats_btree_lookups(int64_t *);
173 int libhammer_stats_btree_searches(int64_t *);
174 int libhammer_btree_stats(struct libhammer_btree_stats *);
175 int libhammer_io_stats(struct libhammer_io_stats *);
177 int libhammer_pfs_get_snapshots(libhammer_fsinfo_t, libhammer_pfsinfo_t);
178 void libhammer_pfs_free_snapshots(libhammer_pfsinfo_t);
180 char *libhammer_find_pfs_mount(uuid_t *);
181 void libhammer_pfs_canonical_path(char *, libhammer_pfsinfo_t, char **);
182 void *_libhammer_malloc(size_t);
183 void libhammer_compat_old_snapcount(libhammer_pfsinfo_t);
187 * Wrappers to operate PFS TAILQ for each HAMMER filesystem
189 static __inline libhammer_pfsinfo_t
190 libhammer_get_next_pfs(libhammer_pfsinfo_t pfsinfo)
192 return TAILQ_NEXT(pfsinfo, entries);
195 static __inline libhammer_pfsinfo_t
196 libhammer_get_prev_pfs(libhammer_pfsinfo_t pfsinfo)
198 return TAILQ_PREV(pfsinfo, pfslist, entries);
201 static __inline libhammer_pfsinfo_t
202 libhammer_get_first_pfs(libhammer_fsinfo_t fip)
204 return TAILQ_FIRST(&fip->list_pseudo);
207 static __inline libhammer_pfsinfo_t
208 libhammer_get_last_pfs(libhammer_fsinfo_t fip)
210 return TAILQ_LAST(&fip->list_pseudo, pfslist);
214 * Wrappers to operate snapshot TAILQ for each PFS
216 static __inline libhammer_snapinfo_t
217 libhammer_get_next_snap(libhammer_snapinfo_t sip)
219 return TAILQ_NEXT(sip, entries);
222 static __inline libhammer_snapinfo_t
223 libhammer_get_prev_snap(libhammer_snapinfo_t sip)
225 return TAILQ_PREV(sip, snaplist, entries);
228 static __inline libhammer_snapinfo_t
229 libhammer_get_first_snap(libhammer_pfsinfo_t pip)
231 return TAILQ_FIRST(&pip->list_snap);
234 static __inline libhammer_snapinfo_t
235 libhammer_get_last_snap(libhammer_pfsinfo_t pip)
237 return TAILQ_LAST(&pip->list_snap, snaplist);