summaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/stree.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-12 20:21:28 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-12 20:21:28 -0700
commitbd4c625c061c2a38568d0add3478f59172455159 (patch)
tree1c44a17c55bce2ee7ad5ea3d15a208ecc0955f74 /fs/reiserfs/stree.c
parent7fa94c8868edfef8cb6a201fcc9a5078b7b961da (diff)
reiserfs: run scripts/Lindent on reiserfs code
This was a pure indentation change, using: scripts/Lindent fs/reiserfs/*.c include/linux/reiserfs_*.h to make reiserfs match the regular Linux indentation style. As Jeff Mahoney <jeffm@suse.com> writes: The ReiserFS code is a mix of a number of different coding styles, sometimes different even from line-to-line. Since the code has been relatively stable for quite some time and there are few outstanding patches to be applied, it is time to reformat the code to conform to the Linux style standard outlined in Documentation/CodingStyle. This patch contains the result of running scripts/Lindent against fs/reiserfs/*.c and include/linux/reiserfs_*.h. There are places where the code can be made to look better, but I'd rather keep those patches separate so that there isn't a subtle by-hand hand accident in the middle of a huge patch. To be clear: This patch is reformatting *only*. A number of patches may follow that continue to make the code more consistent with the Linux coding style. Hans wasn't particularly enthusiastic about these patches, but said he wouldn't really oppose them either. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/reiserfs/stree.c')
-rw-r--r--fs/reiserfs/stree.c3369
1 files changed, 1743 insertions, 1626 deletions
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 63158491e152..e2d08d7bcffc 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -59,46 +59,45 @@
#include <linux/quotaops.h>
/* Does the buffer contain a disk block which is in the tree. */
-inline int B_IS_IN_TREE (const struct buffer_head * p_s_bh)
+inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
{
- RFALSE( B_LEVEL (p_s_bh) > MAX_HEIGHT,
- "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh);
+ RFALSE(B_LEVEL(p_s_bh) > MAX_HEIGHT,
+ "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh);
- return ( B_LEVEL (p_s_bh) != FREE_LEVEL );
+ return (B_LEVEL(p_s_bh) != FREE_LEVEL);
}
//
// to gets item head in le form
//
-inline void copy_item_head(struct item_head * p_v_to,
- const struct item_head * p_v_from)
+inline void copy_item_head(struct item_head *p_v_to,
+ const struct item_head *p_v_from)
{
- memcpy (p_v_to, p_v_from, IH_SIZE);
+ memcpy(p_v_to, p_v_from, IH_SIZE);
}
-
/* k1 is pointer to on-disk structure which is stored in little-endian
form. k2 is pointer to cpu variable. For key of items of the same
object this returns 0.
Returns: -1 if key1 < key2
0 if key1 == key2
1 if key1 > key2 */
-inline int comp_short_keys (const struct reiserfs_key * le_key,
- const struct cpu_key * cpu_key)
+inline int comp_short_keys(const struct reiserfs_key *le_key,
+ const struct cpu_key *cpu_key)
{
- __u32 n;
- n = le32_to_cpu(le_key->k_dir_id);
- if (n < cpu_key->on_disk_key.k_dir_id)
- return -1;
- if (n > cpu_key->on_disk_key.k_dir_id)
- return 1;
- n = le32_to_cpu(le_key->k_objectid);
- if (n < cpu_key->on_disk_key.k_objectid)
- return -1;
- if (n > cpu_key->on_disk_key.k_objectid)
- return 1;
- return 0;
+ __u32 n;
+ n = le32_to_cpu(le_key->k_dir_id);
+ if (n < cpu_key->on_disk_key.k_dir_id)
+ return -1;
+ if (n > cpu_key->on_disk_key.k_dir_id)
+ return 1;
+ n = le32_to_cpu(le_key->k_objectid);
+ if (n < cpu_key->on_disk_key.k_objectid)
+ return -1;
+ if (n > cpu_key->on_disk_key.k_objectid)
+ return 1;
+ return 0;
}
/* k1 is pointer to on-disk structure which is stored in little-endian
@@ -106,68 +105,72 @@ inline int comp_short_keys (const struct reiserfs_key * le_key,
Compare keys using all 4 key fields.
Returns: -1 if key1 < key2 0
if key1 = key2 1 if key1 > key2 */
-static inline int comp_keys (const struct reiserfs_key * le_key, const struct cpu_key * cpu_key)
+static inline int comp_keys(const struct reiserfs_key *le_key,
+ const struct cpu_key *cpu_key)
{
- int retval;
-
- retval = comp_short_keys (le_key, cpu_key);
- if (retval)
- return retval;
- if (le_key_k_offset (le_key_version(le_key), le_key) < cpu_key_k_offset (cpu_key))
- return -1;
- if (le_key_k_offset (le_key_version(le_key), le_key) > cpu_key_k_offset (cpu_key))
- return 1;
-
- if (cpu_key->key_length == 3)
- return 0;
-
- /* this part is needed only when tail conversion is in progress */
- if (le_key_k_type (le_key_version(le_key), le_key) < cpu_key_k_type (cpu_key))
- return -1;
+ int retval;
+
+ retval = comp_short_keys(le_key, cpu_key);
+ if (retval)
+ return retval;
+ if (le_key_k_offset(le_key_version(le_key), le_key) <
+ cpu_key_k_offset(cpu_key))
+ return -1;
+ if (le_key_k_offset(le_key_version(le_key), le_key) >
+ cpu_key_k_offset(cpu_key))
+ return 1;
+
+ if (cpu_key->key_length == 3)
+ return 0;
+
+ /* this part is needed only when tail conversion is in progress */
+ if (le_key_k_type(le_key_version(le_key), le_key) <
+ cpu_key_k_type(cpu_key))
+ return -1;
+
+ if (le_key_k_type(le_key_version(le_key), le_key) >
+ cpu_key_k_type(cpu_key))
+ return 1;
- if (le_key_k_type (le_key_version(le_key), le_key) > cpu_key_k_type (cpu_key))
- return 1;
-
- return 0;
+ return 0;
}
-
-inline int comp_short_le_keys (const struct reiserfs_key * key1, const struct reiserfs_key * key2)
+inline int comp_short_le_keys(const struct reiserfs_key *key1,
+ const struct reiserfs_key *key2)
{
- __u32 * p_s_1_u32, * p_s_2_u32;
- int n_key_length = REISERFS_SHORT_KEY_LEN;
-
- p_s_1_u32 = (__u32 *)key1;
- p_s_2_u32 = (__u32 *)key2;
- for( ; n_key_length--; ++p_s_1_u32, ++p_s_2_u32 ) {
- if ( le32_to_cpu (*p_s_1_u32) < le32_to_cpu (*p_s_2_u32) )
- return -1;
- if ( le32_to_cpu (*p_s_1_u32) > le32_to_cpu (*p_s_2_u32) )
- return 1;
- }
- return 0;
+ __u32 *p_s_1_u32, *p_s_2_u32;
+ int n_key_length = REISERFS_SHORT_KEY_LEN;
+
+ p_s_1_u32 = (__u32 *) key1;
+ p_s_2_u32 = (__u32 *) key2;
+ for (; n_key_length--; ++p_s_1_u32, ++p_s_2_u32) {
+ if (le32_to_cpu(*p_s_1_u32) < le32_to_cpu(*p_s_2_u32))
+ return -1;
+ if (le32_to_cpu(*p_s_1_u32) > le32_to_cpu(*p_s_2_u32))
+ return 1;
+ }
+ return 0;
}
-inline void le_key2cpu_key (struct cpu_key * to, const struct reiserfs_key * from)
+inline void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from)
{
- int version;
- to->on_disk_key.k_dir_id = le32_to_cpu (from->k_dir_id);
- to->on_disk_key.k_objectid = le32_to_cpu (from->k_objectid);
-
- // find out version of the key
- version = le_key_version (from);
- to->version = version;
- to->on_disk_key.k_offset = le_key_k_offset(version, from);
- to->on_disk_key.k_type = le_key_k_type(version, from);
+ int version;
+ to->on_disk_key.k_dir_id = le32_to_cpu(from->k_dir_id);
+ to->on_disk_key.k_objectid = le32_to_cpu(from->k_objectid);
+
+ // find out version of the key
+ version = le_key_version(from);
+ to->version = version;
+ to->on_disk_key.k_offset = le_key_k_offset(version, from);
+ to->on_disk_key.k_type = le_key_k_type(version, from);
}
-
-
// this does not say which one is bigger, it only returns 1 if keys
// are not equal, 0 otherwise
-inline int comp_le_keys (const struct reiserfs_key * k1, const struct reiserfs_key * k2)
+inline int comp_le_keys(const struct reiserfs_key *k1,
+ const struct reiserfs_key *k2)
{
- return memcmp (k1, k2, sizeof (struct reiserfs_key));
+ return memcmp(k1, k2, sizeof(struct reiserfs_key));
}
/**************************************************************************
@@ -184,373 +187,396 @@ inline int comp_le_keys (const struct reiserfs_key * k1, const struct reiserfs_k
there are no possible items, and we have not found it. With each examination we
cut the number of possible items it could be by one more than half rounded down,
or we find it. */
-static inline int bin_search (
- const void * p_v_key, /* Key to search for. */
- const void * p_v_base,/* First item in the array. */
- int p_n_num, /* Number of items in the array. */
- int p_n_width, /* Item size in the array.
- searched. Lest the reader be
- confused, note that this is crafted
- as a general function, and when it
- is applied specifically to the array
- of item headers in a node, p_n_width
- is actually the item header size not
- the item size. */
- int * p_n_pos /* Number of the searched for element. */
- ) {
- int n_rbound, n_lbound, n_j;
-
- for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 )
- switch( comp_keys((struct reiserfs_key *)((char * )p_v_base + n_j * p_n_width), (struct cpu_key *)p_v_key) ) {
- case -1: n_lbound = n_j + 1; continue;
- case 1: n_rbound = n_j - 1; continue;
- case 0: *p_n_pos = n_j; return ITEM_FOUND; /* Key found in the array. */
- }
-
- /* bin_search did not find given key, it returns position of key,
- that is minimal and greater than the given one. */
- *p_n_pos = n_lbound;
- return ITEM_NOT_FOUND;
+static inline int bin_search(const void *p_v_key, /* Key to search for. */
+ const void *p_v_base, /* First item in the array. */
+ int p_n_num, /* Number of items in the array. */
+ int p_n_width, /* Item size in the array.
+ searched. Lest the reader be
+ confused, note that this is crafted
+ as a general function, and when it
+ is applied specifically to the array
+ of item headers in a node, p_n_width
+ is actually the item header size not
+ the item size. */
+ int *p_n_pos /* Number of the searched for element. */
+ )
+{
+ int n_rbound, n_lbound, n_j;
+
+ for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2;
+ n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2)
+ switch (comp_keys
+ ((struct reiserfs_key *)((char *)p_v_base +
+ n_j * p_n_width),
+ (struct cpu_key *)p_v_key)) {
+ case -1:
+ n_lbound = n_j + 1;
+ continue;
+ case 1:
+ n_rbound = n_j - 1;
+ continue;
+ case 0:
+ *p_n_pos = n_j;
+ return ITEM_FOUND; /* Key found in the array. */
+ }
+
+ /* bin_search did not find given key, it returns position of key,
+ that is minimal and greater than the given one. */
+ *p_n_pos = n_lbound;
+ return ITEM_NOT_FOUND;
}
#ifdef CONFIG_REISERFS_CHECK
-extern struct tree_balance * cur_tb;
+extern struct tree_balance *cur_tb;
#endif
-
-
/* Minimal possible key. It is never in the tree. */
-const struct reiserfs_key MIN_KEY = {0, 0, {{0, 0},}};
+const struct reiserfs_key MIN_KEY = { 0, 0, {{0, 0},} };
/* Maximal possible key. It is never in the tree. */
-static const struct reiserfs_key MAX_KEY = {
+static const struct reiserfs_key MAX_KEY = {
__constant_cpu_to_le32(0xffffffff),
__constant_cpu_to_le32(0xffffffff),
{{__constant_cpu_to_le32(0xffffffff),
- __constant_cpu_to_le32(0xffffffff)},}
+ __constant_cpu_to_le32(0xffffffff)},}
};
-
/* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom
of the path, and going upwards. We must check the path's validity at each step. If the key is not in
the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
case we return a special key, either MIN_KEY or MAX_KEY. */
-static inline const struct reiserfs_key * get_lkey (
- const struct path * p_s_chk_path,
- const struct super_block * p_s_sb
- ) {
- int n_position, n_path_offset = p_s_chk_path->path_length;
- struct buffer_head * p_s_parent;
-
- RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
- "PAP-5010: invalid offset in the path");
-
- /* While not higher in path than first element. */
- while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
-
- RFALSE( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
- "PAP-5020: parent is not uptodate");
-
- /* Parent at the path is not in the tree now. */
- if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
- return &MAX_KEY;
- /* Check whether position in the parent is correct. */
- if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
- return &MAX_KEY;
- /* Check whether parent at the path really points to the child. */
- if ( B_N_CHILD_NUM(p_s_parent, n_position) !=
- PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
- return &MAX_KEY;
- /* Return delimiting key if position in the parent is not equal to zero. */
- if ( n_position )
- return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
- }
- /* Return MIN_KEY if we are in the root of the buffer tree. */
- if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
- SB_ROOT_BLOCK (p_s_sb) )
- return &MIN_KEY;
- return &MAX_KEY;
+static inline const struct reiserfs_key *get_lkey(const struct path
+ *p_s_chk_path,
+ const struct super_block
+ *p_s_sb)
+{
+ int n_position, n_path_offset = p_s_chk_path->path_length;
+ struct buffer_head *p_s_parent;
+
+ RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
+ "PAP-5010: invalid offset in the path");
+
+ /* While not higher in path than first element. */
+ while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
+
+ RFALSE(!buffer_uptodate
+ (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
+ "PAP-5020: parent is not uptodate");
+
+ /* Parent at the path is not in the tree now. */
+ if (!B_IS_IN_TREE
+ (p_s_parent =
+ PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
+ return &MAX_KEY;
+ /* Check whether position in the parent is correct. */
+ if ((n_position =
+ PATH_OFFSET_POSITION(p_s_chk_path,
+ n_path_offset)) >
+ B_NR_ITEMS(p_s_parent))
+ return &MAX_KEY;
+ /* Check whether parent at the path really points to the child. */
+ if (B_N_CHILD_NUM(p_s_parent, n_position) !=
+ PATH_OFFSET_PBUFFER(p_s_chk_path,
+ n_path_offset + 1)->b_blocknr)
+ return &MAX_KEY;
+ /* Return delimiting key if position in the parent is not equal to zero. */
+ if (n_position)
+ return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
+ }
+ /* Return MIN_KEY if we are in the root of the buffer tree. */
+ if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
+ b_blocknr == SB_ROOT_BLOCK(p_s_sb))
+ return &MIN_KEY;
+ return &MAX_KEY;
}
-
/* Get delimiting key of the buffer at the path and its right neighbor. */
-inline const struct reiserfs_key * get_rkey (
- const struct path * p_s_chk_path,
- const struct super_block * p_s_sb
- ) {
- int n_position,
- n_path_offset = p_s_chk_path->path_length;
- struct buffer_head * p_s_parent;
-
- RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
- "PAP-5030: invalid offset in the path");
-
- while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
-
- RFALSE( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
- "PAP-5040: parent is not uptodate");
-
- /* Parent at the path is not in the tree now. */
- if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
- return &MIN_KEY;
- /* Check whether position in the parent is correct. */
- if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
- return &MIN_KEY;
- /* Check whether parent at the path really points to the child. */
- if ( B_N_CHILD_NUM(p_s_parent, n_position) !=
- PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
- return &MIN_KEY;
- /* Return delimiting key if position in the parent is not the last one. */
- if ( n_position != B_NR_ITEMS(p_s_parent) )
- return B_N_PDELIM_KEY(p_s_parent, n_position);
- }
- /* Return MAX_KEY if we are in the root of the buffer tree. */
- if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
- SB_ROOT_BLOCK (p_s_sb) )
- return &MAX_KEY;
- return &MIN_KEY;
+inline const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path,
+ const struct super_block *p_s_sb)
+{
+ int n_position, n_path_offset = p_s_chk_path->path_length;
+ struct buffer_head *p_s_parent;
+
+ RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
+ "PAP-5030: invalid offset in the path");
+
+ while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
+
+ RFALSE(!buffer_uptodate
+ (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
+ "PAP-5040: parent is not uptodate");
+
+ /* Parent at the path is not in the tree now. */
+ if (!B_IS_IN_TREE
+ (p_s_parent =
+ PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
+ return &MIN_KEY;
+ /* Check whether position in the parent is correct. */
+ if ((n_position =
+ PATH_OFFSET_POSITION(p_s_chk_path,
+ n_path_offset)) >
+ B_NR_ITEMS(p_s_parent))
+ return &MIN_KEY;
+ /* Check whether parent at the path really points to the child. */
+ if (B_N_CHILD_NUM(p_s_parent, n_position) !=
+ PATH_OFFSET_PBUFFER(p_s_chk_path,
+ n_path_offset + 1)->b_blocknr)
+ return &MIN_KEY;
+ /* Return delimiting key if position in the parent is not the last one. */
+ if (n_position != B_NR_ITEMS(p_s_parent))
+ return B_N_PDELIM_KEY(p_s_parent, n_position);
+ }
+ /* Return MAX_KEY if we are in the root of the buffer tree. */
+ if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
+ b_blocknr == SB_ROOT_BLOCK(p_s_sb))
+ return &MAX_KEY;
+ return &MIN_KEY;
}
-
/* Check whether a key is contained in the tree rooted from a buffer at a path. */
/* This works by looking at the left and right delimiting keys for the buffer in the last path_element in
the path. These delimiting keys are stored at least one level above that buffer in the tree. If the
buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in
this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */
-static inline int key_in_buffer (
- struct path * p_s_chk_path, /* Path which should be checked. */
- const struct cpu_key * p_s_key, /* Key which should be checked. */
- struct super_block * p_s_sb /* Super block pointer. */
- ) {
-
- RFALSE( ! p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET ||
- p_s_chk_path->path_length > MAX_HEIGHT,
- "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
- p_s_key, p_s_chk_path->path_length);
- RFALSE( !PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev,
- "PAP-5060: device must not be NODEV");
-
- if ( comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1 )
- /* left delimiting key is bigger, that the key we look for */
- return 0;
- // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
- if ( comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1 )
- /* p_s_key must be less than right delimitiing key */
- return 0;
- return 1;
-}
-
+static inline int key_in_buffer(struct path *p_s_chk_path, /* Path which should be checked. */
+ const struct cpu_key *p_s_key, /* Key which should be checked. */
+ struct super_block *p_s_sb /* Super block pointer. */
+ )
+{
-inline void decrement_bcount(
- struct buffer_head * p_s_bh
- ) {
- if ( p_s_bh ) {
- if ( atomic_read (&(p_s_bh->b_count)) ) {
- put_bh(p_s_bh) ;
- return;
- }
- reiserfs_panic(NULL, "PAP-5070: decrement_bcount: trying to free free buffer %b", p_s_bh);
- }
+ RFALSE(!p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET
+ || p_s_chk_path->path_length > MAX_HEIGHT,
+ "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
+ p_s_key, p_s_chk_path->path_length);
+ RFALSE(!PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev,
+ "PAP-5060: device must not be NODEV");
+
+ if (comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1)
+ /* left delimiting key is bigger, that the key we look for */
+ return 0;
+ // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
+ if (comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1)
+ /* p_s_key must be less than right delimitiing key */
+ return 0;
+ return 1;
}
+inline void decrement_bcount(struct buffer_head *p_s_bh)
+{
+ if (p_s_bh) {
+ if (atomic_read(&(p_s_bh->b_count))) {
+ put_bh(p_s_bh);
+ return;
+ }
+ reiserfs_panic(NULL,
+ "PAP-5070: decrement_bcount: trying to free free buffer %b",
+ p_s_bh);
+ }
+}
/* Decrement b_count field of the all buffers in the path. */
-void decrement_counters_in_path (
- struct path * p_s_search_path
- ) {
- int n_path_offset = p_s_search_path->path_length;
-
- RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET ||
- n_path_offset > EXTENDED_MAX_HEIGHT - 1,
- "PAP-5080: invalid path offset of %d", n_path_offset);
-
- while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET ) {
- struct buffer_head * bh;
-
- bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
- decrement_bcount (bh);
- }
- p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
-}
+void decrement_counters_in_path(struct path *p_s_search_path)
+{
+ int n_path_offset = p_s_search_path->path_length;
+
+ RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET ||
+ n_path_offset > EXTENDED_MAX_HEIGHT - 1,
+ "PAP-5080: invalid path offset of %d", n_path_offset);
+ while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
+ struct buffer_head *bh;
-int reiserfs_check_path(struct path *p) {
- RFALSE( p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
- "path not properly relsed") ;
- return 0 ;
+ bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
+ decrement_bcount(bh);
+ }
+ p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
}
+int reiserfs_check_path(struct path *p)
+{
+ RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
+ "path not properly relsed");
+ return 0;
+}
/* Release all buffers in the path. Restore dirty bits clean
** when preparing the buffer for the log
**
** only called from fix_nodes()
*/
-void pathrelse_and_restore (
- struct super_block *s,
- struct path * p_s_search_path
- ) {
- int n_path_offset = p_s_search_path->path_length;
-
- RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
- "clm-4000: invalid path offset");
-
- while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET ) {
- reiserfs_restore_prepared_buffer(s, PATH_OFFSET_PBUFFER(p_s_search_path,
- n_path_offset));
- brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
- }
- p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
+void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path)
+{
+ int n_path_offset = p_s_search_path->path_length;
+
+ RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
+ "clm-4000: invalid path offset");
+
+ while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
+ reiserfs_restore_prepared_buffer(s,
+ PATH_OFFSET_PBUFFER
+ (p_s_search_path,
+ n_path_offset));
+ brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
+ }
+ p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
}
/* Release all buffers in the path. */
-void pathrelse (
- struct path * p_s_search_path
- ) {
- int n_path_offset = p_s_search_path->path_length;
-
- RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
- "PAP-5090: invalid path offset");
-
- while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET )
- brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
-
- p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
-}
+void pathrelse(struct path *p_s_search_path)
+{
+ int n_path_offset = p_s_search_path->path_length;
+ RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
+ "PAP-5090: invalid path offset");
+ while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
+ brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
-static int is_leaf (char * buf, int blocksize, struct buffer_head * bh)
-{
- struct block_head * blkh;
- struct item_head * ih;
- int used_space;
- int prev_location;
- int i;
- int nr;
-
- blkh = (struct block_head *)buf;
- if ( blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
- reiserfs_warning (NULL, "is_leaf: this should be caught earlier");
- return 0;
- }
+ p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
+}
- nr = blkh_nr_item(blkh);
- if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) {
- /* item number is too big or too small */
- reiserfs_warning (NULL, "is_leaf: nr_item seems wrong: %z", bh);
- return 0;
- }
- ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1;
- used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location (ih));
- if (used_space != blocksize - blkh_free_space(blkh)) {
- /* free space does not match to calculated amount of use space */
- reiserfs_warning (NULL, "is_leaf: free space seems wrong: %z", bh);
- return 0;
- }
-
- // FIXME: it is_leaf will hit performance too much - we may have
- // return 1 here
-
- /* check tables of item heads */
- ih = (struct item_head *)(buf + BLKH_SIZE);
- prev_location = blocksize;
- for (i = 0; i < nr; i ++, ih ++) {
- if ( le_ih_k_type(ih) == TYPE_ANY) {
- reiserfs_warning (NULL, "is_leaf: wrong item type for item %h",ih);
- return 0;
+static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
+{
+ struct block_head *blkh;
+ struct item_head *ih;
+ int used_space;
+ int prev_location;
+ int i;
+ int nr;
+
+ blkh = (struct block_head *)buf;
+ if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
+ reiserfs_warning(NULL,
+ "is_leaf: this should be caught earlier");
+ return 0;
}
- if (ih_location (ih) >= blocksize || ih_location (ih) < IH_SIZE * nr) {
- reiserfs_warning (NULL, "is_leaf: item location seems wrong: %h", ih);
- return 0;
+
+ nr = blkh_nr_item(blkh);
+ if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) {
+ /* item number is too big or too small */
+ reiserfs_warning(NULL, "is_leaf: nr_item seems wrong: %z", bh);
+ return 0;
}
- if (ih_item_len (ih) < 1 || ih_item_len (ih) > MAX_ITEM_LEN (blocksize)) {
- reiserfs_warning (NULL, "is_leaf: item length seems wrong: %h", ih);
- return 0;
+ ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1;
+ used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih));
+ if (used_space != blocksize - blkh_free_space(blkh)) {
+ /* free space does not match to calculated amount of use space */
+ reiserfs_warning(NULL, "is_leaf: free space seems wrong: %z",
+ bh);
+ return 0;
}
- if (prev_location - ih_location (ih) != ih_item_len (ih)) {
- reiserfs_warning (NULL, "is_leaf: item location seems wrong (second one): %h", ih);
- return 0;
+ // FIXME: it is_leaf will hit performance too much - we may have
+ // return 1 here
+
+ /* check tables of item heads */
+ ih = (struct item_head *)(buf + BLKH_SIZE);
+ prev_location = blocksize;
+ for (i = 0; i < nr; i++, ih++) {
+ if (le_ih_k_type(ih) == TYPE_ANY) {
+ reiserfs_warning(NULL,
+ "is_leaf: wrong item type for item %h",
+ ih);
+ return 0;
+ }
+ if (ih_location(ih) >= blocksize
+ || ih_location(ih) < IH_SIZE * nr) {
+ reiserfs_warning(NULL,
+ "is_leaf: item location seems wrong: %h",
+ ih);
+ return 0;
+ }
+ if (ih_item_len(ih) < 1
+ || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) {
+ reiserfs_warning(NULL,
+ "is_leaf: item length seems wrong: %h",
+ ih);
+ return 0;
+ }
+ if (prev_location - ih_location(ih) != ih_item_len(ih)) {
+ reiserfs_warning(NULL,
+ "is_leaf: item location seems wrong (second one): %h",
+ ih);
+ return 0;
+ }
+ prev_location = ih_location(ih);
}
- prev_location = ih_location (ih);
- }
- // one may imagine much more checks
- return 1;
+ // one may imagine much more checks
+ return 1;
}
-
/* returns 1 if buf looks like an internal node, 0 otherwise */
-static int is_internal (char * buf, int blocksize, struct buffer_head * bh)
+static int is_internal(char *buf, int blocksize, struct buffer_head *bh)
{
- struct block_head * blkh;
- int nr;
- int used_space;
-
- blkh = (struct block_head *)buf;
- nr = blkh_level(blkh);
- if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) {
- /* this level is not possible for internal nodes */
- reiserfs_warning (NULL, "is_internal: this should be caught earlier");
- return 0;
- }
-
- nr = blkh_nr_item(blkh);
- if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
- /* for internal which is not root we might check min number of keys */
- reiserfs_warning (NULL, "is_internal: number of key seems wrong: %z", bh);
- return 0;
- }
+ struct block_head *blkh;
+ int nr;
+ int used_space;
+
+ blkh = (struct block_head *)buf;
+ nr = blkh_level(blkh);
+ if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) {
+ /* this level is not possible for internal nodes */
+ reiserfs_warning(NULL,
+ "is_internal: this should be caught earlier");
+ return 0;
+ }
- used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1);
- if (used_space != blocksize - blkh_free_space(blkh)) {
- reiserfs_warning (NULL, "is_internal: free space seems wrong: %z", bh);
- return 0;
- }
+ nr = blkh_nr_item(blkh);
+ if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
+ /* for internal which is not root we might check min number of keys */
+ reiserfs_warning(NULL,
+ "is_internal: number of key seems wrong: %z",
+ bh);
+ return 0;
+ }
- // one may imagine much more checks
- return 1;
+ used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1);
+ if (used_space != blocksize - blkh_free_space(blkh)) {
+ reiserfs_warning(NULL,
+ "is_internal: free space seems wrong: %z", bh);
+ return 0;
+ }
+ // one may imagine much more checks
+ return 1;
}
-
// make sure that bh contains formatted node of reiserfs tree of
// 'level'-th level
-static int is_tree_node (struct buffer_head * bh, int level)
+static int is_tree_node(struct buffer_head *bh, int level)
{
- if (B_LEVEL (bh) != level) {
- reiserfs_warning (NULL, "is_tree_node: node level %d does not match to the expected one %d",
- B_LEVEL (bh), level);
- return 0;
- }
- if (level == DISK_LEAF_NODE_LEVEL)
- return is_leaf (bh->b_data, bh->b_size, bh);
+ if (B_LEVEL(bh) != level) {
+ reiserfs_warning(NULL,
+ "is_tree_node: node level %d does not match to the expected one %d",
+ B_LEVEL(bh), level);
+ return 0;
+ }
+ if (level == DISK_LEAF_NODE_LEVEL)
+ return is_leaf(bh->b_data, bh->b_size, bh);
- return is_internal (bh->b_data, bh->b_size, bh);
+ return is_internal(bh->b_data, bh->b_size, bh);
}
-
-
#define SEARCH_BY_KEY_READA 16
/* The function is NOT SCHEDULE-SAFE! */
-static void search_by_key_reada (struct super_block * s,
- struct buffer_head **bh,
- unsigned long *b, int num)
+static void search_by_key_reada(struct super_block *s,
+ struct buffer_head **bh,
+ unsigned long *b, int num)
{
- int i,j;
-
- for (i = 0 ; i < num ; i++) {
- bh[i] = sb_getblk (s, b[i]);
- }
- for (j = 0 ; j < i ; j++) {
- /*
- * note, this needs attention if we are getting rid of the BKL
- * you have to make sure the prepared bit isn't set on this buffer
- */
- if (!buffer_uptodate(bh[j]))
- ll_rw_block(READA, 1, bh + j);
- brelse(bh[j]);
- }
+ int i, j;
+
+ for (i = 0; i < num; i++) {
+ bh[i] = sb_getblk(s, b[i]);
+ }
+ for (j = 0; j < i; j++) {
+ /*
+ * note, this needs attention if we are getting rid of the BKL
+ * you have to make sure the prepared bit isn't set on this buffer
+ */
+ if (!buffer_uptodate(bh[j]))
+ ll_rw_block(READA, 1, bh + j);
+ brelse(bh[j]);
+ }
}
/**************************************************************************
@@ -576,194 +602,200 @@ static void search_by_key_reada (struct super_block * s,
correctness of the top of the path but need not be checked for the
correctness of the bottom of the path */
/* The function is NOT SCHEDULE-SAFE! */
-int search_by_key (struct super_block * p_s_sb,
- const struct cpu_key * p_s_key, /* Key to search. */
- struct path * p_s_search_path, /* This structure was
- allocated and initialized
- by the calling
- function. It is filled up
- by this function. */
- int n_stop_level /* How far down the tree to search. To
- stop at leaf level - set to
- DISK_LEAF_NODE_LEVEL */
- ) {
- int n_block_number;
- int expected_level;
- struct buffer_head * p_s_bh;
- struct path_element * p_s_last_element;
- int n_node_level, n_retval;
- int right_neighbor_of_leaf_node;
- int fs_gen;
- struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
- unsigned long reada_blocks[SEARCH_BY_KEY_READA];
- int reada_count = 0;
+int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */
+ struct path *p_s_search_path, /* This structure was
+ allocated and initialized
+ by the calling
+ function. It is filled up
+ by this function. */
+ int n_stop_level /* How far down the tree to search. To
+ stop at leaf level - set to
+ DISK_LEAF_NODE_LEVEL */
+ )
+{
+ int n_block_number;
+ int expected_level;
+ struct buffer_head *p_s_bh;
+ struct path_element *p_s_last_element;
+ int n_node_level, n_retval;
+ int right_neighbor_of_leaf_node;
+ int fs_gen;
+ struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
+ unsigned long reada_blocks[SEARCH_BY_KEY_READA];
+ int reada_count = 0;
#ifdef CONFIG_REISERFS_CHECK
- int n_repeat_counter = 0;
+ int n_repeat_counter = 0;
#endif
-
- PROC_INFO_INC( p_s_sb, search_by_key );
-
- /* As we add each node to a path we increase its count. This means that
- we must be careful to release all nodes in a path before we either
- discard the path struct or re-use the path struct, as we do here. */
- decrement_counters_in_path(p_s_search_path);
+ PROC_INFO_INC(p_s_sb, search_by_key);
+
+ /* As we add each node to a path we increase its count. This means that
+ we must be careful to release all nodes in a path before we either
+ discard the path struct or re-use the path struct, as we do here. */
- right_neighbor_of_leaf_node = 0;
+ decrement_counters_in_path(p_s_search_path);
- /* With each iteration of this loop we search through the items in the
- current node, and calculate the next current node(next path element)
- for the next iteration of this loop.. */
- n_block_number = SB_ROOT_BLOCK (p_s_sb);
- expected_level = -1;
- while ( 1 ) {
+ right_neighbor_of_leaf_node = 0;
+
+ /* With each iteration of this loop we search through the items in the
+ current node, and calculate the next current node(next path element)
+ for the next iteration of this loop.. */
+ n_block_number = SB_ROOT_BLOCK(p_s_sb);
+ expected_level = -1;
+ while (1) {
#ifdef CONFIG_REISERFS_CHECK
- if ( !(++n_repeat_counter % 50000) )
- reiserfs_warning (p_s_sb, "PAP-5100: search_by_key: %s:"
- "there were %d iterations of while loop "
- "looking for key %K",
- current->comm, n_repeat_counter, p_s_key);
+ if (!(++n_repeat_counter % 50000))
+ reiserfs_warning(p_s_sb, "PAP-5100: search_by_key: %s:"
+ "there were %d iterations of while loop "
+ "looking for key %K",
+ current->comm, n_repeat_counter,
+ p_s_key);
#endif
- /* prep path to have another element added to it. */
- p_s_last_element = PATH_OFFSET_PELEMENT(p_s_search_path, ++p_s_search_path->path_length);
- fs_gen = get_generation (p_s_sb);
-
- /* Read the next tree node, and set the last element in the path to
- have a pointer to it. */