2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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
34 * $DragonFly: src/sys/vfs/hammer/hammer_ioctl.c,v 1.32 2008/11/13 02:23:29 dillon Exp $
39 static int hammer_ioc_gethistory(hammer_transaction_t trans, hammer_inode_t ip,
40 struct hammer_ioc_history *hist);
41 static int hammer_ioc_synctid(hammer_transaction_t trans, hammer_inode_t ip,
42 struct hammer_ioc_synctid *std);
43 static int hammer_ioc_get_version(hammer_transaction_t trans,
45 struct hammer_ioc_version *ver);
46 static int hammer_ioc_set_version(hammer_transaction_t trans,
48 struct hammer_ioc_version *ver);
49 static int hammer_ioc_get_info(hammer_transaction_t trans,
50 struct hammer_ioc_info *info);
51 static int hammer_ioc_add_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
52 struct hammer_ioc_snapshot *snap);
53 static int hammer_ioc_del_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
54 struct hammer_ioc_snapshot *snap);
55 static int hammer_ioc_get_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
56 struct hammer_ioc_snapshot *snap);
57 static int hammer_ioc_get_config(hammer_transaction_t trans, hammer_inode_t ip,
58 struct hammer_ioc_config *snap);
59 static int hammer_ioc_set_config(hammer_transaction_t trans, hammer_inode_t ip,
60 struct hammer_ioc_config *snap);
63 hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
66 struct hammer_transaction trans;
69 error = priv_check_cred(cred, PRIV_HAMMER_IOCTL, 0);
71 hammer_start_transaction(&trans, ip->hmp);
76 error = hammer_ioc_prune(&trans, ip,
77 (struct hammer_ioc_prune *)data);
80 case HAMMERIOC_GETHISTORY:
81 error = hammer_ioc_gethistory(&trans, ip,
82 (struct hammer_ioc_history *)data);
84 case HAMMERIOC_REBLOCK:
86 error = hammer_ioc_reblock(&trans, ip,
87 (struct hammer_ioc_reblock *)data);
90 case HAMMERIOC_REBALANCE:
92 error = hammer_ioc_rebalance(&trans, ip,
93 (struct hammer_ioc_rebalance *)data);
96 case HAMMERIOC_SYNCTID:
97 error = hammer_ioc_synctid(&trans, ip,
98 (struct hammer_ioc_synctid *)data);
100 case HAMMERIOC_GET_PSEUDOFS:
101 error = hammer_ioc_get_pseudofs(&trans, ip,
102 (struct hammer_ioc_pseudofs_rw *)data);
104 case HAMMERIOC_SET_PSEUDOFS:
106 error = hammer_ioc_set_pseudofs(&trans, ip, cred,
107 (struct hammer_ioc_pseudofs_rw *)data);
110 case HAMMERIOC_UPG_PSEUDOFS:
112 error = hammer_ioc_upgrade_pseudofs(&trans, ip,
113 (struct hammer_ioc_pseudofs_rw *)data);
116 case HAMMERIOC_DGD_PSEUDOFS:
118 error = hammer_ioc_downgrade_pseudofs(&trans, ip,
119 (struct hammer_ioc_pseudofs_rw *)data);
122 case HAMMERIOC_RMR_PSEUDOFS:
124 error = hammer_ioc_destroy_pseudofs(&trans, ip,
125 (struct hammer_ioc_pseudofs_rw *)data);
128 case HAMMERIOC_WAI_PSEUDOFS:
130 error = hammer_ioc_wait_pseudofs(&trans, ip,
131 (struct hammer_ioc_pseudofs_rw *)data);
134 case HAMMERIOC_MIRROR_READ:
136 error = hammer_ioc_mirror_read(&trans, ip,
137 (struct hammer_ioc_mirror_rw *)data);
140 case HAMMERIOC_MIRROR_WRITE:
142 error = hammer_ioc_mirror_write(&trans, ip,
143 (struct hammer_ioc_mirror_rw *)data);
146 case HAMMERIOC_GET_VERSION:
147 error = hammer_ioc_get_version(&trans, ip,
148 (struct hammer_ioc_version *)data);
150 case HAMMERIOC_GET_INFO:
151 error = hammer_ioc_get_info(&trans,
152 (struct hammer_ioc_info *)data);
154 case HAMMERIOC_SET_VERSION:
156 error = hammer_ioc_set_version(&trans, ip,
157 (struct hammer_ioc_version *)data);
160 case HAMMERIOC_EXPAND:
162 error = priv_check_cred(cred, PRIV_HAMMER_EXPAND, 0);
164 error = hammer_ioc_expand(&trans, ip,
165 (struct hammer_ioc_expand *)data);
168 case HAMMERIOC_ADD_SNAPSHOT:
170 error = hammer_ioc_add_snapshot(
171 &trans, ip, (struct hammer_ioc_snapshot *)data);
174 case HAMMERIOC_DEL_SNAPSHOT:
176 error = hammer_ioc_del_snapshot(
177 &trans, ip, (struct hammer_ioc_snapshot *)data);
180 case HAMMERIOC_GET_SNAPSHOT:
181 error = hammer_ioc_get_snapshot(
182 &trans, ip, (struct hammer_ioc_snapshot *)data);
184 case HAMMERIOC_GET_CONFIG:
185 error = hammer_ioc_get_config(
186 &trans, ip, (struct hammer_ioc_config *)data);
188 case HAMMERIOC_SET_CONFIG:
190 error = hammer_ioc_set_config(
191 &trans, ip, (struct hammer_ioc_config *)data);
198 hammer_done_transaction(&trans);
203 * Iterate through an object's inode or an object's records and record
206 static void add_history(hammer_inode_t ip, struct hammer_ioc_history *hist,
207 hammer_btree_elm_t elm);
211 hammer_ioc_gethistory(hammer_transaction_t trans, hammer_inode_t ip,
212 struct hammer_ioc_history *hist)
214 struct hammer_cursor cursor;
215 hammer_btree_elm_t elm;
219 * Validate the structure and initialize for return.
221 if (hist->beg_tid > hist->end_tid)
223 if (hist->head.flags & HAMMER_IOC_HISTORY_ATKEY) {
224 if (hist->key > hist->nxt_key)
228 hist->obj_id = ip->obj_id;
230 hist->nxt_tid = hist->end_tid;
231 hist->head.flags &= ~HAMMER_IOC_HISTORY_NEXT_TID;
232 hist->head.flags &= ~HAMMER_IOC_HISTORY_NEXT_KEY;
233 hist->head.flags &= ~HAMMER_IOC_HISTORY_EOF;
234 hist->head.flags &= ~HAMMER_IOC_HISTORY_UNSYNCED;
235 if ((ip->flags & HAMMER_INODE_MODMASK) &
236 ~(HAMMER_INODE_ATIME | HAMMER_INODE_MTIME)) {
237 hist->head.flags |= HAMMER_IOC_HISTORY_UNSYNCED;
241 * Setup the cursor. We can't handle undeletable records
242 * (create_tid of 0) at the moment. A create_tid of 0 has
243 * a special meaning and cannot be specified in the cursor.
245 error = hammer_init_cursor(trans, &cursor, &ip->cache[0], NULL);
247 hammer_done_cursor(&cursor);
251 cursor.key_beg.obj_id = hist->obj_id;
252 cursor.key_beg.create_tid = hist->beg_tid;
253 cursor.key_beg.delete_tid = 0;
254 cursor.key_beg.obj_type = 0;
255 if (cursor.key_beg.create_tid == HAMMER_MIN_TID)
256 cursor.key_beg.create_tid = 1;
258 cursor.key_end.obj_id = hist->obj_id;
259 cursor.key_end.create_tid = hist->end_tid;
260 cursor.key_end.delete_tid = 0;
261 cursor.key_end.obj_type = 0;
263 cursor.flags |= HAMMER_CURSOR_END_EXCLUSIVE;
265 if (hist->head.flags & HAMMER_IOC_HISTORY_ATKEY) {
267 * key-range within the file. For a regular file the
268 * on-disk key represents BASE+LEN, not BASE, so the
269 * first possible record containing the offset 'key'
270 * has an on-disk key of (key + 1).
272 cursor.key_beg.key = hist->key;
273 cursor.key_end.key = HAMMER_MAX_KEY;
274 cursor.key_beg.localization = ip->obj_localization +
275 HAMMER_LOCALIZE_MISC;
276 cursor.key_end.localization = ip->obj_localization +
277 HAMMER_LOCALIZE_MISC;
279 switch(ip->ino_data.obj_type) {
280 case HAMMER_OBJTYPE_REGFILE:
281 ++cursor.key_beg.key;
282 cursor.key_beg.rec_type = HAMMER_RECTYPE_DATA;
284 case HAMMER_OBJTYPE_DIRECTORY:
285 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
286 cursor.key_beg.localization = ip->obj_localization +
287 hammer_dir_localization(ip);
288 cursor.key_end.localization = ip->obj_localization +
289 hammer_dir_localization(ip);
291 case HAMMER_OBJTYPE_DBFILE:
292 cursor.key_beg.rec_type = HAMMER_RECTYPE_DB;
298 cursor.key_end.rec_type = cursor.key_beg.rec_type;
303 cursor.key_beg.key = 0;
304 cursor.key_end.key = 0;
305 cursor.key_beg.rec_type = HAMMER_RECTYPE_INODE;
306 cursor.key_end.rec_type = HAMMER_RECTYPE_INODE;
307 cursor.key_beg.localization = ip->obj_localization +
308 HAMMER_LOCALIZE_INODE;
309 cursor.key_end.localization = ip->obj_localization +
310 HAMMER_LOCALIZE_INODE;
313 error = hammer_btree_first(&cursor);
315 elm = &cursor.node->ondisk->elms[cursor.index];
317 add_history(ip, hist, elm);
318 if (hist->head.flags & (HAMMER_IOC_HISTORY_NEXT_TID |
319 HAMMER_IOC_HISTORY_NEXT_KEY |
320 HAMMER_IOC_HISTORY_EOF)) {
323 error = hammer_btree_iterate(&cursor);
325 if (error == ENOENT) {
326 hist->head.flags |= HAMMER_IOC_HISTORY_EOF;
329 hammer_done_cursor(&cursor);
334 * Add the scanned element to the ioctl return structure. Some special
335 * casing is required for regular files to accomodate how data ranges are
339 add_history(hammer_inode_t ip, struct hammer_ioc_history *hist,
340 hammer_btree_elm_t elm)
344 if (elm->base.btype != HAMMER_BTREE_TYPE_RECORD)
346 if ((hist->head.flags & HAMMER_IOC_HISTORY_ATKEY) &&
347 ip->ino_data.obj_type == HAMMER_OBJTYPE_REGFILE) {
351 if (hist->nxt_key > elm->leaf.base.key - elm->leaf.data_len &&
352 hist->key < elm->leaf.base.key - elm->leaf.data_len) {
353 hist->nxt_key = elm->leaf.base.key - elm->leaf.data_len;
355 if (hist->nxt_key > elm->leaf.base.key)
356 hist->nxt_key = elm->leaf.base.key;
359 * Record is beyond MAXPHYS, there won't be any more records
360 * in the iteration covering the requested offset (key).
362 if (elm->leaf.base.key >= MAXPHYS &&
363 elm->leaf.base.key - MAXPHYS > hist->key) {
364 hist->head.flags |= HAMMER_IOC_HISTORY_NEXT_KEY;
368 * Data-range of record does not cover the key.
370 if (elm->leaf.base.key - elm->leaf.data_len > hist->key)
373 } else if (hist->head.flags & HAMMER_IOC_HISTORY_ATKEY) {
377 if (hist->nxt_key > elm->leaf.base.key &&
378 hist->key < elm->leaf.base.key) {
379 hist->nxt_key = elm->leaf.base.key;
383 * Record is beyond the requested key.
385 if (elm->leaf.base.key > hist->key)
386 hist->head.flags |= HAMMER_IOC_HISTORY_NEXT_KEY;
390 * Add create_tid if it is in-bounds.
394 elm->leaf.base.create_tid != hist->hist_ary[i - 1].tid) &&
395 elm->leaf.base.create_tid >= hist->beg_tid &&
396 elm->leaf.base.create_tid < hist->end_tid) {
397 if (hist->count == HAMMER_MAX_HISTORY_ELMS) {
398 hist->nxt_tid = elm->leaf.base.create_tid;
399 hist->head.flags |= HAMMER_IOC_HISTORY_NEXT_TID;
402 hist->hist_ary[i].tid = elm->leaf.base.create_tid;
403 hist->hist_ary[i].time32 = elm->leaf.create_ts;
408 * Add delete_tid if it is in-bounds. Note that different portions
409 * of the history may have overlapping data ranges with different
410 * delete_tid's. If this case occurs the delete_tid may match the
411 * create_tid of a following record. XXX
417 if (elm->leaf.base.delete_tid &&
418 elm->leaf.base.delete_tid >= hist->beg_tid &&
419 elm->leaf.base.delete_tid < hist->end_tid) {
420 if (i == HAMMER_MAX_HISTORY_ELMS) {
421 hist->nxt_tid = elm->leaf.base.delete_tid;
422 hist->head.flags |= HAMMER_IOC_HISTORY_NEXT_TID;
425 hist->hist_ary[i].tid = elm->leaf.base.delete_tid;
426 hist->hist_ary[i].time32 = elm->leaf.delete_ts;
432 * Acquire synchronization TID
436 hammer_ioc_synctid(hammer_transaction_t trans, hammer_inode_t ip,
437 struct hammer_ioc_synctid *std)
439 hammer_mount_t hmp = ip->hmp;
443 case HAMMER_SYNCTID_NONE:
444 std->tid = hmp->flusher.tid; /* inaccurate */
446 case HAMMER_SYNCTID_ASYNC:
447 hammer_queue_inodes_flusher(hmp, MNT_NOWAIT);
448 hammer_flusher_async(hmp, NULL);
449 std->tid = hmp->flusher.tid; /* inaccurate */
451 case HAMMER_SYNCTID_SYNC1:
452 hammer_queue_inodes_flusher(hmp, MNT_WAIT);
453 hammer_flusher_sync(hmp);
454 std->tid = hmp->flusher.tid;
456 case HAMMER_SYNCTID_SYNC2:
457 hammer_queue_inodes_flusher(hmp, MNT_WAIT);
458 hammer_flusher_sync(hmp);
459 std->tid = hmp->flusher.tid;
460 hammer_flusher_sync(hmp);
470 * Retrieve version info.
472 * Load min_version, wip_version, and max_versino. If cur_version is passed
473 * as 0 then load the current version into cur_version. Load the description
474 * for cur_version into the description array.
476 * Returns 0 on success, EINVAL if cur_version is non-zero and set to an
481 hammer_ioc_get_version(hammer_transaction_t trans, hammer_inode_t ip,
482 struct hammer_ioc_version *ver)
486 ver->min_version = HAMMER_VOL_VERSION_MIN;
487 ver->wip_version = HAMMER_VOL_VERSION_WIP;
488 ver->max_version = HAMMER_VOL_VERSION_MAX;
489 if (ver->cur_version == 0)
490 ver->cur_version = trans->hmp->version;
491 switch(ver->cur_version) {
493 ksnprintf(ver->description, sizeof(ver->description),
494 "First HAMMER release (DragonFly 2.0+)");
497 ksnprintf(ver->description, sizeof(ver->description),
498 "New directory entry layout (DragonFly 2.3+)");
501 ksnprintf(ver->description, sizeof(ver->description),
502 "New snapshot management (DragonFly 2.5+)");
505 ksnprintf(ver->description, sizeof(ver->description),
518 hammer_ioc_set_version(hammer_transaction_t trans, hammer_inode_t ip,
519 struct hammer_ioc_version *ver)
521 struct hammer_cursor cursor;
522 hammer_volume_t volume;
525 if (ver->cur_version < trans->hmp->version)
527 if (ver->cur_version == trans->hmp->version)
529 if (ver->cur_version > HAMMER_VOL_VERSION_MAX)
531 if (trans->hmp->ronly)
535 * Update the root volume header and the version cached in
536 * the hammer_mount structure.
538 error = hammer_init_cursor(trans, &cursor, NULL, NULL);
541 hammer_sync_lock_sh(trans);
543 volume = hammer_get_root_volume(cursor.trans->hmp, &error);
544 KKASSERT(error == 0);
545 hammer_modify_volume_field(cursor.trans, volume, vol_version);
546 volume->ondisk->vol_version = ver->cur_version;
547 cursor.trans->hmp->version = ver->cur_version;
548 hammer_modify_volume_done(volume);
549 hammer_rel_volume(volume, 0);
551 hammer_sync_unlock(trans);
553 ver->head.error = error;
554 hammer_done_cursor(&cursor);
563 hammer_ioc_get_info(hammer_transaction_t trans, struct hammer_ioc_info *info) {
565 struct hammer_volume_ondisk *od = trans->hmp->rootvol->ondisk;
566 struct hammer_mount *hm = trans->hmp;
568 /* Fill the structure with the necessary information */
569 _hammer_checkspace(hm, HAMMER_CHKSPC_WRITE, &info->rsvbigblocks);
570 info->rsvbigblocks = info->rsvbigblocks >> HAMMER_LARGEBLOCK_BITS;
571 strlcpy(info->vol_name, od->vol_name, sizeof(od->vol_name));
573 info->vol_fsid = hm->fsid;
574 info->vol_fstype = od->vol_fstype;
575 info->version = hm->version;
577 info->inodes = od->vol0_stat_inodes;
578 info->bigblocks = od->vol0_stat_bigblocks;
579 info->freebigblocks = od->vol0_stat_freebigblocks;
580 info->nvolumes = hm->nvolumes;
586 * Add a snapshot transction id(s) to the list of snapshots.
588 * NOTE: Records are created with an allocated TID. If a flush cycle
589 * is in progress the record may be synced in the current flush
590 * cycle and the volume header will reflect the allocation of the
591 * TID, but the synchronization point may not catch up to the
592 * TID until the next flush cycle.
596 hammer_ioc_add_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
597 struct hammer_ioc_snapshot *snap)
599 hammer_mount_t hmp = ip->hmp;
600 struct hammer_btree_leaf_elm leaf;
601 struct hammer_cursor cursor;
607 if (snap->count > HAMMER_SNAPS_PER_IOCTL)
609 if (snap->index > snap->count)
612 hammer_lock_ex(&hmp->snapshot_lock);
615 * Look for keys starting after the previous iteration, or at
616 * the beginning if snap->count is 0.
618 error = hammer_init_cursor(trans, &cursor, &ip->cache[0], NULL);
620 hammer_done_cursor(&cursor);
624 cursor.asof = HAMMER_MAX_TID;
625 cursor.flags |= HAMMER_CURSOR_BACKEND | HAMMER_CURSOR_ASOF;
627 bzero(&leaf, sizeof(leaf));
628 leaf.base.obj_id = HAMMER_OBJID_ROOT;
629 leaf.base.rec_type = HAMMER_RECTYPE_SNAPSHOT;
630 leaf.base.create_tid = hammer_alloc_tid(hmp, 1);
631 leaf.base.btype = HAMMER_BTREE_TYPE_RECORD;
632 leaf.base.localization = ip->obj_localization + HAMMER_LOCALIZE_INODE;
633 leaf.data_len = sizeof(struct hammer_snapshot_data);
635 while (snap->index < snap->count) {
636 leaf.base.key = (int64_t)snap->snaps[snap->index].tid;
637 cursor.key_beg = leaf.base;
638 error = hammer_btree_lookup(&cursor);
644 cursor.flags &= ~HAMMER_CURSOR_ASOF;
645 error = hammer_create_at_cursor(&cursor, &leaf,
646 &snap->snaps[snap->index],
647 HAMMER_CREATE_MODE_SYS);
648 if (error == EDEADLK) {
649 hammer_done_cursor(&cursor);
652 cursor.flags |= HAMMER_CURSOR_ASOF;
657 snap->head.error = error;
658 hammer_done_cursor(&cursor);
659 hammer_unlock(&hmp->snapshot_lock);
664 * Delete snapshot transaction id(s) from the list of snapshots.
668 hammer_ioc_del_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
669 struct hammer_ioc_snapshot *snap)
671 hammer_mount_t hmp = ip->hmp;
672 struct hammer_cursor cursor;
678 if (snap->count > HAMMER_SNAPS_PER_IOCTL)
680 if (snap->index > snap->count)
683 hammer_lock_ex(&hmp->snapshot_lock);
686 * Look for keys starting after the previous iteration, or at
687 * the beginning if snap->count is 0.
689 error = hammer_init_cursor(trans, &cursor, &ip->cache[0], NULL);
691 hammer_done_cursor(&cursor);
695 cursor.key_beg.obj_id = HAMMER_OBJID_ROOT;
696 cursor.key_beg.create_tid = 0;
697 cursor.key_beg.delete_tid = 0;
698 cursor.key_beg.obj_type = 0;
699 cursor.key_beg.rec_type = HAMMER_RECTYPE_SNAPSHOT;
700 cursor.key_beg.localization = ip->obj_localization + HAMMER_LOCALIZE_INODE;
701 cursor.asof = HAMMER_MAX_TID;
702 cursor.flags |= HAMMER_CURSOR_ASOF;
704 while (snap->index < snap->count) {
705 cursor.key_beg.key = (int64_t)snap->snaps[snap->index].tid;
706 error = hammer_btree_lookup(&cursor);
709 error = hammer_btree_extract(&cursor, HAMMER_CURSOR_GET_LEAF);
712 error = hammer_delete_at_cursor(&cursor, HAMMER_DELETE_DESTROY,
714 if (error == EDEADLK) {
715 hammer_done_cursor(&cursor);
722 snap->head.error = error;
723 hammer_done_cursor(&cursor);
724 hammer_unlock(&hmp->snapshot_lock);
729 * Retrieve as many snapshot ids as possible or until the array is
730 * full, starting after the last transction id passed in. If count
731 * is 0 we retrieve starting at the beginning.
733 * NOTE: Because the b-tree key field is signed but transaction ids
734 * are unsigned the returned list will be signed-sorted instead
735 * of unsigned sorted. The Caller must still sort the aggregate
740 hammer_ioc_get_snapshot(hammer_transaction_t trans, hammer_inode_t ip,
741 struct hammer_ioc_snapshot *snap)
743 struct hammer_cursor cursor;
749 if (snap->index != 0)
751 if (snap->count > HAMMER_SNAPS_PER_IOCTL)
755 * Look for keys starting after the previous iteration, or at
756 * the beginning if snap->count is 0.
758 error = hammer_init_cursor(trans, &cursor, &ip->cache[0], NULL);
760 hammer_done_cursor(&cursor);
764 cursor.key_beg.obj_id = HAMMER_OBJID_ROOT;
765 cursor.key_beg.create_tid = 0;
766 cursor.key_beg.delete_tid = 0;
767 cursor.key_beg.obj_type = 0;
768 cursor.key_beg.rec_type = HAMMER_RECTYPE_SNAPSHOT;
769 cursor.key_beg.localization = ip->obj_localization + HAMMER_LOCALIZE_INODE;
770 if (snap->count == 0)
771 cursor.key_beg.key = HAMMER_MIN_KEY;
773 cursor.key_beg.key = (int64_t)snap->snaps[snap->count - 1].tid + 1;
775 cursor.key_end = cursor.key_beg;
776 cursor.key_end.key = HAMMER_MAX_KEY;
777 cursor.asof = HAMMER_MAX_TID;
778 cursor.flags |= HAMMER_CURSOR_END_EXCLUSIVE | HAMMER_CURSOR_ASOF;
782 error = hammer_btree_first(&cursor);
783 while (error == 0 && snap->count < HAMMER_SNAPS_PER_IOCTL) {
784 error = hammer_btree_extract(&cursor, HAMMER_CURSOR_GET_LEAF);
787 if (cursor.leaf->base.rec_type == HAMMER_RECTYPE_SNAPSHOT) {
788 error = hammer_btree_extract(&cursor, HAMMER_CURSOR_GET_LEAF |
789 HAMMER_CURSOR_GET_DATA);
790 snap->snaps[snap->count] = cursor.data->snap;
793 error = hammer_btree_iterate(&cursor);
796 if (error == ENOENT) {
797 snap->head.flags |= HAMMER_IOC_SNAPSHOT_EOF;
800 snap->head.error = error;
801 hammer_done_cursor(&cursor);
806 * Retrieve the PFS hammer cleanup utility config record. This is
807 * different (newer than) the PFS config.
811 hammer_ioc_get_config(hammer_transaction_t trans, hammer_inode_t ip,
812 struct hammer_ioc_config *config)
814 struct hammer_cursor cursor;
817 error = hammer_init_cursor(trans, &cursor, &ip->cache[0], NULL);
819 hammer_done_cursor(&cursor);
823 cursor.key_beg.obj_id = HAMMER_OBJID_ROOT;
824 cursor.key_beg.create_tid = 0;
825 cursor.key_beg.delete_tid = 0;
826 cursor.key_beg.obj_type = 0;
827 cursor.key_beg.rec_type = HAMMER_RECTYPE_CONFIG;
828 cursor.key_beg.localization = ip->obj_localization + HAMMER_LOCALIZE_INODE;
829 cursor.key_beg.key = 0; /* config space page 0 */
831 cursor.asof = HAMMER_MAX_TID;
832 cursor.flags |= HAMMER_CURSOR_ASOF;
834 error = hammer_btree_lookup(&cursor);
836 error = hammer_btree_extract(&cursor, HAMMER_CURSOR_GET_LEAF |
837 HAMMER_CURSOR_GET_DATA);
839 config->config = cursor.data->config;
841 /* error can be ENOENT */
842 config->head.error = error;
843 hammer_done_cursor(&cursor);
848 * Retrieve the PFS hammer cleanup utility config record. This is
849 * different (newer than) the PFS config.
851 * This is kinda a hack.
855 hammer_ioc_set_config(hammer_transaction_t trans, hammer_inode_t ip,
856 struct hammer_ioc_config *config)
858 struct hammer_btree_leaf_elm leaf;
859 struct hammer_cursor cursor;
860 hammer_mount_t hmp = ip->hmp;
864 error = hammer_init_cursor(trans, &cursor, &ip->cache[0], NULL);
866 hammer_done_cursor(&cursor);
870 bzero(&leaf, sizeof(leaf));
871 leaf.base.obj_id = HAMMER_OBJID_ROOT;
872 leaf.base.rec_type = HAMMER_RECTYPE_CONFIG;
873 leaf.base.create_tid = hammer_alloc_tid(hmp, 1);
874 leaf.base.btype = HAMMER_BTREE_TYPE_RECORD;
875 leaf.base.localization = ip->obj_localization + HAMMER_LOCALIZE_INODE;
876 leaf.base.key = 0; /* page 0 */
877 leaf.data_len = sizeof(struct hammer_config_data);
879 cursor.key_beg = leaf.base;
881 cursor.asof = HAMMER_MAX_TID;
882 cursor.flags |= HAMMER_CURSOR_BACKEND | HAMMER_CURSOR_ASOF;
884 error = hammer_btree_lookup(&cursor);
886 error = hammer_btree_extract(&cursor, HAMMER_CURSOR_GET_LEAF |
887 HAMMER_CURSOR_GET_DATA);
888 error = hammer_delete_at_cursor(&cursor, HAMMER_DELETE_DESTROY,
890 if (error == EDEADLK) {
891 hammer_done_cursor(&cursor);
898 cursor.flags &= ~HAMMER_CURSOR_ASOF;
899 cursor.key_beg = leaf.base;
900 error = hammer_create_at_cursor(&cursor, &leaf,
902 HAMMER_CREATE_MODE_SYS);
903 if (error == EDEADLK) {
904 hammer_done_cursor(&cursor);
908 config->head.error = error;
909 hammer_done_cursor(&cursor);