diff options
Diffstat (limited to 'fs/reiserfs/stree.c')
-rw-r--r-- | fs/reiserfs/stree.c | 812 |
1 files changed, 469 insertions, 343 deletions
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c index 40b3e77c8ff3..aa86757e48f8 100644 --- a/fs/reiserfs/stree.c +++ b/fs/reiserfs/stree.c | |||
@@ -8,46 +8,6 @@ | |||
8 | * Pereslavl-Zalessky Russia | 8 | * Pereslavl-Zalessky Russia |
9 | */ | 9 | */ |
10 | 10 | ||
11 | /* | ||
12 | * This file contains functions dealing with S+tree | ||
13 | * | ||
14 | * B_IS_IN_TREE | ||
15 | * copy_item_head | ||
16 | * comp_short_keys | ||
17 | * comp_keys | ||
18 | * comp_short_le_keys | ||
19 | * le_key2cpu_key | ||
20 | * comp_le_keys | ||
21 | * bin_search | ||
22 | * get_lkey | ||
23 | * get_rkey | ||
24 | * key_in_buffer | ||
25 | * decrement_bcount | ||
26 | * reiserfs_check_path | ||
27 | * pathrelse_and_restore | ||
28 | * pathrelse | ||
29 | * search_by_key_reada | ||
30 | * search_by_key | ||
31 | * search_for_position_by_key | ||
32 | * comp_items | ||
33 | * prepare_for_direct_item | ||
34 | * prepare_for_direntry_item | ||
35 | * prepare_for_delete_or_cut | ||
36 | * calc_deleted_bytes_number | ||
37 | * init_tb_struct | ||
38 | * padd_item | ||
39 | * reiserfs_delete_item | ||
40 | * reiserfs_delete_solid_item | ||
41 | * reiserfs_delete_object | ||
42 | * maybe_indirect_to_direct | ||
43 | * indirect_to_direct_roll_back | ||
44 | * reiserfs_cut_from_item | ||
45 | * truncate_directory | ||
46 | * reiserfs_do_truncate | ||
47 | * reiserfs_paste_into_item | ||
48 | * reiserfs_insert_item | ||
49 | */ | ||
50 | |||
51 | #include <linux/time.h> | 11 | #include <linux/time.h> |
52 | #include <linux/string.h> | 12 | #include <linux/string.h> |
53 | #include <linux/pagemap.h> | 13 | #include <linux/pagemap.h> |
@@ -65,21 +25,21 @@ inline int B_IS_IN_TREE(const struct buffer_head *bh) | |||
65 | return (B_LEVEL(bh) != FREE_LEVEL); | 25 | return (B_LEVEL(bh) != FREE_LEVEL); |
66 | } | 26 | } |
67 | 27 | ||
68 | // | 28 | /* to get item head in le form */ |
69 | // to gets item head in le form | ||
70 | // | ||
71 | inline void copy_item_head(struct item_head *to, | 29 | inline void copy_item_head(struct item_head *to, |
72 | const struct item_head *from) | 30 | const struct item_head *from) |
73 | { | 31 | { |
74 | memcpy(to, from, IH_SIZE); | 32 | memcpy(to, from, IH_SIZE); |
75 | } | 33 | } |
76 | 34 | ||
77 | /* k1 is pointer to on-disk structure which is stored in little-endian | 35 | /* |
78 | form. k2 is pointer to cpu variable. For key of items of the same | 36 | * k1 is pointer to on-disk structure which is stored in little-endian |
79 | object this returns 0. | 37 | * form. k2 is pointer to cpu variable. For key of items of the same |
80 | Returns: -1 if key1 < key2 | 38 | * object this returns 0. |
81 | 0 if key1 == key2 | 39 | * Returns: -1 if key1 < key2 |
82 | 1 if key1 > key2 */ | 40 | * 0 if key1 == key2 |
41 | * 1 if key1 > key2 | ||
42 | */ | ||
83 | inline int comp_short_keys(const struct reiserfs_key *le_key, | 43 | inline int comp_short_keys(const struct reiserfs_key *le_key, |
84 | const struct cpu_key *cpu_key) | 44 | const struct cpu_key *cpu_key) |
85 | { | 45 | { |
@@ -97,11 +57,13 @@ inline int comp_short_keys(const struct reiserfs_key *le_key, | |||
97 | return 0; | 57 | return 0; |
98 | } | 58 | } |
99 | 59 | ||
100 | /* k1 is pointer to on-disk structure which is stored in little-endian | 60 | /* |
101 | form. k2 is pointer to cpu variable. | 61 | * k1 is pointer to on-disk structure which is stored in little-endian |
102 | Compare keys using all 4 key fields. | 62 | * form. k2 is pointer to cpu variable. |
103 | Returns: -1 if key1 < key2 0 | 63 | * Compare keys using all 4 key fields. |
104 | if key1 = key2 1 if key1 > key2 */ | 64 | * Returns: -1 if key1 < key2 0 |
65 | * if key1 = key2 1 if key1 > key2 | ||
66 | */ | ||
105 | static inline int comp_keys(const struct reiserfs_key *le_key, | 67 | static inline int comp_keys(const struct reiserfs_key *le_key, |
106 | const struct cpu_key *cpu_key) | 68 | const struct cpu_key *cpu_key) |
107 | { | 69 | { |
@@ -155,15 +117,17 @@ inline void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from) | |||
155 | to->on_disk_key.k_dir_id = le32_to_cpu(from->k_dir_id); | 117 | to->on_disk_key.k_dir_id = le32_to_cpu(from->k_dir_id); |
156 | to->on_disk_key.k_objectid = le32_to_cpu(from->k_objectid); | 118 | to->on_disk_key.k_objectid = le32_to_cpu(from->k_objectid); |
157 | 119 | ||
158 | // find out version of the key | 120 | /* find out version of the key */ |
159 | version = le_key_version(from); | 121 | version = le_key_version(from); |
160 | to->version = version; | 122 | to->version = version; |
161 | to->on_disk_key.k_offset = le_key_k_offset(version, from); | 123 | to->on_disk_key.k_offset = le_key_k_offset(version, from); |
162 | to->on_disk_key.k_type = le_key_k_type(version, from); | 124 | to->on_disk_key.k_type = le_key_k_type(version, from); |
163 | } | 125 | } |
164 | 126 | ||
165 | // this does not say which one is bigger, it only returns 1 if keys | 127 | /* |
166 | // are not equal, 0 otherwise | 128 | * this does not say which one is bigger, it only returns 1 if keys |
129 | * are not equal, 0 otherwise | ||
130 | */ | ||
167 | inline int comp_le_keys(const struct reiserfs_key *k1, | 131 | inline int comp_le_keys(const struct reiserfs_key *k1, |
168 | const struct reiserfs_key *k2) | 132 | const struct reiserfs_key *k2) |
169 | { | 133 | { |
@@ -177,24 +141,27 @@ inline int comp_le_keys(const struct reiserfs_key *k1, | |||
177 | * *pos = number of the searched element if found, else the * | 141 | * *pos = number of the searched element if found, else the * |
178 | * number of the first element that is larger than key. * | 142 | * number of the first element that is larger than key. * |
179 | **************************************************************************/ | 143 | **************************************************************************/ |
180 | /* For those not familiar with binary search: lbound is the leftmost item that it | 144 | /* |
181 | could be, rbound the rightmost item that it could be. We examine the item | 145 | * For those not familiar with binary search: lbound is the leftmost item |
182 | halfway between lbound and rbound, and that tells us either that we can increase | 146 | * that it could be, rbound the rightmost item that it could be. We examine |
183 | lbound, or decrease rbound, or that we have found it, or if lbound <= rbound that | 147 | * the item halfway between lbound and rbound, and that tells us either |
184 | there are no possible items, and we have not found it. With each examination we | 148 | * that we can increase lbound, or decrease rbound, or that we have found it, |
185 | cut the number of possible items it could be by one more than half rounded down, | 149 | * or if lbound <= rbound that there are no possible items, and we have not |
186 | or we find it. */ | 150 | * found it. With each examination we cut the number of possible items it |
151 | * could be by one more than half rounded down, or we find it. | ||
152 | */ | ||
187 | static inline int bin_search(const void *key, /* Key to search for. */ | 153 | static inline int bin_search(const void *key, /* Key to search for. */ |
188 | const void *base, /* First item in the array. */ | 154 | const void *base, /* First item in the array. */ |
189 | int num, /* Number of items in the array. */ | 155 | int num, /* Number of items in the array. */ |
190 | int width, /* Item size in the array. | 156 | /* |
191 | searched. Lest the reader be | 157 | * Item size in the array. searched. Lest the |
192 | confused, note that this is crafted | 158 | * reader be confused, note that this is crafted |
193 | as a general function, and when it | 159 | * as a general function, and when it is applied |
194 | is applied specifically to the array | 160 | * specifically to the array of item headers in a |
195 | of item headers in a node, width | 161 | * node, width is actually the item header size |
196 | is actually the item header size not | 162 | * not the item size. |
197 | the item size. */ | 163 | */ |
164 | int width, | ||
198 | int *pos /* Number of the searched for element. */ | 165 | int *pos /* Number of the searched for element. */ |
199 | ) | 166 | ) |
200 | { | 167 | { |
@@ -216,8 +183,10 @@ static inline int bin_search(const void *key, /* Key to search for. */ | |||
216 | return ITEM_FOUND; /* Key found in the array. */ | 183 | return ITEM_FOUND; /* Key found in the array. */ |
217 | } | 184 | } |
218 | 185 | ||
219 | /* bin_search did not find given key, it returns position of key, | 186 | /* |
220 | that is minimal and greater than the given one. */ | 187 | * bin_search did not find given key, it returns position of key, |
188 | * that is minimal and greater than the given one. | ||
189 | */ | ||
221 | *pos = lbound; | 190 | *pos = lbound; |
222 | return ITEM_NOT_FOUND; | 191 | return ITEM_NOT_FOUND; |
223 | } | 192 | } |
@@ -234,10 +203,14 @@ static const struct reiserfs_key MAX_KEY = { | |||
234 | __constant_cpu_to_le32(0xffffffff)},} | 203 | __constant_cpu_to_le32(0xffffffff)},} |
235 | }; | 204 | }; |
236 | 205 | ||
237 | /* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom | 206 | /* |
238 | of the path, and going upwards. We must check the path's validity at each step. If the key is not in | 207 | * Get delimiting key of the buffer by looking for it in the buffers in the |
239 | the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this | 208 | * path, starting from the bottom of the path, and going upwards. We must |
240 | case we return a special key, either MIN_KEY or MAX_KEY. */ | 209 | * check the path's validity at each step. If the key is not in the path, |
210 | * there is no delimiting key in the tree (buffer is first or last buffer | ||
211 | * in tree), and in this case we return a special key, either MIN_KEY or | ||
212 | * MAX_KEY. | ||
213 | */ | ||
241 | static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_path, | 214 | static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_path, |
242 | const struct super_block *sb) | 215 | const struct super_block *sb) |
243 | { | 216 | { |
@@ -270,7 +243,10 @@ static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_pat | |||
270 | PATH_OFFSET_PBUFFER(chk_path, | 243 | PATH_OFFSET_PBUFFER(chk_path, |
271 | path_offset + 1)->b_blocknr) | 244 | path_offset + 1)->b_blocknr) |
272 | return &MAX_KEY; | 245 | return &MAX_KEY; |
273 | /* Return delimiting key if position in the parent is not equal to zero. */ | 246 | /* |
247 | * Return delimiting key if position in the parent | ||
248 | * is not equal to zero. | ||
249 | */ | ||
274 | if (position) | 250 | if (position) |
275 | return internal_key(parent, position - 1); | 251 | return internal_key(parent, position - 1); |
276 | } | 252 | } |
@@ -308,15 +284,23 @@ inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path, | |||
308 | path_offset)) > | 284 | path_offset)) > |
309 | B_NR_ITEMS(parent)) | 285 | B_NR_ITEMS(parent)) |
310 | return &MIN_KEY; | 286 | return &MIN_KEY; |
311 | /* Check whether parent at the path really points to the child. */ | 287 | /* |
288 | * Check whether parent at the path really points | ||
289 | * to the child. | ||
290 | */ | ||
312 | if (B_N_CHILD_NUM(parent, position) != | 291 | if (B_N_CHILD_NUM(parent, position) != |
313 | PATH_OFFSET_PBUFFER(chk_path, | 292 | PATH_OFFSET_PBUFFER(chk_path, |
314 | path_offset + 1)->b_blocknr) | 293 | path_offset + 1)->b_blocknr) |
315 | return &MIN_KEY; | 294 | return &MIN_KEY; |
316 | /* Return delimiting key if position in the parent is not the last one. */ | 295 | |
296 | /* | ||
297 | * Return delimiting key if position in the parent | ||
298 | * is not the last one. | ||
299 | */ | ||
317 | if (position != B_NR_ITEMS(parent)) | 300 | if (position != B_NR_ITEMS(parent)) |
318 | return internal_key(parent, position); | 301 | return internal_key(parent, position); |
319 | } | 302 | } |
303 | |||
320 | /* Return MAX_KEY if we are in the root of the buffer tree. */ | 304 | /* Return MAX_KEY if we are in the root of the buffer tree. */ |
321 | if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> | 305 | if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> |
322 | b_blocknr == SB_ROOT_BLOCK(sb)) | 306 | b_blocknr == SB_ROOT_BLOCK(sb)) |
@@ -324,13 +308,20 @@ inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path, | |||
324 | return &MIN_KEY; | 308 | return &MIN_KEY; |
325 | } | 309 | } |
326 | 310 | ||
327 | /* Check whether a key is contained in the tree rooted from a buffer at a path. */ | 311 | /* |
328 | /* This works by looking at the left and right delimiting keys for the buffer in the last path_element in | 312 | * Check whether a key is contained in the tree rooted from a buffer at a path. |
329 | the path. These delimiting keys are stored at least one level above that buffer in the tree. If the | 313 | * This works by looking at the left and right delimiting keys for the buffer |
330 | buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in | 314 | * in the last path_element in the path. These delimiting keys are stored |
331 | this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ | 315 | * at least one level above that buffer in the tree. If the buffer is the |
332 | static inline int key_in_buffer(struct treepath *chk_path, /* Path which should be checked. */ | 316 | * first or last node in the tree order then one of the delimiting keys may |
333 | const struct cpu_key *key, /* Key which should be checked. */ | 317 | * be absent, and in this case get_lkey and get_rkey return a special key |
318 | * which is MIN_KEY or MAX_KEY. | ||
319 | */ | ||
320 | static inline int key_in_buffer( | ||
321 | /* Path which should be checked. */ | ||
322 | struct treepath *chk_path, | ||
323 | /* Key which should be checked. */ | ||
324 | const struct cpu_key *key, | ||
334 | struct super_block *sb | 325 | struct super_block *sb |
335 | ) | 326 | ) |
336 | { | 327 | { |
@@ -359,9 +350,11 @@ int reiserfs_check_path(struct treepath *p) | |||
359 | return 0; | 350 | return 0; |
360 | } | 351 | } |
361 | 352 | ||
362 | /* Drop the reference to each buffer in a path and restore | 353 | /* |
354 | * Drop the reference to each buffer in a path and restore | ||
363 | * dirty bits clean when preparing the buffer for the log. | 355 | * dirty bits clean when preparing the buffer for the log. |
364 | * This version should only be called from fix_nodes() */ | 356 | * This version should only be called from fix_nodes() |
357 | */ | ||
365 | void pathrelse_and_restore(struct super_block *sb, | 358 | void pathrelse_and_restore(struct super_block *sb, |
366 | struct treepath *search_path) | 359 | struct treepath *search_path) |
367 | { | 360 | { |
@@ -418,14 +411,17 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) | |||
418 | } | 411 | } |
419 | ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; | 412 | ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; |
420 | used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih)); | 413 | used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih)); |
414 | |||
415 | /* free space does not match to calculated amount of use space */ | ||
421 | if (used_space != blocksize - blkh_free_space(blkh)) { | 416 | if (used_space != blocksize - blkh_free_space(blkh)) { |
422 | /* free space does not match to calculated amount of use space */ | ||
423 | reiserfs_warning(NULL, "reiserfs-5082", | 417 | reiserfs_warning(NULL, "reiserfs-5082", |
424 | "free space seems wrong: %z", bh); | 418 | "free space seems wrong: %z", bh); |
425 | return 0; | 419 | return 0; |
426 | } | 420 | } |
427 | // FIXME: it is_leaf will hit performance too much - we may have | 421 | /* |
428 | // return 1 here | 422 | * FIXME: it is_leaf will hit performance too much - we may have |
423 | * return 1 here | ||
424 | */ | ||
429 | 425 | ||
430 | /* check tables of item heads */ | 426 | /* check tables of item heads */ |
431 | ih = (struct item_head *)(buf + BLKH_SIZE); | 427 | ih = (struct item_head *)(buf + BLKH_SIZE); |
@@ -460,7 +456,7 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) | |||
460 | prev_location = ih_location(ih); | 456 | prev_location = ih_location(ih); |
461 | } | 457 | } |
462 | 458 | ||
463 | // one may imagine much more checks | 459 | /* one may imagine many more checks */ |
464 | return 1; | 460 | return 1; |
465 | } | 461 | } |
466 | 462 | ||
@@ -481,8 +477,8 @@ static int is_internal(char *buf, int blocksize, struct buffer_head *bh) | |||
481 | } | 477 | } |
482 | 478 | ||
483 | nr = blkh_nr_item(blkh); | 479 | nr = blkh_nr_item(blkh); |
480 | /* for internal which is not root we might check min number of keys */ | ||
484 | if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) { | 481 | if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) { |
485 | /* for internal which is not root we might check min number of keys */ | ||
486 | reiserfs_warning(NULL, "reiserfs-5088", | 482 | reiserfs_warning(NULL, "reiserfs-5088", |
487 | "number of key seems wrong: %z", bh); | 483 | "number of key seems wrong: %z", bh); |
488 | return 0; | 484 | return 0; |
@@ -494,12 +490,15 @@ static int is_internal(char *buf, int blocksize, struct buffer_head *bh) | |||
494 | "free space seems wrong: %z", bh); | 490 | "free space seems wrong: %z", bh); |
495 | return 0; | 491 | return 0; |
496 | } | 492 | } |
497 | // one may imagine much more checks | 493 | |
494 | /* one may imagine many more checks */ | ||
498 | return 1; | 495 | return 1; |
499 | } | 496 | } |
500 | 497 | ||
501 | // make sure that bh contains formatted node of reiserfs tree of | 498 | /* |
502 | // 'level'-th level | 499 | * make sure that bh contains formatted node of reiserfs tree of |
500 | * 'level'-th level | ||
501 | */ | ||
503 | static int is_tree_node(struct buffer_head *bh, int level) | 502 | static int is_tree_node(struct buffer_head *bh, int level) |
504 | { | 503 | { |
505 | if (B_LEVEL(bh) != level) { | 504 | if (B_LEVEL(bh) != level) { |
@@ -546,7 +545,8 @@ static int search_by_key_reada(struct super_block *s, | |||
546 | for (j = 0; j < i; j++) { | 545 | for (j = 0; j < i; j++) { |
547 | /* | 546 | /* |
548 | * note, this needs attention if we are getting rid of the BKL | 547 | * note, this needs attention if we are getting rid of the BKL |
549 | * you have to make sure the prepared bit isn't set on this buffer | 548 | * you have to make sure the prepared bit isn't set on this |
549 | * buffer | ||
550 | */ | 550 | */ |
551 | if (!buffer_uptodate(bh[j])) { | 551 | if (!buffer_uptodate(bh[j])) { |
552 | if (depth == -1) | 552 | if (depth == -1) |
@@ -558,39 +558,34 @@ static int search_by_key_reada(struct super_block *s, | |||
558 | return depth; | 558 | return depth; |
559 | } | 559 | } |
560 | 560 | ||
561 | /************************************************************************** | 561 | /* |
562 | * Algorithm SearchByKey * | 562 | * This function fills up the path from the root to the leaf as it |
563 | * look for item in the Disk S+Tree by its key * | 563 | * descends the tree looking for the key. It uses reiserfs_bread to |
564 | * Input: sb - super block * | 564 | * try to find buffers in the cache given their block number. If it |
565 | * key - pointer to the key to search * | 565 | * does not find them in the cache it reads them from disk. For each |
566 | * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR * | 566 | * node search_by_key finds using reiserfs_bread it then uses |
567 | * search_path - path from the root to the needed leaf * | 567 | * bin_search to look through that node. bin_search will find the |
568 | **************************************************************************/ | 568 | * position of the block_number of the next node if it is looking |
569 | 569 | * through an internal node. If it is looking through a leaf node | |
570 | /* This function fills up the path from the root to the leaf as it | 570 | * bin_search will find the position of the item which has key either |
571 | descends the tree looking for the key. It uses reiserfs_bread to | 571 | * equal to given key, or which is the maximal key less than the given |
572 | try to find buffers in the cache given their block number. If it | 572 | * key. search_by_key returns a path that must be checked for the |
573 | does not find them in the cache it reads them from disk. For each | 573 | * correctness of the top of the path but need not be checked for the |
574 | node search_by_key finds using reiserfs_bread it then uses | 574 | * correctness of the bottom of the path |
575 | bin_search to look through that node. bin_search will find the | 575 | */ |
576 | position of the block_number of the next node if it is looking | 576 | /* |
577 | through an internal node. If it is looking through a leaf node | 577 | * search_by_key - search for key (and item) in stree |
578 | bin_search will find the position of the item which has key either | 578 | * @sb: superblock |
579 | equal to given key, or which is the maximal key less than the given | 579 | * @key: pointer to key to search for |
580 | key. search_by_key returns a path that must be checked for the | 580 | * @search_path: Allocated and initialized struct treepath; Returned filled |
581 | correctness of the top of the path but need not be checked for the | 581 | * on success. |
582 | correctness of the bottom of the path */ | 582 | * @stop_level: How far down the tree to search, Use DISK_LEAF_NODE_LEVEL to |
583 | /* The function is NOT SCHEDULE-SAFE! */ | 583 | * stop at leaf level. |
584 | int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to search. */ | 584 | * |
585 | struct treepath *search_path,/* This structure was | 585 | * The function is NOT SCHEDULE-SAFE! |
586 | allocated and initialized | 586 | */ |
587 | by the calling | 587 | int search_by_key(struct super_block *sb, const struct cpu_key *key, |
588 | function. It is filled up | 588 | struct treepath *search_path, int stop_level) |
589 | by this function. */ | ||
590 | int stop_level /* How far down the tree to search. To | ||
591 | stop at leaf level - set to | ||
592 | DISK_LEAF_NODE_LEVEL */ | ||
593 | ) | ||
594 | { | 589 | { |
595 | b_blocknr_t block_number; | 590 | b_blocknr_t block_number; |
596 | int expected_level; | 591 | int expected_level; |
@@ -609,17 +604,22 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
609 | 604 | ||
610 | PROC_INFO_INC(sb, search_by_key); | 605 | PROC_INFO_INC(sb, search_by_key); |
611 | 606 | ||
612 | /* As we add each node to a path we increase its count. This means that | 607 | /* |
613 | we must be careful to release all nodes in a path before we either | 608 | * As we add each node to a path we increase its count. This means |
614 | discard the path struct or re-use the path struct, as we do here. */ | 609 | * that we must be careful to release all nodes in a path before we |
610 | * either discard the path struct or re-use the path struct, as we | ||
611 | * do here. | ||
612 | */ | ||
615 | 613 | ||
616 | pathrelse(search_path); | 614 | pathrelse(search_path); |
617 | 615 | ||
618 | right_neighbor_of_leaf_node = 0; | 616 | right_neighbor_of_leaf_node = 0; |
619 | 617 | ||
620 | /* With each iteration of this loop we search through the items in the | 618 | /* |
621 | current node, and calculate the next current node(next path element) | 619 | * With each iteration of this loop we search through the items in the |
622 | for the next iteration of this loop.. */ | 620 | * current node, and calculate the next current node(next path element) |
621 | * for the next iteration of this loop.. | ||
622 | */ | ||
623 | block_number = SB_ROOT_BLOCK(sb); | 623 | block_number = SB_ROOT_BLOCK(sb); |
624 | expected_level = -1; | 624 | expected_level = -1; |
625 | while (1) { | 625 | while (1) { |
@@ -639,8 +639,10 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
639 | ++search_path->path_length); | 639 | ++search_path->path_length); |
640 | fs_gen = get_generation(sb); | 640 | fs_gen = get_generation(sb); |
641 | 641 | ||
642 | /* Read the next tree node, and set the last element in the path to | 642 | /* |
643 | have a pointer to it. */ | 643 | * Read the next tree node, and set the last element |
644 | * in the path to have a pointer to it. | ||
645 | */ | ||
644 | if ((bh = last_element->pe_buffer = | 646 | if ((bh = last_element->pe_buffer = |
645 | sb_getblk(sb, block_number))) { | 647 | sb_getblk(sb, block_number))) { |
646 | 648 | ||
@@ -676,9 +678,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
676 | expected_level = SB_TREE_HEIGHT(sb); | 678 | expected_level = SB_TREE_HEIGHT(sb); |
677 | expected_level--; | 679 | expected_level--; |
678 | 680 | ||
679 | /* It is possible that schedule occurred. We must check whether the key | 681 | /* |
680 | to search is still in the tree rooted from the current buffer. If | 682 | * It is possible that schedule occurred. We must check |
681 | not then repeat search from the root. */ | 683 | * whether the key to search is still in the tree rooted |
684 | * from the current buffer. If not then repeat search | ||
685 | * from the root. | ||
686 | */ | ||
682 | if (fs_changed(fs_gen, sb) && | 687 | if (fs_changed(fs_gen, sb) && |
683 | (!B_IS_IN_TREE(bh) || | 688 | (!B_IS_IN_TREE(bh) || |
684 | B_LEVEL(bh) != expected_level || | 689 | B_LEVEL(bh) != expected_level || |
@@ -689,8 +694,10 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
689 | sbk_restarted[expected_level - 1]); | 694 | sbk_restarted[expected_level - 1]); |
690 | pathrelse(search_path); | 695 | pathrelse(search_path); |
691 | 696 | ||
692 | /* Get the root block number so that we can repeat the search | 697 | /* |
693 | starting from the root. */ | 698 | * Get the root block number so that we can |
699 | * repeat the search starting from the root. | ||
700 | */ | ||
694 | block_number = SB_ROOT_BLOCK(sb); | 701 | block_number = SB_ROOT_BLOCK(sb); |
695 | expected_level = -1; | 702 | expected_level = -1; |
696 | right_neighbor_of_leaf_node = 0; | 703 | right_neighbor_of_leaf_node = 0; |
@@ -699,9 +706,11 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
699 | continue; | 706 | continue; |
700 | } | 707 | } |
701 | 708 | ||
702 | /* only check that the key is in the buffer if key is not | 709 | /* |
703 | equal to the MAX_KEY. Latter case is only possible in | 710 | * only check that the key is in the buffer if key is not |
704 | "finish_unfinished()" processing during mount. */ | 711 | * equal to the MAX_KEY. Latter case is only possible in |
712 | * "finish_unfinished()" processing during mount. | ||
713 | */ | ||
705 | RFALSE(comp_keys(&MAX_KEY, key) && | 714 | RFALSE(comp_keys(&MAX_KEY, key) && |
706 | !key_in_buffer(search_path, key, sb), | 715 | !key_in_buffer(search_path, key, sb), |
707 | "PAP-5130: key is not in the buffer"); | 716 | "PAP-5130: key is not in the buffer"); |
@@ -713,8 +722,10 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
713 | } | 722 | } |
714 | #endif | 723 | #endif |
715 | 724 | ||
716 | // make sure, that the node contents look like a node of | 725 | /* |
717 | // certain level | 726 | * make sure, that the node contents look like a node of |
727 | * certain level | ||
728 | */ | ||
718 | if (!is_tree_node(bh, expected_level)) { | 729 | if (!is_tree_node(bh, expected_level)) { |
719 | reiserfs_error(sb, "vs-5150", | 730 | reiserfs_error(sb, "vs-5150", |
720 | "invalid format found in block %ld. " | 731 | "invalid format found in block %ld. " |
@@ -743,21 +754,31 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
743 | } | 754 | } |
744 | 755 | ||
745 | /* we are not in the stop level */ | 756 | /* we are not in the stop level */ |
757 | /* | ||
758 | * item has been found, so we choose the pointer which | ||
759 | * is to the right of the found one | ||
760 | */ | ||
746 | if (retval == ITEM_FOUND) | 761 | if (retval == ITEM_FOUND) |
747 | /* item has been found, so we choose the pointer which is to the right of the found one */ | ||
748 | last_element->pe_position++; | 762 | last_element->pe_position++; |
749 | 763 | ||
750 | /* if item was not found we choose the position which is to | 764 | /* |
751 | the left of the found item. This requires no code, | 765 | * if item was not found we choose the position which is to |
752 | bin_search did it already. */ | 766 | * the left of the found item. This requires no code, |
767 | * bin_search did it already. | ||
768 | */ | ||
753 | 769 | ||
754 | /* So we have chosen a position in the current node which is | 770 | /* |
755 | an internal node. Now we calculate child block number by | 771 | * So we have chosen a position in the current node which is |
756 | position in the node. */ | 772 | * an internal node. Now we calculate child block number by |
773 | * position in the node. | ||
774 | */ | ||
757 | block_number = | 775 | block_number = |
758 | B_N_CHILD_NUM(bh, last_element->pe_position); | 776 | B_N_CHILD_NUM(bh, last_element->pe_position); |
759 | 777 | ||
760 | /* if we are going to read leaf nodes, try for read ahead as well */ | 778 | /* |
779 | * if we are going to read leaf nodes, try for read | ||
780 | * ahead as well | ||
781 | */ | ||
761 | if ((search_path->reada & PATH_READA) && | 782 | if ((search_path->reada & PATH_READA) && |
762 | node_level == DISK_LEAF_NODE_LEVEL + 1) { | 783 | node_level == DISK_LEAF_NODE_LEVEL + 1) { |
763 | int pos = last_element->pe_position; | 784 | int pos = last_element->pe_position; |
@@ -789,26 +810,28 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s | |||
789 | } | 810 | } |
790 | } | 811 | } |
791 | 812 | ||
792 | /* Form the path to an item and position in this item which contains | 813 | /* |
793 | file byte defined by key. If there is no such item | 814 | * Form the path to an item and position in this item which contains |
794 | corresponding to the key, we point the path to the item with | 815 | * file byte defined by key. If there is no such item |
795 | maximal key less than key, and *pos_in_item is set to one | 816 | * corresponding to the key, we point the path to the item with |
796 | past the last entry/byte in the item. If searching for entry in a | 817 | * maximal key less than key, and *pos_in_item is set to one |
797 | directory item, and it is not found, *pos_in_item is set to one | 818 | * past the last entry/byte in the item. If searching for entry in a |
798 | entry more than the entry with maximal key which is less than the | 819 | * directory item, and it is not found, *pos_in_item is set to one |
799 | sought key. | 820 | * entry more than the entry with maximal key which is less than the |
800 | 821 | * sought key. | |
801 | Note that if there is no entry in this same node which is one more, | 822 | * |
802 | then we point to an imaginary entry. for direct items, the | 823 | * Note that if there is no entry in this same node which is one more, |
803 | position is in units of bytes, for indirect items the position is | 824 | * then we point to an imaginary entry. for direct items, the |
804 | in units of blocknr entries, for directory items the position is in | 825 | * position is in units of bytes, for indirect items the position is |
805 | units of directory entries. */ | 826 | * in units of blocknr entries, for directory items the position is in |
806 | 827 | * units of directory entries. | |
828 | */ | ||
807 | /* The function is NOT SCHEDULE-SAFE! */ | 829 | /* The function is NOT SCHEDULE-SAFE! */ |
808 | int search_for_position_by_key(struct super_block *sb, /* Pointer to the super block. */ | 830 | int search_for_position_by_key(struct super_block *sb, |
809 | const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */ | 831 | /* Key to search (cpu variable) */ |
810 | struct treepath *search_path /* Filled up by this function. */ | 832 | const struct cpu_key *p_cpu_key, |
811 | ) | 833 | /* Filled up by this function. */ |
834 | struct treepath *search_path) | ||
812 | { | 835 | { |
813 | struct item_head *p_le_ih; /* pointer to on-disk structure */ | 836 | struct item_head *p_le_ih; /* pointer to on-disk structure */ |
814 | int blk_size; | 837 | int blk_size; |
@@ -851,7 +874,8 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b | |||
851 | if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { | 874 | if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { |
852 | return FILE_NOT_FOUND; | 875 | return FILE_NOT_FOUND; |
853 | } | 876 | } |
854 | // FIXME: quite ugly this far | 877 | |
878 | /* FIXME: quite ugly this far */ | ||
855 | 879 | ||
856 | item_offset = le_ih_k_offset(p_le_ih); | 880 | item_offset = le_ih_k_offset(p_le_ih); |
857 | offset = cpu_key_k_offset(p_cpu_key); | 881 | offset = cpu_key_k_offset(p_cpu_key); |
@@ -866,8 +890,10 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b | |||
866 | return POSITION_FOUND; | 890 | return POSITION_FOUND; |
867 | } | 891 | } |
868 | 892 | ||
869 | /* Needed byte is not contained in the item pointed to by the | 893 | /* |
870 | path. Set pos_in_item out of the item. */ | 894 | * Needed byte is not contained in the item pointed to by the |
895 | * path. Set pos_in_item out of the item. | ||
896 | */ | ||
871 | if (is_indirect_le_ih(p_le_ih)) | 897 | if (is_indirect_le_ih(p_le_ih)) |
872 | pos_in_item(search_path) = | 898 | pos_in_item(search_path) = |
873 | ih_item_len(p_le_ih) / UNFM_P_SIZE; | 899 | ih_item_len(p_le_ih) / UNFM_P_SIZE; |
@@ -896,15 +922,13 @@ int comp_items(const struct item_head *stored_ih, const struct treepath *path) | |||
896 | return memcmp(stored_ih, ih, IH_SIZE); | 922 | return memcmp(stored_ih, ih, IH_SIZE); |
897 | } | 923 | } |
898 | 924 | ||
899 | /* unformatted nodes are not logged anymore, ever. This is safe | 925 | /* unformatted nodes are not logged anymore, ever. This is safe now */ |
900 | ** now | ||
901 | */ | ||
902 | #define held_by_others(bh) (atomic_read(&(bh)->b_count) > 1) | 926 | #define held_by_others(bh) (atomic_read(&(bh)->b_count) > 1) |
903 | 927 | ||
904 | // block can not be forgotten as it is in I/O or held by someone | 928 | /* block can not be forgotten as it is in I/O or held by someone */ |
905 | #define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh))) | 929 | #define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh))) |
906 | 930 | ||
907 | // prepare for delete or cut of direct item | 931 | /* prepare for delete or cut of direct item */ |
908 | static inline int prepare_for_direct_item(struct treepath *path, | 932 | static inline int prepare_for_direct_item(struct treepath *path, |
909 | struct item_head *le_ih, | 933 | struct item_head *le_ih, |
910 | struct inode *inode, | 934 | struct inode *inode, |
@@ -917,9 +941,8 @@ static inline int prepare_for_direct_item(struct treepath *path, | |||
917 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); | 941 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); |
918 | return M_DELETE; | 942 | return M_DELETE; |
919 | } | 943 | } |
920 | // new file gets truncated | 944 | /* new file gets truncated */ |
921 | if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { | 945 | if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { |
922 | // | ||
923 | round_len = ROUND_UP(new_file_length); | 946 | round_len = ROUND_UP(new_file_length); |
924 | /* this was new_file_length < le_ih ... */ | 947 | /* this was new_file_length < le_ih ... */ |
925 | if (round_len < le_ih_k_offset(le_ih)) { | 948 | if (round_len < le_ih_k_offset(le_ih)) { |
@@ -933,12 +956,13 @@ static inline int prepare_for_direct_item(struct treepath *path, | |||
933 | return M_CUT; /* Cut from this item. */ | 956 | return M_CUT; /* Cut from this item. */ |
934 | } | 957 | } |
935 | 958 | ||
936 | // old file: items may have any length | 959 | /* old file: items may have any length */ |
937 | 960 | ||
938 | if (new_file_length < le_ih_k_offset(le_ih)) { | 961 | if (new_file_length < le_ih_k_offset(le_ih)) { |
939 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); | 962 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); |
940 | return M_DELETE; /* Delete this item. */ | 963 | return M_DELETE; /* Delete this item. */ |
941 | } | 964 | } |
965 | |||
942 | /* Calculate first position and size for cutting from item. */ | 966 | /* Calculate first position and size for cutting from item. */ |
943 | *cut_size = -(ih_item_len(le_ih) - | 967 | *cut_size = -(ih_item_len(le_ih) - |
944 | (pos_in_item(path) = | 968 | (pos_in_item(path) = |
@@ -957,12 +981,15 @@ static inline int prepare_for_direntry_item(struct treepath *path, | |||
957 | RFALSE(ih_entry_count(le_ih) != 2, | 981 | RFALSE(ih_entry_count(le_ih) != 2, |
958 | "PAP-5220: incorrect empty directory item (%h)", le_ih); | 982 | "PAP-5220: incorrect empty directory item (%h)", le_ih); |
959 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); | 983 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); |
960 | return M_DELETE; /* Delete the directory item containing "." and ".." entry. */ | 984 | /* Delete the directory item containing "." and ".." entry. */ |
985 | return M_DELETE; | ||
961 | } | 986 | } |
962 | 987 | ||
963 | if (ih_entry_count(le_ih) == 1) { | 988 | if (ih_entry_count(le_ih) == 1) { |
964 | /* Delete the directory item such as there is one record only | 989 | /* |
965 | in this item */ | 990 | * Delete the directory item such as there is one record only |
991 | * in this item | ||
992 | */ | ||
966 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); | 993 | *cut_size = -(IH_SIZE + ih_item_len(le_ih)); |
967 | return M_DELETE; | 994 | return M_DELETE; |
968 | } | 995 | } |
@@ -976,14 +1003,30 @@ static inline int prepare_for_direntry_item(struct treepath *path, | |||
976 | 1003 | ||
977 | #define JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD (2 * JOURNAL_PER_BALANCE_CNT + 1) | 1004 | #define JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD (2 * JOURNAL_PER_BALANCE_CNT + 1) |
978 | 1005 | ||
979 | /* If the path points to a directory or direct item, calculate mode and the size cut, for balance. | 1006 | /* |
980 | If the path points to an indirect item, remove some number of its unformatted nodes. | 1007 | * If the path points to a directory or direct item, calculate mode |
981 | In case of file truncate calculate whether this item must be deleted/truncated or last | 1008 | * and the size cut, for balance. |
982 | unformatted node of this item will be converted to a direct item. | 1009 | * If the path points to an indirect item, remove some number of its |
983 | This function returns a determination of what balance mode the calling function should employ. */ | 1010 | * unformatted nodes. |
984 | 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 | 1011 | * In case of file truncate calculate whether this item must be |
985 | from end of the file. */ | 1012 | * deleted/truncated or last unformatted node of this item will be |
986 | int *cut_size, unsigned long long new_file_length /* MAX_KEY_OFFSET in case of delete. */ | 1013 | * converted to a direct item. |
1014 | * This function returns a determination of what balance mode the | ||
1015 | * calling function should employ. | ||
1016 | */ | ||
1017 | static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, | ||
1018 | struct inode *inode, | ||
1019 | struct treepath *path, | ||
1020 | const struct cpu_key *item_key, | ||
1021 | /* | ||
1022 | * Number of unformatted nodes | ||
1023 | * which were removed from end | ||
1024 | * of the file. | ||
1025 | */ | ||
1026 | int *removed, | ||
1027 | int *cut_size, | ||
1028 | /* MAX_KEY_OFFSET in case of delete. */ | ||
1029 | unsigned long long new_file_length | ||
987 | ) | 1030 | ) |
988 | { | 1031 | { |
989 | struct super_block *sb = inode->i_sb; | 1032 | struct super_block *sb = inode->i_sb; |
@@ -1023,8 +1066,10 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st | |||
1023 | int pos = 0; | 1066 | int pos = 0; |
1024 | 1067 | ||
1025 | if ( new_file_length == max_reiserfs_offset (inode) ) { | 1068 | if ( new_file_length == max_reiserfs_offset (inode) ) { |
1026 | /* prepare_for_delete_or_cut() is called by | 1069 | /* |
1027 | * reiserfs_delete_item() */ | 1070 | * prepare_for_delete_or_cut() is called by |
1071 | * reiserfs_delete_item() | ||
1072 | */ | ||
1028 | new_file_length = 0; | 1073 | new_file_length = 0; |
1029 | delete = 1; | 1074 | delete = 1; |
1030 | } | 1075 | } |
@@ -1040,9 +1085,12 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st | |||
1040 | __le32 *unfm; | 1085 | __le32 *unfm; |
1041 | __u32 block; | 1086 | __u32 block; |
1042 | 1087 | ||
1043 | /* Each unformatted block deletion may involve one additional | 1088 | /* |
1044 | * bitmap block into the transaction, thereby the initial | 1089 | * Each unformatted block deletion may involve |
1045 | * journal space reservation might not be enough. */ | 1090 | * one additional bitmap block into the transaction, |
1091 | * thereby the initial journal space reservation | ||
1092 | * might not be enough. | ||
1093 | */ | ||
1046 | if (!delete && (*cut_size) != 0 && | 1094 | if (!delete && (*cut_size) != 0 && |
1047 | reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) | 1095 | reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) |
1048 | break; | 1096 | break; |
@@ -1074,17 +1122,21 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st | |||
1074 | break; | 1122 | break; |
1075 | } | 1123 | } |
1076 | } | 1124 | } |
1077 | /* a trick. If the buffer has been logged, this will do nothing. If | 1125 | /* |
1078 | ** we've broken the loop without logging it, it will restore the | 1126 | * a trick. If the buffer has been logged, this will |
1079 | ** buffer */ | 1127 | * do nothing. If we've broken the loop without logging |
1128 | * it, it will restore the buffer | ||
1129 | */ | ||
1080 | reiserfs_restore_prepared_buffer(sb, bh); | 1130 | reiserfs_restore_prepared_buffer(sb, bh); |
1081 | } while (need_re_search && | 1131 | } while (need_re_search && |
1082 | search_for_position_by_key(sb, item_key, path) == POSITION_FOUND); | 1132 | search_for_position_by_key(sb, item_key, path) == POSITION_FOUND); |
1083 | pos_in_item(path) = pos * UNFM_P_SIZE; | 1133 | pos_in_item(path) = pos * UNFM_P_SIZE; |
1084 | 1134 | ||
1085 | if (*cut_size == 0) { | 1135 | if (*cut_size == 0) { |
1086 | /* Nothing were cut. maybe convert last unformatted node to the | 1136 | /* |
1087 | * direct item? */ | 1137 | * Nothing was cut. maybe convert last unformatted node to the |
1138 | * direct item? | ||
1139 | */ | ||
1088 | result = M_CONVERT; | 1140 | result = M_CONVERT; |
1089 | } | 1141 | } |
1090 | return result; | 1142 | return result; |
@@ -1104,9 +1156,11 @@ static int calc_deleted_bytes_number(struct tree_balance *tb, char mode) | |||
1104 | (mode == | 1156 | (mode == |
1105 | M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0]; | 1157 | M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0]; |
1106 | if (is_direntry_le_ih(p_le_ih)) { | 1158 | if (is_direntry_le_ih(p_le_ih)) { |
1107 | /* return EMPTY_DIR_SIZE; We delete emty directoris only. | 1159 | /* |
1108 | * we can't use EMPTY_DIR_SIZE, as old format dirs have a different | 1160 | * return EMPTY_DIR_SIZE; We delete emty directories only. |
1109 | * empty size. ick. FIXME, is this right? */ | 1161 | * we can't use EMPTY_DIR_SIZE, as old format dirs have a |
1162 | * different empty size. ick. FIXME, is this right? | ||
1163 | */ | ||
1110 | return del_size; | 1164 | return del_size; |
1111 | } | 1165 | } |
1112 | 1166 | ||
@@ -1169,7 +1223,8 @@ char head2type(struct item_head *ih) | |||
1169 | } | 1223 | } |
1170 | #endif | 1224 | #endif |
1171 | 1225 | ||
1172 | /* Delete object item. | 1226 | /* |
1227 | * Delete object item. | ||
1173 | * th - active transaction handle | 1228 | * th - active transaction handle |
1174 | * path - path to the deleted item | 1229 | * path - path to the deleted item |
1175 | * item_key - key to search for the deleted item | 1230 | * item_key - key to search for the deleted item |
@@ -1221,7 +1276,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, | |||
1221 | 1276 | ||
1222 | PROC_INFO_INC(sb, delete_item_restarted); | 1277 | PROC_INFO_INC(sb, delete_item_restarted); |
1223 | 1278 | ||
1224 | // file system changed, repeat search | 1279 | /* file system changed, repeat search */ |
1225 | ret_value = | 1280 | ret_value = |
1226 | search_for_position_by_key(sb, item_key, path); | 1281 | search_for_position_by_key(sb, item_key, path); |
1227 | if (ret_value == IO_ERROR) | 1282 | if (ret_value == IO_ERROR) |
@@ -1238,16 +1293,18 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, | |||
1238 | unfix_nodes(&s_del_balance); | 1293 | unfix_nodes(&s_del_balance); |
1239 | return 0; | 1294 | return 0; |
1240 | } | 1295 | } |
1241 | // reiserfs_delete_item returns item length when success | 1296 | |
1297 | /* reiserfs_delete_item returns item length when success */ | ||
1242 | ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); | 1298 | ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); |
1243 | q_ih = tp_item_head(path); | 1299 | q_ih = tp_item_head(path); |
1244 | quota_cut_bytes = ih_item_len(q_ih); | 1300 | quota_cut_bytes = ih_item_len(q_ih); |
1245 | 1301 | ||
1246 | /* hack so the quota code doesn't have to guess if the file | 1302 | /* |
1247 | ** has a tail. On tail insert, we allocate quota for 1 unformatted node. | 1303 | * hack so the quota code doesn't have to guess if the file has a |
1248 | ** We test the offset because the tail might have been | 1304 | * tail. On tail insert, we allocate quota for 1 unformatted node. |
1249 | ** split into multiple items, and we only want to decrement for | 1305 | * We test the offset because the tail might have been |
1250 | ** the unfm node once | 1306 | * split into multiple items, and we only want to decrement for |
1307 | * the unfm node once | ||
1251 | */ | 1308 | */ |
1252 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(q_ih)) { | 1309 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(q_ih)) { |
1253 | if ((le_ih_k_offset(q_ih) & (sb->s_blocksize - 1)) == 1) { | 1310 | if ((le_ih_k_offset(q_ih) & (sb->s_blocksize - 1)) == 1) { |
@@ -1261,24 +1318,28 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, | |||
1261 | int off; | 1318 | int off; |
1262 | char *data; | 1319 | char *data; |
1263 | 1320 | ||
1264 | /* We are in direct2indirect conversion, so move tail contents | 1321 | /* |
1265 | to the unformatted node */ | 1322 | * We are in direct2indirect conversion, so move tail contents |
1266 | /* note, we do the copy before preparing the buffer because we | 1323 | * to the unformatted node |
1267 | ** don't care about the contents of the unformatted node yet. | 1324 | */ |
1268 | ** the only thing we really care about is the direct item's data | 1325 | /* |
1269 | ** is in the unformatted node. | 1326 | * note, we do the copy before preparing the buffer because we |
1270 | ** | 1327 | * don't care about the contents of the unformatted node yet. |
1271 | ** Otherwise, we would have to call reiserfs_prepare_for_journal on | 1328 | * the only thing we really care about is the direct item's |
1272 | ** the unformatted node, which might schedule, meaning we'd have to | 1329 | * data is in the unformatted node. |
1273 | ** loop all the way back up to the start of the while loop. | 1330 | * |
1274 | ** | 1331 | * Otherwise, we would have to call |
1275 | ** The unformatted node must be dirtied later on. We can't be | 1332 | * reiserfs_prepare_for_journal on the unformatted node, |
1276 | ** sure here if the entire tail has been deleted yet. | 1333 | * which might schedule, meaning we'd have to loop all the |
1277 | ** | 1334 | * way back up to the start of the while loop. |
1278 | ** un_bh is from the page cache (all unformatted nodes are | 1335 | * |
1279 | ** from the page cache) and might be a highmem page. So, we | 1336 | * The unformatted node must be dirtied later on. We can't be |
1280 | ** can't use un_bh->b_data. | 1337 | * sure here if the entire tail has been deleted yet. |
1281 | ** -clm | 1338 | * |
1339 | * un_bh is from the page cache (all unformatted nodes are | ||
1340 | * from the page cache) and might be a highmem page. So, we | ||
1341 | * can't use un_bh->b_data. | ||
1342 | * -clm | ||
1282 | */ | 1343 | */ |
1283 | 1344 | ||
1284 | data = kmap_atomic(un_bh->b_page); | 1345 | data = kmap_atomic(un_bh->b_page); |
@@ -1288,6 +1349,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, | |||
1288 | ret_value); | 1349 | ret_value); |
1289 | kunmap_atomic(data); | 1350 | kunmap_atomic(data); |
1290 | } | 1351 | } |
1352 | |||
1291 | /* Perform balancing after all resources have been collected at once. */ | 1353 | /* Perform balancing after all resources have been collected at once. */ |
1292 | do_balance(&s_del_balance, NULL, NULL, M_DELETE); | 1354 | do_balance(&s_del_balance, NULL, NULL, M_DELETE); |
1293 | 1355 | ||
@@ -1304,20 +1366,21 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, | |||
1304 | return ret_value; | 1366 | return ret_value; |
1305 | } | 1367 | } |
1306 | 1368 | ||
1307 | /* Summary Of Mechanisms For Handling Collisions Between Processes: | 1369 | /* |
1308 | 1370 | * Summary Of Mechanisms For Handling Collisions Between Processes: | |
1309 | deletion of the body of the object is performed by iput(), with the | 1371 | * |
1310 | result that if multiple processes are operating on a file, the | 1372 | * deletion of the body of the object is performed by iput(), with the |
1311 | deletion of the body of the file is deferred until the last process | 1373 | * result that if multiple processes are operating on a file, the |
1312 | that has an open inode performs its iput(). | 1374 | * deletion of the body of the file is deferred until the last process |
1313 | 1375 | * that has an open inode performs its iput(). | |
1314 | writes and truncates are protected from collisions by use of | 1376 | * |
1315 | semaphores. | 1377 | * writes and truncates are protected from collisions by use of |
1316 | 1378 | * semaphores. | |
1317 | creates, linking, and mknod are protected from collisions with other | 1379 | * |
1318 | processes by making the reiserfs_add_entry() the last step in the | 1380 | * creates, linking, and mknod are protected from collisions with other |
1319 | creation, and then rolling back all changes if there was a collision. | 1381 | * processes by making the reiserfs_add_entry() the last step in the |
1320 | - Hans | 1382 | * creation, and then rolling back all changes if there was a collision. |
1383 | * - Hans | ||
1321 | */ | 1384 | */ |
1322 | 1385 | ||
1323 | /* this deletes item which never gets split */ | 1386 | /* this deletes item which never gets split */ |
@@ -1347,7 +1410,11 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, | |||
1347 | } | 1410 | } |
1348 | if (retval != ITEM_FOUND) { | 1411 | if (retval != ITEM_FOUND) { |
1349 | pathrelse(&path); | 1412 | pathrelse(&path); |
1350 | // No need for a warning, if there is just no free space to insert '..' item into the newly-created subdir | 1413 | /* |
1414 | * No need for a warning, if there is just no free | ||
1415 | * space to insert '..' item into the | ||
1416 | * newly-created subdir | ||
1417 | */ | ||
1351 | if (! | 1418 | if (! |
1352 | ((unsigned long long) | 1419 | ((unsigned long long) |
1353 | GET_HASH_VALUE(le_key_k_offset | 1420 | GET_HASH_VALUE(le_key_k_offset |
@@ -1376,7 +1443,11 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, | |||
1376 | 1443 | ||
1377 | if (retval == CARRY_ON) { | 1444 | if (retval == CARRY_ON) { |
1378 | do_balance(&tb, NULL, NULL, M_DELETE); | 1445 | do_balance(&tb, NULL, NULL, M_DELETE); |
1379 | if (inode) { /* Should we count quota for item? (we don't count quotas for save-links) */ | 1446 | /* |
1447 | * Should we count quota for item? (we don't | ||
1448 | * count quotas for save-links) | ||
1449 | */ | ||
1450 | if (inode) { | ||
1380 | int depth; | 1451 | int depth; |
1381 | #ifdef REISERQUOTA_DEBUG | 1452 | #ifdef REISERQUOTA_DEBUG |
1382 | reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE, | 1453 | reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE, |
@@ -1391,7 +1462,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, | |||
1391 | } | 1462 | } |
1392 | break; | 1463 | break; |
1393 | } | 1464 | } |
1394 | // IO_ERROR, NO_DISK_SPACE, etc | 1465 | |
1466 | /* IO_ERROR, NO_DISK_SPACE, etc */ | ||
1395 | reiserfs_warning(th->t_super, "vs-5360", | 1467 | reiserfs_warning(th->t_super, "vs-5360", |
1396 | "could not delete %K due to fix_nodes failure", | 1468 | "could not delete %K due to fix_nodes failure", |
1397 | &cpu_key); | 1469 | &cpu_key); |
@@ -1447,11 +1519,13 @@ static void unmap_buffers(struct page *page, loff_t pos) | |||
1447 | do { | 1519 | do { |
1448 | next = bh->b_this_page; | 1520 | next = bh->b_this_page; |
1449 | 1521 | ||
1450 | /* we want to unmap the buffers that contain the tail, and | 1522 | /* |
1451 | ** all the buffers after it (since the tail must be at the | 1523 | * we want to unmap the buffers that contain |
1452 | ** end of the file). We don't want to unmap file data | 1524 | * the tail, and all the buffers after it |
1453 | ** before the tail, since it might be dirty and waiting to | 1525 | * (since the tail must be at the end of the |
1454 | ** reach disk | 1526 | * file). We don't want to unmap file data |
1527 | * before the tail, since it might be dirty | ||
1528 | * and waiting to reach disk | ||
1455 | */ | 1529 | */ |
1456 | cur_index += bh->b_size; | 1530 | cur_index += bh->b_size; |
1457 | if (cur_index > tail_index) { | 1531 | if (cur_index > tail_index) { |
@@ -1476,9 +1550,10 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, | |||
1476 | BUG_ON(!th->t_trans_id); | 1550 | BUG_ON(!th->t_trans_id); |
1477 | BUG_ON(new_file_size != inode->i_size); | 1551 | BUG_ON(new_file_size != inode->i_size); |
1478 | 1552 | ||
1479 | /* the page being sent in could be NULL if there was an i/o error | 1553 | /* |
1480 | ** reading in the last block. The user will hit problems trying to | 1554 | * the page being sent in could be NULL if there was an i/o error |
1481 | ** read the file, but for now we just skip the indirect2direct | 1555 | * reading in the last block. The user will hit problems trying to |
1556 | * read the file, but for now we just skip the indirect2direct | ||
1482 | */ | 1557 | */ |
1483 | if (atomic_read(&inode->i_count) > 1 || | 1558 | if (atomic_read(&inode->i_count) > 1 || |
1484 | !tail_has_to_be_packed(inode) || | 1559 | !tail_has_to_be_packed(inode) || |
@@ -1490,17 +1565,18 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, | |||
1490 | pathrelse(path); | 1565 | pathrelse(path); |
1491 | return cut_bytes; | 1566 | return cut_bytes; |
1492 | } | 1567 | } |
1568 | |||
1493 | /* Perform the conversion to a direct_item. */ | 1569 | /* Perform the conversion to a direct_item. */ |
1494 | /* return indirect_to_direct(inode, path, item_key, | ||
1495 | new_file_size, mode); */ | ||
1496 | return indirect2direct(th, inode, page, path, item_key, | 1570 | return indirect2direct(th, inode, page, path, item_key, |
1497 | new_file_size, mode); | 1571 | new_file_size, mode); |
1498 | } | 1572 | } |
1499 | 1573 | ||
1500 | /* we did indirect_to_direct conversion. And we have inserted direct | 1574 | /* |
1501 | item successesfully, but there were no disk space to cut unfm | 1575 | * we did indirect_to_direct conversion. And we have inserted direct |
1502 | pointer being converted. Therefore we have to delete inserted | 1576 | * item successesfully, but there were no disk space to cut unfm |
1503 | direct item(s) */ | 1577 | * pointer being converted. Therefore we have to delete inserted |
1578 | * direct item(s) | ||
1579 | */ | ||
1504 | static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, | 1580 | static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, |
1505 | struct inode *inode, struct treepath *path) | 1581 | struct inode *inode, struct treepath *path) |
1506 | { | 1582 | { |
@@ -1509,7 +1585,7 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, | |||
1509 | int removed; | 1585 | int removed; |
1510 | BUG_ON(!th->t_trans_id); | 1586 | BUG_ON(!th->t_trans_id); |
1511 | 1587 | ||
1512 | make_cpu_key(&tail_key, inode, inode->i_size + 1, TYPE_DIRECT, 4); // !!!! | 1588 | make_cpu_key(&tail_key, inode, inode->i_size + 1, TYPE_DIRECT, 4); |
1513 | tail_key.key_length = 4; | 1589 | tail_key.key_length = 4; |
1514 | 1590 | ||
1515 | tail_len = | 1591 | tail_len = |
@@ -1539,7 +1615,6 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, | |||
1539 | reiserfs_warning(inode->i_sb, "reiserfs-5091", "indirect_to_direct " | 1615 | reiserfs_warning(inode->i_sb, "reiserfs-5091", "indirect_to_direct " |
1540 | "conversion has been rolled back due to " | 1616 | "conversion has been rolled back due to " |
1541 | "lack of disk space"); | 1617 | "lack of disk space"); |
1542 | //mark_file_without_tail (inode); | ||
1543 | mark_inode_dirty(inode); | 1618 | mark_inode_dirty(inode); |
1544 | } | 1619 | } |
1545 | 1620 | ||
@@ -1551,15 +1626,18 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1551 | struct page *page, loff_t new_file_size) | 1626 | struct page *page, loff_t new_file_size) |
1552 | { | 1627 | { |
1553 | struct super_block *sb = inode->i_sb; | 1628 | struct super_block *sb = inode->i_sb; |
1554 | /* Every function which is going to call do_balance must first | 1629 | /* |
1555 | create a tree_balance structure. Then it must fill up this | 1630 | * Every function which is going to call do_balance must first |
1556 | structure by using the init_tb_struct and fix_nodes functions. | 1631 | * create a tree_balance structure. Then it must fill up this |
1557 | After that we can make tree balancing. */ | 1632 | * structure by using the init_tb_struct and fix_nodes functions. |
1633 | * After that we can make tree balancing. | ||
1634 | */ | ||
1558 | struct tree_balance s_cut_balance; | 1635 | struct tree_balance s_cut_balance; |
1559 | struct item_head *p_le_ih; | 1636 | struct item_head *p_le_ih; |
1560 | int cut_size = 0, /* Amount to be cut. */ | 1637 | int cut_size = 0; /* Amount to be cut. */ |
1561 | ret_value = CARRY_ON, removed = 0, /* Number of the removed unformatted nodes. */ | 1638 | int ret_value = CARRY_ON; |
1562 | is_inode_locked = 0; | 1639 | int removed = 0; /* Number of the removed unformatted nodes. */ |
1640 | int is_inode_locked = 0; | ||
1563 | char mode; /* Mode of the balance. */ | 1641 | char mode; /* Mode of the balance. */ |
1564 | int retval2 = -1; | 1642 | int retval2 = -1; |
1565 | int quota_cut_bytes; | 1643 | int quota_cut_bytes; |
@@ -1571,21 +1649,27 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1571 | init_tb_struct(th, &s_cut_balance, inode->i_sb, path, | 1649 | init_tb_struct(th, &s_cut_balance, inode->i_sb, path, |
1572 | cut_size); | 1650 | cut_size); |
1573 | 1651 | ||
1574 | /* Repeat this loop until we either cut the item without needing | 1652 | /* |
1575 | to balance, or we fix_nodes without schedule occurring */ | 1653 | * Repeat this loop until we either cut the item without needing |
1654 | * to balance, or we fix_nodes without schedule occurring | ||
1655 | */ | ||
1576 | while (1) { | 1656 | while (1) { |
1577 | /* Determine the balance mode, position of the first byte to | 1657 | /* |
1578 | be cut, and size to be cut. In case of the indirect item | 1658 | * Determine the balance mode, position of the first byte to |
1579 | free unformatted nodes which are pointed to by the cut | 1659 | * be cut, and size to be cut. In case of the indirect item |
1580 | pointers. */ | 1660 | * free unformatted nodes which are pointed to by the cut |
1661 | * pointers. | ||
1662 | */ | ||
1581 | 1663 | ||
1582 | mode = | 1664 | mode = |
1583 | prepare_for_delete_or_cut(th, inode, path, | 1665 | prepare_for_delete_or_cut(th, inode, path, |
1584 | item_key, &removed, | 1666 | item_key, &removed, |
1585 | &cut_size, new_file_size); | 1667 | &cut_size, new_file_size); |
1586 | if (mode == M_CONVERT) { | 1668 | if (mode == M_CONVERT) { |
1587 | /* convert last unformatted node to direct item or leave | 1669 | /* |
1588 | tail in the unformatted node */ | 1670 | * convert last unformatted node to direct item or |
1671 | * leave tail in the unformatted node | ||
1672 | */ | ||
1589 | RFALSE(ret_value != CARRY_ON, | 1673 | RFALSE(ret_value != CARRY_ON, |
1590 | "PAP-5570: can not convert twice"); | 1674 | "PAP-5570: can not convert twice"); |
1591 | 1675 | ||
@@ -1599,15 +1683,20 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1599 | 1683 | ||
1600 | is_inode_locked = 1; | 1684 | is_inode_locked = 1; |
1601 | 1685 | ||
1602 | /* removing of last unformatted node will change value we | 1686 | /* |
1603 | have to return to truncate. Save it */ | 1687 | * removing of last unformatted node will |
1688 | * change value we have to return to truncate. | ||
1689 | * Save it | ||
1690 | */ | ||
1604 | retval2 = ret_value; | 1691 | retval2 = ret_value; |
1605 | /*retval2 = sb->s_blocksize - (new_file_size & (sb->s_blocksize - 1)); */ | ||
1606 | 1692 | ||
1607 | /* So, we have performed the first part of the conversion: | 1693 | /* |
1608 | inserting the new direct item. Now we are removing the | 1694 | * So, we have performed the first part of the |
1609 | last unformatted node pointer. Set key to search for | 1695 | * conversion: |
1610 | it. */ | 1696 | * inserting the new direct item. Now we are |
1697 | * removing the last unformatted node pointer. | ||
1698 | * Set key to search for it. | ||
1699 | */ | ||
1611 | set_cpu_key_k_type(item_key, TYPE_INDIRECT); | 1700 | set_cpu_key_k_type(item_key, TYPE_INDIRECT); |
1612 | item_key->key_length = 4; | 1701 | item_key->key_length = 4; |
1613 | new_file_size -= | 1702 | new_file_size -= |
@@ -1650,11 +1739,13 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1650 | return (ret_value == IO_ERROR) ? -EIO : -ENOENT; | 1739 | return (ret_value == IO_ERROR) ? -EIO : -ENOENT; |
1651 | } /* while */ | 1740 | } /* while */ |
1652 | 1741 | ||
1653 | // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) | 1742 | /* check fix_nodes results (IO_ERROR or NO_DISK_SPACE) */ |
1654 | if (ret_value != CARRY_ON) { | 1743 | if (ret_value != CARRY_ON) { |
1655 | if (is_inode_locked) { | 1744 | if (is_inode_locked) { |
1656 | // FIXME: this seems to be not needed: we are always able | 1745 | /* |
1657 | // to cut item | 1746 | * FIXME: this seems to be not needed: we are always |
1747 | * able to cut item | ||
1748 | */ | ||
1658 | indirect_to_direct_roll_back(th, inode, path); | 1749 | indirect_to_direct_roll_back(th, inode, path); |
1659 | } | 1750 | } |
1660 | if (ret_value == NO_DISK_SPACE) | 1751 | if (ret_value == NO_DISK_SPACE) |
@@ -1678,15 +1769,16 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1678 | else | 1769 | else |
1679 | ret_value = retval2; | 1770 | ret_value = retval2; |
1680 | 1771 | ||
1681 | /* For direct items, we only change the quota when deleting the last | 1772 | /* |
1682 | ** item. | 1773 | * For direct items, we only change the quota when deleting the last |
1774 | * item. | ||
1683 | */ | 1775 | */ |
1684 | p_le_ih = tp_item_head(s_cut_balance.tb_path); | 1776 | p_le_ih = tp_item_head(s_cut_balance.tb_path); |
1685 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) { | 1777 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) { |
1686 | if (mode == M_DELETE && | 1778 | if (mode == M_DELETE && |
1687 | (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) == | 1779 | (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) == |
1688 | 1) { | 1780 | 1) { |
1689 | // FIXME: this is to keep 3.5 happy | 1781 | /* FIXME: this is to keep 3.5 happy */ |
1690 | REISERFS_I(inode)->i_first_direct_byte = U32_MAX; | 1782 | REISERFS_I(inode)->i_first_direct_byte = U32_MAX; |
1691 | quota_cut_bytes = sb->s_blocksize + UNFM_P_SIZE; | 1783 | quota_cut_bytes = sb->s_blocksize + UNFM_P_SIZE; |
1692 | } else { | 1784 | } else { |
@@ -1697,9 +1789,11 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1697 | if (is_inode_locked) { | 1789 | if (is_inode_locked) { |
1698 | struct item_head *le_ih = | 1790 | struct item_head *le_ih = |
1699 | tp_item_head(s_cut_balance.tb_path); | 1791 | tp_item_head(s_cut_balance.tb_path); |
1700 | /* we are going to complete indirect2direct conversion. Make | 1792 | /* |
1701 | sure, that we exactly remove last unformatted node pointer | 1793 | * we are going to complete indirect2direct conversion. Make |
1702 | of the item */ | 1794 | * sure, that we exactly remove last unformatted node pointer |
1795 | * of the item | ||
1796 | */ | ||
1703 | if (!is_indirect_le_ih(le_ih)) | 1797 | if (!is_indirect_le_ih(le_ih)) |
1704 | reiserfs_panic(sb, "vs-5652", | 1798 | reiserfs_panic(sb, "vs-5652", |
1705 | "item must be indirect %h", le_ih); | 1799 | "item must be indirect %h", le_ih); |
@@ -1717,17 +1811,20 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, | |||
1717 | "(CUT, insert_size==%d)", | 1811 | "(CUT, insert_size==%d)", |
1718 | le_ih, s_cut_balance.insert_size[0]); | 1812 | le_ih, s_cut_balance.insert_size[0]); |
1719 | } | 1813 | } |
1720 | /* it would be useful to make sure, that right neighboring | 1814 | /* |
1721 | item is direct item of this file */ | 1815 | * it would be useful to make sure, that right neighboring |
1816 | * item is direct item of this file | ||
1817 | */ | ||
1722 | } | 1818 | } |
1723 | #endif | 1819 | #endif |
1724 | 1820 | ||
1725 | do_balance(&s_cut_balance, NULL, NULL, mode); | 1821 | do_balance(&s_cut_balance, NULL, NULL, mode); |
1726 | if (is_inode_locked) { | 1822 | if (is_inode_locked) { |
1727 | /* we've done an indirect->direct conversion. when the data block | 1823 | /* |
1728 | ** was freed, it was removed from the list of blocks that must | 1824 | * we've done an indirect->direct conversion. when the |
1729 | ** be flushed before the transaction commits, make sure to | 1825 | * data block was freed, it was removed from the list of |
1730 | ** unmap and invalidate it | 1826 | * blocks that must be flushed before the transaction |
1827 | * commits, make sure to unmap and invalidate it | ||
1731 | */ | 1828 | */ |
1732 | unmap_buffers(page, tail_pos); | 1829 | unmap_buffers(page, tail_pos); |
1733 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; | 1830 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; |
@@ -1758,20 +1855,25 @@ static void truncate_directory(struct reiserfs_transaction_handle *th, | |||
1758 | set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_STAT_DATA); | 1855 | set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_STAT_DATA); |
1759 | } | 1856 | } |
1760 | 1857 | ||
1761 | /* Truncate file to the new size. Note, this must be called with a transaction | 1858 | /* |
1762 | already started */ | 1859 | * Truncate file to the new size. Note, this must be called with a |
1860 | * transaction already started | ||
1861 | */ | ||
1763 | int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | 1862 | int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, |
1764 | struct inode *inode, /* ->i_size contains new size */ | 1863 | struct inode *inode, /* ->i_size contains new size */ |
1765 | struct page *page, /* up to date for last block */ | 1864 | struct page *page, /* up to date for last block */ |
1766 | int update_timestamps /* when it is called by | 1865 | /* |
1767 | file_release to convert | 1866 | * when it is called by file_release to convert |
1768 | the tail - no timestamps | 1867 | * the tail - no timestamps should be updated |
1769 | should be updated */ | 1868 | */ |
1869 | int update_timestamps | ||
1770 | ) | 1870 | ) |
1771 | { | 1871 | { |
1772 | INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ | 1872 | INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ |
1773 | struct item_head *p_le_ih; /* Pointer to an item header. */ | 1873 | struct item_head *p_le_ih; /* Pointer to an item header. */ |
1774 | struct cpu_key s_item_key; /* Key to search for a previous file item. */ | 1874 | |
1875 | /* Key to search for a previous file item. */ | ||
1876 | struct cpu_key s_item_key; | ||
1775 | loff_t file_size, /* Old file size. */ | 1877 | loff_t file_size, /* Old file size. */ |
1776 | new_file_size; /* New file size. */ | 1878 | new_file_size; /* New file size. */ |
1777 | int deleted; /* Number of deleted or truncated bytes. */ | 1879 | int deleted; /* Number of deleted or truncated bytes. */ |
@@ -1784,8 +1886,8 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | |||
1784 | || S_ISLNK(inode->i_mode))) | 1886 | || S_ISLNK(inode->i_mode))) |
1785 | return 0; | 1887 | return 0; |
1786 | 1888 | ||
1889 | /* deletion of directory - no need to update timestamps */ | ||
1787 | if (S_ISDIR(inode->i_mode)) { | 1890 | if (S_ISDIR(inode->i_mode)) { |
1788 | // deletion of directory - no need to update timestamps | ||
1789 | truncate_directory(th, inode); | 1891 | truncate_directory(th, inode); |
1790 | return 0; | 1892 | return 0; |
1791 | } | 1893 | } |
@@ -1793,7 +1895,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | |||
1793 | /* Get new file size. */ | 1895 | /* Get new file size. */ |
1794 | new_file_size = inode->i_size; | 1896 | new_file_size = inode->i_size; |
1795 | 1897 | ||
1796 | // FIXME: note, that key type is unimportant here | 1898 | /* FIXME: note, that key type is unimportant here */ |
1797 | make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode), | 1899 | make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode), |
1798 | TYPE_DIRECT, 3); | 1900 | TYPE_DIRECT, 3); |
1799 | 1901 | ||
@@ -1827,9 +1929,11 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | |||
1827 | int bytes = | 1929 | int bytes = |
1828 | op_bytes_number(p_le_ih, inode->i_sb->s_blocksize); | 1930 | op_bytes_number(p_le_ih, inode->i_sb->s_blocksize); |
1829 | 1931 | ||
1830 | /* this may mismatch with real file size: if last direct item | 1932 | /* |
1831 | had no padding zeros and last unformatted node had no free | 1933 | * this may mismatch with real file size: if last direct item |
1832 | space, this file would have this file size */ | 1934 | * had no padding zeros and last unformatted node had no free |
1935 | * space, this file would have this file size | ||
1936 | */ | ||
1833 | file_size = offset + bytes - 1; | 1937 | file_size = offset + bytes - 1; |
1834 | } | 1938 | } |
1835 | /* | 1939 | /* |
@@ -1867,14 +1971,17 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | |||
1867 | 1971 | ||
1868 | set_cpu_key_k_offset(&s_item_key, file_size); | 1972 | set_cpu_key_k_offset(&s_item_key, file_size); |
1869 | 1973 | ||
1870 | /* While there are bytes to truncate and previous file item is presented in the tree. */ | 1974 | /* |
1975 | * While there are bytes to truncate and previous | ||
1976 | * file item is presented in the tree. | ||
1977 | */ | ||
1871 | 1978 | ||
1872 | /* | 1979 | /* |
1873 | ** This loop could take a really long time, and could log | 1980 | * This loop could take a really long time, and could log |
1874 | ** many more blocks than a transaction can hold. So, we do a polite | 1981 | * many more blocks than a transaction can hold. So, we do |
1875 | ** journal end here, and if the transaction needs ending, we make | 1982 | * a polite journal end here, and if the transaction needs |
1876 | ** sure the file is consistent before ending the current trans | 1983 | * ending, we make sure the file is consistent before ending |
1877 | ** and starting a new one | 1984 | * the current trans and starting a new one |
1878 | */ | 1985 | */ |
1879 | if (journal_transaction_should_end(th, 0) || | 1986 | if (journal_transaction_should_end(th, 0) || |
1880 | reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { | 1987 | reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { |
@@ -1906,7 +2013,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | |||
1906 | 2013 | ||
1907 | update_and_out: | 2014 | update_and_out: |
1908 | if (update_timestamps) { | 2015 | if (update_timestamps) { |
1909 | // this is truncate, not file closing | 2016 | /* this is truncate, not file closing */ |
1910 | inode->i_mtime = CURRENT_TIME_SEC; | 2017 | inode->i_mtime = CURRENT_TIME_SEC; |
1911 | inode->i_ctime = CURRENT_TIME_SEC; | 2018 | inode->i_ctime = CURRENT_TIME_SEC; |
1912 | } | 2019 | } |
@@ -1918,7 +2025,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, | |||
1918 | } | 2025 | } |
1919 | 2026 | ||
1920 | #ifdef CONFIG_REISERFS_CHECK | 2027 | #ifdef CONFIG_REISERFS_CHECK |
1921 | // this makes sure, that we __append__, not overwrite or add holes | 2028 | /* this makes sure, that we __append__, not overwrite or add holes */ |
1922 | static void check_research_for_paste(struct treepath *path, | 2029 | static void check_research_for_paste(struct treepath *path, |
1923 | const struct cpu_key *key) | 2030 | const struct cpu_key *key) |
1924 | { | 2031 | { |
@@ -1952,13 +2059,22 @@ static void check_research_for_paste(struct treepath *path, | |||
1952 | } | 2059 | } |
1953 | #endif /* config reiserfs check */ | 2060 | #endif /* config reiserfs check */ |
1954 | 2061 | ||
1955 | /* Paste bytes to the existing item. Returns bytes number pasted into the item. */ | 2062 | /* |
1956 | int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *search_path, /* Path to the pasted item. */ | 2063 | * Paste bytes to the existing item. |
1957 | const struct cpu_key *key, /* Key to search for the needed item. */ | 2064 | * Returns bytes number pasted into the item. |
1958 | struct inode *inode, /* Inode item belongs to */ | 2065 | */ |
1959 | const char *body, /* Pointer to the bytes to paste. */ | 2066 | int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, |
2067 | /* Path to the pasted item. */ | ||
2068 | struct treepath *search_path, | ||
2069 | /* Key to search for the needed item. */ | ||
2070 | const struct cpu_key *key, | ||
2071 | /* Inode item belongs to */ | ||
2072 | struct inode *inode, | ||
2073 | /* Pointer to the bytes to paste. */ | ||
2074 | const char *body, | ||
2075 | /* Size of pasted bytes. */ | ||
1960 | int pasted_size) | 2076 | int pasted_size) |
1961 | { /* Size of pasted bytes. */ | 2077 | { |
1962 | struct super_block *sb = inode->i_sb; | 2078 | struct super_block *sb = inode->i_sb; |
1963 | struct tree_balance s_paste_balance; | 2079 | struct tree_balance s_paste_balance; |
1964 | int retval; | 2080 | int retval; |
@@ -2019,8 +2135,10 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree | |||
2019 | #endif | 2135 | #endif |
2020 | } | 2136 | } |
2021 | 2137 | ||
2022 | /* Perform balancing after all resources are collected by fix_nodes, and | 2138 | /* |
2023 | accessing them will not risk triggering schedule. */ | 2139 | * Perform balancing after all resources are collected by fix_nodes, |
2140 | * and accessing them will not risk triggering schedule. | ||
2141 | */ | ||
2024 | if (retval == CARRY_ON) { | 2142 | if (retval == CARRY_ON) { |
2025 | do_balance(&s_paste_balance, NULL /*ih */ , body, M_PASTE); | 2143 | do_balance(&s_paste_balance, NULL /*ih */ , body, M_PASTE); |
2026 | return 0; | 2144 | return 0; |
@@ -2041,7 +2159,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree | |||
2041 | return retval; | 2159 | return retval; |
2042 | } | 2160 | } |
2043 | 2161 | ||
2044 | /* Insert new item into the buffer at the path. | 2162 | /* |
2163 | * Insert new item into the buffer at the path. | ||
2045 | * th - active transaction handle | 2164 | * th - active transaction handle |
2046 | * path - path to the inserted item | 2165 | * path - path to the inserted item |
2047 | * ih - pointer to the item header to insert | 2166 | * ih - pointer to the item header to insert |
@@ -2064,8 +2183,10 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, | |||
2064 | fs_gen = get_generation(inode->i_sb); | 2183 | fs_gen = get_generation(inode->i_sb); |
2065 | quota_bytes = ih_item_len(ih); | 2184 | quota_bytes = ih_item_len(ih); |
2066 | 2185 | ||
2067 | /* hack so the quota code doesn't have to guess if the file has | 2186 | /* |
2068 | ** a tail, links are always tails, so there's no guessing needed | 2187 | * hack so the quota code doesn't have to guess |
2188 | * if the file has a tail, links are always tails, | ||
2189 | * so there's no guessing needed | ||
2069 | */ | 2190 | */ |
2070 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(ih)) | 2191 | if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(ih)) |
2071 | quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE; | 2192 | quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE; |
@@ -2074,8 +2195,10 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, | |||
2074 | "reiserquota insert_item(): allocating %u id=%u type=%c", | 2195 | "reiserquota insert_item(): allocating %u id=%u type=%c", |
2075 | quota_bytes, inode->i_uid, head2type(ih)); | 2196 | quota_bytes, inode->i_uid, head2type(ih)); |
2076 | #endif | 2197 | #endif |
2077 | /* We can't dirty inode here. It would be immediately written but | 2198 | /* |
2078 | * appropriate stat item isn't inserted yet... */ | 2199 | * We can't dirty inode here. It would be immediately |
2200 | * written but appropriate stat item isn't inserted yet... | ||
2201 | */ | ||
2079 | depth = reiserfs_write_unlock_nested(inode->i_sb); | 2202 | depth = reiserfs_write_unlock_nested(inode->i_sb); |
2080 | retval = dquot_alloc_space_nodirty(inode, quota_bytes); | 2203 | retval = dquot_alloc_space_nodirty(inode, quota_bytes); |
2081 | reiserfs_write_lock_nested(inode->i_sb, depth); | 2204 | reiserfs_write_lock_nested(inode->i_sb, depth); |
@@ -2089,7 +2212,10 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, | |||
2089 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 2212 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
2090 | s_ins_balance.key = key->on_disk_key; | 2213 | s_ins_balance.key = key->on_disk_key; |
2091 | #endif | 2214 | #endif |
2092 | /* DQUOT_* can schedule, must check to be sure calling fix_nodes is safe */ | 2215 | /* |
2216 | * DQUOT_* can schedule, must check to be sure calling | ||
2217 | * fix_nodes is safe | ||
2218 | */ | ||
2093 | if (inode && fs_changed(fs_gen, inode->i_sb)) { | 2219 | if (inode && fs_changed(fs_gen, inode->i_sb)) { |
2094 | goto search_again; | 2220 | goto search_again; |
2095 | } | 2221 | } |