HAMMER: Mirroring, misc bug fixes
[dragonfly.git] / sys / vfs / hammer / hammer_ioctl.h
blob80d783fde49f36dec8d1ee79489a2ed1675fe6d1
1 /*
2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.h,v 1.22 2008/07/31 04:42:04 dillon Exp $
37 * HAMMER ioctl's. This file can be #included from userland
40 #ifndef VFS_HAMMER_IOCTL_H_
41 #define VFS_HAMMER_IOCTL_H_
43 #include <sys/types.h>
44 #include <sys/ioccom.h>
45 #include "hammer_disk.h"
48 * Common HAMMER ioctl header
50 * Global flags are stored in the upper 16 bits.
52 struct hammer_ioc_head {
53 int32_t flags;
54 int32_t error;
55 int32_t reserved02[4];
58 #define HAMMER_IOC_HEAD_ERROR 0x00008000
59 #define HAMMER_IOC_HEAD_INTR 0x00010000
60 #define HAMMER_IOC_DO_BTREE 0x00020000 /* reblocker */
61 #define HAMMER_IOC_DO_INODES 0x00040000 /* reblocker */
62 #define HAMMER_IOC_DO_DATA 0x00080000 /* reblocker */
63 #define HAMMER_IOC_DO_DIRS 0x00100000 /* reblocker */
65 #define HAMMER_IOC_DO_FLAGS (HAMMER_IOC_DO_BTREE | \
66 HAMMER_IOC_DO_INODES | \
67 HAMMER_IOC_DO_DATA | \
68 HAMMER_IOC_DO_DIRS)
71 * HAMMERIOC_PRUNE
73 * beg/end TID ranges in the element array must be sorted in descending
74 * order, with the most recent (highest) range at elms[0].
76 struct hammer_ioc_prune_elm {
77 hammer_tid_t beg_tid; /* starting tid */
78 hammer_tid_t end_tid; /* ending tid (non inclusive) */
79 hammer_tid_t mod_tid; /* modulo */
82 #define HAMMER_MAX_PRUNE_ELMS (1024*1024/24)
84 struct hammer_ioc_prune {
85 struct hammer_ioc_head head;
86 int nelms;
87 int reserved01;
89 struct hammer_base_elm key_beg; /* stop forward scan (reverse scan) */
90 struct hammer_base_elm key_end; /* start forward scan (reverse scan) */
91 struct hammer_base_elm key_cur; /* scan interruption point */
93 int64_t stat_scanrecords;/* number of records scanned */
94 int64_t stat_rawrecords; /* number of raw records pruned */
95 int64_t stat_dirrecords; /* number of dir records pruned */
96 int64_t stat_bytes; /* number of data bytes pruned */
97 int64_t stat_realignments; /* number of raw records realigned */
98 hammer_tid_t stat_oldest_tid; /* oldest create_tid encountered */
99 int64_t reserved02[6];
100 struct hammer_ioc_prune_elm *elms; /* user supplied array */
103 #define HAMMER_IOC_PRUNE_ALL 0x0001
107 * HAMMERIOC_GETHISTORY
109 * Retrieve an array of ordered transaction ids >= beg and < end indicating
110 * all changes made to the specified object's inode up to the
111 * maximum.
113 * If ATKEY is set the key field indicates a particular key within the
114 * inode to retrieve the history for.
116 * On return count is set to the number of elements returned, nxt_tid is
117 * set to the tid the caller should store in beg_tid to continue the
118 * iteration, and nxt_key is set to the nearest key boundary > key
119 * indicating the range key - nxt_key (nxt_key non-inclusive) the tid
120 * array represents. Also obj_id is set to the object's inode number.
122 * nxt_key can be used to iterate the contents of a single file but should
123 * not be stored in key until all modifications at key have been retrieved.
124 * To work properly nxt_key should be initialized to HAMMER_MAX_KEY.
125 * Successive ioctl() calls will reduce nxt_key as appropriate so at the
126 * end of your iterating for 'key', key to nxt_key will represent the
127 * shortest range of keys that all returned TIDs apply to.
130 #define HAMMER_MAX_HISTORY_ELMS 64
132 typedef struct hammer_ioc_hist_entry {
133 hammer_tid_t tid;
134 u_int32_t time32;
135 u_int32_t unused;
136 } *hammer_ioc_hist_entry_t;
138 struct hammer_ioc_history {
139 struct hammer_ioc_head head;
140 int64_t obj_id;
141 hammer_tid_t beg_tid;
142 hammer_tid_t nxt_tid;
143 hammer_tid_t end_tid;
144 int64_t key;
145 int64_t nxt_key;
146 int count;
147 int reserve01;
148 struct hammer_ioc_hist_entry hist_ary[HAMMER_MAX_HISTORY_ELMS];
151 #define HAMMER_IOC_HISTORY_ATKEY 0x0001
152 #define HAMMER_IOC_HISTORY_NEXT_TID 0x0002 /* iterate via nxt_tid */
153 #define HAMMER_IOC_HISTORY_NEXT_KEY 0x0004 /* iterate via nxt_key */
154 #define HAMMER_IOC_HISTORY_EOF 0x0008 /* no more keys */
155 #define HAMMER_IOC_HISTORY_UNSYNCED 0x0010 /* unsynced info in inode */
158 * Reblock request
160 struct hammer_ioc_reblock {
161 struct hammer_ioc_head head;
162 int32_t free_level; /* 0 for maximum compaction */
163 u_int32_t reserved01;
165 struct hammer_base_elm key_beg; /* start forward scan */
166 struct hammer_base_elm key_end; /* stop forward scan */
167 struct hammer_base_elm key_cur; /* scan interruption point */
169 int64_t btree_count; /* B-Tree nodes checked */
170 int64_t record_count; /* Records checked */
171 int64_t data_count; /* Data segments checked */
172 int64_t data_byte_count; /* Data bytes checked */
174 int64_t btree_moves; /* B-Tree nodes moved */
175 int64_t record_moves; /* Records moved */
176 int64_t data_moves; /* Data segments moved */
177 int64_t data_byte_moves; /* Data bytes moved */
179 int32_t unused02;
180 int32_t unused03;
184 * HAMMERIOC_SYNCTID
186 enum hammer_synctid_op {
187 HAMMER_SYNCTID_NONE, /* no sync (TID will not be accurate) */
188 HAMMER_SYNCTID_ASYNC, /* async (TID will not be accurate) */
189 HAMMER_SYNCTID_SYNC1, /* single sync - might undo after crash */
190 HAMMER_SYNCTID_SYNC2 /* double sync - guarantee no undo */
193 struct hammer_ioc_synctid {
194 struct hammer_ioc_head head;
195 enum hammer_synctid_op op;
196 hammer_tid_t tid;
200 * HAMMERIOC_GET_PSEUDOFS
201 * HAMMERIOC_SET_PSEUDOFS
203 struct hammer_ioc_pseudofs_rw {
204 struct hammer_ioc_head head;
205 int pfs_id;
206 u_int32_t bytes;
207 u_int32_t version;
208 u_int32_t flags;
209 struct hammer_pseudofs_data *ondisk;
212 #define HAMMER_IOC_PSEUDOFS_VERSION 1
214 #define HAMMER_IOC_PFS_SYNC_BEG 0x0001
215 #define HAMMER_IOC_PFS_SYNC_END 0x0002
216 #define HAMMER_IOC_PFS_SHARED_UUID 0x0004
217 #define HAMMER_IOC_PFS_MIRROR_UUID 0x0008
218 #define HAMMER_IOC_PFS_MASTER_ID 0x0010
219 #define HAMMER_IOC_PFS_MIRROR_FLAGS 0x0020
220 #define HAMMER_IOC_PFS_LABEL 0x0040
222 #define HAMMER_MAX_PFS 65536
225 * HAMMERIOC_MIRROR_READ/WRITE
227 struct hammer_ioc_mirror_rw {
228 struct hammer_ioc_head head;
229 struct hammer_base_elm key_beg; /* start forward scan */
230 struct hammer_base_elm key_end; /* stop forward scan */
231 struct hammer_base_elm key_cur; /* interruption point */
232 hammer_tid_t tid_beg; /* filter modification range */
233 hammer_tid_t tid_end; /* filter modification range */
234 void *ubuf; /* user buffer */
235 int count; /* current size */
236 int size; /* max size */
237 int pfs_id; /* PFS id being read/written */
238 int reserved01;
239 uuid_t shared_uuid; /* validator for safety */
243 * NOTE: crc is for the data block starting at rec_size, not including the
244 * data[] array.
246 struct hammer_ioc_mrecord_head {
247 u_int32_t signature; /* signature for byte order */
248 u_int32_t rec_crc;
249 u_int32_t rec_size;
250 u_int32_t type;
251 /* extended */
254 typedef struct hammer_ioc_mrecord_head *hammer_ioc_mrecord_head_t;
256 struct hammer_ioc_mrecord_rec {
257 struct hammer_ioc_mrecord_head head;
258 struct hammer_btree_leaf_elm leaf;
259 /* extended by data */
262 struct hammer_ioc_mrecord_skip {
263 struct hammer_ioc_mrecord_head head;
264 struct hammer_base_elm skip_beg;
265 struct hammer_base_elm skip_end;
268 struct hammer_ioc_mrecord_update {
269 struct hammer_ioc_mrecord_head head;
270 hammer_tid_t tid;
273 struct hammer_ioc_mrecord_sync {
274 struct hammer_ioc_mrecord_head head;
277 struct hammer_ioc_mrecord_pfs {
278 struct hammer_ioc_mrecord_head head;
279 u_int32_t version;
280 u_int32_t reserved01;
281 struct hammer_pseudofs_data pfsd;
284 union hammer_ioc_mrecord_any {
285 struct hammer_ioc_mrecord_head head;
286 struct hammer_ioc_mrecord_rec rec;
287 struct hammer_ioc_mrecord_skip skip;
288 struct hammer_ioc_mrecord_update update;
289 struct hammer_ioc_mrecord_update sync;
290 struct hammer_ioc_mrecord_pfs pfs;
293 typedef union hammer_ioc_mrecord_any *hammer_ioc_mrecord_any_t;
295 #define HAMMER_MREC_TYPE_RESERVED 0
296 #define HAMMER_MREC_TYPE_REC 1 /* record w/ data */
297 #define HAMMER_MREC_TYPE_PFSD 2 /* (userland only) */
298 #define HAMMER_MREC_TYPE_UPDATE 3 /* (userland only) */
299 #define HAMMER_MREC_TYPE_SYNC 4 /* (userland only) */
300 #define HAMMER_MREC_TYPE_SKIP 5 /* skip-range */
301 #define HAMMER_MREC_TYPE_PASS 6 /* record for cmp only (pass) */
302 #define HAMMER_MREC_TYPE_TERM 7 /* (userland only) */
303 #define HAMMER_MREC_TYPE_IDLE 8 /* (userland only) */
305 #define HAMMER_MREC_CRCOFF (offsetof(struct hammer_ioc_mrecord_head, rec_size))
306 #define HAMMER_MREC_HEADSIZE sizeof(struct hammer_ioc_mrecord_head)
308 #define HAMMER_IOC_MIRROR_SIGNATURE 0x4dd97272U
309 #define HAMMER_IOC_MIRROR_SIGNATURE_REV 0x7272d94dU
312 * Ioctl cmd ids
315 #define HAMMERIOC_PRUNE _IOWR('h',1,struct hammer_ioc_prune)
316 #define HAMMERIOC_GETHISTORY _IOWR('h',2,struct hammer_ioc_history)
317 #define HAMMERIOC_REBLOCK _IOWR('h',3,struct hammer_ioc_reblock)
318 #define HAMMERIOC_SYNCTID _IOWR('h',4,struct hammer_ioc_synctid)
319 #define HAMMERIOC_SET_PSEUDOFS _IOWR('h',5,struct hammer_ioc_pseudofs_rw)
320 #define HAMMERIOC_GET_PSEUDOFS _IOWR('h',6,struct hammer_ioc_pseudofs_rw)
321 #define HAMMERIOC_MIRROR_READ _IOWR('h',7,struct hammer_ioc_mirror_rw)
322 #define HAMMERIOC_MIRROR_WRITE _IOWR('h',8,struct hammer_ioc_mirror_rw)
323 #define HAMMERIOC_UPG_PSEUDOFS _IOWR('h',9,struct hammer_ioc_pseudofs_rw)
324 #define HAMMERIOC_DGD_PSEUDOFS _IOWR('h',10,struct hammer_ioc_pseudofs_rw)
325 #define HAMMERIOC_RMR_PSEUDOFS _IOWR('h',11,struct hammer_ioc_pseudofs_rw)
326 #define HAMMERIOC_WAI_PSEUDOFS _IOWR('h',12,struct hammer_ioc_pseudofs_rw)
328 #endif