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: 10 * 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. 20 * 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. 33 * 34 * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.h,v 1.23 2008/11/13 02:18:43 dillon Exp $ 35 */ 36 /* 37 * HAMMER ioctl's. This file can be #included from userland 38 */ 39 40 #ifndef VFS_HAMMER_IOCTL_H_ 41 #define VFS_HAMMER_IOCTL_H_ 42 43 #include <sys/param.h> 44 #include <sys/ioccom.h> 45 #include "hammer_disk.h" 46 47 /* 48 * Common HAMMER ioctl header 49 * 50 * Global flags are stored in the upper 16 bits. 51 */ 52 struct hammer_ioc_head { 53 int32_t flags; 54 int32_t error; 55 int32_t reserved02[4]; 56 }; 57 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 */ 64 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) 69 70 /* 71 * HAMMERIOC_PRUNE 72 * 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]. 75 */ 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 */ 80 }; 81 82 #define HAMMER_MAX_PRUNE_ELMS (1024*1024/24) 83 84 struct hammer_ioc_prune { 85 struct hammer_ioc_head head; 86 int nelms; 87 int reserved01; 88 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 */ 92 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 */ 101 }; 102 103 #define HAMMER_IOC_PRUNE_ALL 0x0001 104 105 /* 106 * HAMMERIOC_REPACK 107 * 108 * Forward scan leaf-up B-Tree packing. The saturation point is typically 109 * set to HAMMER_BTREE_LEAF_ELMS * 2 / 3 for 2/3rds fill. Referenced nodes 110 * have to be skipped, we can't track cursors through pack ops. 111 */ 112 struct hammer_ioc_rebalance { 113 struct hammer_ioc_head head; 114 int saturation; /* saturation pt elements/node */ 115 int reserved02; 116 117 struct hammer_base_elm key_beg; /* start forward scan */ 118 struct hammer_base_elm key_end; /* stop forward scan (inclusive) */ 119 struct hammer_base_elm key_cur; /* current scan index */ 120 121 int64_t stat_ncount; /* number of nodes scanned */ 122 int64_t stat_deletions; /* number of nodes deleted */ 123 int64_t stat_collisions;/* number of collision retries */ 124 int64_t stat_nrebal; /* number of btree-nodes rebalanced */ 125 int32_t allpfs; /* rebalance all PFS if set */ 126 int32_t unused04; 127 }; 128 129 /* 130 * HAMMERIOC_GETHISTORY 131 * 132 * Retrieve an array of ordered transaction ids >= beg and < end indicating 133 * all changes made to the specified object's inode up to the 134 * maximum. 135 * 136 * If ATKEY is set the key field indicates a particular key within the 137 * inode to retrieve the history for. 138 * 139 * On return count is set to the number of elements returned, nxt_tid is 140 * set to the tid the caller should store in beg_tid to continue the 141 * iteration, and nxt_key is set to the nearest key boundary > key 142 * indicating the range key - nxt_key (nxt_key non-inclusive) the tid 143 * array represents. Also obj_id is set to the object's inode number. 144 * 145 * nxt_key can be used to iterate the contents of a single file but should 146 * not be stored in key until all modifications at key have been retrieved. 147 * To work properly nxt_key should be initialized to HAMMER_MAX_KEY. 148 * Successive ioctl() calls will reduce nxt_key as appropriate so at the 149 * end of your iterating for 'key', key to nxt_key will represent the 150 * shortest range of keys that all returned TIDs apply to. 151 */ 152 153 #define HAMMER_MAX_HISTORY_ELMS 64 154 155 typedef struct hammer_ioc_hist_entry { 156 hammer_tid_t tid; 157 u_int32_t time32; 158 u_int32_t unused; 159 } *hammer_ioc_hist_entry_t; 160 161 struct hammer_ioc_history { 162 struct hammer_ioc_head head; 163 int64_t obj_id; 164 hammer_tid_t beg_tid; 165 hammer_tid_t nxt_tid; 166 hammer_tid_t end_tid; 167 int64_t key; 168 int64_t nxt_key; 169 int count; 170 int reserve01; 171 struct hammer_ioc_hist_entry hist_ary[HAMMER_MAX_HISTORY_ELMS]; 172 }; 173 174 #define HAMMER_IOC_HISTORY_ATKEY 0x0001 175 #define HAMMER_IOC_HISTORY_NEXT_TID 0x0002 /* iterate via nxt_tid */ 176 #define HAMMER_IOC_HISTORY_NEXT_KEY 0x0004 /* iterate via nxt_key */ 177 #define HAMMER_IOC_HISTORY_EOF 0x0008 /* no more keys */ 178 #define HAMMER_IOC_HISTORY_UNSYNCED 0x0010 /* unsynced info in inode */ 179 180 /* 181 * Reblock request 182 */ 183 struct hammer_ioc_reblock { 184 struct hammer_ioc_head head; 185 int32_t free_level; /* 0 for maximum compaction */ 186 u_int32_t reserved01; 187 188 struct hammer_base_elm key_beg; /* start forward scan */ 189 struct hammer_base_elm key_end; /* stop forward scan */ 190 struct hammer_base_elm key_cur; /* scan interruption point */ 191 192 int64_t btree_count; /* B-Tree nodes checked */ 193 int64_t record_count; /* Records checked */ 194 int64_t data_count; /* Data segments checked */ 195 int64_t data_byte_count; /* Data bytes checked */ 196 197 int64_t btree_moves; /* B-Tree nodes moved */ 198 int64_t record_moves; /* Records moved */ 199 int64_t data_moves; /* Data segments moved */ 200 int64_t data_byte_moves; /* Data bytes moved */ 201 202 int32_t allpfs; /* Reblock all PFS if set */ 203 int32_t unused03; 204 }; 205 206 /* 207 * HAMMERIOC_SYNCTID 208 */ 209 enum hammer_synctid_op { 210 HAMMER_SYNCTID_NONE, /* no sync (TID will not be accurate) */ 211 HAMMER_SYNCTID_ASYNC, /* async (TID will not be accurate) */ 212 HAMMER_SYNCTID_SYNC1, /* single sync - might undo after crash */ 213 HAMMER_SYNCTID_SYNC2 /* double sync - guarantee no undo */ 214 }; 215 216 struct hammer_ioc_synctid { 217 struct hammer_ioc_head head; 218 enum hammer_synctid_op op; 219 hammer_tid_t tid; 220 }; 221 222 /* 223 * HAMMERIOC_GET_INFO 224 */ 225 struct hammer_ioc_info { 226 struct hammer_ioc_head head; 227 228 char vol_name[64]; 229 uuid_t vol_fsid; 230 uuid_t vol_fstype; 231 232 int version; 233 int nvolumes; 234 int reserved01; 235 int reserved02; 236 237 int64_t bigblocks; 238 int64_t freebigblocks; 239 int64_t rsvbigblocks; 240 int64_t inodes; 241 242 int64_t reservedext[16]; 243 }; 244 245 /* 246 * HAMMERIOC_PFS_ITERATE 247 */ 248 struct hammer_ioc_pfs_iterate { 249 struct hammer_ioc_head head; 250 uint32_t pos; /* set PFS id here */ 251 struct hammer_pseudofs_data *ondisk; 252 }; 253 254 /* 255 * HAMMERIOC_GET_PSEUDOFS 256 * HAMMERIOC_SET_PSEUDOFS 257 */ 258 struct hammer_ioc_pseudofs_rw { 259 struct hammer_ioc_head head; 260 int pfs_id; 261 u_int32_t bytes; 262 u_int32_t version; 263 u_int32_t flags; 264 struct hammer_pseudofs_data *ondisk; 265 }; 266 267 #define HAMMER_IOC_PSEUDOFS_VERSION 1 268 269 #define HAMMER_IOC_PFS_SYNC_BEG 0x0001 270 #define HAMMER_IOC_PFS_SYNC_END 0x0002 271 #define HAMMER_IOC_PFS_SHARED_UUID 0x0004 272 #define HAMMER_IOC_PFS_MIRROR_UUID 0x0008 273 #define HAMMER_IOC_PFS_MASTER_ID 0x0010 274 #define HAMMER_IOC_PFS_MIRROR_FLAGS 0x0020 275 #define HAMMER_IOC_PFS_LABEL 0x0040 276 277 #define HAMMER_MAX_PFS 65536 278 279 /* 280 * HAMMERIOC_MIRROR_READ/WRITE 281 */ 282 struct hammer_ioc_mirror_rw { 283 struct hammer_ioc_head head; 284 struct hammer_base_elm key_beg; /* start forward scan */ 285 struct hammer_base_elm key_end; /* stop forward scan */ 286 struct hammer_base_elm key_cur; /* interruption point */ 287 hammer_tid_t tid_beg; /* filter modification range */ 288 hammer_tid_t tid_end; /* filter modification range */ 289 void *ubuf; /* user buffer */ 290 int count; /* current size */ 291 int size; /* max size */ 292 int pfs_id; /* PFS id being read/written */ 293 int reserved01; 294 uuid_t shared_uuid; /* validator for safety */ 295 }; 296 297 #define HAMMER_IOC_MIRROR_NODATA 0x0001 /* do not include bulk data */ 298 299 /* 300 * NOTE: crc is for the data block starting at rec_size, not including the 301 * data[] array. 302 */ 303 struct hammer_ioc_mrecord_head { 304 u_int32_t signature; /* signature for byte order */ 305 u_int32_t rec_crc; 306 u_int32_t rec_size; 307 u_int32_t type; 308 /* extended */ 309 }; 310 311 typedef struct hammer_ioc_mrecord_head *hammer_ioc_mrecord_head_t; 312 313 struct hammer_ioc_mrecord_rec { 314 struct hammer_ioc_mrecord_head head; 315 struct hammer_btree_leaf_elm leaf; 316 /* extended by data */ 317 }; 318 319 struct hammer_ioc_mrecord_skip { 320 struct hammer_ioc_mrecord_head head; 321 struct hammer_base_elm skip_beg; 322 struct hammer_base_elm skip_end; 323 }; 324 325 struct hammer_ioc_mrecord_update { 326 struct hammer_ioc_mrecord_head head; 327 hammer_tid_t tid; 328 }; 329 330 struct hammer_ioc_mrecord_sync { 331 struct hammer_ioc_mrecord_head head; 332 }; 333 334 struct hammer_ioc_mrecord_pfs { 335 struct hammer_ioc_mrecord_head head; 336 u_int32_t version; 337 u_int32_t reserved01; 338 struct hammer_pseudofs_data pfsd; 339 }; 340 341 struct hammer_ioc_version { 342 struct hammer_ioc_head head; 343 u_int32_t cur_version; 344 u_int32_t min_version; 345 u_int32_t wip_version; 346 u_int32_t max_version; 347 char description[64]; 348 }; 349 350 struct hammer_ioc_volume { 351 struct hammer_ioc_head head; 352 char device_name[MAXPATHLEN]; 353 int64_t vol_size; 354 int64_t boot_area_size; 355 int64_t mem_area_size; 356 }; 357 358 struct hammer_ioc_volume_list { 359 struct hammer_ioc_volume *vols; 360 int nvols; 361 }; 362 363 union hammer_ioc_mrecord_any { 364 struct hammer_ioc_mrecord_head head; 365 struct hammer_ioc_mrecord_rec rec; 366 struct hammer_ioc_mrecord_skip skip; 367 struct hammer_ioc_mrecord_update update; 368 struct hammer_ioc_mrecord_update sync; 369 struct hammer_ioc_mrecord_pfs pfs; 370 struct hammer_ioc_version version; 371 }; 372 373 typedef union hammer_ioc_mrecord_any *hammer_ioc_mrecord_any_t; 374 375 /* 376 * MREC types. Flags are in the upper 16 bits but some are also included 377 * in the type mask to force them into any switch() on the type. 378 * 379 * NOTE: Any record whos data is CRC-errored will have HAMMER_MRECF_CRC set, 380 * and the bit is also part of the type mask. 381 */ 382 #define HAMMER_MREC_TYPE_RESERVED 0 383 #define HAMMER_MREC_TYPE_REC 1 /* record w/ data */ 384 #define HAMMER_MREC_TYPE_PFSD 2 /* (userland only) */ 385 #define HAMMER_MREC_TYPE_UPDATE 3 /* (userland only) */ 386 #define HAMMER_MREC_TYPE_SYNC 4 /* (userland only) */ 387 #define HAMMER_MREC_TYPE_SKIP 5 /* skip-range */ 388 #define HAMMER_MREC_TYPE_PASS 6 /* record for cmp only (pass) */ 389 #define HAMMER_MREC_TYPE_TERM 7 /* (userland only) */ 390 #define HAMMER_MREC_TYPE_IDLE 8 /* (userland only) */ 391 392 #define HAMMER_MREC_TYPE_REC_BADCRC (HAMMER_MREC_TYPE_REC | \ 393 HAMMER_MRECF_CRC_ERROR) 394 #define HAMMER_MREC_TYPE_REC_NODATA (HAMMER_MREC_TYPE_REC | \ 395 HAMMER_MRECF_NODATA) 396 397 #define HAMMER_MRECF_TYPE_LOMASK 0x000000FF 398 #define HAMMER_MRECF_TYPE_MASK 0x800000FF 399 #define HAMMER_MRECF_CRC_ERROR 0x80000000 400 401 #define HAMMER_MRECF_DATA_CRC_BAD 0x40000000 402 #define HAMMER_MRECF_RECD_CRC_BAD 0x20000000 403 #define HAMMER_MRECF_NODATA 0x10000000 404 405 #define HAMMER_MREC_CRCOFF (offsetof(struct hammer_ioc_mrecord_head, rec_size)) 406 #define HAMMER_MREC_HEADSIZE sizeof(struct hammer_ioc_mrecord_head) 407 408 #define HAMMER_IOC_MIRROR_SIGNATURE 0x4dd97272U 409 #define HAMMER_IOC_MIRROR_SIGNATURE_REV 0x7272d94dU 410 411 /* 412 * HAMMERIOC_ADD_SNAPSHOT - Add snapshot tid(s). 413 * HAMMERIOC_DEL_SNAPSHOT - Delete snapshot tids. 414 * HAMMERIOC_GET_SNAPSHOT - Get/continue retrieving snapshot tids. 415 * (finds restart point based on last snaps[] entry) 416 * 417 * These are per-PFS operations. 418 * 419 * NOTE: There is no limit on the number of snapshots, but there is a limit 420 * on how many can be set or returned in each ioctl. 421 * 422 * NOTE: ADD and DEL start at snap->index. If an error occurs the index will 423 * point at the errored record. snap->index must be set to 0 for GET. 424 */ 425 #define HAMMER_SNAPS_PER_IOCTL 16 426 427 #define HAMMER_IOC_SNAPSHOT_EOF 0x0008 /* no more keys */ 428 429 struct hammer_ioc_snapshot { 430 struct hammer_ioc_head head; 431 int unused01; 432 u_int32_t index; 433 u_int32_t count; 434 struct hammer_snapshot_data snaps[HAMMER_SNAPS_PER_IOCTL]; 435 }; 436 437 /* 438 * HAMMERIOC_GET_CONFIG 439 * HAMMERIOC_SET_CONFIG 440 * 441 * The configuration space is a freeform nul-terminated string, typically 442 * a text file. It is per-PFS and used by the 'hammer cleanup' utility. 443 * 444 * The configuration space is NOT mirrored. mirror-write will ignore 445 * configuration space records. 446 */ 447 struct hammer_ioc_config { 448 struct hammer_ioc_head head; 449 u_int32_t reserved01; 450 u_int32_t reserved02; 451 u_int64_t reserved03[4]; 452 struct hammer_config_data config; 453 }; 454 455 /* 456 * HAMMERIOC_DEDUP 457 */ 458 struct hammer_ioc_dedup { 459 struct hammer_ioc_head head; 460 struct hammer_base_elm elm1; 461 struct hammer_base_elm elm2; /* candidate for dedup */ 462 }; 463 464 #define HAMMER_IOC_DEDUP_CMP_FAILURE 0x0001 /* verification failed */ 465 #define HAMMER_IOC_DEDUP_UNDERFLOW 0x0002 /* big-block underflow */ 466 #define HAMMER_IOC_DEDUP_INVALID_ZONE 0x0004 /* we can't dedup all zones */ 467 468 /* 469 * HAMMERIOC_GET_DATA 470 */ 471 struct hammer_ioc_data { 472 struct hammer_ioc_head head; 473 struct hammer_base_elm elm; /* btree key to lookup */ 474 struct hammer_btree_leaf_elm leaf; 475 void *ubuf; /* user buffer */ 476 int size; /* max size */ 477 }; 478 479 /* 480 * Ioctl cmd ids 481 */ 482 #define HAMMERIOC_PRUNE _IOWR('h',1,struct hammer_ioc_prune) 483 #define HAMMERIOC_GETHISTORY _IOWR('h',2,struct hammer_ioc_history) 484 #define HAMMERIOC_REBLOCK _IOWR('h',3,struct hammer_ioc_reblock) 485 #define HAMMERIOC_SYNCTID _IOWR('h',4,struct hammer_ioc_synctid) 486 #define HAMMERIOC_SET_PSEUDOFS _IOWR('h',5,struct hammer_ioc_pseudofs_rw) 487 #define HAMMERIOC_GET_PSEUDOFS _IOWR('h',6,struct hammer_ioc_pseudofs_rw) 488 #define HAMMERIOC_MIRROR_READ _IOWR('h',7,struct hammer_ioc_mirror_rw) 489 #define HAMMERIOC_MIRROR_WRITE _IOWR('h',8,struct hammer_ioc_mirror_rw) 490 #define HAMMERIOC_UPG_PSEUDOFS _IOWR('h',9,struct hammer_ioc_pseudofs_rw) 491 #define HAMMERIOC_DGD_PSEUDOFS _IOWR('h',10,struct hammer_ioc_pseudofs_rw) 492 #define HAMMERIOC_RMR_PSEUDOFS _IOWR('h',11,struct hammer_ioc_pseudofs_rw) 493 #define HAMMERIOC_WAI_PSEUDOFS _IOWR('h',12,struct hammer_ioc_pseudofs_rw) 494 #define HAMMERIOC_GET_VERSION _IOWR('h',13,struct hammer_ioc_version) 495 #define HAMMERIOC_SET_VERSION _IOWR('h',14,struct hammer_ioc_version) 496 #define HAMMERIOC_REBALANCE _IOWR('h',15,struct hammer_ioc_rebalance) 497 #define HAMMERIOC_GET_INFO _IOR('h',16,struct hammer_ioc_info) 498 #define HAMMERIOC_ADD_VOLUME _IOWR('h',17,struct hammer_ioc_volume) 499 #define HAMMERIOC_ADD_SNAPSHOT _IOWR('h',18,struct hammer_ioc_snapshot) 500 #define HAMMERIOC_DEL_SNAPSHOT _IOWR('h',19,struct hammer_ioc_snapshot) 501 #define HAMMERIOC_GET_SNAPSHOT _IOWR('h',20,struct hammer_ioc_snapshot) 502 #define HAMMERIOC_GET_CONFIG _IOWR('h',21,struct hammer_ioc_config) 503 #define HAMMERIOC_SET_CONFIG _IOWR('h',22,struct hammer_ioc_config) 504 #define HAMMERIOC_DEL_VOLUME _IOWR('h',24,struct hammer_ioc_volume) 505 #define HAMMERIOC_DEDUP _IOWR('h',25,struct hammer_ioc_dedup) 506 #define HAMMERIOC_GET_DATA _IOWR('h',26,struct hammer_ioc_data) 507 #define HAMMERIOC_LIST_VOLUMES _IOWR('h',27,struct hammer_ioc_volume_list) 508 #define HAMMERIOC_PFS_ITERATE _IOWR('h',28,struct hammer_ioc_pfs_iterate) 509 510 #endif 511 512