libusb/libz: Install *.pc files (for dports) using FILES and FILESDIR.
[dragonfly.git] / sys / vfs / hammer / hammer_cursor.h
CommitLineData
8cd0a023
MD
1/*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
745703c7 3 *
8cd0a023
MD
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
745703c7 6 *
8cd0a023
MD
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
745703c7 10 *
8cd0a023
MD
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.
745703c7 20 *
8cd0a023
MD
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.
745703c7 33 *
5c8d05e2 34 * $DragonFly: src/sys/vfs/hammer/hammer_cursor.h,v 1.26 2008/08/06 15:38:58 dillon Exp $
8cd0a023
MD
35 */
36
964cb30d
TK
37#ifndef VFS_HAMMER_CURSOR_H_
38#define VFS_HAMMER_CURSOR_H_
39
8cd0a023
MD
40/*
41 * The hammer_cursor structure is the primary in-memory management structure
745703c7 42 * for B-Tree operations.
8cd0a023
MD
43 *
44 * The most important issue to make note of is that a hammer_cursor is a
45 * tracking structure. Any active hammer_cursor structure will be linked into
46 * hammer_node based lists and B-Tree operations executed by unrelated
47 * treads MAY MODIFY YOUR CURSOR when you are not holding an exclusive
48 * lock on the cursor's nodes.
49 *
6a37e7e4
MD
50 * The cursor module maintains a shared lock on cursor->node and
51 * cursor->parent.
8cd0a023 52 */
22a0040d 53typedef struct hammer_cursor {
8cd0a023
MD
54 /*
55 * Parent B-Tree node, current B-Tree node, and related element
56 * indices.
57 */
36f82b23 58 hammer_transaction_t trans;
4e17f465
MD
59 hammer_node_t parent;
60 int parent_index;
6a37e7e4 61
4e17f465
MD
62 hammer_node_t node;
63 int index;
8cd0a023 64
6a37e7e4 65 /*
4e17f465 66 * Set if a deadlock occurs. hammer_done_cursor() will block on
b3bad96f
MD
67 * this after releasing parent and node, before returning. See
68 * also hammer_recover_cursor().
6a37e7e4 69 */
b3bad96f 70 TAILQ_ENTRY(hammer_cursor) deadlk_entry;
6a37e7e4 71 hammer_node_t deadlk_node;
b84de5af 72 hammer_record_t deadlk_rec;
6a37e7e4 73
b33e2cc0 74 /*
9582c7da 75 * Set along with HAMMER_CURSOR_CREATE_CHECK when doing an as-of
b33e2cc0
MD
76 * search. If ENOENT is returned and the flag is set, the caller
77 * must iterate with a new delete_tid.
78 */
9582c7da 79 hammer_tid_t create_check;
b33e2cc0 80
8cd0a023
MD
81 /*
82 * Pointer to the current node's bounds. Typically points to the
f176517c
TK
83 * appropriate boundary elements in the parent.
84 * The right-boundary is range-exclusive.
8cd0a023
MD
85 */
86 hammer_base_elm_t left_bound;
87 hammer_base_elm_t right_bound;
88
89 /*
d5530d22
MD
90 * Key or key range governing search. The cursor code may adjust
91 * key_beg/key_end if asof is non-zero.
8cd0a023
MD
92 */
93 struct hammer_base_elm key_beg;
94 struct hammer_base_elm key_end;
d5530d22 95 hammer_tid_t asof;
4c038e17 96 struct hammer_cmirror *cmirror;
8cd0a023
MD
97
98 /*
99 * Related data and record references. Note that the related buffers
100 * can be NULL when data and/or record is not, typically indicating
101 * information referenced via an in-memory record.
102 */
562d34c2 103 hammer_buffer_t data_buffer; /* extended data */
053f997d 104 hammer_btree_leaf_elm_t leaf;
513f50d5 105 hammer_data_ondisk_t data;
8cd0a023
MD
106
107 /*
108 * Iteration and extraction control variables
109 */
110 int flags;
3214ade6 111 int rec_generation;
8cd0a023
MD
112
113 /*
114 * Merged in-memory/on-disk iterations also use these fields.
115 */
e1067862 116 hammer_inode_t ip;
877580d2 117 hammer_record_t iprec;
22a0040d 118} *hammer_cursor_t;
8cd0a023 119
cf977f11 120#define HAMMER_CURSOR_GET_LEAF 0x0001 /* not used */
a89aec1b 121#define HAMMER_CURSOR_GET_DATA 0x0002
b84de5af 122#define HAMMER_CURSOR_BACKEND 0x0004 /* cursor run by backend */
a89aec1b 123#define HAMMER_CURSOR_INSERT 0x0008 /* adjust for insert */
b84de5af 124#define HAMMER_CURSOR_DELETE_VISIBILITY 0x0010 /* special del-on-disk recs */
d26d0ae9
MD
125#define HAMMER_CURSOR_END_INCLUSIVE 0x0020 /* key_end is inclusive */
126#define HAMMER_CURSOR_END_EXCLUSIVE 0x0040 /* key_end is exclusive (def) */
a89aec1b
MD
127
128#define HAMMER_CURSOR_ATEDISK 0x0100
129#define HAMMER_CURSOR_ATEMEM 0x0200
130#define HAMMER_CURSOR_DISKEOF 0x0400
131#define HAMMER_CURSOR_MEMEOF 0x0800
5c8d05e2 132#define HAMMER_CURSOR_RETEST 0x1000 /* retest current element */
c82af904 133#define HAMMER_CURSOR_MIRROR_FILTERED 0x2000 /* mirror_tid filter */
d5530d22 134#define HAMMER_CURSOR_ASOF 0x4000 /* as-of lookup */
9582c7da 135#define HAMMER_CURSOR_CREATE_CHECK 0x8000 /* as-of lookup */
8cd0a023 136
11ad5ade 137#define HAMMER_CURSOR_PRUNING 0x00010000
2f85fa4d 138#define HAMMER_CURSOR_REBLOCKING 0x00020000
adf01747
MD
139#define HAMMER_CURSOR_TRACKED 0x00040000
140#define HAMMER_CURSOR_TRACKED_RIPOUT 0x00080000
3214ade6 141#define HAMMER_CURSOR_LASTWASMEM 0x00100000 /* hammer_ip_next logic */
6dc17446 142#define HAMMER_CURSOR_ITERATE_CHECK 0x00200000
18bee4a2 143#define HAMMER_CURSOR_NOSWAPCACHE 0x00400000 /* applies to LARGE_DATA */
11ad5ade 144
4e17f465
MD
145/*
146 * Flags we can clear when reusing a cursor (we can clear all of them)
147 */
148#define HAMMER_CURSOR_INITMASK (~0)
149
4c038e17
MD
150/*
151 * Mirror scan extension structure. Caller sets mirror_tid to restrict
152 * the scan. If the iteration is able to skip one or more internal nodes
153 * it returns an internal node with skip_beg/end set to the skipped range.
154 *
155 * If the first element of an internal node is skipped skip_beg will use
156 * the left_bound inherited from the parent, and the same for the last
157 * element. This is because gaps can develop in the bounds.
158 */
159struct hammer_cmirror {
160 hammer_tid_t mirror_tid;
161 struct hammer_base_elm skip_beg;
162 struct hammer_base_elm skip_end;
163};
164
47637bff
MD
165/*
166 * NOTE: iprec can be NULL, but the address-of does not indirect through
167 * it so we are ok.
168 */
169#define hammer_cursor_inmem(cursor) \
170 ((cursor)->leaf == &(cursor)->iprec->leaf)
171#define hammer_cursor_ondisk(cursor) \
172 ((cursor)->leaf != &(cursor)->iprec->leaf)
173
964cb30d 174#endif /* !VFS_HAMMER_CURSOR_H_ */