diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-30 15:29:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-30 15:33:01 -0400 |
commit | e1c502482853f84606928f5a2f2eb6da1993cda1 (patch) | |
tree | ca296007164906342a195bdf3a5305277e6af5da /fs/reiserfs/stree.c | |
parent | 019abbc87025a030fd25008612afd4eff8a375f7 (diff) | |
parent | ee93961be1faddf9e9a638bc519145c20f0cfeba (diff) |
Merge branch 'reiserfs-updates' from Jeff Mahoney
* reiserfs-updates: (35 commits)
reiserfs: rename [cn]_* variables
reiserfs: rename p_._ variables
reiserfs: rename p_s_tb to tb
reiserfs: rename p_s_inode to inode
reiserfs: rename p_s_bh to bh
reiserfs: rename p_s_sb to sb
reiserfs: strip trailing whitespace
reiserfs: cleanup path functions
reiserfs: factor out buffer_info initialization
reiserfs: add atomic addition of selinux attributes during inode creation
reiserfs: use generic readdir for operations across all xattrs
reiserfs: journaled xattrs
reiserfs: use generic xattr handlers
reiserfs: remove i_has_xattr_dir
reiserfs: make per-inode xattr locking more fine grained
reiserfs: eliminate per-super xattr lock
reiserfs: simplify xattr internal file lookups/opens
reiserfs: Clean up xattrs when REISERFS_FS_XATTR is unset
reiserfs: remove IS_PRIVATE helpers
reiserfs: remove link detection code
...
Fixed up conflicts manually due to:
- quota name cleanups vs variable naming changes:
fs/reiserfs/inode.c
fs/reiserfs/namei.c
fs/reiserfs/stree.c
fs/reiserfs/xattr.c
- exported include header cleanups
include/linux/reiserfs_fs.h
Diffstat (limited to 'fs/reiserfs/stree.c')
-rw-r--r-- | fs/reiserfs/stree.c | 1168 |
1 files changed, 566 insertions, 602 deletions
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c index 73aaa33f673..d036ee5b1c8 100644 --- a/fs/reiserfs/stree.c +++ b/fs/reiserfs/stree.c | |||
@@ -23,7 +23,6 @@ | |||
23 | * get_rkey | 23 | * get_rkey |
24 | * key_in_buffer | 24 | * key_in_buffer |
25 | * decrement_bcount | 25 | * decrement_bcount |
26 | * decrement_counters_in_path | ||
27 | * reiserfs_check_path | 26 | * reiserfs_check_path |
28 | * pathrelse_and_restore | 27 | * pathrelse_and_restore |
29 | * pathrelse | 28 | * pathrelse |
@@ -57,28 +56,28 @@ | |||
57 | #include <linux/quotaops.h> | 56 | #include <linux/quotaops.h> |
58 | 57 | ||
59 | /* Does the buffer contain a disk block which is in the tree. */ | 58 | /* Does the buffer contain a disk block which is in the tree. */ |
60 | inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh) | 59 | inline int B_IS_IN_TREE(const struct buffer_head *bh) |
61 | { | 60 | { |
62 | 61 | ||
63 | RFALSE(B_LEVEL(p_s_bh) > MAX_HEIGHT, | 62 | RFALSE(B_LEVEL(bh) > MAX_HEIGHT, |
64 | "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh); | 63 | "PAP-1010: block (%b) has too big level (%z)", bh, bh); |
65 | 64 | ||
66 | return (B_LEVEL(p_s_bh) != FREE_LEVEL); | 65 | return (B_LEVEL(bh) != FREE_LEVEL); |
67 | } | 66 | } |
68 | 67 | ||
69 | // | 68 | // |
70 | // to gets item head in le form | 69 | // to gets item head in le form |
71 | // | 70 | // |
72 | inline void copy_item_head(struct item_head *p_v_to, | 71 | inline void copy_item_head(struct item_head *to, |
73 | const struct item_head *p_v_from) | 72 | const struct item_head *from) |
74 | { | 73 | { |
75 | memcpy(p_v_to, p_v_from, IH_SIZE); | 74 | memcpy(to, from, IH_SIZE); |
76 | } | 75 | } |
77 | 76 | ||
78 | /* k1 is pointer to on-disk structure which is stored in little-endian | 77 | /* k1 is pointer to on-disk structure which is stored in little-endian |
79 | form. k2 is pointer to cpu variable. For key of items of the same | 78 | form. k2 is pointer to cpu variable. For key of items of the same |
80 | object this returns 0. | 79 | object this returns 0. |
81 | Returns: -1 if key1 < key2 | 80 | Returns: -1 if key1 < key2 |
82 | 0 if key1 == key2 | 81 | 0 if key1 == key2 |
83 | 1 if key1 > key2 */ | 82 | 1 if key1 > key2 */ |
84 | inline int comp_short_keys(const struct reiserfs_key *le_key, | 83 | inline int comp_short_keys(const struct reiserfs_key *le_key, |
@@ -136,15 +135,15 @@ static inline int comp_keys(const struct reiserfs_key *le_key, | |||
136 | inline int comp_short_le_keys(const struct reiserfs_key *key1, | 135 | inline int comp_short_le_keys(const struct reiserfs_key *key1, |
137 | const struct reiserfs_key *key2) | 136 | const struct reiserfs_key *key2) |
138 | { | 137 | { |
139 | __u32 *p_s_1_u32, *p_s_2_u32; | 138 | __u32 *k1_u32, *k2_u32; |
140 | int n_key_length = REISERFS_SHORT_KEY_LEN; | 139 | int key_length = REISERFS_SHORT_KEY_LEN; |
141 | 140 | ||
142 | p_s_1_u32 = (__u32 *) key1; | 141 | k1_u32 = (__u32 *) key1; |
143 | p_s_2_u32 = (__u32 *) key2; | 142 | k2_u32 = (__u32 *) key2; |
144 | for (; n_key_length--; ++p_s_1_u32, ++p_s_2_u32) { | 143 | for (; key_length--; ++k1_u32, ++k2_u32) { |
145 | if (le32_to_cpu(*p_s_1_u32) < le32_to_cpu(*p_s_2_u32)) | 144 | if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32)) |
146 | return -1; | 145 | return -1; |
147 | if (le32_to_cpu(*p_s_1_u32) > le32_to_cpu(*p_s_2_u32)) | 146 | if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32)) |
148 | return 1; | 147 | return 1; |
149 | } | 148 | } |
150 | return 0; | 149 | return 0; |
@@ -175,52 +174,51 @@ inline int comp_le_keys(const struct reiserfs_key *k1, | |||
175 | * Binary search toolkit function * | 174 | * Binary search toolkit function * |
176 | * Search for an item in the array by the item key * | 175 | * Search for an item in the array by the item key * |
177 | * Returns: 1 if found, 0 if not found; * | 176 | * Returns: 1 if found, 0 if not found; * |
178 | * *p_n_pos = number of the searched element if found, else the * | 177 | * *pos = number of the searched element if found, else the * |
179 | * number of the first element that is larger than p_v_key. * | 178 | * number of the first element that is larger than key. * |
180 | **************************************************************************/ | 179 | **************************************************************************/ |
181 | /* For those not familiar with binary search: n_lbound is the leftmost item that it | 180 | /* For those not familiar with binary search: lbound is the leftmost item that it |
182 | could be, n_rbound the rightmost item that it could be. We examine the item | 181 | could be, rbound the rightmost item that it could be. We examine the item |
183 | halfway between n_lbound and n_rbound, and that tells us either that we can increase | 182 | halfway between lbound and rbound, and that tells us either that we can increase |
184 | n_lbound, or decrease n_rbound, or that we have found it, or if n_lbound <= n_rbound that | 183 | lbound, or decrease rbound, or that we have found it, or if lbound <= rbound that |
185 | there are no possible items, and we have not found it. With each examination we | 184 | there are no possible items, and we have not found it. With each examination we |
186 | cut the number of possible items it could be by one more than half rounded down, | 185 | cut the number of possible items it could be by one more than half rounded down, |
187 | or we find it. */ | 186 | or we find it. */ |
188 | static inline int bin_search(const void *p_v_key, /* Key to search for. */ | 187 | static inline int bin_search(const void *key, /* Key to search for. */ |
189 | const void *p_v_base, /* First item in the array. */ | 188 | const void *base, /* First item in the array. */ |
190 | int p_n_num, /* Number of items in the array. */ | 189 | int num, /* Number of items in the array. */ |
191 | int p_n_width, /* Item size in the array. | 190 | int width, /* Item size in the array. |
192 | searched. Lest the reader be | 191 | searched. Lest the reader be |
193 | confused, note that this is crafted | 192 | confused, note that this is crafted |
194 | as a general function, and when it | 193 | as a general function, and when it |
195 | is applied specifically to the array | 194 | is applied specifically to the array |
196 | of item headers in a node, p_n_width | 195 | of item headers in a node, width |
197 | is actually the item header size not | 196 | is actually the item header size not |
198 | the item size. */ | 197 | the item size. */ |
199 | int *p_n_pos /* Number of the searched for element. */ | 198 | int *pos /* Number of the searched for element. */ |
200 | ) | 199 | ) |
201 | { | 200 | { |
202 | int n_rbound, n_lbound, n_j; | 201 | int rbound, lbound, j; |
203 | 202 | ||
204 | for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2; | 203 | for (j = ((rbound = num - 1) + (lbound = 0)) / 2; |
205 | n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2) | 204 | lbound <= rbound; j = (rbound + lbound) / 2) |
206 | switch (comp_keys | 205 | switch (comp_keys |
207 | ((struct reiserfs_key *)((char *)p_v_base + | 206 | ((struct reiserfs_key *)((char *)base + j * width), |
208 | n_j * p_n_width), | 207 | (struct cpu_key *)key)) { |
209 | (struct cpu_key *)p_v_key)) { | ||
210 | case -1: | 208 | case -1: |
211 | n_lbound = n_j + 1; | 209 | lbound = j + 1; |
212 | continue; | 210 | continue; |
213 | case 1: | 211 | case 1: |
214 | n_rbound = n_j - 1; | 212 | rbound = j - 1; |
215 | continue; | 213 | continue; |
216 | case 0: | 214 | case 0: |
217 | *p_n_pos = n_j; | 215 | *pos = j; |
218 | return ITEM_FOUND; /* Key found in the array. */ | 216 | return ITEM_FOUND; /* Key found in the array. */ |
219 | } | 217 | } |
220 | 218 | ||
221 | /* bin_search did not find given key, it returns position of key, | 219 | /* bin_search did not find given key, it returns position of key, |
222 | that is minimal and greater than the given one. */ | 220 | that is minimal and greater than the given one. */ |
223 | *p_n_pos = n_lbound; | 221 | *pos = lbound; |
224 | return ITEM_NOT_FOUND; | 222 | return ITEM_NOT_FOUND; |
225 | } | 223 | } |
226 | 224 | ||
@@ -243,90 +241,88 @@ static const struct reiserfs_key MAX_KEY = { | |||
243 | of the path, and going upwards. We must check the path's validity at each step. If the key is not in | 241 | of the path, and going upwards. We must check the path's validity at each step. If the key is not in |
244 | the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this | 242 | the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this |
245 | case we return a special key, either MIN_KEY or MAX_KEY. */ | 243 | case we return a special key, either MIN_KEY or MAX_KEY. */ |
246 | static inline const struct reiserfs_key *get_lkey(const struct treepath | 244 | static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_path, |
247 | *p_s_chk_path, | 245 | const struct super_block *sb) |
248 | const struct super_block | ||
249 | *p_s_sb) | ||
250 | { | 246 | { |
251 | int n_position, n_path_offset = p_s_chk_path->path_length; | 247 | int position, path_offset = chk_path->path_length; |
252 | struct buffer_head *p_s_parent; | 248 | struct buffer_head *parent; |
253 | 249 | ||
254 | RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, | 250 | RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET, |
255 | "PAP-5010: invalid offset in the path"); | 251 | "PAP-5010: invalid offset in the path"); |
256 | 252 | ||
257 | /* While not higher in path than first element. */ | 253 | /* While not higher in path than first element. */ |
258 | while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { | 254 | while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { |
259 | 255 | ||
260 | RFALSE(!buffer_uptodate | 256 | RFALSE(!buffer_uptodate |
261 | (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), | 257 | (PATH_OFFSET_PBUFFER(chk_path, path_offset)), |
262 | "PAP-5020: parent is not uptodate"); | 258 | "PAP-5020: parent is not uptodate"); |
263 | 259 | ||
264 | /* Parent at the path is not in the tree now. */ | 260 | /* Parent at the path is not in the tree now. */ |
265 | if (!B_IS_IN_TREE | 261 | if (!B_IS_IN_TREE |
266 | (p_s_parent = | 262 | (parent = |
267 | PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset))) | 263 | PATH_OFFSET_PBUFFER(chk_path, path_offset))) |
268 | return &MAX_KEY; | 264 | return &MAX_KEY; |
269 | /* Check whether position in the parent is correct. */ | 265 | /* Check whether position in the parent is correct. */ |
270 | if ((n_position = | 266 | if ((position = |
271 | PATH_OFFSET_POSITION(p_s_chk_path, | 267 | PATH_OFFSET_POSITION(chk_path, |
272 | n_path_offset)) > | 268 | path_offset)) > |
273 | B_NR_ITEMS(p_s_parent)) | 269 | B_NR_ITEMS(parent)) |
274 | return &MAX_KEY; | 270 | return &MAX_KEY; |
275 | /* Check whether parent at the path really points to the child. */ | 271 | /* Check whether parent at the path really points to the child. */ |
276 | if (B_N_CHILD_NUM(p_s_parent, n_position) != | 272 | if (B_N_CHILD_NUM(parent, position) != |
277 | PATH_OFFSET_PBUFFER(p_s_chk_path, | 273 | PATH_OFFSET_PBUFFER(chk_path, |
278 | n_path_offset + 1)->b_blocknr) | 274 | path_offset + 1)->b_blocknr) |
279 | return &MAX_KEY; | 275 | return &MAX_KEY; |
280 | /* Return delimiting key if position in the parent is not equal to zero. */ | 276 | /* Return delimiting key if position in the parent is not equal to zero. */ |
281 | if (n_position) | 277 | if (position) |
282 | return B_N_PDELIM_KEY(p_s_parent, n_position - 1); | 278 | return B_N_PDELIM_KEY(parent, position - 1); |
283 | } | 279 | } |
284 | /* Return MIN_KEY if we are in the root of the buffer tree. */ | 280 | /* Return MIN_KEY if we are in the root of the buffer tree. */ |
285 | if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)-> | 281 | if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> |
286 | b_blocknr == SB_ROOT_BLOCK(p_s_sb)) | 282 | b_blocknr == SB_ROOT_BLOCK(sb)) |
287 | return &MIN_KEY; | 283 | return &MIN_KEY; |
288 | return &MAX_KEY; | 284 | return &MAX_KEY; |
289 | } | 285 | } |
290 | 286 | ||
291 | /* Get delimiting key of the buffer at the path and its right neighbor. */ | 287 | /* Get delimiting key of the buffer at the path and its right neighbor. */ |
292 | inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path, | 288 | inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path, |
293 | const struct super_block *p_s_sb) | 289 | const struct super_block *sb) |
294 | { | 290 | { |
295 | int n_position, n_path_offset = p_s_chk_path->path_length; | 291 | int position, path_offset = chk_path->path_length; |
296 | struct buffer_head *p_s_parent; | 292 | struct buffer_head *parent; |
297 | 293 | ||
298 | RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, | 294 | RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET, |
299 | "PAP-5030: invalid offset in the path"); | 295 | "PAP-5030: invalid offset in the path"); |
300 | 296 | ||
301 | while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { | 297 | while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { |
302 | 298 | ||
303 | RFALSE(!buffer_uptodate | 299 | RFALSE(!buffer_uptodate |
304 | (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), | 300 | (PATH_OFFSET_PBUFFER(chk_path, path_offset)), |
305 | "PAP-5040: parent is not uptodate"); | 301 | "PAP-5040: parent is not uptodate"); |
306 | 302 | ||
307 | /* Parent at the path is not in the tree now. */ | 303 | /* Parent at the path is not in the tree now. */ |
308 | if (!B_IS_IN_TREE | 304 | if (!B_IS_IN_TREE |
309 | (p_s_parent = | 305 | (parent = |
310 | PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset))) | 306 | PATH_OFFSET_PBUFFER(chk_path, path_offset))) |
311 | return &MIN_KEY; | 307 | return &MIN_KEY; |
312 | /* Check whether position in the parent is correct. */ | 308 | /* Check whether position in the parent is correct. */ |
313 | if ((n_position = | 309 | if ((position = |
314 | PATH_OFFSET_POSITION(p_s_chk_path, | 310 | PATH_OFFSET_POSITION(chk_path, |
315 | n_path_offset)) > | 311 | path_offset)) > |
316 | B_NR_ITEMS(p_s_parent)) | 312 | B_NR_ITEMS(parent)) |
317 | return &MIN_KEY; | 313 | return &MIN_KEY; |
318 | /* Check whether parent at the path really points to the child. */ | 314 | /* Check whether parent at the path really points to the child. */ |
319 | if (B_N_CHILD_NUM(p_s_parent, n_position) != | 315 | if (B_N_CHILD_NUM(parent, position) != |
320 | PATH_OFFSET_PBUFFER(p_s_chk_path, | 316 | PATH_OFFSET_PBUFFER(chk_path, |
321 | n_path_offset + 1)->b_blocknr) | 317 | path_offset + 1)->b_blocknr) |
322 | return &MIN_KEY; | 318 | return &MIN_KEY; |
323 | /* Return delimiting key if position in the parent is not the last one. */ | 319 | /* Return delimiting key if position in the parent is not the last one. */ |
324 | if (n_position != B_NR_ITEMS(p_s_parent)) | 320 | if (position != B_NR_ITEMS(parent)) |
325 | return B_N_PDELIM_KEY(p_s_parent, n_position); | 321 | return B_N_PDELIM_KEY(parent, position); |
326 | } | 322 | } |
327 | /* Return MAX_KEY if we are in the root of the buffer tree. */ | 323 | /* Return MAX_KEY if we are in the root of the buffer tree. */ |
328 | if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)-> | 324 | if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> |
329 | b_blocknr == SB_ROOT_BLOCK(p_s_sb)) | 325 | b_blocknr == SB_ROOT_BLOCK(sb)) |
330 | return &MAX_KEY; | 326 | return &MAX_KEY; |
331 | return &MIN_KEY; | 327 | return &MIN_KEY; |
332 | } | 328 | } |
@@ -336,60 +332,29 @@ inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path, | |||
336 | the path. These delimiting keys are stored at least one level above that buffer in the tree. If the | 332 | the path. These delimiting keys are stored at least one level above that buffer in the tree. If the |
337 | buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in | 333 | buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in |
338 | this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ | 334 | this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ |
339 | static inline int key_in_buffer(struct treepath *p_s_chk_path, /* Path which should be checked. */ | 335 | static inline int key_in_buffer(struct treepath *chk_path, /* Path which should be checked. */ |
340 | const struct cpu_key *p_s_key, /* Key which should be checked. */ | 336 | const struct cpu_key *key, /* Key which should be checked. */ |
341 | struct super_block *p_s_sb /* Super block pointer. */ | 337 | struct super_block *sb |
342 | ) | 338 | ) |
343 | { | 339 | { |
344 | 340 | ||
345 | RFALSE(!p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET | 341 | RFALSE(!key || chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET |
346 | || p_s_chk_path->path_length > MAX_HEIGHT, | 342 | || chk_path->path_length > MAX_HEIGHT, |
347 | "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)", | 343 | "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)", |
348 | p_s_key, p_s_chk_path->path_length); | 344 | key, chk_path->path_length); |
349 | RFALSE(!PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev, | 345 | RFALSE(!PATH_PLAST_BUFFER(chk_path)->b_bdev, |
350 | "PAP-5060: device must not be NODEV"); | 346 | "PAP-5060: device must not be NODEV"); |
351 | 347 | ||
352 | if (comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1) | 348 | if (comp_keys(get_lkey(chk_path, sb), key) == 1) |
353 | /* left delimiting key is bigger, that the key we look for */ | 349 | /* left delimiting key is bigger, that the key we look for */ |
354 | return 0; | 350 | return 0; |
355 | // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 ) | 351 | /* if ( comp_keys(key, get_rkey(chk_path, sb)) != -1 ) */ |
356 | if (comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1) | 352 | if (comp_keys(get_rkey(chk_path, sb), key) != 1) |
357 | /* p_s_key must be less than right delimitiing key */ | 353 | /* key must be less than right delimitiing key */ |
358 | return 0; | 354 | return 0; |
359 | return 1; | 355 | return 1; |
360 | } | 356 | } |
361 | 357 | ||
362 | inline void decrement_bcount(struct buffer_head *p_s_bh) | ||
363 | { | ||
364 | if (p_s_bh) { | ||
365 | if (atomic_read(&(p_s_bh->b_count))) { | ||
366 | put_bh(p_s_bh); | ||
367 | return; | ||
368 | } | ||
369 | reiserfs_panic(NULL, | ||
370 | "PAP-5070: decrement_bcount: trying to free free buffer %b", | ||
371 | p_s_bh); | ||
372 | } | ||
373 | } | ||
374 | |||
375 | /* Decrement b_count field of the all buffers in the path. */ | ||
376 | void decrement_counters_in_path(struct treepath *p_s_search_path) | ||
377 | { | ||
378 | int n_path_offset = p_s_search_path->path_length; | ||
379 | |||
380 | RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET || | ||
381 | n_path_offset > EXTENDED_MAX_HEIGHT - 1, | ||
382 | "PAP-5080: invalid path offset of %d", n_path_offset); | ||
383 | |||
384 | while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { | ||
385 | struct buffer_head *bh; | ||
386 | |||
387 | bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--); | ||
388 | decrement_bcount(bh); | ||
389 | } | ||
390 | p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; | ||
391 | } | ||
392 | |||
393 | int reiserfs_check_path(struct treepath *p) | 358 | int reiserfs_check_path(struct treepath *p) |
394 | { | 359 | { |
395 | RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET, | 360 | RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET, |
@@ -397,40 +362,38 @@ int reiserfs_check_path(struct treepath *p) | |||
397 | return 0; | 362 | return 0; |
398 | } | 363 | } |
399 | 364 | ||
400 | /* Release all buffers in the path. Restore dirty bits clean | 365 | /* Drop the reference to each buffer in a path and restore |
401 | ** when preparing the buffer for the log | 366 | * dirty bits clean when preparing the buffer for the log. |
402 | ** | 367 | * This version should only be called from fix_nodes() */ |
403 | ** only called from fix_nodes() | 368 | void pathrelse_and_restore(struct super_block *sb, |
404 | */ | 369 | struct treepath *search_path) |
405 | void pathrelse_and_restore(struct super_block *s, struct treepath *p_s_search_path) | ||
406 | { | 370 | { |
407 | int n_path_offset = p_s_search_path->path_length; | 371 | int path_offset = search_path->path_length; |
408 | 372 | ||
409 | RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, | 373 | RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, |
410 | "clm-4000: invalid path offset"); | 374 | "clm-4000: invalid path offset"); |
411 | 375 | ||
412 | while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { | 376 | while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { |
413 | reiserfs_restore_prepared_buffer(s, | 377 | struct buffer_head *bh; |
414 | PATH_OFFSET_PBUFFER | 378 | bh = PATH_OFFSET_PBUFFER(search_path, path_offset--); |
415 | (p_s_search_path, | 379 | reiserfs_restore_prepared_buffer(sb, bh); |
416 | n_path_offset)); | 380 | brelse(bh); |
417 | brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--)); | ||
418 | } | 381 | } |
419 | p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; | 382 | search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; |
420 | } | 383 | } |
421 | 384 | ||
422 | /* Release all buffers in the path. */ | 385 | /* Drop the reference to each buffer in a path */ |
423 | void pathrelse(struct treepath *p_s_search_path) | 386 | void pathrelse(struct treepath *search_path) |
424 | { | 387 | { |
425 | int n_path_offset = p_s_search_path->path_length; | 388 | int path_offset = search_path->path_length; |
426 | 389 | ||
427 | RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, | 390 | RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, |
428 | "PAP-5090: invalid path offset"); | 391 | "PAP-5090: invalid path offset"); |
429 | 392 | ||
430 | while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) | 393 | while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) |
431 | brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--)); | 394 | brelse(PATH_OFFSET_PBUFFER(search_path, path_offset--)); |
432 | 395 | ||
433 | p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; | 396 | search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; |
434 | } | 397 | } |
435 | 398 | ||
436 | static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) | 399 | static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) |
@@ -444,23 +407,24 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) | |||
444 | 407 | ||
445 | blkh = (struct block_head *)buf; | 408 | blkh = (struct block_head *)buf; |
446 | if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) { | 409 | if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) { |
447 | reiserfs_warning(NULL, | 410 | reiserfs_warning(NULL, "reiserfs-5080", |
448 | "is_leaf: this should be caught earlier"); | 411 | "this should be caught earlier"); |
449 | return 0; | 412 | return 0; |
450 | } | 413 | } |
451 | 414 | ||
452 | nr = blkh_nr_item(blkh); | 415 | nr = blkh_nr_item(blkh); |
453 | if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) { | 416 | if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) { |
454 | /* item number is too big or too small */ | 417 | /* item number is too big or too small */ |
455 | reiserfs_warning(NULL, "is_leaf: nr_item seems wrong: %z", bh); | 418 | reiserfs_warning(NULL, "reiserfs-5081", |
419 | "nr_item seems wrong: %z", bh); | ||
456 | return 0; | 420 | return 0; |
457 | } | 421 | } |
458 | ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; | 422 | ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; |
459 | used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih)); | 423 | used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih)); |
460 | if (used_space != blocksize - blkh_free_space(blkh)) { | 424 | if (used_space != blocksize - blkh_free_space(blkh)) { |
461 | /* free space does not match to calculated amount of use space */ | 425 | /* free space does not match to calculated amount of use space */ |
462 | reiserfs_warning(NULL, "is_leaf: free space seems wrong: %z", | 426 | reiserfs_warning(NULL, "reiserfs-5082", |
463 | bh); | 427 | "free space seems wrong: %z", bh); |
464 | return 0; | 428 | return 0; |
465 | } | 429 | } |
466 | // FIXME: it is_leaf will hit performance too much - we may have | 430 | // FIXME: it is_leaf will hit performance too much - we may have |
@@ -471,29 +435,29 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) | |||
471 | prev_location = blocksize; | 435 | prev_location = blocksize; |
472 | for (i = 0; i < nr; i++, ih++) { | 436 | for (i = 0; i < nr; i++, ih++) { |
473 | if (le_ih_k_type(ih) == TYPE_ANY) { | 437 | if (le_ih_k_type(ih) == TYPE_ANY) { |
474 | reiserfs_warning(NULL, | 438 | reiserfs_warning(NULL, "reiserfs-5083", |
475 | "is_leaf: wrong item type for item %h", | 439 | "wrong item type for item %h", |
476 | ih); | 440 | ih); |
477 | return 0; | 441 | return 0; |
478 | } | 442 | } |
479 | if (ih_location(ih) >= blocksize | 443 | if (ih_location(ih) >= blocksize |
480 | || ih_location(ih) < IH_SIZE * nr) { | 444 | || ih_location(ih) < IH_SIZE * nr) { |
481 | reiserfs_warning(NULL, | 445 | reiserfs_warning(NULL, "reiserfs-5084", |
482 | "is_leaf: item location seems wrong: %h", | 446 | "item location seems wrong: %h", |
483 | ih); | 447 | ih); |
484 | return 0; | 448 | return 0; |
485 | } | 449 | } |
486 | if (ih_item_len(ih) < 1 | 450 | if (ih_item_len(ih) < 1 |
487 | || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) { | 451 | || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) { |
488 | reiserfs_warning(NULL, | 452 | reiserfs_warning(NULL, "reiserfs-5085", |
489 | "is_leaf: item length seems wrong: %h", | 453 | "item length seems wrong: %h", |
490 | ih); | 454 | ih); |
491 | return 0; | 455 | return 0; |
492 | } | 456 | } |
493 | if (prev_location - ih_location(ih) != ih_item_len(ih)) { | 457 | if (prev_location - ih_location(ih) != ih_item_len(ih)) { |
494 | reiserfs_warning(NULL, | 458 | reiserfs_warning(NULL, "reiserfs-5086", |
495 | "is_leaf: item location seems wrong (second one): %h", | 459 | "item location seems wrong " |
496 | ih); | 460 | "(second one): %h", ih); |
497 | return 0; | 461 | return 0; |
498 | } | 462 | } |
499 | prev_location = ih_location(ih); | 463 | prev_location = ih_location(ih); |
@@ -514,24 +478,23 @@ static int is_internal(char *buf, int blocksize, struct buffer_head *bh) | |||
514 | nr = blkh_level(blkh); | 478 | nr = blkh_level(blkh); |
515 | if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) { | 479 | if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) { |
516 | /* this level is not possible for internal nodes */ | 480 | /* this level is not possible for internal nodes */ |
517 | reiserfs_warning(NULL, | 481 | reiserfs_warning(NULL, "reiserfs-5087", |
518 | "is_internal: this should be caught earlier"); | 482 | "this should be caught earlier"); |
519 | return 0; | 483 | return 0; |
520 | } | 484 | } |
521 | 485 | ||
522 | nr = blkh_nr_item(blkh); | 486 | nr = blkh_nr_item(blkh); |
523 | if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) { | 487 | if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) { |
524 | /* for internal which is not root we might check min number of keys */ | 488 | /* for internal which is not root we might check min number of keys */ |
525 | reiserfs_warning(NULL, | 489 | reiserfs_warning(NULL, "reiserfs-5088", |
526 | "is_internal: number of key seems wrong: %z", | 490 | "number of key seems wrong: %z", bh); |
527 | bh); | ||
528 | return 0; | 491 | return 0; |
529 | } | 492 | } |
530 | 493 | ||
531 | used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1); | 494 | used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1); |
532 | if (used_space != blocksize - blkh_free_space(blkh)) { | 495 | if (used_space != blocksize - blkh_free_space(blkh)) { |
533 | reiserfs_warning(NULL, | 496 | reiserfs_warning(NULL, "reiserfs-5089", |
534 | "is_internal: free space seems wrong: %z", bh); | 497 | "free space seems wrong: %z", bh); |
535 | return 0; | 498 | return 0; |
536 | } | 499 | } |
537 | // one may imagine much more checks | 500 | // one may imagine much more checks |
@@ -543,8 +506,8 @@ static int is_internal(char *buf, int blocksize, struct buffer_head *bh) | |||
543 | static int is_tree_node(struct buffer_head *bh, int level) | 506 | static int is_tree_node(struct buffer_head *bh, int level) |
544 | { | 507 | { |
545 | if (B_LEVEL(bh) != level) { | 508 | if (B_LEVEL(bh) != level) { |
546 | reiserfs_warning(NULL, | 509 | reiserfs_warning(NULL, "reiserfs-5090", "node level %d does " |
547 | "is_tree_node: node level %d does not match to the expected one %d", | 510 | "not match to the expected one %d", |
548 | B_LEVEL(bh), level); | 511 | B_LEVEL(bh), level); |
549 | return 0; | 512 | return 0; |
550 | } | 513 | } |
@@ -580,10 +543,10 @@ static void search_by_key_reada(struct super_block *s, | |||
580 | /************************************************************************** | 543 | /************************************************************************** |
581 | * Algorithm SearchByKey * | 544 | * Algorithm SearchByKey * |
582 | * look for item in the Disk S+Tree by its key * | 545 | * look for item in the Disk S+Tree by its key * |
583 | * Input: p_s_sb - super block * | 546 | * Input: sb - super block * |
584 | * p_s_key - pointer to the key to search * | 547 | * key - pointer to the key to search * |
585 | * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR * | 548 | * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR * |
586 | * p_s_search_path - path from the root to the needed leaf * | 549 | * search_path - path from the root to the needed leaf * |
587 | **************************************************************************/ | 550 | **************************************************************************/ |
588 | 551 | ||
589 | /* This function fills up the path from the root to the leaf as it | 552 | /* This function fills up the path from the root to the leaf as it |
@@ -600,22 +563,22 @@ static void search_by_key_reada(struct super_block *s, | |||
600 | correctness of the top of the path but need not be checked for the | 563 | correctness of the top of the path but need not be checked for the |
601 | correctness of the bottom of the path */ | 564 | correctness of the bottom of the path */ |
602 | /* The function is NOT SCHEDULE-SAFE! */ | 565 | /* The function is NOT SCHEDULE-SAFE! */ |
603 | int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */ | 566 | int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to search. */ |
604 | struct treepath *p_s_search_path,/* This structure was | 567 | struct treepath *search_path,/* This structure was |
605 | allocated and initialized | 568 | allocated and initialized |
606 | by the calling | 569 | by the calling |
607 | function. It is filled up | 570 | function. It is filled up |
608 | by this function. */ | 571 | by this function. */ |
609 | int n_stop_level /* How far down the tree to search. To | 572 | int stop_level /* How far down the tree to search. To |
610 | stop at leaf level - set to | 573 | stop at leaf level - set to |
611 | DISK_LEAF_NODE_LEVEL */ | 574 | DISK_LEAF_NODE_LEVEL */ |
612 | ) | 575 | ) |
613 | { | 576 | { |
614 | b_blocknr_t n_block_number; | 577 | b_blocknr_t block_number; |
615 | int expected_level; | 578 | int expected_level; |
616 | struct buffer_head *p_s_bh; | 579 | struct buffer_head *bh; |
617 | struct path_element *p_s_last_element; | 580 | struct path_element *last_element; |
618 | int n_node_level, n_retval; | 581 | int node_level, retval; |
619 | int right_neighbor_of_leaf_node; | 582 | int right_neighbor_of_leaf_node; |
620 | int fs_gen; | 583 | int fs_gen; |
621 | struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; | 584 | struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; |
@@ -623,80 +586,79 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* | |||
623 | int reada_count = 0; | 586 | int reada_count = 0; |
624 | 587 | ||
625 | #ifdef CONFIG_REISERFS_CHECK | 588 | #ifdef CONFIG_REISERFS_CHECK |
626 | int n_repeat_counter = 0; | 589 | int repeat_counter = 0; |
627 | #endif | 590 | #endif |
628 | 591 | ||
629 | PROC_INFO_INC(p_s_sb, search_by_key); | 592 | PROC_INFO_INC(sb, search_by_key); |
630 | 593 | ||
631 | /* As we add each node to a path we increase its count. This means that | 594 | /* As we add each node to a path we increase its count. This means that |
632 | we must be careful to release all nodes in a path before we either | 595 | we must be careful to release all nodes in a path before we either |
633 | discard the path struct or re-use the path struct, as we do here. */ | 596 | discard the path struct or re-use the path struct, as we do here. */ |
634 | 597 | ||
635 | decrement_counters_in_path(p_s_search_path); | 598 | pathrelse(search_path); |
636 | 599 | ||
637 | right_neighbor_of_leaf_node = 0; | 600 | right_neighbor_of_leaf_node = 0; |
638 | 601 | ||
639 | /* With each iteration of this loop we search through the items in the | 602 | /* With each iteration of this loop we search through the items in the |
640 | current node, and calculate the next current node(next path element) | 603 | current node, and calculate the next current node(next path element) |
641 | for the next iteration of this loop.. */ | 604 | for the next iteration of this loop.. */ |
642 | n_block_number = SB_ROOT_BLOCK(p_s_sb); | 605 | block_number = SB_ROOT_BLOCK(sb); |
643 | expected_level = -1; | 606 | expected_level = -1; |
644 | while (1) { | 607 | while (1) { |
645 | 608 | ||
646 | #ifdef CONFIG_REISERFS_CHECK | 609 | #ifdef CONFIG_REISERFS_CHECK |
647 | if (!(++n_repeat_counter % 50000)) | 610 | if (!(++repeat_counter % 50000)) |
648 | reiserfs_warning(p_s_sb, "PAP-5100: search_by_key: %s:" | 611 | reiserfs_warning(sb, "PAP-5100", |
649 | "there were %d iterations of while loop " | 612 | "%s: there were %d iterations of " |
650 | "looking for key %K", | 613 | "while loop looking for key %K", |
651 | current->comm, n_repeat_counter, | 614 | current->comm, repeat_counter, |
652 | p_s_key); | 615 | key); |
653 | #endif | 616 | #endif |
654 | 617 | ||
655 | /* prep path to have another element added to it. */ | 618 | /* prep path to have another element added to it. */ |
656 | p_s_last_element = | 619 | last_element = |
657 | PATH_OFFSET_PELEMENT(p_s_search_path, | 620 | PATH_OFFSET_PELEMENT(search_path, |
658 | ++p_s_search_path->path_length); | 621 | ++search_path->path_length); |
659 | fs_gen = get_generation(p_s_sb); | 622 | fs_gen = get_generation(sb); |
660 | 623 | ||
661 | /* Read the next tree node, and set the last element in the path to | 624 | /* Read the next tree node, and set the last element in the path to |
662 | have a pointer to it. */ | 625 | have a pointer to it. */ |
663 | if ((p_s_bh = p_s_last_element->pe_buffer = | 626 | if ((bh = last_element->pe_buffer = |
664 | sb_getblk(p_s_sb, n_block_number))) { | 627 | sb_getblk(sb, block_number))) { |
665 | if (!buffer_uptodate(p_s_bh) && reada_count > 1) { | 628 | if (!buffer_uptodate(bh) && reada_count > 1) |
666 | search_by_key_reada(p_s_sb, reada_bh, | 629 | search_by_key_reada(sb, reada_bh, |
667 | reada_blocks, reada_count); | 630 | reada_blocks, reada_count); |
668 | } | 631 | ll_rw_block(READ, 1, &bh); |
669 | ll_rw_block(READ, 1, &p_s_bh); | 632 | wait_on_buffer(bh); |
670 | wait_on_buffer(p_s_bh); | 633 | if (!buffer_uptodate(bh)) |
671 | if (!buffer_uptodate(p_s_bh)) | ||
672 | goto io_error; | 634 | goto io_error; |
673 | } else { | 635 | } else { |
674 | io_error: | 636 | io_error: |
675 | p_s_search_path->path_length--; | 637 | search_path->path_length--; |
676 | pathrelse(p_s_search_path); | 638 | pathrelse(search_path); |
677 | return IO_ERROR; | 639 | return IO_ERROR; |
678 | } | 640 | } |
679 | reada_count = 0; | 641 | reada_count = 0; |
680 | if (expected_level == -1) | 642 | if (expected_level == -1) |
681 | expected_level = SB_TREE_HEIGHT(p_s_sb); | 643 | expected_level = SB_TREE_HEIGHT(sb); |
682 | expected_level--; | 644 | expected_level--; |
683 | 645 | ||
684 | /* It is possible that schedule occurred. We must check whether the key | 646 | /* It is possible that schedule occurred. We must check whether the key |
685 | to search is still in the tree rooted from the current buffer. If | 647 | to search is still in the tree rooted from the current buffer. If |
686 | not then repeat search from the root. */ | 648 | not then repeat search from the root. */ |
687 | if (fs_changed(fs_gen, p_s_sb) && | 649 | if (fs_changed(fs_gen, sb) && |
688 | (!B_IS_IN_TREE(p_s_bh) || | 650 | (!B_IS_IN_TREE(bh) || |
689 | B_LEVEL(p_s_bh) != expected_level || | 651 | B_LEVEL(bh) != expected_level || |
690 | !key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) { | 652 | !key_in_buffer(search_path, key, sb))) { |
691 | PROC_INFO_INC(p_s_sb, search_by_key_fs_changed); | 653 | PROC_INFO_INC(sb, search_by_key_fs_changed); |
692 | PROC_INFO_INC(p_s_sb, search_by_key_restarted); | 654 | PROC_INFO_INC(sb, search_by_key_restarted); |
693 | PROC_INFO_INC(p_s_sb, | 655 | PROC_INFO_INC(sb, |
694 | sbk_restarted[expected_level - 1]); | 656 | sbk_restarted[expected_level - 1]); |
695 | decrement_counters_in_path(p_s_search_path); | 657 | pathrelse(search_path); |
696 | 658 | ||
697 | /* Get the root block number so that we can repeat the search | 659 | /* Get the root block number so that we can repeat the search |
698 | starting from the root. */ | 660 | starting from the root. */ |
699 | n_block_number = SB_ROOT_BLOCK(p_s_sb); | 661 | block_number = SB_ROOT_BLOCK(sb); |
700 | expected_level = -1; | 662 | expected_level = -1; |
701 | right_neighbor_of_leaf_node = 0; | 663 | right_neighbor_of_leaf_node = 0; |
702 | 664 | ||
@@ -704,53 +666,53 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* | |||
704 | continue; | 666 | continue; |
705 | } | 667 | } |
706 | 668 | ||
707 | /* only check that the key is in the buffer if p_s_key is not | 669 | /* only check that the key is in the buffer if key is not |
708 | equal to the MAX_KEY. Latter case is only possible in | 670 | equal to the MAX_KEY. Latter case is only possible in |
709 | "finish_unfinished()" processing during mount. */ | 671 | "finish_unfinished()" processing during mount. */ |
710 | RFALSE(comp_keys(&MAX_KEY, p_s_key) && | 672 | RFALSE(comp_keys(&MAX_KEY, key) && |
711 | !key_in_buffer(p_s_search_path, p_s_key, p_s_sb), | 673 | !key_in_buffer(search_path, key, sb), |
712 | "PAP-5130: key is not in the buffer"); | 674 | "PAP-5130: key is not in the buffer"); |
713 | #ifdef CONFIG_REISERFS_CHECK | 675 | #ifdef CONFIG_REISERFS_CHECK |
714 | if (cur_tb) { | 676 | if (cur_tb) { |
715 | print_cur_tb("5140"); | 677 | print_cur_tb("5140"); |
716 | reiserfs_panic(p_s_sb, | 678 | reiserfs_panic(sb, "PAP-5140", |
717 | "PAP-5140: search_by_key: schedule occurred in do_balance!"); | 679 | "schedule occurred in do_balance!"); |
718 | } | 680 | } |
719 | #endif | 681 | #endif |
720 | 682 | ||
721 | // make sure, that the node contents look like a node of | 683 | // make sure, that the node contents look like a node of |
722 | // certain level | 684 | // certain level |
723 | if (!is_tree_node(p_s_bh, expected_level)) { | 685 | if (!is_tree_node(bh, expected_level)) { |
724 | reiserfs_warning(p_s_sb, "vs-5150: search_by_key: " | 686 | reiserfs_error(sb, "vs-5150", |
725 | "invalid format found in block %ld. Fsck?", | 687 | "invalid format found in block %ld. " |
726 | p_s_bh->b_blocknr); | 688 | "Fsck?", bh->b_blocknr); |
727 | pathrelse(p_s_search_path); | 689 | pathrelse(search_path); |
728 | return IO_ERROR; | 690 | return IO_ERROR; |
729 | } | 691 | } |
730 | 692 | ||
731 | /* ok, we have acquired next formatted node in the tree */ | 693 | /* ok, we have acquired next formatted node in the tree */ |
732 | n_node_level = B_LEVEL(p_s_bh); | 694 | node_level = B_LEVEL(bh); |
733 | 695 | ||
734 | PROC_INFO_BH_STAT(p_s_sb, p_s_bh, n_node_level - 1); | 696 | PROC_INFO_BH_STAT(sb, bh, node_level - 1); |
735 | 697 | ||
736 | RFALSE(n_node_level < n_stop_level, | 698 | RFALSE(node_level < stop_level, |
737 | "vs-5152: tree level (%d) is less than stop level (%d)", | 699 | "vs-5152: tree level (%d) is less than stop level (%d)", |
738 | n_node_level, n_stop_level); | 700 | node_level, stop_level); |
739 | 701 | ||
740 | n_retval = bin_search(p_s_key, B_N_PITEM_HEAD(p_s_bh, 0), | 702 | retval = bin_search(key, B_N_PITEM_HEAD(bh, 0), |
741 | B_NR_ITEMS(p_s_bh), | 703 | B_NR_ITEMS(bh), |
742 | (n_node_level == | 704 | (node_level == |
743 | DISK_LEAF_NODE_LEVEL) ? IH_SIZE : | 705 | DISK_LEAF_NODE_LEVEL) ? IH_SIZE : |
744 | KEY_SIZE, | 706 | KEY_SIZE, |
745 | &(p_s_last_element->pe_position)); | 707 | &(last_element->pe_position)); |
746 | if (n_node_level == n_stop_level) { | 708 | if (node_level == stop_level) { |
747 | return n_retval; | 709 | return retval; |
748 | } | 710 | } |
749 | 711 | ||
750 | /* we are not in the stop level */ | 712 | /* we are not in the stop level */ |
751 | if (n_retval == ITEM_FOUND) | 713 | if (retval == ITEM_FOUND) |
752 | /* item has been found, so we choose the pointer which is to the right of the found one */ | 714 | /* item has been found, so we choose the pointer which is to the right of the found one */ |
753 | p_s_last_element->pe_position++; | 715 | last_element->pe_position++; |
754 | 716 | ||
755 | /* if item was not found we choose the position which is to | 717 | /* if item was not found we choose the position which is to |
756 | the left of the found item. This requires no code, | 718 | the left of the found item. This requires no code, |
@@ -759,24 +721,24 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* | |||
759 | /* So we have chosen a position in the current node which is | 721 | /* So we have chosen a position in the current node which is |
760 | an internal node. Now we calculate child block number by | 722 | an internal node. Now we calculate child block number by |
761 | position in the node. */ | 723 | position in the node. */ |
762 | n_block_number = | 724 | block_number = |
763 | B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position); | 725 | B_N_CHILD_NUM(bh, last_element->pe_position); |
764 | 726 | ||
765 | /* if we are going to read leaf nodes, try for read ahead as well */ | 727 | /* if we are going to read leaf nodes, try for read ahead as well */ |
766 | if ((p_s_search_path->reada & PATH_READA) && | 728 | if ((search_path->reada & PATH_READA) && |
767 | n_node_level == DISK_LEAF_NODE_LEVEL + 1) { | 729 | node_level == DISK_LEAF_NODE_LEVEL + 1) { |
768 | int pos = p_s_last_element->pe_position; | 730 | int pos = last_element->pe_position; |
769 | int limit = B_NR_ITEMS(p_s_bh); | 731 | int limit = B_NR_ITEMS(bh); |
770 | struct reiserfs_key *le_key; | 732 | struct reiserfs_key *le_key; |
771 | 733 | ||
772 | if (p_s_search_path->reada & PATH_READA_BACK) | 734 | if (search_path->reada & PATH_READA_BACK) |
773 | limit = 0; | 735 | limit = 0; |
774 | while (reada_count < SEARCH_BY_KEY_READA) { | 736 | while (reada_count < SEARCH_BY_KEY_READA) { |
775 | if (pos == limit) | 737 | if (pos == limit) |
776 | break; | 738 | break; |
777 | reada_blocks[reada_count++] = | 739 | reada_blocks[reada_count++] = |
778 | B_N_CHILD_NUM(p_s_bh, pos); | 740 | B_N_CHILD_NUM(bh, pos); |
779 | if (p_s_search_path->reada & PATH_READA_BACK) | 741 | if (search_path->reada & PATH_READA_BACK) |
780 | pos--; | 742 | pos--; |
781 | else | 743 | else |
782 | pos++; | 744 | pos++; |
@@ -784,9 +746,9 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* | |||
784 | /* | 746 | /* |
785 | * check to make sure we're in the same object | 747 | * check to make sure we're in the same object |
786 | */ | 748 | */ |
787 | le_key = B_N_PDELIM_KEY(p_s_bh, pos); | 749 | le_key = B_N_PDELIM_KEY(bh, pos); |
788 | if (le32_to_cpu(le_key->k_objectid) != | 750 | if (le32_to_cpu(le_key->k_objectid) != |
789 | p_s_key->on_disk_key.k_objectid) { | 751 | key->on_disk_key.k_objectid) { |
790 | break; | 752 | break; |
791 | } | 753 | } |
792 | } | 754 | } |
@@ -795,11 +757,11 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* | |||
795 | } | 757 | } |
796 | 758 | ||
797 | /* Form the path to an item and position in this item which contains | 759 | /* Form the path to an item and position in this item which contains |
798 | file byte defined by p_s_key. If there is no such item | 760 | file byte defined by key. If there is no such item |
799 | corresponding to the key, we point the path to the item with | 761 | corresponding to the key, we point the path to the item with |
800 | maximal key less than p_s_key, and *p_n_pos_in_item is set to one | 762 | maximal key less than key, and *pos_in_item is set to one |
801 | past the last entry/byte in the item. If searching for entry in a | 763 | past the last entry/byte in the item. If searching for entry in a |
802 | directory item, and it is not found, *p_n_pos_in_item is set to one | 764 | directory item, and it is not found, *pos_in_item is set to one |
803 | entry more than the entry with maximal key which is less than the | 765 | entry more than the entry with maximal key which is less than the |
804 | sought key. | 766 | sought key. |
805 | 767 | ||
@@ -810,48 +772,48 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* | |||
810 | units of directory entries. */ | 772 | units of directory entries. */ |
811 | 773 | ||
812 | /* The function is NOT SCHEDULE-SAFE! */ | 774 | /* The function is NOT SCHEDULE-SAFE! */ |
813 | int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the super block. */ | 775 | int search_for_position_by_key(struct super_block *sb, /* Pointer to the super block. */ |
814 | const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */ | 776 | const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */ |
815 | struct treepath *p_s_search_path /* Filled up by this function. */ | 777 | struct treepath *search_path /* Filled up by this function. */ |
816 | ) | 778 | ) |
817 | { | 779 | { |
818 | struct item_head *p_le_ih; /* pointer to on-disk structure */ | 780 | struct item_head *p_le_ih; /* pointer to on-disk structure */ |
819 | int n_blk_size; | 781 | int blk_size; |
820 | loff_t item_offset, offset; | 782 | loff_t item_offset, offset; |
821 | struct reiserfs_dir_entry de; | 783 | struct reiserfs_dir_entry de; |
822 | int retval; | 784 | int retval; |
823 | 785 | ||
824 | /* If searching for directory entry. */ | 786 | /* If searching for directory entry. */ |
825 | if (is_direntry_cpu_key(p_cpu_key)) | 787 | if (is_direntry_cpu_key(p_cpu_key)) |
826 | return search_by_entry_key(p_s_sb, p_cpu_key, p_s_search_path, | 788 | return search_by_entry_key(sb, p_cpu_key, search_path, |
827 | &de); | 789 | &de); |
828 | 790 | ||
829 | /* If not searching for directory entry. */ | 791 | /* If not searching for directory entry. */ |
830 | 792 | ||
831 | /* If item is found. */ | 793 | /* If item is found. */ |
832 | retval = search_item(p_s_sb, p_cpu_key, p_s_search_path); | 794 | retval = search_item(sb, p_cpu_key, search_path); |
833 | if (retval == IO_ERROR) | 795 | if (retval == IO_ERROR) |
834 | return retval; | 796 | return retval; |
835 | if (retval == ITEM_FOUND) { | 797 | if (retval == ITEM_FOUND) { |
836 | 798 | ||
837 | RFALSE(!ih_item_len | 799 | RFALSE(!ih_item_len |
838 | (B_N_PITEM_HEAD | 800 | (B_N_PITEM_HEAD |
839 | (PATH_PLAST_BUFFER(p_s_search_path), | 801 | (PATH_PLAST_BUFFER(search_path), |
840 | PATH_LAST_POSITION(p_s_search_path))), | 802 | PATH_LAST_POSITION(search_path))), |
841 | "PAP-5165: item length equals zero"); | 803 | "PAP-5165: item length equals zero"); |
842 | 804 | ||
843 | pos_in_item(p_s_search_path) = 0; | 805 | pos_in_item(search_path) = 0; |
844 | return POSITION_FOUND; | 806 | return POSITION_FOUND; |
845 | } | 807 | } |
846 | 808 | ||
847 | RFALSE(!PATH_LAST_POSITION(p_s_search_path), | 809 | RFALSE(!PATH_LAST_POSITION(search_path), |
848 | "PAP-5170: position equals zero"); | 810 | "PAP-5170: position equals zero"); |
849 | 811 | ||
850 | /* Item is not found. Set path to the previous item. */ | 812 | /* Item is not found. Set path to the previous item. */ |
851 | p_le_ih = | 813 | p_le_ih = |
852 | B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path), | 814 | B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path), |
853 | --PATH_LAST_POSITION(p_s_search_path)); | 815 | --PATH_LAST_POSITION(search_path)); |
854 | n_blk_size = p_s_sb->s_blocksize; | 816 | blk_size = sb->s_blocksize; |
855 | 817 | ||
856 | if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { | 818 | if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { |
857 | return FILE_NOT_FOUND; | 819 | return FILE_NOT_FOUND; |
@@ -863,10 +825,10 @@ int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the sup | |||
863 | 825 | ||
864 | /* Needed byte is contained in the item pointed to by the path. */ | 826 | /* Needed byte is contained in the item pointed to by the path. */ |
865 | if (item_offset <= offset && | 827 | if (item_offset <= offset && |
866 | item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) { | 828 | item_offset + op_bytes_number(p_le_ih, blk_size) > offset) { |
867 | pos_in_item(p_s_search_path) = offset - item_offset; | 829 | pos_in_item(search_path) = offset - item_offset; |
868 | if (is_indirect_le_ih(p_le_ih)) { | 830 | if (is_indirect_le_ih(p_le_ih)) { |
869 | pos_in_item(p_s_search_path) /= n_blk_size; | 831 | pos_in_item(search_path) /= blk_size; |
870 | } | 832 | } |
871 | return POSITION_FOUND; | 833 | return POSITION_FOUND; |
872 | } | 834 | } |
@@ -874,30 +836,30 @@ int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the sup | |||
874 | /* Needed byte is not contained in the item pointed to by the | 836 | /* Needed byte is not contained in the item pointed to by the |
875 | path. Set pos_in_item out of the item. */ | 837 | path. Set pos_in_item out of the item. */ |
876 | if (is_indirect_le_ih(p_le_ih)) | 838 | if (is_indirect_le_ih(p_le_ih)) |
877 | pos_in_item(p_s_search_path) = | 839 | pos_in_item(search_path) = |
878 | ih_item_len(p_le_ih) / UNFM_P_SIZE; | 840 | ih_item_len(p_le_ih) / UNFM_P_SIZE; |
879 | else | 841 | else |
880 | pos_in_item(p_s_search_path) = ih_item_len(p_le_ih); | 842 | pos_in_item(search_path) = ih_item_len(p_le_ih); |
881 | 843 | ||
882 | return POSITION_NOT_FOUND; | 844 | return POSITION_NOT_FOUND; |
883 | } | 845 | } |
884 | 846 | ||
885 | /* Compare given item and item pointed to by the path. */ | 847 | /* Compare given item and item pointed to by the path. */ |
886 | int comp_items(const struct item_head *stored_ih, const struct treepath *p_s_path) | 848 | int comp_items(const struct item_head *stored_ih, const struct treepath *path) |
887 | { | 849 | { |
888 | struct buffer_head *p_s_bh; | 850 | struct buffer_head *bh = PATH_PLAST_BUFFER(path); |
889 | struct item_head *ih; | 851 | struct item_head *ih; |
890 | 852 | ||
891 | /* Last buffer at the path is not in the tree. */ | 853 | /* Last buffer at the path is not in the tree. */ |
892 | if (!B_IS_IN_TREE(p_s_bh = PATH_PLAST_BUFFER(p_s_path))) | 854 | if (!B_IS_IN_TREE(bh)) |
893 | return 1; | 855 | return 1; |
894 | 856 | ||
895 | /* Last path position is invalid. */ | 857 | /* Last path position is invalid. */ |
896 | if (PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(p_s_bh)) | 858 | if (PATH_LAST_POSITION(path) >= B_NR_ITEMS(bh)) |
897 | return 1; | 859 | return 1; |
898 | 860 | ||
899 | /* we need only to know, whether it is the same item */ | 861 | /* we need only to know, whether it is the same item */ |
900 | ih = get_ih(p_s_path); | 862 | ih = get_ih(path); |
901 | return memcmp(stored_ih, ih, IH_SIZE); | 863 | return memcmp(stored_ih, ih, IH_SIZE); |
902 | } | 864 | } |
903 | 865 | ||
@@ -924,9 +886,9 @@ static inline int prepare_for_direct_item(struct treepath *path, | |||
924 | } | 886 | } |
925 | // new file gets truncated | 887 | // new file gets truncated |
926 | if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { | 888 | if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { |
927 | // | 889 | // |
928 | round_len = ROUND_UP(new_file_length); | 890 | round_len = ROUND_UP(new_file_length); |
929 | /* this was n_new_file_length < le_ih ... */ | 891 | /* this was new_file_length < le_ih ... */ |
930 | if (round_len < le_ih_k_offset(le_ih)) { | 892 | if (round_len < le_ih_k_offset(le_ih)) { |
931 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); | 893 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); |
932 | return M_DELETE; /* Delete this item. */ | 894 | return M_DELETE; /* Delete this item. */ |
@@ -986,96 +948,95 @@ static inline int prepare_for_direntry_item(struct treepath *path, | |||
986 | In case of file truncate calculate whether this item must be deleted/truncated or last | 948 | In case of file truncate calculate whether this item must be deleted/truncated or last |
987 | unformatted node of this item will be converted to a direct item. | 949 | unformatted node of this item will be converted to a direct item. |
988 | This function returns a determination of what balance mode the calling function should employ. */ | 950 | This function returns a determination of what balance mode the calling function should employ. */ |
989 | static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed | 951 | static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path, const struct cpu_key *item_key, int *removed, /* Number of unformatted nodes which were removed |
990 | from end of the file. */ | 952 | from end of the file. */ |
991 | int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */ | 953 | int *cut_size, unsigned long long new_file_length /* MAX_KEY_OFFSET in case of delete. */ |
992 | ) | 954 | ) |
993 | { | 955 | { |
994 | struct super_block *p_s_sb = inode->i_sb; | 956 | struct super_block *sb = inode->i_sb; |
995 | struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_path); | 957 | struct item_head *p_le_ih = PATH_PITEM_HEAD(path); |
996 | struct buffer_head *p_s_bh = PATH_PLAST_BUFFER(p_s_path); | 958 | struct buffer_head *bh = PATH_PLAST_BUFFER(path); |
997 | 959 | ||
998 | BUG_ON(!th->t_trans_id); | 960 | BUG_ON(!th->t_trans_id); |
999 | 961 | ||
1000 | /* Stat_data item. */ | 962 | /* Stat_data item. */ |
1001 | if (is_statdata_le_ih(p_le_ih)) { | 963 | if (is_statdata_le_ih(p_le_ih)) { |
1002 | 964 | ||
1003 | RFALSE(n_new_file_length != max_reiserfs_offset(inode), | 965 | RFALSE(new_file_length != max_reiserfs_offset(inode), |
1004 | "PAP-5210: mode must be M_DELETE"); | 966 | "PAP-5210: mode must be M_DELETE"); |
1005 | 967 | ||
1006 | *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih)); | 968 | *cut_size = -(IH_SIZE + ih_item_len(p_le_ih)); |
1007 | return M_DELETE; | 969 | return M_DELETE; |
1008 | } | 970 | } |
1009 | 971 | ||
1010 | /* Directory item. */ | 972 | /* Directory item. */ |
1011 | if (is_direntry_le_ih(p_le_ih)) | 973 | if (is_direntry_le_ih(p_le_ih)) |
1012 | return prepare_for_direntry_item(p_s_path, p_le_ih, inode, | 974 | return prepare_for_direntry_item(path, p_le_ih, inode, |
1013 | n_new_file_length, | 975 | new_file_length, |
1014 | p_n_cut_size); | 976 | cut_size); |
1015 | 977 | ||
1016 | /* Direct item. */ | 978 | /* Direct item. */ |
1017 | if (is_direct_le_ih(p_le_ih)) | 979 | if (is_direct_le_ih(p_le_ih)) |
1018 | return prepare_for_direct_item(p_s_path, p_le_ih, inode, | 980 | return prepare_for_direct_item(path, p_le_ih, inode, |
1019 | n_new_file_length, p_n_cut_size); | 981 | new_file_length, cut_size); |
1020 | 982 | ||
1021 | /* Case of an indirect item. */ | 983 | /* Case of an indirect item. */ |
1022 | { | 984 | { |
1023 | int blk_size = p_s_sb->s_blocksize; | 985 | int blk_size = sb->s_blocksize; |
1024 | struct item_head s_ih; | 986 | struct item_head s_ih; |
1025 | int need_re_search; | 987 | int need_re_search; |
1026 | int delete = 0; | 988 | int delete = 0; |
1027 | int result = M_CUT; | 989 | int result = M_CUT; |
1028 | int pos = 0; | 990 | int pos = 0; |
1029 | 991 | ||
1030 | if ( n_new_file_length == max_reiserfs_offset (inode) ) { | 992 | if ( new_file_length == max_reiserfs_offset (inode) ) { |
1031 | /* prepare_for_delete_or_cut() is called by | 993 | /* prepare_for_delete_or_cut() is called by |
1032 | * reiserfs_delete_item() */ | 994 | * reiserfs_delete_item() */ |
1033 | n_new_file_length = 0; | 995 | new_file_length = 0; |
1034 | delete = 1; | 996 | delete = 1; |
1035 | } | 997 | } |
1036 | 998 | ||
1037 | do { | 999 | do { |
1038 | need_re_search = 0; | 1000 | need_re_search = 0; |
1039 | *p_n_cut_size = 0; | 1001 | *cut_size = 0; |
1040 | p_s_bh = PATH_PLAST_BUFFER(p_s_path); | 1002 | bh = PATH_PLAST_BUFFER(path); |
1041 | copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); | 1003 | copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); |
1042 | pos = I_UNFM_NUM(&s_ih); | 1004 | pos = I_UNFM_NUM(&s_ih); |
1043 | 1005 | ||
1044 | while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > n_new_file_length) { | 1006 | while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > new_file_length) { |
1045 | __le32 *unfm; | 1007 | __le32 *unfm; |
1046 | __u32 block; | 1008 | __u32 block; |
1047 | 1009 | ||
1048 | /* Each unformatted block deletion may involve one additional | 1010 | /* Each unformatted block deletion may involve one additional |
1049 | * bitmap block into the transaction, thereby the initial | 1011 | * bitmap block into the transaction, thereby the initial |
1050 | * journal space reservation might not be enough. */ | 1012 | * journal space reservation might not be enough. */ |
1051 | if (!delete && (*p_n_cut_size) != 0 && | 1013 | if (!delete && (*cut_size) != 0 && |
1052 | reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { | 1014 | reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) |
1053 | break; | 1015 | break; |
1054 | } | ||
1055 | 1016 | ||
1056 | unfm = (__le32 *)B_I_PITEM(p_s_bh, &s_ih) + pos - 1; | 1017 | unfm = (__le32 *)B_I_PITEM(bh, &s_ih) + pos - 1; |
1057 | block = get_block_num(unfm, 0); | 1018 | block = get_block_num(unfm, 0); |
1058 | 1019 | ||
1059 | if (block != 0) { | 1020 | if (block != 0) { |
1060 | reiserfs_prepare_for_journal(p_s_sb, p_s_bh, 1); | 1021 | reiserfs_prepare_for_journal(sb, bh, 1); |
1061 | put_block_num(unfm, 0, 0); | 1022 | put_block_num(unfm, 0, 0); |
1062 | journal_mark_dirty (th, p_s_sb, p_s_bh); | 1023 | journal_mark_dirty(th, sb, bh); |
1063 | reiserfs_free_block(th, inode, block, 1); | 1024 | reiserfs_free_block(th, inode, block, 1); |
1064 | } | 1025 | } |
1065 | 1026 | ||
1066 | cond_resched(); | 1027 | cond_resched(); |
1067 | 1028 | ||
1068 | if (item_moved (&s_ih, p_s_path)) { | 1029 | if (item_moved (&s_ih, path)) { |
1069 | need_re_search = 1; | 1030 | need_re_search = 1; |
1070 | break; | 1031 | break; |
1071 | } | 1032 | } |
1072 | 1033 | ||
1073 | pos --; | 1034 | pos --; |
1074 | (*p_n_removed) ++; | 1035 | (*removed)++; |
1075 | (*p_n_cut_size) -= UNFM_P_SIZE; | 1036 | (*cut_size) -= UNFM_P_SIZE; |
1076 | 1037 | ||
1077 | if (pos == 0) { | 1038 | if (pos == 0) { |
1078 | (*p_n_cut_size) -= IH_SIZE; | 1039 | (*cut_size) -= IH_SIZE; |
1079 | result = M_DELETE; | 1040 | result = M_DELETE; |
1080 | break; | 1041 | break; |
1081 | } | 1042 | } |
@@ -1083,12 +1044,12 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st | |||
1083 | /* a trick. If the buffer has been logged, this will do nothing. If | 1044 | /* a trick. If the buffer has been logged, this will do nothing. If |
1084 | ** we've broken the loop without logging it, it will restore the | 1045 | ** we've broken the loop without logging it, it will restore the |
1085 | ** buffer */ | 1046 | ** buffer */ |
1086 | reiserfs_restore_prepared_buffer(p_s_sb, p_s_bh); | 1047 | reiserfs_restore_prepared_buffer(sb, bh); |
1087 | } while (need_re_search && | 1048 | } while (need_re_search && |
1088 | search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) == POSITION_FOUND); | 1049 | search_for_position_by_key(sb, item_key, path) == POSITION_FOUND); |
1089 | pos_in_item(p_s_path) = pos * UNFM_P_SIZE; | 1050 | pos_in_item(path) = pos * UNFM_P_SIZE; |
1090 | 1051 | ||
1091 | if (*p_n_cut_size == 0) { | 1052 | if (*cut_size == 0) { |
1092 | /* Nothing were cut. maybe convert last unformatted node to the | 1053 | /* Nothing were cut. maybe convert last unformatted node to the |
1093 | * direct item? */ | 1054 | * direct item? */ |
1094 | result = M_CONVERT; | 1055 | result = M_CONVERT; |
@@ -1098,45 +1059,45 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st | |||
1098 | } | 1059 | } |
1099 | 1060 | ||
1100 | /* Calculate number of bytes which will be deleted or cut during balance */ | 1061 | /* Calculate number of bytes which will be deleted or cut during balance */ |
1101 | static int calc_deleted_bytes_number(struct tree_balance *p_s_tb, char c_mode) | 1062 | static int calc_deleted_bytes_number(struct tree_balance *tb, char mode) |
1102 | { | 1063 | { |
1103 | int n_del_size; | 1064 | int del_size; |
1104 | struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path); | 1065 | struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path); |
1105 | 1066 | ||
1106 | if (is_statdata_le_ih(p_le_ih)) | 1067 | if (is_statdata_le_ih(p_le_ih)) |
1107 | return 0; | 1068 | return 0; |
1108 | 1069 | ||
1109 | n_del_size = | 1070 | del_size = |
1110 | (c_mode == | 1071 | (mode == |
1111 | M_DELETE) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0]; | 1072 | M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0]; |
1112 | if (is_direntry_le_ih(p_le_ih)) { | 1073 | if (is_direntry_le_ih(p_le_ih)) { |
1113 | // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */ | 1074 | /* return EMPTY_DIR_SIZE; We delete emty directoris only. |
1114 | // we can't use EMPTY_DIR_SIZE, as old format dirs have a different | 1075 | * we can't use EMPTY_DIR_SIZE, as old format dirs have a different |
1115 | // empty size. ick. FIXME, is this right? | 1076 | * empty size. ick. FIXME, is this right? */ |
1116 | // | 1077 | return del_size; |
1117 | return n_del_size; | ||
1118 | } | 1078 | } |
1119 | 1079 | ||
1120 | if (is_indirect_le_ih(p_le_ih)) | 1080 | if (is_indirect_le_ih(p_le_ih)) |
1121 | n_del_size = (n_del_size / UNFM_P_SIZE) * (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size); // - get_ih_free_space (p_le_ih); | 1081 | del_size = (del_size / UNFM_P_SIZE) * |
1122 | return n_del_size; | 1082 | (PATH_PLAST_BUFFER(tb->tb_path)->b_size); |
1083 | return del_size; | ||
1123 | } | 1084 | } |
1124 | 1085 | ||
1125 | static void init_tb_struct(struct reiserfs_transaction_handle *th, | 1086 | static void init_tb_struct(struct reiserfs_transaction_handle *th, |
1126 | struct tree_balance *p_s_tb, | 1087 | struct tree_balance *tb, |
1127 | struct super_block *p_s_sb, | 1088 | struct super_block *sb, |
1128 | struct treepath *p_s_path, int n_size) | 1089 | struct treepath *path, int size) |
1129 | { | 1090 | { |
1130 | 1091 | ||
1131 | BUG_ON(!th->t_trans_id); | 1092 | BUG_ON(!th->t_trans_id); |
1132 | 1093 | ||
1133 | memset(p_s_tb, '\0', sizeof(struct tree_balance)); | 1094 | memset(tb, '\0', sizeof(struct tree_balance)); |
1134 | p_s_tb->transaction_handle = th; | 1095 | tb->transaction_handle = th; |
1135 | p_s_tb->tb_sb = p_s_sb; | 1096 | tb->tb_sb = sb; |
1136 | p_s_tb->tb_path = p_s_path; | 1097 | tb->tb_path = path; |
1137 | PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL; | 1098 | PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL; |
1138 | PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0; | 1099 | PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0; |
1139 | p_s_tb->insert_size[0] = n_size; | 1100 | tb->insert_size[0] = size; |
1140 | } | 1101 | } |
1141 | 1102 | ||
1142 | void padd_item(char *item, int total_length, int length) | 1103 | void padd_item(char *item, int total_length, int length) |
@@ -1175,73 +1136,77 @@ char head2type(struct item_head *ih) | |||
1175 | } | 1136 | } |
1176 | #endif | 1137 | #endif |
1177 | 1138 | ||
1178 | /* Delete object item. */ | 1139 | /* Delete object item. |
1179 | int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the deleted item. */ | 1140 | * th - active transaction handle |
1180 | const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */ | 1141 | * path - path to the deleted item |
1181 | struct inode *p_s_inode, /* inode is here just to update i_blocks and quotas */ | 1142 | * item_key - key to search for the deleted item |
1182 | struct buffer_head *p_s_un_bh) | 1143 | * indode - used for updating i_blocks and quotas |
1183 | { /* NULL or unformatted node pointer. */ | 1144 | * un_bh - NULL or unformatted node pointer |
1184 | struct super_block *p_s_sb = p_s_inode->i_sb; | 1145 | */ |
1146 | int reiserfs_delete_item(struct reiserfs_transaction_handle *th, | ||
1147 | struct treepath *path, const struct cpu_key *item_key, | ||
1148 | struct inode *inode, struct buffer_head *un_bh) | ||
1149 | { | ||
1150 | struct super_block *sb = inode->i_sb; | ||
1185 | struct tree_balance s_del_balance; | 1151 | struct tree_balance s_del_balance; |
1186 | struct item_head s_ih; | 1152 | struct item_head s_ih; |
1187 | struct item_head *q_ih; | 1153 | struct item_head *q_ih; |
1188 | int quota_cut_bytes; | 1154 | int quota_cut_bytes; |
1189 | int n_ret_value, n_del_size, n_removed; | 1155 | int ret_value, del_size, removed; |
1190 | 1156 | ||
1191 | #ifdef CONFIG_REISERFS_CHECK | 1157 | #ifdef CONFIG_REISERFS_CHECK |
1192 | char c_mode; | 1158 | char mode; |
1193 | int n_iter = 0; | 1159 | int iter = 0; |
1194 | #endif | 1160 | #endif |
1195 | 1161 | ||
1196 | BUG_ON(!th->t_trans_id); | 1162 | BUG_ON(!th->t_trans_id); |
1197 | 1163 | ||
1198 | init_tb_struct(th, &s_del_balance, p_s_sb, p_s_path, | 1164 | init_tb_struct(th, &s_del_balance, sb, path, |
1199 | 0 /*size is unknown */ ); | 1165 | 0 /*size is unknown */ ); |
1200 | 1166 | ||
1201 | while (1) { | 1167 | while (1) { |
1202 | n_removed = 0; | 1168 | removed = 0; |
1203 | 1169 | ||
1204 | #ifdef CONFIG_REISERFS_CHECK | 1170 | #ifdef CONFIG_REISERFS_CHECK |
1205 | n_iter++; | 1171 | iter++; |
1206 | c_mode = | 1172 | mode = |
1207 | #endif | 1173 | #endif |
1208 | prepare_for_delete_or_cut(th, p_s_inode, p_s_path, | 1174 | prepare_for_delete_or_cut(th, inode, path, |
1209 | p_s_item_key, &n_removed, | 1175 | item_key, &removed, |
1210 | &n_del_size, | 1176 | &del_size, |
1211 | max_reiserfs_offset(p_s_inode)); | 1177 | max_reiserfs_offset(inode)); |
1212 | 1178 | ||
1213 | RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); | 1179 | RFALSE(mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); |
1214 | 1180 | ||
1215 | copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); | 1181 | copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); |
1216 | s_del_balance.insert_size[0] = n_del_size; | 1182 | s_del_balance.insert_size[0] = del_size; |
1217 | 1183 | ||
1218 | n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); | 1184 | ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); |
1219 | if (n_ret_value != REPEAT_SEARCH) | 1185 | if (ret_value != REPEAT_SEARCH) |
1220 | break; | 1186 | break; |
1221 | 1187 | ||
1222 | PROC_INFO_INC(p_s_sb, delete_item_restarted); | 1188 | PROC_INFO_INC(sb, delete_item_restarted); |
1223 | 1189 | ||
1224 | // file system changed, repeat search | 1190 | // file system changed, repeat search |
1225 | n_ret_value = | 1191 | ret_value = |
1226 | search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); | 1192 | search_for_position_by_key(sb, item_key, path); |
1227 | if (n_ret_value == IO_ERROR) | 1193 | if (ret_value == IO_ERROR) |
1228 | break; | 1194 | break; |
1229 | if (n_ret_value == FILE_NOT_FOUND) { | 1195 | if (ret_value == FILE_NOT_FOUND) { |
1230 | reiserfs_warning(p_s_sb, | 1196 | reiserfs_warning(sb, "vs-5340", |
1231 | "vs-5340: reiserfs_delete_item: " | ||
1232 | "no items of the file %K found", | 1197 | "no items of the file %K found", |
1233 | p_s_item_key); | 1198 | item_key); |
1234 | break; | 1199 | break; |
1235 | } | 1200 | } |
1236 | } /* while (1) */ | 1201 | } /* while (1) */ |
1237 | 1202 | ||
1238 | if (n_ret_value != CARRY_ON) { | 1203 | if (ret_value != CARRY_ON) { |
1239 | unfix_nodes(&s_del_balance); | 1204 | unfix_nodes(&s_del_balance); |
1240 | return 0; | 1205 | return 0; |
1241 | } | 1206 | } |
1242 | // reiserfs_delete_item returns item length when success | 1207 | // reiserfs_delete_item returns item length when success |
1243 | n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); | 1208 | ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); |
1244 | q_ih = get_ih(p_s_path); | 1209 | q_ih = get_ih(path); |
1245 | quota_cut_bytes = ih_item_len(q_ih); | 1210 | quota_cut_bytes = ih_item_len(q_ih); |
1246 | 1211 | ||
1247 | /* hack so the quota code doesn't have to guess if the file | 1212 | /* hack so the quota code doesn't have to guess if the file |
@@ -1250,15 +1215,15 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath | |||
1250 | ** split into multiple items, and we only want to decrement for | 1215 | ** split into multiple items, and we only want to decrement for |
1251 | ** the unfm node once | 1216 | ** the unfm node once |
1252 | */ | 1217 | */ |
1253 | if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(q_ih)) { | 1218 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(q_ih)) { |
1254 | if ((le_ih_k_offset(q_ih) & (p_s_sb->s_blocksize - 1)) == 1) { | 1219 | if ((le_ih_k_offset(q_ih) & (sb->s_blocksize - 1)) == 1) { |
1255 | quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE; | 1220 | quota_cut_bytes = sb->s_blocksize + UNFM_P_SIZE; |
1256 | } else { | 1221 | } else { |
1257 | quota_cut_bytes = 0; | 1222 | quota_cut_bytes = 0; |
1258 | } | 1223 | } |
1259 | } | 1224 | } |
1260 | 1225 | ||
1261 | if (p_s_un_bh) { | 1226 | if (un_bh) { |
1262 | int off; | 1227 | int off; |
1263 | char *data; | 1228 | char *data; |
1264 | 1229 | ||
@@ -1276,31 +1241,31 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath | |||
1276 | ** The unformatted node must be dirtied later on. We can't be | 1241 | ** The unformatted node must be dirtied later on. We can't be |
1277 | ** sure here if the entire tail has been deleted yet. | 1242 | ** sure here if the entire tail has been deleted yet. |
1278 | ** | 1243 | ** |
1279 | ** p_s_un_bh is from the page cache (all unformatted nodes are | 1244 | ** un_bh is from the page cache (all unformatted nodes are |
1280 | ** from the page cache) and might be a highmem page. So, we | 1245 | ** from the page cache) and might be a highmem page. So, we |
1281 | ** can't use p_s_un_bh->b_data. | 1246 | ** can't use un_bh->b_data. |
1282 | ** -clm | 1247 | ** -clm |
1283 | */ | 1248 | */ |
1284 | 1249 | ||
1285 | data = kmap_atomic(p_s_un_bh->b_page, KM_USER0); | 1250 | data = kmap_atomic(un_bh->b_page, KM_USER0); |
1286 | off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1)); | 1251 | off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1)); |
1287 | memcpy(data + off, | 1252 | memcpy(data + off, |
1288 | B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih), | 1253 | B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih), |
1289 | n_ret_value); | 1254 | ret_value); |
1290 | kunmap_atomic(data, KM_USER0); | 1255 | kunmap_atomic(data, KM_USER0); |
1291 | } | 1256 | } |
1292 | /* Perform balancing after all resources have been collected at once. */ | 1257 | /* Perform balancing after all resources have been collected at once. */ |
1293 | do_balance(&s_del_balance, NULL, NULL, M_DELETE); | 1258 | do_balance(&s_del_balance, NULL, NULL, M_DELETE); |
1294 | 1259 | ||
1295 | #ifdef REISERQUOTA_DEBUG | 1260 | #ifdef REISERQUOTA_DEBUG |
1296 | reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, | 1261 | reiserfs_debug(sb, REISERFS_DEBUG_CODE, |
1297 | "reiserquota delete_item(): freeing %u, id=%u type=%c", | 1262 | "reiserquota delete_item(): freeing %u, id=%u type=%c", |
1298 | quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih)); | 1263 | quota_cut_bytes, inode->i_uid, head2type(&s_ih)); |
1299 | #endif | 1264 | #endif |
1300 | vfs_dq_free_space_nodirty(p_s_inode, quota_cut_bytes); | 1265 | vfs_dq_free_space_nodirty(inode, quota_cut_bytes); |
1301 | 1266 | ||
1302 | /* Return deleted body length */ | 1267 | /* Return deleted body length */ |
1303 | return n_ret_value; | 1268 | return ret_value; |
1304 | } | 1269 | } |
1305 | 1270 | ||
1306 | /* Summary Of Mechanisms For Handling Collisions Between Processes: | 1271 | /* Summary Of Mechanisms For Handling Collisions Between Processes: |
@@ -1338,10 +1303,9 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, | |||
1338 | while (1) { | 1303 | while (1) { |
1339 | retval = search_item(th->t_super, &cpu_key, &path); | 1304 | retval = search_item(th->t_super, &cpu_key, &path); |
1340 | if (retval == IO_ERROR) { | 1305 | if (retval == IO_ERROR) { |
1341 | reiserfs_warning(th->t_super, | 1306 | reiserfs_error(th->t_super, "vs-5350", |
1342 | "vs-5350: reiserfs_delete_solid_item: " | 1307 | "i/o failure occurred trying " |
1343 | "i/o failure occurred trying to delete %K", | 1308 | "to delete %K", &cpu_key); |
1344 | &cpu_key); | ||
1345 | break; | 1309 | break; |
1346 | } | 1310 | } |
1347 | if (retval != ITEM_FOUND) { | 1311 | if (retval != ITEM_FOUND) { |
@@ -1355,9 +1319,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, | |||
1355 | GET_GENERATION_NUMBER(le_key_k_offset | 1319 | GET_GENERATION_NUMBER(le_key_k_offset |
1356 | (le_key_version(key), | 1320 | (le_key_version(key), |
1357 | key)) == 1)) | 1321 | key)) == 1)) |
1358 | reiserfs_warning(th->t_super, | 1322 | reiserfs_warning(th->t_super, "vs-5355", |
1359 | "vs-5355: reiserfs_delete_solid_item: %k not found", | 1323 | "%k not found", key); |
1360 | key); | ||
1361 | break; | 1324 | break; |
1362 | } | 1325 | } |
1363 | if (!tb_init) { | 1326 | if (!tb_init) { |
@@ -1389,8 +1352,7 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, | |||
1389 | break; | 1352 | break; |
1390 | } | 1353 | } |
1391 | // IO_ERROR, NO_DISK_SPACE, etc | 1354 | // IO_ERROR, NO_DISK_SPACE, etc |
1392 | reiserfs_warning(th->t_super, | 1355 | reiserfs_warning(th->t_super, "vs-5360", |
1393 | "vs-5360: reiserfs_delete_solid_item: " | ||
1394 | "could not delete %K due to fix_nodes failure", | 1356 | "could not delete %K due to fix_nodes failure", |
1395 | &cpu_key); | 1357 | &cpu_key); |
1396 | unfix_nodes(&tb); | 1358 | unfix_nodes(&tb); |
@@ -1462,36 +1424,37 @@ static void unmap_buffers(struct page *page, loff_t pos) | |||
1462 | } | 1424 | } |
1463 | 1425 | ||
1464 | static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, | 1426 | static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, |
1465 | struct inode *p_s_inode, | 1427 | struct inode *inode, |
1466 | struct page *page, | 1428 | struct page *page, |
1467 | struct treepath *p_s_path, | 1429 | struct treepath *path, |
1468 | const struct cpu_key *p_s_item_key, | 1430 | const struct cpu_key *item_key, |
1469 | loff_t n_new_file_size, char *p_c_mode) | 1431 | loff_t new_file_size, char *mode) |
1470 | { | 1432 | { |
1471 | struct super_block *p_s_sb = p_s_inode->i_sb; | 1433 | struct super_block *sb = inode->i_sb; |
1472 | int n_block_size = p_s_sb->s_blocksize; | 1434 | int block_size = sb->s_blocksize; |
1473 | int cut_bytes; | 1435 | int cut_bytes; |
1474 | BUG_ON(!th->t_trans_id); | 1436 | BUG_ON(!th->t_trans_id); |
1475 | BUG_ON(n_new_file_size != p_s_inode->i_size); | 1437 | BUG_ON(new_file_size != inode->i_size); |
1476 | 1438 | ||
1477 | /* the page being sent in could be NULL if there was an i/o error | 1439 | /* the page being sent in could be NULL if there was an i/o error |
1478 | ** reading in the last block. The user will hit problems trying to | 1440 | ** reading in the last block. The user will hit problems trying to |
1479 | ** read the file, but for now we just skip the indirect2direct | 1441 | ** read the file, but for now we just skip the indirect2direct |
1480 | */ | 1442 | */ |
1481 | if (atomic_read(&p_s_inode->i_count) > 1 || | 1443 | if (atomic_read(&inode->i_count) > 1 || |
1482 | !tail_has_to_be_packed(p_s_inode) || | 1444 | !tail_has_to_be_packed(inode) || |
1483 | !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) { | 1445 | !page || (REISERFS_I(inode)->i_flags & i_nopack_mask)) { |
1484 | // leave tail in an unformatted node | 1446 | /* leave tail in an unformatted node */ |
1485 | *p_c_mode = M_SKIP_BALANCING; | 1447 | *mode = M_SKIP_BALANCING; |
1486 | cut_bytes = | 1448 | cut_bytes = |
1487 | n_block_size - (n_new_file_size & (n_block_size - 1)); | 1449 | block_size - (new_file_size & (block_size - 1)); |
1488 | pathrelse(p_s_path); | 1450 | pathrelse(path); |
1489 | return cut_bytes; | 1451 | return cut_bytes; |
1490 | } | 1452 | } |
1491 | /* Permorm the conversion to a direct_item. */ | 1453 | /* Perform the conversion to a direct_item. */ |
1492 | /*return indirect_to_direct (p_s_inode, p_s_path, p_s_item_key, n_new_file_size, p_c_mode); */ | 1454 | /* return indirect_to_direct(inode, path, item_key, |
1493 | return indirect2direct(th, p_s_inode, page, p_s_path, p_s_item_key, | 1455 | new_file_size, mode); */ |
1494 | n_new_file_size, p_c_mode); | 1456 | return indirect2direct(th, inode, page, path, item_key, |
1457 | new_file_size, mode); | ||
1495 | } | 1458 | } |
1496 | 1459 | ||
1497 | /* we did indirect_to_direct conversion. And we have inserted direct | 1460 | /* we did indirect_to_direct conversion. And we have inserted direct |
@@ -1515,8 +1478,8 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, | |||
1515 | /* look for the last byte of the tail */ | 1478 | /* look for the last byte of the tail */ |
1516 | if (search_for_position_by_key(inode->i_sb, &tail_key, path) == | 1479 | if (search_for_position_by_key(inode->i_sb, &tail_key, path) == |
1517 | POSITION_NOT_FOUND) | 1480 | POSITION_NOT_FOUND) |
1518 | reiserfs_panic(inode->i_sb, | 1481 | reiserfs_panic(inode->i_sb, "vs-5615", |
1519 | "vs-5615: indirect_to_direct_roll_back: found invalid item"); | 1482 | "found invalid item"); |
1520 | RFALSE(path->pos_in_item != | 1483 | RFALSE(path->pos_in_item != |
1521 | ih_item_len(PATH_PITEM_HEAD(path)) - 1, | 1484 | ih_item_len(PATH_PITEM_HEAD(path)) - 1, |
1522 | "vs-5616: appended bytes found"); | 1485 | "vs-5616: appended bytes found"); |
@@ -1533,38 +1496,39 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, | |||
1533 | set_cpu_key_k_offset(&tail_key, | 1496 | set_cpu_key_k_offset(&tail_key, |
1534 | cpu_key_k_offset(&tail_key) - removed); | 1497 | cpu_key_k_offset(&tail_key) - removed); |
1535 | } | 1498 | } |
1536 | reiserfs_warning(inode->i_sb, | 1499 | reiserfs_warning(inode->i_sb, "reiserfs-5091", "indirect_to_direct " |
1537 | "indirect_to_direct_roll_back: indirect_to_direct conversion has been rolled back due to lack of disk space"); | 1500 | "conversion has been rolled back due to " |
1501 | "lack of disk space"); | ||
1538 | //mark_file_without_tail (inode); | 1502 | //mark_file_without_tail (inode); |
1539 | mark_inode_dirty(inode); | 1503 | mark_inode_dirty(inode); |
1540 | } | 1504 | } |
1541 | 1505 | ||
1542 | /* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ | 1506 | /* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ |
1543 | int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | 1507 | int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, |
1544 | struct treepath *p_s_path, | 1508 | struct treepath *path, |
1545 | struct cpu_key *p_s_item_key, | 1509 | struct cpu_key *item_key, |
1546 | struct inode *p_s_inode, | 1510 | struct inode *inode, |
1547 | struct page *page, loff_t n_new_file_size) | 1511 | struct page *page, loff_t new_file_size) |
1548 | { | 1512 | { |
1549 | struct super_block *p_s_sb = p_s_inode->i_sb; | 1513 | struct super_block *sb = inode->i_sb; |
1550 | /* Every function which is going to call do_balance must first | 1514 | /* Every function which is going to call do_balance must first |
1551 | create a tree_balance structure. Then it must fill up this | 1515 | create a tree_balance structure. Then it must fill up this |
1552 | structure by using the init_tb_struct and fix_nodes functions. | 1516 | structure by using the init_tb_struct and fix_nodes functions. |
1553 | After that we can make tree balancing. */ | 1517 | After that we can make tree balancing. */ |
1554 | struct tree_balance s_cut_balance; | 1518 | struct tree_balance s_cut_balance; |
1555 | struct item_head *p_le_ih; | 1519 | struct item_head *p_le_ih; |
1556 | int n_cut_size = 0, /* Amount to be cut. */ | 1520 | int cut_size = 0, /* Amount to be cut. */ |
1557 | n_ret_value = CARRY_ON, n_removed = 0, /* Number of the removed unformatted nodes. */ | 1521 | ret_value = CARRY_ON, removed = 0, /* Number of the removed unformatted nodes. */ |
1558 | n_is_inode_locked = 0; | 1522 | is_inode_locked = 0; |
1559 | char c_mode; /* Mode of the balance. */ | 1523 | char mode; /* Mode of the balance. */ |
1560 | int retval2 = -1; | 1524 | int retval2 = -1; |
1561 | int quota_cut_bytes; | 1525 | int quota_cut_bytes; |
1562 | loff_t tail_pos = 0; | 1526 | loff_t tail_pos = 0; |
1563 | 1527 | ||
1564 | BUG_ON(!th->t_trans_id); | 1528 | BUG_ON(!th->t_trans_id); |
1565 | 1529 | ||
1566 | init_tb_struct(th, &s_cut_balance, p_s_inode->i_sb, p_s_path, | 1530 | init_tb_struct(th, &s_cut_balance, inode->i_sb, path, |
1567 | n_cut_size); | 1531 | cut_size); |
1568 | 1532 | ||
1569 | /* Repeat this loop until we either cut the item without needing | 1533 | /* Repeat this loop until we either cut the item without needing |
1570 | to balance, or we fix_nodes without schedule occurring */ | 1534 | to balance, or we fix_nodes without schedule occurring */ |
@@ -1574,144 +1538,142 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1574 | free unformatted nodes which are pointed to by the cut | 1538 | free unformatted nodes which are pointed to by the cut |
1575 | pointers. */ | 1539 | pointers. */ |
1576 | 1540 | ||
1577 | c_mode = | 1541 | mode = |
1578 | prepare_for_delete_or_cut(th, p_s_inode, p_s_path, | 1542 | prepare_for_delete_or_cut(th, inode, path, |
1579 | p_s_item_key, &n_removed, | 1543 | item_key, &removed, |
1580 | &n_cut_size, n_new_file_size); | 1544 | &cut_size, new_file_size); |
1581 | if (c_mode == M_CONVERT) { | 1545 | if (mode == M_CONVERT) { |
1582 | /* convert last unformatted node to direct item or leave | 1546 | /* convert last unformatted node to direct item or leave |
1583 | tail in the unformatted node */ | 1547 | tail in the unformatted node */ |
1584 | RFALSE(n_ret_value != CARRY_ON, | 1548 | RFALSE(ret_value != CARRY_ON, |
1585 | "PAP-5570: can not convert twice"); | 1549 | "PAP-5570: can not convert twice"); |
1586 | 1550 | ||
1587 | n_ret_value = | 1551 | ret_value = |
1588 | maybe_indirect_to_direct(th, p_s_inode, page, | 1552 | maybe_indirect_to_direct(th, inode, page, |
1589 | p_s_path, p_s_item_key, | 1553 | path, item_key, |
1590 | n_new_file_size, &c_mode); | 1554 | new_file_size, &mode); |
1591 | if (c_mode == M_SKIP_BALANCING) | 1555 | if (mode == M_SKIP_BALANCING) |
1592 | /* tail has been left in the unformatted node */ | 1556 | /* tail has been left in the unformatted node */ |
1593 | return n_ret_value; | 1557 | return ret_value; |
1594 | 1558 | ||
1595 | n_is_inode_locked = 1; | 1559 | is_inode_locked = 1; |
1596 | 1560 | ||
1597 | /* removing of last unformatted node will change value we | 1561 | /* removing of last unformatted node will change value we |
1598 | have to return to truncate. Save it */ | 1562 | have to return to truncate. Save it */ |
1599 | retval2 = n_ret_value; | 1563 | retval2 = ret_value; |
1600 | /*retval2 = p_s_sb->s_blocksize - (n_new_file_size & (p_s_sb->s_blocksize - 1)); */ | 1564 | /*retval2 = sb->s_blocksize - (new_file_size & (sb->s_blocksize - 1)); */ |
1601 | 1565 | ||
1602 | /* So, we have performed the first part of the conversion: | 1566 | /* So, we have performed the first part of the conversion: |
1603 | inserting the new direct item. Now we are removing the | 1567 | inserting the new direct item. Now we are removing the |
1604 | last unformatted node pointer. Set key to search for | 1568 | last unformatted node pointer. Set key to search for |
1605 | it. */ | 1569 | it. */ |
1606 | set_cpu_key_k_type(p_s_item_key, TYPE_INDIRECT); | 1570 | set_cpu_key_k_type(item_key, TYPE_INDIRECT); |
1607 | p_s_item_key->key_length = 4; | 1571 | item_key->key_length = 4; |
1608 | n_new_file_size -= | 1572 | new_file_size -= |
1609 | (n_new_file_size & (p_s_sb->s_blocksize - 1)); | 1573 | (new_file_size & (sb->s_blocksize - 1)); |
1610 | tail_pos = n_new_file_size; | 1574 | tail_pos = new_file_size; |
1611 | set_cpu_key_k_offset(p_s_item_key, n_new_file_size + 1); | 1575 | set_cpu_key_k_offset(item_key, new_file_size + 1); |
1612 | if (search_for_position_by_key | 1576 | if (search_for_position_by_key |
1613 | (p_s_sb, p_s_item_key, | 1577 | (sb, item_key, |
1614 | p_s_path) == POSITION_NOT_FOUND) { | 1578 | path) == POSITION_NOT_FOUND) { |
1615 | print_block(PATH_PLAST_BUFFER(p_s_path), 3, | 1579 | print_block(PATH_PLAST_BUFFER(path), 3, |
1616 | PATH_LAST_POSITION(p_s_path) - 1, | 1580 | PATH_LAST_POSITION(path) - 1, |
1617 | PATH_LAST_POSITION(p_s_path) + 1); | 1581 | PATH_LAST_POSITION(path) + 1); |
1618 | reiserfs_panic(p_s_sb, | 1582 | reiserfs_panic(sb, "PAP-5580", "item to " |
1619 | "PAP-5580: reiserfs_cut_from_item: item to convert does not exist (%K)", | 1583 | "convert does not exist (%K)", |
1620 | p_s_item_key); | 1584 | item_key); |
1621 | } | 1585 | } |
1622 | continue; | 1586 | continue; |
1623 | } | 1587 | } |
1624 | if (n_cut_size == 0) { | 1588 | if (cut_size == 0) { |
1625 | pathrelse(p_s_path); | 1589 | pathrelse(path); |
1626 | return 0; | 1590 | return 0; |
1627 | } | 1591 | } |
1628 | 1592 | ||
1629 | s_cut_balance.insert_size[0] = n_cut_size; | 1593 | s_cut_balance.insert_size[0] = cut_size; |
1630 | 1594 | ||
1631 | n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL); | 1595 | ret_value = fix_nodes(mode, &s_cut_balance, NULL, NULL); |
1632 | if (n_ret_value != REPEAT_SEARCH) | 1596 | if (ret_value != REPEAT_SEARCH) |
1633 | break; | 1597 | break; |
1634 | 1598 | ||
1635 | PROC_INFO_INC(p_s_sb, cut_from_item_restarted); | 1599 | PROC_INFO_INC(sb, cut_from_item_restarted); |
1636 | 1600 | ||
1637 | n_ret_value = | 1601 | ret_value = |
1638 | search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); | 1602 | search_for_position_by_key(sb, item_key, path); |
1639 | if (n_ret_value == POSITION_FOUND) | 1603 | if (ret_value == POSITION_FOUND) |
1640 | continue; | 1604 | continue; |
1641 | 1605 | ||
1642 | reiserfs_warning(p_s_sb, | 1606 | reiserfs_warning(sb, "PAP-5610", "item %K not found", |
1643 | "PAP-5610: reiserfs_cut_from_item: item %K not found", | 1607 | item_key); |
1644 | p_s_item_key); | ||
1645 | unfix_nodes(&s_cut_balance); | 1608 | unfix_nodes(&s_cut_balance); |
1646 | return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; | 1609 | return (ret_value == IO_ERROR) ? -EIO : -ENOENT; |
1647 | } /* while */ | 1610 | } /* while */ |
1648 | 1611 | ||
1649 | // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) | 1612 | // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) |
1650 | if (n_ret_value != CARRY_ON) { | 1613 | if (ret_value != CARRY_ON) { |
1651 | if (n_is_inode_locked) { | 1614 | if (is_inode_locked) { |
1652 | // FIXME: this seems to be not needed: we are always able | 1615 | // FIXME: this seems to be not needed: we are always able |
1653 | // to cut item | 1616 | // to cut item |
1654 | indirect_to_direct_roll_back(th, p_s_inode, p_s_path); | 1617 | indirect_to_direct_roll_back(th, inode, path); |
1655 | } | 1618 | } |
1656 | if (n_ret_value == NO_DISK_SPACE) | 1619 | if (ret_value == NO_DISK_SPACE) |
1657 | reiserfs_warning(p_s_sb, "NO_DISK_SPACE"); | 1620 | reiserfs_warning(sb, "reiserfs-5092", |
1621 | "NO_DISK_SPACE"); | ||
1658 | unfix_nodes(&s_cut_balance); | 1622 | unfix_nodes(&s_cut_balance); |
1659 | return -EIO; | 1623 | return -EIO; |
1660 | } | 1624 | } |
1661 | 1625 | ||
1662 | /* go ahead and perform balancing */ | 1626 | /* go ahead and perform balancing */ |
1663 | 1627 | ||
1664 | RFALSE(c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode"); | 1628 | RFALSE(mode == M_PASTE || mode == M_INSERT, "invalid mode"); |
1665 | 1629 | ||
1666 | /* Calculate number of bytes that need to be cut from the item. */ | 1630 | /* Calculate number of bytes that need to be cut from the item. */ |
1667 | quota_cut_bytes = | 1631 | quota_cut_bytes = |
1668 | (c_mode == | 1632 | (mode == |
1669 | M_DELETE) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance. | 1633 | M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance. |
1670 | insert_size[0]; | 1634 | insert_size[0]; |
1671 | if (retval2 == -1) | 1635 | if (retval2 == -1) |
1672 | n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); | 1636 | ret_value = calc_deleted_bytes_number(&s_cut_balance, mode); |
1673 | else | 1637 | else |
1674 | n_ret_value = retval2; | 1638 | ret_value = retval2; |
1675 | 1639 | ||
1676 | /* For direct items, we only change the quota when deleting the last | 1640 | /* For direct items, we only change the quota when deleting the last |
1677 | ** item. | 1641 | ** item. |
1678 | */ | 1642 | */ |
1679 | p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path); | 1643 | p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path); |
1680 | if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(p_le_ih)) { | 1644 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) { |
1681 | if (c_mode == M_DELETE && | 1645 | if (mode == M_DELETE && |
1682 | (le_ih_k_offset(p_le_ih) & (p_s_sb->s_blocksize - 1)) == | 1646 | (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) == |
1683 | 1) { | 1647 | 1) { |
1684 | // FIXME: this is to keep 3.5 happy | 1648 | // FIXME: this is to keep 3.5 happy |
1685 | REISERFS_I(p_s_inode)->i_first_direct_byte = U32_MAX; | 1649 | REISERFS_I(inode)->i_first_direct_byte = U32_MAX; |
1686 | quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE; | 1650 | quota_cut_bytes = sb->s_blocksize + UNFM_P_SIZE; |
1687 | } else { | 1651 | } else { |
1688 | quota_cut_bytes = 0; | 1652 | quota_cut_bytes = 0; |
1689 | } | 1653 | } |
1690 | } | 1654 | } |
1691 | #ifdef CONFIG_REISERFS_CHECK | 1655 | #ifdef CONFIG_REISERFS_CHECK |
1692 | if (n_is_inode_locked) { | 1656 | if (is_inode_locked) { |
1693 | struct item_head *le_ih = | 1657 | struct item_head *le_ih = |
1694 | PATH_PITEM_HEAD(s_cut_balance.tb_path); | 1658 | PATH_PITEM_HEAD(s_cut_balance.tb_path); |
1695 | /* we are going to complete indirect2direct conversion. Make | 1659 | /* we are going to complete indirect2direct conversion. Make |
1696 | sure, that we exactly remove last unformatted node pointer | 1660 | sure, that we exactly remove last unformatted node pointer |
1697 | of the item */ | 1661 | of the item */ |
1698 | if (!is_indirect_le_ih(le_ih)) | 1662 | if (!is_indirect_le_ih(le_ih)) |
1699 | reiserfs_panic(p_s_sb, | 1663 | reiserfs_panic(sb, "vs-5652", |
1700 | "vs-5652: reiserfs_cut_from_item: " | ||
1701 | "item must be indirect %h", le_ih); | 1664 | "item must be indirect %h", le_ih); |
1702 | 1665 | ||
1703 | if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) | 1666 | if (mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) |
1704 | reiserfs_panic(p_s_sb, | 1667 | reiserfs_panic(sb, "vs-5653", "completing " |
1705 | "vs-5653: reiserfs_cut_from_item: " | 1668 | "indirect2direct conversion indirect " |
1706 | "completing indirect2direct conversion indirect item %h " | 1669 | "item %h being deleted must be of " |
1707 | "being deleted must be of 4 byte long", | 1670 | "4 byte long", le_ih); |
1708 | le_ih); | ||
1709 | 1671 | ||
1710 | if (c_mode == M_CUT | 1672 | if (mode == M_CUT |
1711 | && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { | 1673 | && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { |
1712 | reiserfs_panic(p_s_sb, | 1674 | reiserfs_panic(sb, "vs-5654", "can not complete " |
1713 | "vs-5654: reiserfs_cut_from_item: " | 1675 | "indirect2direct conversion of %h " |
1714 | "can not complete indirect2direct conversion of %h (CUT, insert_size==%d)", | 1676 | "(CUT, insert_size==%d)", |
1715 | le_ih, s_cut_balance.insert_size[0]); | 1677 | le_ih, s_cut_balance.insert_size[0]); |
1716 | } | 1678 | } |
1717 | /* it would be useful to make sure, that right neighboring | 1679 | /* it would be useful to make sure, that right neighboring |
@@ -1719,23 +1681,23 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1719 | } | 1681 | } |
1720 | #endif | 1682 | #endif |
1721 | 1683 | ||
1722 | do_balance(&s_cut_balance, NULL, NULL, c_mode); | 1684 | do_balance(&s_cut_balance, NULL, NULL, mode); |
1723 | if (n_is_inode_locked) { | 1685 | if (is_inode_locked) { |
1724 | /* we've done an indirect->direct conversion. when the data block | 1686 | /* we've done an indirect->direct conversion. when the data block |
1725 | ** was freed, it was removed from the list of blocks that must | 1687 | ** was freed, it was removed from the list of blocks that must |
1726 | ** be flushed before the transaction commits, make sure to | 1688 | ** be flushed before the transaction commits, make sure to |
1727 | ** unmap and invalidate it | 1689 | ** unmap and invalidate it |
1728 | */ | 1690 | */ |
1729 | unmap_buffers(page, tail_pos); | 1691 | unmap_buffers(page, tail_pos); |
1730 | REISERFS_I(p_s_inode)->i_flags &= ~i_pack_on_close_mask; | 1692 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; |
1731 | } | 1693 | } |
1732 | #ifdef REISERQUOTA_DEBUG | 1694 | #ifdef REISERQUOTA_DEBUG |
1733 | reiserfs_debug(p_s_inode->i_sb, REISERFS_DEBUG_CODE, | 1695 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, |
1734 | "reiserquota cut_from_item(): freeing %u id=%u type=%c", | 1696 | "reiserquota cut_from_item(): freeing %u id=%u type=%c", |
1735 | quota_cut_bytes, p_s_inode->i_uid, '?'); | 1697 | quota_cut_bytes, inode->i_uid, '?'); |
1736 | #endif | 1698 | #endif |
1737 | vfs_dq_free_space_nodirty(p_s_inode, quota_cut_bytes); | 1699 | vfs_dq_free_space_nodirty(inode, quota_cut_bytes); |
1738 | return n_ret_value; | 1700 | return ret_value; |
1739 | } | 1701 | } |
1740 | 1702 | ||
1741 | static void truncate_directory(struct reiserfs_transaction_handle *th, | 1703 | static void truncate_directory(struct reiserfs_transaction_handle *th, |
@@ -1743,8 +1705,7 @@ static void truncate_directory(struct reiserfs_transaction_handle *th, | |||
1743 | { | 1705 | { |
1744 | BUG_ON(!th->t_trans_id); | 1706 | BUG_ON(!th->t_trans_id); |
1745 | if (inode->i_nlink) | 1707 | if (inode->i_nlink) |
1746 | reiserfs_warning(inode->i_sb, | 1708 | reiserfs_error(inode->i_sb, "vs-5655", "link count != 0"); |
1747 | "vs-5655: truncate_directory: link count != 0"); | ||
1748 | 1709 | ||
1749 | set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), DOT_OFFSET); | 1710 | set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), DOT_OFFSET); |
1750 | set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_DIRENTRY); | 1711 | set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_DIRENTRY); |
@@ -1756,8 +1717,8 @@ static void truncate_directory(struct reiserfs_transaction_handle *th, | |||
1756 | 1717 | ||
1757 | /* Truncate file to the new size. Note, this must be called with a transaction | 1718 | /* Truncate file to the new size. Note, this must be called with a transaction |
1758 | already started */ | 1719 | already started */ |
1759 | int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, /* ->i_size contains new | 1720 | int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, |
1760 | size */ | 1721 | struct inode *inode, /* ->i_size contains new size */ |
1761 | struct page *page, /* up to date for last block */ | 1722 | struct page *page, /* up to date for last block */ |
1762 | int update_timestamps /* when it is called by | 1723 | int update_timestamps /* when it is called by |
1763 | file_release to convert | 1724 | file_release to convert |
@@ -1768,47 +1729,45 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p | |||
1768 | INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ | 1729 | INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ |
1769 | struct item_head *p_le_ih; /* Pointer to an item header. */ | 1730 | struct item_head *p_le_ih; /* Pointer to an item header. */ |
1770 | struct cpu_key s_item_key; /* Key to search for a previous file item. */ | 1731 | struct cpu_key s_item_key; /* Key to search for a previous file item. */ |
1771 | loff_t n_file_size, /* Old file size. */ | 1732 | loff_t file_size, /* Old file size. */ |
1772 | n_new_file_size; /* New file size. */ | 1733 | new_file_size; /* New file size. */ |
1773 | int n_deleted; /* Number of deleted or truncated bytes. */ | 1734 | int deleted; /* Number of deleted or truncated bytes. */ |
1774 | int retval; | 1735 | int retval; |
1775 | int err = 0; | 1736 | int err = 0; |
1776 | 1737 | ||
1777 | BUG_ON(!th->t_trans_id); | 1738 | BUG_ON(!th->t_trans_id); |
1778 | if (! | 1739 | if (! |
1779 | (S_ISREG(p_s_inode->i_mode) || S_ISDIR(p_s_inode->i_mode) | 1740 | (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) |
1780 | || S_ISLNK(p_s_inode->i_mode))) | 1741 | || S_ISLNK(inode->i_mode))) |
1781 | return 0; | 1742 | return 0; |
1782 | 1743 | ||
1783 | if (S_ISDIR(p_s_inode->i_mode)) { | 1744 | if (S_ISDIR(inode->i_mode)) { |
1784 | // deletion of directory - no need to update timestamps | 1745 | // deletion of directory - no need to update timestamps |
1785 | truncate_directory(th, p_s_inode); | 1746 | truncate_directory(th, inode); |
1786 | return 0; | 1747 | return 0; |
1787 | } | 1748 | } |
1788 | 1749 | ||
1789 | /* Get new file size. */ | 1750 | /* Get new file size. */ |
1790 | n_new_file_size = p_s_inode->i_size; | 1751 | new_file_size = inode->i_size; |
1791 | 1752 | ||
1792 | // FIXME: note, that key type is unimportant here | 1753 | // FIXME: note, that key type is unimportant here |
1793 | make_cpu_key(&s_item_key, p_s_inode, max_reiserfs_offset(p_s_inode), | 1754 | make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode), |
1794 | TYPE_DIRECT, 3); | 1755 | TYPE_DIRECT, 3); |
1795 | 1756 | ||
1796 | retval = | 1757 | retval = |
1797 | search_for_position_by_key(p_s_inode->i_sb, &s_item_key, | 1758 | search_for_position_by_key(inode->i_sb, &s_item_key, |
1798 | &s_search_path); | 1759 | &s_search_path); |
1799 | if (retval == IO_ERROR) { | 1760 | if (retval == IO_ERROR) { |
1800 | reiserfs_warning(p_s_inode->i_sb, | 1761 | reiserfs_error(inode->i_sb, "vs-5657", |
1801 | "vs-5657: reiserfs_do_truncate: " | 1762 | "i/o failure occurred trying to truncate %K", |
1802 | "i/o failure occurred trying to truncate %K", | 1763 | &s_item_key); |
1803 | &s_item_key); | ||
1804 | err = -EIO; | 1764 | err = -EIO; |
1805 | goto out; | 1765 | goto out; |
1806 | } | 1766 | } |
1807 | if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) { | 1767 | if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) { |
1808 | reiserfs_warning(p_s_inode->i_sb, | 1768 | reiserfs_error(inode->i_sb, "PAP-5660", |
1809 | "PAP-5660: reiserfs_do_truncate: " | 1769 | "wrong result %d of search for %K", retval, |
1810 | "wrong result %d of search for %K", retval, | 1770 | &s_item_key); |
1811 | &s_item_key); | ||
1812 | 1771 | ||
1813 | err = -EIO; | 1772 | err = -EIO; |
1814 | goto out; | 1773 | goto out; |
@@ -1819,56 +1778,56 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p | |||
1819 | /* Get real file size (total length of all file items) */ | 1778 | /* Get real file size (total length of all file items) */ |
1820 | p_le_ih = PATH_PITEM_HEAD(&s_search_path); | 1779 | p_le_ih = PATH_PITEM_HEAD(&s_search_path); |
1821 | if (is_statdata_le_ih(p_le_ih)) | 1780 | if (is_statdata_le_ih(p_le_ih)) |
1822 | n_file_size = 0; | 1781 | file_size = 0; |
1823 | else { | 1782 | else { |
1824 | loff_t offset = le_ih_k_offset(p_le_ih); | 1783 | loff_t offset = le_ih_k_offset(p_le_ih); |
1825 | int bytes = | 1784 | int bytes = |
1826 | op_bytes_number(p_le_ih, p_s_inode->i_sb->s_blocksize); | 1785 | op_bytes_number(p_le_ih, inode->i_sb->s_blocksize); |
1827 | 1786 | ||
1828 | /* this may mismatch with real file size: if last direct item | 1787 | /* this may mismatch with real file size: if last direct item |
1829 | had no padding zeros and last unformatted node had no free | 1788 | had no padding zeros and last unformatted node had no free |
1830 | space, this file would have this file size */ | 1789 | space, this file would have this file size */ |
1831 | n_file_size = offset + bytes - 1; | 1790 | file_size = offset + bytes - 1; |
1832 | } | 1791 | } |
1833 | /* | 1792 | /* |
1834 | * are we doing a full truncate or delete, if so | 1793 | * are we doing a full truncate or delete, if so |
1835 | * kick in the reada code | 1794 | * kick in the reada code |
1836 | */ | 1795 | */ |
1837 | if (n_new_file_size == 0) | 1796 | if (new_file_size == 0) |
1838 | s_search_path.reada = PATH_READA | PATH_READA_BACK; | 1797 | s_search_path.reada = PATH_READA | PATH_READA_BACK; |
1839 | 1798 | ||
1840 | if (n_file_size == 0 || n_file_size < n_new_file_size) { | 1799 | if (file_size == 0 || file_size < new_file_size) { |
1841 | goto update_and_out; | 1800 | goto update_and_out; |
1842 | } | 1801 | } |
1843 | 1802 | ||
1844 | /* Update key to search for the last file item. */ | 1803 | /* Update key to search for the last file item. */ |
1845 | set_cpu_key_k_offset(&s_item_key, n_file_size); | 1804 | set_cpu_key_k_offset(&s_item_key, file_size); |
1846 | 1805 | ||
1847 | do { | 1806 | do { |
1848 | /* Cut or delete file item. */ | 1807 | /* Cut or delete file item. */ |
1849 | n_deleted = | 1808 | deleted = |
1850 | reiserfs_cut_from_item(th, &s_search_path, &s_item_key, | 1809 | reiserfs_cut_from_item(th, &s_search_path, &s_item_key, |
1851 | p_s_inode, page, n_new_file_size); | 1810 | inode, page, new_file_size); |
1852 | if (n_deleted < 0) { | 1811 | if (deleted < 0) { |
1853 | reiserfs_warning(p_s_inode->i_sb, | 1812 | reiserfs_warning(inode->i_sb, "vs-5665", |
1854 | "vs-5665: reiserfs_do_truncate: reiserfs_cut_from_item failed"); | 1813 | "reiserfs_cut_from_item failed"); |
1855 | reiserfs_check_path(&s_search_path); | 1814 | reiserfs_check_path(&s_search_path); |
1856 | return 0; | 1815 | return 0; |
1857 | } | 1816 | } |
1858 | 1817 | ||
1859 | RFALSE(n_deleted > n_file_size, | 1818 | RFALSE(deleted > file_size, |
1860 | "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", | 1819 | "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", |
1861 | n_deleted, n_file_size, &s_item_key); | 1820 | deleted, file_size, &s_item_key); |
1862 | 1821 | ||
1863 | /* Change key to search the last file item. */ | 1822 | /* Change key to search the last file item. */ |
1864 | n_file_size -= n_deleted; | 1823 | file_size -= deleted; |
1865 | 1824 | ||
1866 | set_cpu_key_k_offset(&s_item_key, n_file_size); | 1825 | set_cpu_key_k_offset(&s_item_key, file_size); |
1867 | 1826 | ||
1868 | /* While there are bytes to truncate and previous file item is presented in the tree. */ | 1827 | /* While there are bytes to truncate and previous file item is presented in the tree. */ |
1869 | 1828 | ||
1870 | /* | 1829 | /* |
1871 | ** This loop could take a really long time, and could log | 1830 | ** This loop could take a really long time, and could log |
1872 | ** many more blocks than a transaction can hold. So, we do a polite | 1831 | ** many more blocks than a transaction can hold. So, we do a polite |
1873 | ** journal end here, and if the transaction needs ending, we make | 1832 | ** journal end here, and if the transaction needs ending, we make |
1874 | ** sure the file is consistent before ending the current trans | 1833 | ** sure the file is consistent before ending the current trans |
@@ -1877,37 +1836,38 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p | |||
1877 | if (journal_transaction_should_end(th, 0) || | 1836 | if (journal_transaction_should_end(th, 0) || |
1878 | reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { | 1837 | reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { |
1879 | int orig_len_alloc = th->t_blocks_allocated; | 1838 | int orig_len_alloc = th->t_blocks_allocated; |
1880 | decrement_counters_in_path(&s_search_path); | 1839 | pathrelse(&s_search_path); |
1881 | 1840 | ||
1882 | if (update_timestamps) { | 1841 | if (update_timestamps) { |
1883 | p_s_inode->i_mtime = p_s_inode->i_ctime = | 1842 | inode->i_mtime = CURRENT_TIME_SEC; |
1884 | CURRENT_TIME_SEC; | 1843 | inode->i_ctime = CURRENT_TIME_SEC; |
1885 | } | 1844 | } |
1886 | reiserfs_update_sd(th, p_s_inode); | 1845 | reiserfs_update_sd(th, inode); |
1887 | 1846 | ||
1888 | err = journal_end(th, p_s_inode->i_sb, orig_len_alloc); | 1847 | err = journal_end(th, inode->i_sb, orig_len_alloc); |
1889 | if (err) | 1848 | if (err) |
1890 | goto out; | 1849 | goto out; |
1891 | err = journal_begin(th, p_s_inode->i_sb, | 1850 | err = journal_begin(th, inode->i_sb, |
1892 | JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD + JOURNAL_PER_BALANCE_CNT * 4) ; | 1851 | JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD + JOURNAL_PER_BALANCE_CNT * 4) ; |
1893 | if (err) | 1852 | if (err) |
1894 | goto out; | 1853 | goto out; |
1895 | reiserfs_update_inode_transaction(p_s_inode); | 1854 | reiserfs_update_inode_transaction(inode); |
1896 | } | 1855 | } |
1897 | } while (n_file_size > ROUND_UP(n_new_file_size) && | 1856 | } while (file_size > ROUND_UP(new_file_size) && |
1898 | search_for_position_by_key(p_s_inode->i_sb, &s_item_key, | 1857 | search_for_position_by_key(inode->i_sb, &s_item_key, |
1899 | &s_search_path) == POSITION_FOUND); | 1858 | &s_search_path) == POSITION_FOUND); |
1900 | 1859 | ||
1901 | RFALSE(n_file_size > ROUND_UP(n_new_file_size), | 1860 | RFALSE(file_size > ROUND_UP(new_file_size), |
1902 | "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d", | 1861 | "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d", |
1903 | n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid); | 1862 | new_file_size, file_size, s_item_key.on_disk_key.k_objectid); |
1904 | 1863 | ||
1905 | update_and_out: | 1864 | update_and_out: |
1906 | if (update_timestamps) { | 1865 | if (update_timestamps) { |
1907 | // this is truncate, not file closing | 1866 | // this is truncate, not file closing |
1908 | p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC; | 1867 | inode->i_mtime = CURRENT_TIME_SEC; |
1868 | inode->i_ctime = CURRENT_TIME_SEC; | ||
1909 | } | 1869 | } |
1910 | reiserfs_update_sd(th, p_s_inode); | 1870 | reiserfs_update_sd(th, inode); |
1911 | 1871 | ||
1912 | out: | 1872 | out: |
1913 | pathrelse(&s_search_path); | 1873 | pathrelse(&s_search_path); |
@@ -1917,7 +1877,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p | |||
1917 | #ifdef CONFIG_REISERFS_CHECK | 1877 | #ifdef CONFIG_REISERFS_CHECK |
1918 | // this makes sure, that we __append__, not overwrite or add holes | 1878 | // this makes sure, that we __append__, not overwrite or add holes |
1919 | static void check_research_for_paste(struct treepath *path, | 1879 | static void check_research_for_paste(struct treepath *path, |
1920 | const struct cpu_key *p_s_key) | 1880 | const struct cpu_key *key) |
1921 | { | 1881 | { |
1922 | struct item_head *found_ih = get_ih(path); | 1882 | struct item_head *found_ih = get_ih(path); |
1923 | 1883 | ||
@@ -1925,36 +1885,36 @@ static void check_research_for_paste(struct treepath *path, | |||
1925 | if (le_ih_k_offset(found_ih) + | 1885 | if (le_ih_k_offset(found_ih) + |
1926 | op_bytes_number(found_ih, | 1886 | op_bytes_number(found_ih, |
1927 | get_last_bh(path)->b_size) != | 1887 | get_last_bh(path)->b_size) != |
1928 | cpu_key_k_offset(p_s_key) | 1888 | cpu_key_k_offset(key) |
1929 | || op_bytes_number(found_ih, | 1889 | || op_bytes_number(found_ih, |
1930 | get_last_bh(path)->b_size) != | 1890 | get_last_bh(path)->b_size) != |
1931 | pos_in_item(path)) | 1891 | pos_in_item(path)) |
1932 | reiserfs_panic(NULL, | 1892 | reiserfs_panic(NULL, "PAP-5720", "found direct item " |
1933 | "PAP-5720: check_research_for_paste: " | 1893 | "%h or position (%d) does not match " |
1934 | "found direct item %h or position (%d) does not match to key %K", | 1894 | "to key %K", found_ih, |
1935 | found_ih, pos_in_item(path), p_s_key); | 1895 | pos_in_item(path), key); |
1936 | } | 1896 | } |
1937 | if (is_indirect_le_ih(found_ih)) { | 1897 | if (is_indirect_le_ih(found_ih)) { |
1938 | if (le_ih_k_offset(found_ih) + | 1898 | if (le_ih_k_offset(found_ih) + |
1939 | op_bytes_number(found_ih, | 1899 | op_bytes_number(found_ih, |
1940 | get_last_bh(path)->b_size) != | 1900 | get_last_bh(path)->b_size) != |
1941 | cpu_key_k_offset(p_s_key) | 1901 | cpu_key_k_offset(key) |
1942 | || I_UNFM_NUM(found_ih) != pos_in_item(path) | 1902 | || I_UNFM_NUM(found_ih) != pos_in_item(path) |
1943 | || get_ih_free_space(found_ih) != 0) | 1903 | || get_ih_free_space(found_ih) != 0) |
1944 | reiserfs_panic(NULL, | 1904 | reiserfs_panic(NULL, "PAP-5730", "found indirect " |
1945 | "PAP-5730: check_research_for_paste: " | 1905 | "item (%h) or position (%d) does not " |
1946 | "found indirect item (%h) or position (%d) does not match to key (%K)", | 1906 | "match to key (%K)", |
1947 | found_ih, pos_in_item(path), p_s_key); | 1907 | found_ih, pos_in_item(path), key); |
1948 | } | 1908 | } |
1949 | } | 1909 | } |
1950 | #endif /* config reiserfs check */ | 1910 | #endif /* config reiserfs check */ |
1951 | 1911 | ||
1952 | /* Paste bytes to the existing item. Returns bytes number pasted into the item. */ | 1912 | /* Paste bytes to the existing item. Returns bytes number pasted into the item. */ |
1953 | int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_search_path, /* Path to the pasted item. */ | 1913 | int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *search_path, /* Path to the pasted item. */ |
1954 | const struct cpu_key *p_s_key, /* Key to search for the needed item. */ | 1914 | const struct cpu_key *key, /* Key to search for the needed item. */ |
1955 | struct inode *inode, /* Inode item belongs to */ | 1915 | struct inode *inode, /* Inode item belongs to */ |
1956 | const char *p_c_body, /* Pointer to the bytes to paste. */ | 1916 | const char *body, /* Pointer to the bytes to paste. */ |
1957 | int n_pasted_size) | 1917 | int pasted_size) |
1958 | { /* Size of pasted bytes. */ | 1918 | { /* Size of pasted bytes. */ |
1959 | struct tree_balance s_paste_balance; | 1919 | struct tree_balance s_paste_balance; |
1960 | int retval; | 1920 | int retval; |
@@ -1967,18 +1927,18 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree | |||
1967 | #ifdef REISERQUOTA_DEBUG | 1927 | #ifdef REISERQUOTA_DEBUG |
1968 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, | 1928 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, |
1969 | "reiserquota paste_into_item(): allocating %u id=%u type=%c", | 1929 | "reiserquota paste_into_item(): allocating %u id=%u type=%c", |
1970 | n_pasted_size, inode->i_uid, | 1930 | pasted_size, inode->i_uid, |
1971 | key2type(&(p_s_key->on_disk_key))); | 1931 | key2type(&(key->on_disk_key))); |
1972 | #endif | 1932 | #endif |
1973 | 1933 | ||
1974 | if (vfs_dq_alloc_space_nodirty(inode, n_pasted_size)) { | 1934 | if (vfs_dq_alloc_space_nodirty(inode, pasted_size)) { |
1975 | pathrelse(p_s_search_path); | 1935 | pathrelse(search_path); |
1976 | return -EDQUOT; | 1936 | return -EDQUOT; |
1977 | } | 1937 | } |
1978 | init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path, | 1938 | init_tb_struct(th, &s_paste_balance, th->t_super, search_path, |
1979 | n_pasted_size); | 1939 | pasted_size); |
1980 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 1940 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
1981 | s_paste_balance.key = p_s_key->on_disk_key; | 1941 | s_paste_balance.key = key->on_disk_key; |
1982 | #endif | 1942 | #endif |
1983 | 1943 | ||
1984 | /* DQUOT_* can schedule, must check before the fix_nodes */ | 1944 | /* DQUOT_* can schedule, must check before the fix_nodes */ |
@@ -1988,33 +1948,33 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree | |||
1988 | 1948 | ||
1989 | while ((retval = | 1949 | while ((retval = |
1990 | fix_nodes(M_PASTE, &s_paste_balance, NULL, | 1950 | fix_nodes(M_PASTE, &s_paste_balance, NULL, |
1991 | p_c_body)) == REPEAT_SEARCH) { | 1951 | body)) == REPEAT_SEARCH) { |
1992 | search_again: | 1952 | search_again: |
1993 | /* file system changed while we were in the fix_nodes */ | 1953 | /* file system changed while we were in the fix_nodes */ |
1994 | PROC_INFO_INC(th->t_super, paste_into_item_restarted); | 1954 | PROC_INFO_INC(th->t_super, paste_into_item_restarted); |
1995 | retval = | 1955 | retval = |
1996 | search_for_position_by_key(th->t_super, p_s_key, | 1956 | search_for_position_by_key(th->t_super, key, |
1997 | p_s_search_path); | 1957 | search_path); |
1998 | if (retval == IO_ERROR) { | 1958 | if (retval == IO_ERROR) { |
1999 | retval = -EIO; | 1959 | retval = -EIO; |
2000 | goto error_out; | 1960 | goto error_out; |
2001 | } | 1961 | } |
2002 | if (retval == POSITION_FOUND) { | 1962 | if (retval == POSITION_FOUND) { |
2003 | reiserfs_warning(inode->i_sb, | 1963 | reiserfs_warning(inode->i_sb, "PAP-5710", |
2004 | "PAP-5710: reiserfs_paste_into_item: entry or pasted byte (%K) exists", | 1964 | "entry or pasted byte (%K) exists", |
2005 | p_s_key); | 1965 | key); |
2006 | retval = -EEXIST; | 1966 | retval = -EEXIST; |
2007 | goto error_out; | 1967 | goto error_out; |
2008 | } | 1968 | } |
2009 | #ifdef CONFIG_REISERFS_CHECK | 1969 | #ifdef CONFIG_REISERFS_CHECK |
2010 | check_research_for_paste(p_s_search_path, p_s_key); | 1970 | check_research_for_paste(search_path, key); |
2011 | #endif | 1971 | #endif |
2012 | } | 1972 | } |
2013 | 1973 | ||
2014 | /* Perform balancing after all resources are collected by fix_nodes, and | 1974 | /* Perform balancing after all resources are collected by fix_nodes, and |
2015 | accessing them will not risk triggering schedule. */ | 1975 | accessing them will not risk triggering schedule. */ |
2016 | if (retval == CARRY_ON) { | 1976 | if (retval == CARRY_ON) { |
2017 | do_balance(&s_paste_balance, NULL /*ih */ , p_c_body, M_PASTE); | 1977 | do_balance(&s_paste_balance, NULL /*ih */ , body, M_PASTE); |
2018 | return 0; | 1978 | return 0; |
2019 | } | 1979 | } |
2020 | retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; | 1980 | retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; |
@@ -2024,18 +1984,24 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree | |||
2024 | #ifdef REISERQUOTA_DEBUG | 1984 | #ifdef REISERQUOTA_DEBUG |
2025 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, | 1985 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, |
2026 | "reiserquota paste_into_item(): freeing %u id=%u type=%c", | 1986 | "reiserquota paste_into_item(): freeing %u id=%u type=%c", |
2027 | n_pasted_size, inode->i_uid, | 1987 | pasted_size, inode->i_uid, |
2028 | key2type(&(p_s_key->on_disk_key))); | 1988 | key2type(&(key->on_disk_key))); |
2029 | #endif | 1989 | #endif |
2030 | vfs_dq_free_space_nodirty(inode, n_pasted_size); | 1990 | vfs_dq_free_space_nodirty(inode, pasted_size); |
2031 | return retval; | 1991 | return retval; |
2032 | } | 1992 | } |
2033 | 1993 | ||
2034 | /* Insert new item into the buffer at the path. */ | 1994 | /* Insert new item into the buffer at the path. |
2035 | int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the inserteded item. */ | 1995 | * th - active transaction handle |
2036 | const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */ | 1996 | * path - path to the inserted item |
2037 | struct inode *inode, const char *p_c_body) | 1997 | * ih - pointer to the item header to insert |
2038 | { /* Pointer to the bytes to insert. */ | 1998 | * body - pointer to the bytes to insert |
1999 | */ | ||
2000 | int reiserfs_insert_item(struct reiserfs_transaction_handle *th, | ||
2001 | struct treepath *path, const struct cpu_key *key, | ||
2002 | struct item_head *ih, struct inode *inode, | ||
2003 | const char *body) | ||
2004 | { | ||
2039 | struct tree_balance s_ins_balance; | 2005 | struct tree_balance s_ins_balance; |
2040 | int retval; | 2006 | int retval; |
2041 | int fs_gen = 0; | 2007 | int fs_gen = 0; |
@@ -2045,28 +2011,27 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath | |||
2045 | 2011 | ||
2046 | if (inode) { /* Do we count quotas for item? */ | 2012 | if (inode) { /* Do we count quotas for item? */ |
2047 | fs_gen = get_generation(inode->i_sb); | 2013 | fs_gen = get_generation(inode->i_sb); |
2048 | quota_bytes = ih_item_len(p_s_ih); | 2014 | quota_bytes = ih_item_len(ih); |
2049 | 2015 | ||
2050 | /* hack so the quota code doesn't have to guess if the file has | 2016 | /* hack so the quota code doesn't have to guess if the file has |
2051 | ** a tail, links are always tails, so there's no guessing needed | 2017 | ** a tail, links are always tails, so there's no guessing needed |
2052 | */ | 2018 | */ |
2053 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_s_ih)) { | 2019 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(ih)) |
2054 | quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE; | 2020 | quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE; |
2055 | } | ||
2056 | #ifdef REISERQUOTA_DEBUG | 2021 | #ifdef REISERQUOTA_DEBUG |
2057 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, | 2022 | reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, |
2058 | "reiserquota insert_item(): allocating %u id=%u type=%c", | 2023 | "reiserquota insert_item(): allocating %u id=%u type=%c", |
2059 | quota_bytes, inode->i_uid, head2type(p_s_ih)); | 2024 | quota_bytes, inode->i_uid, head2type(ih)); |
2060 | #endif | 2025 | #endif |
2061 | /* We can't dirty inode here. It would be immediately written but | 2026 | /* We can't dirty inode here. It would be immediately written but |
2062 | * appropriate stat item isn't inserted yet... */ | 2027 | * appropriate stat item isn't inserted yet... */ |
2063 | if (vfs_dq_alloc_space_nodirty(inode, quota_bytes)) { | 2028 | if (vfs_dq_alloc_space_nodirty(inode, quota_bytes)) { |
2064 | pathrelse(p_s_path); | 2029 | pathrelse(path); |
2065 | return -EDQUOT; | 2030 | return -EDQUOT; |
2066 | } | 2031 | } |
2067 | } | 2032 | } |
2068 | init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, | 2033 | init_tb_struct(th, &s_ins_balance, th->t_super, path, |
2069 | IH_SIZE + ih_item_len(p_s_ih)); | 2034 | IH_SIZE + ih_item_len(ih)); |
2070 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 2035 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
2071 | s_ins_balance.key = key->on_disk_key; | 2036 | s_ins_balance.key = key->on_disk_key; |
2072 | #endif | 2037 | #endif |
@@ -2076,19 +2041,18 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath | |||
2076 | } | 2041 | } |
2077 | 2042 | ||
2078 | while ((retval = | 2043 | while ((retval = |
2079 | fix_nodes(M_INSERT, &s_ins_balance, p_s_ih, | 2044 | fix_nodes(M_INSERT, &s_ins_balance, ih, |
2080 | p_c_body)) == REPEAT_SEARCH) { | 2045 | body)) == REPEAT_SEARCH) { |
2081 | search_again: | 2046 | search_again: |
2082 | /* file system changed while we were in the fix_nodes */ | 2047 | /* file system changed while we were in the fix_nodes */ |
2083 | PROC_INFO_INC(th->t_super, insert_item_restarted); | 2048 | PROC_INFO_INC(th->t_super, insert_item_restarted); |
2084 | retval = search_item(th->t_super, key, p_s_path); | 2049 | retval = search_item(th->t_super, key, path); |
2085 | if (retval == IO_ERROR) { | 2050 | if (retval == IO_ERROR) { |
2086 | retval = -EIO; | 2051 | retval = -EIO; |
2087 | goto error_out; | 2052 | goto error_out; |
2088 | } | 2053 | } |
2089 | if (retval == ITEM_FOUND) { | 2054 | if (retval == ITEM_FOUND) { |
2090 | reiserfs_warning(th->t_super, | 2055 | reiserfs_warning(th->t_super, "PAP-5760", |
2091 | "PAP-5760: reiserfs_insert_item: " | ||
2092 | "key %K already exists in the tree", | 2056 | "key %K already exists in the tree", |
2093 | key); | 2057 | key); |
2094 | retval = -EEXIST; | 2058 | retval = -EEXIST; |
@@ -2098,7 +2062,7 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath | |||
2098 | 2062 | ||
2099 | /* make balancing after all resources will be collected at a time */ | 2063 | /* make balancing after all resources will be collected at a time */ |
2100 | if (retval == CARRY_ON) { | 2064 | if (retval == CARRY_ON) { |
2101 | do_balance(&s_ins_balance, p_s_ih, p_c_body, M_INSERT); | 2065 | do_balance(&s_ins_balance, ih, body, M_INSERT); |
2102 | return 0; | 2066 | return 0; |
2103 | } | 2067 | } |
2104 | 2068 | ||
@@ -2109,7 +2073,7 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath | |||
2109 | #ifdef REISERQUOTA_DEBUG | 2073 | #ifdef REISERQUOTA_DEBUG |
2110 | reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE, | 2074 | reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE, |
2111 | "reiserquota insert_item(): freeing %u id=%u type=%c", | 2075 | "reiserquota insert_item(): freeing %u id=%u type=%c", |
2112 | quota_bytes, inode->i_uid, head2type(p_s_ih)); | 2076 | quota_bytes, inode->i_uid, head2type(ih)); |
2113 | #endif | 2077 | #endif |
2114 | if (inode) | 2078 | if (inode) |
2115 | vfs_dq_free_space_nodirty(inode, quota_bytes); | 2079 | vfs_dq_free_space_nodirty(inode, quota_bytes); |