libhammer - Add an overlooked function that releases snaps
[dragonfly.git] / lib / libhammer / libhammer.h
CommitLineData
cb7575e6
AHJ
1/*
2 * Copyright (c) 2011 The DragonFly Project. All rights reserved.
3 *
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>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
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
17 * distribution.
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.
21 *
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
33 * SUCH DAMAGE.
34 *
35 */
c422eb8a 36
cb7575e6
AHJ
37#ifndef _LIBHAMMER_H_
38#define _LIBHAMMER_H_
39
40#include <sys/queue.h>
41#include <sys/param.h>
42
43#include <vfs/hammer/hammer_disk.h>
44#include <vfs/hammer/hammer_ioctl.h>
45
46#define TXTLEN 64
47
48#define HAMMER_BUFLISTS 64
49#define HAMMER_BUFLISTMASK (HAMMER_BUFLISTS - 1)
50#define COLLECT_HSIZE 1024
51#define COLLECT_HMASK (COLLECT_HSIZE - 1)
52#define HAMMER_BUFINFO_READAHEAD 0x0001
53/*
54 * WARNING: Do not make the SNAPSHOTS_BASE "/var/snapshots" because
55 * it will interfere with the older HAMMER VERS < 3 snapshots directory
56 * for the /var PFS.
57 */
58#define SNAPSHOTS_BASE "/var/hammer" /* HAMMER VERS >= 3 */
59#define WS " \t\r\n"
60
61#define SERIALBUF_SIZE (512 * 1024)
62#define RD_HSIZE 32768
63#define RD_HMASK (RD_HSIZE - 1)
64
65#define DICTF_MADEDIR 0x01
66#define DICTF_MADEFILE 0x02
67#define DICTF_PARENT 0x04 /* parent attached for real */
68#define DICTF_TRAVERSED 0x80
69#define FLAG_TOOFARLEFT 0x0001
70#define FLAG_TOOFARRIGHT 0x0002
71#define FLAG_BADTYPE 0x0004
72#define FLAG_BADCHILDPARENT 0x0008
73#define FLAG_BADMIRRORTID 0x0010
74
75/*
76 * Hammer information system structures
77 */
78struct libhammer_head {
79 int32_t error;
80 int32_t flags;
81 int32_t rsv[2];
82};
83
a77d0377
AHJ
84typedef struct libhammer_snapinfo {
85 struct libhammer_head head; /* Additional error and flags */
86
87 TAILQ_ENTRY(libhammer_snapinfo) entries;
88 hammer_tid_t tid;
89 u_int64_t ts;
90 char label[64];
91 u_int64_t rsv;
92} *libhammer_snapinfo_t;
93
cb7575e6
AHJ
94typedef struct libhammer_pfsinfo {
95 struct libhammer_head head; /* Additional error and flags */
96
97 uint32_t snapcount; /* Snapshot count */
98 u_int32_t version; /* HAMMER version */
99 char *mountedon; /* Mount path of the PFS */
100 int ismaster; /* Is a PFS master */
101 int pfs_id; /* PFS ID number */
102 int mirror_flags; /* Misc flags */
103 char snapshots[64]; /* softlink dir for pruning */
104 uuid_t unique_uuid; /* unique uuid of this master/slave */
105 TAILQ_ENTRY(libhammer_pfsinfo) entries;
a77d0377 106 TAILQ_HEAD(snaplist, libhammer_snapinfo) list_snap;
4468f47b
AHJ
107 hammer_tid_t beg_tid; /* Earliest TID with full history */
108 hammer_tid_t end_tid; /* Current synchronisation TID */
109
110 uint64_t rsv[4];
cb7575e6
AHJ
111} *libhammer_pfsinfo_t;
112
a77d0377 113typedef struct libhammer_fsinfo {
cb7575e6
AHJ
114 struct libhammer_head head; /* Additional error and flags */
115
116 char vol_name[TXTLEN]; /* Volume name */
117 uuid_t vol_fsid; /* Filesystem UUID */
118 int version; /* HAMMER version */
119 int nvolumes; /* Number of volumes */
925016b9 120 int64_t inodes; /* no. of inodes */
cb7575e6 121 int64_t bigblocks; /* Total big blocks */
e2fb4261 122 int64_t freebigblocks; /* Free big blocks */
cb7575e6
AHJ
123 int64_t rsvbigblocks; /* Reserved big blocks */
124 int32_t rsv[8];
125 TAILQ_HEAD(pfslist, libhammer_pfsinfo) list_pseudo;
a77d0377 126} *libhammer_fsinfo_t;
cb7575e6 127
c422eb8a
AHJ
128struct libhammer_btree_stats {
129 int64_t elements;
130 int64_t iterations;
131 int64_t splits;
132 int64_t inserts;
133 int64_t deletes;
134 int64_t lookups;
135 int64_t searches;
136};
137
138struct libhammer_io_stats {
139 int64_t undo;
140 int64_t dev_writes;
141 int64_t dev_reads;
142 int64_t file_writes;
143 int64_t file_reads;
144 int64_t file_iop_writes;
145 int64_t file_iop_reads;
146 int64_t inode_flushes;
147 int64_t commits;
148};
149
cb7575e6 150/*
c422eb8a 151 * Function prototypes
cb7575e6
AHJ
152 */
153__BEGIN_DECLS
a77d0377
AHJ
154libhammer_fsinfo_t libhammer_get_fsinfo(const char *);
155void libhammer_free_fsinfo(libhammer_fsinfo_t);
c422eb8a
AHJ
156
157int libhammer_stats_redo(int64_t *);
158int libhammer_stats_undo(int64_t *);
159int libhammer_stats_commits(int64_t *);
160int libhammer_stats_inode_flushes(int64_t *);
161int libhammer_stats_disk_write(int64_t *);
162int libhammer_stats_disk_read(int64_t *);
163int libhammer_stats_file_iopsw(int64_t *);
164int libhammer_stats_file_iopsr(int64_t *);
165int libhammer_stats_file_write(int64_t *);
166int libhammer_stats_file_read(int64_t *);
167int libhammer_stats_record_iterations(int64_t *);
168int libhammer_stats_root_iterations(int64_t *);
169int libhammer_stats_btree_iterations(int64_t *);
170int libhammer_stats_btree_splits(int64_t *);
171int libhammer_stats_btree_elements(int64_t *);
172int libhammer_stats_btree_deletes(int64_t *);
173int libhammer_stats_btree_inserts(int64_t *);
174int libhammer_stats_btree_lookups(int64_t *);
175int libhammer_stats_btree_searches(int64_t *);
176int libhammer_btree_stats(struct libhammer_btree_stats *);
177int libhammer_io_stats(struct libhammer_io_stats *);
178
a77d0377 179int libhammer_pfs_get_snapshots(libhammer_fsinfo_t, libhammer_pfsinfo_t);
cc96d2fe 180void libhammer_pfs_free_snapshots(libhammer_pfsinfo_t);
a77d0377 181
d428efb7 182char *libhammer_find_pfs_mount(uuid_t *);
a77d0377 183void libhammer_pfs_canonical_path(char *, libhammer_pfsinfo_t, char **);
c422eb8a 184void *_libhammer_malloc(size_t);
a77d0377 185void libhammer_compat_old_snapcount(libhammer_pfsinfo_t);
cb7575e6
AHJ
186__END_DECLS
187
a77d0377
AHJ
188/*
189 * Wrappers to operate PFS TAILQ for each HAMMER filesystem
190 */
cb7575e6
AHJ
191static __inline libhammer_pfsinfo_t
192libhammer_get_next_pfs(libhammer_pfsinfo_t pfsinfo)
193{
194 return TAILQ_NEXT(pfsinfo, entries);
195}
196
197static __inline libhammer_pfsinfo_t
198libhammer_get_prev_pfs(libhammer_pfsinfo_t pfsinfo)
199{
200 return TAILQ_PREV(pfsinfo, pfslist, entries);
201}
202
203static __inline libhammer_pfsinfo_t
a77d0377 204libhammer_get_first_pfs(libhammer_fsinfo_t fip)
cb7575e6 205{
a77d0377 206 return TAILQ_FIRST(&fip->list_pseudo);
cb7575e6
AHJ
207}
208
209static __inline libhammer_pfsinfo_t
a77d0377
AHJ
210libhammer_get_last_pfs(libhammer_fsinfo_t fip)
211{
212 return TAILQ_LAST(&fip->list_pseudo, pfslist);
213}
214
215/*
216 * Wrappers to operate snapshot TAILQ for each PFS
217 */
218static __inline libhammer_snapinfo_t
219libhammer_get_next_snap(libhammer_snapinfo_t sip)
220{
221 return TAILQ_NEXT(sip, entries);
222}
223
224static __inline libhammer_snapinfo_t
225libhammer_get_prev_snap(libhammer_snapinfo_t sip)
226{
227 return TAILQ_PREV(sip, snaplist, entries);
228}
229
230static __inline libhammer_snapinfo_t
231libhammer_get_first_snap(libhammer_pfsinfo_t pip)
232{
233 return TAILQ_FIRST(&pip->list_snap);
234}
235
236static __inline libhammer_snapinfo_t
237libhammer_get_last_snap(libhammer_pfsinfo_t pip)
cb7575e6 238{
a77d0377 239 return TAILQ_LAST(&pip->list_snap, snaplist);
cb7575e6
AHJ
240}
241
8ab1d23a 242#endif