Merge branch 'vendor/OPENSSL'
[dragonfly.git] / lib / libhammer / libhammer.h
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  */
36
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 /*
49  * WARNING: Do not make the SNAPSHOTS_BASE "/var/snapshots" because
50  * it will interfere with the older HAMMER VERS < 3 snapshots directory
51  * for the /var PFS.
52  */
53 #define SNAPSHOTS_BASE  "/var/hammer"   /* HAMMER VERS >= 3 */
54
55 /*
56  * Hammer information system structures
57  */
58 struct libhammer_head {
59         int32_t error;
60         int32_t flags;
61         int32_t rsv[2];
62 };
63
64 typedef struct libhammer_snapinfo {
65         struct libhammer_head head; /* Additional error and flags */
66
67         TAILQ_ENTRY(libhammer_snapinfo) entries;
68         hammer_tid_t    tid;
69         u_int64_t       ts;
70         char            label[64];
71         u_int64_t       rsv;
72 } *libhammer_snapinfo_t;
73
74 typedef struct libhammer_pfsinfo {
75         struct libhammer_head head; /* Additional error and flags */
76
77         uint32_t  snapcount;        /* Snapshot count */
78         u_int32_t version;          /* HAMMER version */
79         char      *mountedon;       /* Mount path of the PFS */
80         int       ismaster;         /* Is a PFS master */
81         int       pfs_id;           /* PFS ID number */
82         int       mirror_flags;     /* Misc flags */
83         char      snapshots[64];    /* softlink dir for pruning */
84         uuid_t    unique_uuid;      /* unique uuid of this master/slave */
85         TAILQ_ENTRY(libhammer_pfsinfo) entries;
86         TAILQ_HEAD(snaplist, libhammer_snapinfo) list_snap;
87         hammer_tid_t beg_tid;       /* Earliest TID with full history */
88         hammer_tid_t end_tid;       /* Current synchronisation TID */
89
90         uint64_t rsv[4];
91 } *libhammer_pfsinfo_t;
92
93 typedef struct libhammer_fsinfo {
94         struct libhammer_head head; /* Additional error and flags */
95
96         char     vol_name[TXTLEN];  /* Volume name */
97         uuid_t   vol_fsid;          /* Filesystem UUID */
98         int      version;           /* HAMMER version */
99         int      nvolumes;          /* Number of volumes */
100         int64_t  inodes;            /* no. of inodes */
101         int64_t  bigblocks;         /* Total big blocks */
102         int64_t  freebigblocks;     /* Free big blocks */
103         int64_t  rsvbigblocks;      /* Reserved big blocks */
104         int32_t  rsv[8];
105         TAILQ_HEAD(pfslist, libhammer_pfsinfo) list_pseudo;
106 } *libhammer_fsinfo_t;
107
108 struct libhammer_btree_stats {
109         int64_t elements;
110         int64_t iterations;
111         int64_t splits;
112         int64_t inserts;
113         int64_t deletes;
114         int64_t lookups;
115         int64_t searches;
116 };
117
118 struct libhammer_io_stats {
119         int64_t undo;
120         int64_t dev_writes;
121         int64_t dev_reads;
122         int64_t file_writes;
123         int64_t file_reads;
124         int64_t file_iop_writes;
125         int64_t file_iop_reads;
126         int64_t inode_flushes;
127         int64_t commits;
128 };
129
130 /*
131  * Function prototypes
132  */
133 __BEGIN_DECLS
134 libhammer_fsinfo_t libhammer_get_fsinfo(const char *);
135 void libhammer_free_fsinfo(libhammer_fsinfo_t);
136
137 int libhammer_stats_redo(int64_t *);
138 int libhammer_stats_undo(int64_t *);
139 int libhammer_stats_commits(int64_t *);
140 int libhammer_stats_inode_flushes(int64_t *);
141 int libhammer_stats_disk_write(int64_t *);
142 int libhammer_stats_disk_read(int64_t *);
143 int libhammer_stats_file_iopsw(int64_t *);
144 int libhammer_stats_file_iopsr(int64_t *);
145 int libhammer_stats_file_write(int64_t *);
146 int libhammer_stats_file_read(int64_t *);
147 int libhammer_stats_record_iterations(int64_t *);
148 int libhammer_stats_root_iterations(int64_t *);
149 int libhammer_stats_btree_iterations(int64_t *);
150 int libhammer_stats_btree_splits(int64_t *);
151 int libhammer_stats_btree_elements(int64_t *);
152 int libhammer_stats_btree_deletes(int64_t *);
153 int libhammer_stats_btree_inserts(int64_t *);
154 int libhammer_stats_btree_lookups(int64_t *);
155 int libhammer_stats_btree_searches(int64_t *);
156 int libhammer_btree_stats(struct libhammer_btree_stats *);
157 int libhammer_io_stats(struct libhammer_io_stats *);
158
159 int libhammer_pfs_get_snapshots(libhammer_fsinfo_t, libhammer_pfsinfo_t);
160 void libhammer_pfs_free_snapshots(libhammer_pfsinfo_t);
161
162 char *libhammer_find_pfs_mount(uuid_t *);
163 void libhammer_pfs_canonical_path(char *, libhammer_pfsinfo_t, char **);
164 void *_libhammer_malloc(size_t);
165 void libhammer_compat_old_snapcount(libhammer_pfsinfo_t);
166 __END_DECLS
167
168 /*
169  * Wrappers to operate PFS TAILQ for each HAMMER filesystem
170  */
171 static __inline libhammer_pfsinfo_t
172 libhammer_get_next_pfs(libhammer_pfsinfo_t pfsinfo)
173 {
174         return TAILQ_NEXT(pfsinfo, entries);
175 }
176
177 static __inline libhammer_pfsinfo_t
178 libhammer_get_prev_pfs(libhammer_pfsinfo_t pfsinfo)
179 {
180         return TAILQ_PREV(pfsinfo, pfslist, entries);
181 }
182
183 static __inline libhammer_pfsinfo_t
184 libhammer_get_first_pfs(libhammer_fsinfo_t fip)
185 {
186         return TAILQ_FIRST(&fip->list_pseudo);
187 }
188
189 static __inline libhammer_pfsinfo_t
190 libhammer_get_last_pfs(libhammer_fsinfo_t fip)
191 {
192         return TAILQ_LAST(&fip->list_pseudo, pfslist);
193 }
194
195 /*
196  * Wrappers to operate snapshot TAILQ for each PFS
197  */
198 static __inline libhammer_snapinfo_t
199 libhammer_get_next_snap(libhammer_snapinfo_t sip)
200 {
201         return TAILQ_NEXT(sip, entries);
202 }
203
204 static __inline libhammer_snapinfo_t
205 libhammer_get_prev_snap(libhammer_snapinfo_t sip)
206 {
207         return TAILQ_PREV(sip, snaplist, entries);
208 }
209
210 static __inline libhammer_snapinfo_t
211 libhammer_get_first_snap(libhammer_pfsinfo_t pip)
212 {
213         return TAILQ_FIRST(&pip->list_snap);
214 }
215
216 static __inline libhammer_snapinfo_t
217 libhammer_get_last_snap(libhammer_pfsinfo_t pip)
218 {
219         return TAILQ_LAST(&pip->list_snap, snaplist);
220 }
221
222 #endif