6b13f685e
김민수
BSP 최초 추가
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#include <linux/slab.h>
#include "btrfs-tests.h"
#include "../ctree.h"
#include "../extent_io.h"
#include "../disk-io.h"
static int test_btrfs_split_item(void)
{
struct btrfs_path *path;
struct btrfs_root *root;
struct extent_buffer *eb;
struct btrfs_item *item;
char *value = "mary had a little lamb";
char *split1 = "mary had a little";
char *split2 = " lamb";
char *split3 = "mary";
char *split4 = " had a little";
char buf[32];
struct btrfs_key key;
u32 value_len = strlen(value);
int ret = 0;
test_msg("Running btrfs_split_item tests
");
root = btrfs_alloc_dummy_root();
if (IS_ERR(root)) {
test_msg("Could not allocate root
");
return PTR_ERR(root);
}
path = btrfs_alloc_path();
if (!path) {
test_msg("Could not allocate path
");
kfree(root);
return -ENOMEM;
}
path->nodes[0] = eb = alloc_dummy_extent_buffer(0, 4096);
if (!eb) {
test_msg("Could not allocate dummy buffer
");
ret = -ENOMEM;
goto out;
}
path->slots[0] = 0;
key.objectid = 0;
key.type = BTRFS_EXTENT_CSUM_KEY;
key.offset = 0;
setup_items_for_insert(root, path, &key, &value_len, value_len,
value_len + sizeof(struct btrfs_item), 1);
item = btrfs_item_nr(0);
write_extent_buffer(eb, value, btrfs_item_ptr_offset(eb, 0),
value_len);
key.offset = 3;
ret = btrfs_split_item(NULL, root, path, &key, 17);
if (ret) {
test_msg("Split item failed %d
", ret);
goto out;
}
btrfs_item_key_to_cpu(eb, &key, 0);
if (key.objectid != 0 || key.type != BTRFS_EXTENT_CSUM_KEY ||
key.offset != 0) {
test_msg("Invalid key at slot 0
");
ret = -EINVAL;
goto out;
}
item = btrfs_item_nr(0);
if (btrfs_item_size(eb, item) != strlen(split1)) {
test_msg("Invalid len in the first split
");
ret = -EINVAL;
goto out;
}
read_extent_buffer(eb, buf, btrfs_item_ptr_offset(eb, 0),
strlen(split1));
if (memcmp(buf, split1, strlen(split1))) {
test_msg("Data in the buffer doesn't match what it should "
"in the first split have='%.*s' want '%s'
",
(int)strlen(split1), buf, split1);
ret = -EINVAL;
goto out;
}
btrfs_item_key_to_cpu(eb, &key, 1);
if (key.objectid != 0 || key.type != BTRFS_EXTENT_CSUM_KEY ||
key.offset != 3) {
test_msg("Invalid key at slot 1
");
ret = -EINVAL;
goto out;
}
item = btrfs_item_nr(1);
if (btrfs_item_size(eb, item) != strlen(split2)) {
test_msg("Invalid len in the second split
");
ret = -EINVAL;
goto out;
}
read_extent_buffer(eb, buf, btrfs_item_ptr_offset(eb, 1),
strlen(split2));
if (memcmp(buf, split2, strlen(split2))) {
test_msg("Data in the buffer doesn't match what it should "
"in the second split
");
ret = -EINVAL;
goto out;
}
key.offset = 1;
ret = btrfs_split_item(NULL, root, path, &key, 4);
if (ret) {
test_msg("Second split item failed %d
", ret);
goto out;
}
btrfs_item_key_to_cpu(eb, &key, 0);
if (key.objectid != 0 || key.type != BTRFS_EXTENT_CSUM_KEY ||
key.offset != 0) {
test_msg("Invalid key at slot 0
");
ret = -EINVAL;
goto out;
}
item = btrfs_item_nr(0);
if (btrfs_item_size(eb, item) != strlen(split3)) {
test_msg("Invalid len in the first split
");
ret = -EINVAL;
goto out;
}
read_extent_buffer(eb, buf, btrfs_item_ptr_offset(eb, 0),
strlen(split3));
if (memcmp(buf, split3, strlen(split3))) {
test_msg("Data in the buffer doesn't match what it should "
"in the third split");
ret = -EINVAL;
goto out;
}
btrfs_item_key_to_cpu(eb, &key, 1);
if (key.objectid != 0 || key.type != BTRFS_EXTENT_CSUM_KEY ||
key.offset != 1) {
test_msg("Invalid key at slot 1
");
ret = -EINVAL;
goto out;
}
item = btrfs_item_nr(1);
if (btrfs_item_size(eb, item) != strlen(split4)) {
test_msg("Invalid len in the second split
");
ret = -EINVAL;
goto out;
}
read_extent_buffer(eb, buf, btrfs_item_ptr_offset(eb, 1),
strlen(split4));
if (memcmp(buf, split4, strlen(split4))) {
test_msg("Data in the buffer doesn't match what it should "
"in the fourth split
");
ret = -EINVAL;
goto out;
}
btrfs_item_key_to_cpu(eb, &key, 2);
if (key.objectid != 0 || key.type != BTRFS_EXTENT_CSUM_KEY ||
key.offset != 3) {
test_msg("Invalid key at slot 2
");
ret = -EINVAL;
goto out;
}
item = btrfs_item_nr(2);
if (btrfs_item_size(eb, item) != strlen(split2)) {
test_msg("Invalid len in the second split
");
ret = -EINVAL;
goto out;
}
read_extent_buffer(eb, buf, btrfs_item_ptr_offset(eb, 2),
strlen(split2));
if (memcmp(buf, split2, strlen(split2))) {
test_msg("Data in the buffer doesn't match what it should "
"in the last chunk
");
ret = -EINVAL;
goto out;
}
out:
btrfs_free_path(path);
kfree(root);
return ret;
}
int btrfs_test_extent_buffer_operations(void)
{
test_msg("Running extent buffer operation tests");
return test_btrfs_split_item();
}
|