Skip to contentSkip to conversation

reiserfs: patch queue (v2)

PATCH In review [email protected] 1 participant 43 messages Jun 11, 2007 – Jun 14, 2007

lore
Share & tools
lore
#0 lore raw

cover reiserfs: patch queue (v2)

Hi all -

The following are a series of patches that have been kicking around for a while. I thought I'd just put them out there to gauge interest and to get some testing before submitting to -mm.

I've re-ordered a few of the patches. This is actually four distinct, unrelated, though context-dependent, patch series. I've moved the trivial changes to the front of the list to better reflect that.

There are a few groups:
* Little changes (01-04)
- Fixes lockdep warnings in xattr code.
- Changes reiserfs_panic() to panic() instead of BUG.
- Includes bitmap is_reusable unconditionally and uses to to catch corruption. This is light-weight now that the stupid loop is gone.
- Make bitmap used cached first zero bit.

* Error handling (05-11)
- Reformat error/warning/panic/info/etc messages to be consistent with one another.
- Makes some warnings informational. Rather than printing the reiserfs_warning() full preamble to declare that a mount option was invalid, we use reiserfs_info instead.
- Rework reiserfs_warning to take a unique ID, print the function name, print the device name.
- Rework reiserfs_panic similarly.
- Add reiserfs_error() to handle metadata errors.
- Use reiserfs_error().

* Extended attributes (12-22)
- Simplify internal file lookups/opens.
- Eliminate per-super xattr lock.
- Make per-inode xattr lock more fine-grained.
- Remove i_has_xattr_dir flag.
- Remove shared xattr detection (unused).
- Use generic xattr handler infrastructure.
- Use O_NOATIME for internal file opens.
- Add per-file data=ordered mode and use it for xattrs.
- Journal xattrs.
- Kill xattr_readdir in favor of a for_each_xattr.
- Add atomic addition of selinux attributes during inode creation.

* Cleanups, code readability (23-30)
- Cleanup path functions to reduce redundancy.
- Strip trailing whitespace from all reiserfs code.
- Rename p_s_sb to sb.
- Rename p_s_bh to bh.
- Rename p_s_inode to inode.
- Rename p_s_tb to tb.
- Rename misc p_._ variables.
- Rename [cn]_* variables.

* Clean up do_balan.c (31-40)
- Factor out buffer_info initializations.
- Turn tb->s[12]num and tb[12]bytes into an array.
- Split balance_leaf from the 2500 line beast to more manageable chunks.
- Clean up balance_leaf_when_delete.
- Clean up comments.

I look forward to comments. The journaled xattr changes in particular need testing as deadlocks may still lurk in there.

Changes:
- Reworked journal abort code to provide cleaner syslog output
- Always abort journal on error, unless panicking
- Always use bl_ prefix in do_balan.c
- Fixed unchecked deref in reiserfs_free_block

I've also posted the patch set here:
ftp://ftp.suse.com/pub/people/jeffm/reiserfs/kernel-v2.6/2.6.22-rc4-git3/

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#1 lore raw

PATCH 1/40 reiserfs: fix up lockdep warnings

This patch adds I_MUTEX_XATTR annotations to the inode locking in the reiserfs xattr code.

---
 fs/reiserfs/xattr.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/reiserfs/xattr.c +3 -2
@@ -478,7 +478,7 @@ reiserfs_xattr_set(struct inode *inode, 
 	/* Resize it so we're ok to write there */
 	newattrs.ia_size = buffer_size;
 	newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
-	mutex_lock(&xinode->i_mutex);
+	mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR);
 	err = notify_change(fp->f_path.dentry, &newattrs);
 	if (err)
 		goto out_filp;
@@ -1217,7 +1217,8 @@ int reiserfs_xattr_init(struct super_blo
 		if (!IS_ERR(dentry)) {
 			if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
 				struct inode *inode = dentry->d_parent->d_inode;
-				mutex_lock(&inode->i_mutex);
+				mutex_lock_nested(&inode->i_mutex,
+				                  I_MUTEX_XATTR);
 				err = inode->i_op->mkdir(inode, dentry, 0700);
 				mutex_unlock(&inode->i_mutex);
 				if (err) {
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#2 lore raw

PATCH 2/40 reiserfs: dont use BUG when panicking

In reply to [email protected]

This patch changes reiserfs_panic() to use panic() initially instead of BUG(). Using BUG() ignores the configurable panic behavior, so systems that should be failing and rebooting are left hanging. This causes problems in active/standby HA scenarios.

---
 fs/reiserfs/prints.c |    7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/reiserfs/prints.c +1 -6
@@ -356,13 +356,8 @@ extern struct tree_balance *cur_tb;
 void reiserfs_panic(struct super_block *sb, const char *fmt, ...)
 {
 	do_reiserfs_warning(fmt);
-	printk(KERN_EMERG "REISERFS: panic (device %s): %s\n",
+	panic(KERN_EMERG "REISERFS: panic (device %s): %s\n",
 	       reiserfs_bdevname(sb), error_buf);
-	BUG();
-
-	/* this is not actually called, but makes reiserfs_panic() "noreturn" */
-	panic("REISERFS: panic (device %s): %s\n",
-	      reiserfs_bdevname(sb), error_buf);
 }
 
 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#3 lore raw

PATCH 3/40 reiserfs: use is_reusable to catch corruption

In reply to [email protected]

This patch builds in is_reusable() unconditionally and uses it to catch corruption before it reaches the block freeing paths.

--

 fs/reiserfs/bitmap.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
fs/reiserfs/bitmap.c +13 -8
@@ -56,7 +56,6 @@ static inline void get_bit_address(struc
 	*offset = block & ((s->s_blocksize << 3) - 1);
 }
 
-#ifdef CONFIG_REISERFS_CHECK
 int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
 {
 	int bmap, offset;
@@ -106,7 +105,6 @@ int is_reusable(struct super_block *s, b
 
 	return 1;
 }
-#endif				/* CONFIG_REISERFS_CHECK */
 
 /* searches in journal structures for a given block number (bmap, off). If block
    is found in reiserfs journal it suggests next free block candidate to test. */
@@ -434,12 +432,19 @@ void reiserfs_free_block(struct reiserfs
 			 int for_unformatted)
 {
 	struct super_block *s = th->t_super;
-
 	BUG_ON(!th->t_trans_id);
 
 	RFALSE(!s, "vs-4061: trying to free block on nonexistent device");
-	RFALSE(is_reusable(s, block, 1) == 0,
-	       "vs-4071: can not free such block");
+	if (!is_reusable(s, block, 1))
+		return;
+
+	if (sb_block_count(REISERFS_SB(s)->s_rs) > blocks) {
+		reiserfs_error(th->t_super, "bitmap-4072",
+		               "Trying to free block outside file system "
+			       "boundaries (%lu > %lu)",
+			       block, blocks);
+		return;
+	}
 	/* mark it before we clear it, just in case */
 	journal_mark_freed(th, s, block);
 	_reiserfs_free_block(th, inode, block, for_unformatted);
@@ -449,11 +454,11 @@ void reiserfs_free_block(struct reiserfs
 static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th,
 					 struct inode *inode, b_blocknr_t block)
 {
+	BUG_ON(!th->t_trans_id);
 	RFALSE(!th->t_super,
 	       "vs-4060: trying to free block on nonexistent device");
-	RFALSE(is_reusable(th->t_super, block, 1) == 0,
-	       "vs-4070: can not free such block");
-	BUG_ON(!th->t_trans_id);
+	if (!is_reusable(th->t_super, block, 1))
+		return;
 	_reiserfs_free_block(th, inode, block, 1);
 }
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#4 lore raw

Re: [patch 03/40] reiserfs: use is_reusable to catch corruption

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

fs/reiserfs/bitmap.c void reiserfs_free_block(struct reiserfs · line 447

Quoted 7 lines · [email protected] wrote:
fs/reiserfs/bitmap.c +7 -0
+	if (sb_block_count(REISERFS_SB(s)->s_rs) > blocks) {
+		reiserfs_error(th->t_super, "bitmap-4072",
+		               "Trying to free block outside file system "
+			       "boundaries (%lu > %lu)",
+			       block, blocks);
+		return;
+	}

Should be:

        if (block > sb_block_count(REISERFS_SB(s)->s_rs)) {
                reiserfs_error(th->t_super, "bitmap-4072",
                               "Trying to free block outside file system "
                               "boundaries (%lu > %lu)",
                               block, sb_block_count(REISERFS_SB(s)->s_rs));
                return;

Too many balls in the air.

- -Jeff

- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFGcBMgLPWxlyuTD7IRAjgWAKCQMKvTGYkYtv2kQmA5kCFqzFvtJACgkdxM 4FGl1fbMzWx/ONgjmoVtW1M=
=xFYz
-----END PGP SIGNATURE-----

#5 lore raw

PATCH 4/40 reiserfs: make bitmap use cached first zero bit

In reply to [email protected]

Currently, the bitmap code uses half of the hinting data gathered and cached and wastes the other half. We'll skip completely full bitmaps, but start scanning in bitmaps at locations where if we consulted the zero bit hint, we'd know there aren't any free bits available.

This patch uses the first zero hint to bump the beginning of the search window to where we know there is at least one zero bit.

---

 fs/reiserfs/bitmap.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/reiserfs/bitmap.c +4 -1
@@ -166,7 +166,10 @@ static int scan_bitmap_block(struct reis
 			return 0;	// No free blocks in this bitmap
 		}
 
-		/* search for a first zero bit -- beggining of a window */
+		if (*beg < bi->first_zero_hint)
+			*beg = bi->first_zero_hint;
+
+		/* search for a first zero bit -- beginning of a window */
 		*beg = reiserfs_find_next_zero_le_bit
 		    ((unsigned long *)(bh->b_data), boundary, *beg);
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#6 lore raw

PATCH 5/40 reiserfs: use more consistent printk formatting

In reply to [email protected]

The output format between a warning/error/panic/info/etc changes with which one is used.

The following patch makes the messages more internally consistent, but also more consistent with other Linux filesystems.

--

 fs/reiserfs/prints.c |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
fs/reiserfs/prints.c +14 -14
@@ -268,10 +268,10 @@ void reiserfs_warning(struct super_block
 {
 	do_reiserfs_warning(fmt);
 	if (sb)
-		printk(KERN_WARNING "ReiserFS: %s: warning: %s\n",
-		       reiserfs_bdevname(sb), error_buf);
+		printk(KERN_WARNING "REISERFS warning (device %s): %s\n",
+		       sb->s_id, error_buf);
 	else
-		printk(KERN_WARNING "ReiserFS: warning: %s\n", error_buf);
+		printk(KERN_WARNING "REISERFS warning: %s\n", error_buf);
 }
 
 /* No newline.. reiserfs_info calls can be followed by printk's */
@@ -279,10 +279,10 @@ void reiserfs_info(struct super_block *s
 {
 	do_reiserfs_warning(fmt);
 	if (sb)
-		printk(KERN_NOTICE "ReiserFS: %s: %s",
-		       reiserfs_bdevname(sb), error_buf);
+		printk(KERN_NOTICE "REISERFS (device %s): %s",
+		       sb->s_id, error_buf);
 	else
-		printk(KERN_NOTICE "ReiserFS: %s", error_buf);
+		printk(KERN_NOTICE "REISERFS %s:", error_buf);
 }
 
 /* No newline.. reiserfs_printk calls can be followed by printk's */
@@ -297,10 +297,10 @@ void reiserfs_debug(struct super_block *
 #ifdef CONFIG_REISERFS_CHECK
 	do_reiserfs_warning(fmt);
 	if (s)
-		printk(KERN_DEBUG "ReiserFS: %s: %s\n",
-		       reiserfs_bdevname(s), error_buf);
+		printk(KERN_DEBUG "REISERFS debug (device %s): %s\n",
+		       s->s_id, error_buf);
 	else
-		printk(KERN_DEBUG "ReiserFS: %s\n", error_buf);
+		printk(KERN_DEBUG "REISERFS debug: %s\n", error_buf);
 #endif
 }
 
@@ -365,15 +365,15 @@ void reiserfs_abort(struct super_block *
 	do_reiserfs_warning(fmt);
 
 	if (reiserfs_error_panic(sb)) {
-		panic(KERN_CRIT "REISERFS: panic (device %s): %s\n",
-		      reiserfs_bdevname(sb), error_buf);
+		panic(KERN_CRIT "REISERFS panic (device %s): %s\n", sb->s_id,
+		      error_buf);
 	}
 
-	if (sb->s_flags & MS_RDONLY)
+	if (reiserfs_is_journal_aborted(SB_JOURNAL(sb)))
 		return;
 
-	printk(KERN_CRIT "REISERFS: abort (device %s): %s\n",
-	       reiserfs_bdevname(sb), error_buf);
+	printk(KERN_CRIT "REISERFS abort (device %s): %s\n", sb->s_id,
+	       error_buf);
 
 	sb->s_flags |= MS_RDONLY;
 	reiserfs_journal_abort(sb, errno);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#7 lore raw

PATCH 6/40 reiserfs: make some warnings informational

In reply to [email protected]

In several places, reiserfs_warning is used when there is no warning, just a notice. This patch changes some of them to indicate that the message is merely informational.

--

 fs/reiserfs/bitmap.c |    4 ++--
 fs/reiserfs/super.c  |   14 ++++++--------
 fs/reiserfs/xattr.c  |   10 ++++------
 3 files changed, 12 insertions(+), 16 deletions(-)
fs/reiserfs/bitmap.c +2 -2
@@ -40,7 +40,7 @@
 
 #define SET_OPTION(optname) \
    do { \
-        reiserfs_warning(s, "reiserfs: option \"%s\" is set", #optname); \
+        reiserfs_info(s, "block allocator option \"%s\" is set", #optname); \
         set_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)); \
     } while(0)
 #define TEST_OPTION(optname, s) \
@@ -633,7 +633,7 @@ int reiserfs_parse_alloc_options(struct 
 		return 1;
 	}
 
-	reiserfs_warning(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s));
+	reiserfs_info(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s));
 	return 0;
 }
 
fs/reiserfs/super.c +6 -8
@@ -1308,13 +1308,11 @@ static int read_super_block(struct super
 		/* magic is of non-standard journal filesystem, look at s_version to
 		   find which format is in use */
 		if (sb_version(rs) == REISERFS_VERSION_2)
-			reiserfs_warning(s,
-					 "read_super_block: found reiserfs format \"3.6\""
-					 " with non-standard journal");
+			reiserfs_info(s, "found reiserfs format \"3.6\""
+			              " with non-standard journal\n");
 		else if (sb_version(rs) == REISERFS_VERSION_1)
-			reiserfs_warning(s,
-					 "read_super_block: found reiserfs format \"3.5\""
-					 " with non-standard journal");
+			reiserfs_info(s, "found reiserfs format \"3.5\""
+			              " with non-standard journal\n");
 		else {
 			reiserfs_warning(s,
 					 "sh-2012: read_super_block: found unknown "
@@ -1393,8 +1391,8 @@ static __u32 find_hash_out(struct super_
 			if (reiserfs_rupasov_hash(s)) {
 				hash = YURA_HASH;
 			}
-			reiserfs_warning(s, "FS seems to be empty, autodetect "
-					 "is using the default hash");
+			reiserfs_info(s, "FS seems to be empty, autodetect "
+					 "is using the default hash\n");
 			break;
 		}
 		r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
fs/reiserfs/xattr.c +4 -6
@@ -1227,12 +1227,10 @@ int reiserfs_xattr_init(struct super_blo
 				}
 
 				if (dentry && dentry->d_inode)
-					reiserfs_warning(s,
-							 "Created %s on %s - reserved for "
-							 "xattr storage.",
-							 PRIVROOT_NAME,
-							 reiserfs_bdevname
-							 (inode->i_sb));
+					reiserfs_info(s, "Created %s - "
+					              "reserved for xattr "
+						      "storage.\n",
+						      PRIVROOT_NAME);
 			} else if (!dentry->d_inode) {
 				dput(dentry);
 				dentry = NULL;
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#8 lore raw

PATCH 7/40 reiserfs: rework reiserfs_warning

In reply to [email protected]

ReiserFS warnings can be somewhat inconsistent.
In some cases:
* a unique identifier may be associated with it
* the function name may be included
* the device may be printed separately

This patch aims to make warnings more consistent. reiserfs_warning() prints the device name, so printing it a second time is not required. The function name for a warning is always helpful in debugging, so it is now automatically inserted into the output. Hans has stated that every warning should have a unique identifier. Some cases lack them, others really shouldn't have them. reiserfs_warning() now expects an id associated with each message. In the rare case where one isn't needed, "" will suffice.

--

 fs/reiserfs/bitmap.c          |   50 ++++----
 fs/reiserfs/do_balan.c        |   39 +++---
 fs/reiserfs/file.c            |   11 +
 fs/reiserfs/fix_node.c        |   14 +-
 fs/reiserfs/inode.c           |   63 +++++------
 fs/reiserfs/item_ops.c        |   60 +++++-----
 fs/reiserfs/journal.c         |  168 +++++++++++++++--------------
 fs/reiserfs/lbalance.c        |   12 +-
 fs/reiserfs/namei.c           |   45 +++----
 fs/reiserfs/objectid.c        |    5 
 fs/reiserfs/prints.c          |   11 +
 fs/reiserfs/procfs.c          |    5 
 fs/reiserfs/stree.c           |  107 ++++++++----------
 fs/reiserfs/super.c           |  240 ++++++++++++++++++++++--------------------
 fs/reiserfs/tail_conversion.c |    6 -
 fs/reiserfs/xattr.c           |   21 ++-
 include/linux/reiserfs_fs.h   |    9 +
 17 files changed, 444 insertions(+), 422 deletions(-)
fs/reiserfs/bitmap.c +23 -27
@@ -61,8 +61,8 @@ int is_reusable(struct super_block *s, b
 	int bmap, offset;
 
 	if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
-		reiserfs_warning(s,
-				 "vs-4010: is_reusable: block number is out of range %lu (%u)",
+		reiserfs_warning(s, "vs-4010",
+		                 "block number is out of range %lu (%u)",
 				 block, SB_BLOCK_COUNT(s));
 		return 0;
 	}
@@ -75,30 +75,29 @@ int is_reusable(struct super_block *s, b
 			      &(REISERFS_SB(s)->s_properties)))) {
 		b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
 		if (block >= bmap1 && block <= bmap1 + SB_BMAP_NR(s)) {
-			reiserfs_warning(s, "vs: 4019: is_reusable: "
-					 "bitmap block %lu(%u) can't be freed or reused",
+			reiserfs_warning(s, "vs-4019", "bitmap block "
+			                 "%lu(%u) can't be freed or reused",
 					 block, SB_BMAP_NR(s));
 			return 0;
 		}
 	} else {
 		if (offset == 0) {
-			reiserfs_warning(s, "vs: 4020: is_reusable: "
-					 "bitmap block %lu(%u) can't be freed or reused",
+			reiserfs_warning(s, "vs-4020", "bitmap block "
+			                 "%lu(%u) can't be freed or reused",
 					 block, SB_BMAP_NR(s));
 			return 0;
 		}
 	}
 
 	if (bmap >= SB_BMAP_NR(s)) {
-		reiserfs_warning(s,
-				 "vs-4030: is_reusable: there is no so many bitmap blocks: "
-				 "block=%lu, bitmap_nr=%d", block, bmap);
+		reiserfs_warning(s, "vs-4030", "there is no so many "
+		                 "bitmap blocks: block=%lu, bitmap_nr=%d",
+				 block, bmap);
 		return 0;
 	}
 
 	if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
-		reiserfs_warning(s,
-				 "vs-4050: is_reusable: this is root block (%u), "
+		reiserfs_warning(s, "vs-4050", "this is root block (%u), "
 				 "it must be busy", SB_ROOT_BLOCK(s));
 		return 0;
 	}
@@ -150,8 +149,8 @@ static int scan_bitmap_block(struct reis
 /* - I mean `a window of zero bits' as in description of this function - Zam. */
 
 	if (!bi) {
-		reiserfs_warning(s, "NULL bitmap info pointer for bitmap %d",
-				 bmap_n);
+		reiserfs_warning(s, "jdm-4055", "NULL bitmap info pointer "
+		                 "for bitmap %d", bmap_n);
 		return 0;
 	}
 
@@ -399,9 +398,8 @@ static void _reiserfs_free_block(struct 
 	get_bit_address(s, block, &nr, &offset);
 
 	if (nr >= sb_bmap_nr(rs)) {
-		reiserfs_warning(s, "vs-4075: reiserfs_free_block: "
-				 "block %lu is out of range on %s",
-				 block, reiserfs_bdevname(s));
+ 		reiserfs_warning(s, "vs-4075",
+				 "block %lu is out of range", block);
 		return;
 	}
 
@@ -413,9 +411,8 @@ static void _reiserfs_free_block(struct 
 
 	/* clear bit for the given block in bit map */
 	if (!reiserfs_test_and_clear_le_bit(offset, bmbh->b_data)) {
-		reiserfs_warning(s, "vs-4080: reiserfs_free_block: "
-				 "free_block (%s:%lu)[dev:blocknr]: bit already cleared",
-				 reiserfs_bdevname(s), block);
+		reiserfs_warning(s, "vs-4080",
+		                 "block %lu: bit already cleared", block);
 	}
 	apbi[nr].free_count++;
 	journal_mark_dirty(th, s, bmbh);
@@ -474,9 +471,8 @@ static void __discard_prealloc(struct re
 	BUG_ON(!th->t_trans_id);
 #ifdef CONFIG_REISERFS_CHECK
 	if (ei->i_prealloc_count < 0)
-		reiserfs_warning(th->t_super,
-				 "zam-4001:%s: inode has negative prealloc blocks count.",
-				 __FUNCTION__);
+		reiserfs_warning(th->t_super, "zam-4001",
+		                 "inode has negative prealloc blocks count.");
 #endif
 	while (ei->i_prealloc_count > 0) {
 		reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block);
@@ -512,9 +508,9 @@ void reiserfs_discard_all_prealloc(struc
 				i_prealloc_list);
 #ifdef CONFIG_REISERFS_CHECK
 		if (!ei->i_prealloc_count) {
-			reiserfs_warning(th->t_super,
-					 "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.",
-					 __FUNCTION__);
+			reiserfs_warning(th->t_super, "zam-4001",
+			                 "inode is in prealloc list but has "
+					 "no preallocated blocks.");
 		}
 #endif
 		__discard_prealloc(th, ei);
@@ -628,8 +624,8 @@ int reiserfs_parse_alloc_options(struct 
 			continue;
 		}
 
-		reiserfs_warning(s, "zam-4001: %s : unknown option - %s",
-				 __FUNCTION__, this_char);
+		reiserfs_warning(s, "zam-4001", "unknown option - %s",
+				 this_char);
 		return 1;
 	}
 
fs/reiserfs/do_balan.c +19 -20
@@ -1755,15 +1755,15 @@ static void store_thrown(struct tree_bal
 	int i;
 
 	if (buffer_dirty(bh))
-		reiserfs_warning(tb->tb_sb,
-				 "store_thrown deals with dirty buffer");
+		reiserfs_warning(tb->tb_sb, "reiserfs-12320",
+		                 "called with dirty buffer");
 	for (i = 0; i < ARRAY_SIZE(tb->thrown); i++)
 		if (!tb->thrown[i]) {
 			tb->thrown[i] = bh;
 			get_bh(bh);	/* free_thrown puts this */
 			return;
 		}
-	reiserfs_warning(tb->tb_sb, "store_thrown: too many thrown buffers");
+	reiserfs_warning(tb->tb_sb, "reiserfs-12321", "too many thrown buffers");
 }
 
 static void free_thrown(struct tree_balance *tb)
@@ -1774,8 +1774,8 @@ static void free_thrown(struct tree_bala
 		if (tb->thrown[i]) {
 			blocknr = tb->thrown[i]->b_blocknr;
 			if (buffer_dirty(tb->thrown[i]))
-				reiserfs_warning(tb->tb_sb,
-						 "free_thrown deals with dirty buffer %d",
+				reiserfs_warning(tb->tb_sb, "reiserfs-12322",
+				                 "called with dirty buffer %d",
 						 blocknr);
 			brelse(tb->thrown[i]);	/* incremented in store_thrown */
 			reiserfs_free_block(tb->transaction_handle, NULL,
@@ -1880,13 +1880,12 @@ static void check_internal_node(struct s
 	}
 }
 
-static int locked_or_not_in_tree(struct buffer_head *bh, char *which)
+static int locked_or_not_in_tree(struct tree_balance *tb,
+                                 struct buffer_head *bh, char *which)
 {
 	if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) ||
 	    !B_IS_IN_TREE(bh)) {
-		reiserfs_warning(NULL,
-				 "vs-12339: locked_or_not_in_tree: %s (%b)",
-				 which, bh);
+		reiserfs_warning(tb->tb_sb, "vs-12339", "%s (%b)", which, bh);
 		return 1;
 	}
 	return 0;
@@ -1905,18 +1904,19 @@ static int check_before_balancing(struct
 	/* double check that buffers that we will modify are unlocked. (fix_nodes should already have
 	   prepped all of these for us). */
 	if (tb->lnum[0]) {
-		retval |= locked_or_not_in_tree(tb->L[0], "L[0]");
-		retval |= locked_or_not_in_tree(tb->FL[0], "FL[0]");
-		retval |= locked_or_not_in_tree(tb->CFL[0], "CFL[0]");
+		retval |= locked_or_not_in_tree(tb, tb->L[0], "L[0]");
+		retval |= locked_or_not_in_tree(tb, tb->FL[0], "FL[0]");
+		retval |= locked_or_not_in_tree(tb, tb->CFL[0], "CFL[0]");
 		check_leaf(tb->L[0]);
 	}
 	if (tb->rnum[0]) {
-		retval |= locked_or_not_in_tree(tb->R[0], "R[0]");
-		retval |= locked_or_not_in_tree(tb->FR[0], "FR[0]");
-		retval |= locked_or_not_in_tree(tb->CFR[0], "CFR[0]");
+		retval |= locked_or_not_in_tree(tb, tb->R[0], "R[0]");
+		retval |= locked_or_not_in_tree(tb, tb->FR[0], "FR[0]");
+		retval |= locked_or_not_in_tree(tb, tb->CFR[0], "CFR[0]");
 		check_leaf(tb->R[0]);
 	}
-	retval |= locked_or_not_in_tree(PATH_PLAST_BUFFER(tb->tb_path), "S[0]");
+	retval |= locked_or_not_in_tree(tb, PATH_PLAST_BUFFER(tb->tb_path),
+	                                "S[0]");
 	check_leaf(PATH_PLAST_BUFFER(tb->tb_path));
 
 	return retval;
@@ -1955,7 +1955,7 @@ static void check_after_balance_leaf(str
 					       PATH_H_POSITION(tb->tb_path,
 							       1))));
 		print_cur_tb("12223");
-		reiserfs_warning(tb->tb_sb,
+		reiserfs_warning(tb->tb_sb, "reiserfs-12363",
 				 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
 				 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d",
 				 left,
@@ -2107,9 +2107,8 @@ void do_balance(struct tree_balance *tb,
 	}
 	/* if we have no real work to do  */
 	if (!tb->insert_size[0]) {
-		reiserfs_warning(tb->tb_sb,
-				 "PAP-12350: do_balance: insert_size == 0, mode == %c",
-				 flag);
+		reiserfs_warning(tb->tb_sb, "PAP-12350",
+		                 "insert_size == 0, mode == %c", flag);
 		unfix_nodes(tb);
 		return;
 	}
fs/reiserfs/file.c +6 -5
@@ -76,7 +76,7 @@ static int reiserfs_file_release(struct 
 			 * and let the admin know what is going on.
 			 */
 			igrab(inode);
-			reiserfs_warning(inode->i_sb,
+			reiserfs_warning(inode->i_sb, "clm-9001",
 					 "pinning inode %lu because the "
 					 "preallocation can't be freed",
 					 inode->i_ino);
@@ -397,7 +397,8 @@ static int reiserfs_allocate_blocks_for_
 						if (res != -ENOSPC) {
 							reiserfs_warning(inode->
 									 i_sb,
-									 "green-9008: search_by_key (%K) returned %d",
+									 "green-9008",
+									 "search_by_key (%K) returned %d",
 									 &key,
 									 res);
 						}
@@ -599,7 +600,8 @@ static int reiserfs_allocate_blocks_for_
 				   occured, we need to warn user and return error */
 				if (res != -ENOSPC) {
 					reiserfs_warning(inode->i_sb,
-							 "green-9009: search_by_key (%K) "
+							 "green-9009",
+							 "search_by_key (%K) "
 							 "returned %d", &key,
 							 res);
 				}
@@ -1015,8 +1017,7 @@ static int reiserfs_prepare_file_region_
 	int item_pos = -1;	/* Position in indirect item */
 
 	if (num_pages < 1) {
-		reiserfs_warning(inode->i_sb,
-				 "green-9001: reiserfs_prepare_file_region_for_write "
+		reiserfs_warning(inode->i_sb, "green-9001",
 				 "called with zero number of pages to process");
 		return -EFAULT;
 	}
fs/reiserfs/fix_node.c +7 -7
@@ -496,8 +496,8 @@ static int get_num_ver(int mode, struct 
 		snum012[needed_nodes - 1 + 3] = units;
 
 		if (needed_nodes > 2)
-			reiserfs_warning(tb->tb_sb, "vs-8111: get_num_ver: "
-					 "split_item_position is out of boundary");
+			reiserfs_warning(tb->tb_sb, "vs-8111",
+					 "split_item_position is out of range");
 		snum012[needed_nodes - 1]++;
 		split_item_positions[needed_nodes - 1] = i;
 		needed_nodes++;
@@ -533,8 +533,8 @@ static int get_num_ver(int mode, struct 
 
 		if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY &&
 		    vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT)
-			reiserfs_warning(tb->tb_sb, "vs-8115: get_num_ver: not "
-					 "directory or indirect item");
+			reiserfs_warning(tb->tb_sb, "vs-8115",
+			                 "not directory or indirect item");
 	}
 
 	/* now we know S2bytes, calculate S1bytes */
@@ -2266,9 +2266,9 @@ static int wait_tb_buffers_until_unlocke
 #ifdef CONFIG_REISERFS_CHECK
 			repeat_counter++;
 			if ((repeat_counter % 10000) == 0) {
-				reiserfs_warning(p_s_tb->tb_sb,
-						 "wait_tb_buffers_until_released(): too many "
-						 "iterations waiting for buffer to unlock "
+				reiserfs_warning(p_s_tb->tb_sb, "reiserfs-8200",
+						 "too many iterations waiting "
+						 "for buffer to unlock "
 						 "(%b)", locked);
 
 				/* Don't loop forever.  Try to recover from possible error. */
fs/reiserfs/inode.c +30 -33

157 lines not on this page · raw message

fs/reiserfs/item_ops.c +32 -28

153 lines not on this page · raw message

fs/reiserfs/journal.c +89 -79

422 lines not on this page · raw message

fs/reiserfs/lbalance.c +8 -4
@@ -1287,12 +1287,16 @@ void leaf_paste_entries(struct buffer_he
 			prev = (i != 0) ? deh_location(&(deh[i - 1])) : 0;
 
 			if (prev && prev <= deh_location(&(deh[i])))
-				reiserfs_warning(NULL,
-						 "vs-10240: leaf_paste_entries: directory item (%h) corrupted (prev %a, cur(%d) %a)",
+				reiserfs_warning(NULL, "vs-10240",
+				                 "directory item (%h) "
+						 "corrupted (prev %a, "
+						 "cur(%d) %a)",
 						 ih, deh + i - 1, i, deh + i);
 			if (next && next >= deh_location(&(deh[i])))
-				reiserfs_warning(NULL,
-						 "vs-10250: leaf_paste_entries: directory item (%h) corrupted (cur(%d) %a, next %a)",
+				reiserfs_warning(NULL, "vs-10250",
+				                 "directory item (%h) "
+						 "corrupted (cur(%d) %a, "
+						 "next %a)",
 						 ih, i, deh + i, deh + i + 1);
 		}
 	}
fs/reiserfs/namei.c +21 -24

99 lines not on this page · raw message

fs/reiserfs/objectid.c +2 -3
@@ -61,7 +61,7 @@ __u32 reiserfs_get_unused_objectid(struc
 	/* comment needed -Hans */
 	unused_objectid = le32_to_cpu(map[1]);
 	if (unused_objectid == U32_MAX) {
-		reiserfs_warning(s, "%s: no more object ids", __FUNCTION__);
+		reiserfs_warning(s, "reiserfs-15100", "no more object ids");
 		reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s));
 		return 0;
 	}
@@ -161,8 +161,7 @@ void reiserfs_release_objectid(struct re
 		i += 2;
 	}
 
-	reiserfs_warning(s,
-			 "vs-15011: reiserfs_release_objectid: tried to free free object id (%lu)",
+	reiserfs_warning(s, "vs-15011", "tried to free free object id (%lu)",
 			 (long unsigned)objectid_to_release);
 }
 
fs/reiserfs/prints.c +7 -4
@@ -264,14 +264,17 @@ static void prepare_error_buf(const char
     va_end( args );\
 }
 
-void reiserfs_warning(struct super_block *sb, const char *fmt, ...)
+void __reiserfs_warning(struct super_block *sb, const char *id,
+                               const char *function, const char *fmt, ...)
 {
 	do_reiserfs_warning(fmt);
 	if (sb)
-		printk(KERN_WARNING "REISERFS warning (device %s): %s\n",
-		       sb->s_id, error_buf);
+		printk(KERN_WARNING "REISERFS warning (device %s): %s%s%s: %s\n",
+		       sb->s_id, id ? id : "", id ? " " : "",
+		       function, error_buf);
 	else
-		printk(KERN_WARNING "REISERFS warning: %s\n", error_buf);
+		printk(KERN_WARNING "REISERFS warning: %s%s%s: %s\n",
+		       id ? id : "", id ? " " : "", function, error_buf);
 }
 
 /* No newline.. reiserfs_info calls can be followed by printk's */
fs/reiserfs/procfs.c +2 -3
@@ -514,7 +514,7 @@ int reiserfs_proc_info_init(struct super
 		add_file(sb, "journal", show_journal);
 		return 0;
 	}
-	reiserfs_warning(sb, "reiserfs: cannot create /proc/%s/%s",
+	reiserfs_warning(sb, "cannot create /proc/%s/%s",
 			 proc_info_root_name, b);
 	return 1;
 }
@@ -570,8 +570,7 @@ int reiserfs_proc_info_global_init(void)
 		if (proc_info_root) {
 			proc_info_root->owner = THIS_MODULE;
 		} else {
-			reiserfs_warning(NULL,
-					 "reiserfs: cannot create /proc/%s",
+			reiserfs_warning(NULL, "cannot create /proc/%s",
 					 proc_info_root_name);
 			return 1;
 		}
fs/reiserfs/stree.c +50 -57

258 lines not on this page · raw message

fs/reiserfs/super.c +126 -114

561 lines not on this page · raw message

fs/reiserfs/tail_conversion.c +3 -3
@@ -48,9 +48,9 @@ int direct2indirect(struct reiserfs_tran
 
 	// FIXME: we could avoid this 
 	if (search_for_position_by_key(sb, &end_key, path) == POSITION_FOUND) {
-		reiserfs_warning(sb, "PAP-14030: direct2indirect: "
-				 "pasted or inserted byte exists in the tree %K. "
-				 "Use fsck to repair.", &end_key);
+		reiserfs_warning(sb, "PAP-14030",
+				 "pasted or inserted byte exists in "
+				 "the tree %K. Use fsck to repair.", &end_key);
 		pathrelse(path);
 		return -EIO;
 	}
fs/reiserfs/xattr.c +13 -8
@@ -278,7 +278,8 @@ static int __xattr_readdir(struct file *
 		ih = de.de_ih;
 
 		if (!is_direntry_le_ih(ih)) {
-			reiserfs_warning(inode->i_sb, "not direntry %h", ih);
+			reiserfs_warning(inode->i_sb, "jdm-20000",
+			                 "not direntry %h", ih);
 			break;
 		}
 		copy_item_head(&tmp_ih, ih);
@@ -619,7 +620,7 @@ reiserfs_xattr_get(const struct inode *i
 			if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
 				unlock_page(page);
 				reiserfs_put_page(page);
-				reiserfs_warning(inode->i_sb,
+				reiserfs_warning(inode->i_sb, "jdm-20001",
 						 "Invalid magic for xattr (%s) "
 						 "associated with %k", name,
 						 INODE_PKEY(inode));
@@ -639,7 +640,7 @@ reiserfs_xattr_get(const struct inode *i
 
 	if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
 	    hash) {
-		reiserfs_warning(inode->i_sb,
+		reiserfs_warning(inode->i_sb, "jdm-20002",
 				 "Invalid hash for xattr (%s) associated "
 				 "with %k", name, INODE_PKEY(inode));
 		err = -EIO;
@@ -673,7 +674,8 @@ __reiserfs_xattr_del(struct dentry *xadi
 		goto out_file;
 
 	if (!is_reiserfs_priv_object(dentry->d_inode)) {
-		reiserfs_warning(dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have "
+		reiserfs_warning(dir->i_sb, "jdm-20003",
+		                 "OID %08x [%.*s/%.*s] doesn't have "
 				 "priv flag set [parent is %sset].",
 				 le32_to_cpu(INODE_PKEY(dentry->d_inode)->
 					     k_objectid), xadir->d_name.len,
@@ -779,7 +781,7 @@ int reiserfs_delete_xattrs(struct inode 
 		reiserfs_write_unlock_xattrs(inode->i_sb);
 		dput(root);
 	} else {
-		reiserfs_warning(inode->i_sb,
+		reiserfs_warning(inode->i_sb, "jdm-20004",
 				 "Couldn't remove all entries in directory");
 	}
 	unlock_kernel();
@@ -1199,7 +1201,8 @@ int reiserfs_xattr_init(struct super_blo
 	} else if (reiserfs_xattrs_optional(s)) {
 		/* Old format filesystem, but optional xattrs have been enabled
 		 * at mount time. Error out. */
-		reiserfs_warning(s, "xattrs/ACLs not supported on pre v3.6 "
+		reiserfs_warning(s, "jdm-20005",
+		                 "xattrs/ACLs not supported on pre v3.6 "
 				 "format filesystem. Failing mount.");
 		err = -EOPNOTSUPP;
 		goto error;
@@ -1246,8 +1249,10 @@ int reiserfs_xattr_init(struct super_blo
 			/* If we're read-only it just means that the dir hasn't been
 			 * created. Not an error -- just no xattrs on the fs. We'll
 			 * check again if we go read-write */
-			reiserfs_warning(s, "xattrs/ACLs enabled and couldn't "
-					 "find/create .reiserfs_priv. Failing mount.");
+			reiserfs_warning(s, "jdm-20006",
+			                 "xattrs/ACLs enabled and couldn't "
+					 "find/create .reiserfs_priv. "
+					 "Failing mount.");
 			err = -EOPNOTSUPP;
 		}
 	}
include/linux/reiserfs_fs.h +6 -3
@@ -77,7 +77,10 @@
 */
 #define REISERFS_DEBUG_CODE 5	/* extra messages to help find/debug errors */
 
-void reiserfs_warning(struct super_block *s, const char *fmt, ...);
+void __reiserfs_warning(struct super_block *s, const char *id,
+                        const char *func, const char *fmt, ...);
+#define reiserfs_warning(s, id, fmt, args...) \
+        __reiserfs_warning(s, id, __FUNCTION__, fmt, ##args)
 /* assertions handling */
 
 /** always check a condition and panic if it's false. */
@@ -538,7 +541,7 @@ static inline int uniqueness2type(__u32 
 	case V1_DIRENTRY_UNIQUENESS:
 		return TYPE_DIRENTRY;
 	default:
-		reiserfs_warning(NULL, "vs-500: unknown uniqueness %d",
+		reiserfs_warning(NULL, "vs-500", "unknown uniqueness %d",
 				 uniqueness);
 	case V1_ANY_UNIQUENESS:
 		return TYPE_ANY;
@@ -558,7 +561,7 @@ static inline __u32 type2uniqueness(int 
 	case TYPE_DIRENTRY:
 		return V1_DIRENTRY_UNIQUENESS;
 	default:
-		reiserfs_warning(NULL, "vs-501: unknown type %d", type);
+		reiserfs_warning(NULL, "vs-501", "unknown type %d", type);
 	case TYPE_ANY:
 		return V1_ANY_UNIQUENESS;
 	}
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#9 lore raw

PATCH 8/40 reiserfs: rework reiserfs_panic

In reply to [email protected]

ReiserFS panics can be somewhat inconsistent.
In some cases:
* a unique identifier may be associated with it
* the function name may be included
* the device may be printed separately

This patch aims to make warnings more consistent. reiserfs_warning() prints the device name, so printing it a second time is not required. The function name for a warning is always helpful in debugging, so it is now automatically inserted into the output. Hans has stated that every warning should have a unique identifier. Some cases lack them, others really shouldn't have them. reiserfs_warning() now expects an id associated with each message. In the rare case where one isn't needed, "" will suffice.

---
 fs/reiserfs/do_balan.c        |   60 ++++++++++++++++------------------
 fs/reiserfs/file.c            |   32 ++++++++++--------
 fs/reiserfs/fix_node.c        |   74 +++++++++++++++++++++---------------------
 fs/reiserfs/ibalance.c        |   12 +++---
 fs/reiserfs/inode.c           |    3 -
 fs/reiserfs/item_ops.c        |    8 ++--
 fs/reiserfs/journal.c         |   56 +++++++++++++++----------------
 fs/reiserfs/lbalance.c        |   27 ++++++++-------
 fs/reiserfs/namei.c           |   18 ++++------
 fs/reiserfs/objectid.c        |    3 -
 fs/reiserfs/prints.c          |   34 ++++++++++---------
 fs/reiserfs/stree.c           |   49 +++++++++++++--------------
 fs/reiserfs/tail_conversion.c |   10 ++---
 include/linux/reiserfs_fs.h   |   23 ++++++++++---
 14 files changed, 212 insertions(+), 197 deletions(-)
fs/reiserfs/do_balan.c +29 -31
@@ -153,8 +153,8 @@ static int balance_leaf_when_delete(stru
 
 	default:
 		print_cur_tb("12040");
-		reiserfs_panic(tb->tb_sb,
-			       "PAP-12040: balance_leaf_when_delete: unexpectable mode: %s(%d)",
+		reiserfs_panic(tb->tb_sb, "PAP-12040",
+		               "unexpected mode: %s(%d)",
 			       (flag ==
 				M_PASTE) ? "PASTE" : ((flag ==
 						       M_INSERT) ? "INSERT" :
@@ -722,8 +722,8 @@ static int balance_leaf(struct tree_bala
 				}
 				break;
 			default:	/* cases d and t */
-				reiserfs_panic(tb->tb_sb,
-					       "PAP-12130: balance_leaf: lnum > 0: unexpectable mode: %s(%d)",
+				reiserfs_panic(tb->tb_sb, "PAP-12130",
+				               "lnum > 0: unexpected mode: %s(%d)",
 					       (flag ==
 						M_DELETE) ? "DELETE" : ((flag ==
 									 M_CUT)
@@ -1136,8 +1136,8 @@ static int balance_leaf(struct tree_bala
 			}
 			break;
 		default:	/* cases d and t */
-			reiserfs_panic(tb->tb_sb,
-				       "PAP-12175: balance_leaf: rnum > 0: unexpectable mode: %s(%d)",
+			reiserfs_panic(tb->tb_sb, "PAP-12175",
+			               "rnum > 0: unexpected mode: %s(%d)",
 				       (flag ==
 					M_DELETE) ? "DELETE" : ((flag ==
 								 M_CUT) ? "CUT"
@@ -1167,8 +1167,8 @@ static int balance_leaf(struct tree_bala
 		   not set correctly */
 		if (tb->CFL[0]) {
 			if (!tb->CFR[0])
-				reiserfs_panic(tb->tb_sb,
-					       "vs-12195: balance_leaf: CFR not initialized");
+				reiserfs_panic(tb->tb_sb, "vs-12195",
+				               "CFR not initialized");
 			copy_key(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]),
 				 B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]));
 			do_balance_mark_internal_dirty(tb, tb->CFL[0], 0);
@@ -1475,7 +1475,8 @@ static int balance_leaf(struct tree_bala
 					    && (pos_in_item != ih_item_len(ih)
 						|| tb->insert_size[0] <= 0))
 						reiserfs_panic(tb->tb_sb,
-							       "PAP-12235: balance_leaf: pos_in_item must be equal to ih_item_len");
+						               "PAP-12235",
+							       "pos_in_item must be equal to ih_item_len");
 #endif				/* CONFIG_REISERFS_CHECK */
 
 					ret_val =
@@ -1535,8 +1536,8 @@ static int balance_leaf(struct tree_bala
 			}
 			break;
 		default:	/* cases d and t */
-			reiserfs_panic(tb->tb_sb,
-				       "PAP-12245: balance_leaf: blknum > 2: unexpectable mode: %s(%d)",
+			reiserfs_panic(tb->tb_sb, "PAP-12245",
+			               "blknum > 2: unexpected mode: %s(%d)",
 				       (flag ==
 					M_DELETE) ? "DELETE" : ((flag ==
 								 M_CUT) ? "CUT"
@@ -1681,7 +1682,7 @@ static int balance_leaf(struct tree_bala
 							print_cur_tb("12285");
 							reiserfs_panic(tb->
 								       tb_sb,
-								       "PAP-12285: balance_leaf: insert_size must be 0 (%d)",
+								       "PAP-12285", "insert_size must be 0 (%d)",
 								       tb->
 								       insert_size
 								       [0]);
@@ -1697,11 +1698,10 @@ static int balance_leaf(struct tree_bala
 	if (flag == M_PASTE && tb->insert_size[0]) {
 		print_cur_tb("12290");
 		reiserfs_panic(tb->tb_sb,
-			       "PAP-12290: balance_leaf: insert_size is still not 0 (%d)",
-			       tb->insert_size[0]);
+		               "PAP-12290", "insert_size is still not 0 (%d)",
+		               tb->insert_size[0]);
 	}
 #endif				/* CONFIG_REISERFS_CHECK */
-
 	return 0;
 }				/* Leaf level of the tree is balanced (end of balance_leaf) */
 
@@ -1732,8 +1732,7 @@ struct buffer_head *get_FEB(struct tree_
 			break;
 
 	if (i == MAX_FEB_SIZE)
-		reiserfs_panic(tb->tb_sb,
-			       "vs-12300: get_FEB: FEB list is empty");
+		reiserfs_panic(tb->tb_sb, "vs-12300", "FEB list is empty");
 
 	bi.tb = tb;
 	bi.bi_bh = first_b = tb->FEB[i];
@@ -1776,7 +1775,7 @@ static void free_thrown(struct tree_bala
 			if (buffer_dirty(tb->thrown[i]))
 				reiserfs_warning(tb->tb_sb, "reiserfs-12322",
 				                 "called with dirty buffer %d",
-						 blocknr);
+				                 blocknr);
 			brelse(tb->thrown[i]);	/* incremented in store_thrown */
 			reiserfs_free_block(tb->transaction_handle, NULL,
 					    blocknr, 0);
@@ -1873,8 +1872,8 @@ static void check_internal_node(struct s
 	for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) {
 		if (!is_reusable(s, dc_block_number(dc), 1)) {
 			print_cur_tb(mes);
-			reiserfs_panic(s,
-				       "PAP-12338: check_internal_node: invalid child pointer %y in %b",
+			reiserfs_panic(s, "PAP-12338",
+			               "invalid child pointer %y in %b",
 				       dc, bh);
 		}
 	}
@@ -1896,9 +1895,10 @@ static int check_before_balancing(struct
 	int retval = 0;
 
 	if (cur_tb) {
-		reiserfs_panic(tb->tb_sb, "vs-12335: check_before_balancing: "
-			       "suspect that schedule occurred based on cur_tb not being null at this point in code. "
-			       "do_balance cannot properly handle schedule occurring while it runs.");
+		reiserfs_panic(tb->tb_sb, "vs-12335", "suspect that schedule "
+		               "occurred based on cur_tb not being null at "
+		               "this point in code. do_balance cannot properly "
+		               "handle schedule occurring while it runs.");
 	}
 
 	/* double check that buffers that we will modify are unlocked. (fix_nodes should already have
@@ -1930,8 +1930,8 @@ static void check_after_balance_leaf(str
 		    dc_size(B_N_CHILD
 			    (tb->FL[0], get_left_neighbor_position(tb, 0)))) {
 			print_cur_tb("12221");
-			reiserfs_panic(tb->tb_sb,
-				       "PAP-12355: check_after_balance_leaf: shift to left was incorrect");
+			reiserfs_panic(tb->tb_sb, "PAP-12355",
+			               "shift to left was incorrect");
 		}
 	}
 	if (tb->rnum[0]) {
@@ -1940,8 +1940,8 @@ static void check_after_balance_leaf(str
 		    dc_size(B_N_CHILD
 			    (tb->FR[0], get_right_neighbor_position(tb, 0)))) {
 			print_cur_tb("12222");
-			reiserfs_panic(tb->tb_sb,
-				       "PAP-12360: check_after_balance_leaf: shift to right was incorrect");
+			reiserfs_panic(tb->tb_sb, "PAP-12360",
+			               "shift to right was incorrect");
 		}
 	}
 	if (PATH_H_PBUFFER(tb->tb_path, 1) &&
@@ -1966,8 +1966,7 @@ static void check_after_balance_leaf(str
 					 (PATH_H_PBUFFER(tb->tb_path, 1),
 					  PATH_H_POSITION(tb->tb_path, 1))),
 				 right);
-		reiserfs_panic(tb->tb_sb,
-			       "PAP-12365: check_after_balance_leaf: S is incorrect");
+		reiserfs_panic(tb->tb_sb, "PAP-12365", "S is incorrect");
 	}
 }
 
@@ -2102,8 +2101,7 @@ void do_balance(struct tree_balance *tb,
 	tb->need_balance_dirty = 0;
 
 	if (FILESYSTEM_CHANGED_TB(tb)) {
-		reiserfs_panic(tb->tb_sb,
-			       "clm-6000: do_balance, fs generation has changed\n");
+		reiserfs_panic(tb->tb_sb, "clm-6000", "fs generation has changed");
 	}
 	/* if we have no real work to do  */
 	if (!tb->insert_size[0]) {
fs/reiserfs/file.c +18 -14
@@ -413,7 +413,8 @@ static int reiserfs_allocate_blocks_for_
 								 (char *)zeros);
 				} else {
 					reiserfs_panic(inode->i_sb,
-						       "green-9011: Unexpected key type %K\n",
+					               "green-9011",
+						       "Unexpected key type %K",
 						       &key);
 				}
 				if (res) {
@@ -615,9 +616,8 @@ static int reiserfs_allocate_blocks_for_
 						 (char *)(allocated_blocks +
 							  curr_block));
 		} else {
-			reiserfs_panic(inode->i_sb,
-				       "green-9010: unexpected item type for key %K\n",
-				       &key);
+			reiserfs_panic(inode->i_sb, "green-9010",
+			               "unexpected item type for key %K", &key);
 		}
 	}
 	// the caller is responsible for closing the transaction
@@ -642,15 +642,16 @@ static int reiserfs_allocate_blocks_for_
 		int block_start, block_end;	// in-page offsets for buffers.
 
 		if (!page_buffers(page))
-			reiserfs_panic(inode->i_sb,
-				       "green-9005: No buffers for prepared page???");
+			reiserfs_panic(inode->i_sb, "green-9005",
+			               "No buffers for prepared page???");
 
 		/* For each buffer in page */
 		for (bh = head, block_start = 0; bh != head || !block_start;
 		     block_start = block_end, bh = bh->b_this_page) {
 			if (!bh)
-				reiserfs_panic(inode->i_sb,
-					       "green-9006: Allocated but absent buffer for a page?");
+				reiserfs_panic(inode->i_sb, "green-9006",
+				               "Allocated but absent buffer "
+					       "for a page?");
 			block_end = block_start + inode->i_sb->s_blocksize;
 			if (i == 0 && block_end <= from)
 				/* if this buffer is before requested data to map, skip it */
@@ -1091,8 +1092,9 @@ static int reiserfs_prepare_file_region_
 		for (bh = head, block_start = 0; bh != head || !block_start;
 		     block_start = block_end, bh = bh->b_this_page) {
 			if (!bh)
-				reiserfs_panic(inode->i_sb,
-					       "green-9002: Allocated but absent buffer for a page?");
+				reiserfs_panic(inode->i_sb, "green-9002",
+				               "Allocated but absent "
+					       "buffer for a page?");
 			/* Find where this buffer ends */
 			block_end = block_start + inode->i_sb->s_blocksize;
 			if (i == 0 && block_end <= from)
@@ -1178,8 +1180,9 @@ static int reiserfs_prepare_file_region_
 		     block_start = block_end, bh = bh->b_this_page) {
 
 			if (!bh)
-				reiserfs_panic(inode->i_sb,
-					       "green-9002: Allocated but absent buffer for a page?");
+				reiserfs_panic(inode->i_sb, "green-9002",
+				               "Allocated but absent "
+					       "buffer for a page?");
 			/* Find where this buffer ends */
 			block_end = block_start + inode->i_sb->s_blocksize;
 			if (block_end <= from)
@@ -1212,8 +1215,9 @@ static int reiserfs_prepare_file_region_
 		     block_start = block_end, bh = bh->b_this_page) {
 
 			if (!bh)
-				reiserfs_panic(inode->i_sb,
-					       "green-9002: Allocated but absent buffer for a page?");
+				reiserfs_panic(inode->i_sb, "green-9002",
+				               "Allocated but absent "
+					       "buffer for a page?");
 			/* Find where this buffer ends */
 			block_end = block_start + inode->i_sb->s_blocksize;
 			if (block_start >= to)
fs/reiserfs/fix_node.c +38 -36

147 lines not on this page · raw message

fs/reiserfs/ibalance.c +6 -6
@@ -105,8 +105,8 @@ static void internal_define_dest_src_inf
 		break;
 
 	default:
-		reiserfs_panic(tb->tb_sb,
-			       "internal_define_dest_src_infos: shift type is unknown (%d)",
+		reiserfs_panic(tb->tb_sb, "ibalance-1",
+			       "shift type is unknown (%d)",
 			       shift_mode);
 	}
 }
@@ -702,8 +702,8 @@ static void balance_internal_when_delete
 
 		return;
 	}
-	reiserfs_panic(tb->tb_sb,
-		       "balance_internal_when_delete: unexpected tb->lnum[%d]==%d or tb->rnum[%d]==%d",
+	reiserfs_panic(tb->tb_sb, "ibalance-2",
+		       "unexpected tb->lnum[%d]==%d or tb->rnum[%d]==%d",
 		       h, tb->lnum[h], h, tb->rnum[h]);
 }
 
@@ -940,8 +940,8 @@ int balance_internal(struct tree_balance
 		struct block_head *blkh;
 
 		if (tb->blknum[h] != 1)
-			reiserfs_panic(NULL,
-				       "balance_internal: One new node required for creating the new root");
+			reiserfs_panic(NULL, "ibalance-3", "One new node "
+			               "required for creating the new root");
 		/* S[h] = empty buffer from the list FEB. */
 		tbSh = get_FEB(tb);
 		blkh = B_BLK_HEAD(tbSh);
fs/reiserfs/inode.c +1 -2
@@ -1295,8 +1295,7 @@ static void update_stat_data(struct tree
 	ih = PATH_PITEM_HEAD(path);
 
 	if (!is_statdata_le_ih(ih))
-		reiserfs_panic(inode->i_sb,
-			       "vs-13065: update_stat_data: key %k, found item %h",
+		reiserfs_panic(inode->i_sb, "vs-13065", "key %k, found item %h",
 			       INODE_PKEY(inode), ih);
 
 	if (stat_data_v1(ih)) {
fs/reiserfs/item_ops.c +5 -3
@@ -517,8 +517,9 @@ static int direntry_create_vi(struct vir
 		    ((is_affected
 		      && (vn->vn_mode == M_PASTE
 			  || vn->vn_mode == M_CUT)) ? insert_size : 0)) {
-			reiserfs_panic(NULL,
-				       "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item",
+			reiserfs_panic(NULL, "vs-8025", "(mode==%c, "
+			               "insert_size==%d), invalid length of "
+				       "directory item",
 				       vn->vn_mode, insert_size);
 		}
 	}
@@ -549,7 +550,8 @@ static int direntry_check_left(struct vi
 	}
 
 	if (entries == dir_u->entry_count) {
-		reiserfs_panic(NULL, "free space %d, entry_count %d\n", free,
+		reiserfs_panic(NULL, "item_ops-1",
+		               "free space %d, entry_count %d", free,
 			       dir_u->entry_count);
 	}
 
fs/reiserfs/journal.c +28 -28

143 lines not on this page · raw message

fs/reiserfs/lbalance.c +15 -12
@@ -168,10 +168,11 @@ static int leaf_copy_boundary_item(struc
 			if (bytes_or_entries == ih_item_len(ih)
 			    && is_indirect_le_ih(ih))
 				if (get_ih_free_space(ih))
-					reiserfs_panic(NULL,
-						       "vs-10020: leaf_copy_boundary_item: "
-						       "last unformatted node must be filled entirely (%h)",
-						       ih);
+					reiserfs_panic(sb_from_bi(dest_bi),
+					               "vs-10020",
+						       "last unformatted node "
+						       "must be filled "
+						       "entirely (%h)", ih);
 		}
 #endif
 
@@ -622,9 +623,8 @@ static void leaf_define_dest_src_infos(i
 		break;
 
 	default:
-		reiserfs_panic(NULL,
-			       "vs-10250: leaf_define_dest_src_infos: shift type is unknown (%d)",
-			       shift_mode);
+		reiserfs_panic(sb_from_bi(src_bi), "vs-10250",
+		               "shift type is unknown (%d)", shift_mode);
 	}
 	RFALSE(src_bi->bi_bh == 0 || dest_bi->bi_bh == 0,
 	       "vs-10260: mode==%d, source (%p) or dest (%p) buffer is initialized incorrectly",
@@ -674,9 +674,9 @@ int leaf_shift_left(struct tree_balance 
 #ifdef CONFIG_REISERFS_CHECK
 			if (tb->tb_mode == M_PASTE || tb->tb_mode == M_INSERT) {
 				print_cur_tb("vs-10275");
-				reiserfs_panic(tb->tb_sb,
-					       "vs-10275: leaf_shift_left: balance condition corrupted (%c)",
-					       tb->tb_mode);
+				reiserfs_panic(tb->tb_sb, "vs-10275",
+				               "balance condition corrupted "
+					       "(%c)", tb->tb_mode);
 			}
 #endif
 
@@ -889,9 +889,12 @@ void leaf_paste_in_buffer(struct buffer_
 
 #ifdef CONFIG_REISERFS_CHECK
 	if (zeros_number > paste_size) {
+		struct super_block *sb = NULL;
+		if (bi && bi->tb)
+			sb = bi->tb->tb_sb;
 		print_cur_tb("10177");
-		reiserfs_panic(NULL,
-			       "vs-10177: leaf_paste_in_buffer: ero number == %d, paste_size == %d",
+		reiserfs_panic(sb, "vs-10177",
+		               "zeros_number == %d, paste_size == %d",
 			       zeros_number, paste_size);
 	}
 #endif				/* CONFIG_REISERFS_CHECK */
fs/reiserfs/namei.c +8 -10
@@ -145,10 +145,9 @@ int search_by_entry_key(struct super_blo
 	if (!is_direntry_le_ih(de->de_ih) ||
 	    COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) {
 		print_block(de->de_bh, 0, -1, -1);
-		reiserfs_panic(sb,
-			       "vs-7005: search_by_entry_key: found item %h is not directory item or "
-			       "does not belong to the same directory as key %K",
-			       de->de_ih, key);
+		reiserfs_panic(sb, "vs-7005", "found item %h is not directory "
+		               "item or does not belong to the same directory "
+			       "as key %K", de->de_ih, key);
 	}
 #endif				/* CONFIG_REISERFS_CHECK */
 
@@ -1194,15 +1193,14 @@ static int entry_points_to_object(const 
 
 	if (inode) {
 		if (!de_visible(de->de_deh + de->de_entry_num))
-			reiserfs_panic(NULL,
-				       "vs-7042: entry_points_to_object: entry must be visible");
+			reiserfs_panic(inode->i_sb, "vs-7042",
+			               "entry must be visible");
 		return (de->de_objectid == inode->i_ino) ? 1 : 0;
 	}
 
 	/* this must be added hidden entry */
 	if (de_visible(de->de_deh + de->de_entry_num))
-		reiserfs_panic(NULL,
-			       "vs-7043: entry_points_to_object: entry must be visible");
+		reiserfs_panic(NULL, "vs-7043", "entry must be visible");
 
 	return 1;
 }
@@ -1316,8 +1314,8 @@ static int reiserfs_rename(struct inode 
 			       new_dentry->d_name.len, old_inode, 0);
 	if (retval == -EEXIST) {
 		if (!new_dentry_inode) {
-			reiserfs_panic(old_dir->i_sb,
-				       "vs-7050: new entry is found, new inode == 0\n");
+			reiserfs_panic(old_dir->i_sb, "vs-7050",
+			               "new entry is found, new inode == 0");
 		}
 	} else if (retval) {
 		int err = journal_end(&th, old_dir->i_sb, jbegin_count);
fs/reiserfs/objectid.c +1 -2
@@ -18,8 +18,7 @@
 static void check_objectid_map(struct super_block *s, __le32 * map)
 {
 	if (le32_to_cpu(map[0]) != 1)
-		reiserfs_panic(s,
-			       "vs-15010: check_objectid_map: map corrupted: %lx",
+		reiserfs_panic(s, "vs-15010", "map corrupted: %lx",
 			       (long unsigned int)le32_to_cpu(map[0]));
 
 	// FIXME: add something else here
fs/reiserfs/prints.c +18 -16
@@ -356,11 +356,21 @@ void reiserfs_debug(struct super_block *
 extern struct tree_balance *cur_tb;
 #endif
 
-void reiserfs_panic(struct super_block *sb, const char *fmt, ...)
+void __reiserfs_panic(struct super_block *sb, const char *id,
+                      const char *function, const char *fmt, ...)
 {
 	do_reiserfs_warning(fmt);
-	panic(KERN_EMERG "REISERFS: panic (device %s): %s\n",
-	       reiserfs_bdevname(sb), error_buf);
+
+#ifdef CONFIG_REISERFS_CHECK
+	dump_stack();
+#endif
+	if (sb)
+		panic(KERN_WARNING "REISERFS panic (device %s): %s%s%s: %s\n",
+		      sb->s_id, id ? id : "", id ? " " : "",
+		      function, error_buf);
+	else
+		panic(KERN_WARNING "REISERFS panic: %s%s%s: %s\n",
+		      id ? id : "", id ? " " : "", function, error_buf);
 }
 
 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
@@ -679,12 +689,10 @@ static void check_leaf_block_head(struct
 	blkh = B_BLK_HEAD(bh);
 	nr = blkh_nr_item(blkh);
 	if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
-		reiserfs_panic(NULL,
-			       "vs-6010: check_leaf_block_head: invalid item number %z",
+		reiserfs_panic(NULL, "vs-6010", "invalid item number %z",
 			       bh);
 	if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
-		reiserfs_panic(NULL,
-			       "vs-6020: check_leaf_block_head: invalid free space %z",
+		reiserfs_panic(NULL, "vs-6020", "invalid free space %z",
 			       bh);
 
 }
@@ -695,21 +703,15 @@ static void check_internal_block_head(st
 
 	blkh = B_BLK_HEAD(bh);
 	if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
-		reiserfs_panic(NULL,
-			       "vs-6025: check_internal_block_head: invalid level %z",
-			       bh);
+		reiserfs_panic(NULL, "vs-6025", "invalid level %z", bh);
 
 	if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
-		reiserfs_panic(NULL,
-			       "vs-6030: check_internal_block_head: invalid item number %z",
-			       bh);
+		reiserfs_panic(NULL, "vs-6030", "invalid item number %z", bh);
 
 	if (B_FREE_SPACE(bh) !=
 	    bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
 	    DC_SIZE * (B_NR_ITEMS(bh) + 1))
-		reiserfs_panic(NULL,
-			       "vs-6040: check_internal_block_head: invalid free space %z",
-			       bh);
+		reiserfs_panic(NULL, "vs-6040", "invalid free space %z", bh);
 
 }
 
fs/reiserfs/stree.c +23 -26

97 lines not on this page · raw message

fs/reiserfs/tail_conversion.c +4 -6
@@ -92,8 +92,7 @@ int direct2indirect(struct reiserfs_tran
 		   last item of the file */
 		if (search_for_position_by_key(sb, &end_key, path) ==
 		    POSITION_FOUND)
-			reiserfs_panic(sb,
-				       "PAP-14050: direct2indirect: "
+			reiserfs_panic(sb, "PAP-14050",
 				       "direct item (%K) not found", &end_key);
 		p_le_ih = PATH_PITEM_HEAD(path);
 		RFALSE(!is_direct_le_ih(p_le_ih),
@@ -214,8 +213,7 @@ int indirect2direct(struct reiserfs_tran
 		/* re-search indirect item */
 		if (search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path)
 		    == POSITION_NOT_FOUND)
-			reiserfs_panic(p_s_sb,
-				       "PAP-5520: indirect2direct: "
+			reiserfs_panic(p_s_sb, "PAP-5520",
 				       "item to be converted %K does not exist",
 				       p_s_item_key);
 		copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
@@ -224,8 +222,8 @@ int indirect2direct(struct reiserfs_tran
 		    (ih_item_len(&s_ih) / UNFM_P_SIZE -
 		     1) * p_s_sb->s_blocksize;
 		if (pos != pos1)
-			reiserfs_panic(p_s_sb, "vs-5530: indirect2direct: "
-				       "tail position changed while we were reading it");
+			reiserfs_panic(p_s_sb, "vs-5530", "tail position "
+			               "changed while we were reading it");
 #endif
 	}
 
include/linux/reiserfs_fs.h +18 -5
@@ -84,11 +84,11 @@ void __reiserfs_warning(struct super_blo
 /* assertions handling */
 
 /** always check a condition and panic if it's false. */
-#define RASSERT( cond, format, args... )					\
-if( !( cond ) ) 								\
-  reiserfs_panic( NULL, "reiserfs[%i]: assertion " #cond " failed at "	\
+#define RASSERT( cond, format, args... )			\
+if( !( cond ) )							\
+  reiserfs_panic( NULL, "assertion failure", "(" #cond ") at "	\
 		  __FILE__ ":%i:%s: " format "\n",		\
-		  in_interrupt() ? -1 : current -> pid, __LINE__ , __FUNCTION__ , ##args )
+		  __LINE__ , __FUNCTION__ , ##args )
 
 #if defined( CONFIG_REISERFS_CHECK )
 #define RFALSE( cond, format, args... ) RASSERT( !( cond ), format, ##args )
@@ -1431,6 +1431,16 @@ struct buffer_info {
 	int bi_position;
 };
 
+static inline struct super_block *sb_from_tb(struct tree_balance *tb)
+{
+	return tb ? tb->tb_sb : NULL;
+}
+
+static inline struct super_block *sb_from_bi(struct buffer_info *bi)
+{
+	return bi ? sb_from_tb(bi->tb) : NULL;
+}
+
 /* there are 4 types of items: stat data, directory item, indirect, direct.
 +-------------------+------------+--------------+------------+
 |	            |  k_offset  | k_uniqueness | mergeable? |
@@ -1977,8 +1987,11 @@ int fix_nodes(int n_op_mode, struct tree
 void unfix_nodes(struct tree_balance *);
 
 /* prints.c */
-void reiserfs_panic(struct super_block *s, const char *fmt, ...)
+void __reiserfs_panic(struct super_block *s, const char *id,
+                      const char *function, const char *fmt, ...)
     __attribute__ ((noreturn));
+#define reiserfs_panic(s, id, fmt, args...) \
+        __reiserfs_panic(s, id, __FUNCTION__, fmt, ##args)
 void reiserfs_info(struct super_block *s, const char *fmt, ...);
 void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);
 void print_indirect_item(struct buffer_head *bh, int item_num);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#10 lore raw

PATCH 9/40 reiserfs: rearrange journal abort

In reply to [email protected]

This patch kills off reiserfs_journal_abort as it is never called, and combines __reiserfs_journal_abort_{soft,hard} into one function called reiserfs_abort_journal, which performs the same work. It is silent as opposed to the old version, since the message was always issued after a regular 'abort' message.

---
 fs/reiserfs/journal.c       |   23 ++++-------------------
 fs/reiserfs/prints.c        |    2 +-
 include/linux/reiserfs_fs.h |    2 +-
 3 files changed, 6 insertions(+), 21 deletions(-)
fs/reiserfs/journal.c +4 -19
@@ -4256,14 +4256,15 @@ static int do_journal_end(struct reiserf
 	return journal->j_errno;
 }
 
-static void __reiserfs_journal_abort_hard(struct super_block *sb)
+/* Send the file system read only and refuse new transactions */
+void reiserfs_abort_journal(struct super_block *sb, int errno)
 {
 	struct reiserfs_journal *journal = SB_JOURNAL(sb);
 	if (test_bit(J_ABORTED, &journal->j_state))
 		return;
 
-	printk(KERN_CRIT "REISERFS: Aborting journal for filesystem on %s\n",
-	       reiserfs_bdevname(sb));
+	if (!journal->j_errno)
+		journal->j_errno = errno;
 
 	sb->s_flags |= MS_RDONLY;
 	set_bit(J_ABORTED, &journal->j_state);
@@ -4273,19 +4274,3 @@ static void __reiserfs_journal_abort_har
 #endif
 }
 
-static void __reiserfs_journal_abort_soft(struct super_block *sb, int errno)
-{
-	struct reiserfs_journal *journal = SB_JOURNAL(sb);
-	if (test_bit(J_ABORTED, &journal->j_state))
-		return;
-
-	if (!journal->j_errno)
-		journal->j_errno = errno;
-
-	__reiserfs_journal_abort_hard(sb);
-}
-
-void reiserfs_journal_abort(struct super_block *sb, int errno)
-{
-	return __reiserfs_journal_abort_soft(sb, errno);
-}
fs/reiserfs/prints.c +1 -1
@@ -389,7 +389,7 @@ void reiserfs_abort(struct super_block *
 	       error_buf);
 
 	sb->s_flags |= MS_RDONLY;
-	reiserfs_journal_abort(sb, errno);
+	reiserfs_abort_journal(sb, errno);
 }
 
 /* this prints internal nodes (4 keys/items in line) (dc_number,
include/linux/reiserfs_fs.h +1 -1
@@ -1753,7 +1753,7 @@ int journal_begin(struct reiserfs_transa
 		  struct super_block *p_s_sb, unsigned long);
 int journal_join_abort(struct reiserfs_transaction_handle *,
 		       struct super_block *p_s_sb, unsigned long);
-void reiserfs_journal_abort(struct super_block *sb, int errno);
+void reiserfs_abort_journal(struct super_block *sb, int errno);
 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
 int reiserfs_allocate_list_bitmaps(struct super_block *s,
 				   struct reiserfs_list_bitmap *, int);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#11 lore raw

PATCH 10/40 reiserfs: introduce reiserfs_error()

In reply to [email protected]

Although reiserfs can currently handle severe errors such as journal failure, it cannot handle less severe errors like metadata i/o failure. The following patch adds a reiserfs_error() function akin to the one in ext3.

Subsequent patches will use this new error handler to handle errors more gracefully in general.

--

 fs/reiserfs/prints.c        |   23 +++++++++++++++++++++++
 include/linux/reiserfs_fs.h |    3 +++
 2 files changed, 26 insertions(+)
fs/reiserfs/prints.c +23 -0
@@ -373,6 +373,29 @@ void __reiserfs_panic(struct super_block
 		      id ? id : "", id ? " " : "", function, error_buf);
 }
 
+void __reiserfs_error(struct super_block *sb, const char *id,
+                      const char *function, const char *fmt, ...)
+{
+	do_reiserfs_warning(fmt);
+
+	if (reiserfs_error_panic(sb))
+		__reiserfs_panic(sb, id, function, error_buf);
+
+	if (id && id[0])
+		printk(KERN_CRIT "REISERFS error (device %s): %s %s: %s\n",
+	               sb->s_id, id, function, error_buf);
+	else
+		printk(KERN_CRIT "REISERFS error (device %s): %s: %s\n",
+	               sb->s_id, function, error_buf);
+
+	if (sb->s_flags & MS_RDONLY)
+		return;
+
+	reiserfs_info(sb, "Remounting filesystem read-only\n");
+	sb->s_flags |= MS_RDONLY;
+	reiserfs_abort_journal(sb, -EIO);
+}
+
 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
 {
 	do_reiserfs_warning(fmt);
include/linux/reiserfs_fs.h +3 -0
@@ -1992,6 +1992,9 @@ void __reiserfs_panic(struct super_block
     __attribute__ ((noreturn));
 #define reiserfs_panic(s, id, fmt, args...) \
         __reiserfs_panic(s, id, __FUNCTION__, fmt, ##args)
+void __reiserfs_error(struct super_block *s, const char *id, const char *function, const char *fmt, ...);
+#define reiserfs_error(s, id, fmt, args...) \
+        __reiserfs_error(s, id, __FUNCTION__, fmt, ##args)
 void reiserfs_info(struct super_block *s, const char *fmt, ...);
 void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);
 void print_indirect_item(struct buffer_head *bh, int item_num);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#12 lore raw

PATCH 11/40 reiserfs: use reiserfs_error()

In reply to [email protected]

This patch makes many paths that are currently using warnings to handle the error.

--

 fs/reiserfs/bitmap.c          |   55 ++++++++++++++++-----------------
 fs/reiserfs/file.c            |   14 ++++----
 fs/reiserfs/inode.c           |   43 ++++++++++++-------------
 fs/reiserfs/lbalance.c        |   20 ++++++------
 fs/reiserfs/namei.c           |   24 +++++++-------
 fs/reiserfs/objectid.c        |    4 +-
 fs/reiserfs/stree.c           |   70 +++++++++++++++++++++---------------------
 fs/reiserfs/super.c           |   15 ++++-----
 fs/reiserfs/tail_conversion.c |    6 +--
 fs/reiserfs/xattr.c           |   21 ++++++------
 10 files changed, 134 insertions(+), 138 deletions(-)
fs/reiserfs/bitmap.c +28 -27
@@ -61,9 +61,9 @@ int is_reusable(struct super_block *s, b
 	int bmap, offset;
 
 	if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
-		reiserfs_warning(s, "vs-4010",
-		                 "block number is out of range %lu (%u)",
-				 block, SB_BLOCK_COUNT(s));
+		reiserfs_error(s, "vs-4010",
+		               "block number is out of range %lu (%u)",
+			       block, SB_BLOCK_COUNT(s));
 		return 0;
 	}
 
@@ -75,30 +75,30 @@ int is_reusable(struct super_block *s, b
 			      &(REISERFS_SB(s)->s_properties)))) {
 		b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
 		if (block >= bmap1 && block <= bmap1 + SB_BMAP_NR(s)) {
-			reiserfs_warning(s, "vs-4019", "bitmap block "
-			                 "%lu(%u) can't be freed or reused",
-					 block, SB_BMAP_NR(s));
+			reiserfs_error(s, "vs-4019", "bitmap block "
+			               "%lu(%u) can't be freed or reused",
+				       block, SB_BMAP_NR(s));
 			return 0;
 		}
 	} else {
 		if (offset == 0) {
-			reiserfs_warning(s, "vs-4020", "bitmap block "
-			                 "%lu(%u) can't be freed or reused",
-					 block, SB_BMAP_NR(s));
+			reiserfs_error(s, "vs-4020", "bitmap block "
+			               "%lu(%u) can't be freed or reused",
+				       block, SB_BMAP_NR(s));
 			return 0;
 		}
 	}
 
 	if (bmap >= SB_BMAP_NR(s)) {
-		reiserfs_warning(s, "vs-4030", "there is no so many "
-		                 "bitmap blocks: block=%lu, bitmap_nr=%d",
-				 block, bmap);
+		reiserfs_error(s, "vs-4030", "there is no so many "
+		               "bitmap blocks: block=%lu, bitmap_nr=%d",
+			       block, bmap);
 		return 0;
 	}
 
 	if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
-		reiserfs_warning(s, "vs-4050", "this is root block (%u), "
-				 "it must be busy", SB_ROOT_BLOCK(s));
+		reiserfs_error(s, "vs-4050", "this is root block (%u), "
+		               "it must be busy", SB_ROOT_BLOCK(s));
 		return 0;
 	}
 
@@ -149,8 +149,8 @@ static int scan_bitmap_block(struct reis
 /* - I mean `a window of zero bits' as in description of this function - Zam. */
 
 	if (!bi) {
-		reiserfs_warning(s, "jdm-4055", "NULL bitmap info pointer "
-		                 "for bitmap %d", bmap_n);
+		reiserfs_error(s, "jdm-4055", "NULL bitmap info pointer "
+		               "for bitmap %d", bmap_n);
 		return 0;
 	}
 
@@ -398,8 +398,8 @@ static void _reiserfs_free_block(struct 
 	get_bit_address(s, block, &nr, &offset);
 
 	if (nr >= sb_bmap_nr(rs)) {
- 		reiserfs_warning(s, "vs-4075",
-				 "block %lu is out of range", block);
+		reiserfs_error(s, "vs-4075",
+		               "block %lu is out of range", block);
 		return;
 	}
 
@@ -411,8 +411,8 @@ static void _reiserfs_free_block(struct 
 
 	/* clear bit for the given block in bit map */
 	if (!reiserfs_test_and_clear_le_bit(offset, bmbh->b_data)) {
-		reiserfs_warning(s, "vs-4080",
-		                 "block %lu: bit already cleared", block);
+		reiserfs_error(s, "vs-4080",
+		               "block %lu: bit already cleared", block);
 	}
 	apbi[nr].free_count++;
 	journal_mark_dirty(th, s, bmbh);
@@ -471,8 +471,8 @@ static void __discard_prealloc(struct re
 	BUG_ON(!th->t_trans_id);
 #ifdef CONFIG_REISERFS_CHECK
 	if (ei->i_prealloc_count < 0)
-		reiserfs_warning(th->t_super, "zam-4001",
-		                 "inode has negative prealloc blocks count.");
+		reiserfs_error(th->t_super, "zam-4001",
+		               "inode has negative prealloc blocks count.");
 #endif
 	while (ei->i_prealloc_count > 0) {
 		reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block);
@@ -508,9 +508,9 @@ void reiserfs_discard_all_prealloc(struc
 				i_prealloc_list);
 #ifdef CONFIG_REISERFS_CHECK
 		if (!ei->i_prealloc_count) {
-			reiserfs_warning(th->t_super, "zam-4001",
-			                 "inode is in prealloc list but has "
-					 "no preallocated blocks.");
+			reiserfs_error(th->t_super, "zam-4001",
+			               "inode is in prealloc list but has "
+			               "no preallocated blocks.");
 		}
 #endif
 		__discard_prealloc(th, ei);
@@ -1287,8 +1287,9 @@ void reiserfs_cache_bitmap_metadata(stru
 			}
 		}
 	}
-	/* The first bit must ALWAYS be 1 */
-	BUG_ON(info->first_zero_hint == 0);
+	if (info->first_zero_hint == 0)
+		reiserfs_error(sb, "reiserfs-2025", "bitmap block %lu is "
+		               "corrupted: first bit must be 1", bh->b_blocknr);
 }
 
 struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
fs/reiserfs/file.c +7 -7
@@ -395,7 +395,7 @@ static int reiserfs_allocate_blocks_for_
 					if (res != ITEM_NOT_FOUND) {
 						/* item should not exist, otherwise we have error */
 						if (res != -ENOSPC) {
-							reiserfs_warning(inode->
+							reiserfs_error(inode->
 									 i_sb,
 									 "green-9008",
 									 "search_by_key (%K) returned %d",
@@ -412,7 +412,7 @@ static int reiserfs_allocate_blocks_for_
 								 inode,
 								 (char *)zeros);
 				} else {
-					reiserfs_panic(inode->i_sb,
+					reiserfs_error(inode->i_sb,
 					               "green-9011",
 						       "Unexpected key type %K",
 						       &key);
@@ -600,11 +600,11 @@ static int reiserfs_allocate_blocks_for_
 				/* Well, if we have found such item already, or some error
 				   occured, we need to warn user and return error */
 				if (res != -ENOSPC) {
-					reiserfs_warning(inode->i_sb,
-							 "green-9009",
-							 "search_by_key (%K) "
-							 "returned %d", &key,
-							 res);
+					reiserfs_error(inode->i_sb,
+					               "green-9009",
+					               "search_by_key (%K) "
+					               "returned %d", &key,
+					               res);
 				}
 				res = -EIO;
 				goto error_exit_free_blocks;
fs/reiserfs/inode.c +20 -23

85 lines not on this page · raw message

fs/reiserfs/lbalance.c +10 -10
@@ -1290,17 +1290,17 @@ void leaf_paste_entries(struct buffer_he
 			prev = (i != 0) ? deh_location(&(deh[i - 1])) : 0;
 
 			if (prev && prev <= deh_location(&(deh[i])))
-				reiserfs_warning(NULL, "vs-10240",
-				                 "directory item (%h) "
-						 "corrupted (prev %a, "
-						 "cur(%d) %a)",
-						 ih, deh + i - 1, i, deh + i);
+				reiserfs_error(NULL, "vs-10240",
+				               "directory item (%h) "
+				               "corrupted (prev %a, "
+				               "cur(%d) %a)",
+				               ih, deh + i - 1, i, deh + i);
 			if (next && next >= deh_location(&(deh[i])))
-				reiserfs_warning(NULL, "vs-10250",
-				                 "directory item (%h) "
-						 "corrupted (cur(%d) %a, "
-						 "next %a)",
-						 ih, i, deh + i, deh + i + 1);
+				reiserfs_error(NULL, "vs-10250",
+				               "directory item (%h) "
+				               "corrupted (cur(%d) %a, "
+				               "next %a)",
+				               ih, i, deh + i, deh + i + 1);
 		}
 	}
 #endif
fs/reiserfs/namei.c +12 -12
@@ -120,8 +120,8 @@ int search_by_entry_key(struct super_blo
 	switch (retval) {
 	case ITEM_NOT_FOUND:
 		if (!PATH_LAST_POSITION(path)) {
-			reiserfs_warning(sb, "vs-7000", "search_by_key "
-			                 "returned item position == 0");
+			reiserfs_error(sb, "vs-7000", "search_by_key "
+			               "returned item position == 0");
 			pathrelse(path);
 			return IO_ERROR;
 		}
@@ -135,7 +135,7 @@ int search_by_entry_key(struct super_blo
 
 	default:
 		pathrelse(path);
-		reiserfs_warning(sb, "vs-7002", "no path to here");
+		reiserfs_error(sb, "vs-7002", "no path to here");
 		return IO_ERROR;
 	}
 
@@ -298,7 +298,7 @@ static int reiserfs_find_entry(struct in
 		    search_by_entry_key(dir->i_sb, &key_to_search,
 					path_to_entry, de);
 		if (retval == IO_ERROR) {
-			reiserfs_warning(dir->i_sb, "zam-7001", "io error");
+			reiserfs_error(dir->i_sb, "zam-7001", "io error");
 			return IO_ERROR;
 		}
 
@@ -490,9 +490,9 @@ static int reiserfs_add_entry(struct rei
 		}
 
 		if (retval != NAME_FOUND) {
-			reiserfs_warning(dir->i_sb, "zam-7002",
-			                 "reiserfs_find_entry() returned "
-					 "unexpected value (%d)", retval);
+			reiserfs_error(dir->i_sb, "zam-7002",
+			               "reiserfs_find_entry() returned "
+			               "unexpected value (%d)", retval);
 		}
 
 		return -EEXIST;
@@ -902,9 +902,9 @@ static int reiserfs_rmdir(struct inode *
 		goto end_rmdir;
 
 	if (inode->i_nlink != 2 && inode->i_nlink != 1)
-		reiserfs_warning(inode->i_sb, "reiserfs-7040",
-		                 "empty directory has nlink != 2 (%d)",
-				 inode->i_nlink);
+		reiserfs_error(inode->i_sb, "reiserfs-7040",
+		               "empty directory has nlink != 2 (%d)",
+		               inode->i_nlink);
 
 	clear_nlink(inode);
 	inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
@@ -1495,8 +1495,8 @@ static int reiserfs_rename(struct inode 
 	if (reiserfs_cut_from_item
 	    (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL,
 	     0) < 0)
-		reiserfs_warning(old_dir->i_sb, "vs-7060",
-		                 "couldn't not cut old name. Fsck later?");
+		reiserfs_error(old_dir->i_sb, "vs-7060",
+		               "couldn't not cut old name. Fsck later?");
 
 	old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
 
fs/reiserfs/objectid.c +2 -2
@@ -160,8 +160,8 @@ void reiserfs_release_objectid(struct re
 		i += 2;
 	}
 
-	reiserfs_warning(s, "vs-15011", "tried to free free object id (%lu)",
-			 (long unsigned)objectid_to_release);
+	reiserfs_error(s, "vs-15011", "tried to free free object id (%lu)",
+	               (long unsigned)objectid_to_release);
 }
 
 int reiserfs_convert_objectid_map_v1(struct super_block *s)
fs/reiserfs/stree.c +35 -35

159 lines not on this page · raw message

fs/reiserfs/super.c +7 -8
@@ -190,9 +190,8 @@ static int finish_unfinished(struct supe
 	while (!retval) {
 		retval = search_item(s, &max_cpu_key, &path);
 		if (retval != ITEM_NOT_FOUND) {
-			reiserfs_warning(s, "vs-2140",
-			                 "search_by_key returned %d",
-					 retval);
+			reiserfs_error(s, "vs-2140",
+			               "search_by_key returned %d", retval);
 			break;
 		}
 
@@ -362,9 +361,9 @@ void add_save_link(struct reiserfs_trans
 	retval = search_item(inode->i_sb, &key, &path);
 	if (retval != ITEM_NOT_FOUND) {
 		if (retval != -ENOSPC)
-			reiserfs_warning(inode->i_sb, "vs-2100",
-					 "search_by_key (%K) returned %d", &key,
-					 retval);
+			reiserfs_error(inode->i_sb, "vs-2100",
+			               "search_by_key (%K) returned %d", &key,
+			               retval);
 		pathrelse(&path);
 		return;
 	}
@@ -377,8 +376,8 @@ void add_save_link(struct reiserfs_trans
 	    reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
 	if (retval) {
 		if (retval != -ENOSPC)
-			reiserfs_warning(inode->i_sb, "vs-2120",
-			                 "insert_item returned %d", retval);
+			reiserfs_error(inode->i_sb, "vs-2120",
+			               "insert_item returned %d", retval);
 	} else {
 		if (truncate)
 			REISERFS_I(inode)->i_flags |=
fs/reiserfs/tail_conversion.c +3 -3
@@ -48,9 +48,9 @@ int direct2indirect(struct reiserfs_tran
 
 	// FIXME: we could avoid this 
 	if (search_for_position_by_key(sb, &end_key, path) == POSITION_FOUND) {
-		reiserfs_warning(sb, "PAP-14030",
-				 "pasted or inserted byte exists in "
-				 "the tree %K. Use fsck to repair.", &end_key);
+		reiserfs_error(sb, "PAP-14030",
+		               "pasted or inserted byte exists in "
+		               "the tree %K. Use fsck to repair.", &end_key);
 		pathrelse(path);
 		return -EIO;
 	}
fs/reiserfs/xattr.c +10 -11
@@ -278,8 +278,8 @@ static int __xattr_readdir(struct file *
 		ih = de.de_ih;
 
 		if (!is_direntry_le_ih(ih)) {
-			reiserfs_warning(inode->i_sb, "jdm-20000",
-			                 "not direntry %h", ih);
+			reiserfs_error(inode->i_sb, "jdm-20000",
+			               "not direntry %h", ih);
 			break;
 		}
 		copy_item_head(&tmp_ih, ih);
@@ -674,15 +674,14 @@ __reiserfs_xattr_del(struct dentry *xadi
 		goto out_file;
 
 	if (!is_reiserfs_priv_object(dentry->d_inode)) {
-		reiserfs_warning(dir->i_sb, "jdm-20003",
-		                 "OID %08x [%.*s/%.*s] doesn't have "
-				 "priv flag set [parent is %sset].",
-				 le32_to_cpu(INODE_PKEY(dentry->d_inode)->
-					     k_objectid), xadir->d_name.len,
-				 xadir->d_name.name, namelen, name,
-				 is_reiserfs_priv_object(xadir->
-							 d_inode) ? "" :
-				 "not ");
+		reiserfs_error(dir->i_sb, "jdm-20003",
+		               "OID %08x [%.*s/%.*s] doesn't have "
+		               "priv flag set [parent is %sset].",
+		               le32_to_cpu(INODE_PKEY(dentry->d_inode)->
+		                           k_objectid), xadir->d_name.len,
+		               xadir->d_name.name, namelen, name,
+		               is_reiserfs_priv_object(xadir-> d_inode) ? "" :
+		               "not ");
 		dput(dentry);
 		return -EIO;
 	}
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#13 lore raw

PATCH 12/40 reiserfs: simplify xattr internal file lookups/opens

In reply to [email protected]

The xattr file open/lookup code is needlessly complex. We can use vfs-level operations to perform the same work, and also simplify the locking constraints. The locking advantages will be exploited in future patches.

---
 fs/reiserfs/xattr.c |  200 +++++++++++++++++-----------------------------------
 1 file changed, 66 insertions(+), 134 deletions(-)
fs/reiserfs/xattr.c +66 -134
@@ -46,173 +46,104 @@
 #include <linux/stat.h>
 #include <asm/semaphore.h>
 
-#define FL_READONLY 128
-#define FL_DIR_SEM_HELD 256
 #define PRIVROOT_NAME ".reiserfs_priv"
 #define XAROOT_NAME   "xattrs"
 
 static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
 								*prefix);
 
-/* Returns the dentry referring to the root of the extended attribute
- * directory tree. If it has already been retrieved, it is used. If it
- * hasn't been created and the flags indicate creation is allowed, we
- * attempt to create it. On error, we return a pointer-encoded error.
- */
-static struct dentry *get_xa_root(struct super_block *sb, int flags)
-{
-	struct dentry *privroot = dget(REISERFS_SB(sb)->priv_root);
-	struct dentry *xaroot;
+#define xattr_may_create(flags)	(!flags || flags & XATTR_CREATE)
 
-	/* This needs to be created at mount-time */
-	if (!privroot)
-		return ERR_PTR(-ENODATA);
+static struct dentry *lookup_or_create_dir(struct dentry *parent,
+                                           const char *name, int flags)
+{
+	struct dentry *dentry;
+	BUG_ON(!parent);
 
-	mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR);
-	if (REISERFS_SB(sb)->xattr_root) {
-		xaroot = dget(REISERFS_SB(sb)->xattr_root);
-		goto out;
-	}
+	mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_XATTR);
 
-	xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME));
-	if (IS_ERR(xaroot)) {
-		goto out;
-	} else if (!xaroot->d_inode) {
+	dentry = lookup_one_len(name, parent, strlen(name));
+	if (IS_ERR(dentry)) {
+		mutex_unlock(&parent->d_inode->i_mutex);
+		return dentry;
+	} else if (!dentry->d_inode) {
 		int err = -ENODATA;
-		if (flags == 0 || flags & XATTR_CREATE)
-			err = privroot->d_inode->i_op->mkdir(privroot->d_inode,
-			                                     xaroot, 0700);
+
+		if (xattr_may_create(flags))
+			err = vfs_mkdir(parent->d_inode, dentry, 0700);
+
 		if (err) {
-			dput(xaroot);
-			xaroot = ERR_PTR(err);
-			goto out;
+			dput(dentry);
+			dentry = ERR_PTR(err);
 		}
 	}
-	REISERFS_SB(sb)->xattr_root = dget(xaroot);
 
-      out:
-	mutex_unlock(&privroot->d_inode->i_mutex);
-	dput(privroot);
-	return xaroot;
+	mutex_unlock(&parent->d_inode->i_mutex);
+	return dentry;
+}
+
+static struct dentry *open_xa_root(struct super_block *sb, int flags)
+{
+	struct dentry *privroot = REISERFS_SB(sb)->priv_root;
+	if (!privroot)
+		return ERR_PTR(-ENODATA);
+	return lookup_or_create_dir(privroot, XAROOT_NAME, flags);
 }
 
-/* Opens the directory corresponding to the inode's extended attribute store.
- * If flags allow, the tree to the directory may be created. If creation is
- * prohibited, -ENODATA is returned. */
 static struct dentry *open_xa_dir(const struct inode *inode, int flags)
 {
 	struct dentry *xaroot, *xadir;
 	char namebuf[17];
 
-	xaroot = get_xa_root(inode->i_sb, flags);
+	xaroot = open_xa_root(inode->i_sb, flags);
 	if (IS_ERR(xaroot))
 		return xaroot;
 
-	/* ok, we have xaroot open */
 	snprintf(namebuf, sizeof(namebuf), "%X.%X",
 		 le32_to_cpu(INODE_PKEY(inode)->k_objectid),
 		 inode->i_generation);
-	xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
-	if (IS_ERR(xadir)) {
-		dput(xaroot);
-		return xadir;
-	}
-
-	if (!xadir->d_inode) {
-		int err;
-		if (flags == 0 || flags & XATTR_CREATE) {
-			/* Although there is nothing else trying to create this directory,
-			 * another directory with the same hash may be created, so we need
-			 * to protect against that */
-			err =
-			    xaroot->d_inode->i_op->mkdir(xaroot->d_inode, xadir,
-							 0700);
-			if (err) {
-				dput(xaroot);
-				dput(xadir);
-				return ERR_PTR(err);
-			}
-		}
-		if (!xadir->d_inode) {
-			dput(xaroot);
-			dput(xadir);
-			return ERR_PTR(-ENODATA);
-		}
-	}
 
+	xadir = lookup_or_create_dir(xaroot, namebuf, flags);
 	dput(xaroot);
 	return xadir;
+
 }
 
-/* Returns a dentry corresponding to a specific extended attribute file
- * for the inode. If flags allow, the file is created. Otherwise, a
- * valid or negative dentry, or an error is returned. */
-static struct dentry *get_xa_file_dentry(const struct inode *inode,
-					 const char *name, int flags)
+static struct file *open_xattr_file(const struct inode *inode,
+                                    const char *name, int flags)
 {
 	struct dentry *xadir, *xafile;
 	int err = 0;
 
 	xadir = open_xa_dir(inode, flags);
-	if (IS_ERR(xadir)) {
+	if (IS_ERR(xadir))
 		return ERR_PTR(PTR_ERR(xadir));
-	} else if (xadir && !xadir->d_inode) {
-		dput(xadir);
-		return ERR_PTR(-ENODATA);
-	}
 
+	mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
 	xafile = lookup_one_len(name, xadir, strlen(name));
 	if (IS_ERR(xafile)) {
-		dput(xadir);
-		return ERR_PTR(PTR_ERR(xafile));
+		err = PTR_ERR(xafile);
+		goto out;
 	}
 
-	if (xafile->d_inode) {	/* file exists */
-		if (flags & XATTR_CREATE) {
-			err = -EEXIST;
-			dput(xafile);
-			goto out;
-		}
-	} else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
-		goto out;
-	} else {
-		/* inode->i_mutex is down, so nothing else can try to create
-		 * the same xattr */
-		err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
-						   0700 | S_IFREG, NULL);
+	if (xafile->d_inode && (flags & XATTR_CREATE))
+		err = -EEXIST;
 
-		if (err) {
-			dput(xafile);
-			goto out;
-		}
+	if (!xafile->d_inode) {
+		err = -ENODATA;
+		if (xattr_may_create(flags))
+			err = vfs_create(xadir->d_inode, xafile,
+			                 0700|S_IFREG, NULL);
 	}
 
-      out:
-	dput(xadir);
 	if (err)
-		xafile = ERR_PTR(err);
-	return xafile;
-}
-
-/* Opens a file pointer to the attribute associated with inode */
-static struct file *open_xa_file(const struct inode *inode, const char *name,
-				 int flags)
-{
-	struct dentry *xafile;
-	struct file *fp;
-
-	xafile = get_xa_file_dentry(inode, name, flags);
-	if (IS_ERR(xafile))
-		return ERR_PTR(PTR_ERR(xafile));
-	else if (!xafile->d_inode) {
 		dput(xafile);
-		return ERR_PTR(-ENODATA);
-	}
-
-	fp = dentry_open(xafile, NULL, O_RDWR);
-	/* dentry_open dputs the dentry if it fails */
-
-	return fp;
+out:
+	mutex_unlock(&xadir->d_inode->i_mutex);
+	dput(xadir);
+	if (err)
+		return ERR_PTR(err);
+	return dentry_open(xafile, NULL, O_RDWR);
 }
 
 /*
@@ -455,7 +386,7 @@ reiserfs_xattr_set(struct inode *inode, 
 		xahash = xattr_hash(buffer, buffer_size);
 
       open_file:
-	fp = open_xa_file(inode, name, flags);
+	fp = open_xattr_file(inode, name, flags);
 	if (IS_ERR(fp)) {
 		err = PTR_ERR(fp);
 		goto out;
@@ -573,7 +504,7 @@ reiserfs_xattr_get(const struct inode *i
 	if (get_inode_sd_version(inode) == STAT_DATA_V1)
 		return -EOPNOTSUPP;
 
-	fp = open_xa_file(inode, name, FL_READONLY);
+	fp = open_xattr_file(inode, name, XATTR_REPLACE);
 	if (IS_ERR(fp)) {
 		err = PTR_ERR(fp);
 		goto out;
@@ -586,12 +517,12 @@ reiserfs_xattr_get(const struct inode *i
 	/* Just return the size needed */
 	if (buffer == NULL) {
 		err = isize - sizeof(struct reiserfs_xattr_header);
-		goto out_dput;
+		goto out_fput;
 	}
 
 	if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
 		err = -ERANGE;
-		goto out_dput;
+		goto out_fput;
 	}
 
 	while (file_pos < isize) {
@@ -606,7 +537,7 @@ reiserfs_xattr_get(const struct inode *i
 		page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
 		if (IS_ERR(page)) {
 			err = PTR_ERR(page);
-			goto out_dput;
+			goto out_fput;
 		}
 
 		lock_page(page);
@@ -625,7 +556,7 @@ reiserfs_xattr_get(const struct inode *i
 						 "associated with %k", name,
 						 INODE_PKEY(inode));
 				err = -EIO;
-				goto out_dput;
+				goto out_fput;
 			}
 			hash = le32_to_cpu(rxh->h_hash);
 		}
@@ -644,9 +575,10 @@ reiserfs_xattr_get(const struct inode *i
 				 "Invalid hash for xattr (%s) associated "
 				 "with %k", name, INODE_PKEY(inode));
 		err = -EIO;
+		goto out_fput;
 	}
 
-      out_dput:
+      out_fput:
 	fput(fp);
 
       out:
@@ -686,9 +618,7 @@ __reiserfs_xattr_del(struct dentry *xadi
 		return -EIO;
 	}
 
-	err = dir->i_op->unlink(dir, dentry);
-	if (!err)
-		d_delete(dentry);
+	err = vfs_unlink(xadir->d_inode, dentry);
 
       out_file:
 	dput(dentry);
@@ -702,7 +632,7 @@ int reiserfs_xattr_del(struct inode *ino
 	struct dentry *dir;
 	int err;
 
-	dir = open_xa_dir(inode, FL_READONLY);
+	dir = open_xa_dir(inode, XATTR_REPLACE);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
 		goto out;
@@ -748,7 +678,7 @@ int reiserfs_delete_xattrs(struct inode 
 		return 0;
 	}
 	reiserfs_read_lock_xattrs(inode->i_sb);
-	dir = open_xa_dir(inode, FL_READONLY);
+	dir = open_xa_dir(inode, XATTR_REPLACE);
 	reiserfs_read_unlock_xattrs(inode->i_sb);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
@@ -774,9 +704,11 @@ int reiserfs_delete_xattrs(struct inode 
 
 	/* Leftovers besides . and .. -- that's not good. */
 	if (dir->d_inode->i_nlink <= 2) {
-		root = get_xa_root(inode->i_sb, XATTR_REPLACE);
+		root = open_xa_root(inode->i_sb, XATTR_REPLACE);
 		reiserfs_write_lock_xattrs(inode->i_sb);
+		mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_XATTR);
 		err = vfs_rmdir(root->d_inode, dir);
+		mutex_unlock(&root->d_inode->i_mutex);
 		reiserfs_write_unlock_xattrs(inode->i_sb);
 		dput(root);
 	} else {
@@ -841,7 +773,7 @@ int reiserfs_chown_xattrs(struct inode *
 		return 0;
 	}
 	reiserfs_read_lock_xattrs(inode->i_sb);
-	dir = open_xa_dir(inode, FL_READONLY);
+	dir = open_xa_dir(inode, XATTR_REPLACE);
 	reiserfs_read_unlock_xattrs(inode->i_sb);
 	if (IS_ERR(dir)) {
 		if (PTR_ERR(dir) != -ENODATA)
@@ -1038,7 +970,7 @@ ssize_t reiserfs_listxattr(struct dentry
 
 	reiserfs_read_lock_xattr_i(dentry->d_inode);
 	reiserfs_read_lock_xattrs(dentry->d_sb);
-	dir = open_xa_dir(dentry->d_inode, FL_READONLY);
+	dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE);
 	reiserfs_read_unlock_xattrs(dentry->d_sb);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#14 lore raw

PATCH 13/40 reiserfs: eliminate per-super xattr lock

In reply to [email protected]

With the switch to using inode->i_mutex locking during lookups/creation in the xattr root, the per-super xattr lock is no longer needed.

This patch removes it.

--

 fs/reiserfs/inode.c            |   14 -------
 fs/reiserfs/namei.c            |   29 ----------------
 fs/reiserfs/super.c            |    4 --
 fs/reiserfs/xattr.c            |   34 +++---------------
 fs/reiserfs/xattr_acl.c        |   74 ++++++++++++++++++-----------------------
 include/linux/reiserfs_fs.h    |    3 -
 include/linux/reiserfs_fs_sb.h |    1 
 include/linux/reiserfs_xattr.h |   18 ---------
 8 files changed, 40 insertions(+), 137 deletions(-)
fs/reiserfs/inode.c +1 -13
@@ -1966,19 +1966,7 @@ int reiserfs_new_inode(struct reiserfs_t
       out_inserted_sd:
 	inode->i_nlink = 0;
 	th->t_trans_id = 0;	/* so the caller can't use this handle later */
-
-	/* If we were inheriting an ACL, we need to release the lock so that
-	 * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
-	 * code really needs to be reworked, but this will take care of it
-	 * for now. -jeffm */
-#ifdef CONFIG_REISERFS_FS_POSIX_ACL
-	if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
-		reiserfs_write_unlock_xattrs(dir->i_sb);
-		iput(inode);
-		reiserfs_write_lock_xattrs(dir->i_sb);
-	} else
-#endif
-		iput(inode);
+	iput(inode);
 	return err;
 }
 
fs/reiserfs/namei.c +0 -29
@@ -617,9 +617,6 @@ static int reiserfs_create(struct inode 
 
 	reiserfs_write_lock(dir->i_sb);
 
-	if (locked)
-		reiserfs_write_lock_xattrs(dir->i_sb);
-
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
 	if (retval) {
 		drop_new_inode(inode);
@@ -632,11 +629,6 @@ static int reiserfs_create(struct inode 
 	if (retval)
 		goto out_failed;
 
-	if (locked) {
-		reiserfs_write_unlock_xattrs(dir->i_sb);
-		locked = 0;
-	}
-
 	inode->i_op = &reiserfs_file_inode_operations;
 	inode->i_fop = &reiserfs_file_operations;
 	inode->i_mapping->a_ops = &reiserfs_address_space_operations;
@@ -661,8 +653,6 @@ static int reiserfs_create(struct inode 
 	retval = journal_end(&th, dir->i_sb, jbegin_count);
 
       out_failed:
-	if (locked)
-		reiserfs_write_unlock_xattrs(dir->i_sb);
 	reiserfs_write_unlock(dir->i_sb);
 	return retval;
 }
@@ -692,9 +682,6 @@ static int reiserfs_mknod(struct inode *
 
 	reiserfs_write_lock(dir->i_sb);
 
-	if (locked)
-		reiserfs_write_lock_xattrs(dir->i_sb);
-
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
 	if (retval) {
 		drop_new_inode(inode);
@@ -708,11 +695,6 @@ static int reiserfs_mknod(struct inode *
 		goto out_failed;
 	}
 
-	if (locked) {
-		reiserfs_write_unlock_xattrs(dir->i_sb);
-		locked = 0;
-	}
-
 	inode->i_op = &reiserfs_special_inode_operations;
 	init_special_inode(inode, inode->i_mode, rdev);
 
@@ -740,8 +722,6 @@ static int reiserfs_mknod(struct inode *
 	retval = journal_end(&th, dir->i_sb, jbegin_count);
 
       out_failed:
-	if (locked)
-		reiserfs_write_unlock_xattrs(dir->i_sb);
 	reiserfs_write_unlock(dir->i_sb);
 	return retval;
 }
@@ -771,8 +751,6 @@ static int reiserfs_mkdir(struct inode *
 	locked = reiserfs_cache_default_acl(dir);
 
 	reiserfs_write_lock(dir->i_sb);
-	if (locked)
-		reiserfs_write_lock_xattrs(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
 	if (retval) {
@@ -794,11 +772,6 @@ static int reiserfs_mkdir(struct inode *
 		goto out_failed;
 	}
 
-	if (locked) {
-		reiserfs_write_unlock_xattrs(dir->i_sb);
-		locked = 0;
-	}
-
 	reiserfs_update_inode_transaction(inode);
 	reiserfs_update_inode_transaction(dir);
 
@@ -826,8 +799,6 @@ static int reiserfs_mkdir(struct inode *
 	d_instantiate(dentry, inode);
 	retval = journal_end(&th, dir->i_sb, jbegin_count);
       out_failed:
-	if (locked)
-		reiserfs_write_unlock_xattrs(dir->i_sb);
 	reiserfs_write_unlock(dir->i_sb);
 	return retval;
 }
fs/reiserfs/super.c +0 -4
@@ -1574,10 +1574,6 @@ static int reiserfs_fill_super(struct su
 	REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
 	/* Preallocate by 16 blocks (17-1) at once */
 	REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
-#ifdef CONFIG_REISERFS_FS_XATTR
-	/* Initialize the rwsem for xattr dir */
-	init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
-#endif
 	/* setup default block allocator options */
 	reiserfs_init_alloc_options(s);
 
fs/reiserfs/xattr.c +6 -28
@@ -27,6 +27,12 @@
  * these are special cases for filesystem ACLs, they are interpreted by the
  * kernel, in addition, they are negatively and positively cached and attached
  * to the inode so that unnecessary lookups are avoided.
+ *
+ * Locking works like so:
+ * The xattr root (/.reiserfs_priv/xattrs) is protected by its i_mutex.
+ * The xattr dir (/.reiserfs_priv/xattrs/<oid>.<gen>) is protected by
+ * inode->xattr_sem.
+ * The xattrs themselves are likewise protected by the xattr_sem.
  */
 
 #include <linux/reiserfs_fs.h>
@@ -677,9 +683,7 @@ int reiserfs_delete_xattrs(struct inode 
 	    !reiserfs_xattrs(inode->i_sb)) {
 		return 0;
 	}
-	reiserfs_read_lock_xattrs(inode->i_sb);
 	dir = open_xa_dir(inode, XATTR_REPLACE);
-	reiserfs_read_unlock_xattrs(inode->i_sb);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
 		goto out;
@@ -705,11 +709,9 @@ int reiserfs_delete_xattrs(struct inode 
 	/* Leftovers besides . and .. -- that's not good. */
 	if (dir->d_inode->i_nlink <= 2) {
 		root = open_xa_root(inode->i_sb, XATTR_REPLACE);
-		reiserfs_write_lock_xattrs(inode->i_sb);
 		mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_XATTR);
 		err = vfs_rmdir(root->d_inode, dir);
 		mutex_unlock(&root->d_inode->i_mutex);
-		reiserfs_write_unlock_xattrs(inode->i_sb);
 		dput(root);
 	} else {
 		reiserfs_warning(inode->i_sb, "jdm-20004",
@@ -772,9 +774,7 @@ int reiserfs_chown_xattrs(struct inode *
 	    !reiserfs_xattrs(inode->i_sb)) {
 		return 0;
 	}
-	reiserfs_read_lock_xattrs(inode->i_sb);
 	dir = open_xa_dir(inode, XATTR_REPLACE);
-	reiserfs_read_unlock_xattrs(inode->i_sb);
 	if (IS_ERR(dir)) {
 		if (PTR_ERR(dir) != -ENODATA)
 			err = PTR_ERR(dir);
@@ -819,7 +819,6 @@ int reiserfs_chown_xattrs(struct inode *
 
 /*
  * Inode operation getxattr()
- * Preliminary locking: we down dentry->d_inode->i_mutex
  */
 ssize_t
 reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
@@ -833,9 +832,7 @@ reiserfs_getxattr(struct dentry * dentry
 		return -EOPNOTSUPP;
 
 	reiserfs_read_lock_xattr_i(dentry->d_inode);
-	reiserfs_read_lock_xattrs(dentry->d_sb);
 	err = xah->get(dentry->d_inode, name, buffer, size);
-	reiserfs_read_unlock_xattrs(dentry->d_sb);
 	reiserfs_read_unlock_xattr_i(dentry->d_inode);
 	return err;
 }
@@ -851,23 +848,13 @@ reiserfs_setxattr(struct dentry *dentry,
 {
 	struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
 	int err;
-	int lock;
 
 	if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
 	    get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
 		return -EOPNOTSUPP;
 
 	reiserfs_write_lock_xattr_i(dentry->d_inode);
-	lock = !has_xattr_dir(dentry->d_inode);
-	if (lock)
-		reiserfs_write_lock_xattrs(dentry->d_sb);
-	else
-		reiserfs_read_lock_xattrs(dentry->d_sb);
 	err = xah->set(dentry->d_inode, name, value, size, flags);
-	if (lock)
-		reiserfs_write_unlock_xattrs(dentry->d_sb);
-	else
-		reiserfs_read_unlock_xattrs(dentry->d_sb);
 	reiserfs_write_unlock_xattr_i(dentry->d_inode);
 	return err;
 }
@@ -887,8 +874,6 @@ int reiserfs_removexattr(struct dentry *
 		return -EOPNOTSUPP;
 
 	reiserfs_write_lock_xattr_i(dentry->d_inode);
-	reiserfs_read_lock_xattrs(dentry->d_sb);
-
 	/* Deletion pre-operation */
 	if (xah->del) {
 		err = xah->del(dentry->d_inode, name);
@@ -902,7 +887,6 @@ int reiserfs_removexattr(struct dentry *
 	mark_inode_dirty(dentry->d_inode);
 
       out:
-	reiserfs_read_unlock_xattrs(dentry->d_sb);
 	reiserfs_write_unlock_xattr_i(dentry->d_inode);
 	return err;
 }
@@ -951,8 +935,6 @@ reiserfs_listxattr_filler(void *buf, con
 
 /*
  * Inode operation listxattr()
- *
- * Preliminary locking: we down dentry->d_inode->i_mutex
  */
 ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
 {
@@ -969,9 +951,7 @@ ssize_t reiserfs_listxattr(struct dentry
 		return -EOPNOTSUPP;
 
 	reiserfs_read_lock_xattr_i(dentry->d_inode);
-	reiserfs_read_lock_xattrs(dentry->d_sb);
 	dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE);
-	reiserfs_read_unlock_xattrs(dentry->d_sb);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
 		if (err == -ENODATA)
@@ -1211,11 +1191,9 @@ static int reiserfs_check_acl(struct ino
 	int error = -EAGAIN; /* do regular unix permission checks by default */
 
 	reiserfs_read_lock_xattr_i(inode);
-	reiserfs_read_lock_xattrs(inode->i_sb);
 
 	acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
 
-	reiserfs_read_unlock_xattrs(inode->i_sb);
 	reiserfs_read_unlock_xattr_i(inode);
 
 	if (acl) {
fs/reiserfs/xattr_acl.c +33 -41

136 lines not on this page · raw message

include/linux/reiserfs_fs.h +0 -3
@@ -2209,7 +2209,4 @@ long reiserfs_compat_ioctl(struct file *
 #define reiserfs_write_lock( sb ) lock_kernel()
 #define reiserfs_write_unlock( sb ) unlock_kernel()
 
-/* xattr stuff */
-#define REISERFS_XATTR_DIR_SEM(s) (REISERFS_SB(s)->xattr_dir_sem)
-
 #endif				/* _LINUX_REISER_FS_H */
include/linux/reiserfs_fs_sb.h +0 -1
@@ -403,7 +403,6 @@ struct reiserfs_sb_info {
 	struct dentry *priv_root;	/* root of /.reiserfs_priv */
 #ifdef CONFIG_REISERFS_FS_XATTR
 	struct dentry *xattr_root;	/* root of /.reiserfs_priv/.xa */
-	struct rw_semaphore xattr_dir_sem;
 #endif
 	int j_errno;
 #ifdef CONFIG_QUOTA
include/linux/reiserfs_xattr.h +0 -18
@@ -68,24 +68,6 @@ extern struct reiserfs_xattr_handler sec
 int reiserfs_xattr_register_handlers(void) __init;
 void reiserfs_xattr_unregister_handlers(void);
 
-static inline void reiserfs_write_lock_xattrs(struct super_block *sb)
-{
-	down_write(&REISERFS_XATTR_DIR_SEM(sb));
-}
-static inline void reiserfs_write_unlock_xattrs(struct super_block *sb)
-{
-	up_write(&REISERFS_XATTR_DIR_SEM(sb));
-}
-static inline void reiserfs_read_lock_xattrs(struct super_block *sb)
-{
-	down_read(&REISERFS_XATTR_DIR_SEM(sb));
-}
-
-static inline void reiserfs_read_unlock_xattrs(struct super_block *sb)
-{
-	up_read(&REISERFS_XATTR_DIR_SEM(sb));
-}
-
 static inline void reiserfs_write_lock_xattr_i(struct inode *inode)
 {
 	down_write(&REISERFS_I(inode)->xattr_sem);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#15 lore raw

PATCH 14/40 reiserfs: make per-inode xattr locking more fine grained

In reply to [email protected]

The per-inode locking can be made more fine-grained to surround just the interaction with the filesystem itself. This really only applies to protecting reads during a write, since concurrent writes are barred with inode->i_mutex at the vfs level.

--

 fs/reiserfs/inode.c            |    2 -
 fs/reiserfs/xattr.c            |   62 +++++++++++++++++------------------------
 fs/reiserfs/xattr_acl.c        |    7 ----
 include/linux/reiserfs_fs_i.h  |    3 -
 include/linux/reiserfs_xattr.h |   26 -----------------
 5 files changed, 28 insertions(+), 72 deletions(-)
fs/reiserfs/inode.c +0 -2
@@ -1128,7 +1128,6 @@ static void init_inode(struct inode *ino
 	mutex_init(&(REISERFS_I(inode)->i_mmap));
 	reiserfs_init_acl_access(inode);
 	reiserfs_init_acl_default(inode);
-	reiserfs_init_xattr_rwsem(inode);
 
 	if (stat_data_v1(ih)) {
 		struct stat_data_v1 *sd =
@@ -1832,7 +1831,6 @@ int reiserfs_new_inode(struct reiserfs_t
 	mutex_init(&(REISERFS_I(inode)->i_mmap));
 	reiserfs_init_acl_access(inode);
 	reiserfs_init_acl_default(inode);
-	reiserfs_init_xattr_rwsem(inode);
 
 	if (old_format_only(sb))
 		make_le_item_head(&ih, NULL, KEY_FORMAT_3_5, SD_OFFSET,
fs/reiserfs/xattr.c +27 -35

202 lines not on this page · raw message

fs/reiserfs/xattr_acl.c +1 -6
@@ -418,9 +418,7 @@ int reiserfs_cache_default_acl(struct in
 	int ret = 0;
 	if (reiserfs_posixacl(inode->i_sb) && !is_reiserfs_priv_object(inode)) {
 		struct posix_acl *acl;
-		reiserfs_read_lock_xattr_i(inode);
 		acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
-		reiserfs_read_unlock_xattr_i(inode);
 		ret = (acl && !IS_ERR(acl));
 		if (ret)
 			posix_acl_release(acl);
@@ -452,11 +450,8 @@ int reiserfs_acl_chmod(struct inode *ino
 	if (!clone)
 		return -ENOMEM;
 	error = posix_acl_chmod_masq(clone, inode->i_mode);
-	if (!error) {
-		reiserfs_write_lock_xattr_i(inode);
+	if (!error)
 		error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone);
-		reiserfs_write_unlock_xattr_i(inode);
-	}
 	posix_acl_release(clone);
 	return error;
 }
include/linux/reiserfs_fs_i.h +0 -3
@@ -58,9 +58,6 @@ struct reiserfs_inode_info {
 	struct posix_acl *i_acl_access;
 	struct posix_acl *i_acl_default;
 #endif
-#ifdef CONFIG_REISERFS_FS_XATTR
-	struct rw_semaphore xattr_sem;
-#endif
 	struct inode vfs_inode;
 };
 
include/linux/reiserfs_xattr.h +0 -26
@@ -68,34 +68,12 @@ extern struct reiserfs_xattr_handler sec
 int reiserfs_xattr_register_handlers(void) __init;
 void reiserfs_xattr_unregister_handlers(void);
 
-static inline void reiserfs_write_lock_xattr_i(struct inode *inode)
-{
-	down_write(&REISERFS_I(inode)->xattr_sem);
-}
-static inline void reiserfs_write_unlock_xattr_i(struct inode *inode)
-{
-	up_write(&REISERFS_I(inode)->xattr_sem);
-}
-static inline void reiserfs_read_lock_xattr_i(struct inode *inode)
-{
-	down_read(&REISERFS_I(inode)->xattr_sem);
-}
-
-static inline void reiserfs_read_unlock_xattr_i(struct inode *inode)
-{
-	up_read(&REISERFS_I(inode)->xattr_sem);
-}
 
 static inline void reiserfs_mark_inode_private(struct inode *inode)
 {
 	inode->i_flags |= S_PRIVATE;
 }
 
-static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
-{
-	init_rwsem(&REISERFS_I(inode)->xattr_sem);
-}
-
 #else
 
 #define is_reiserfs_priv_object(inode) 0
@@ -104,10 +82,6 @@ static inline void reiserfs_init_xattr_r
 #define reiserfs_setxattr NULL
 #define reiserfs_listxattr NULL
 #define reiserfs_removexattr NULL
-#define reiserfs_write_lock_xattrs(sb) do {;} while(0)
-#define reiserfs_write_unlock_xattrs(sb) do {;} while(0)
-#define reiserfs_read_lock_xattrs(sb)
-#define reiserfs_read_unlock_xattrs(sb)
 
 #define reiserfs_permission NULL
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#16 lore raw

PATCH 15/40 reiserfs: remove i_has_xattr_dir

In reply to [email protected]

With the changes to xattr root locking, the i_has_xattr_dir flag is no longer needed. This patch removes it.

---
 fs/reiserfs/xattr.c |    7 -------
 1 file changed, 7 deletions(-)
fs/reiserfs/xattr.c +0 -7
@@ -393,7 +393,6 @@ reiserfs_xattr_set(struct inode *inode, 
 
 	xahash = xattr_hash(buffer, buffer_size);
 	xinode = fp->f_path.dentry->d_inode;
-	REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
 
 	/* we need to copy it off.. */
 	if (xinode->i_nlink > 1) {
@@ -512,7 +511,6 @@ reiserfs_xattr_get(const struct inode *i
 
 	xinode = fp->f_path.dentry->d_inode;
 	isize = xinode->i_size;
-	REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
 
 	/* Just return the size needed */
 	if (buffer == NULL) {
@@ -732,9 +730,6 @@ int reiserfs_delete_xattrs(struct inode 
 	fput(fp);
 
       out:
-	if (!err)
-		REISERFS_I(inode)->i_flags =
-		    REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
 	return err;
 }
 
@@ -968,8 +963,6 @@ ssize_t reiserfs_listxattr(struct dentry
 	buf.r_pos = 0;
 	buf.r_inode = dentry->d_inode;
 
-	REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
-
 	err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf);
 	if (err)
 		goto out_dir;
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#17 lore raw

PATCH 16/40 reiserfs: remove link detection code

In reply to [email protected]

Early in the reiserfs xattr development, there was a plan to use hardlinks to save disk space for identical xattrs. That code never materialized and isn't going to, so this patch removes the detection code.

---
 fs/reiserfs/xattr.c |   13 -------------
 1 file changed, 13 deletions(-)
fs/reiserfs/xattr.c +0 -13
@@ -384,7 +384,6 @@ reiserfs_xattr_set(struct inode *inode, 
 	if (!buffer)
 		return reiserfs_xattr_del(inode, name);
 
-      open_file:
 	fp = open_xattr_file(inode, name, flags);
 	if (IS_ERR(fp)) {
 		err = PTR_ERR(fp);
@@ -394,18 +393,6 @@ reiserfs_xattr_set(struct inode *inode, 
 	xahash = xattr_hash(buffer, buffer_size);
 	xinode = fp->f_path.dentry->d_inode;
 
-	/* we need to copy it off.. */
-	if (xinode->i_nlink > 1) {
-		fput(fp);
-		err = reiserfs_xattr_del(inode, name);
-		if (err < 0)
-			goto out;
-		/* We just killed the old one, we're not replacing anymore */
-		if (flags & XATTR_REPLACE)
-			flags &= ~XATTR_REPLACE;
-		goto open_file;
-	}
-
 	/* Resize it so we're ok to write there */
 	newattrs.ia_size = buffer_size;
 	newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#18 lore raw

PATCH 17/40 reiserfs: use generic xattr handlers

In reply to [email protected]

Christoph Hellwig had asked me quite some time ago to port the reiserfs xattrs to the generic xattr interface.

This patch replaces the reiserfs-specific xattr handling code with the generic struct xattr_handler.

However, since reiserfs doesn't split the prefix and name when accessing xattrs, it can't leverage generic_{set,get,list,remove}xattr without needlessly reconstructing the name on the back end.

---
 fs/reiserfs/super.c            |    7 
 fs/reiserfs/xattr.c            |  399 +++++++++++++++--------------------------
 fs/reiserfs/xattr_acl.c        |   72 ++-----
 fs/reiserfs/xattr_security.c   |   26 --
 fs/reiserfs/xattr_trusted.c    |   45 +---
 fs/reiserfs/xattr_user.c       |   30 ---
 include/linux/reiserfs_acl.h   |   16 -
 include/linux/reiserfs_fs_sb.h |    3 
 include/linux/reiserfs_xattr.h |   29 --
 9 files changed, 206 insertions(+), 421 deletions(-)
fs/reiserfs/super.c +0 -7
@@ -2132,9 +2132,6 @@ static int __init init_reiserfs_fs(void)
 		return ret;
 	}
 
-	if ((ret = reiserfs_xattr_register_handlers()))
-		goto failed_reiserfs_xattr_register_handlers;
-
 	reiserfs_proc_info_global_init();
 	reiserfs_proc_register_global("version",
 				      reiserfs_global_version_in_proc);
@@ -2145,9 +2142,6 @@ static int __init init_reiserfs_fs(void)
 		return 0;
 	}
 
-	reiserfs_xattr_unregister_handlers();
-
-      failed_reiserfs_xattr_register_handlers:
 	reiserfs_proc_unregister_global("version");
 	reiserfs_proc_info_global_done();
 	destroy_inodecache();
@@ -2157,7 +2151,6 @@ static int __init init_reiserfs_fs(void)
 
 static void __exit exit_reiserfs_fs(void)
 {
-	reiserfs_xattr_unregister_handlers();
 	reiserfs_proc_unregister_global("version");
 	reiserfs_proc_info_global_done();
 	unregister_filesystem(&reiserfs_fs_type);
fs/reiserfs/xattr.c +150 -249

548 lines not on this page · raw message

fs/reiserfs/xattr_acl.c +22 -50

119 lines not on this page · raw message

fs/reiserfs/xattr_security.c +8 -18
@@ -33,35 +33,25 @@ security_set(struct inode *inode, const 
 	return reiserfs_xattr_set(inode, name, buffer, size, flags);
 }
 
-static int security_del(struct inode *inode, const char *name)
+static size_t security_list(struct inode *inode, char *list, size_t list_len,
+			    const char *name, size_t namelen)
 {
-	if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
-		return -EINVAL;
-
-	if (is_reiserfs_priv_object(inode))
-		return -EPERM;
-
-	return 0;
-}
-
-static int
-security_list(struct inode *inode, const char *name, int namelen, char *out)
-{
-	int len = namelen;
+	const size_t len = namelen + 1;
 
 	if (is_reiserfs_priv_object(inode))
 		return 0;
 
-	if (out)
-		memcpy(out, name, len);
+	if (list && len <= list_len) {
+		memcpy(list, name, namelen);
+		list[namelen] = '\0';
+	}
 
 	return len;
 }
 
-struct reiserfs_xattr_handler security_handler = {
+struct xattr_handler reiserfs_xattr_security_handler = {
 	.prefix = XATTR_SECURITY_PREFIX,
 	.get = security_get,
 	.set = security_set,
-	.del = security_del,
 	.list = security_list,
 };
fs/reiserfs/xattr_trusted.c +11 -34

71 lines not on this page · raw message

fs/reiserfs/xattr_user.c +8 -22
@@ -6,10 +6,6 @@
 #include <linux/reiserfs_xattr.h>
 #include <asm/uaccess.h>
 
-#ifdef CONFIG_REISERFS_FS_POSIX_ACL
-# include <linux/reiserfs_acl.h>
-#endif
-
 #define XATTR_USER_PREFIX "user."
 
 static int
@@ -36,33 +32,23 @@ user_set(struct inode *inode, const char
 	return reiserfs_xattr_set(inode, name, buffer, size, flags);
 }
 
-static int user_del(struct inode *inode, const char *name)
+static size_t user_list(struct inode *inode, char *list, size_t list_size,
+                        const char *name, size_t name_len)
 {
-	if (strlen(name) < sizeof(XATTR_USER_PREFIX))
-		return -EINVAL;
+	const size_t len = name_len + 1;
 
 	if (!reiserfs_xattrs_user(inode->i_sb))
-		return -EOPNOTSUPP;
-	return 0;
-}
-
-static int
-user_list(struct inode *inode, const char *name, int namelen, char *out)
-{
-	int len = namelen;
-	if (!reiserfs_xattrs_user(inode->i_sb))
 		return 0;
-
-	if (out)
-		memcpy(out, name, len);
-
+	if (list && len <= list_size) {
+		memcpy(list, name, name_len);
+		list[name_len] = '\0';
+	}
 	return len;
 }
 
-struct reiserfs_xattr_handler user_handler = {
+struct xattr_handler reiserfs_xattr_user_handler = {
 	.prefix = XATTR_USER_PREFIX,
 	.get = user_get,
 	.set = user_set,
-	.del = user_del,
 	.list = user_list,
 };
include/linux/reiserfs_acl.h +2 -14
@@ -52,10 +52,8 @@ int reiserfs_acl_chmod(struct inode *ino
 int reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
 				 struct inode *inode);
 int reiserfs_cache_default_acl(struct inode *dir);
-extern int reiserfs_xattr_posix_acl_init(void) __init;
-extern int reiserfs_xattr_posix_acl_exit(void);
-extern struct reiserfs_xattr_handler posix_acl_default_handler;
-extern struct reiserfs_xattr_handler posix_acl_access_handler;
+extern struct xattr_handler reiserfs_posix_acl_default_handler;
+extern struct xattr_handler reiserfs_posix_acl_access_handler;
 
 static inline void reiserfs_init_acl_access(struct inode *inode)
 {
@@ -75,16 +73,6 @@ static inline struct posix_acl *reiserfs
 	return NULL;
 }
 
-static inline int reiserfs_xattr_posix_acl_init(void)
-{
-	return 0;
-}
-
-static inline int reiserfs_xattr_posix_acl_exit(void)
-{
-	return 0;
-}
-
 static inline int reiserfs_acl_chmod(struct inode *inode)
 {
 	return 0;
include/linux/reiserfs_fs_sb.h +1 -2
@@ -452,7 +452,6 @@ enum reiserfs_mount_options {
 	REISERFS_NO_UNHASHED_RELOCATION,
 	REISERFS_HASHED_RELOCATION,
 	REISERFS_ATTRS,
-	REISERFS_XATTRS,
 	REISERFS_XATTRS_USER,
 	REISERFS_POSIXACL,
 	REISERFS_BARRIER_NONE,
@@ -490,7 +489,7 @@ enum reiserfs_mount_options {
 #define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG))
 #define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED))
 #define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK))
-#define reiserfs_xattrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS))
+#define reiserfs_xattrs(s) ((s)->s_xattr != NULL)
 #define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER))
 #define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL))
 #define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s))
include/linux/reiserfs_xattr.h +4 -25
@@ -29,20 +29,6 @@ struct iattr;
 struct super_block;
 struct nameidata;
 
-struct reiserfs_xattr_handler {
-	char *prefix;
-	int (*init) (void);
-	void (*exit) (void);
-	int (*get) (struct inode * inode, const char *name, void *buffer,
-		    size_t size);
-	int (*set) (struct inode * inode, const char *name, const void *buffer,
-		    size_t size, int flags);
-	int (*del) (struct inode * inode, const char *name);
-	int (*list) (struct inode * inode, const char *name, int namelen,
-		     char *out);
-	struct list_head handlers;
-};
-
 #ifdef CONFIG_REISERFS_FS_XATTR
 #define is_reiserfs_priv_object(inode) IS_PRIVATE(inode)
 #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
@@ -57,16 +43,12 @@ int reiserfs_chown_xattrs(struct inode *
 int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
 int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd);
 
-int reiserfs_xattr_del(struct inode *, const char *);
-int reiserfs_xattr_get(const struct inode *, const char *, void *, size_t);
+int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
 int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
 
-extern struct reiserfs_xattr_handler user_handler;
-extern struct reiserfs_xattr_handler trusted_handler;
-extern struct reiserfs_xattr_handler security_handler;
-
-int reiserfs_xattr_register_handlers(void) __init;
-void reiserfs_xattr_unregister_handlers(void);
+extern struct xattr_handler reiserfs_xattr_user_handler;
+extern struct xattr_handler reiserfs_xattr_trusted_handler;
+extern struct xattr_handler reiserfs_xattr_security_handler;
 
 
 static inline void reiserfs_mark_inode_private(struct inode *inode)
@@ -85,9 +67,6 @@ static inline void reiserfs_mark_inode_p
 
 #define reiserfs_permission NULL
 
-#define reiserfs_xattr_register_handlers() 0
-#define reiserfs_xattr_unregister_handlers()
-
 static inline int reiserfs_delete_xattrs(struct inode *inode)
 {
 	return 0;
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#19 lore raw

PATCH 18/40 reiserfs: use better open options for internal files

In reply to [email protected]

The generic read path will mark the file's atime during the course of the read. For xattr backing files, this behavior is undesirable, so we open the xattr files and directories with O_NOATIME. We also add the O_DIRECTORY flag where the xattr dir is opened for readdir.

--

 fs/reiserfs/xattr.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/reiserfs/xattr.c +3 -3
@@ -188,7 +188,7 @@ out:
 	dput(xadir);
 	if (err)
 		return ERR_PTR(err);
-	return dentry_open(xafile, NULL, O_RDWR);
+	return dentry_open(xafile, NULL, O_RDWR|O_NOATIME);
 }
 
 /*
@@ -691,7 +691,7 @@ int reiserfs_delete_xattrs(struct inode 
 		goto out;
 	}
 
-	fp = dentry_open(dir, NULL, O_RDWR);
+	fp = dentry_open(dir, NULL, O_RDWR|O_NOATIME|O_DIRECTORY);
 	if (IS_ERR(fp)) {
 		err = PTR_ERR(fp);
 		/* dentry_open dputs the dentry if it fails */
@@ -780,7 +780,7 @@ int reiserfs_chown_xattrs(struct inode *
 		goto out;
 	}
 
-	fp = dentry_open(dir, NULL, O_RDWR);
+	fp = dentry_open(dir, NULL, O_RDWR|O_NOATIME|O_DIRECTORY);
 	if (IS_ERR(fp)) {
 		err = PTR_ERR(fp);
 		/* dentry_open dputs the dentry if it fails */
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#20 lore raw

PATCH 19/40 reiserfs: add per-file data=ordered mode and use it for xattrs

In reply to [email protected]

This patch allows a per-file data=ordered mode similar to the per-file data=journal mode implemented now. This functionality isn't yet exported, but the main use of this code is to allow xattrs to be ordered even if the the file system is mounted with data=writeback.

--

 fs/reiserfs/file.c            |    2 +-
 fs/reiserfs/inode.c           |    2 +-
 fs/reiserfs/xattr.c           |    5 +++++
 include/linux/reiserfs_fs.h   |    8 ++++++++
 include/linux/reiserfs_fs_i.h |    3 ++-
 5 files changed, 17 insertions(+), 3 deletions(-)
fs/reiserfs/file.c +1 -1
@@ -804,7 +804,7 @@ int reiserfs_commit_page(struct inode *i
 				/* do data=ordered on any page past the end
 				 * of file and any buffer marked BH_New.
 				 */
-				if (reiserfs_data_ordered(inode->i_sb) &&
+				if (reiserfs_file_data_ordered(inode) &&
 				    (new || page->index >= i_size_index)) {
 					reiserfs_add_ordered_list(inode, bh);
 				}
fs/reiserfs/inode.c +1 -1
@@ -734,7 +734,7 @@ int reiserfs_get_block(struct inode *ino
 			}
 			set_buffer_new(bh_result);
 			if (buffer_dirty(bh_result)
-			    && reiserfs_data_ordered(inode->i_sb))
+			    && reiserfs_file_data_ordered(inode))
 				reiserfs_add_ordered_list(inode, bh_result);
 			put_block_num(item, pos_in_item, allocated_block_nr);
 			unfm_ptr = allocated_block_nr;
fs/reiserfs/xattr.c +5 -0
@@ -462,6 +462,11 @@ reiserfs_xattr_set(struct inode *inode, 
 		goto out_filp;
 
 	mapping = xinode->i_mapping;
+
+	/* If we're in writeback mode, we still need to order xattr writes */
+	if (reiserfs_data_writeback(xinode->i_sb))
+		REISERFS_I(xinode)->i_flags |= i_data_ordered;
+
 	while (buffer_pos < buffer_size || buffer_pos == 0) {
 		size_t chunk;
 		size_t skip = 0;
include/linux/reiserfs_fs.h +8 -0
@@ -1699,6 +1699,14 @@ static inline int reiserfs_file_data_log
 	return 0;
 }
 
+static inline int reiserfs_file_data_ordered(struct inode *inode)
+{
+	if (reiserfs_data_ordered(inode->i_sb) ||
+	    (REISERFS_I(inode)->i_flags & i_data_ordered))
+		return 1;
+	return 0;
+}
+
 static inline int reiserfs_transaction_running(struct super_block *s)
 {
 	struct reiserfs_transaction_handle *th = current->journal_info;
include/linux/reiserfs_fs_i.h +2 -1
@@ -25,7 +25,8 @@ typedef enum {
 	i_link_saved_truncate_mask = 0x0020,
 	i_has_xattr_dir = 0x0040,
 	i_data_log = 0x0080,
-	i_ever_mapped = 0x0100
+	i_ever_mapped = 0x0100,
+	i_data_ordered = 0x0200,
 } reiserfs_inode_flags;
 
 struct reiserfs_inode_info {
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#21 lore raw

PATCH 20/40 reiserfs: journaled xattrs

In reply to [email protected]

Deadlocks are possible in the xattr code between the journal lock and the xattr sems.

This patch implements journalling for xattr operations. The benefit is twofold:
* It gets rid of the deadlock possibility by always ensuring that xattr write operations are initiated inside a transaction.
* It corrects the problem where xattr backing files aren't considered any differently than normal files, despite the fact they are metadata.

I discussed the added journal load with Chris Mason, and we decided that since xattrs (versus other journal activity) is fairly rare, the introduction of larger transactions to support journaled xattrs wouldn't be too big a deal.

--

 fs/reiserfs/inode.c            |    3 -
 fs/reiserfs/namei.c            |   14 +----
 fs/reiserfs/xattr.c            |   52 +++++++++++++++++++-
 fs/reiserfs/xattr_acl.c        |  104 +++++++++++++++++++++++++++++++----------
 include/linux/reiserfs_acl.h   |    3 -
 include/linux/reiserfs_fs.h    |    4 +
 include/linux/reiserfs_xattr.h |   28 +++++++++++
 7 files changed, 168 insertions(+), 40 deletions(-)
fs/reiserfs/inode.c +1 -2
@@ -1920,9 +1920,8 @@ int reiserfs_new_inode(struct reiserfs_t
 		goto out_inserted_sd;
 	}
 
-	/* XXX CHECK THIS */
 	if (reiserfs_posixacl(inode->i_sb)) {
-		retval = reiserfs_inherit_default_acl(dir, dentry, inode);
+		retval = reiserfs_inherit_default_acl(th, dir, dentry, inode);
 		if (retval) {
 			err = retval;
 			reiserfs_check_path(&path_to_key);
fs/reiserfs/namei.c +3 -11
@@ -606,15 +606,13 @@ static int reiserfs_create(struct inode 
 	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
 		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
 	struct reiserfs_transaction_handle th;
-	int locked;
 
 	if (!(inode = new_inode(dir->i_sb))) {
 		return -ENOMEM;
 	}
 	new_inode_init(inode, dir, mode);
 
-	locked = reiserfs_cache_default_acl(dir);
-
+	jbegin_count += reiserfs_cache_default_acl(dir);
 	reiserfs_write_lock(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
@@ -668,7 +666,6 @@ static int reiserfs_mknod(struct inode *
 	    JOURNAL_PER_BALANCE_CNT * 3 +
 	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
 		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
-	int locked;
 
 	if (!new_valid_dev(rdev))
 		return -EINVAL;
@@ -678,8 +675,7 @@ static int reiserfs_mknod(struct inode *
 	}
 	new_inode_init(inode, dir, mode);
 
-	locked = reiserfs_cache_default_acl(dir);
-
+	jbegin_count += reiserfs_cache_default_acl(dir);
 	reiserfs_write_lock(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
@@ -736,7 +732,6 @@ static int reiserfs_mkdir(struct inode *
 	    JOURNAL_PER_BALANCE_CNT * 3 +
 	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
 		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
-	int locked;
 
 #ifdef DISPLACE_NEW_PACKING_LOCALITIES
 	/* set flag that new packing locality created and new blocks for the content     * of that directory are not displaced yet */
@@ -748,8 +743,7 @@ static int reiserfs_mkdir(struct inode *
 	}
 	new_inode_init(inode, dir, mode);
 
-	locked = reiserfs_cache_default_acl(dir);
-
+	jbegin_count += reiserfs_cache_default_acl(dir);
 	reiserfs_write_lock(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
@@ -1036,8 +1030,6 @@ static int reiserfs_symlink(struct inode
 	memcpy(name, symname, strlen(symname));
 	padd_item(name, item_len, strlen(symname));
 
-	/* We would inherit the default ACL here, but symlinks don't get ACLs */
-
 	retval = journal_begin(&th, parent_dir->i_sb, jbegin_count);
 	if (retval) {
 		drop_new_inode(inode);
fs/reiserfs/xattr.c +50 -2

75 lines not on this page · raw message

fs/reiserfs/xattr_acl.c +80 -24

168 lines not on this page · raw message

include/linux/reiserfs_acl.h +2 -1
@@ -49,7 +49,8 @@ static inline int reiserfs_acl_count(siz
 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
 struct posix_acl *reiserfs_get_acl(struct inode *inode, int type);
 int reiserfs_acl_chmod(struct inode *inode);
-int reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
+int reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
+                                 struct inode *dir, struct dentry *dentry,
 				 struct inode *inode);
 int reiserfs_cache_default_acl(struct inode *dir);
 extern struct xattr_handler reiserfs_posix_acl_default_handler;
include/linux/reiserfs_fs.h +4 -0
@@ -1595,6 +1595,10 @@ struct reiserfs_journal_header {
 #define JOURNAL_MAX_COMMIT_AGE 30
 #define JOURNAL_MAX_TRANS_AGE 30
 #define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)
+#define JOURNAL_BLOCKS_PER_OBJECT(sb)  (JOURNAL_PER_BALANCE_CNT * 3 + \
+                                        2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \
+                                             REISERFS_QUOTA_TRANS_BLOCKS(sb)))
+
 #ifdef CONFIG_QUOTA
 /* We need to update data and inode (atime) */
 #define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & (1<<REISERFS_QUOTA) ? 2 : 0)
include/linux/reiserfs_xattr.h +28 -0
@@ -45,6 +45,7 @@ int reiserfs_permission(struct inode *in
 
 int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
 int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
+int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,struct inode *, const char *, const void *, size_t, int);
 
 extern struct xattr_handler reiserfs_xattr_user_handler;
 extern struct xattr_handler reiserfs_xattr_trusted_handler;
@@ -56,6 +57,33 @@ static inline void reiserfs_mark_inode_p
 	inode->i_flags |= S_PRIVATE;
 }
 
+#define xattr_size(size) ((size) + sizeof (struct reiserfs_xattr_header))
+#define reiserfs_xattr_nblocks(inode, size) (reiserfs_file_data_log(inode) && _ROUND_UP(xattr_size(size), (inode)->i_sb->s_blocksize) >> (inode)->i_sb->s_blocksize_bits)
+
+/* We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
+ * Let's try to be smart about it.
+ * xattr root: We cache it. If it's not cached, we may need to create it.
+ * xattr dir: If anything has been loaded for this inode, we can set a flag
+ *            saying so.
+ * xattr file: Since we don't cache xattrs, we can't tell. We always include
+ *             blocks for it.
+ *
+ * However, since root and dir can be created between calls - YOU MUST SAVE
+ * THIS VALUE.
+ */
+static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
+{
+	size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
+
+	if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
+		nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
+		if (REISERFS_SB(inode->i_sb)->xattr_root == NULL)
+			nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
+	}
+
+	return nblocks;
+}
+
 #else
 
 #define is_reiserfs_priv_object(inode) 0
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#22 lore raw

PATCH 21/40 reiserfs: use generic readdir for operations across all xattrs

In reply to [email protected]

The current reiserfs xattr implementation open codes reiserfs_readdir and frees the path before calling the filldir function. Typically, the filldir function is something that modifies the file system, such as a chown or an inode deletion that also require reading of an inode associated with each direntry. Since the file system is modified, the path retained becomes invalid for the next run. In addition, it runs backwards in attempt to minimize activity.

This is clearly suboptimal from a code cleanliness perspective as well as performance-wise.

This patch implements a generic reiserfs_for_each_xattr that uses the generic readdir and a specific filldir routine that simply populates an array of dentries and then performs a specific operation on them. When all files have been operated on, it then calls the operation on the directory itself.

The result is a noticable code reduction and better performance.

--

 fs/reiserfs/xattr.c |  439 +++++++++++++++-------------------------------------
 1 file changed, 129 insertions(+), 310 deletions(-)
fs/reiserfs/xattr.c +129 -310
@@ -191,182 +191,6 @@ out:
 	return dentry_open(xafile, NULL, O_RDWR|O_NOATIME);
 }
 
-/*
- * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but
- * we need to drop the path before calling the filldir struct.  That
- * would be a big performance hit to the non-xattr case, so I've copied
- * the whole thing for now. --clm
- *
- * the big difference is that I go backwards through the directory,
- * and don't mess with f->f_pos, but the idea is the same.  Do some
- * action on each and every entry in the directory.
- *
- * we're called with i_mutex held, so there are no worries about the directory
- * changing underneath us.
- */
-static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
-{
-	struct inode *inode = filp->f_path.dentry->d_inode;
-	struct cpu_key pos_key;	/* key of current position in the directory (key of directory entry) */
-	INITIALIZE_PATH(path_to_entry);
-	struct buffer_head *bh;
-	int entry_num;
-	struct item_head *ih, tmp_ih;
-	int search_res;
-	char *local_buf;
-	loff_t next_pos;
-	char small_buf[32];	/* avoid kmalloc if we can */
-	struct reiserfs_de_head *deh;
-	int d_reclen;
-	char *d_name;
-	off_t d_off;
-	ino_t d_ino;
-	struct reiserfs_dir_entry de;
-
-	/* form key for search the next directory entry using f_pos field of
-	   file structure */
-	next_pos = max_reiserfs_offset(inode);
-
-	while (1) {
-	      research:
-		if (next_pos <= DOT_DOT_OFFSET)
-			break;
-		make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
-
-		search_res =
-		    search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
-					&de);
-		if (search_res == IO_ERROR) {
-			// FIXME: we could just skip part of directory which could
-			// not be read
-			pathrelse(&path_to_entry);
-			return -EIO;
-		}
-
-		if (search_res == NAME_NOT_FOUND)
-			de.de_entry_num--;
-
-		set_de_name_and_namelen(&de);
-		entry_num = de.de_entry_num;
-		deh = &(de.de_deh[entry_num]);
-
-		bh = de.de_bh;
-		ih = de.de_ih;
-
-		if (!is_direntry_le_ih(ih)) {
-			reiserfs_error(inode->i_sb, "jdm-20000",
-			               "not direntry %h", ih);
-			break;
-		}
-		copy_item_head(&tmp_ih, ih);
-
-		/* we must have found item, that is item of this directory, */
-		RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
-		       "vs-9000: found item %h does not match to dir we readdir %K",
-		       ih, &pos_key);
-
-		if (deh_offset(deh) <= DOT_DOT_OFFSET) {
-			break;
-		}
-
-		/* look for the previous entry in the directory */
-		next_pos = deh_offset(deh) - 1;
-
-		if (!de_visible(deh))
-			/* it is hidden entry */
-			continue;
-
-		d_reclen = entry_length(bh, ih, entry_num);
-		d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
-		d_off = deh_offset(deh);
-		d_ino = deh_objectid(deh);
-
-		if (!d_name[d_reclen - 1])
-			d_reclen = strlen(d_name);
-
-		if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) {
-			/* too big to send back to VFS */
-			continue;
-		}
-
-		/* Ignore the .reiserfs_priv entry */
-		if (reiserfs_xattrs(inode->i_sb) &&
-		    !old_format_only(inode->i_sb) &&
-		    deh_objectid(deh) ==
-		    le32_to_cpu(INODE_PKEY
-				(REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
-				k_objectid))
-			continue;
-
-		if (d_reclen <= 32) {
-			local_buf = small_buf;
-		} else {
-			local_buf = kmalloc(d_reclen, GFP_NOFS);
-			if (!local_buf) {
-				pathrelse(&path_to_entry);
-				return -ENOMEM;
-			}
-			if (item_moved(&tmp_ih, &path_to_entry)) {
-				kfree(local_buf);
-
-				/* sigh, must retry.  Do this same offset again */
-				next_pos = d_off;
-				goto research;
-			}
-		}
-
-		// Note, that we copy name to user space via temporary
-		// buffer (local_buf) because filldir will block if
-		// user space buffer is swapped out. At that time
-		// entry can move to somewhere else
-		memcpy(local_buf, d_name, d_reclen);
-
-		/* the filldir function might need to start transactions,
-		 * or do who knows what.  Release the path now that we've
-		 * copied all the important stuff out of the deh
-		 */
-		pathrelse(&path_to_entry);
-
-		if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
-			    DT_UNKNOWN) < 0) {
-			if (local_buf != small_buf) {
-				kfree(local_buf);
-			}
-			goto end;
-		}
-		if (local_buf != small_buf) {
-			kfree(local_buf);
-		}
-	}			/* while */
-
-      end:
-	pathrelse(&path_to_entry);
-	return 0;
-}
-
-/*
- * this could be done with dedicated readdir ops for the xattr files,
- * but I want to get something working asap
- * this is stolen from vfs_readdir
- *
- */
-static
-int xattr_readdir(struct file *file, filldir_t filler, void *buf)
-{
-	struct inode *inode = file->f_path.dentry->d_inode;
-	int res = -ENOTDIR;
-	if (!file->f_op || !file->f_op->readdir)
-		goto out;
-	res = -ENOENT;
-	if (!IS_DEADDIR(inode)) {
-		lock_kernel();
-		res = __xattr_readdir(file, buf, filler);
-		unlock_kernel();
-	}
-      out:
-	return res;
-}
-
 /* Internal operations on file data */
 static inline void reiserfs_put_page(struct page *page)
 {
@@ -670,152 +494,83 @@ reiserfs_xattr_get(struct inode *inode, 
 	return err;
 }
 
-/* The following are side effects of other operations that aren't explicitly
- * modifying extended attributes. This includes operations such as permissions
- * or ownership changes, object deletions, etc. */
-
-static int
-reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
-			      loff_t offset, u64 ino, unsigned int d_type)
+#if 0
+static int __restart_transaction_if_needed(struct inode *inode, int chunk)
 {
-	struct dentry *xadir = (struct dentry *)buf;
-	struct dentry *dentry;
-	int err = 0;
+	struct reiserfs_transaction_handle *th = current->journal_info;
+	struct super_block *s = th->t_super;
+	int len = th->t_blocks_allocated;
+	int err;
 
-	dentry = lookup_one_len(name, xadir, namelen);
-	if (IS_ERR(dentry)) {
-		err = PTR_ERR(dentry);
-		goto out;
-	} else if (!dentry->d_inode) {
-		err = -ENODATA;
-		goto out_file;
-	}
+	BUG_ON(!th->t_trans_id);
+	BUG_ON(!th->t_refcount);
 
-	/* Skip directories.. */
-	if (S_ISDIR(dentry->d_inode->i_mode))
-		goto out_file;
-
-	err = vfs_unlink(xadir->d_inode, dentry);
-
-      out_file:
-	dput(dentry);
-
-      out:
-	return err;
-}
-
-/* This is called w/ inode->i_mutex downed */
-int reiserfs_delete_xattrs(struct inode *inode)
-{
-	struct file *fp;
-	struct dentry *dir, *root;
-	int err = 0;
-
-	/* Skip out, an xattr has no xattrs associated with it */
-	if (is_reiserfs_priv_object(inode) ||
-	    get_inode_sd_version(inode) == STAT_DATA_V1 ||
-	    !reiserfs_xattrs(inode->i_sb)) {
+	if (!journal_transaction_should_end(th, len))
 		return 0;
-	}
-	dir = open_xa_dir(inode, XATTR_REPLACE);
-	if (IS_ERR(dir)) {
-		err = PTR_ERR(dir);
-		goto out;
-	} else if (!dir->d_inode) {
-		dput(dir);
-		err = 0;
-		goto out;
-	}
 
-	fp = dentry_open(dir, NULL, O_RDWR|O_NOATIME|O_DIRECTORY);
-	if (IS_ERR(fp)) {
-		err = PTR_ERR(fp);
-		/* dentry_open dputs the dentry if it fails */
-		goto out;
+	/* we cannot restart while nested */
+	if (th->t_refcount > 1) {
+		reiserfs_warning(th->t_super, "jdm-20003", "can't restart nested transaction in %s\n", __FUNCTION__);
+		return 0;
 	}
 
-	mutex_lock_nested(&fp->f_path.dentry->d_inode->i_mutex, I_MUTEX_XATTR);
-	lock_kernel();
-	err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir);
-	unlock_kernel();
-	mutex_unlock(&fp->f_path.dentry->d_inode->i_mutex);
-	if (err)
-		goto out_dir;
-
-	/* Leftovers besides . and .. -- that's not good. */
-	if (dir->d_inode->i_nlink <= 2) {
-		struct reiserfs_transaction_handle th;
-		int jbegin_count;
-		int jerr;
-
-		jbegin_count = JOURNAL_PER_BALANCE_CNT * 2 + 2 + 4 *
-		               REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
-		reiserfs_write_lock(inode->i_sb);
-		err = journal_begin (&th, inode->i_sb, jbegin_count);
-		if (err) {
-			reiserfs_write_unlock(inode->i_sb);
-			unlock_kernel();
-			goto out_dir;
-		}
-		root = open_xa_root(inode->i_sb, XATTR_REPLACE);
-		mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_XATTR);
-		err = vfs_rmdir(root->d_inode, dir);
-		mutex_unlock(&root->d_inode->i_mutex);
-		jerr = journal_end (&th, inode->i_sb, jbegin_count);
-		reiserfs_write_unlock(inode->i_sb);
-		dput(root);
-		if (!err && jerr)
-			err = jerr;
-	} else {
-		reiserfs_warning(inode->i_sb, "jdm-20004",
-				 "Couldn't remove all entries in directory");
+	err = journal_end(th, s, len);
+	if (!err) {
+		err = journal_begin(th, s, chunk);
+		if (!err)
+			reiserfs_update_inode_transaction(inode);
 	}
 
-      out_dir:
-	fput(fp);
-
-      out:
 	return err;
 }
+#endif
 
-struct reiserfs_chown_buf {
-	struct inode *inode;
+/* The following are side effects of other operations that aren't explicitly
+ * modifying extended attributes. This includes operations such as permissions
+ * or ownership changes, object deletions, etc. */
+struct reiserfs_dentry_buf {
 	struct dentry *xadir;
-	struct iattr *attrs;
+	int count;
+	struct dentry *dentries[8];
 };
 
-/* XXX: If there is a better way to do this, I'd love to hear about it */
 static int
-reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
-			     loff_t offset, u64 ino, unsigned int d_type)
+fill_with_dentries(void *buf, const char *name, int namelen, loff_t offset,
+                   u64 ino, unsigned int d_type)
 {
-	struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf;
-	struct dentry *xafile, *xadir = chown_buf->xadir;
-	struct iattr *attrs = chown_buf->attrs;
-	int err = 0;
+	struct reiserfs_dentry_buf *dbuf = buf;
+	struct dentry *dentry;
+
+	if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
+		return -ENOSPC;
+
+	if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))
+		return 0;
 
-	xafile = lookup_one_len(name, xadir, namelen);
-	if (IS_ERR(xafile))
-		return PTR_ERR(xafile);
-	else if (!xafile->d_inode) {
-		dput(xafile);
+	dentry = lookup_one_len(name, dbuf->xadir, namelen);
+	if (IS_ERR(dentry)) {
+		return PTR_ERR(dentry);
+	} else if (!dentry->d_inode) {
+		/* This should never happen */
+		dput(dentry);
 		return -ENODATA;
 	}
 
-	if (!S_ISDIR(xafile->d_inode->i_mode))
-		err = notify_change(xafile, attrs);
-	dput(xafile);
-
-	return err;
+	dbuf->dentries[dbuf->count++] = dentry;
+	return 0;
 }
 
-int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
+typedef int(*xattr_action)(struct dentry *dentry, void *data);
+
+static int reiserfs_for_each_xattr(struct inode *inode, xattr_action action,
+                                   void *data)
 {
 	struct file *fp;
 	struct dentry *dir;
 	int err = 0;
-	struct reiserfs_chown_buf buf;
-	unsigned int ia_valid = attrs->ia_valid;
+	struct reiserfs_dentry_buf buf = {
+		.count = 0,
+	};
 
 	/* Skip out, an xattr has no xattrs associated with it */
 	if (is_reiserfs_priv_object(inode) ||
@@ -841,31 +596,95 @@ int reiserfs_chown_xattrs(struct inode *
 	}
 
 	mutex_lock_nested(&fp->f_path.dentry->d_inode->i_mutex, I_MUTEX_XATTR);
-	lock_kernel();
-
-	attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
 	buf.xadir = dir;
-	buf.attrs = attrs;
-	buf.inode = inode;
 
-	err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf);
-	if (err) {
-		unlock_kernel();
-		goto out_dir;
-	}
+	err = fp->f_op->readdir(fp, &buf, fill_with_dentries);
+	while ((err == 0 || err == -ENOSPC) && buf.count) {
+		int i;
+		err = 0;
 
-	err = notify_change(dir, attrs);
-	unlock_kernel();
+		for (i = 0; i < buf.count && buf.dentries[i]; i++) {
+			int lerr = 0;
+			struct dentry *dentry = buf.dentries[i];
+
+			if (err == 0 && !S_ISDIR(dentry->d_inode->i_mode))
+				lerr = action(dentry, data);
+
+			dput(dentry);
+			buf.dentries[i] = NULL;
+
+			if (lerr)
+				err = lerr;
+		}
+		buf.count = 0;
+		if (err == 0)
+			err = fp->f_op->readdir(fp, &buf, fill_with_dentries);
+	}
 
-      out_dir:
 	mutex_unlock(&fp->f_path.dentry->d_inode->i_mutex);
+
+	if (err == 0)
+		err = action(dir, data);
+
 	fput(fp);
 
       out:
-	attrs->ia_valid = ia_valid;
 	return err;
 }
 
+static int delete_one_xattr(struct dentry *dentry, void *data)
+{
+	struct inode *dir = dentry->d_parent->d_inode;
+
+	/* This is the xattr dir, handle specially. */
+	if (S_ISDIR(dentry->d_inode->i_mode)) {
+		int err;
+		struct reiserfs_transaction_handle th;
+		int nblocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
+		              4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
+
+		BUG_ON(dentry == dentry->d_parent);
+		if (dir == dentry->d_inode) {
+			printk ("dir = %s\n", dentry->d_parent->d_name.name);
+			printk ("dentry = %s\n", dentry->d_name.name);
+			return -EBUSY;
+		}
+
+		/* reiserfs_rmdir is going to start a transaction itself,
+		 * but we need to start it outside of locking the xattr
+		 * root to preserve lock ordering. */
+		err = journal_begin(&th, dir->i_sb, nblocks);
+		if (err == 0) {
+			int err2;
+			mutex_lock_nested(&dir->i_mutex, I_MUTEX_XATTR);
+			err = vfs_rmdir(dir, dentry);
+			err2 = journal_end(&th, dir->i_sb, nblocks);
+			mutex_unlock(&dir->i_mutex);
+			if (err2)
+				err = err2;
+		}
+		return err;
+	}
+
+	return vfs_unlink(dir, dentry);
+}
+
+static int chown_one_xattr(struct dentry *dentry, void *data)
+{
+	struct iattr *attrs = data;
+	return notify_change(dentry, attrs);
+}
+
+int reiserfs_delete_xattrs(struct inode *inode)
+{
+	return reiserfs_for_each_xattr(inode, delete_one_xattr, NULL);
+}
+
+int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
+{
+	return reiserfs_for_each_xattr(inode, chown_one_xattr, attrs);
+}
+
 /* Actual operations that are exported to VFS-land */
 
 /*
@@ -996,7 +815,7 @@ ssize_t reiserfs_listxattr(struct dentry
 		goto out;
 	}
 
-	err = xattr_readdir(fp, listxattr_filler, &buf);
+	err = fp->f_op->readdir(fp, &buf, listxattr_filler);
 	if (err)
 		goto out_dir;
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#23 lore raw

PATCH 22/40 reiserfs: add atomic addition of selinux attributes during inode creation

In reply to [email protected]

Some time ago, some changes were made to make security inode attributes be atomically written during inode creation. ReiserFS fell behind in this area, but with the reworking of the xattr code, it's now fairly easy to add.

The following patch adds the ability for security attributes to be added automatically during inode creation.

--

 fs/reiserfs/inode.c            |   16 +++++++++++
 fs/reiserfs/namei.c            |   37 ++++++++++++++++++++++++---
 fs/reiserfs/xattr_security.c   |   55 +++++++++++++++++++++++++++++++++++++++--
 include/linux/reiserfs_fs.h    |    4 ++
 include/linux/reiserfs_xattr.h |   31 +++++++++++++++++++++++
 5 files changed, 135 insertions(+), 8 deletions(-)
fs/reiserfs/inode.c +15 -1
@@ -1758,7 +1758,8 @@ int reiserfs_new_inode(struct reiserfs_t
 		       /* 0 for regular, EMTRY_DIR_SIZE for dirs, 
 		          strlen (symname) for symlinks) */
 		       loff_t i_size, struct dentry *dentry,
-		       struct inode *inode)
+		       struct inode *inode,
+		       struct reiserfs_security_handle *security)
 {
 	struct super_block *sb;
 	INITIALIZE_PATH(path_to_key);
@@ -1936,6 +1937,19 @@ int reiserfs_new_inode(struct reiserfs_t
 		reiserfs_mark_inode_private(inode);
 	}
 
+	if (security->name) {
+		retval = reiserfs_security_write(th, inode, security);
+		if (retval) {
+			err = retval;
+			reiserfs_check_path(&path_to_key);
+			retval = journal_end(th, th->t_super,
+			                     th->t_blocks_allocated);
+			if (retval)
+				err = retval;
+			goto out_inserted_sd;
+		}
+	}
+
 	insert_inode_hash(inode);
 	reiserfs_update_sd(th, inode);
 	reiserfs_check_path(&path_to_key);
fs/reiserfs/namei.c +33 -4
@@ -606,6 +606,7 @@ static int reiserfs_create(struct inode 
 	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
 		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
 	struct reiserfs_transaction_handle th;
+	struct reiserfs_security_handle security;
 
 	if (!(inode = new_inode(dir->i_sb))) {
 		return -ENOMEM;
@@ -613,6 +614,12 @@ static int reiserfs_create(struct inode 
 	new_inode_init(inode, dir, mode);
 
 	jbegin_count += reiserfs_cache_default_acl(dir);
+	retval = reiserfs_security_init(dir, inode, &security);
+	if (retval < 0) {
+		drop_new_inode(inode);
+		return retval;
+	}
+	jbegin_count += retval;
 	reiserfs_write_lock(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
@@ -623,7 +630,7 @@ static int reiserfs_create(struct inode 
 
 	retval =
 	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-			       inode);
+			       inode, &security);
 	if (retval)
 		goto out_failed;
 
@@ -661,6 +668,7 @@ static int reiserfs_mknod(struct inode *
 	int retval;
 	struct inode *inode;
 	struct reiserfs_transaction_handle th;
+	struct reiserfs_security_handle security;
 	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
 	int jbegin_count =
 	    JOURNAL_PER_BALANCE_CNT * 3 +
@@ -676,6 +684,12 @@ static int reiserfs_mknod(struct inode *
 	new_inode_init(inode, dir, mode);
 
 	jbegin_count += reiserfs_cache_default_acl(dir);
+	retval = reiserfs_security_init(dir, inode, &security);
+	if (retval < 0) {
+		drop_new_inode(inode);
+		return retval;
+	}
+	jbegin_count += retval;
 	reiserfs_write_lock(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
@@ -686,7 +700,7 @@ static int reiserfs_mknod(struct inode *
 
 	retval =
 	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-			       inode);
+			       inode, &security);
 	if (retval) {
 		goto out_failed;
 	}
@@ -727,6 +741,7 @@ static int reiserfs_mkdir(struct inode *
 	int retval;
 	struct inode *inode;
 	struct reiserfs_transaction_handle th;
+	struct reiserfs_security_handle security;
 	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
 	int jbegin_count =
 	    JOURNAL_PER_BALANCE_CNT * 3 +
@@ -744,6 +759,12 @@ static int reiserfs_mkdir(struct inode *
 	new_inode_init(inode, dir, mode);
 
 	jbegin_count += reiserfs_cache_default_acl(dir);
+	retval = reiserfs_security_init(dir, inode, &security);
+	if (retval < 0) {
+		drop_new_inode(inode);
+		return retval;
+	}
+	jbegin_count += retval;
 	reiserfs_write_lock(dir->i_sb);
 
 	retval = journal_begin(&th, dir->i_sb, jbegin_count);
@@ -760,7 +781,7 @@ static int reiserfs_mkdir(struct inode *
 	    retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
 					old_format_only(dir->i_sb) ?
 					EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
-					dentry, inode);
+					dentry, inode, &security);
 	if (retval) {
 		dir->i_nlink--;
 		goto out_failed;
@@ -1001,6 +1022,7 @@ static int reiserfs_symlink(struct inode
 	char *name;
 	int item_len;
 	struct reiserfs_transaction_handle th;
+	struct reiserfs_security_handle security;
 	int mode = S_IFLNK | S_IRWXUGO;
 	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
 	int jbegin_count =
@@ -1013,6 +1035,13 @@ static int reiserfs_symlink(struct inode
 	}
 	new_inode_init(inode, parent_dir, mode);
 
+	retval = reiserfs_security_init(parent_dir, inode, &security);
+	if (retval < 0) {
+		drop_new_inode(inode);
+		return retval;
+	}
+	jbegin_count += retval;
+
 	reiserfs_write_lock(parent_dir->i_sb);
 	item_len = ROUND_UP(strlen(symname));
 	if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) {
@@ -1039,7 +1068,7 @@ static int reiserfs_symlink(struct inode
 
 	retval =
 	    reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
-			       dentry, inode);
+			       dentry, inode, &security);
 	kfree(name);
 	if (retval) {		/* reiserfs_new_inode iputs for us */
 		goto out_failed;
fs/reiserfs/xattr_security.c +53 -2

69 lines not on this page · raw message

include/linux/reiserfs_fs.h +3 -1
@@ -1909,10 +1909,12 @@ void make_le_item_head(struct item_head 
 		       loff_t offset, int type, int length, int entry_count);
 struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);
 
+struct reiserfs_security_handle;
 int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
 		       struct inode *dir, int mode,
 		       const char *symname, loff_t i_size,
-		       struct dentry *dentry, struct inode *inode);
+		       struct dentry *dentry, struct inode *inode,
+		       struct reiserfs_security_handle *security);
 
 void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
 			     struct inode *inode, loff_t size);
include/linux/reiserfs_xattr.h +31 -0
@@ -15,6 +15,12 @@ struct reiserfs_xattr_header {
 	__le32 h_hash;		/* hash of the value */
 };
 
+struct reiserfs_security_handle {
+	char *name;
+	void *value;
+	size_t length;
+};
+
 #ifdef __KERNEL__
 
 #include <linux/init.h>
@@ -50,6 +56,14 @@ int reiserfs_xattr_set_handle(struct rei
 extern struct xattr_handler reiserfs_xattr_user_handler;
 extern struct xattr_handler reiserfs_xattr_trusted_handler;
 extern struct xattr_handler reiserfs_xattr_security_handler;
+#ifdef CONFIG_REISERFS_FS_SECURITY
+int reiserfs_security_init(struct inode *dir, struct inode *inode,
+                           struct reiserfs_security_handle *sec);
+int reiserfs_security_write(struct reiserfs_transaction_handle *th,
+                            struct inode *inode,
+			    struct reiserfs_security_handle *sec);
+void reiserfs_security_free(struct reiserfs_security_handle *sec);
+#endif
 
 
 static inline void reiserfs_mark_inode_private(struct inode *inode)
@@ -114,6 +128,23 @@ static inline void reiserfs_init_xattr_r
 }
 #endif  /*  CONFIG_REISERFS_FS_XATTR  */
 
+#ifndef CONFIG_REISERFS_FS_SECURITY
+static inline int reiserfs_security_init(struct inode *dir,
+                                         struct inode *inode,
+                                         struct reiserfs_security_handle *sec)
+{
+	return 0;
+}
+static inline int reiserfs_security_write(struct reiserfs_transaction_handle *th,
+                                          struct inode *inode,
+					  struct reiserfs_security_handle *sec)
+{
+	return 0;
+}
+static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
+{}
+#endif
+
 #endif  /*  __KERNEL__  */
 
 #endif  /*  _LINUX_REISERFS_XATTR_H  */
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#24 lore raw

PATCH 23/40 reiserfs: cleanup path functions

In reply to [email protected]

This patch cleans up some redundancies in the reiserfs tree path code.

decrement_bcount() is essentially the same function as brelse(), so we use that instead.

decrement_counters_in_path() is exactly the same function as pathrelse(), so we kill that and use pathrelse() instead.

There's also a bit of cleanup that makes the code a bit more readable.

---

 fs/reiserfs/fix_node.c |   58 ++++++++++++++++++++++++------------------------
 fs/reiserfs/stree.c    |   59 ++++++++++---------------------------------------
 2 files changed, 43 insertions(+), 74 deletions(-)
fs/reiserfs/fix_node.c +30 -28
@@ -753,20 +753,21 @@ static void free_buffers_in_tb(struct tr
 {
 	int n_counter;
 
-	decrement_counters_in_path(p_s_tb->tb_path);
+	pathrelse(p_s_tb->tb_path);
 
 	for (n_counter = 0; n_counter < MAX_HEIGHT; n_counter++) {
-		decrement_bcount(p_s_tb->L[n_counter]);
+		brelse(p_s_tb->L[n_counter]);
+		brelse(p_s_tb->R[n_counter]);
+		brelse(p_s_tb->FL[n_counter]);
+		brelse(p_s_tb->FR[n_counter]);
+		brelse(p_s_tb->CFL[n_counter]);
+		brelse(p_s_tb->CFR[n_counter]);
+
 		p_s_tb->L[n_counter] = NULL;
-		decrement_bcount(p_s_tb->R[n_counter]);
 		p_s_tb->R[n_counter] = NULL;
-		decrement_bcount(p_s_tb->FL[n_counter]);
 		p_s_tb->FL[n_counter] = NULL;
-		decrement_bcount(p_s_tb->FR[n_counter]);
 		p_s_tb->FR[n_counter] = NULL;
-		decrement_bcount(p_s_tb->CFL[n_counter]);
 		p_s_tb->CFL[n_counter] = NULL;
-		decrement_bcount(p_s_tb->CFR[n_counter]);
 		p_s_tb->CFR[n_counter] = NULL;
 	}
 }
@@ -1020,7 +1021,7 @@ static int get_far_parent(struct tree_ba
 	if (buffer_locked(*pp_s_com_father)) {
 		__wait_on_buffer(*pp_s_com_father);
 		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
-			decrement_bcount(*pp_s_com_father);
+			brelse(*pp_s_com_father);
 			return REPEAT_SEARCH;
 		}
 	}
@@ -1048,8 +1049,8 @@ static int get_far_parent(struct tree_ba
 		return IO_ERROR;
 
 	if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
-		decrement_counters_in_path(&s_path_to_neighbor_father);
-		decrement_bcount(*pp_s_com_father);
+		pathrelse(&s_path_to_neighbor_father);
+		brelse(*pp_s_com_father);
 		return REPEAT_SEARCH;
 	}
 
@@ -1061,7 +1062,7 @@ static int get_far_parent(struct tree_ba
 	       FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small");
 
 	s_path_to_neighbor_father.path_length--;
-	decrement_counters_in_path(&s_path_to_neighbor_father);
+	pathrelse(&s_path_to_neighbor_father);
 	return CARRY_ON;
 }
 
@@ -1084,10 +1085,10 @@ static int get_parents(struct tree_balan
 	if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
 		/* The root can not have parents.
 		   Release nodes which previously were obtained as parents of the current node neighbors. */
-		decrement_bcount(p_s_tb->FL[n_h]);
-		decrement_bcount(p_s_tb->CFL[n_h]);
-		decrement_bcount(p_s_tb->FR[n_h]);
-		decrement_bcount(p_s_tb->CFR[n_h]);
+		brelse(p_s_tb->FL[n_h]);
+		brelse(p_s_tb->CFL[n_h]);
+		brelse(p_s_tb->FR[n_h]);
+		brelse(p_s_tb->CFR[n_h]);
 		p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] =
 		    p_s_tb->CFR[n_h] = NULL;
 		return CARRY_ON;
@@ -1113,9 +1114,9 @@ static int get_parents(struct tree_balan
 			return n_ret_value;
 	}
 
-	decrement_bcount(p_s_tb->FL[n_h]);
+	brelse(p_s_tb->FL[n_h]);
 	p_s_tb->FL[n_h] = p_s_curf;	/* New initialization of FL[n_h]. */
-	decrement_bcount(p_s_tb->CFL[n_h]);
+	brelse(p_s_tb->CFL[n_h]);
 	p_s_tb->CFL[n_h] = p_s_curcf;	/* New initialization of CFL[n_h]. */
 
 	RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
@@ -1143,10 +1144,10 @@ static int get_parents(struct tree_balan
 		p_s_tb->rkey[n_h] = n_position;
 	}
 
-	decrement_bcount(p_s_tb->FR[n_h]);
+	brelse(p_s_tb->FR[n_h]);
 	p_s_tb->FR[n_h] = p_s_curf;	/* New initialization of FR[n_path_offset]. */
 
-	decrement_bcount(p_s_tb->CFR[n_h]);
+	brelse(p_s_tb->CFR[n_h]);
 	p_s_tb->CFR[n_h] = p_s_curcf;	/* New initialization of CFR[n_path_offset]. */
 
 	RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
@@ -1962,7 +1963,7 @@ static int get_neighbors(struct tree_bal
 		if (!p_s_bh)
 			return IO_ERROR;
 		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
-			decrement_bcount(p_s_bh);
+			brelse(p_s_bh);
 			PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]);
 			return REPEAT_SEARCH;
 		}
@@ -1978,7 +1979,7 @@ static int get_neighbors(struct tree_bal
 		       dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)),
 		       "PAP-8290: invalid child size of left neighbor");
 
-		decrement_bcount(p_s_tb->L[n_h]);
+		brelse(p_s_tb->L[n_h]);
 		p_s_tb->L[n_h] = p_s_bh;
 	}
 
@@ -1999,11 +2000,11 @@ static int get_neighbors(struct tree_bal
 		if (!p_s_bh)
 			return IO_ERROR;
 		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
-			decrement_bcount(p_s_bh);
+			brelse(p_s_bh);
 			PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]);
 			return REPEAT_SEARCH;
 		}
-		decrement_bcount(p_s_tb->R[n_h]);
+		brelse(p_s_tb->R[n_h]);
 		p_s_tb->R[n_h] = p_s_bh;
 
 		RFALSE(!n_h
@@ -2509,16 +2510,17 @@ int fix_nodes(int n_op_mode, struct tree
 			}
 
 			brelse(p_s_tb->L[i]);
-			p_s_tb->L[i] = NULL;
 			brelse(p_s_tb->R[i]);
-			p_s_tb->R[i] = NULL;
 			brelse(p_s_tb->FL[i]);
-			p_s_tb->FL[i] = NULL;
 			brelse(p_s_tb->FR[i]);
-			p_s_tb->FR[i] = NULL;
 			brelse(p_s_tb->CFL[i]);
-			p_s_tb->CFL[i] = NULL;
 			brelse(p_s_tb->CFR[i]);
+
+			p_s_tb->L[i] = NULL;
+			p_s_tb->R[i] = NULL;
+			p_s_tb->FL[i] = NULL;
+			p_s_tb->FR[i] = NULL;
+			p_s_tb->CFL[i] = NULL;
 			p_s_tb->CFR[i] = NULL;
 		}
 
fs/reiserfs/stree.c +13 -46

105 lines not on this page · raw message

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#25 lore raw

PATCH 24/40 reiserfs: strip trailing whitespace

In reply to [email protected]

This patch strips trailing whitespace from the reiserfs code.

---
 fs/reiserfs/README             |    4 -
 fs/reiserfs/do_balan.c         |   14 ++--
 fs/reiserfs/file.c             |   14 ++--
 fs/reiserfs/fix_node.c         |   38 ++++++------
 fs/reiserfs/hashes.c           |    2 
 fs/reiserfs/ibalance.c         |   10 +--
 fs/reiserfs/inode.c            |   52 ++++++++---------
 fs/reiserfs/ioctl.c            |    2 
 fs/reiserfs/journal.c          |  124 ++++++++++++++++++++---------------------
 fs/reiserfs/lbalance.c         |   18 ++---
 fs/reiserfs/namei.c            |   30 ++++-----
 fs/reiserfs/objectid.c         |    2 
 fs/reiserfs/prints.c           |   26 ++++----
 fs/reiserfs/procfs.c           |    2 
 fs/reiserfs/resize.c           |    6 -
 fs/reiserfs/stree.c            |    8 +-
 fs/reiserfs/super.c            |   10 +--
 fs/reiserfs/tail_conversion.c  |    2 
 include/linux/reiserfs_fs_sb.h |   14 ++--
 19 files changed, 189 insertions(+), 189 deletions(-)
fs/reiserfs/README +2 -2
@@ -1,4 +1,4 @@
-[LICENSING] 
+[LICENSING]
 
 ReiserFS is hereby licensed under the GNU General
 Public License version 2.
@@ -31,7 +31,7 @@ the GPL as not allowing those additional
 it wrongly, and Richard Stallman agrees with me, when carefully read
 you can see that those restrictions on additional terms do not apply
 to the owner of the copyright, and my interpretation of this shall
-govern for this license.  
+govern for this license.
 
 Finally, nothing in this license shall be interpreted to allow you to
 fail to fairly credit me, or to remove my credits, without my
fs/reiserfs/do_balan.c +7 -7
@@ -39,21 +39,21 @@ inline void do_balance_mark_leaf_dirty(s
 #define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
 #define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
 
-/* summary: 
+/* summary:
  if deleting something ( tb->insert_size[0] < 0 )
    return(balance_leaf_when_delete()); (flag d handled here)
  else
    if lnum is larger than 0 we put items into the left node
    if rnum is larger than 0 we put items into the right node
    if snum1 is larger than 0 we put items into the new node s1
-   if snum2 is larger than 0 we put items into the new node s2 
+   if snum2 is larger than 0 we put items into the new node s2
 Note that all *num* count new items being created.
 
 It would be easier to read balance_leaf() if each of these summary
 lines was a separate procedure rather than being inlined.  I think
 that there are many passages here and in balance_leaf_when_delete() in
 which two calls to one procedure can replace two passages, and it
-might save cache space and improve software maintenance costs to do so.  
+might save cache space and improve software maintenance costs to do so.
 
 Vladimir made the perceptive comment that we should offload most of
 the decision making in this function into fix_nodes/check_balance, and
@@ -258,15 +258,15 @@ static int balance_leaf(struct tree_bala
     )
 {
 	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
-	int item_pos = PATH_LAST_POSITION(tb->tb_path);	/*  index into the array of item headers in S[0] 
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);	/*  index into the array of item headers in S[0]
 							   of the affected item */
 	struct buffer_info bi;
 	struct buffer_head *S_new[2];	/* new nodes allocated to hold what could not fit into S */
 	int snum[2];		/* number of items that will be placed
 				   into S_new (includes partially shifted
 				   items) */
-	int sbytes[2];		/* if an item is partially shifted into S_new then 
-				   if it is a directory item 
+	int sbytes[2];		/* if an item is partially shifted into S_new then
+				   if it is a directory item
 				   it is the number of entries from the item that are shifted into S_new
 				   else
 				   it is the number of bytes from the item that are shifted into S_new
@@ -2036,7 +2036,7 @@ static inline void do_balance_starts(str
 	/* store_print_tb (tb); */
 
 	/* do not delete, just comment it out */
-/*    print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb, 
+/*    print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb,
 	     "check");*/
 	RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB");
 #ifdef CONFIG_REISERFS_CHECK
fs/reiserfs/file.c +7 -7
@@ -20,14 +20,14 @@
 ** insertion/balancing, for files that are written in one write.
 ** It avoids unnecessary tail packings (balances) for files that are written in
 ** multiple writes and are small enough to have tails.
-** 
+**
 ** file_release is called by the VFS layer when the file is closed.  If
 ** this is the last open file descriptor, and the file
 ** small enough to have a tail, and the tail is currently in an
 ** unformatted node, the tail is converted back into a direct item.
-** 
+**
 ** We use reiserfs_truncate_file to pack the tail, since it already has
-** all the conditions coded.  
+** all the conditions coded.
 */
 static int reiserfs_file_release(struct inode *inode, struct file *filp)
 {
@@ -723,7 +723,7 @@ static void reiserfs_unprepare_pages(str
 static int reiserfs_copy_from_user_to_file_region(loff_t pos,	/* In-file position */
 						  int num_pages,	/* Number of pages affected */
 						  int write_bytes,	/* Amount of bytes to write */
-						  struct page **prepared_pages,	/* pointer to 
+						  struct page **prepared_pages,	/* pointer to
 										   array to
 										   prepared pages
 										 */
@@ -900,7 +900,7 @@ static int reiserfs_submit_file_region_f
 	}
 	th->t_trans_id = 0;
 
-	/* 
+	/*
 	 * we have to unlock the pages after updating i_size, otherwise
 	 * we race with writepage
 	 */
@@ -971,7 +971,7 @@ static int reiserfs_check_for_tail_and_c
    @prepared_pages array. Also buffers are allocated for these pages.
    First and last page of the region is read if it is overwritten only
    partially. If last page did not exist before write (file hole or file
-   append), it is zeroed, then. 
+   append), it is zeroed, then.
    Returns number of unallocated blocks that should be allocated to cover
    new file data.*/
 static int reiserfs_prepare_file_region_for_write(struct inode *inode
@@ -1256,7 +1256,7 @@ static int reiserfs_prepare_file_region_
 }
 
 /* Write @count bytes at position @ppos in a file indicated by @file
-   from the buffer @buf.  
+   from the buffer @buf.
 
    generic_file_write() is only appropriate for filesystems that are not seeking to optimize performance and want
    something simple that works.  It is not for serious use by general purpose filesystems, excepting the one that it was
fs/reiserfs/fix_node.c +19 -19
@@ -30,8 +30,8 @@
  ** get_direct_parent
  ** get_neighbors
  ** fix_nodes
- ** 
- ** 
+ **
+ **
  **/
 
 #include <linux/time.h>
@@ -377,9 +377,9 @@ static int get_num_ver(int mode, struct 
 	int needed_nodes;
 	int start_item,		/* position of item we start filling node from */
 	 end_item,		/* position of item we finish filling node by */
-	 start_bytes,		/* number of first bytes (entries for directory) of start_item-th item 
+	 start_bytes,		/* number of first bytes (entries for directory) of start_item-th item
 				   we do not include into node that is being filled */
-	 end_bytes;		/* number of last bytes (entries for directory) of end_item-th item 
+	 end_bytes;		/* number of last bytes (entries for directory) of end_item-th item
 				   we do node include into node that is being filled */
 	int split_item_positions[2];	/* these are positions in virtual item of
 					   items, that are split between S[0] and
@@ -569,7 +569,7 @@ extern struct tree_balance *cur_tb;
 
 /* Set parameters for balancing.
  * Performs write of results of analysis of balancing into structure tb,
- * where it will later be used by the functions that actually do the balancing. 
+ * where it will later be used by the functions that actually do the balancing.
  * Parameters:
  *	tb	tree_balance structure;
  *	h	current level of the node;
@@ -1202,7 +1202,7 @@ static inline int can_node_be_removed(in
  *	h	current level of the node;
  *	inum	item number in S[h];
  *	mode	i - insert, p - paste;
- * Returns:	1 - schedule occurred; 
+ * Returns:	1 - schedule occurred;
  *	        0 - balancing for higher levels needed;
  *	       -1 - no balancing for higher levels needed;
  *	       -2 - no disk space.
@@ -1237,7 +1237,7 @@ static int ip_check_balance(struct tree_
 	/* we perform 8 calls to get_num_ver().  For each call we calculate five parameters.
 	   where 4th parameter is s1bytes and 5th - s2bytes
 	 */
-	short snum012[40] = { 0, };	/* s0num, s1num, s2num for 8 cases 
+	short snum012[40] = { 0, };	/* s0num, s1num, s2num for 8 cases
 					   0,1 - do not shift and do not shift but bottle
 					   2 - shift only whole item to left
 					   3 - shift to left and bottle as much as possible
@@ -1286,7 +1286,7 @@ static int ip_check_balance(struct tree_
 
 	create_virtual_node(tb, h);
 
-	/*  
+	/*
 	   determine maximal number of items we can shift to the left neighbor (in tb structure)
 	   and the maximal number of bytes that can flow to the left neighbor
 	   from the left most liquid item that cannot be shifted from S[0] entirely (returned value)
@@ -1347,13 +1347,13 @@ static int ip_check_balance(struct tree_
 
 	{
 		int lpar, rpar, nset, lset, rset, lrset;
-		/* 
+		/*
 		 * regular overflowing of the node
 		 */
 
-		/* get_num_ver works in 2 modes (FLOW & NO_FLOW) 
+		/* get_num_ver works in 2 modes (FLOW & NO_FLOW)
 		   lpar, rpar - number of items we can shift to left/right neighbor (including splitting item)
-		   nset, lset, rset, lrset - shows, whether flowing items give better packing 
+		   nset, lset, rset, lrset - shows, whether flowing items give better packing
 		 */
 #define FLOW 1
 #define NO_FLOW 0		/* do not any splitting */
@@ -1543,7 +1543,7 @@ static int ip_check_balance(struct tree_
  *	h	current level of the node;
  *	inum	item number in S[h];
  *	mode	i - insert, p - paste;
- * Returns:	1 - schedule occurred; 
+ * Returns:	1 - schedule occurred;
  *	        0 - balancing for higher levels needed;
  *	       -1 - no balancing for higher levels needed;
  *	       -2 - no disk space.
@@ -1726,7 +1726,7 @@ static int dc_check_balance_internal(str
  *	h	current level of the node;
  *	inum	item number in S[h];
  *	mode	i - insert, p - paste;
- * Returns:	1 - schedule occurred; 
+ * Returns:	1 - schedule occurred;
  *	        0 - balancing for higher levels needed;
  *	       -1 - no balancing for higher levels needed;
  *	       -2 - no disk space.
@@ -1820,7 +1820,7 @@ static int dc_check_balance_leaf(struct 
  *	h	current level of the node;
  *	inum	item number in S[h];
  *	mode	d - delete, c - cut.
- * Returns:	1 - schedule occurred; 
+ * Returns:	1 - schedule occurred;
  *	        0 - balancing for higher levels needed;
  *	       -1 - no balancing for higher levels needed;
  *	       -2 - no disk space.
@@ -1849,7 +1849,7 @@ static int dc_check_balance(struct tree_
  *	h	current level of the node;
  *	inum	item number in S[h];
  *	mode	i - insert, p - paste, d - delete, c - cut.
- * Returns:	1 - schedule occurred; 
+ * Returns:	1 - schedule occurred;
  *	        0 - balancing for higher levels needed;
  *	       -1 - no balancing for higher levels needed;
  *	       -2 - no disk space.
@@ -2294,15 +2294,15 @@ static int wait_tb_buffers_until_unlocke
  *	analyze what and where should be moved;
  *	get sufficient number of new nodes;
  * Balancing will start only after all resources will be collected at a time.
- * 
+ *
  * When ported to SMP kernels, only at the last moment after all needed nodes
  * are collected in cache, will the resources be locked using the usual
  * textbook ordered lock acquisition algorithms.  Note that ensuring that
  * this code neither write locks what it does not need to write lock nor locks out of order
  * will be a pain in the butt that could have been avoided.  Grumble grumble. -Hans
- * 
+ *
  * fix is meant in the sense of render unchanging
- * 
+ *
  * Latency might be improved by first gathering a list of what buffers are needed
  * and then getting as many of them in parallel as possible? -Hans
  *
@@ -2314,7 +2314,7 @@ static int wait_tb_buffers_until_unlocke
  *      ins_ih & ins_sd are used when inserting
  * Returns:	1 - schedule occurred while the function worked;
  *	        0 - schedule didn't occur while the function worked;
- *             -1 - if no_disk_space 
+ *             -1 - if no_disk_space
  */
 
 int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_ins_ih,	// item head of item being inserted
fs/reiserfs/hashes.c +1 -1
@@ -7,7 +7,7 @@
  * (see Applied Cryptography, 2nd edition, p448).
  *
  * Jeremy Fitzhardinge <[email protected]> 1998
- * 
+ *
  * Jeremy has agreed to the contents of reiserfs/README. -Hans
  * Yura's function is added (04/07/2000)
  */
fs/reiserfs/ibalance.c +5 -5
@@ -278,7 +278,7 @@ static void internal_delete_childs(struc
 
 /* copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest
 * last_first == FIRST_TO_LAST means, that we copy first items from src to tail of dest
- * last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest 
+ * last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest
  */
 static void internal_copy_pointers_items(struct buffer_info *dest_bi,
 					 struct buffer_head *src,
@@ -385,7 +385,7 @@ static void internal_move_pointers_items
 	if (last_first == FIRST_TO_LAST) {	/* shift_left occurs */
 		first_pointer = 0;
 		first_item = 0;
-		/* delete cpy_num - del_par pointers and keys starting for pointers with first_pointer, 
+		/* delete cpy_num - del_par pointers and keys starting for pointers with first_pointer,
 		   for key - with first_item */
 		internal_delete_pointers_items(src_bi, first_pointer,
 					       first_item, cpy_num - del_par);
@@ -453,7 +453,7 @@ static void internal_insert_key(struct b
 	}
 }
 
-/* Insert d_key'th (delimiting) key from buffer cfl to tail of dest. 
+/* Insert d_key'th (delimiting) key from buffer cfl to tail of dest.
  * Copy pointer_amount node pointers and pointer_amount - 1 items from buffer src to buffer dest.
  * Replace  d_key'th key in buffer cfl.
  * Delete pointer_amount items and node pointers from buffer src.
@@ -518,7 +518,7 @@ static void internal_shift1_left(struct 
 	/*    internal_move_pointers_items (tb->L[h], tb->S[h], FIRST_TO_LAST, pointer_amount, 1); */
 }
 
-/* Insert d_key'th (delimiting) key from buffer cfr to head of dest. 
+/* Insert d_key'th (delimiting) key from buffer cfr to head of dest.
  * Copy n node pointers and n - 1 items from buffer src to buffer dest.
  * Replace  d_key'th key in buffer cfr.
  * Delete n items and node pointers from buffer src.
@@ -749,7 +749,7 @@ int balance_internal(struct tree_balance
        this means that new pointers and items must be inserted AFTER *
        child_pos
        }
-       else 
+       else
        {
        it is the position of the leftmost pointer that must be deleted (together with
        its corresponding key to the left of the pointer)
fs/reiserfs/inode.c +26 -26

166 lines not on this page · raw message

fs/reiserfs/ioctl.c +1 -1
@@ -166,7 +166,7 @@ static int reiserfs_unpack(struct inode 
 	}
 
 	/* we unpack by finding the page with the tail, and calling
-	 ** reiserfs_prepare_write on that page.  This will force a 
+	 ** reiserfs_prepare_write on that page.  This will force a
 	 ** reiserfs_get_block to unpack the tail for us.
 	 */
 	index = inode->i_size >> PAGE_CACHE_SHIFT;
fs/reiserfs/journal.c +62 -62

361 lines not on this page · raw message

fs/reiserfs/lbalance.c +9 -9
@@ -119,8 +119,8 @@ static void leaf_copy_dir_entries(struct
 			   DEH_SIZE * copy_count + copy_records_len);
 }
 
-/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or 
-   part of it or nothing (see the return 0 below) from SOURCE to the end 
+/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or
+   part of it or nothing (see the return 0 below) from SOURCE to the end
    (if last_first) or beginning (!last_first) of the DEST */
 /* returns 1 if anything was copied, else 0 */
 static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
@@ -396,7 +396,7 @@ static void leaf_item_bottle(struct buff
 		else {
 			struct item_head n_ih;
 
-			/* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST 
+			/* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST
 			   part defined by 'cpy_bytes'; create new item header; change old item_header (????);
 			   n_ih = new item_header;
 			 */
@@ -426,7 +426,7 @@ static void leaf_item_bottle(struct buff
 		else {
 			struct item_head n_ih;
 
-			/* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST 
+			/* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST
 			   part defined by 'cpy_bytes'; create new item header;
 			   n_ih = new item_header;
 			 */
@@ -724,7 +724,7 @@ int leaf_shift_right(struct tree_balance
 static void leaf_delete_items_entirely(struct buffer_info *bi,
 				       int first, int del_num);
 /*  If del_bytes == -1, starting from position 'first' delete del_num items in whole in buffer CUR.
-    If not. 
+    If not.
     If last_first == 0. Starting from position 'first' delete del_num-1 items in whole. Delete part of body of
     the first item. Part defined by del_bytes. Don't delete first item header
     If last_first == 1. Starting from position 'first+1' delete del_num-1 items in whole. Delete part of body of
@@ -783,7 +783,7 @@ void leaf_delete_items(struct buffer_inf
 				/* len = body len of item */
 				len = ih_item_len(ih);
 
-			/* delete the part of the last item of the bh 
+			/* delete the part of the last item of the bh
 			   do not delete item header
 			 */
 			leaf_cut_from_buffer(cur_bi, B_NR_ITEMS(bh) - 1,
@@ -865,7 +865,7 @@ void leaf_insert_into_buf(struct buffer_
 	}
 }
 
-/* paste paste_size bytes to affected_item_num-th item. 
+/* paste paste_size bytes to affected_item_num-th item.
    When item is a directory, this only prepare space for new entries */
 void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num,
 			  int pos_in_item, int paste_size,
@@ -1022,7 +1022,7 @@ static int leaf_cut_entries(struct buffe
 /*  when cut item is part of regular file
         pos_in_item - first byte that must be cut
         cut_size - number of bytes to be cut beginning from pos_in_item
- 
+
    when cut item is part of directory
         pos_in_item - number of first deleted entry
         cut_size - count of deleted entries
@@ -1274,7 +1274,7 @@ void leaf_paste_entries(struct buffer_he
 	/* change item key if necessary (when we paste before 0-th entry */
 	if (!before) {
 		set_le_ih_k_offset(ih, deh_offset(new_dehs));
-/*      memcpy (&ih->ih_key.k_offset, 
+/*      memcpy (&ih->ih_key.k_offset,
 		       &new_dehs->deh_offset, SHORT_KEY_SIZE);*/
 	}
 #ifdef CONFIG_REISERFS_CHECK
fs/reiserfs/namei.c +15 -15
@@ -106,7 +106,7 @@ key of the first directory entry in it.
 This function first calls search_by_key, then, if item whose first
 entry matches is not found it looks for the entry inside directory
 item found by search_by_key. Fills the path to the entry, and to the
-entry position in the item 
+entry position in the item
 
 */
 
@@ -370,7 +370,7 @@ static struct dentry *reiserfs_lookup(st
 	return d_splice_alias(inode, dentry);
 }
 
-/* 
+/*
 ** looks up the dentry of the parent directory for child.
 ** taken from ext2_get_parent
 */
@@ -409,7 +409,7 @@ struct dentry *reiserfs_get_parent(struc
 	return parent;
 }
 
-/* add entry to the directory (entry can be hidden). 
+/* add entry to the directory (entry can be hidden).
 
 insert definition of when hidden directories are used here -Hans
 
@@ -567,7 +567,7 @@ static int drop_new_inode(struct inode *
 	return 0;
 }
 
-/* utility function that does setup for reiserfs_new_inode.  
+/* utility function that does setup for reiserfs_new_inode.
 ** DQUOT_INIT needs lots of credits so it's better to have it
 ** outside of a transaction, so we had to pull some bits of
 ** reiserfs_new_inode out into this func.
@@ -822,7 +822,7 @@ static inline int reiserfs_empty_dir(str
 {
 	/* we can cheat because an old format dir cannot have
 	 ** EMPTY_DIR_SIZE, and a new format dir cannot have
-	 ** EMPTY_DIR_SIZE_V1.  So, if the inode is either size, 
+	 ** EMPTY_DIR_SIZE_V1.  So, if the inode is either size,
 	 ** regardless of disk format version, the directory is empty.
 	 */
 	if (inode->i_size != EMPTY_DIR_SIZE &&
@@ -1162,7 +1162,7 @@ static int reiserfs_link(struct dentry *
 	return retval;
 }
 
-// de contains information pointing to an entry which 
+// de contains information pointing to an entry which
 static int de_still_valid(const char *name, int len,
 			  struct reiserfs_dir_entry *de)
 {
@@ -1206,10 +1206,10 @@ static void set_ino_in_dir_entry(struct 
 	de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
 }
 
-/* 
+/*
  * process, that is going to call fix_nodes/do_balance must hold only
  * one path. If it holds 2 or more, it can get into endless waiting in
- * get_empty_nodes or its clones 
+ * get_empty_nodes or its clones
  */
 static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 			   struct inode *new_dir, struct dentry *new_dentry)
@@ -1263,7 +1263,7 @@ static int reiserfs_rename(struct inode 
 
 	old_inode_mode = old_inode->i_mode;
 	if (S_ISDIR(old_inode_mode)) {
-		// make sure, that directory being renamed has correct ".." 
+		// make sure, that directory being renamed has correct ".."
 		// and that its new parent directory has not too many links
 		// already
 
@@ -1274,8 +1274,8 @@ static int reiserfs_rename(struct inode 
 			}
 		}
 
-		/* directory is renamed, its parent directory will be changed, 
-		 ** so find ".." entry 
+		/* directory is renamed, its parent directory will be changed,
+		 ** so find ".." entry
 		 */
 		dot_dot_de.de_gen_number_bit_string = NULL;
 		retval =
@@ -1385,9 +1385,9 @@ static int reiserfs_rename(struct inode 
 		   this stuff, yes? Then, having
 		   gathered everything into RAM we
 		   should lock the buffers, yes?  -Hans */
-		/* probably.  our rename needs to hold more 
-		 ** than one path at once.  The seals would 
-		 ** have to be written to deal with multi-path 
+		/* probably.  our rename needs to hold more
+		 ** than one path at once.  The seals would
+		 ** have to be written to deal with multi-path
 		 ** issues -chris
 		 */
 		/* sanity checking before doing the rename - avoid races many
@@ -1465,7 +1465,7 @@ static int reiserfs_rename(struct inode 
 	}
 
 	if (S_ISDIR(old_inode_mode)) {
-		// adjust ".." of renamed directory 
+		// adjust ".." of renamed directory
 		set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
 		journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
 
fs/reiserfs/objectid.c +1 -1
@@ -181,7 +181,7 @@ int reiserfs_convert_objectid_map_v1(str
 
 	if (cur_size > new_size) {
 		/* mark everyone used that was listed as free at the end of the objectid
-		 ** map 
+		 ** map
 		 */
 		objectid_map[new_size - 1] = objectid_map[cur_size - 1];
 		set_sb_oid_cursize(disk_sb, new_size);
fs/reiserfs/prints.c +13 -13
@@ -181,11 +181,11 @@ static char *is_there_reiserfs_struct(ch
    appropriative printk. With this reiserfs_warning you can use format
    specification for complex structures like you used to do with
    printfs for integers, doubles and pointers. For instance, to print
-   out key structure you have to write just: 
-   reiserfs_warning ("bad key %k", key); 
-   instead of 
-   printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid, 
-           key->k_offset, key->k_uniqueness); 
+   out key structure you have to write just:
+   reiserfs_warning ("bad key %k", key);
+   instead of
+   printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,
+           key->k_offset, key->k_uniqueness);
 */
 
 static void prepare_error_buf(const char *fmt, va_list args)
@@ -247,11 +247,11 @@ static void prepare_error_buf(const char
 }
 
 /* in addition to usual conversion specifiers this accepts reiserfs
-   specific conversion specifiers: 
-   %k to print little endian key, 
-   %K to print cpu key, 
+   specific conversion specifiers:
+   %k to print little endian key,
+   %K to print cpu key,
    %h to print item_head,
-   %t to print directory entry 
+   %t to print directory entry
    %z to print block head (arg must be struct buffer_head *
    %b to print buffer_head
 */
@@ -317,17 +317,17 @@ void reiserfs_debug(struct super_block *
     maintainer-errorid.  Don't bother with reusing errorids, there are
     lots of numbers out there.
 
-    Example: 
-    
+    Example:
+
     reiserfs_panic(
 	p_sb, "reiser-29: reiserfs_new_blocknrs: "
 	"one of search_start or rn(%d) is equal to MAX_B_NUM,"
-	"which means that we are optimizing location based on the bogus location of a temp buffer (%p).", 
+	"which means that we are optimizing location based on the bogus location of a temp buffer (%p).",
 	rn, bh
     );
 
     Regular panic()s sometimes clear the screen before the message can
-    be read, thus the need for the while loop.  
+    be read, thus the need for the while loop.
 
     Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it
     pointless complexity):
fs/reiserfs/procfs.c +1 -1
@@ -645,7 +645,7 @@ int reiserfs_global_version_in_proc(char
  *
  */
 
-/* 
+/*
  * Make Linus happy.
  * Local variables:
  * c-indentation-style: "K&R"
fs/reiserfs/resize.c +3 -3
@@ -1,8 +1,8 @@
-/* 
+/*
  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  */
 
-/* 
+/*
  * Written by Alexander Zarochentcev.
  *
  * The kernel part of the (on-line) reiserfs resizer.
@@ -100,7 +100,7 @@ int reiserfs_resize(struct super_block *
 			memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size);
 
 			/* just in case vfree schedules on us, copy the new
-			 ** pointer into the journal struct before freeing the 
+			 ** pointer into the journal struct before freeing the
 			 ** old one
 			 */
 			node_tmp = jb->bitmaps;
fs/reiserfs/stree.c +4 -4
@@ -77,7 +77,7 @@ inline void copy_item_head(struct item_h
 /* 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 
+   Returns: -1 if key1 < key2
    0 if key1 == key2
    1 if key1 > key2 */
 inline int comp_short_keys(const struct reiserfs_key *le_key,
@@ -890,7 +890,7 @@ static inline int prepare_for_direct_ite
 	}
 	// new file gets truncated
 	if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) {
-		// 
+		//
 		round_len = ROUND_UP(new_file_length);
 		/* this was n_new_file_length < le_ih ... */
 		if (round_len < le_ih_k_offset(le_ih)) {
@@ -1446,7 +1446,7 @@ static int maybe_indirect_to_direct(stru
 	if (atomic_read(&p_s_inode->i_count) > 1 ||
 	    !tail_has_to_be_packed(p_s_inode) ||
 	    !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) {
-		// leave tail in an unformatted node    
+		// leave tail in an unformatted node
 		*p_c_mode = M_SKIP_BALANCING;
 		cut_bytes =
 		    n_block_size - (n_new_file_size & (n_block_size - 1));
@@ -1829,7 +1829,7 @@ int reiserfs_do_truncate(struct reiserfs
 		/* While there are bytes to truncate and previous file item is presented in the tree. */
 
 		/*
-		 ** This loop could take a really long time, and could log 
+		 ** This loop could take a really long time, and could log
 		 ** many more blocks than a transaction can hold.  So, we do a polite
 		 ** journal end here, and if the transaction needs ending, we make
 		 ** sure the file is consistent before ending the current trans
fs/reiserfs/super.c +5 -5
@@ -739,7 +739,7 @@ static int reiserfs_getopt(struct super_
 			   char **opt_arg, unsigned long *bit_flags)
 {
 	char *p;
-	/* foo=bar, 
+	/* foo=bar,
 	   ^   ^  ^
 	   |   |  +-- option_end
 	   |   +-- arg_start
@@ -1280,7 +1280,7 @@ static int read_super_block(struct super
 	}
 	//
 	// ok, reiserfs signature (old or new) found in at the given offset
-	//    
+	//
 	fs_blocksize = sb_blocksize(rs);
 	brelse(bh);
 	sb_set_blocksize(s, fs_blocksize);
@@ -1466,8 +1466,8 @@ static int what_hash(struct super_block 
 		code = find_hash_out(s);
 
 	if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
-		/* detection has found the hash, and we must check against the 
-		 ** mount options 
+		/* detection has found the hash, and we must check against the
+		 ** mount options
 		 */
 		if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
 			reiserfs_warning(s, "reiserfs-2507",
@@ -1499,7 +1499,7 @@ static int what_hash(struct super_block 
 		}
 	}
 
-	/* if we are mounted RW, and we have a new valid hash code, update 
+	/* if we are mounted RW, and we have a new valid hash code, update
 	 ** the super
 	 */
 	if (code != UNSET_HASH &&
fs/reiserfs/tail_conversion.c +1 -1
@@ -46,7 +46,7 @@ int direct2indirect(struct reiserfs_tran
 	/* Set the key to search for the place for new unfm pointer */
 	make_cpu_key(&end_key, inode, tail_offset, TYPE_INDIRECT, 4);
 
-	// FIXME: we could avoid this 
+	// FIXME: we could avoid this
 	if (search_for_position_by_key(sb, &end_key, path) == POSITION_FOUND) {
 		reiserfs_error(sb, "PAP-14030",
 		               "pasted or inserted byte exists in "
include/linux/reiserfs_fs_sb.h +7 -7
@@ -14,7 +14,7 @@ typedef enum {
 } reiserfs_super_block_flags;
 
 /* struct reiserfs_super_block accessors/mutators
- * since this is a disk structure, it will always be in 
+ * since this is a disk structure, it will always be in
  * little endian format. */
 #define sb_block_count(sbp)         (le32_to_cpu((sbp)->s_v1.s_block_count))
 #define set_sb_block_count(sbp,v)   ((sbp)->s_v1.s_block_count = cpu_to_le32(v))
@@ -80,16 +80,16 @@ typedef enum {
 
 /* LOGGING -- */
 
-/* These all interelate for performance.  
+/* These all interelate for performance.
 **
-** If the journal block count is smaller than n transactions, you lose speed. 
+** If the journal block count is smaller than n transactions, you lose speed.
 ** I don't know what n is yet, I'm guessing 8-16.
 **
 ** typical transaction size depends on the application, how often fsync is
-** called, and how many metadata blocks you dirty in a 30 second period.  
+** called, and how many metadata blocks you dirty in a 30 second period.
 ** The more small files (<16k) you use, the larger your transactions will
 ** be.
-** 
+**
 ** If your journal fills faster than dirty buffers get flushed to disk, it must flush them before allowing the journal
 ** to wrap, which slows things down.  If you need high speed meta data updates, the journal should be big enough
 ** to prevent wrapping before dirty meta blocks get to disk.
@@ -239,7 +239,7 @@ struct reiserfs_journal {
 
 	struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS];	/* array of bitmaps to record the deleted blocks */
 	struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE];	/* hash table for real buffer heads in current trans */
-	struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE];	/* hash table for all the real buffer heads in all 
+	struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE];	/* hash table for all the real buffer heads in all
 										   the transactions */
 	struct list_head j_prealloc_list;	/* list of inodes which have preallocated blocks */
 	int j_persistent_trans;
@@ -427,7 +427,7 @@ enum reiserfs_mount_options {
 				   partition will be dealt with in a
 				   manner of 3.5.x */
 
-/* -o hash={tea, rupasov, r5, detect} is meant for properly mounting 
+/* -o hash={tea, rupasov, r5, detect} is meant for properly mounting
 ** reiserfs disks from 3.5.19 or earlier.  99% of the time, this option
 ** is not required.  If the normal autodection code can't determine which
 ** hash to use (because both hashes had the same value for a file)
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#26 lore raw

PATCH 26/40 reiserfs: rename p_s_bh to bh

In reply to [email protected]

This patch is a simple s/p_s_bh/bh/g to the reiserfs code. This is the second in a series of patches to rip out some of the awful variable naming in reiserfs.

---

 fs/reiserfs/fix_node.c      |   88 ++++++++++++++++++++++----------------------
 fs/reiserfs/stree.c         |   62 +++++++++++++++----------------
 include/linux/reiserfs_fs.h |   36 +++++++++---------
 3 files changed, 93 insertions(+), 93 deletions(-)
fs/reiserfs/fix_node.c +44 -44
@@ -1885,7 +1885,7 @@ static int check_balance(int mode,
 /* Check whether parent at the path is the really parent of the current node.*/
 static int get_direct_parent(struct tree_balance *p_s_tb, int n_h)
 {
-	struct buffer_head *p_s_bh;
+	struct buffer_head *bh;
 	struct treepath *p_s_path = p_s_tb->tb_path;
 	int n_position,
 	    n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
@@ -1907,21 +1907,21 @@ static int get_direct_parent(struct tree
 	}
 
 	if (!B_IS_IN_TREE
-	    (p_s_bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1)))
+	    (bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1)))
 		return REPEAT_SEARCH;	/* Parent in the path is not in the tree. */
 
 	if ((n_position =
 	     PATH_OFFSET_POSITION(p_s_path,
-				  n_path_offset - 1)) > B_NR_ITEMS(p_s_bh))
+				  n_path_offset - 1)) > B_NR_ITEMS(bh))
 		return REPEAT_SEARCH;
 
-	if (B_N_CHILD_NUM(p_s_bh, n_position) !=
+	if (B_N_CHILD_NUM(bh, n_position) !=
 	    PATH_OFFSET_PBUFFER(p_s_path, n_path_offset)->b_blocknr)
 		/* Parent in the path is not parent of the current node in the tree. */
 		return REPEAT_SEARCH;
 
-	if (buffer_locked(p_s_bh)) {
-		__wait_on_buffer(p_s_bh);
+	if (buffer_locked(bh)) {
+		__wait_on_buffer(bh);
 		if (FILESYSTEM_CHANGED_TB(p_s_tb))
 			return REPEAT_SEARCH;
 	}
@@ -1941,29 +1941,29 @@ static int get_neighbors(struct tree_bal
 	    n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h + 1);
 	unsigned long n_son_number;
 	struct super_block *sb = p_s_tb->tb_sb;
-	struct buffer_head *p_s_bh;
+	struct buffer_head *bh;
 
 	PROC_INFO_INC(sb, get_neighbors[n_h]);
 
 	if (p_s_tb->lnum[n_h]) {
 		/* We need left neighbor to balance S[n_h]. */
 		PROC_INFO_INC(sb, need_l_neighbor[n_h]);
-		p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
+		bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
 
-		RFALSE(p_s_bh == p_s_tb->FL[n_h] &&
+		RFALSE(bh == p_s_tb->FL[n_h] &&
 		       !PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset),
 		       "PAP-8270: invalid position in the parent");
 
 		n_child_position =
-		    (p_s_bh ==
+		    (bh ==
 		     p_s_tb->FL[n_h]) ? p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->
 								       FL[n_h]);
 		n_son_number = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position);
-		p_s_bh = sb_bread(sb, n_son_number);
-		if (!p_s_bh)
+		bh = sb_bread(sb, n_son_number);
+		if (!bh)
 			return IO_ERROR;
 		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
-			brelse(p_s_bh);
+			brelse(bh);
 			PROC_INFO_INC(sb, get_neighbors_restart[n_h]);
 			return REPEAT_SEARCH;
 		}
@@ -1971,48 +1971,48 @@ static int get_neighbors(struct tree_bal
 		RFALSE(!B_IS_IN_TREE(p_s_tb->FL[n_h]) ||
 		       n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) ||
 		       B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) !=
-		       p_s_bh->b_blocknr, "PAP-8275: invalid parent");
-		RFALSE(!B_IS_IN_TREE(p_s_bh), "PAP-8280: invalid child");
+		       bh->b_blocknr, "PAP-8275: invalid parent");
+		RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child");
 		RFALSE(!n_h &&
-		       B_FREE_SPACE(p_s_bh) !=
-		       MAX_CHILD_SIZE(p_s_bh) -
+		       B_FREE_SPACE(bh) !=
+		       MAX_CHILD_SIZE(bh) -
 		       dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)),
 		       "PAP-8290: invalid child size of left neighbor");
 
 		brelse(p_s_tb->L[n_h]);
-		p_s_tb->L[n_h] = p_s_bh;
+		p_s_tb->L[n_h] = bh;
 	}
 
 	if (p_s_tb->rnum[n_h]) {	/* We need right neighbor to balance S[n_path_offset]. */
 		PROC_INFO_INC(sb, need_r_neighbor[n_h]);
-		p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
+		bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
 
-		RFALSE(p_s_bh == p_s_tb->FR[n_h] &&
+		RFALSE(bh == p_s_tb->FR[n_h] &&
 		       PATH_OFFSET_POSITION(p_s_tb->tb_path,
 					    n_path_offset) >=
-		       B_NR_ITEMS(p_s_bh),
+		       B_NR_ITEMS(bh),
 		       "PAP-8295: invalid position in the parent");
 
 		n_child_position =
-		    (p_s_bh == p_s_tb->FR[n_h]) ? p_s_tb->rkey[n_h] + 1 : 0;
+		    (bh == p_s_tb->FR[n_h]) ? p_s_tb->rkey[n_h] + 1 : 0;
 		n_son_number = B_N_CHILD_NUM(p_s_tb->FR[n_h], n_child_position);
-		p_s_bh = sb_bread(sb, n_son_number);
-		if (!p_s_bh)
+		bh = sb_bread(sb, n_son_number);
+		if (!bh)
 			return IO_ERROR;
 		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
-			brelse(p_s_bh);
+			brelse(bh);
 			PROC_INFO_INC(sb, get_neighbors_restart[n_h]);
 			return REPEAT_SEARCH;
 		}
 		brelse(p_s_tb->R[n_h]);
-		p_s_tb->R[n_h] = p_s_bh;
+		p_s_tb->R[n_h] = bh;
 
 		RFALSE(!n_h
-		       && B_FREE_SPACE(p_s_bh) !=
-		       MAX_CHILD_SIZE(p_s_bh) -
+		       && B_FREE_SPACE(bh) !=
+		       MAX_CHILD_SIZE(bh) -
 		       dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)),
 		       "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
-		       B_FREE_SPACE(p_s_bh), MAX_CHILD_SIZE(p_s_bh),
+		       B_FREE_SPACE(bh), MAX_CHILD_SIZE(bh),
 		       dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)));
 
 	}
@@ -2088,51 +2088,51 @@ static int get_mem_for_virtual_node(stru
 
 #ifdef CONFIG_REISERFS_CHECK
 static void tb_buffer_sanity_check(struct super_block *sb,
-				   struct buffer_head *p_s_bh,
+				   struct buffer_head *bh,
 				   const char *descr, int level)
 {
-	if (p_s_bh) {
-		if (atomic_read(&(p_s_bh->b_count)) <= 0) {
+	if (bh) {
+		if (atomic_read(&(bh->b_count)) <= 0) {
 
 			reiserfs_panic(sb, "jmacd-1", "negative or zero "
 			               "reference counter for buffer %s[%d] "
-				       "(%b)", descr, level, p_s_bh);
+				       "(%b)", descr, level, bh);
 		}
 
-		if (!buffer_uptodate(p_s_bh)) {
+		if (!buffer_uptodate(bh)) {
 			reiserfs_panic(sb, "jmacd-2", "buffer is not up "
 			               "to date %s[%d] (%b)",
-				       descr, level, p_s_bh);
+				       descr, level, bh);
 		}
 
-		if (!B_IS_IN_TREE(p_s_bh)) {
+		if (!B_IS_IN_TREE(bh)) {
 			reiserfs_panic(sb, "jmacd-3", "buffer is not "
 			               "in tree %s[%d] (%b)",
-				       descr, level, p_s_bh);
+				       descr, level, bh);
 		}
 
-		if (p_s_bh->b_bdev != sb->s_bdev) {
+		if (bh->b_bdev != sb->s_bdev) {
 			reiserfs_panic(sb, "jmacd-4", "buffer has wrong "
 			               "device %s[%d] (%b)",
-				       descr, level, p_s_bh);
+				       descr, level, bh);
 		}
 
-		if (p_s_bh->b_size != sb->s_blocksize) {
+		if (bh->b_size != sb->s_blocksize) {
 			reiserfs_panic(sb, "jmacd-5", "buffer has wrong "
 			               "blocksize %s[%d] (%b)",
-				       descr, level, p_s_bh);
+				       descr, level, bh);
 		}
 
-		if (p_s_bh->b_blocknr > SB_BLOCK_COUNT(sb)) {
+		if (bh->b_blocknr > SB_BLOCK_COUNT(sb)) {
 			reiserfs_panic(sb, "jmacd-6", "buffer block "
 			               "number too high %s[%d] (%b)",
-				       descr, level, p_s_bh);
+				       descr, level, bh);
 		}
 	}
 }
 #else
 static void tb_buffer_sanity_check(struct super_block *sb,
-				   struct buffer_head *p_s_bh,
+				   struct buffer_head *bh,
 				   const char *descr, int level)
 {;
 }
fs/reiserfs/stree.c +31 -31

175 lines not on this page · raw message

include/linux/reiserfs_fs.h +18 -18
@@ -731,25 +731,25 @@ struct block_head {
 #define DISK_LEAF_NODE_LEVEL  1	/* Leaf node level. */
 
 /* Given the buffer head of a formatted node, resolve to the block head of that node. */
-#define B_BLK_HEAD(p_s_bh)            ((struct block_head *)((p_s_bh)->b_data))
+#define B_BLK_HEAD(bh)            ((struct block_head *)((bh)->b_data))
 /* Number of items that are in buffer. */
-#define B_NR_ITEMS(p_s_bh)            (blkh_nr_item(B_BLK_HEAD(p_s_bh)))
-#define B_LEVEL(p_s_bh)               (blkh_level(B_BLK_HEAD(p_s_bh)))
-#define B_FREE_SPACE(p_s_bh)          (blkh_free_space(B_BLK_HEAD(p_s_bh)))
-
-#define PUT_B_NR_ITEMS(p_s_bh,val)    do { set_blkh_nr_item(B_BLK_HEAD(p_s_bh),val); } while (0)
-#define PUT_B_LEVEL(p_s_bh,val)       do { set_blkh_level(B_BLK_HEAD(p_s_bh),val); } while (0)
-#define PUT_B_FREE_SPACE(p_s_bh,val)  do { set_blkh_free_space(B_BLK_HEAD(p_s_bh),val); } while (0)
+#define B_NR_ITEMS(bh)            (blkh_nr_item(B_BLK_HEAD(bh)))
+#define B_LEVEL(bh)               (blkh_level(B_BLK_HEAD(bh)))
+#define B_FREE_SPACE(bh)          (blkh_free_space(B_BLK_HEAD(bh)))
+
+#define PUT_B_NR_ITEMS(bh,val)    do { set_blkh_nr_item(B_BLK_HEAD(bh),val); } while (0)
+#define PUT_B_LEVEL(bh,val)       do { set_blkh_level(B_BLK_HEAD(bh),val); } while (0)
+#define PUT_B_FREE_SPACE(bh,val)  do { set_blkh_free_space(B_BLK_HEAD(bh),val); } while (0)
 
 /* Get right delimiting key. -- little endian */
-#define B_PRIGHT_DELIM_KEY(p_s_bh)   (&(blk_right_delim_key(B_BLK_HEAD(p_s_bh))))
+#define B_PRIGHT_DELIM_KEY(bh)   (&(blk_right_delim_key(B_BLK_HEAD(bh))))
 
 /* Does the buffer contain a disk leaf. */
-#define B_IS_ITEMS_LEVEL(p_s_bh)     (B_LEVEL(p_s_bh) == DISK_LEAF_NODE_LEVEL)
+#define B_IS_ITEMS_LEVEL(bh)     (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL)
 
 /* Does the buffer contain a disk internal node */
-#define B_IS_KEYS_LEVEL(p_s_bh)      (B_LEVEL(p_s_bh) > DISK_LEAF_NODE_LEVEL \
-                                            && B_LEVEL(p_s_bh) <= MAX_HEIGHT)
+#define B_IS_KEYS_LEVEL(bh)      (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \
+                                            && B_LEVEL(bh) <= MAX_HEIGHT)
 
 /***************************************************************************/
 /*                             STAT DATA                                   */
@@ -1099,12 +1099,12 @@ struct disk_child {
 #define put_dc_size(dc_p, val)   do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)
 
 /* Get disk child by buffer header and position in the tree node. */
-#define B_N_CHILD(p_s_bh,n_pos)  ((struct disk_child *)\
-((p_s_bh)->b_data+BLKH_SIZE+B_NR_ITEMS(p_s_bh)*KEY_SIZE+DC_SIZE*(n_pos)))
+#define B_N_CHILD(bh,n_pos)  ((struct disk_child *)\
+((bh)->b_data+BLKH_SIZE+B_NR_ITEMS(bh)*KEY_SIZE+DC_SIZE*(n_pos)))
 
 /* Get disk child number by buffer header and position in the tree node. */
-#define B_N_CHILD_NUM(p_s_bh,n_pos) (dc_block_number(B_N_CHILD(p_s_bh,n_pos)))
-#define PUT_B_N_CHILD_NUM(p_s_bh,n_pos, val) (put_dc_block_number(B_N_CHILD(p_s_bh,n_pos), val ))
+#define B_N_CHILD_NUM(bh,n_pos) (dc_block_number(B_N_CHILD(bh,n_pos)))
+#define PUT_B_N_CHILD_NUM(bh,n_pos, val) (put_dc_block_number(B_N_CHILD(bh,n_pos), val ))
 
  /* maximal value of field child_size in structure disk_child */
  /* child size is the combined size of all items and their headers */
@@ -1827,7 +1827,7 @@ int search_by_key(struct super_block *, 
 int search_for_position_by_key(struct super_block *sb,
 			       const struct cpu_key *p_s_cpu_key,
 			       struct treepath *p_s_search_path);
-extern void decrement_bcount(struct buffer_head *p_s_bh);
+extern void decrement_bcount(struct buffer_head *bh);
 void decrement_counters_in_path(struct treepath *p_s_search_path);
 void pathrelse(struct treepath *p_s_search_path);
 int reiserfs_check_path(struct treepath *p);
@@ -1972,7 +1972,7 @@ int reiserfs_global_version_in_proc(char
 #define PROC_INFO_MAX( sb, field, value ) VOID_V
 #define PROC_INFO_INC( sb, field ) VOID_V
 #define PROC_INFO_ADD( sb, field, val ) VOID_V
-#define PROC_INFO_BH_STAT( sb, p_s_bh, n_node_level ) VOID_V
+#define PROC_INFO_BH_STAT( sb, bh, n_node_level ) VOID_V
 #endif
 
 /* dir.c */
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#27 lore raw

PATCH 27/40 reiserfs: rename p_s_inode to inode

In reply to [email protected]

This patch is a simple s/p_s_inode/inode/g to the reiserfs code. This is the third in a series of patches to rip out some of the awful variable naming in reiserfs.

---

 fs/reiserfs/file.c            |   16 +++----
 fs/reiserfs/inode.c           |   42 +++++++++---------
 fs/reiserfs/stree.c           |   96 +++++++++++++++++++++---------------------
 fs/reiserfs/tail_conversion.c |   16 +++----
 include/linux/reiserfs_fs.h   |    4 -
 5 files changed, 87 insertions(+), 87 deletions(-)
fs/reiserfs/file.c +8 -8
@@ -137,17 +137,17 @@ static void reiserfs_vfs_truncate_file(s
 static int reiserfs_sync_file(struct file *p_s_filp,
 			      struct dentry *p_s_dentry, int datasync)
 {
-	struct inode *p_s_inode = p_s_dentry->d_inode;
+	struct inode *inode = p_s_dentry->d_inode;
 	int n_err;
 	int barrier_done;
 
-	BUG_ON(!S_ISREG(p_s_inode->i_mode));
-	n_err = sync_mapping_buffers(p_s_inode->i_mapping);
-	reiserfs_write_lock(p_s_inode->i_sb);
-	barrier_done = reiserfs_commit_for_inode(p_s_inode);
-	reiserfs_write_unlock(p_s_inode->i_sb);
-	if (barrier_done != 1 && reiserfs_barrier_flush(p_s_inode->i_sb))
-		blkdev_issue_flush(p_s_inode->i_sb->s_bdev, NULL);
+	BUG_ON(!S_ISREG(inode->i_mode));
+	n_err = sync_mapping_buffers(inode->i_mapping);
+	reiserfs_write_lock(inode->i_sb);
+	barrier_done = reiserfs_commit_for_inode(inode);
+	reiserfs_write_unlock(inode->i_sb);
+	if (barrier_done != 1 && reiserfs_barrier_flush(inode->i_sb))
+		blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
 	if (barrier_done < 0)
 		return barrier_done;
 	return (n_err < 0) ? -EIO : 0;
fs/reiserfs/inode.c +21 -21

120 lines not on this page · raw message

fs/reiserfs/stree.c +48 -48

270 lines not on this page · raw message

fs/reiserfs/tail_conversion.c +8 -8
@@ -170,12 +170,12 @@ void reiserfs_unmap_buffer(struct buffer
    what we expect from it (number of cut bytes). But when tail remains
    in the unformatted node, we set mode to SKIP_BALANCING and unlock
    inode */
-int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, struct page *page, struct treepath *p_s_path,	/* path to the indirect item. */
+int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *inode, struct page *page, struct treepath *p_s_path,	/* path to the indirect item. */
 		    const struct cpu_key *p_s_item_key,	/* Key to look for unformatted node pointer to be cut. */
 		    loff_t n_new_file_size,	/* New file size. */
 		    char *p_c_mode)
 {
-	struct super_block *sb = p_s_inode->i_sb;
+	struct super_block *sb = inode->i_sb;
 	struct item_head s_ih;
 	unsigned long n_block_size = sb->s_blocksize;
 	char *tail;
@@ -193,7 +193,7 @@ int indirect2direct(struct reiserfs_tran
 	copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
 
 	tail_len = (n_new_file_size & (n_block_size - 1));
-	if (get_inode_sd_version(p_s_inode) == STAT_DATA_V2)
+	if (get_inode_sd_version(inode) == STAT_DATA_V2)
 		round_tail_len = ROUND_UP(tail_len);
 	else
 		round_tail_len = tail_len;
@@ -228,7 +228,7 @@ int indirect2direct(struct reiserfs_tran
 	}
 
 	/* Set direct item header to insert. */
-	make_le_item_head(&s_ih, NULL, get_inode_item_key_version(p_s_inode),
+	make_le_item_head(&s_ih, NULL, get_inode_item_key_version(inode),
 			  pos1 + 1, TYPE_DIRECT, round_tail_len,
 			  0xffff /*ih_free_space */ );
 
@@ -244,7 +244,7 @@ int indirect2direct(struct reiserfs_tran
 	set_cpu_key_k_type(&key, TYPE_DIRECT);
 	key.key_length = 4;
 	/* Insert tail as new direct item in the tree */
-	if (reiserfs_insert_item(th, p_s_path, &key, &s_ih, p_s_inode,
+	if (reiserfs_insert_item(th, p_s_path, &key, &s_ih, inode,
 				 tail ? tail : NULL) < 0) {
 		/* No disk memory. So we can not convert last unformatted node
 		   to the direct item.  In this case we used to adjust
@@ -258,7 +258,7 @@ int indirect2direct(struct reiserfs_tran
 	kunmap(page);
 
 	/* make sure to get the i_blocks changes from reiserfs_insert_item */
-	reiserfs_update_sd(th, p_s_inode);
+	reiserfs_update_sd(th, inode);
 
 	// note: we have now the same as in above direct2indirect
 	// conversion: there are two keys which have matching first three
@@ -269,8 +269,8 @@ int indirect2direct(struct reiserfs_tran
 	*p_c_mode = M_CUT;
 
 	/* we store position of first direct item in the in-core inode */
-	//mark_file_with_tail (p_s_inode, pos1 + 1);
-	REISERFS_I(p_s_inode)->i_first_direct_byte = pos1 + 1;
+	//mark_file_with_tail (inode, pos1 + 1);
+	REISERFS_I(inode)->i_first_direct_byte = pos1 + 1;
 
 	return n_block_size - round_tail_len;
 }
include/linux/reiserfs_fs.h +2 -2
@@ -1859,9 +1859,9 @@ int reiserfs_delete_item(struct reiserfs
 void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
 				struct inode *inode, struct reiserfs_key *key);
 int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
-			   struct inode *p_s_inode);
+			   struct inode *inode);
 int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
-			 struct inode *p_s_inode, struct page *,
+			 struct inode *inode, struct page *,
 			 int update_timestamps);
 
 #define i_block_size(inode) ((inode)->i_sb->s_blocksize)
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#28 lore raw

PATCH 28/40 reiserfs: rename p_s_tb to tb

In reply to [email protected]

This patch is a simple s/p_s_tb/tb/g to the reiserfs code. This is the fourth in a series of patches to rip out some of the awful variable naming in reiserfs.

---

 fs/reiserfs/fix_node.c      |  446 ++++++++++++++++++++++----------------------
 fs/reiserfs/stree.c         |   20 -
 include/linux/reiserfs_fs.h |    2 
 3 files changed, 234 insertions(+), 234 deletions(-)
fs/reiserfs/fix_node.c +223 -223
@@ -749,26 +749,26 @@ else \
 		  -1, -1);\
 }
 
-static void free_buffers_in_tb(struct tree_balance *p_s_tb)
+static void free_buffers_in_tb(struct tree_balance *tb)
 {
 	int n_counter;
 
-	pathrelse(p_s_tb->tb_path);
+	pathrelse(tb->tb_path);
 
 	for (n_counter = 0; n_counter < MAX_HEIGHT; n_counter++) {
-		brelse(p_s_tb->L[n_counter]);
-		brelse(p_s_tb->R[n_counter]);
-		brelse(p_s_tb->FL[n_counter]);
-		brelse(p_s_tb->FR[n_counter]);
-		brelse(p_s_tb->CFL[n_counter]);
-		brelse(p_s_tb->CFR[n_counter]);
-
-		p_s_tb->L[n_counter] = NULL;
-		p_s_tb->R[n_counter] = NULL;
-		p_s_tb->FL[n_counter] = NULL;
-		p_s_tb->FR[n_counter] = NULL;
-		p_s_tb->CFL[n_counter] = NULL;
-		p_s_tb->CFR[n_counter] = NULL;
+		brelse(tb->L[n_counter]);
+		brelse(tb->R[n_counter]);
+		brelse(tb->FL[n_counter]);
+		brelse(tb->FR[n_counter]);
+		brelse(tb->CFL[n_counter]);
+		brelse(tb->CFR[n_counter]);
+
+		tb->L[n_counter] = NULL;
+		tb->R[n_counter] = NULL;
+		tb->FL[n_counter] = NULL;
+		tb->FR[n_counter] = NULL;
+		tb->CFL[n_counter] = NULL;
+		tb->CFR[n_counter] = NULL;
 	}
 }
 
@@ -778,14 +778,14 @@ static void free_buffers_in_tb(struct tr
  *	        NO_DISK_SPACE - no disk space.
  */
 /* The function is NOT SCHEDULE-SAFE! */
-static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h)
+static int get_empty_nodes(struct tree_balance *tb, int n_h)
 {
 	struct buffer_head *p_s_new_bh,
-	    *p_s_Sh = PATH_H_PBUFFER(p_s_tb->tb_path, n_h);
+	    *p_s_Sh = PATH_H_PBUFFER(tb->tb_path, n_h);
 	b_blocknr_t *p_n_blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, };
 	int n_counter, n_number_of_freeblk, n_amount_needed,	/* number of needed empty blocks */
 	 n_retval = CARRY_ON;
-	struct super_block *sb = p_s_tb->tb_sb;
+	struct super_block *sb = tb->tb_sb;
 
 	/* number_of_freeblk is the number of empty blocks which have been
 	   acquired for use by the balancing algorithm minus the number of
@@ -803,15 +803,15 @@ static int get_empty_nodes(struct tree_b
 	   the analysis or 0 if not restarted, then subtract the amount needed
 	   by all of the levels of the tree below n_h. */
 	/* blknum includes S[n_h], so we subtract 1 in this calculation */
-	for (n_counter = 0, n_number_of_freeblk = p_s_tb->cur_blknum;
+	for (n_counter = 0, n_number_of_freeblk = tb->cur_blknum;
 	     n_counter < n_h; n_counter++)
 		n_number_of_freeblk -=
-		    (p_s_tb->blknum[n_counter]) ? (p_s_tb->blknum[n_counter] -
+		    (tb->blknum[n_counter]) ? (tb->blknum[n_counter] -
 						   1) : 0;
 
 	/* Allocate missing empty blocks. */
 	/* if p_s_Sh == 0  then we are getting a new root */
-	n_amount_needed = (p_s_Sh) ? (p_s_tb->blknum[n_h] - 1) : 1;
+	n_amount_needed = (p_s_Sh) ? (tb->blknum[n_h] - 1) : 1;
 	/*  Amount_needed = the amount that we need more than the amount that we have. */
 	if (n_amount_needed > n_number_of_freeblk)
 		n_amount_needed -= n_number_of_freeblk;
@@ -819,7 +819,7 @@ static int get_empty_nodes(struct tree_b
 		return CARRY_ON;
 
 	/* No need to check quota - is not allocated for blocks used for formatted nodes */
-	if (reiserfs_new_form_blocknrs(p_s_tb, a_n_blocknrs,
+	if (reiserfs_new_form_blocknrs(tb, a_n_blocknrs,
 				       n_amount_needed) == NO_DISK_SPACE)
 		return NO_DISK_SPACE;
 
@@ -838,14 +838,14 @@ static int get_empty_nodes(struct tree_b
 		       p_s_new_bh);
 
 		/* Put empty buffers into the array. */
-		RFALSE(p_s_tb->FEB[p_s_tb->cur_blknum],
+		RFALSE(tb->FEB[tb->cur_blknum],
 		       "PAP-8141: busy slot for new buffer");
 
 		set_buffer_journal_new(p_s_new_bh);
-		p_s_tb->FEB[p_s_tb->cur_blknum++] = p_s_new_bh;
+		tb->FEB[tb->cur_blknum++] = p_s_new_bh;
 	}
 
-	if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(p_s_tb))
+	if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb))
 		n_retval = REPEAT_SEARCH;
 
 	return n_retval;
@@ -894,33 +894,33 @@ static int get_rfree(struct tree_balance
 }
 
 /* Check whether left neighbor is in memory. */
-static int is_left_neighbor_in_cache(struct tree_balance *p_s_tb, int n_h)
+static int is_left_neighbor_in_cache(struct tree_balance *tb, int n_h)
 {
 	struct buffer_head *p_s_father, *left;
-	struct super_block *sb = p_s_tb->tb_sb;
+	struct super_block *sb = tb->tb_sb;
 	b_blocknr_t n_left_neighbor_blocknr;
 	int n_left_neighbor_position;
 
-	if (!p_s_tb->FL[n_h])	/* Father of the left neighbor does not exist. */
+	if (!tb->FL[n_h])	/* Father of the left neighbor does not exist. */
 		return 0;
 
 	/* Calculate father of the node to be balanced. */
-	p_s_father = PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1);
+	p_s_father = PATH_H_PBUFFER(tb->tb_path, n_h + 1);
 
 	RFALSE(!p_s_father ||
 	       !B_IS_IN_TREE(p_s_father) ||
-	       !B_IS_IN_TREE(p_s_tb->FL[n_h]) ||
+	       !B_IS_IN_TREE(tb->FL[n_h]) ||
 	       !buffer_uptodate(p_s_father) ||
-	       !buffer_uptodate(p_s_tb->FL[n_h]),
+	       !buffer_uptodate(tb->FL[n_h]),
 	       "vs-8165: F[h] (%b) or FL[h] (%b) is invalid",
-	       p_s_father, p_s_tb->FL[n_h]);
+	       p_s_father, tb->FL[n_h]);
 
 	/* Get position of the pointer to the left neighbor into the left father. */
-	n_left_neighbor_position = (p_s_father == p_s_tb->FL[n_h]) ?
-	    p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->FL[n_h]);
+	n_left_neighbor_position = (p_s_father == tb->FL[n_h]) ?
+	    tb->lkey[n_h] : B_NR_ITEMS(tb->FL[n_h]);
 	/* Get left neighbor block number. */
 	n_left_neighbor_blocknr =
-	    B_N_CHILD_NUM(p_s_tb->FL[n_h], n_left_neighbor_position);
+	    B_N_CHILD_NUM(tb->FL[n_h], n_left_neighbor_position);
 	/* Look for the left neighbor in the cache. */
 	if ((left = sb_find_get_block(sb, n_left_neighbor_blocknr))) {
 
@@ -951,14 +951,14 @@ static void decrement_key(struct cpu_key
  		SCHEDULE_OCCURRED - schedule occurred while the function worked;
  *	        CARRY_ON         - schedule didn't occur while the function worked;
  */
-static int get_far_parent(struct tree_balance *p_s_tb,
+static int get_far_parent(struct tree_balance *tb,
 			  int n_h,
 			  struct buffer_head **pp_s_father,
 			  struct buffer_head **pp_s_com_father, char c_lr_par)
 {
 	struct buffer_head *p_s_parent;
 	INITIALIZE_PATH(s_path_to_neighbor_father);
-	struct treepath *p_s_path = p_s_tb->tb_path;
+	struct treepath *p_s_path = tb->tb_path;
 	struct cpu_key s_lr_father_key;
 	int n_counter,
 	    n_position = INT_MAX,
@@ -1003,9 +1003,9 @@ static int get_far_parent(struct tree_ba
 	if (n_counter == FIRST_PATH_ELEMENT_OFFSET) {
 		/* Check whether first buffer in the path is the root of the tree. */
 		if (PATH_OFFSET_PBUFFER
-		    (p_s_tb->tb_path,
+		    (tb->tb_path,
 		     FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
-		    SB_ROOT_BLOCK(p_s_tb->tb_sb)) {
+		    SB_ROOT_BLOCK(tb->tb_sb)) {
 			*pp_s_father = *pp_s_com_father = NULL;
 			return CARRY_ON;
 		}
@@ -1020,7 +1020,7 @@ static int get_far_parent(struct tree_ba
 
 	if (buffer_locked(*pp_s_com_father)) {
 		__wait_on_buffer(*pp_s_com_father);
-		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
+		if (FILESYSTEM_CHANGED_TB(tb)) {
 			brelse(*pp_s_com_father);
 			return REPEAT_SEARCH;
 		}
@@ -1033,9 +1033,9 @@ static int get_far_parent(struct tree_ba
 	le_key2cpu_key(&s_lr_father_key,
 		       B_N_PDELIM_KEY(*pp_s_com_father,
 				      (c_lr_par ==
-				       LEFT_PARENTS) ? (p_s_tb->lkey[n_h - 1] =
+				       LEFT_PARENTS) ? (tb->lkey[n_h - 1] =
 							n_position -
-							1) : (p_s_tb->rkey[n_h -
+							1) : (tb->rkey[n_h -
 									   1] =
 							      n_position)));
 
@@ -1043,12 +1043,12 @@ static int get_far_parent(struct tree_ba
 		decrement_key(&s_lr_father_key);
 
 	if (search_by_key
-	    (p_s_tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father,
+	    (tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father,
 	     n_h + 1) == IO_ERROR)
 		// path is released
 		return IO_ERROR;
 
-	if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
+	if (FILESYSTEM_CHANGED_TB(tb)) {
 		pathrelse(&s_path_to_neighbor_father);
 		brelse(*pp_s_com_father);
 		return REPEAT_SEARCH;
@@ -1073,24 +1073,24 @@ static int get_far_parent(struct tree_ba
  * Returns:	SCHEDULE_OCCURRED - schedule occurred while the function worked;
  *	        CARRY_ON - schedule didn't occur while the function worked;
  */
-static int get_parents(struct tree_balance *p_s_tb, int n_h)
+static int get_parents(struct tree_balance *tb, int n_h)
 {
-	struct treepath *p_s_path = p_s_tb->tb_path;
+	struct treepath *p_s_path = tb->tb_path;
 	int n_position,
 	    n_ret_value,
-	    n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
+	    n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h);
 	struct buffer_head *p_s_curf, *p_s_curcf;
 
 	/* Current node is the root of the tree or will be root of the tree */
 	if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
 		/* The root can not have parents.
 		   Release nodes which previously were obtained as parents of the current node neighbors. */
-		brelse(p_s_tb->FL[n_h]);
-		brelse(p_s_tb->CFL[n_h]);
-		brelse(p_s_tb->FR[n_h]);
-		brelse(p_s_tb->CFR[n_h]);
-		p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] =
-		    p_s_tb->CFR[n_h] = NULL;
+		brelse(tb->FL[n_h]);
+		brelse(tb->CFL[n_h]);
+		brelse(tb->FR[n_h]);
+		brelse(tb->CFR[n_h]);
+		tb->FL[n_h] = tb->CFL[n_h] = tb->FR[n_h] =
+		    tb->CFR[n_h] = NULL;
 		return CARRY_ON;
 	}
 
@@ -1102,22 +1102,22 @@ static int get_parents(struct tree_balan
 		    PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1);
 		get_bh(p_s_curf);
 		get_bh(p_s_curf);
-		p_s_tb->lkey[n_h] = n_position - 1;
+		tb->lkey[n_h] = n_position - 1;
 	} else {
 		/* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node.
 		   Calculate current common parent of L[n_path_offset] and the current node. Note that
 		   CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset].
 		   Calculate lkey[n_path_offset]. */
-		if ((n_ret_value = get_far_parent(p_s_tb, n_h + 1, &p_s_curf,
+		if ((n_ret_value = get_far_parent(tb, n_h + 1, &p_s_curf,
 						  &p_s_curcf,
 						  LEFT_PARENTS)) != CARRY_ON)
 			return n_ret_value;
 	}
 
-	brelse(p_s_tb->FL[n_h]);
-	p_s_tb->FL[n_h] = p_s_curf;	/* New initialization of FL[n_h]. */
-	brelse(p_s_tb->CFL[n_h]);
-	p_s_tb->CFL[n_h] = p_s_curcf;	/* New initialization of CFL[n_h]. */
+	brelse(tb->FL[n_h]);
+	tb->FL[n_h] = p_s_curf;	/* New initialization of FL[n_h]. */
+	brelse(tb->CFL[n_h]);
+	tb->CFL[n_h] = p_s_curcf;	/* New initialization of CFL[n_h]. */
 
 	RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
 	       (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)),
@@ -1131,7 +1131,7 @@ static int get_parents(struct tree_balan
    Calculate current common parent of R[n_h] and current node. Note that CFR[n_h]
    not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */
 		if ((n_ret_value =
-		     get_far_parent(p_s_tb, n_h + 1, &p_s_curf, &p_s_curcf,
+		     get_far_parent(tb, n_h + 1, &p_s_curf, &p_s_curcf,
 				    RIGHT_PARENTS)) != CARRY_ON)
 			return n_ret_value;
 	} else {
@@ -1141,14 +1141,14 @@ static int get_parents(struct tree_balan
 		    PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1);
 		get_bh(p_s_curf);
 		get_bh(p_s_curf);
-		p_s_tb->rkey[n_h] = n_position;
+		tb->rkey[n_h] = n_position;
 	}
 
-	brelse(p_s_tb->FR[n_h]);
-	p_s_tb->FR[n_h] = p_s_curf;	/* New initialization of FR[n_path_offset]. */
+	brelse(tb->FR[n_h]);
+	tb->FR[n_h] = p_s_curf;	/* New initialization of FR[n_path_offset]. */
 
-	brelse(p_s_tb->CFR[n_h]);
-	p_s_tb->CFR[n_h] = p_s_curcf;	/* New initialization of CFR[n_path_offset]. */
+	brelse(tb->CFR[n_h]);
+	tb->CFR[n_h] = p_s_curcf;	/* New initialization of CFR[n_path_offset]. */
 
 	RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
 	       (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)),
@@ -1883,12 +1883,12 @@ static int check_balance(int mode,
 }
 
 /* Check whether parent at the path is the really parent of the current node.*/
-static int get_direct_parent(struct tree_balance *p_s_tb, int n_h)
+static int get_direct_parent(struct tree_balance *tb, int n_h)
 {
 	struct buffer_head *bh;
-	struct treepath *p_s_path = p_s_tb->tb_path;
+	struct treepath *p_s_path = tb->tb_path;
 	int n_position,
-	    n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
+	    n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h);
 
 	/* We are in the root or in the new root. */
 	if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
@@ -1897,7 +1897,7 @@ static int get_direct_parent(struct tree
 		       "PAP-8260: invalid offset in the path");
 
 		if (PATH_OFFSET_PBUFFER(p_s_path, FIRST_PATH_ELEMENT_OFFSET)->
-		    b_blocknr == SB_ROOT_BLOCK(p_s_tb->tb_sb)) {
+		    b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) {
 			/* Root is not changed. */
 			PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1) = NULL;
 			PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1) = 0;
@@ -1922,7 +1922,7 @@ static int get_direct_parent(struct tree
 
 	if (buffer_locked(bh)) {
 		__wait_on_buffer(bh);
-		if (FILESYSTEM_CHANGED_TB(p_s_tb))
+		if (FILESYSTEM_CHANGED_TB(tb))
 			return REPEAT_SEARCH;
 	}
 
@@ -1935,85 +1935,85 @@ static int get_direct_parent(struct tree
  * Returns:	SCHEDULE_OCCURRED - schedule occurred while the function worked;
  *	        CARRY_ON - schedule didn't occur while the function worked;
  */
-static int get_neighbors(struct tree_balance *p_s_tb, int n_h)
+static int get_neighbors(struct tree_balance *tb, int n_h)
 {
 	int n_child_position,
-	    n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h + 1);
+	    n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h + 1);
 	unsigned long n_son_number;
-	struct super_block *sb = p_s_tb->tb_sb;
+	struct super_block *sb = tb->tb_sb;
 	struct buffer_head *bh;
 
 	PROC_INFO_INC(sb, get_neighbors[n_h]);
 
-	if (p_s_tb->lnum[n_h]) {
+	if (tb->lnum[n_h]) {
 		/* We need left neighbor to balance S[n_h]. */
 		PROC_INFO_INC(sb, need_l_neighbor[n_h]);
-		bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
+		bh = PATH_OFFSET_PBUFFER(tb->tb_path, n_path_offset);
 
-		RFALSE(bh == p_s_tb->FL[n_h] &&
-		       !PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset),
+		RFALSE(bh == tb->FL[n_h] &&
+		       !PATH_OFFSET_POSITION(tb->tb_path, n_path_offset),
 		       "PAP-8270: invalid position in the parent");
 
 		n_child_position =
 		    (bh ==
-		     p_s_tb->FL[n_h]) ? p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->
+		     tb->FL[n_h]) ? tb->lkey[n_h] : B_NR_ITEMS(tb->
 								       FL[n_h]);
-		n_son_number = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position);
+		n_son_number = B_N_CHILD_NUM(tb->FL[n_h], n_child_position);
 		bh = sb_bread(sb, n_son_number);
 		if (!bh)
 			return IO_ERROR;
-		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
+		if (FILESYSTEM_CHANGED_TB(tb)) {
 			brelse(bh);
 			PROC_INFO_INC(sb, get_neighbors_restart[n_h]);
 			return REPEAT_SEARCH;
 		}
 
-		RFALSE(!B_IS_IN_TREE(p_s_tb->FL[n_h]) ||
-		       n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) ||
-		       B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) !=
+		RFALSE(!B_IS_IN_TREE(tb->FL[n_h]) ||
+		       n_child_position > B_NR_ITEMS(tb->FL[n_h]) ||
+		       B_N_CHILD_NUM(tb->FL[n_h], n_child_position) !=
 		       bh->b_blocknr, "PAP-8275: invalid parent");
 		RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child");
 		RFALSE(!n_h &&
 		       B_FREE_SPACE(bh) !=
 		       MAX_CHILD_SIZE(bh) -
-		       dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)),
+		       dc_size(B_N_CHILD(tb->FL[0], n_child_position)),
 		       "PAP-8290: invalid child size of left neighbor");
 
-		brelse(p_s_tb->L[n_h]);
-		p_s_tb->L[n_h] = bh;
+		brelse(tb->L[n_h]);
+		tb->L[n_h] = bh;
 	}
 
-	if (p_s_tb->rnum[n_h]) {	/* We need right neighbor to balance S[n_path_offset]. */
+	if (tb->rnum[n_h]) {	/* We need right neighbor to balance S[n_path_offset]. */
 		PROC_INFO_INC(sb, need_r_neighbor[n_h]);
-		bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
+		bh = PATH_OFFSET_PBUFFER(tb->tb_path, n_path_offset);
 
-		RFALSE(bh == p_s_tb->FR[n_h] &&
-		       PATH_OFFSET_POSITION(p_s_tb->tb_path,
+		RFALSE(bh == tb->FR[n_h] &&
+		       PATH_OFFSET_POSITION(tb->tb_path,
 					    n_path_offset) >=
 		       B_NR_ITEMS(bh),
 		       "PAP-8295: invalid position in the parent");
 
 		n_child_position =
-		    (bh == p_s_tb->FR[n_h]) ? p_s_tb->rkey[n_h] + 1 : 0;
-		n_son_number = B_N_CHILD_NUM(p_s_tb->FR[n_h], n_child_position);
+		    (bh == tb->FR[n_h]) ? tb->rkey[n_h] + 1 : 0;
+		n_son_number = B_N_CHILD_NUM(tb->FR[n_h], n_child_position);
 		bh = sb_bread(sb, n_son_number);
 		if (!bh)
 			return IO_ERROR;
-		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
+		if (FILESYSTEM_CHANGED_TB(tb)) {
 			brelse(bh);
 			PROC_INFO_INC(sb, get_neighbors_restart[n_h]);
 			return REPEAT_SEARCH;
 		}
-		brelse(p_s_tb->R[n_h]);
-		p_s_tb->R[n_h] = bh;
+		brelse(tb->R[n_h]);
+		tb->R[n_h] = bh;
 
 		RFALSE(!n_h
 		       && B_FREE_SPACE(bh) !=
 		       MAX_CHILD_SIZE(bh) -
-		       dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)),
+		       dc_size(B_N_CHILD(tb->FR[0], n_child_position)),
 		       "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
 		       B_FREE_SPACE(bh), MAX_CHILD_SIZE(bh),
-		       dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)));
+		       dc_size(B_N_CHILD(tb->FR[0], n_child_position)));
 
 	}
 	return CARRY_ON;
@@ -2143,7 +2143,7 @@ static int clear_all_dirty_bits(struct s
 	return reiserfs_prepare_for_journal(s, bh, 0);
 }
 
-static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
+static int wait_tb_buffers_until_unlocked(struct tree_balance *tb)
 {
 	struct buffer_head *locked;
 #ifdef CONFIG_REISERFS_CHECK
@@ -2155,95 +2155,95 @@ static int wait_tb_buffers_until_unlocke
 
 		locked = NULL;
 
-		for (i = p_s_tb->tb_path->path_length;
+		for (i = tb->tb_path->path_length;
 		     !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) {
-			if (PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) {
+			if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) {
 				/* if I understand correctly, we can only be sure the last buffer
 				 ** in the path is in the tree --clm
 				 */
 #ifdef CONFIG_REISERFS_CHECK
-				if (PATH_PLAST_BUFFER(p_s_tb->tb_path) ==
-				    PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
+				if (PATH_PLAST_BUFFER(tb->tb_path) ==
+				    PATH_OFFSET_PBUFFER(tb->tb_path, i)) {
+					tb_buffer_sanity_check(tb->tb_sb,
 							       PATH_OFFSET_PBUFFER
-							       (p_s_tb->tb_path,
+							       (tb->tb_path,
 								i), "S",
-							       p_s_tb->tb_path->
+							       tb->tb_path->
 							       path_length - i);
 				}
 #endif
-				if (!clear_all_dirty_bits(p_s_tb->tb_sb,
+				if (!clear_all_dirty_bits(tb->tb_sb,
 							  PATH_OFFSET_PBUFFER
-							  (p_s_tb->tb_path,
+							  (tb->tb_path,
 							   i))) {
 					locked =
-					    PATH_OFFSET_PBUFFER(p_s_tb->tb_path,
+					    PATH_OFFSET_PBUFFER(tb->tb_path,
 								i);
 				}
 			}
 		}
 
-		for (i = 0; !locked && i < MAX_HEIGHT && p_s_tb->insert_size[i];
+		for (i = 0; !locked && i < MAX_HEIGHT && tb->insert_size[i];
 		     i++) {
 
-			if (p_s_tb->lnum[i]) {
+			if (tb->lnum[i]) {
 
-				if (p_s_tb->L[i]) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
-							       p_s_tb->L[i],
+				if (tb->L[i]) {
+					tb_buffer_sanity_check(tb->tb_sb,
+							       tb->L[i],
 							       "L", i);
 					if (!clear_all_dirty_bits
-					    (p_s_tb->tb_sb, p_s_tb->L[i]))
-						locked = p_s_tb->L[i];
+					    (tb->tb_sb, tb->L[i]))
+						locked = tb->L[i];
 				}
 
-				if (!locked && p_s_tb->FL[i]) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
-							       p_s_tb->FL[i],
+				if (!locked && tb->FL[i]) {
+					tb_buffer_sanity_check(tb->tb_sb,
+							       tb->FL[i],
 							       "FL", i);
 					if (!clear_all_dirty_bits
-					    (p_s_tb->tb_sb, p_s_tb->FL[i]))
-						locked = p_s_tb->FL[i];
+					    (tb->tb_sb, tb->FL[i]))
+						locked = tb->FL[i];
 				}
 
-				if (!locked && p_s_tb->CFL[i]) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
-							       p_s_tb->CFL[i],
+				if (!locked && tb->CFL[i]) {
+					tb_buffer_sanity_check(tb->tb_sb,
+							       tb->CFL[i],
 							       "CFL", i);
 					if (!clear_all_dirty_bits
-					    (p_s_tb->tb_sb, p_s_tb->CFL[i]))
-						locked = p_s_tb->CFL[i];
+					    (tb->tb_sb, tb->CFL[i]))
+						locked = tb->CFL[i];
 				}
 
 			}
 
-			if (!locked && (p_s_tb->rnum[i])) {
+			if (!locked && (tb->rnum[i])) {
 
-				if (p_s_tb->R[i]) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
-							       p_s_tb->R[i],
+				if (tb->R[i]) {
+					tb_buffer_sanity_check(tb->tb_sb,
+							       tb->R[i],
 							       "R", i);
 					if (!clear_all_dirty_bits
-					    (p_s_tb->tb_sb, p_s_tb->R[i]))
-						locked = p_s_tb->R[i];
+					    (tb->tb_sb, tb->R[i]))
+						locked = tb->R[i];
 				}
 
-				if (!locked && p_s_tb->FR[i]) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
-							       p_s_tb->FR[i],
+				if (!locked && tb->FR[i]) {
+					tb_buffer_sanity_check(tb->tb_sb,
+							       tb->FR[i],
 							       "FR", i);
 					if (!clear_all_dirty_bits
-					    (p_s_tb->tb_sb, p_s_tb->FR[i]))
-						locked = p_s_tb->FR[i];
+					    (tb->tb_sb, tb->FR[i]))
+						locked = tb->FR[i];
 				}
 
-				if (!locked && p_s_tb->CFR[i]) {
-					tb_buffer_sanity_check(p_s_tb->tb_sb,
-							       p_s_tb->CFR[i],
+				if (!locked && tb->CFR[i]) {
+					tb_buffer_sanity_check(tb->tb_sb,
+							       tb->CFR[i],
 							       "CFR", i);
 					if (!clear_all_dirty_bits
-					    (p_s_tb->tb_sb, p_s_tb->CFR[i]))
-						locked = p_s_tb->CFR[i];
+					    (tb->tb_sb, tb->CFR[i]))
+						locked = tb->CFR[i];
 				}
 			}
 		}
@@ -2256,10 +2256,10 @@ static int wait_tb_buffers_until_unlocke
 		 ** --clm
 		 */
 		for (i = 0; !locked && i < MAX_FEB_SIZE; i++) {
-			if (p_s_tb->FEB[i]) {
+			if (tb->FEB[i]) {
 				if (!clear_all_dirty_bits
-				    (p_s_tb->tb_sb, p_s_tb->FEB[i]))
-					locked = p_s_tb->FEB[i];
+				    (tb->tb_sb, tb->FEB[i]))
+					locked = tb->FEB[i];
 			}
 		}
 
@@ -2267,19 +2267,19 @@ static int wait_tb_buffers_until_unlocke
 #ifdef CONFIG_REISERFS_CHECK
 			repeat_counter++;
 			if ((repeat_counter % 10000) == 0) {
-				reiserfs_warning(p_s_tb->tb_sb, "reiserfs-8200",
+				reiserfs_warning(tb->tb_sb, "reiserfs-8200",
 						 "too many iterations waiting "
 						 "for buffer to unlock "
 						 "(%b)", locked);
 
 				/* Don't loop forever.  Try to recover from possible error. */
 
-				return (FILESYSTEM_CHANGED_TB(p_s_tb)) ?
+				return (FILESYSTEM_CHANGED_TB(tb)) ?
 				    REPEAT_SEARCH : CARRY_ON;
 			}
 #endif
 			__wait_on_buffer(locked);
-			if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
+			if (FILESYSTEM_CHANGED_TB(tb)) {
 				return REPEAT_SEARCH;
 			}
 		}
@@ -2317,132 +2317,132 @@ static int wait_tb_buffers_until_unlocke
  *             -1 - if no_disk_space
  */
 
-int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_ins_ih,	// item head of item being inserted
+int fix_nodes(int n_op_mode, struct tree_balance *tb, struct item_head *p_s_ins_ih,	// item head of item being inserted
 	      const void *data	// inserted item or data to be pasted
     )
 {
-	int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(p_s_tb->tb_path);
+	int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(tb->tb_path);
 	int n_pos_in_item;
 
 	/* we set wait_tb_buffers_run when we have to restore any dirty bits cleared
 	 ** during wait_tb_buffers_run
 	 */
 	int wait_tb_buffers_run = 0;
-	struct buffer_head *p_s_tbS0 = PATH_PLAST_BUFFER(p_s_tb->tb_path);
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
 
-	++REISERFS_SB(p_s_tb->tb_sb)->s_fix_nodes;
+	++REISERFS_SB(tb->tb_sb)->s_fix_nodes;
 
-	n_pos_in_item = p_s_tb->tb_path->pos_in_item;
+	n_pos_in_item = tb->tb_path->pos_in_item;
 
-	p_s_tb->fs_gen = get_generation(p_s_tb->tb_sb);
+	tb->fs_gen = get_generation(tb->tb_sb);
 
 	/* we prepare and log the super here so it will already be in the
 	 ** transaction when do_balance needs to change it.
 	 ** This way do_balance won't have to schedule when trying to prepare
 	 ** the super for logging
 	 */
-	reiserfs_prepare_for_journal(p_s_tb->tb_sb,
-				     SB_BUFFER_WITH_SB(p_s_tb->tb_sb), 1);
-	journal_mark_dirty(p_s_tb->transaction_handle, p_s_tb->tb_sb,
-			   SB_BUFFER_WITH_SB(p_s_tb->tb_sb));
-	if (FILESYSTEM_CHANGED_TB(p_s_tb))
+	reiserfs_prepare_for_journal(tb->tb_sb,
+				     SB_BUFFER_WITH_SB(tb->tb_sb), 1);
+	journal_mark_dirty(tb->transaction_handle, tb->tb_sb,
+			   SB_BUFFER_WITH_SB(tb->tb_sb));
+	if (FILESYSTEM_CHANGED_TB(tb))
 		return REPEAT_SEARCH;
 
 	/* if it possible in indirect_to_direct conversion */
-	if (buffer_locked(p_s_tbS0)) {
-		__wait_on_buffer(p_s_tbS0);
-		if (FILESYSTEM_CHANGED_TB(p_s_tb))
+	if (buffer_locked(tbS0)) {
+		__wait_on_buffer(tbS0);
+		if (FILESYSTEM_CHANGED_TB(tb))
 			return REPEAT_SEARCH;
 	}
 #ifdef CONFIG_REISERFS_CHECK
 	if (cur_tb) {
 		print_cur_tb("fix_nodes");
-		reiserfs_panic(p_s_tb->tb_sb, "PAP-8305",
+		reiserfs_panic(tb->tb_sb, "PAP-8305",
 		               "there is pending do_balance");
 	}
 
-	if (!buffer_uptodate(p_s_tbS0) || !B_IS_IN_TREE(p_s_tbS0)) {
-		reiserfs_panic(p_s_tb->tb_sb, "PAP-8320", "S[0] (%b %z) is "
+	if (!buffer_uptodate(tbS0) || !B_IS_IN_TREE(tbS0)) {
+		reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is "
 		               "not uptodate at the beginning of fix_nodes "
 		               "or not in tree (mode %c)",
-		               p_s_tbS0, p_s_tbS0, n_op_mode);
+		               tbS0, tbS0, n_op_mode);
 	}
 
 	/* Check parameters. */
 	switch (n_op_mode) {
 	case M_INSERT:
-		if (n_item_num <= 0 || n_item_num > B_NR_ITEMS(p_s_tbS0))
-			reiserfs_panic(p_s_tb->tb_sb, "PAP-8330", "Incorrect "
+		if (n_item_num <= 0 || n_item_num > B_NR_ITEMS(tbS0))
+			reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect "
 			               "item number %d (in S0 - %d) in case "
 			               "of insert", n_item_num,
-			               B_NR_ITEMS(p_s_tbS0));
+			               B_NR_ITEMS(tbS0));
 		break;
 	case M_PASTE:
 	case M_DELETE:
 	case M_CUT:
-		if (n_item_num < 0 || n_item_num >= B_NR_ITEMS(p_s_tbS0)) {
-			print_block(p_s_tbS0, 0, -1, -1);
-			reiserfs_panic(p_s_tb->tb_sb, "PAP-8335", "Incorrect "
+		if (n_item_num < 0 || n_item_num >= B_NR_ITEMS(tbS0)) {
+			print_block(tbS0, 0, -1, -1);
+			reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect "
 			               "item number(%d); mode = %c "
 			               "insert_size = %d",
 			               n_item_num, n_op_mode,
-			               p_s_tb->insert_size[0]);
+			               tb->insert_size[0]);
 		}
 		break;
 	default:
-		reiserfs_panic(p_s_tb->tb_sb, "PAP-8340", "Incorrect mode "
+		reiserfs_panic(tb->tb_sb, "PAP-8340", "Incorrect mode "
 		               "of operation");
 	}
 #endif
 
-	if (get_mem_for_virtual_node(p_s_tb) == REPEAT_SEARCH)
+	if (get_mem_for_virtual_node(tb) == REPEAT_SEARCH)
 		// FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat
 		return REPEAT_SEARCH;
 
 	/* Starting from the leaf level; for all levels n_h of the tree. */
-	for (n_h = 0; n_h < MAX_HEIGHT && p_s_tb->insert_size[n_h]; n_h++) {
-		if ((n_ret_value = get_direct_parent(p_s_tb, n_h)) != CARRY_ON) {
+	for (n_h = 0; n_h < MAX_HEIGHT && tb->insert_size[n_h]; n_h++) {
+		if ((n_ret_value = get_direct_parent(tb, n_h)) != CARRY_ON) {
 			goto repeat;
 		}
 
 		if ((n_ret_value =
-		     check_balance(n_op_mode, p_s_tb, n_h, n_item_num,
+		     check_balance(n_op_mode, tb, n_h, n_item_num,
 				   n_pos_in_item, p_s_ins_ih,
 				   data)) != CARRY_ON) {
 			if (n_ret_value == NO_BALANCING_NEEDED) {
 				/* No balancing for higher levels needed. */
 				if ((n_ret_value =
-				     get_neighbors(p_s_tb, n_h)) != CARRY_ON) {
+				     get_neighbors(tb, n_h)) != CARRY_ON) {
 					goto repeat;
 				}
 				if (n_h != MAX_HEIGHT - 1)
-					p_s_tb->insert_size[n_h + 1] = 0;
+					tb->insert_size[n_h + 1] = 0;
 				/* ok, analysis and resource gathering are complete */
 				break;
 			}
 			goto repeat;
 		}
 
-		if ((n_ret_value = get_neighbors(p_s_tb, n_h)) != CARRY_ON) {
+		if ((n_ret_value = get_neighbors(tb, n_h)) != CARRY_ON) {
 			goto repeat;
 		}
 
-		if ((n_ret_value = get_empty_nodes(p_s_tb, n_h)) != CARRY_ON) {
+		if ((n_ret_value = get_empty_nodes(tb, n_h)) != CARRY_ON) {
 			goto repeat;	/* No disk space, or schedule occurred and
 					   analysis may be invalid and needs to be redone. */
 		}
 
-		if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h)) {
+		if (!PATH_H_PBUFFER(tb->tb_path, n_h)) {
 			/* We have a positive insert size but no nodes exist on this
 			   level, this means that we are creating a new root. */
 
-			RFALSE(p_s_tb->blknum[n_h] != 1,
+			RFALSE(tb->blknum[n_h] != 1,
 			       "PAP-8350: creating new empty root");
 
 			if (n_h < MAX_HEIGHT - 1)
-				p_s_tb->insert_size[n_h + 1] = 0;
-		} else if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1)) {
-			if (p_s_tb->blknum[n_h] > 1) {
+				tb->insert_size[n_h + 1] = 0;
+		} else if (!PATH_H_PBUFFER(tb->tb_path, n_h + 1)) {
+			if (tb->blknum[n_h] > 1) {
 				/* The tree needs to be grown, so this node S[n_h]
 				   which is the root node is split into two nodes,
 				   and a new node (S[n_h+1]) will be created to
@@ -2451,19 +2451,19 @@ int fix_nodes(int n_op_mode, struct tree
 				RFALSE(n_h == MAX_HEIGHT - 1,
 				       "PAP-8355: attempt to create too high of a tree");
 
-				p_s_tb->insert_size[n_h + 1] =
+				tb->insert_size[n_h + 1] =
 				    (DC_SIZE +
-				     KEY_SIZE) * (p_s_tb->blknum[n_h] - 1) +
+				     KEY_SIZE) * (tb->blknum[n_h] - 1) +
 				    DC_SIZE;
 			} else if (n_h < MAX_HEIGHT - 1)
-				p_s_tb->insert_size[n_h + 1] = 0;
+				tb->insert_size[n_h + 1] = 0;
 		} else
-			p_s_tb->insert_size[n_h + 1] =
-			    (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1);
+			tb->insert_size[n_h + 1] =
+			    (DC_SIZE + KEY_SIZE) * (tb->blknum[n_h] - 1);
 	}
 
-	if ((n_ret_value = wait_tb_buffers_until_unlocked(p_s_tb)) == CARRY_ON) {
-		if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
+	if ((n_ret_value = wait_tb_buffers_until_unlocked(tb)) == CARRY_ON) {
+		if (FILESYSTEM_CHANGED_TB(tb)) {
 			wait_tb_buffers_run = 1;
 			n_ret_value = REPEAT_SEARCH;
 			goto repeat;
@@ -2486,49 +2486,49 @@ int fix_nodes(int n_op_mode, struct tree
 
 		/* Release path buffers. */
 		if (wait_tb_buffers_run) {
-			pathrelse_and_restore(p_s_tb->tb_sb, p_s_tb->tb_path);
+			pathrelse_and_restore(tb->tb_sb, tb->tb_path);
 		} else {
-			pathrelse(p_s_tb->tb_path);
+			pathrelse(tb->tb_path);
 		}
 		/* brelse all resources collected for balancing */
 		for (i = 0; i < MAX_HEIGHT; i++) {
 			if (wait_tb_buffers_run) {
-				reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
-								 p_s_tb->L[i]);
-				reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
-								 p_s_tb->R[i]);
-				reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
-								 p_s_tb->FL[i]);
-				reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
-								 p_s_tb->FR[i]);
-				reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
-								 p_s_tb->
+				reiserfs_restore_prepared_buffer(tb->tb_sb,
+								 tb->L[i]);
+				reiserfs_restore_prepared_buffer(tb->tb_sb,
+								 tb->R[i]);
+				reiserfs_restore_prepared_buffer(tb->tb_sb,
+								 tb->FL[i]);
+				reiserfs_restore_prepared_buffer(tb->tb_sb,
+								 tb->FR[i]);
+				reiserfs_restore_prepared_buffer(tb->tb_sb,
+								 tb->
 								 CFL[i]);
-				reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
-								 p_s_tb->
+				reiserfs_restore_prepared_buffer(tb->tb_sb,
+								 tb->
 								 CFR[i]);
 			}
 
-			brelse(p_s_tb->L[i]);
-			brelse(p_s_tb->R[i]);
-			brelse(p_s_tb->FL[i]);
-			brelse(p_s_tb->FR[i]);
-			brelse(p_s_tb->CFL[i]);
-			brelse(p_s_tb->CFR[i]);
-
-			p_s_tb->L[i] = NULL;
-			p_s_tb->R[i] = NULL;
-			p_s_tb->FL[i] = NULL;
-			p_s_tb->FR[i] = NULL;
-			p_s_tb->CFL[i] = NULL;
-			p_s_tb->CFR[i] = NULL;
+			brelse(tb->L[i]);
+			brelse(tb->R[i]);
+			brelse(tb->FL[i]);
+			brelse(tb->FR[i]);
+			brelse(tb->CFL[i]);
+			brelse(tb->CFR[i]);
+
+			tb->L[i] = NULL;
+			tb->R[i] = NULL;
+			tb->FL[i] = NULL;
+			tb->FR[i] = NULL;
+			tb->CFL[i] = NULL;
+			tb->CFR[i] = NULL;
 		}
 
 		if (wait_tb_buffers_run) {
 			for (i = 0; i < MAX_FEB_SIZE; i++) {
-				if (p_s_tb->FEB[i]) {
+				if (tb->FEB[i]) {
 					reiserfs_restore_prepared_buffer
-					    (p_s_tb->tb_sb, p_s_tb->FEB[i]);
+					    (tb->tb_sb, tb->FEB[i]);
 				}
 			}
 		}
@@ -2537,7 +2537,7 @@ int fix_nodes(int n_op_mode, struct tree
 
 }
 
-/* Anatoly will probably forgive me renaming p_s_tb to tb. I just
+/* Anatoly will probably forgive me renaming tb to tb. I just
    wanted to make lines shorter */
 void unfix_nodes(struct tree_balance *tb)
 {
fs/reiserfs/stree.c +10 -10
@@ -1063,17 +1063,17 @@ static char prepare_for_delete_or_cut(st
 }
 
 /* Calculate number of bytes which will be deleted or cut during balance */
-static int calc_deleted_bytes_number(struct tree_balance *p_s_tb, char c_mode)
+static int calc_deleted_bytes_number(struct tree_balance *tb, char c_mode)
 {
 	int n_del_size;
-	struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path);
+	struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path);
 
 	if (is_statdata_le_ih(p_le_ih))
 		return 0;
 
 	n_del_size =
 	    (c_mode ==
-	     M_DELETE) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0];
+	     M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0];
 	if (is_direntry_le_ih(p_le_ih)) {
 		// return EMPTY_DIR_SIZE; /* We delete emty directoris only. */
 		// we can't use EMPTY_DIR_SIZE, as old format dirs have a different
@@ -1083,25 +1083,25 @@ static int calc_deleted_bytes_number(str
 	}
 
 	if (is_indirect_le_ih(p_le_ih))
-		n_del_size = (n_del_size / UNFM_P_SIZE) * (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size);	// - get_ih_free_space (p_le_ih);
+		n_del_size = (n_del_size / UNFM_P_SIZE) * (PATH_PLAST_BUFFER(tb->tb_path)->b_size);	// - get_ih_free_space (p_le_ih);
 	return n_del_size;
 }
 
 static void init_tb_struct(struct reiserfs_transaction_handle *th,
-			   struct tree_balance *p_s_tb,
+			   struct tree_balance *tb,
 			   struct super_block *sb,
 			   struct treepath *p_s_path, int n_size)
 {
 
 	BUG_ON(!th->t_trans_id);
 
-	memset(p_s_tb, '\0', sizeof(struct tree_balance));
-	p_s_tb->transaction_handle = th;
-	p_s_tb->tb_sb = sb;
-	p_s_tb->tb_path = p_s_path;
+	memset(tb, '\0', sizeof(struct tree_balance));
+	tb->transaction_handle = th;
+	tb->tb_sb = sb;
+	tb->tb_path = p_s_path;
 	PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
 	PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
-	p_s_tb->insert_size[0] = n_size;
+	tb->insert_size[0] = n_size;
 }
 
 void padd_item(char *item, int total_length, int length)
include/linux/reiserfs_fs.h +1 -1
@@ -1996,7 +1996,7 @@ extern const struct address_space_operat
 
 /* fix_nodes.c */
 
-int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb,
+int fix_nodes(int n_op_mode, struct tree_balance *tb,
 	      struct item_head *p_s_ins_ih, const void *);
 void unfix_nodes(struct tree_balance *);
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#29 lore raw

PATCH 29/40 reiserfs: rename p_._ variables

In reply to [email protected]

This patch is a simple s/p_._//g to the reiserfs code. This is the fifth in a series of patches to rip out some of the awful variable naming in reiserfs.

---

 fs/reiserfs/file.c            |    6 
 fs/reiserfs/fix_node.c        |  170 ++++++++--------
 fs/reiserfs/stree.c           |  428 +++++++++++++++++++++---------------------
 fs/reiserfs/tail_conversion.c |   26 +-
 include/linux/reiserfs_fs.h   |   46 ++--
 5 files changed, 338 insertions(+), 338 deletions(-)
fs/reiserfs/file.c +3 -3
@@ -134,10 +134,10 @@ static void reiserfs_vfs_truncate_file(s
  * be removed...
  */
 
-static int reiserfs_sync_file(struct file *p_s_filp,
-			      struct dentry *p_s_dentry, int datasync)
+static int reiserfs_sync_file(struct file *filp,
+			      struct dentry *dentry, int datasync)
 {
-	struct inode *inode = p_s_dentry->d_inode;
+	struct inode *inode = dentry->d_inode;
 	int n_err;
 	int barrier_done;
 
fs/reiserfs/fix_node.c +85 -85

370 lines not on this page · raw message

fs/reiserfs/stree.c +214 -214

1,094 lines not on this page · raw message

fs/reiserfs/tail_conversion.c +13 -13
@@ -170,10 +170,10 @@ void reiserfs_unmap_buffer(struct buffer
    what we expect from it (number of cut bytes). But when tail remains
    in the unformatted node, we set mode to SKIP_BALANCING and unlock
    inode */
-int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *inode, struct page *page, struct treepath *p_s_path,	/* path to the indirect item. */
-		    const struct cpu_key *p_s_item_key,	/* Key to look for unformatted node pointer to be cut. */
+int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *inode, struct page *page, struct treepath *path,	/* path to the indirect item. */
+		    const struct cpu_key *item_key,	/* Key to look for unformatted node pointer to be cut. */
 		    loff_t n_new_file_size,	/* New file size. */
-		    char *p_c_mode)
+		    char *mode)
 {
 	struct super_block *sb = inode->i_sb;
 	struct item_head s_ih;
@@ -187,10 +187,10 @@ int indirect2direct(struct reiserfs_tran
 
 	REISERFS_SB(sb)->s_indirect2direct++;
 
-	*p_c_mode = M_SKIP_BALANCING;
+	*mode = M_SKIP_BALANCING;
 
 	/* store item head path points to. */
-	copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
+	copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
 
 	tail_len = (n_new_file_size & (n_block_size - 1));
 	if (get_inode_sd_version(inode) == STAT_DATA_V2)
@@ -209,14 +209,14 @@ int indirect2direct(struct reiserfs_tran
 
 	tail = (char *)kmap(page);	/* this can schedule */
 
-	if (path_changed(&s_ih, p_s_path)) {
+	if (path_changed(&s_ih, path)) {
 		/* re-search indirect item */
-		if (search_for_position_by_key(sb, p_s_item_key, p_s_path)
+		if (search_for_position_by_key(sb, item_key, path)
 		    == POSITION_NOT_FOUND)
 			reiserfs_panic(sb, "PAP-5520",
 				       "item to be converted %K does not exist",
-				       p_s_item_key);
-		copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
+				       item_key);
+		copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
 #ifdef CONFIG_REISERFS_CHECK
 		pos = le_ih_k_offset(&s_ih) - 1 +
 		    (ih_item_len(&s_ih) / UNFM_P_SIZE -
@@ -238,13 +238,13 @@ int indirect2direct(struct reiserfs_tran
 	 */
 	tail = tail + (pos & (PAGE_CACHE_SIZE - 1));
 
-	PATH_LAST_POSITION(p_s_path)++;
+	PATH_LAST_POSITION(path)++;
 
-	key = *p_s_item_key;
+	key = *item_key;
 	set_cpu_key_k_type(&key, TYPE_DIRECT);
 	key.key_length = 4;
 	/* Insert tail as new direct item in the tree */
-	if (reiserfs_insert_item(th, p_s_path, &key, &s_ih, inode,
+	if (reiserfs_insert_item(th, path, &key, &s_ih, inode,
 				 tail ? tail : NULL) < 0) {
 		/* No disk memory. So we can not convert last unformatted node
 		   to the direct item.  In this case we used to adjust
@@ -266,7 +266,7 @@ int indirect2direct(struct reiserfs_tran
 
 	/* We have inserted new direct item and must remove last
 	   unformatted node. */
-	*p_c_mode = M_CUT;
+	*mode = M_CUT;
 
 	/* we store position of first direct item in the in-core inode */
 	//mark_file_with_tail (inode, pos1 + 1);
include/linux/reiserfs_fs.h +23 -23

114 lines not on this page · raw message

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#30 lore raw

PATCH 30/40 reiserfs: rename _* variables

In reply to [email protected]

This patch renames n_, c_, etc variables to something more sane. This is the sixth in a series of patches to rip out some of the awful variable naming in reiserfs.

---

 fs/reiserfs/file.c            |    6 
 fs/reiserfs/fix_node.c        |  454 +++++++++++++++++++++---------------------
 fs/reiserfs/stree.c           |  367 ++++++++++++++++-----------------
 fs/reiserfs/tail_conversion.c |   30 +-
 4 files changed, 427 insertions(+), 430 deletions(-)
fs/reiserfs/file.c +3 -3
@@ -138,11 +138,11 @@ static int reiserfs_sync_file(struct fil
 			      struct dentry *dentry, int datasync)
 {
 	struct inode *inode = dentry->d_inode;
-	int n_err;
+	int err;
 	int barrier_done;
 
 	BUG_ON(!S_ISREG(inode->i_mode));
-	n_err = sync_mapping_buffers(inode->i_mapping);
+	err = sync_mapping_buffers(inode->i_mapping);
 	reiserfs_write_lock(inode->i_sb);
 	barrier_done = reiserfs_commit_for_inode(inode);
 	reiserfs_write_unlock(inode->i_sb);
@@ -150,7 +150,7 @@ static int reiserfs_sync_file(struct fil
 		blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
 	if (barrier_done < 0)
 		return barrier_done;
-	return (n_err < 0) ? -EIO : 0;
+	return (err < 0) ? -EIO : 0;
 }
 
 /* I really do not want to play with memory shortage right now, so
fs/reiserfs/fix_node.c +227 -227

829 lines not on this page · raw message

fs/reiserfs/stree.c +182 -185

918 lines not on this page · raw message

fs/reiserfs/tail_conversion.c +15 -15
@@ -26,7 +26,7 @@ int direct2indirect(struct reiserfs_tran
 				   converted item. */
 	struct item_head ind_ih;	/* new indirect item to be inserted or
 					   key of unfm pointer to be pasted */
-	int n_blk_size, n_retval;	/* returned value for reiserfs_insert_item and clones */
+	int blk_size, retval;	/* returned value for reiserfs_insert_item and clones */
 	unp_t unfm_ptr;		/* Handle on an unformatted node
 				   that will be inserted in the
 				   tree. */
@@ -35,7 +35,7 @@ int direct2indirect(struct reiserfs_tran
 
 	REISERFS_SB(sb)->s_direct2indirect++;
 
-	n_blk_size = sb->s_blocksize;
+	blk_size = sb->s_blocksize;
 
 	/* and key to search for append or insert pointer to the new
 	   unformatted node. */
@@ -64,17 +64,17 @@ int direct2indirect(struct reiserfs_tran
 		set_ih_free_space(&ind_ih, 0);	/* delete at nearest future */
 		put_ih_item_len(&ind_ih, UNFM_P_SIZE);
 		PATH_LAST_POSITION(path)++;
-		n_retval =
+		retval =
 		    reiserfs_insert_item(th, path, &end_key, &ind_ih, inode,
 					 (char *)&unfm_ptr);
 	} else {
 		/* Paste into last indirect item of an object. */
-		n_retval = reiserfs_paste_into_item(th, path, &end_key, inode,
+		retval = reiserfs_paste_into_item(th, path, &end_key, inode,
 						    (char *)&unfm_ptr,
 						    UNFM_P_SIZE);
 	}
-	if (n_retval) {
-		return n_retval;
+	if (retval) {
+		return retval;
 	}
 	// note: from here there are two keys which have matching first
 	// three key components. They only differ by the fourth one.
@@ -98,7 +98,7 @@ int direct2indirect(struct reiserfs_tran
 		RFALSE(!is_direct_le_ih(p_le_ih),
 		       "vs-14055: direct item expected(%K), found %h",
 		       &end_key, p_le_ih);
-		tail_size = (le_ih_k_offset(p_le_ih) & (n_blk_size - 1))
+		tail_size = (le_ih_k_offset(p_le_ih) & (blk_size - 1))
 		    + ih_item_len(p_le_ih) - 1;
 
 		/* we only send the unbh pointer if the buffer is not up to date.
@@ -113,11 +113,11 @@ int direct2indirect(struct reiserfs_tran
 		} else {
 			up_to_date_bh = unbh;
 		}
-		n_retval = reiserfs_delete_item(th, path, &end_key, inode,
+		retval = reiserfs_delete_item(th, path, &end_key, inode,
 						up_to_date_bh);
 
-		total_tail += n_retval;
-		if (tail_size == n_retval)
+		total_tail += retval;
+		if (tail_size == retval)
 			// done: file does not have direct items anymore
 			break;
 
@@ -129,7 +129,7 @@ int direct2indirect(struct reiserfs_tran
 		unsigned pgoff =
 		    (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1);
 		char *kaddr = kmap_atomic(up_to_date_bh->b_page, KM_USER0);
-		memset(kaddr + pgoff, 0, n_blk_size - total_tail);
+		memset(kaddr + pgoff, 0, blk_size - total_tail);
 		kunmap_atomic(kaddr, KM_USER0);
 	}
 
@@ -177,7 +177,7 @@ int indirect2direct(struct reiserfs_tran
 {
 	struct super_block *sb = inode->i_sb;
 	struct item_head s_ih;
-	unsigned long n_block_size = sb->s_blocksize;
+	unsigned long block_size = sb->s_blocksize;
 	char *tail;
 	int tail_len, round_tail_len;
 	loff_t pos, pos1;	/* position of first byte of the tail */
@@ -192,7 +192,7 @@ int indirect2direct(struct reiserfs_tran
 	/* store item head path points to. */
 	copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
 
-	tail_len = (n_new_file_size & (n_block_size - 1));
+	tail_len = (n_new_file_size & (block_size - 1));
 	if (get_inode_sd_version(inode) == STAT_DATA_V2)
 		round_tail_len = ROUND_UP(tail_len);
 	else
@@ -253,7 +253,7 @@ int indirect2direct(struct reiserfs_tran
 		   unformatted node. For now i_size is considered as guard for
 		   going out of file size */
 		kunmap(page);
-		return n_block_size - round_tail_len;
+		return block_size - round_tail_len;
 	}
 	kunmap(page);
 
@@ -272,5 +272,5 @@ int indirect2direct(struct reiserfs_tran
 	//mark_file_with_tail (inode, pos1 + 1);
 	REISERFS_I(inode)->i_first_direct_byte = pos1 + 1;
 
-	return n_block_size - round_tail_len;
+	return block_size - round_tail_len;
 }
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#31 lore raw

PATCH 31/40 reiserfs: factor out buffer_info initialization

In reply to [email protected]

This is the first in a series of patches to make balance_leaf() not quite so insane.

This patch factors out the open coded initializations of buffer_info structures and defines a few initializers for the 4 cases they're used.

---
 fs/reiserfs/do_balan.c |  175 ++++++++++++++++---------------------------------
 1 file changed, 60 insertions(+), 115 deletions(-)
fs/reiserfs/do_balan.c +60 -115
@@ -29,6 +29,43 @@ struct tree_balance *cur_tb = NULL;	/* d
 					   is interrupting do_balance */
 #endif
 
+static inline void buffer_info_init_left(struct tree_balance *tb,
+                                         struct buffer_info *bi)
+{
+	bi->tb          = tb;
+	bi->bi_bh       = tb->L[0];
+	bi->bi_parent   = tb->FL[0];
+	bi->bi_position = get_left_neighbor_position(tb, 0);
+}
+
+static inline void buffer_info_init_right(struct tree_balance *tb,
+                                          struct buffer_info *bi)
+{
+	bi->tb          = tb;
+	bi->bi_bh       = tb->R[0];
+	bi->bi_parent   = tb->FR[0];
+	bi->bi_position = get_right_neighbor_position(tb, 0);
+}
+
+static inline void buffer_info_init_tbS0(struct tree_balance *tb,
+                                         struct buffer_info *bi)
+{
+	bi->tb          = tb;
+	bi->bi_bh        = PATH_PLAST_BUFFER(tb->tb_path);
+	bi->bi_parent   = PATH_H_PPARENT(tb->tb_path, 0);
+	bi->bi_position = PATH_H_POSITION(tb->tb_path, 1);
+}
+
+static inline void buffer_info_init_bh(struct tree_balance *tb,
+                                       struct buffer_info *bi,
+                                       struct buffer_head *bh)
+{
+	bi->tb          = tb;
+	bi->bi_bh       = bh;
+	bi->bi_parent   = NULL;
+	bi->bi_position = 0;
+}
+
 inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
 				       struct buffer_head *bh, int flag)
 {
@@ -86,6 +123,7 @@ static int balance_leaf_when_delete(stru
 	       "PAP-12010: tree can not be empty");
 
 	ih = B_N_PITEM_HEAD(tbS0, item_pos);
+	buffer_info_init_tbS0(tb, &bi);
 
 	/* Delete or truncate the item */
 
@@ -96,10 +134,6 @@ static int balance_leaf_when_delete(stru
 		       "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
 		       -tb->insert_size[0], ih);
 
-		bi.tb = tb;
-		bi.bi_bh = tbS0;
-		bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
-		bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
 		leaf_delete_items(&bi, 0, item_pos, 1, -1);
 
 		if (!item_pos && tb->CFL[0]) {
@@ -121,10 +155,6 @@ static int balance_leaf_when_delete(stru
 		break;
 
 	case M_CUT:{		/* cut item in S[0] */
-			bi.tb = tb;
-			bi.bi_bh = tbS0;
-			bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
-			bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
 			if (is_direntry_le_ih(ih)) {
 
 				/* UFS unlink semantics are such that you can only delete one directory entry at a time. */
@@ -325,11 +355,7 @@ static int balance_leaf(struct tree_bala
 					       ih_item_len(ih));
 
 					/* Insert new item into L[0] */
-					bi.tb = tb;
-					bi.bi_bh = tb->L[0];
-					bi.bi_parent = tb->FL[0];
-					bi.bi_position =
-					    get_left_neighbor_position(tb, 0);
+					buffer_info_init_left(tb, &bi);
 					leaf_insert_into_buf(&bi,
 							     n + item_pos -
 							     ret_val, ih, body,
@@ -369,11 +395,7 @@ static int balance_leaf(struct tree_bala
 					    leaf_shift_left(tb, tb->lnum[0] - 1,
 							    tb->lbytes);
 					/* Insert new item into L[0] */
-					bi.tb = tb;
-					bi.bi_bh = tb->L[0];
-					bi.bi_parent = tb->FL[0];
-					bi.bi_position =
-					    get_left_neighbor_position(tb, 0);
+					buffer_info_init_left(tb, &bi);
 					leaf_insert_into_buf(&bi,
 							     n + item_pos -
 							     ret_val, ih, body,
@@ -429,13 +451,7 @@ static int balance_leaf(struct tree_bala
 							}
 
 							/* Append given directory entry to directory item */
-							bi.tb = tb;
-							bi.bi_bh = tb->L[0];
-							bi.bi_parent =
-							    tb->FL[0];
-							bi.bi_position =
-							    get_left_neighbor_position
-							    (tb, 0);
+							buffer_info_init_left(tb, &bi);
 							leaf_paste_in_buffer
 							    (&bi,
 							     n + item_pos -
@@ -524,13 +540,7 @@ static int balance_leaf(struct tree_bala
 									     (tbS0,
 									      item_pos)));
 							/* Append to body of item in L[0] */
-							bi.tb = tb;
-							bi.bi_bh = tb->L[0];
-							bi.bi_parent =
-							    tb->FL[0];
-							bi.bi_position =
-							    get_left_neighbor_position
-							    (tb, 0);
+							buffer_info_init_left(tb, &bi);
 							leaf_paste_in_buffer
 							    (&bi,
 							     n + item_pos -
@@ -681,11 +691,7 @@ static int balance_leaf(struct tree_bala
 					    leaf_shift_left(tb, tb->lnum[0],
 							    tb->lbytes);
 					/* Append to body of item in L[0] */
-					bi.tb = tb;
-					bi.bi_bh = tb->L[0];
-					bi.bi_parent = tb->FL[0];
-					bi.bi_position =
-					    get_left_neighbor_position(tb, 0);
+					buffer_info_init_left(tb, &bi);
 					leaf_paste_in_buffer(&bi,
 							     n + item_pos -
 							     ret_val,
@@ -776,11 +782,7 @@ static int balance_leaf(struct tree_bala
 					set_le_ih_k_offset(ih, offset);
 					put_ih_item_len(ih, tb->rbytes);
 					/* Insert part of the item into R[0] */
-					bi.tb = tb;
-					bi.bi_bh = tb->R[0];
-					bi.bi_parent = tb->FR[0];
-					bi.bi_position =
-					    get_right_neighbor_position(tb, 0);
+					buffer_info_init_right(tb, &bi);
 					if ((old_len - tb->rbytes) > zeros_num) {
 						r_zeros_number = 0;
 						r_body =
@@ -817,11 +819,7 @@ static int balance_leaf(struct tree_bala
 							     tb->rnum[0] - 1,
 							     tb->rbytes);
 					/* Insert new item into R[0] */
-					bi.tb = tb;
-					bi.bi_bh = tb->R[0];
-					bi.bi_parent = tb->FR[0];
-					bi.bi_position =
-					    get_right_neighbor_position(tb, 0);
+					buffer_info_init_right(tb, &bi);
 					leaf_insert_into_buf(&bi,
 							     item_pos - n +
 							     tb->rnum[0] - 1,
@@ -881,13 +879,7 @@ static int balance_leaf(struct tree_bala
 							    pos_in_item -
 							    entry_count +
 							    tb->rbytes - 1;
-							bi.tb = tb;
-							bi.bi_bh = tb->R[0];
-							bi.bi_parent =
-							    tb->FR[0];
-							bi.bi_position =
-							    get_right_neighbor_position
-							    (tb, 0);
+							buffer_info_init_right(tb, &bi);
 							leaf_paste_in_buffer
 							    (&bi, 0,
 							     paste_entry_position,
@@ -1019,12 +1011,7 @@ static int balance_leaf(struct tree_bala
 						    (tb, tb->CFR[0], 0);
 
 						/* Append part of body into R[0] */
-						bi.tb = tb;
-						bi.bi_bh = tb->R[0];
-						bi.bi_parent = tb->FR[0];
-						bi.bi_position =
-						    get_right_neighbor_position
-						    (tb, 0);
+						buffer_info_init_right(tb, &bi);
 						if (n_rem > zeros_num) {
 							r_zeros_number = 0;
 							r_body =
@@ -1071,12 +1058,7 @@ static int balance_leaf(struct tree_bala
 							     tb->rbytes);
 					/* append item in R[0] */
 					if (pos_in_item >= 0) {
-						bi.tb = tb;
-						bi.bi_bh = tb->R[0];
-						bi.bi_parent = tb->FR[0];
-						bi.bi_position =
-						    get_right_neighbor_position
-						    (tb, 0);
+						buffer_info_init_right(tb, &bi);
 						leaf_paste_in_buffer(&bi,
 								     item_pos -
 								     n +
@@ -1232,10 +1214,7 @@ static int balance_leaf(struct tree_bala
 					put_ih_item_len(ih, sbytes[i]);
 
 					/* Insert part of the item into S_new[i] before 0-th item */
-					bi.tb = tb;
-					bi.bi_bh = S_new[i];
-					bi.bi_parent = NULL;
-					bi.bi_position = 0;
+					buffer_info_init_bh(tb, &bi, S_new[i]);
 
 					if ((old_len - sbytes[i]) > zeros_num) {
 						r_zeros_number = 0;
@@ -1267,10 +1246,7 @@ static int balance_leaf(struct tree_bala
 							S_new[i]);
 
 					/* Insert new item into S_new[i] */
-					bi.tb = tb;
-					bi.bi_bh = S_new[i];
-					bi.bi_parent = NULL;
-					bi.bi_position = 0;
+					buffer_info_init_bh(tb, &bi, S_new[i]);
 					leaf_insert_into_buf(&bi,
 							     item_pos - n +
 							     snum[i] - 1, ih,
@@ -1327,10 +1303,7 @@ static int balance_leaf(struct tree_bala
 							     sbytes[i] - 1,
 							     S_new[i]);
 							/* Paste given directory entry to directory item */
-							bi.tb = tb;
-							bi.bi_bh = S_new[i];
-							bi.bi_parent = NULL;
-							bi.bi_position = 0;
+							buffer_info_init_bh(tb, &bi, S_new[i]);
 							leaf_paste_in_buffer
 							    (&bi, 0,
 							     pos_in_item -
@@ -1401,11 +1374,7 @@ static int balance_leaf(struct tree_bala
 						if (n_rem < 0)
 							n_rem = 0;
 						/* Append part of body into S_new[0] */
-						bi.tb = tb;
-						bi.bi_bh = S_new[i];
-						bi.bi_parent = NULL;
-						bi.bi_position = 0;
-
+						buffer_info_init_bh(tb, &bi, S_new[i]);
 						if (n_rem > zeros_num) {
 							r_zeros_number = 0;
 							r_body =
@@ -1490,10 +1459,7 @@ static int balance_leaf(struct tree_bala
 					       ret_val);
 
 					/* paste into item */
-					bi.tb = tb;
-					bi.bi_bh = S_new[i];
-					bi.bi_parent = NULL;
-					bi.bi_position = 0;
+					buffer_info_init_bh(tb, &bi, S_new[i]);
 					leaf_paste_in_buffer(&bi,
 							     item_pos - n +
 							     snum[i],
@@ -1560,10 +1526,7 @@ static int balance_leaf(struct tree_bala
 
 		switch (flag) {
 		case M_INSERT:	/* insert item into S[0] */
-			bi.tb = tb;
-			bi.bi_bh = tbS0;
-			bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
-			bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
+			buffer_info_init_tbS0(tb, &bi);
 			leaf_insert_into_buf(&bi, item_pos, ih, body,
 					     zeros_num);
 
@@ -1590,14 +1553,7 @@ static int balance_leaf(struct tree_bala
 						       "PAP-12260: insert_size is 0 already");
 
 						/* prepare space */
-						bi.tb = tb;
-						bi.bi_bh = tbS0;
-						bi.bi_parent =
-						    PATH_H_PPARENT(tb->tb_path,
-								   0);
-						bi.bi_position =
-						    PATH_H_POSITION(tb->tb_path,
-								    1);
+						buffer_info_init_tbS0(tb, &bi);
 						leaf_paste_in_buffer(&bi,
 								     item_pos,
 								     pos_in_item,
@@ -1645,14 +1601,7 @@ static int balance_leaf(struct tree_bala
 						RFALSE(tb->insert_size[0] <= 0,
 						       "PAP-12275: insert size must not be %d",
 						       tb->insert_size[0]);
-						bi.tb = tb;
-						bi.bi_bh = tbS0;
-						bi.bi_parent =
-						    PATH_H_PPARENT(tb->tb_path,
-								   0);
-						bi.bi_position =
-						    PATH_H_POSITION(tb->tb_path,
-								    1);
+						buffer_info_init_tbS0(tb, &bi);
 						leaf_paste_in_buffer(&bi,
 								     item_pos,
 								     pos_in_item,
@@ -1724,7 +1673,6 @@ void make_empty_node(struct buffer_info 
 struct buffer_head *get_FEB(struct tree_balance *tb)
 {
 	int i;
-	struct buffer_head *first_b;
 	struct buffer_info bi;
 
 	for (i = 0; i < MAX_FEB_SIZE; i++)
@@ -1734,16 +1682,13 @@ struct buffer_head *get_FEB(struct tree_
 	if (i == MAX_FEB_SIZE)
 		reiserfs_panic(tb->tb_sb, "vs-12300", "FEB list is empty");
 
-	bi.tb = tb;
-	bi.bi_bh = first_b = tb->FEB[i];
-	bi.bi_parent = NULL;
-	bi.bi_position = 0;
+	buffer_info_init_bh(tb, &bi, tb->FEB[i]);
 	make_empty_node(&bi);
-	set_buffer_uptodate(first_b);
+	set_buffer_uptodate(tb->FEB[i]);
+	tb->used[i] = tb->FEB[i];
 	tb->FEB[i] = NULL;
-	tb->used[i] = first_b;
 
-	return (first_b);
+	return tb->used[i];
 }
 
 /* This is now used because reiserfs_free_block has to be able to
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#32 lore raw

PATCH 32/40 reiserfs: Turn tb->snum and tb->sbytes into an array

In reply to [email protected]

This patch turns tree_balance.s[12]num into snum[2] and tree_balance.s[12]bytes into sbytes[2]. It doesn't have any effect now, but will be used when balance_leaf is split up.

---
 fs/reiserfs/do_balan.c      |   95 ++++++++++++++++++--------------------------
 fs/reiserfs/fix_node.c      |   28 ++++++------
 fs/reiserfs/prints.c        |    6 +-
 include/linux/reiserfs_fs.h |    6 --
 4 files changed, 59 insertions(+), 76 deletions(-)
fs/reiserfs/do_balan.c +40 -55
@@ -82,8 +82,8 @@ inline void do_balance_mark_leaf_dirty(s
  else
    if lnum is larger than 0 we put items into the left node
    if rnum is larger than 0 we put items into the right node
-   if snum1 is larger than 0 we put items into the new node s1
-   if snum2 is larger than 0 we put items into the new node s2
+   if tb->snum[0] is larger than 0 we put items into the new node s1
+   if tb->snum[1] is larger than 0 we put items into the new node s2
 Note that all *num* count new items being created.
 
 It would be easier to read balance_leaf() if each of these summary
@@ -292,15 +292,6 @@ static int balance_leaf(struct tree_bala
 							   of the affected item */
 	struct buffer_info bi;
 	struct buffer_head *S_new[2];	/* new nodes allocated to hold what could not fit into S */
-	int snum[2];		/* number of items that will be placed
-				   into S_new (includes partially shifted
-				   items) */
-	int sbytes[2];		/* if an item is partially shifted into S_new then
-				   if it is a directory item
-				   it is the number of entries from the item that are shifted into S_new
-				   else
-				   it is the number of bytes from the item that are shifted into S_new
-				 */
 	int n, i;
 	int ret_val;
 	int pos_in_item;
@@ -1161,16 +1152,10 @@ static int balance_leaf(struct tree_bala
 	}
 
 	/* Fill new nodes that appear in place of S[0] */
-
-	/* I am told that this copying is because we need an array to enable
-	   the looping code. -Hans */
-	snum[0] = tb->s1num, snum[1] = tb->s2num;
-	sbytes[0] = tb->s1bytes;
-	sbytes[1] = tb->s2bytes;
 	for (i = tb->blknum[0] - 2; i >= 0; i--) {
 
-		RFALSE(!snum[i], "PAP-12200: snum[%d] == %d. Must be > 0", i,
-		       snum[i]);
+		RFALSE(!tb->snum[i], "PAP-12200: tb->snum[%d] == %d. Must be > 0", i,
+		       tb->snum[i]);
 
 		/* here we shift from S to S_new nodes */
 
@@ -1184,16 +1169,16 @@ static int balance_leaf(struct tree_bala
 		switch (flag) {
 		case M_INSERT:	/* insert item */
 
-			if (n - snum[i] < item_pos) {	/* new item or it's part falls to first new node S_new[i] */
-				if (item_pos == n - snum[i] + 1 && sbytes[i] != -1) {	/* part of new item falls into S_new[i] */
+			if (n - tb->snum[i] < item_pos) {	/* new item or it's part falls to first new node S_new[i] */
+				if (item_pos == n - tb->snum[i] + 1 && tb->sbytes[i] != -1) {	/* part of new item falls into S_new[i] */
 					int old_key_comp, old_len,
 					    r_zeros_number;
 					const char *r_body;
 					int version;
 
-					/* Move snum[i]-1 items from S[0] to S_new[i] */
+					/* Move tb->snum[i]-1 items from S[0] to S_new[i] */
 					leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-							snum[i] - 1, -1,
+							tb->snum[i] - 1, -1,
 							S_new[i]);
 					/* Remember key component and item length */
 					version = ih_version(ih);
@@ -1204,29 +1189,29 @@ static int balance_leaf(struct tree_bala
 					set_le_ih_k_offset(ih,
 							   le_ih_k_offset(ih) +
 							   ((old_len -
-							     sbytes[i]) <<
+							     tb->sbytes[i]) <<
 							    (is_indirect_le_ih
 							     (ih) ? tb->tb_sb->
 							     s_blocksize_bits -
 							     UNFM_P_SHIFT :
 							     0)));
 
-					put_ih_item_len(ih, sbytes[i]);
+					put_ih_item_len(ih, tb->sbytes[i]);
 
 					/* Insert part of the item into S_new[i] before 0-th item */
 					buffer_info_init_bh(tb, &bi, S_new[i]);
 
-					if ((old_len - sbytes[i]) > zeros_num) {
+					if ((old_len - tb->sbytes[i]) > zeros_num) {
 						r_zeros_number = 0;
 						r_body =
 						    body + (old_len -
-							    sbytes[i]) -
+							    tb->sbytes[i]) -
 						    zeros_num;
 					} else {
 						r_body = body;
 						r_zeros_number =
 						    zeros_num - (old_len -
-								 sbytes[i]);
+								 tb->sbytes[i]);
 						zeros_num -= r_zeros_number;
 					}
 
@@ -1236,20 +1221,20 @@ static int balance_leaf(struct tree_bala
 					/* Calculate key component and item length to insert into S[i] */
 					set_le_ih_k_offset(ih, old_key_comp);
 					put_ih_item_len(ih,
-							old_len - sbytes[i]);
-					tb->insert_size[0] -= sbytes[i];
+							old_len - tb->sbytes[i]);
+					tb->insert_size[0] -= tb->sbytes[i];
 				} else {	/* whole new item falls into S_new[i] */
 
-					/* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */
+					/* Shift tb->snum[0] - 1 items to S_new[i] (tb->sbytes[i] of split item) */
 					leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-							snum[i] - 1, sbytes[i],
+							tb->snum[i] - 1, tb->sbytes[i],
 							S_new[i]);
 
 					/* Insert new item into S_new[i] */
 					buffer_info_init_bh(tb, &bi, S_new[i]);
 					leaf_insert_into_buf(&bi,
 							     item_pos - n +
-							     snum[i] - 1, ih,
+							     tb->snum[i] - 1, ih,
 							     body, zeros_num);
 
 					zeros_num = tb->insert_size[0] = 0;
@@ -1259,14 +1244,14 @@ static int balance_leaf(struct tree_bala
 			else {	/* new item or it part don't falls into S_new[i] */
 
 				leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-						snum[i], sbytes[i], S_new[i]);
+						tb->snum[i], tb->sbytes[i], S_new[i]);
 			}
 			break;
 
 		case M_PASTE:	/* append item */
 
-			if (n - snum[i] <= item_pos) {	/* pasted item or part if it falls to S_new[i] */
-				if (item_pos == n - snum[i] && sbytes[i] != -1) {	/* we must shift part of the appended item */
+			if (n - tb->snum[i] <= item_pos) {	/* pasted item or part if it falls to S_new[i] */
+				if (item_pos == n - tb->snum[i] && tb->sbytes[i] != -1) {	/* we must shift part of the appended item */
 					struct item_head *aux_ih;
 
 					RFALSE(ih, "PAP-12210: ih must be 0");
@@ -1281,7 +1266,7 @@ static int balance_leaf(struct tree_bala
 						entry_count =
 						    ih_entry_count(aux_ih);
 
-						if (entry_count - sbytes[i] <
+						if (entry_count - tb->sbytes[i] <
 						    pos_in_item
 						    && pos_in_item <=
 						    entry_count) {
@@ -1290,17 +1275,17 @@ static int balance_leaf(struct tree_bala
 							RFALSE(!tb->
 							       insert_size[0],
 							       "PAP-12215: insert_size is already 0");
-							RFALSE(sbytes[i] - 1 >=
+							RFALSE(tb->sbytes[i] - 1 >=
 							       entry_count,
 							       "PAP-12220: there are no so much entries (%d), only %d",
-							       sbytes[i] - 1,
+							       tb->sbytes[i] - 1,
 							       entry_count);
 
-							/* Shift snum[i]-1 items in whole. Shift sbytes[i] directory entries from directory item number snum[i] */
+							/* Shift tb->snum[i]-1 items in whole. Shift tb->sbytes[i] directory entries from directory item number tb->snum[i] */
 							leaf_move_items
 							    (LEAF_FROM_S_TO_SNEW,
-							     tb, snum[i],
-							     sbytes[i] - 1,
+							     tb, tb->snum[i],
+							     tb->sbytes[i] - 1,
 							     S_new[i]);
 							/* Paste given directory entry to directory item */
 							buffer_info_init_bh(tb, &bi, S_new[i]);
@@ -1308,7 +1293,7 @@ static int balance_leaf(struct tree_bala
 							    (&bi, 0,
 							     pos_in_item -
 							     entry_count +
-							     sbytes[i] - 1,
+							     tb->sbytes[i] - 1,
 							     tb->insert_size[0],
 							     body, zeros_num);
 							/* paste new directory entry */
@@ -1319,7 +1304,7 @@ static int balance_leaf(struct tree_bala
 									   -
 									   entry_count
 									   +
-									   sbytes
+									   tb->sbytes
 									   [i] -
 									   1, 1,
 									   (struct
@@ -1338,8 +1323,8 @@ static int balance_leaf(struct tree_bala
 						} else {	/* new directory entry doesn't fall into S_new[i] */
 							leaf_move_items
 							    (LEAF_FROM_S_TO_SNEW,
-							     tb, snum[i],
-							     sbytes[i],
+							     tb, tb->snum[i],
+							     tb->sbytes[i],
 							     S_new[i]);
 						}
 					} else {	/* regular object */
@@ -1358,19 +1343,19 @@ static int balance_leaf(struct tree_bala
 
 						/* Calculate number of bytes which must be shifted from appended item */
 						n_shift =
-						    sbytes[i] -
+						    tb->sbytes[i] -
 						    tb->insert_size[0];
 						if (n_shift < 0)
 							n_shift = 0;
 						leaf_move_items
 						    (LEAF_FROM_S_TO_SNEW, tb,
-						     snum[i], n_shift,
+						     tb->snum[i], n_shift,
 						     S_new[i]);
 
 						/* Calculate number of bytes which must remain in body after append to S_new[i] */
 						n_rem =
 						    tb->insert_size[0] -
-						    sbytes[i];
+						    tb->sbytes[i];
 						if (n_rem < 0)
 							n_rem = 0;
 						/* Append part of body into S_new[0] */
@@ -1450,8 +1435,8 @@ static int balance_leaf(struct tree_bala
 
 					ret_val =
 					    leaf_move_items(LEAF_FROM_S_TO_SNEW,
-							    tb, snum[i],
-							    sbytes[i],
+							    tb, tb->snum[i],
+							    tb->sbytes[i],
 							    S_new[i]);
 
 					RFALSE(ret_val,
@@ -1462,7 +1447,7 @@ static int balance_leaf(struct tree_bala
 					buffer_info_init_bh(tb, &bi, S_new[i]);
 					leaf_paste_in_buffer(&bi,
 							     item_pos - n +
-							     snum[i],
+							     tb->snum[i],
 							     pos_in_item,
 							     tb->insert_size[0],
 							     body, zeros_num);
@@ -1470,11 +1455,11 @@ static int balance_leaf(struct tree_bala
 					pasted =
 					    B_N_PITEM_HEAD(S_new[i],
 							   item_pos - n +
-							   snum[i]);
+							   tb->snum[i]);
 					if (is_direntry_le_ih(pasted)) {
 						leaf_paste_entries(bi.bi_bh,
 								   item_pos -
-								   n + snum[i],
+								   n + tb->snum[i],
 								   pos_in_item,
 								   1,
 								   (struct
@@ -1498,7 +1483,7 @@ static int balance_leaf(struct tree_bala
 			else {	/* pasted item doesn't fall into S_new[i] */
 
 				leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-						snum[i], sbytes[i], S_new[i]);
+						tb->snum[i], tb->sbytes[i], S_new[i]);
 			}
 			break;
 		default:	/* cases d and t */
fs/reiserfs/fix_node.c +14 -14
@@ -399,8 +399,8 @@ static int get_num_ver(int mode, struct 
 
 	/* snum012 [0-2] - number of items, that lay
 	   to S[0], first new node and second new node */
-	snum012[3] = -1;	/* s1bytes */
-	snum012[4] = -1;	/* s2bytes */
+	snum012[3] = -1;	/* sbytes[0] */
+	snum012[4] = -1;	/* sbytes[1] */
 
 	/* internal level */
 	if (h > 0) {
@@ -526,7 +526,7 @@ static int get_num_ver(int mode, struct 
 		    ((split_item_positions[0] ==
 		      split_item_positions[1]) ? snum012[3] : 0);
 
-		// s2bytes
+		// sbytes[2]
 		snum012[4] =
 		    op_unit_num(&vn->vn_vi[split_item_num]) - snum012[4] -
 		    bytes_to_r - bytes_to_l - bytes_to_S1new;
@@ -554,7 +554,7 @@ static int get_num_ver(int mode, struct 
 		    ((split_item_positions[0] == split_item_positions[1]
 		      && snum012[4] != -1) ? snum012[4] : 0);
 
-		// s1bytes
+		// sbytes[0]
 		snum012[3] =
 		    op_unit_num(&vn->vn_vi[split_item_num]) - snum012[3] -
 		    bytes_to_r - bytes_to_l - bytes_to_S2new;
@@ -581,7 +581,7 @@ extern struct tree_balance *cur_tb;
  *		not shifted entirely
  *	rbytes	number of bytes which flow to the right neighbor from the item that is not
  *		not shifted entirely
- *	s1bytes	number of bytes which flow to the first  new node when S[0] splits (this number is contained in s012 array)
+ *	sbytes[0]	number of bytes which flow to the first  new node when S[0] splits (this number is contained in s012 array)
  */
 
 static void set_parameters(struct tree_balance *tb, int h, int lnum,
@@ -595,9 +595,9 @@ static void set_parameters(struct tree_b
 	if (h == 0) {		/* only for leaf level */
 		if (s012 != NULL) {
 			tb->s0num = *s012++,
-			    tb->s1num = *s012++, tb->s2num = *s012++;
-			tb->s1bytes = *s012++;
-			tb->s2bytes = *s012;
+			    tb->snum[0] = *s012++, tb->snum[1] = *s012++;
+			tb->sbytes[0] = *s012++;
+			tb->sbytes[2] = *s012;
 		}
 		tb->lbytes = lb;
 		tb->rbytes = rb;
@@ -1235,9 +1235,9 @@ static int ip_check_balance(struct tree_
 	   nodes that might be created. */
 
 	/* we perform 8 calls to get_num_ver().  For each call we calculate five parameters.
-	   where 4th parameter is s1bytes and 5th - s2bytes
+	   where 4th parameter is sbytes[0] and 5th - sbytes[2]
 	 */
-	short snum012[40] = { 0, };	/* s0num, s1num, s2num for 8 cases
+	short snum012[40] = { 0, };	/* s0num, snum[0], snum[1] for 8 cases
 					   0,1 - do not shift and do not shift but bottle
 					   2 - shift only whole item to left
 					   3 - shift to left and bottle as much as possible
@@ -1374,7 +1374,7 @@ static int ip_check_balance(struct tree_
 		/* calculate number of blocks S[h] must be split into when
 		   nothing is shifted to the neighbors,
 		   as well as number of items in each part of the split node (s012 numbers),
-		   and number of bytes (s1bytes) of the shared drop which flow to S1 if any */
+		   and number of bytes (sbytes[0]) of the shared drop which flow to S1 if any */
 		nset = NOTHING_SHIFT_NO_FLOW;
 		nver = get_num_ver(vn->vn_mode, tb, h,
 				   0, -1, h ? vn->vn_nr_item : 0, -1,
@@ -1395,7 +1395,7 @@ static int ip_check_balance(struct tree_
 		   l_shift_num first items and l_shift_bytes of the right most
 		   liquid item to be shifted are shifted to the left neighbor,
 		   as well as number of items in each part of the splitted node (s012 numbers),
-		   and number of bytes (s1bytes) of the shared drop which flow to S1 if any
+		   and number of bytes (sbytes[0]) of the shared drop which flow to S1 if any
 		 */
 		lset = LEFT_SHIFT_NO_FLOW;
 		lnver = get_num_ver(vn->vn_mode, tb, h,
@@ -1418,7 +1418,7 @@ static int ip_check_balance(struct tree_
 		   r_shift_num first items and r_shift_bytes of the left most
 		   liquid item to be shifted are shifted to the right neighbor,
 		   as well as number of items in each part of the splitted node (s012 numbers),
-		   and number of bytes (s1bytes) of the shared drop which flow to S1 if any
+		   and number of bytes (sbytes[0]) of the shared drop which flow to S1 if any
 		 */
 		rset = RIGHT_SHIFT_NO_FLOW;
 		rnver = get_num_ver(vn->vn_mode, tb, h,
@@ -1446,7 +1446,7 @@ static int ip_check_balance(struct tree_
 		/* calculate number of blocks S[h] must be split into when
 		   items are shifted in both directions,
 		   as well as number of items in each part of the splitted node (s012 numbers),
-		   and number of bytes (s1bytes) of the shared drop which flow to S1 if any
+		   and number of bytes (sbytes[0]) of the shared drop which flow to S1 if any
 		 */
 		lrset = LR_SHIFT_NO_FLOW;
 		lrnver = get_num_ver(vn->vn_mode, tb, h,
fs/reiserfs/prints.c +3 -3
@@ -667,9 +667,9 @@ void store_print_tb(struct tree_balance 
 		"* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
 		"* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
 		tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],
-		tb->rbytes, tb->blknum[0], tb->s0num, tb->s1num, tb->s1bytes,
-		tb->s2num, tb->s2bytes, tb->cur_blknum, tb->lkey[0],
-		tb->rkey[0]);
+		tb->rbytes, tb->blknum[0], tb->s0num, tb->snum[0],
+		tb->sbytes[0], tb->snum[1], tb->sbytes[1], tb->cur_blknum,
+		tb->lkey[0], tb->rkey[0]);
 
 	/* this prints balance parameters for non-leaf levels */
 	h = 0;
include/linux/reiserfs_fs.h +2 -4
@@ -1366,17 +1366,15 @@ struct tree_balance {
 	/* fields that are used only for balancing leaves of the tree */
 	int cur_blknum;		/* number of empty blocks having been already allocated                 */
 	int s0num;		/* number of items that fall into left most  node when S[0] splits     */
-	int s1num;		/* number of items that fall into first  new node when S[0] splits     */
-	int s2num;		/* number of items that fall into second new node when S[0] splits     */
+	int snum[2];		/* number of items that fall into first and second new node when S[0] splits     */
 	int lbytes;		/* number of bytes which can flow to the left neighbor from the        left    */
 	/* most liquid item that cannot be shifted from S[0] entirely         */
 	/* if -1 then nothing will be partially shifted */
 	int rbytes;		/* number of bytes which will flow to the right neighbor from the right        */
 	/* most liquid item that cannot be shifted from S[0] entirely         */
 	/* if -1 then nothing will be partially shifted                           */
-	int s1bytes;		/* number of bytes which flow to the first  new node when S[0] splits   */
+	int sbytes[2];		/* number of bytes which flow to the first and second new node when S[0] splits   */
 	/* note: if S[0] splits into 3 nodes, then items do not need to be cut  */
-	int s2bytes;
 	struct buffer_head *buf_to_free[MAX_FREE_BLOCK];	/* buffers which are to be freed after do_balance finishes by unfix_nodes */
 	char *vn_buf;		/* kmalloced memory. Used to create
 				   virtual node and keep map of
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#33 lore raw

PATCH 33/40 reiserfs: split left balancing part of balance_leaf() off

In reply to [email protected]

This is the first in a set of 4 patches that split balance_leaf up into a group of functions rather than the 2500 beast it once was.

This patch splits off the left-tree balancing behavior.

---
 fs/reiserfs/do_balan.c |  733 ++++++++++++++++++++-----------------------------
 1 file changed, 313 insertions(+), 420 deletions(-)
fs/reiserfs/do_balan.c +313 -420
@@ -276,6 +276,317 @@ static int balance_leaf_when_delete(stru
 	return 0;
 }
 
+/* Insert item into L[0] */
+static void
+bl_left_insert(struct tree_balance *tb, struct item_head *ih,
+                         const char *body, int flag, int *zeros_num)
+{
+	int shift = 0;
+	int was_copied;
+	int new_item_len;
+	struct buffer_info bi;
+	int n = B_NR_ITEMS(tb->L[0]);
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
+
+	/* new item in whole falls into L[0] */
+	if (item_pos != tb->lnum[0] - 1 || tb->lbytes == -1) {
+		/* Shift lnum[0]-1 items to L[0] */
+		was_copied = leaf_shift_left(tb, tb->lnum[0] - 1, tb->lbytes);
+		/* Insert new item into L[0] */
+		buffer_info_init_left(tb, &bi);
+		leaf_insert_into_buf(&bi, n + item_pos - was_copied, ih, body,
+				     *zeros_num);
+		tb->insert_size[0] = 0;
+		*zeros_num = 0;
+		return;
+	}
+
+	/* Only part of new item falls into L[0] */
+	was_copied = leaf_shift_left(tb, tb->lnum[0] - 1, -1);
+
+	/* Calculate item length to insert to S[0] */
+	new_item_len = ih_item_len(ih) - tb->lbytes;
+	/* Calculate and check item length to insert to L[0] */
+	put_ih_item_len(ih, ih_item_len(ih) - new_item_len);
+
+	RFALSE(ih_item_len(ih) <= 0, "PAP-12080: there is nothing to "
+	       "insert into L[0]: ih_item_len=%d", ih_item_len(ih));
+
+	/* Insert new item into L[0] */
+	buffer_info_init_left(tb, &bi);
+	leaf_insert_into_buf(&bi, n + item_pos - was_copied, ih, body,
+			     *zeros_num > ih_item_len(ih) ? ih_item_len(ih) :
+			     *zeros_num);
+
+	/* Calculate key component, item length and body to insert into S[0] */
+	if (is_indirect_le_ih(ih))
+		shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT;
+	set_le_ih_k_offset(ih, le_ih_k_offset(ih) + (tb->lbytes << shift));
+
+	put_ih_item_len(ih, new_item_len);
+	if (tb->lbytes > *zeros_num) {
+		body += (tb->lbytes - *zeros_num);
+		*zeros_num = 0;
+	} else
+		*zeros_num -= tb->lbytes;
+
+	RFALSE(ih_item_len(ih) <= 0, "PAP-12085: there is nothing to "
+	       "insert into S[0]: ih_item_len=%d", ih_item_len(ih));
+}
+
+/* directory item */
+static void
+bl_left_paste_de_partial(struct tree_balance *tb, struct item_head *ih,
+                         const char *body, int flag, int *zeros_num,
+                         int *pos_in_item)
+{
+	struct item_head *pasted;
+	int l_pos_in_item = *pos_in_item;
+	int was_copied;
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
+	struct buffer_info bi;
+	int n = B_NR_ITEMS(tb->L[0]);
+
+	RFALSE(*zeros_num, "PAP-12090: invalid parameter "
+	       "in case of a directory");
+
+	if (tb->lbytes <= *pos_in_item) {
+		/* new directory item doesn't fall into L[0] */
+		/* Shift lnum[0]-1 items in whole. Shift lbytes
+		 * directory entries from directory item number
+		 * lnum[0] */
+		leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
+		/* Calculate new position to append in item body */
+		*pos_in_item -= tb->lbytes;
+		return;
+	}
+
+	/* new directory entry falls into L[0] */
+
+	/* Shift lnum[0] - 1 items in whole.
+	 * Shift lbytes - 1 entries from given directory item */
+	was_copied = leaf_shift_left(tb, tb->lnum[0], tb->lbytes - 1);
+	if (was_copied && !item_pos) {
+		pasted = B_N_PITEM_HEAD(tb->L[0], B_NR_ITEMS(tb->L[0]) - 1);
+		l_pos_in_item += I_ENTRY_COUNT(pasted) - (tb->lbytes - 1);
+	}
+
+	/* Append given directory entry to directory item */
+	buffer_info_init_left(tb, &bi);
+	leaf_paste_in_buffer(&bi, n + item_pos - was_copied, l_pos_in_item,
+	                     tb->insert_size[0], body, *zeros_num);
+
+	/* previous string prepared space for pasting new
+	 * entry, following string pastes this entry */
+
+	/* when we have merge directory item, pos_in_item
+	 * has been changed too */
+
+	/* paste new directory entry. 1 is entry number */
+	leaf_paste_entries(bi.bi_bh,
+			   n + item_pos - was_copied,
+			   l_pos_in_item, 1,
+			   (struct reiserfs_de_head *) body,
+			   body + DEH_SIZE, tb->insert_size[0]);
+	tb->insert_size[0] = 0;
+
+	/* Calculate new position to append in item body */
+	*pos_in_item -= tb->lbytes;
+}
+
+static void
+bl_left_paste_non_de_partial(struct tree_balance *tb, struct item_head *ih,
+                             const char *body, int flag, int *zeros_num,
+                             int *pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
+	struct buffer_info bi;
+	int l_n, version, temp_l;
+	u64 offset;
+	int was_copied;
+	int n = B_NR_ITEMS(tb->L[0]);
+
+	/* regular object */
+	RFALSE(tb->lbytes <= 0, "PAP-12095: there is nothing to "
+	       "shift to L[0]. lbytes=%d", tb->lbytes);
+	RFALSE(*pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)),
+	       "PAP-12100: incorrect position to paste: "
+	       "item_len=%d, pos_in_item=%d",
+	       ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)), *pos_in_item);
+
+	/* only part of the appended item will be in L[0] */
+	if (tb->lbytes < *pos_in_item) {
+		/* Calculate position in item for append in S[0] */
+		*pos_in_item -= tb->lbytes;
+
+		RFALSE(*pos_in_item <= 0,
+		       "PAP-12125: no place for paste. pos_in_item=%d",
+		       *pos_in_item);
+
+		/* Shift lnum[0] - 1 items in whole.
+		 * Shift lbytes - 1 byte from item number lnum[0] */
+		leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
+		return;
+	}
+
+	/* appended item will be in L[0] in whole */
+	/* this bytes number must be appended to the last item of L[h] */
+	l_n = tb->lbytes - *pos_in_item;
+
+	/* Calculate new insert_size[0] */
+	tb->insert_size[0] -= l_n;
+
+	RFALSE(tb-> insert_size[0] <= 0, "PAP-12105: there is "
+	       "nothing to paste into L[0]. insert_size=%d",
+	       tb->insert_size[0]);
+	was_copied = leaf_shift_left(tb, tb->lnum[0],
+			    ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)));
+	/* Append to body of item in L[0] */
+	buffer_info_init_left(tb, &bi);
+	leaf_paste_in_buffer(&bi, n + item_pos - was_copied,
+			     ih_item_len(B_N_PITEM_HEAD(tb->L[0],
+					  n + item_pos -
+					  was_copied)),
+			     l_n, body,
+			     *zeros_num > l_n ? l_n : *zeros_num);
+	/* 0-th item in S0 can be only of DIRECT type when l_n != 0 */
+	temp_l = l_n;
+	RFALSE(ih_item_len (B_N_PITEM_HEAD(tbS0, 0)),
+	     "PAP-12106: item length must be 0");
+	RFALSE(comp_short_le_keys(B_N_PKEY(tbS0, 0),
+                                B_N_PKEY(tb->L[0], n + item_pos - was_copied)),
+	       "PAP-12107: items must be of the same file");
+	if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->L[0],
+			      n + item_pos - was_copied))) {
+		temp_l = l_n << (tb->tb_sb-> s_blocksize_bits - UNFM_P_SHIFT);
+	}
+	/* update key of first item in S0 */
+	version = ih_version(B_N_PITEM_HEAD(tbS0, 0));
+	set_le_key_k_offset(version, B_N_PKEY(tbS0, 0),
+			    le_key_k_offset(version, B_N_PKEY(tbS0, 0)) +
+			    temp_l);
+	/* update left delimiting key */
+	offset = le_key_k_offset(version,
+	                     B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0])) + temp_l;
+	set_le_key_k_offset(version, B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]),
+	                    offset);
+
+	/* Calculate new body, position in item
+	 * and insert_size[0] */
+	if (l_n > *zeros_num) {
+		body += (l_n - *zeros_num);
+		*zeros_num = 0;
+	} else
+		*zeros_num -= l_n;
+
+	*pos_in_item = 0;
+
+	RFALSE(comp_short_le_keys(B_N_PKEY(tbS0, 0),
+	      B_N_PKEY(tb->L[0], B_NR_ITEMS(tb->L[0]) - 1))
+	     || !op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)
+	     || !op_is_left_mergeable(B_N_PDELIM_KEY (tb->CFL[0],
+	       tb->lkey[0]), tbS0->b_size),
+	     "PAP-12120: item must be merge-able with left neighboring item");
+}
+
+static void
+bl_left_paste_solid(struct tree_balance *tb, struct item_head *ih,
+                    const char *body, int flag, int *zeros_num,
+                    int *pos_in_item)
+{
+	int was_copied;
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
+	int n = B_NR_ITEMS(tb->L[0]);
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct buffer_info bi;
+	struct item_head *pasted;
+
+	/* appended item will be in L[0] in whole */
+	if (!item_pos &&
+	    op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)) {
+		/* if we paste into first item of S[0] and it is
+		 * left mergable */
+		/* then increment pos_in_item by the size of the
+		 * last item in L[0] */
+		pasted = B_N_PITEM_HEAD(tb->L[0], n - 1);
+		if (is_direntry_le_ih(pasted))
+			*pos_in_item += ih_entry_count(pasted);
+		else
+			*pos_in_item += ih_item_len(pasted);
+	}
+
+	/* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte
+	 * from item number lnum[0] */
+	was_copied = leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
+
+	/* Append to body of item in L[0] */
+	buffer_info_init_left(tb, &bi);
+	leaf_paste_in_buffer(&bi, n + item_pos - was_copied,
+			     *pos_in_item, tb->insert_size[0], body,
+			     *zeros_num);
+
+	/* if appended item is directory, paste entry */
+	pasted = B_N_PITEM_HEAD(tb->L[0], n + item_pos - was_copied);
+	if (is_direntry_le_ih(pasted))
+		leaf_paste_entries(bi.bi_bh, n + item_pos - was_copied,
+				   *pos_in_item, 1,
+				   (struct reiserfs_de_head *)body,
+				   body + DEH_SIZE, tb->insert_size[0]);
+	/* if appended item is indirect item, put
+	 * unformatted node into un list */
+	if (is_indirect_le_ih(pasted))
+		set_ih_free_space(pasted, 0);
+	tb->insert_size[0] = 0;
+	*zeros_num = 0;
+}
+
+/* Append item in L[0] */
+static void
+bl_left_paste(struct tree_balance *tb, struct item_head *ih,
+			const char *body, int flag, int *zeros_num,
+			int *pos_in_item)
+{
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+
+	/* We must shift the part of the appended item */
+	if (item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
+		if (is_direntry_le_ih(B_N_PITEM_HEAD(tbS0, item_pos)))
+			bl_left_paste_de_partial(tb, ih, body, flag, zeros_num,
+			                         pos_in_item);
+		else
+			bl_left_paste_non_de_partial(tb, ih, body, flag,
+			                             zeros_num, pos_in_item);
+		return;
+	} else {
+		bl_left_paste_solid(tb, ih, body, flag, zeros_num, pos_in_item);
+	}
+}
+
+/* Shift lnum[0] items from S[0] to the left neighbor L[0] */
+static void
+bl_left(struct tree_balance *tb, struct item_head *ih,
+		  const char *body, int flag, int *zeros_num, int *pos_in_item)
+{
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
+
+	BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+	/* new item doesn't fall into L[0] */
+	if (item_pos >= tb->lnum[0]) {
+		leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
+		return;
+	}
+
+	/* new item or it part falls to L[0], shift it too */
+	if (flag == M_INSERT)
+		bl_left_insert(tb, ih, body, flag, zeros_num);
+	else /* M_PASTE */
+		bl_left_paste(tb, ih, body, flag, zeros_num,
+		                        pos_in_item);
+}
+
 static int balance_leaf(struct tree_balance *tb, struct item_head *ih,	/* item header of inserted item (this is on little endian) */
 			const char *body,	/* body  of inserted item or bytes to paste */
 			int flag,	/* i - insert, d - delete, c - cut, p - paste
@@ -314,426 +625,8 @@ static int balance_leaf(struct tree_bala
 	    && is_indirect_le_ih(B_N_PITEM_HEAD(tbS0, item_pos)))
 		pos_in_item *= UNFM_P_SIZE;
 
-	if (tb->lnum[0] > 0) {
-		/* Shift lnum[0] items from S[0] to the left neighbor L[0] */
-		if (item_pos < tb->lnum[0]) {
-			/* new item or it part falls to L[0], shift it too */
-			n = B_NR_ITEMS(tb->L[0]);
-
-			switch (flag) {
-			case M_INSERT:	/* insert item into L[0] */
-
-				if (item_pos == tb->lnum[0] - 1
-				    && tb->lbytes != -1) {
-					/* part of new item falls into L[0] */
-					int new_item_len;
-					int version;
-
-					ret_val =
-					    leaf_shift_left(tb, tb->lnum[0] - 1,
-							    -1);
-
-					/* Calculate item length to insert to S[0] */
-					new_item_len =
-					    ih_item_len(ih) - tb->lbytes;
-					/* Calculate and check item length to insert to L[0] */
-					put_ih_item_len(ih,
-							ih_item_len(ih) -
-							new_item_len);
-
-					RFALSE(ih_item_len(ih) <= 0,
-					       "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
-					       ih_item_len(ih));
-
-					/* Insert new item into L[0] */
-					buffer_info_init_left(tb, &bi);
-					leaf_insert_into_buf(&bi,
-							     n + item_pos -
-							     ret_val, ih, body,
-							     zeros_num >
-							     ih_item_len(ih) ?
-							     ih_item_len(ih) :
-							     zeros_num);
-
-					version = ih_version(ih);
-
-					/* Calculate key component, item length and body to insert into S[0] */
-					set_le_ih_k_offset(ih,
-							   le_ih_k_offset(ih) +
-							   (tb->
-							    lbytes <<
-							    (is_indirect_le_ih
-							     (ih) ? tb->tb_sb->
-							     s_blocksize_bits -
-							     UNFM_P_SHIFT :
-							     0)));
-
-					put_ih_item_len(ih, new_item_len);
-					if (tb->lbytes > zeros_num) {
-						body +=
-						    (tb->lbytes - zeros_num);
-						zeros_num = 0;
-					} else
-						zeros_num -= tb->lbytes;
-
-					RFALSE(ih_item_len(ih) <= 0,
-					       "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
-					       ih_item_len(ih));
-				} else {
-					/* new item in whole falls into L[0] */
-					/* Shift lnum[0]-1 items to L[0] */
-					ret_val =
-					    leaf_shift_left(tb, tb->lnum[0] - 1,
-							    tb->lbytes);
-					/* Insert new item into L[0] */
-					buffer_info_init_left(tb, &bi);
-					leaf_insert_into_buf(&bi,
-							     n + item_pos -
-							     ret_val, ih, body,
-							     zeros_num);
-					tb->insert_size[0] = 0;
-					zeros_num = 0;
-				}
-				break;
-
-			case M_PASTE:	/* append item in L[0] */
-
-				if (item_pos == tb->lnum[0] - 1
-				    && tb->lbytes != -1) {
-					/* we must shift the part of the appended item */
-					if (is_direntry_le_ih
-					    (B_N_PITEM_HEAD(tbS0, item_pos))) {
-
-						RFALSE(zeros_num,
-						       "PAP-12090: invalid parameter in case of a directory");
-						/* directory item */
-						if (tb->lbytes > pos_in_item) {
-							/* new directory entry falls into L[0] */
-							struct item_head
-							    *pasted;
-							int l_pos_in_item =
-							    pos_in_item;
-
-							/* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 entries from given directory item */
-							ret_val =
-							    leaf_shift_left(tb,
-									    tb->
-									    lnum
-									    [0],
-									    tb->
-									    lbytes
-									    -
-									    1);
-							if (ret_val
-							    && !item_pos) {
-								pasted =
-								    B_N_PITEM_HEAD
-								    (tb->L[0],
-								     B_NR_ITEMS
-								     (tb->
-								      L[0]) -
-								     1);
-								l_pos_in_item +=
-								    I_ENTRY_COUNT
-								    (pasted) -
-								    (tb->
-								     lbytes -
-								     1);
-							}
-
-							/* Append given directory entry to directory item */
-							buffer_info_init_left(tb, &bi);
-							leaf_paste_in_buffer
-							    (&bi,
-							     n + item_pos -
-							     ret_val,
-							     l_pos_in_item,
-							     tb->insert_size[0],
-							     body, zeros_num);
-
-							/* previous string prepared space for pasting new entry, following string pastes this entry */
-
-							/* when we have merge directory item, pos_in_item has been changed too */
-
-							/* paste new directory entry. 1 is entry number */
-							leaf_paste_entries(bi.
-									   bi_bh,
-									   n +
-									   item_pos
-									   -
-									   ret_val,
-									   l_pos_in_item,
-									   1,
-									   (struct
-									    reiserfs_de_head
-									    *)
-									   body,
-									   body
-									   +
-									   DEH_SIZE,
-									   tb->
-									   insert_size
-									   [0]
-							    );
-							tb->insert_size[0] = 0;
-						} else {
-							/* new directory item doesn't fall into L[0] */
-							/* Shift lnum[0]-1 items in whole. Shift lbytes directory entries from directory item number lnum[0] */
-							leaf_shift_left(tb,
-									tb->
-									lnum[0],
-									tb->
-									lbytes);
-						}
-						/* Calculate new position to append in item body */
-						pos_in_item -= tb->lbytes;
-					} else {
-						/* regular object */
-						RFALSE(tb->lbytes <= 0,
-						       "PAP-12095: there is nothing to shift to L[0]. lbytes=%d",
-						       tb->lbytes);
-						RFALSE(pos_in_item !=
-						       ih_item_len
-						       (B_N_PITEM_HEAD
-							(tbS0, item_pos)),
-						       "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
-						       ih_item_len
-						       (B_N_PITEM_HEAD
-							(tbS0, item_pos)),
-						       pos_in_item);
-
-						if (tb->lbytes >= pos_in_item) {
-							/* appended item will be in L[0] in whole */
-							int l_n;
-
-							/* this bytes number must be appended to the last item of L[h] */
-							l_n =
-							    tb->lbytes -
-							    pos_in_item;
-
-							/* Calculate new insert_size[0] */
-							tb->insert_size[0] -=
-							    l_n;
-
-							RFALSE(tb->
-							       insert_size[0] <=
-							       0,
-							       "PAP-12105: there is nothing to paste into L[0]. insert_size=%d",
-							       tb->
-							       insert_size[0]);
-							ret_val =
-							    leaf_shift_left(tb,
-									    tb->
-									    lnum
-									    [0],
-									    ih_item_len
-									    (B_N_PITEM_HEAD
-									     (tbS0,
-									      item_pos)));
-							/* Append to body of item in L[0] */
-							buffer_info_init_left(tb, &bi);
-							leaf_paste_in_buffer
-							    (&bi,
-							     n + item_pos -
-							     ret_val,
-							     ih_item_len
-							     (B_N_PITEM_HEAD
-							      (tb->L[0],
-							       n + item_pos -
-							       ret_val)), l_n,
-							     body,
-							     zeros_num >
-							     l_n ? l_n :
-							     zeros_num);
-							/* 0-th item in S0 can be only of DIRECT type when l_n != 0 */
-							{
-								int version;
-								int temp_l =
-								    l_n;
-
-								RFALSE
-								    (ih_item_len
-								     (B_N_PITEM_HEAD
-								      (tbS0,
-								       0)),
-								     "PAP-12106: item length must be 0");
-								RFALSE
-								    (comp_short_le_keys
-								     (B_N_PKEY
-								      (tbS0, 0),
-								      B_N_PKEY
-								      (tb->L[0],
-								       n +
-								       item_pos
-								       -
-								       ret_val)),
-								     "PAP-12107: items must be of the same file");
-								if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->L[0], n + item_pos - ret_val))) {
-									temp_l =
-									    l_n
-									    <<
-									    (tb->
-									     tb_sb->
-									     s_blocksize_bits
-									     -
-									     UNFM_P_SHIFT);
-								}
-								/* update key of first item in S0 */
-								version =
-								    ih_version
-								    (B_N_PITEM_HEAD
-								     (tbS0, 0));
-								set_le_key_k_offset
-								    (version,
-								     B_N_PKEY
-								     (tbS0, 0),
-								     le_key_k_offset
-								     (version,
-								      B_N_PKEY
-								      (tbS0,
-								       0)) +
-								     temp_l);
-								/* update left delimiting key */
-								set_le_key_k_offset
-								    (version,
-								     B_N_PDELIM_KEY
-								     (tb->
-								      CFL[0],
-								      tb->
-								      lkey[0]),
-								     le_key_k_offset
-								     (version,
-								      B_N_PDELIM_KEY
-								      (tb->
-								       CFL[0],
-								       tb->
-								       lkey[0]))
-								     + temp_l);
-							}
-
-							/* Calculate new body, position in item and insert_size[0] */
-							if (l_n > zeros_num) {
-								body +=
-								    (l_n -
-								     zeros_num);
-								zeros_num = 0;
-							} else
-								zeros_num -=
-								    l_n;
-							pos_in_item = 0;
-
-							RFALSE
-							    (comp_short_le_keys
-							     (B_N_PKEY(tbS0, 0),
-							      B_N_PKEY(tb->L[0],
-								       B_NR_ITEMS
-								       (tb->
-									L[0]) -
-								       1))
-							     ||
-							     !op_is_left_mergeable
-							     (B_N_PKEY(tbS0, 0),
-							      tbS0->b_size)
-							     ||
-							     !op_is_left_mergeable
-							     (B_N_PDELIM_KEY
-							      (tb->CFL[0],
-							       tb->lkey[0]),
-							      tbS0->b_size),
-							     "PAP-12120: item must be merge-able with left neighboring item");
-						} else {	/* only part of the appended item will be in L[0] */
-
-							/* Calculate position in item for append in S[0] */
-							pos_in_item -=
-							    tb->lbytes;
-
-							RFALSE(pos_in_item <= 0,
-							       "PAP-12125: no place for paste. pos_in_item=%d",
-							       pos_in_item);
-
-							/* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
-							leaf_shift_left(tb,
-									tb->
-									lnum[0],
-									tb->
-									lbytes);
-						}
-					}
-				} else {	/* appended item will be in L[0] in whole */
-
-					struct item_head *pasted;
-
-					if (!item_pos && op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)) {	/* if we paste into first item of S[0] and it is left mergable */
-						/* then increment pos_in_item by the size of the last item in L[0] */
-						pasted =
-						    B_N_PITEM_HEAD(tb->L[0],
-								   n - 1);
-						if (is_direntry_le_ih(pasted))
-							pos_in_item +=
-							    ih_entry_count
-							    (pasted);
-						else
-							pos_in_item +=
-							    ih_item_len(pasted);
-					}
-
-					/* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
-					ret_val =
-					    leaf_shift_left(tb, tb->lnum[0],
-							    tb->lbytes);
-					/* Append to body of item in L[0] */
-					buffer_info_init_left(tb, &bi);
-					leaf_paste_in_buffer(&bi,
-							     n + item_pos -
-							     ret_val,
-							     pos_in_item,
-							     tb->insert_size[0],
-							     body, zeros_num);
-
-					/* if appended item is directory, paste entry */
-					pasted =
-					    B_N_PITEM_HEAD(tb->L[0],
-							   n + item_pos -
-							   ret_val);
-					if (is_direntry_le_ih(pasted))
-						leaf_paste_entries(bi.bi_bh,
-								   n +
-								   item_pos -
-								   ret_val,
-								   pos_in_item,
-								   1,
-								   (struct
-								    reiserfs_de_head
-								    *)body,
-								   body +
-								   DEH_SIZE,
-								   tb->
-								   insert_size
-								   [0]
-						    );
-					/* if appended item is indirect item, put unformatted node into un list */
-					if (is_indirect_le_ih(pasted))
-						set_ih_free_space(pasted, 0);
-					tb->insert_size[0] = 0;
-					zeros_num = 0;
-				}
-				break;
-			default:	/* cases d and t */
-				reiserfs_panic(tb->tb_sb, "PAP-12130",
-				               "lnum > 0: unexpected mode: %s(%d)",
-					       (flag ==
-						M_DELETE) ? "DELETE" : ((flag ==
-									 M_CUT)
-									? "CUT"
-									:
-									"UNKNOWN"),
-					       flag);
-			}
-		} else {
-			/* new item doesn't fall into L[0] */
-			leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
-		}
-	}
+	if (tb->lnum[0] > 0)
+		bl_left(tb, ih, body, flag, &zeros_num, &pos_in_item);
 
 	/* tb->lnum[0] > 0 */
 	/* Calculate new item position */
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#34 lore raw

PATCH 34/40 reiserfs: split right balancing part of balance_leaf() off

In reply to [email protected]

This is the second in a set of 4 patches that split balance_leaf up into a group of functions rather than the 2500 beast it once was.

This patch splits off the right-tree balancing behavior.

---
 fs/reiserfs/do_balan.c |  671 +++++++++++++++++++++----------------------------
 1 file changed, 290 insertions(+), 381 deletions(-)
fs/reiserfs/do_balan.c +290 -381
@@ -587,6 +587,293 @@ bl_left(struct tree_balance *tb, struct 
 		                        pos_in_item);
 }
 
+static void
+bl_right_insert(struct tree_balance *tb, struct item_head *ih,
+			  const char *body, int flag, int *zeros_num,
+			  int item_pos)
+{
+	loff_t old_key_comp, old_len, r_zeros_number;
+	const char *r_body;
+	loff_t offset;
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+	struct buffer_info bi;
+
+	/* Doesn't fall into R[0] */
+	if (n - tb->rnum[0] >= item_pos) {
+		leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
+		return;
+	}
+
+	/* whole new item falls into R[0] */
+	if (item_pos != n - tb->rnum[0] + 1 || tb->rbytes == -1) {
+		/* Shift rnum[0]-1 items to R[0] */
+		leaf_shift_right(tb, tb->rnum[0] - 1, tb->rbytes);
+
+		/* Insert new item into R[0] */
+		buffer_info_init_right(tb, &bi);
+		leaf_insert_into_buf(&bi, item_pos - n + tb->rnum[0] - 1,
+		                     ih, body, *zeros_num);
+
+		if (item_pos - n + tb->rnum[0] - 1 == 0)
+			replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+		*zeros_num = tb->insert_size[0] = 0;
+		return;
+	}
+
+	/* Only part of item falls into R[0] */
+
+	leaf_shift_right(tb, tb->rnum[0] - 1, -1);
+
+	/* Remember key component and item length */
+	old_key_comp = le_ih_k_offset(ih);
+	old_len = ih_item_len(ih);
+
+	/* Calculate key component and item length to insert into R[0] */
+	offset = le_ih_k_offset(ih) +
+	    ((old_len - tb->rbytes) << (is_indirect_le_ih(ih)
+					? tb->tb_sb->
+					s_blocksize_bits -
+					UNFM_P_SHIFT : 0));
+	set_le_ih_k_offset(ih, offset);
+	put_ih_item_len(ih, tb->rbytes);
+	/* Insert part of the item into R[0] */
+	buffer_info_init_right(tb, &bi);
+	if ((old_len - tb->rbytes) > *zeros_num) {
+		r_zeros_number = 0;
+		r_body = body + (old_len - tb->rbytes) - *zeros_num;
+	} else {
+		r_body = body;
+		r_zeros_number = *zeros_num - (old_len - tb->rbytes);
+		*zeros_num -= r_zeros_number;
+	}
+
+	leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeros_number);
+
+	/* Replace right delimiting key by first key in R[0] */
+	replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+
+	/* Calculate key component and item length to insert into S[0] */
+	set_le_ih_k_offset(ih, old_key_comp);
+	put_ih_item_len(ih, old_len - tb->rbytes);
+
+	tb->insert_size[0] -= tb->rbytes;
+}
+
+static void
+bl_right_paste_de_partial(struct tree_balance *tb, struct item_head *ih,
+                          const char *body, int flag, int *zeros_num,
+                          int item_pos, int *pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct buffer_info bi;
+	int paste_entry_position;
+	int entry_count;
+
+	RFALSE(*zeros_num, "PAP-12145: invalid parameter "
+	       "in case of a directory");
+	entry_count = I_ENTRY_COUNT(B_N_PITEM_HEAD(tbS0,
+						   item_pos));
+
+	if (entry_count - tb->rbytes >= *pos_in_item) {
+		leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
+		return;
+	}
+
+	/* new directory entry falls into R[0] */
+	RFALSE(tb->rbytes - 1 >= entry_count
+	       || !tb-> insert_size[0], "PAP-12150: no enough of entries "
+	       "to shift to R[0]: rbytes=%d, entry_count=%d",
+	       tb->rbytes, entry_count);
+
+	/* Shift rnum[0]-1 items in whole.
+	 * Shift rbytes-1 directory entries from
+	 * directory item number rnum[0] */
+	leaf_shift_right(tb, tb->rnum[0], tb->rbytes - 1);
+
+	/* Paste given directory entry to
+	 * directory item */
+	paste_entry_position = *pos_in_item - entry_count + tb->rbytes - 1;
+	buffer_info_init_right(tb, &bi);
+	leaf_paste_in_buffer(&bi, 0, paste_entry_position, tb->insert_size[0],
+			     body, *zeros_num);
+	/* paste entry */
+	leaf_paste_entries(bi.bi_bh, 0, paste_entry_position, 1,
+			   (struct reiserfs_de_head *) body, body + DEH_SIZE,
+			   tb->insert_size[0]);
+
+	/* change delimiting keys */
+	if (paste_entry_position == 0)
+		replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+
+	tb->insert_size[0] = 0;
+	(*pos_in_item)++;
+}
+
+static void
+bl_right_paste_non_de_partial(struct tree_balance *tb, struct item_head *ih,
+                              const char *body, int flag, int *zeros_num,
+                              int item_pos, int *pos_in_item)
+{
+
+#ifdef CONFIG_REISERFS_CHECK
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+#endif
+	struct buffer_info bi;
+	int n_shift, n_rem, r_zeros_number;
+	const char *r_body;
+	int version;
+	unsigned long temp_rem;
+	u64 offset;
+
+	/* Calculate number of bytes which must be
+	 * shifted from appended item */
+	if ((n_shift = tb->rbytes - tb->insert_size[0]) < 0)
+		n_shift = 0;
+
+	RFALSE(*pos_in_item !=
+		   ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)),
+	       "PAP-12155: invalid position to paste. "
+	       "ih_item_len=%d, pos_in_item=%d", *pos_in_item,
+	       ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)));
+
+	leaf_shift_right(tb, tb->rnum[0], n_shift);
+	/* Calculate number of bytes which must remain
+	 * in body after appending to R[0] */
+	if ((n_rem = tb->insert_size[0] - tb->rbytes) < 0)
+		n_rem = 0;
+
+	temp_rem = n_rem;
+	version = ih_version(B_N_PITEM_HEAD(tb->R[0], 0));
+	if (is_indirect_le_key(version, B_N_PKEY(tb->R[0], 0))) {
+		temp_rem = n_rem << (tb->tb_sb->s_blocksize_bits -
+			      UNFM_P_SHIFT);
+	}
+	offset = le_key_k_offset(version, B_N_PKEY(tb->R[0], 0));
+	set_le_key_k_offset(version, B_N_PKEY(tb->R[0], 0), offset + temp_rem);
+
+	offset = le_key_k_offset (version,
+	                          B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]));
+	set_le_key_k_offset(version, B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]),
+			    offset + temp_rem);
+	do_balance_mark_internal_dirty(tb, tb->CFR[0], 0);
+
+	/* Append part of body into R[0] */
+	buffer_info_init_right(tb, &bi);
+	if (n_rem > *zeros_num) {
+		r_zeros_number = 0;
+		r_body = body + n_rem - *zeros_num;
+	} else {
+		r_body = body;
+		r_zeros_number = *zeros_num - n_rem;
+		*zeros_num -= r_zeros_number;
+	}
+
+	leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0] - n_rem,
+			     r_body, r_zeros_number);
+
+	if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->R[0], 0)))
+		set_ih_free_space(B_N_PITEM_HEAD(tb->R[0], 0), 0);
+
+	tb->insert_size[0] = n_rem;
+	if (!n_rem)
+		(*pos_in_item)++;
+}
+
+static void
+bl_right_paste_solid(struct tree_balance *tb, struct item_head *ih,
+                     const char *body, int flag, int *zeros_num,
+		     int item_pos, int *pos_in_item)
+{
+	struct item_head *pasted;
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+	struct buffer_info bi;
+
+	/* pasted item in whole falls into R[0] */
+	leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
+	/* append item in R[0] */
+	if (*pos_in_item >= 0) {
+		buffer_info_init_right(tb, &bi);
+		leaf_paste_in_buffer(&bi,
+				     item_pos - n + tb->rnum[0],
+				     *pos_in_item,
+				     tb->insert_size[0], body,
+				     *zeros_num);
+	}
+
+	/* paste new entry, if item is directory item */
+	pasted = B_N_PITEM_HEAD(tb->R[0], item_pos - n + tb->rnum[0]);
+	if (is_direntry_le_ih(pasted) && *pos_in_item >= 0) {
+		leaf_paste_entries(bi.bi_bh, item_pos - n + tb->rnum[0],
+				   *pos_in_item, 1,
+				   (struct reiserfs_de_head *)body,
+				   body + DEH_SIZE, tb->insert_size[0]);
+
+		if (!*pos_in_item) {
+			RFALSE(item_pos - n + tb->rnum[0],
+			       "PAP-12165: directory item must be "
+			       "first item of node when pasting is "
+			       "in 0th position");
+
+			/* update delimiting keys */
+			replace_key(tb, tb->CFR[0], tb->rkey[0],
+				    tb->R[0], 0);
+		}
+	}
+
+	if (is_indirect_le_ih(pasted))
+		set_ih_free_space(pasted, 0);
+	*zeros_num = tb->insert_size[0] = 0;
+
+}
+
+static void
+bl_right_paste(struct tree_balance *tb,
+			 struct item_head *ih, const char *body, int flag,
+			 int *zeros_num, int item_pos, int *pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+
+	if (n - tb->rnum[0] > item_pos) {
+		leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
+		return;
+	}
+	/* pasted item or part of it falls to R[0] */
+	/* we must shift the part of the appended item */
+	if (item_pos == n - tb->rnum[0] && tb->rbytes != -1) {
+		if (is_direntry_le_ih(B_N_PITEM_HEAD(tbS0, item_pos)))
+			bl_right_paste_de_partial(tb, ih, body, flag,
+			                          zeros_num, item_pos,
+						  pos_in_item);
+		else
+			bl_right_paste_non_de_partial(tb, ih, body, flag,
+			                              zeros_num, item_pos,
+						      pos_in_item);
+	} else {
+		bl_right_paste_solid(tb, ih, body, flag, zeros_num, item_pos,
+		                     pos_in_item);
+	}
+}
+
+static void
+bl_right(struct tree_balance *tb, struct item_head *ih,
+		   const char *body, int flag, int *zeros_num, int item_pos,
+		   int *pos_in_item)
+{
+	BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+	/* shift rnum[0] items from S[0] to the right neighbor R[0] */
+	if (flag == M_INSERT)
+		bl_right_insert(tb, ih, body, flag, zeros_num,
+		                          item_pos);
+	else
+		bl_right_paste(tb, ih, body, flag, zeros_num,
+		                         item_pos, pos_in_item);
+}
+
+
 static int balance_leaf(struct tree_balance *tb, struct item_head *ih,	/* item header of inserted item (this is on little endian) */
 			const char *body,	/* body  of inserted item or bytes to paste */
 			int flag,	/* i - insert, d - delete, c - cut, p - paste
@@ -604,7 +891,6 @@ static int balance_leaf(struct tree_bala
 	struct buffer_info bi;
 	struct buffer_head *S_new[2];	/* new nodes allocated to hold what could not fit into S */
 	int n, i;
-	int ret_val;
 	int pos_in_item;
 	int zeros_num;
 
@@ -632,386 +918,9 @@ static int balance_leaf(struct tree_bala
 	/* Calculate new item position */
 	item_pos -= (tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0));
 
-	if (tb->rnum[0] > 0) {
-		/* shift rnum[0] items from S[0] to the right neighbor R[0] */
-		n = B_NR_ITEMS(tbS0);
-		switch (flag) {
-
-		case M_INSERT:	/* insert item */
-			if (n - tb->rnum[0] < item_pos) {	/* new item or its part falls to R[0] */
-				if (item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) {	/* part of new item falls into R[0] */
-					loff_t old_key_comp, old_len,
-					    r_zeros_number;
-					const char *r_body;
-					int version;
-					loff_t offset;
-
-					leaf_shift_right(tb, tb->rnum[0] - 1,
-							 -1);
-
-					version = ih_version(ih);
-					/* Remember key component and item length */
-					old_key_comp = le_ih_k_offset(ih);
-					old_len = ih_item_len(ih);
-
-					/* Calculate key component and item length to insert into R[0] */
-					offset =
-					    le_ih_k_offset(ih) +
-					    ((old_len -
-					      tb->
-					      rbytes) << (is_indirect_le_ih(ih)
-							  ? tb->tb_sb->
-							  s_blocksize_bits -
-							  UNFM_P_SHIFT : 0));
-					set_le_ih_k_offset(ih, offset);
-					put_ih_item_len(ih, tb->rbytes);
-					/* Insert part of the item into R[0] */
-					buffer_info_init_right(tb, &bi);
-					if ((old_len - tb->rbytes) > zeros_num) {
-						r_zeros_number = 0;
-						r_body =
-						    body + (old_len -
-							    tb->rbytes) -
-						    zeros_num;
-					} else {
-						r_body = body;
-						r_zeros_number =
-						    zeros_num - (old_len -
-								 tb->rbytes);
-						zeros_num -= r_zeros_number;
-					}
-
-					leaf_insert_into_buf(&bi, 0, ih, r_body,
-							     r_zeros_number);
-
-					/* Replace right delimiting key by first key in R[0] */
-					replace_key(tb, tb->CFR[0], tb->rkey[0],
-						    tb->R[0], 0);
-
-					/* Calculate key component and item length to insert into S[0] */
-					set_le_ih_k_offset(ih, old_key_comp);
-					put_ih_item_len(ih,
-							old_len - tb->rbytes);
-
-					tb->insert_size[0] -= tb->rbytes;
-
-				} else {	/* whole new item falls into R[0] */
-
-					/* Shift rnum[0]-1 items to R[0] */
-					ret_val =
-					    leaf_shift_right(tb,
-							     tb->rnum[0] - 1,
-							     tb->rbytes);
-					/* Insert new item into R[0] */
-					buffer_info_init_right(tb, &bi);
-					leaf_insert_into_buf(&bi,
-							     item_pos - n +
-							     tb->rnum[0] - 1,
-							     ih, body,
-							     zeros_num);
-
-					if (item_pos - n + tb->rnum[0] - 1 == 0) {
-						replace_key(tb, tb->CFR[0],
-							    tb->rkey[0],
-							    tb->R[0], 0);
-
-					}
-					zeros_num = tb->insert_size[0] = 0;
-				}
-			} else {	/* new item or part of it doesn't fall into R[0] */
-
-				leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
-			}
-			break;
-
-		case M_PASTE:	/* append item */
-
-			if (n - tb->rnum[0] <= item_pos) {	/* pasted item or part of it falls to R[0] */
-				if (item_pos == n - tb->rnum[0] && tb->rbytes != -1) {	/* we must shift the part of the appended item */
-					if (is_direntry_le_ih(B_N_PITEM_HEAD(tbS0, item_pos))) {	/* we append to directory item */
-						int entry_count;
-
-						RFALSE(zeros_num,
-						       "PAP-12145: invalid parameter in case of a directory");
-						entry_count =
-						    I_ENTRY_COUNT(B_N_PITEM_HEAD
-								  (tbS0,
-								   item_pos));
-						if (entry_count - tb->rbytes <
-						    pos_in_item)
-							/* new directory entry falls into R[0] */
-						{
-							int paste_entry_position;
-
-							RFALSE(tb->rbytes - 1 >=
-							       entry_count
-							       || !tb->
-							       insert_size[0],
-							       "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d",
-							       tb->rbytes,
-							       entry_count);
-							/* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */
-							leaf_shift_right(tb,
-									 tb->
-									 rnum
-									 [0],
-									 tb->
-									 rbytes
-									 - 1);
-							/* Paste given directory entry to directory item */
-							paste_entry_position =
-							    pos_in_item -
-							    entry_count +
-							    tb->rbytes - 1;
-							buffer_info_init_right(tb, &bi);
-							leaf_paste_in_buffer
-							    (&bi, 0,
-							     paste_entry_position,
-							     tb->insert_size[0],
-							     body, zeros_num);
-							/* paste entry */
-							leaf_paste_entries(bi.
-									   bi_bh,
-									   0,
-									   paste_entry_position,
-									   1,
-									   (struct
-									    reiserfs_de_head
-									    *)
-									   body,
-									   body
-									   +
-									   DEH_SIZE,
-									   tb->
-									   insert_size
-									   [0]
-							    );
-
-							if (paste_entry_position
-							    == 0) {
-								/* change delimiting keys */
-								replace_key(tb,
-									    tb->
-									    CFR
-									    [0],
-									    tb->
-									    rkey
-									    [0],
-									    tb->
-									    R
-									    [0],
-									    0);
-							}
-
-							tb->insert_size[0] = 0;
-							pos_in_item++;
-						} else {	/* new directory entry doesn't fall into R[0] */
-
-							leaf_shift_right(tb,
-									 tb->
-									 rnum
-									 [0],
-									 tb->
-									 rbytes);
-						}
-					} else {	/* regular object */
-
-						int n_shift, n_rem,
-						    r_zeros_number;
-						const char *r_body;
-
-						/* Calculate number of bytes which must be shifted from appended item */
-						if ((n_shift =
-						     tb->rbytes -
-						     tb->insert_size[0]) < 0)
-							n_shift = 0;
-
-						RFALSE(pos_in_item !=
-						       ih_item_len
-						       (B_N_PITEM_HEAD
-							(tbS0, item_pos)),
-						       "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
-						       pos_in_item,
-						       ih_item_len
-						       (B_N_PITEM_HEAD
-							(tbS0, item_pos)));
-
-						leaf_shift_right(tb,
-								 tb->rnum[0],
-								 n_shift);
-						/* Calculate number of bytes which must remain in body after appending to R[0] */
-						if ((n_rem =
-						     tb->insert_size[0] -
-						     tb->rbytes) < 0)
-							n_rem = 0;
-
-						{
-							int version;
-							unsigned long temp_rem =
-							    n_rem;
-
-							version =
-							    ih_version
-							    (B_N_PITEM_HEAD
-							     (tb->R[0], 0));
-							if (is_indirect_le_key
-							    (version,
-							     B_N_PKEY(tb->R[0],
-								      0))) {
-								temp_rem =
-								    n_rem <<
-								    (tb->tb_sb->
-								     s_blocksize_bits
-								     -
-								     UNFM_P_SHIFT);
-							}
-							set_le_key_k_offset
-							    (version,
-							     B_N_PKEY(tb->R[0],
-								      0),
-							     le_key_k_offset
-							     (version,
-							      B_N_PKEY(tb->R[0],
-								       0)) +
-							     temp_rem);
-							set_le_key_k_offset
-							    (version,
-							     B_N_PDELIM_KEY(tb->
-									    CFR
-									    [0],
-									    tb->
-									    rkey
-									    [0]),
-							     le_key_k_offset
-							     (version,
-							      B_N_PDELIM_KEY
-							      (tb->CFR[0],
-							       tb->rkey[0])) +
-							     temp_rem);
-						}
-/*		  k_offset (B_N_PKEY(tb->R[0],0)) += n_rem;
-		  k_offset (B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) += n_rem;*/
-						do_balance_mark_internal_dirty
-						    (tb, tb->CFR[0], 0);
-
-						/* Append part of body into R[0] */
-						buffer_info_init_right(tb, &bi);
-						if (n_rem > zeros_num) {
-							r_zeros_number = 0;
-							r_body =
-							    body + n_rem -
-							    zeros_num;
-						} else {
-							r_body = body;
-							r_zeros_number =
-							    zeros_num - n_rem;
-							zeros_num -=
-							    r_zeros_number;
-						}
-
-						leaf_paste_in_buffer(&bi, 0,
-								     n_shift,
-								     tb->
-								     insert_size
-								     [0] -
-								     n_rem,
-								     r_body,
-								     r_zeros_number);
-
-						if (is_indirect_le_ih
-						    (B_N_PITEM_HEAD
-						     (tb->R[0], 0))) {
-#if 0
-							RFALSE(n_rem,
-							       "PAP-12160: paste more than one unformatted node pointer");
-#endif
-							set_ih_free_space
-							    (B_N_PITEM_HEAD
-							     (tb->R[0], 0), 0);
-						}
-						tb->insert_size[0] = n_rem;
-						if (!n_rem)
-							pos_in_item++;
-					}
-				} else {	/* pasted item in whole falls into R[0] */
-
-					struct item_head *pasted;
-
-					ret_val =
-					    leaf_shift_right(tb, tb->rnum[0],
-							     tb->rbytes);
-					/* append item in R[0] */
-					if (pos_in_item >= 0) {
-						buffer_info_init_right(tb, &bi);
-						leaf_paste_in_buffer(&bi,
-								     item_pos -
-								     n +
-								     tb->
-								     rnum[0],
-								     pos_in_item,
-								     tb->
-								     insert_size
-								     [0], body,
-								     zeros_num);
-					}
-
-					/* paste new entry, if item is directory item */
-					pasted =
-					    B_N_PITEM_HEAD(tb->R[0],
-							   item_pos - n +
-							   tb->rnum[0]);
-					if (is_direntry_le_ih(pasted)
-					    && pos_in_item >= 0) {
-						leaf_paste_entries(bi.bi_bh,
-								   item_pos -
-								   n +
-								   tb->rnum[0],
-								   pos_in_item,
-								   1,
-								   (struct
-								    reiserfs_de_head
-								    *)body,
-								   body +
-								   DEH_SIZE,
-								   tb->
-								   insert_size
-								   [0]
-						    );
-						if (!pos_in_item) {
-
-							RFALSE(item_pos - n +
-							       tb->rnum[0],
-							       "PAP-12165: directory item must be first item of node when pasting is in 0th position");
-
-							/* update delimiting keys */
-							replace_key(tb,
-								    tb->CFR[0],
-								    tb->rkey[0],
-								    tb->R[0],
-								    0);
-						}
-					}
-
-					if (is_indirect_le_ih(pasted))
-						set_ih_free_space(pasted, 0);
-					zeros_num = tb->insert_size[0] = 0;
-				}
-			} else {	/* new item doesn't fall into R[0] */
-
-				leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
-			}
-			break;
-		default:	/* cases d and t */
-			reiserfs_panic(tb->tb_sb, "PAP-12175",
-			               "rnum > 0: unexpected mode: %s(%d)",
-				       (flag ==
-					M_DELETE) ? "DELETE" : ((flag ==
-								 M_CUT) ? "CUT"
-								: "UNKNOWN"),
-				       flag);
-		}
-
-	}
+	if (tb->rnum[0] > 0)
+		bl_right(tb, ih, body, flag, &zeros_num, item_pos,
+		                   &pos_in_item);
 
 	/* tb->rnum[0] > 0 */
 	RFALSE(tb->blknum[0] > 3,
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#35 lore raw

PATCH 35/40 reiserfs: split balance_leaf new node handling out

In reply to [email protected]

This is the third in a set of 4 patches that split balance_leaf up into a group of functions rather than the 2500 beast it once was.

This patch splits off the new node filling behavior.

---
 fs/reiserfs/do_balan.c |  693 +++++++++++++++++++++++--------------------------
 1 file changed, 338 insertions(+), 355 deletions(-)
fs/reiserfs/do_balan.c +338 -355
@@ -873,6 +873,342 @@ bl_right(struct tree_balance *tb, struct
 		                         item_pos, pos_in_item);
 }
 
+static void
+bl_new_nodes_insert(struct tree_balance *tb, struct item_head *ih,
+                              const char *body, int flag,
+                              struct item_head *insert_key, int *zeros_num,
+                              int item_pos, int snum, int sbytes,
+                              struct buffer_head *bh)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+	struct buffer_info bi;
+	int old_key_comp, old_len, r_zeros_number;
+	const char *r_body;
+	int version;
+
+	if (n - snum >= item_pos) {
+		/* new item or it part don't falls into bh */
+		leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum, sbytes, bh);
+		return;
+	}
+
+	if (item_pos != n - snum + 1 || sbytes == -1) {
+		/* Shift snum - 1 items to bh (sbytes of split item) */
+		leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum - 1,
+		                sbytes, bh);
+
+		/* Insert new item into bh */
+		buffer_info_init_bh(tb, &bi, bh);
+		leaf_insert_into_buf(&bi, item_pos - n + snum - 1,
+		                     ih, body, *zeros_num);
+
+		*zeros_num = tb->insert_size[0] = 0;
+		return;
+	}
+
+	/* new item or it's part falls to first new node bh */
+	/* part of new item falls into bh */
+
+	/* Move snum-1 items from S[0] to bh */
+	leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
+			snum - 1, -1, bh);
+
+	/* Remember key component and item length */
+	version = ih_version(ih);
+	old_key_comp = le_ih_k_offset(ih);
+	old_len = ih_item_len(ih);
+
+	/* Calculate key component and item length to
+	 * insert into bh */
+	set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
+			   ((old_len - sbytes) <<
+			    (is_indirect_le_ih
+			     (ih) ? tb->tb_sb->s_blocksize_bits -
+			     UNFM_P_SHIFT : 0)));
+
+	put_ih_item_len(ih, sbytes);
+
+	/* Insert part of the item into bh before 0-th item */
+	buffer_info_init_bh(tb, &bi, bh);
+
+	if ((old_len - sbytes) > *zeros_num) {
+		r_zeros_number = 0;
+		r_body = body + (old_len - sbytes) - *zeros_num;
+	} else {
+		r_body = body;
+		r_zeros_number = *zeros_num - (old_len - sbytes);
+		*zeros_num -= r_zeros_number;
+	}
+
+	leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeros_number);
+
+	/* Calculate key component and item length to
+	 * insert into S[i] */
+	set_le_ih_k_offset(ih, old_key_comp);
+	put_ih_item_len(ih, old_len - sbytes);
+	tb->insert_size[0] -= sbytes;
+}
+
+static void
+bl_new_nodes_paste_de_partial(struct tree_balance *tb, struct item_head *ih,
+                              const char *body, int flag,
+                              struct item_head *insert_key,
+                              int *zeros_num, int item_pos,
+                              int *pos_in_item,
+                              int snum, int sbytes, struct buffer_head *bh)
+{
+	/* we append to directory item */
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int entry_count;
+	struct buffer_info bi;
+	struct item_head *aux_ih = B_N_PITEM_HEAD(tbS0, item_pos);;
+
+	entry_count = ih_entry_count(aux_ih);
+
+	/* new directory entry doesn't fall into bh */
+	if (entry_count - sbytes >= *pos_in_item ||
+	    *pos_in_item > entry_count) {
+		leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
+				snum, sbytes, bh);
+		return;
+	}
+
+	/* new directory entry falls into bh */
+	RFALSE(!tb-> insert_size[0],
+	       "PAP-12215: insert_size is already 0");
+	RFALSE(sbytes - 1 >= entry_count,
+	       "PAP-12220: there are no so much entries (%d), only %d",
+	       sbytes - 1, entry_count);
+
+	/* Shift snum-1 items in whole. Shift
+	 * sbytes directory entries from directory
+	 * item number snum */
+	leaf_move_items(LEAF_FROM_S_TO_SNEW,
+			tb, snum, sbytes - 1,
+			bh);
+	/* Paste given directory entry to
+	 * directory item */
+	buffer_info_init_bh(tb, &bi, bh);
+	leaf_paste_in_buffer(&bi, 0,
+	     *pos_in_item - entry_count + sbytes - 1,
+	     tb->insert_size[0], body, *zeros_num);
+	/* paste new directory entry */
+	leaf_paste_entries(bi.bi_bh, 0,
+			   *pos_in_item - entry_count +
+			   sbytes - 1, 1,
+			   (struct reiserfs_de_head *)
+			   body, body + DEH_SIZE,
+			   tb->insert_size[0]);
+	tb->insert_size[0] = 0;
+	(*pos_in_item)++;
+}
+
+static void
+bl_new_nodes_paste_non_de_partial(struct tree_balance *tb,
+                                  struct item_head *ih,
+                                  const char *body, int flag,
+                                  struct item_head *insert_key,
+                                  int *zeros_num, int item_pos,
+                                  int *pos_in_item, int snum, int sbytes,
+                                  struct buffer_head *bh)
+{
+#ifdef CONFIG_REISERFS_CHECK
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+#endif
+	int n_shift, n_rem, r_zeros_number;
+	const char *r_body;
+	struct item_head *tmp;
+	struct buffer_info bi;
+
+	RFALSE(*pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos))
+	       || tb->insert_size[0] <= 0,
+	       "PAP-12225", "item too short or insert_size <= 0");
+
+	/* Calculate number of bytes which must be shifted from appended item */
+	n_shift = sbytes - tb->insert_size[0];
+	if (n_shift < 0)
+		n_shift = 0;
+	leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum, n_shift, bh);
+
+	/* Calculate number of bytes which must remain
+	 * in body after append to bh */
+	n_rem = tb->insert_size[0] - sbytes;
+	if (n_rem < 0)
+		n_rem = 0;
+
+	/* Append part of body into bh */
+	buffer_info_init_bh(tb, &bi, bh);
+
+	if (n_rem > *zeros_num) {
+		r_zeros_number = 0;
+		r_body = body + n_rem - *zeros_num;
+	} else {
+		r_body = body;
+		r_zeros_number = *zeros_num - n_rem;
+		*zeros_num -= r_zeros_number;
+	}
+
+	leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0] - n_rem,
+			     r_body, r_zeros_number);
+
+	tmp = B_N_PITEM_HEAD(bh, 0);
+	if (is_indirect_le_ih(tmp)) {
+		set_ih_free_space(tmp, 0);
+		set_le_ih_k_offset(tmp, le_ih_k_offset(tmp) +
+		     (n_rem << (tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT)));
+	} else {
+		set_le_ih_k_offset(tmp, le_ih_k_offset(tmp) + n_rem);
+	}
+
+	tb->insert_size[0] = n_rem;
+	if (!n_rem)
+		(*pos_in_item)++;
+}
+
+static void
+bl_new_nodes_paste_solid(struct tree_balance *tb, struct item_head *ih,
+                         const char *body, int flag,
+                         struct item_head *insert_key,
+                         int *zeros_num, int item_pos,
+                         int *pos_in_item, int snum, int sbytes,
+                         struct buffer_head *bh)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+	struct buffer_info bi;
+	struct item_head *pasted;
+	int was_copied;
+#ifdef CONFIG_REISERFS_CHECK
+	struct item_head *aux_ih = B_N_PITEM_HEAD(tbS0, item_pos);;
+
+	/* item falls wholly into bh */
+	if (!is_direntry_le_ih(aux_ih) && (*pos_in_item != ih_item_len(aux_ih)
+		|| tb->insert_size[0] <= 0))
+		reiserfs_panic(tb->tb_sb, "PAP-12235", "pos_in_item must be "
+		               "equal to ih_item_len");
+#endif
+
+	was_copied = leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum,
+				     sbytes, bh);
+
+	RFALSE(was_copied, "PAP-12240: unexpected value returned by "
+	       "leaf_move_items (%d)", was_copied);
+
+	/* paste into item */
+	buffer_info_init_bh(tb, &bi, bh);
+	leaf_paste_in_buffer(&bi, item_pos - n + snum, *pos_in_item,
+			     tb->insert_size[0], body, *zeros_num);
+
+	pasted = B_N_PITEM_HEAD(bh, item_pos - n + snum);
+	if (is_direntry_le_ih(pasted)) {
+		leaf_paste_entries(bi.bi_bh, item_pos - n + snum,
+				   *pos_in_item, 1,
+				   (struct reiserfs_de_head *)body,
+				   body + DEH_SIZE, tb->insert_size[0]);
+	}
+
+	/* if we paste to indirect item update ih_free_space */
+	if (is_indirect_le_ih(pasted))
+		set_ih_free_space(pasted, 0);
+	*zeros_num = tb->insert_size[0] = 0;
+
+}
+
+static void
+bl_new_nodes_paste(struct tree_balance *tb, struct item_head *ih,
+                             const char *body, int flag,
+                             struct item_head *insert_key,
+                             int *zeros_num, int item_pos,
+                             int *pos_in_item, int snum, int sbytes,
+                             struct buffer_head *bh)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+	struct item_head *aux_ih = B_N_PITEM_HEAD(tbS0, item_pos);;
+
+	/* pasted item doesn't fall into bh */
+	if (n - snum > item_pos) {
+		leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum, sbytes, bh);
+		return;
+	}
+	/* pasted item or part if it falls to bh */
+	/* we must shift part of the appended item */
+	if (item_pos == n - snum && sbytes != -1) {
+		RFALSE(ih, "PAP-12210: ih must be 0");
+
+		if (is_direntry_le_ih(aux_ih))
+			bl_new_nodes_paste_de_partial(tb, ih, body, flag,
+			                              insert_key, zeros_num,
+			                              item_pos, pos_in_item,
+			                              snum, sbytes, bh);
+		else
+			bl_new_nodes_paste_non_de_partial(tb, ih, body, flag,
+			                                  insert_key,
+			                                  zeros_num, item_pos,
+			                                  pos_in_item, snum,
+			                                  sbytes, bh);
+	} else {
+		bl_new_nodes_paste_solid(tb, ih, body, flag, insert_key,
+		                         zeros_num, item_pos, pos_in_item,
+		                         snum, sbytes, bh);
+	}
+}
+
+/* @snum: number of items that will be placed into bh
+ * (includes partially shifted items)
+ * @sbytes: if an item is partially shifted into bh then
+ * if it is a directory item:
+ *    it is the number of entries from the item that are
+ *    shifted into bh
+ * else
+ *    it is the number of bytes from the item that are
+ *    shifted into bh
+ */
+static void
+bl_new_nodes(struct tree_balance *tb, struct item_head *ih,
+                       const char *body, int flag,
+                       struct item_head *insert_key,
+                       struct buffer_head **insert_ptr, int *zeros_num,
+                       int item_pos, int *pos_in_item)
+{
+	int i;
+
+	BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+	/* Fill new nodes that appear in place of S[0] */
+	for (i = tb->blknum[0] - 2; i >= 0; i--) {
+		struct buffer_head *bh;
+		RFALSE(!tb->snum[i], "PAP-12200: snum[%d] == %d. Must be > 0",
+		       i, tb->snum[i]);
+
+		/* Use new node since it won't fit in S */
+		bh = get_FEB(tb);
+
+		/* initialized block type and tree level */
+		set_blkh_level(B_BLK_HEAD(bh), DISK_LEAF_NODE_LEVEL);
+
+		if (flag == M_INSERT)
+			bl_new_nodes_insert(tb, ih, body, flag,
+						      insert_key, zeros_num,
+						      item_pos, tb->snum[i],
+			                              tb->sbytes[i], bh);
+		else
+			bl_new_nodes_paste(tb, ih, body, flag,
+			                             insert_key, zeros_num,
+						     item_pos, pos_in_item,
+						     tb->snum[i],
+			                             tb->sbytes[i], bh);
+
+		memcpy(insert_key + i, B_N_PKEY(bh, 0), KEY_SIZE);
+		insert_ptr[i] = bh;
+
+		RFALSE(!buffer_journaled(bh)
+		       || buffer_journal_dirty(bh)
+		       || buffer_dirty(bh),
+		       "PAP-12247: bad state for new buffer : (%b)", bh);
+	}
+}
 
 static int balance_leaf(struct tree_balance *tb, struct item_head *ih,	/* item header of inserted item (this is on little endian) */
 			const char *body,	/* body  of inserted item or bytes to paste */
@@ -889,8 +1225,6 @@ static int balance_leaf(struct tree_bala
 	int item_pos = PATH_LAST_POSITION(tb->tb_path);	/*  index into the array of item headers in S[0]
 							   of the affected item */
 	struct buffer_info bi;
-	struct buffer_head *S_new[2];	/* new nodes allocated to hold what could not fit into S */
-	int n, i;
 	int pos_in_item;
 	int zeros_num;
 
@@ -953,359 +1287,8 @@ static int balance_leaf(struct tree_bala
 		return 0;
 	}
 
-	/* Fill new nodes that appear in place of S[0] */
-	for (i = tb->blknum[0] - 2; i >= 0; i--) {
-
-		RFALSE(!tb->snum[i], "PAP-12200: tb->snum[%d] == %d. Must be > 0", i,
-		       tb->snum[i]);
-
-		/* here we shift from S to S_new nodes */
-
-		S_new[i] = get_FEB(tb);
-
-		/* initialized block type and tree level */
-		set_blkh_level(B_BLK_HEAD(S_new[i]), DISK_LEAF_NODE_LEVEL);
-
-		n = B_NR_ITEMS(tbS0);
-
-		switch (flag) {
-		case M_INSERT:	/* insert item */
-
-			if (n - tb->snum[i] < item_pos) {	/* new item or it's part falls to first new node S_new[i] */
-				if (item_pos == n - tb->snum[i] + 1 && tb->sbytes[i] != -1) {	/* part of new item falls into S_new[i] */
-					int old_key_comp, old_len,
-					    r_zeros_number;
-					const char *r_body;
-					int version;
-
-					/* Move tb->snum[i]-1 items from S[0] to S_new[i] */
-					leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-							tb->snum[i] - 1, -1,
-							S_new[i]);
-					/* Remember key component and item length */
-					version = ih_version(ih);
-					old_key_comp = le_ih_k_offset(ih);
-					old_len = ih_item_len(ih);
-
-					/* Calculate key component and item length to insert into S_new[i] */
-					set_le_ih_k_offset(ih,
-							   le_ih_k_offset(ih) +
-							   ((old_len -
-							     tb->sbytes[i]) <<
-							    (is_indirect_le_ih
-							     (ih) ? tb->tb_sb->
-							     s_blocksize_bits -
-							     UNFM_P_SHIFT :
-							     0)));
-
-					put_ih_item_len(ih, tb->sbytes[i]);
-
-					/* Insert part of the item into S_new[i] before 0-th item */
-					buffer_info_init_bh(tb, &bi, S_new[i]);
-
-					if ((old_len - tb->sbytes[i]) > zeros_num) {
-						r_zeros_number = 0;
-						r_body =
-						    body + (old_len -
-							    tb->sbytes[i]) -
-						    zeros_num;
-					} else {
-						r_body = body;
-						r_zeros_number =
-						    zeros_num - (old_len -
-								 tb->sbytes[i]);
-						zeros_num -= r_zeros_number;
-					}
-
-					leaf_insert_into_buf(&bi, 0, ih, r_body,
-							     r_zeros_number);
-
-					/* Calculate key component and item length to insert into S[i] */
-					set_le_ih_k_offset(ih, old_key_comp);
-					put_ih_item_len(ih,
-							old_len - tb->sbytes[i]);
-					tb->insert_size[0] -= tb->sbytes[i];
-				} else {	/* whole new item falls into S_new[i] */
-
-					/* Shift tb->snum[0] - 1 items to S_new[i] (tb->sbytes[i] of split item) */
-					leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-							tb->snum[i] - 1, tb->sbytes[i],
-							S_new[i]);
-
-					/* Insert new item into S_new[i] */
-					buffer_info_init_bh(tb, &bi, S_new[i]);
-					leaf_insert_into_buf(&bi,
-							     item_pos - n +
-							     tb->snum[i] - 1, ih,
-							     body, zeros_num);
-
-					zeros_num = tb->insert_size[0] = 0;
-				}
-			}
-
-			else {	/* new item or it part don't falls into S_new[i] */
-
-				leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-						tb->snum[i], tb->sbytes[i], S_new[i]);
-			}
-			break;
-
-		case M_PASTE:	/* append item */
-
-			if (n - tb->snum[i] <= item_pos) {	/* pasted item or part if it falls to S_new[i] */
-				if (item_pos == n - tb->snum[i] && tb->sbytes[i] != -1) {	/* we must shift part of the appended item */
-					struct item_head *aux_ih;
-
-					RFALSE(ih, "PAP-12210: ih must be 0");
-
-					if (is_direntry_le_ih
-					    (aux_ih =
-					     B_N_PITEM_HEAD(tbS0, item_pos))) {
-						/* we append to directory item */
-
-						int entry_count;
-
-						entry_count =
-						    ih_entry_count(aux_ih);
-
-						if (entry_count - tb->sbytes[i] <
-						    pos_in_item
-						    && pos_in_item <=
-						    entry_count) {
-							/* new directory entry falls into S_new[i] */
-
-							RFALSE(!tb->
-							       insert_size[0],
-							       "PAP-12215: insert_size is already 0");
-							RFALSE(tb->sbytes[i] - 1 >=
-							       entry_count,
-							       "PAP-12220: there are no so much entries (%d), only %d",
-							       tb->sbytes[i] - 1,
-							       entry_count);
-
-							/* Shift tb->snum[i]-1 items in whole. Shift tb->sbytes[i] directory entries from directory item number tb->snum[i] */
-							leaf_move_items
-							    (LEAF_FROM_S_TO_SNEW,
-							     tb, tb->snum[i],
-							     tb->sbytes[i] - 1,
-							     S_new[i]);
-							/* Paste given directory entry to directory item */
-							buffer_info_init_bh(tb, &bi, S_new[i]);
-							leaf_paste_in_buffer
-							    (&bi, 0,
-							     pos_in_item -
-							     entry_count +
-							     tb->sbytes[i] - 1,
-							     tb->insert_size[0],
-							     body, zeros_num);
-							/* paste new directory entry */
-							leaf_paste_entries(bi.
-									   bi_bh,
-									   0,
-									   pos_in_item
-									   -
-									   entry_count
-									   +
-									   tb->sbytes
-									   [i] -
-									   1, 1,
-									   (struct
-									    reiserfs_de_head
-									    *)
-									   body,
-									   body
-									   +
-									   DEH_SIZE,
-									   tb->
-									   insert_size
-									   [0]
-							    );
-							tb->insert_size[0] = 0;
-							pos_in_item++;
-						} else {	/* new directory entry doesn't fall into S_new[i] */
-							leaf_move_items
-							    (LEAF_FROM_S_TO_SNEW,
-							     tb, tb->snum[i],
-							     tb->sbytes[i],
-							     S_new[i]);
-						}
-					} else {	/* regular object */
-
-						int n_shift, n_rem,
-						    r_zeros_number;
-						const char *r_body;
-
-						RFALSE(pos_in_item !=
-						       ih_item_len
-						       (B_N_PITEM_HEAD
-							(tbS0, item_pos))
-						       || tb->insert_size[0] <=
-						       0,
-						       "PAP-12225: item too short or insert_size <= 0");
-
-						/* Calculate number of bytes which must be shifted from appended item */
-						n_shift =
-						    tb->sbytes[i] -
-						    tb->insert_size[0];
-						if (n_shift < 0)
-							n_shift = 0;
-						leaf_move_items
-						    (LEAF_FROM_S_TO_SNEW, tb,
-						     tb->snum[i], n_shift,
-						     S_new[i]);
-
-						/* Calculate number of bytes which must remain in body after append to S_new[i] */
-						n_rem =
-						    tb->insert_size[0] -
-						    tb->sbytes[i];
-						if (n_rem < 0)
-							n_rem = 0;
-						/* Append part of body into S_new[0] */
-						buffer_info_init_bh(tb, &bi, S_new[i]);
-						if (n_rem > zeros_num) {
-							r_zeros_number = 0;
-							r_body =
-							    body + n_rem -
-							    zeros_num;
-						} else {
-							r_body = body;
-							r_zeros_number =
-							    zeros_num - n_rem;
-							zeros_num -=
-							    r_zeros_number;
-						}
-
-						leaf_paste_in_buffer(&bi, 0,
-								     n_shift,
-								     tb->
-								     insert_size
-								     [0] -
-								     n_rem,
-								     r_body,
-								     r_zeros_number);
-						{
-							struct item_head *tmp;
-
-							tmp =
-							    B_N_PITEM_HEAD(S_new
-									   [i],
-									   0);
-							if (is_indirect_le_ih
-							    (tmp)) {
-								set_ih_free_space
-								    (tmp, 0);
-								set_le_ih_k_offset
-								    (tmp,
-								     le_ih_k_offset
-								     (tmp) +
-								     (n_rem <<
-								      (tb->
-								       tb_sb->
-								       s_blocksize_bits
-								       -
-								       UNFM_P_SHIFT)));
-							} else {
-								set_le_ih_k_offset
-								    (tmp,
-								     le_ih_k_offset
-								     (tmp) +
-								     n_rem);
-							}
-						}
-
-						tb->insert_size[0] = n_rem;
-						if (!n_rem)
-							pos_in_item++;
-					}
-				} else
-					/* item falls wholly into S_new[i] */
-				{
-					int ret_val;
-					struct item_head *pasted;
-
-#ifdef CONFIG_REISERFS_CHECK
-					struct item_head *ih =
-					    B_N_PITEM_HEAD(tbS0, item_pos);
-
-					if (!is_direntry_le_ih(ih)
-					    && (pos_in_item != ih_item_len(ih)
-						|| tb->insert_size[0] <= 0))
-						reiserfs_panic(tb->tb_sb,
-						               "PAP-12235",
-							       "pos_in_item must be equal to ih_item_len");
-#endif				/* CONFIG_REISERFS_CHECK */
-
-					ret_val =
-					    leaf_move_items(LEAF_FROM_S_TO_SNEW,
-							    tb, tb->snum[i],
-							    tb->sbytes[i],
-							    S_new[i]);
-
-					RFALSE(ret_val,
-					       "PAP-12240: unexpected value returned by leaf_move_items (%d)",
-					       ret_val);
-
-					/* paste into item */
-					buffer_info_init_bh(tb, &bi, S_new[i]);
-					leaf_paste_in_buffer(&bi,
-							     item_pos - n +
-							     tb->snum[i],
-							     pos_in_item,
-							     tb->insert_size[0],
-							     body, zeros_num);
-
-					pasted =
-					    B_N_PITEM_HEAD(S_new[i],
-							   item_pos - n +
-							   tb->snum[i]);
-					if (is_direntry_le_ih(pasted)) {
-						leaf_paste_entries(bi.bi_bh,
-								   item_pos -
-								   n + tb->snum[i],
-								   pos_in_item,
-								   1,
-								   (struct
-								    reiserfs_de_head
-								    *)body,
-								   body +
-								   DEH_SIZE,
-								   tb->
-								   insert_size
-								   [0]
-						    );
-					}
-
-					/* if we paste to indirect item update ih_free_space */
-					if (is_indirect_le_ih(pasted))
-						set_ih_free_space(pasted, 0);
-					zeros_num = tb->insert_size[0] = 0;
-				}
-			}
-
-			else {	/* pasted item doesn't fall into S_new[i] */
-
-				leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
-						tb->snum[i], tb->sbytes[i], S_new[i]);
-			}
-			break;
-		default:	/* cases d and t */
-			reiserfs_panic(tb->tb_sb, "PAP-12245",
-			               "blknum > 2: unexpected mode: %s(%d)",
-				       (flag ==
-					M_DELETE) ? "DELETE" : ((flag ==
-								 M_CUT) ? "CUT"
-								: "UNKNOWN"),
-				       flag);
-		}
-
-		memcpy(insert_key + i, B_N_PKEY(S_new[i], 0), KEY_SIZE);
-		insert_ptr[i] = S_new[i];
-
-		RFALSE(!buffer_journaled(S_new[i])
-		       || buffer_journal_dirty(S_new[i])
-		       || buffer_dirty(S_new[i]), "PAP-12247: S_new[%d] : (%b)",
-		       i, S_new[i]);
-	}
+	bl_new_nodes(tb, ih, body, flag, insert_key, insert_ptr,
+	                       &zeros_num, item_pos, &pos_in_item);
 
 	/* if the affected item was not wholly shifted then we perform all necessary operations on that part or whole of the
 	   affected item which remains in S */
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#36 lore raw

PATCH 36/40 reiserfs: split out current node handling from balance_leaf

In reply to [email protected]

This is the last in a set of 4 patches that split balance_leaf up into a group of functions rather than the 2500 beast it once was.

This patch splits off the current node balancing behavior.

---
 fs/reiserfs/do_balan.c |  273 +++++++++++++++++++++++++------------------------
 1 file changed, 142 insertions(+), 131 deletions(-)
fs/reiserfs/do_balan.c +142 -131
@@ -1210,6 +1210,146 @@ bl_new_nodes(struct tree_balance *tb, st
 	}
 }
 
+/* insert item into S[0] */
+static void
+bl_current_node_insert(struct tree_balance *tb, struct item_head *ih,
+                           const char *body, int flag, int zeros_num,
+                           int item_pos)
+{
+	struct buffer_info bi;
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	buffer_info_init_tbS0(tb, &bi);
+	leaf_insert_into_buf(&bi, item_pos, ih, body, zeros_num);
+
+	/* If we insert the first key change the delimiting key */
+	/* CFL[0] can be 0 in reiserfsck */
+	if (item_pos == 0 && tb->CFL[0])
+		replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
+}
+
+static void
+bl_current_node_paste_de_partial(struct tree_balance *tb,
+                                     struct item_head *ih, const char *body,
+                                     int flag, int zeros_num, int item_pos,
+                                     int pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *pasted = B_N_PITEM_HEAD(tbS0, item_pos);
+	struct buffer_info bi;
+
+	if (pos_in_item < 0 || pos_in_item > ih_entry_count(pasted))
+		return;
+
+	RFALSE(!tb->insert_size[0],
+	       "PAP-12260: insert_size is 0 already");
+
+	/* prepare space */
+	buffer_info_init_tbS0(tb, &bi);
+	leaf_paste_in_buffer(&bi, item_pos, pos_in_item, tb->insert_size[0],
+	                     body, zeros_num);
+
+	/* paste entry */
+	leaf_paste_entries(bi.bi_bh, item_pos, pos_in_item, 1,
+			   (struct reiserfs_de_head *)body, body + DEH_SIZE,
+			   tb->insert_size[0]);
+
+	if (!item_pos && !pos_in_item) {
+		RFALSE(!tb->CFL[0] || !tb->L[0],
+		       "PAP-12270: CFL[0]/L[0] must be specified");
+		if (tb->CFL[0])
+			replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
+	}
+	tb->insert_size[0] = 0;
+}
+
+static void
+bl_current_node_paste_non_de_partial(struct tree_balance *tb,
+                                         struct item_head *ih,
+                                         const char *body, int flag,
+                                         int zeros_num, int item_pos,
+                                         int pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *pasted = B_N_PITEM_HEAD(tbS0, item_pos);
+	struct buffer_info bi;
+
+#ifdef CONFIG_REISERFS_CHECK
+	if (pos_in_item != ih_item_len(pasted)) {
+		if (tb->insert_size[0]) {
+			print_cur_tb("12285");
+			reiserfs_panic(tb->tb_sb, "PAP-12285",
+			               "insert_size must be 0 (%d)",
+				       tb->insert_size[0]);
+		}
+		return;
+	}
+#endif
+	RFALSE(tb->insert_size[0] <= 0,
+	       "PAP-12275: insert size must not be %d", tb->insert_size[0]);
+	buffer_info_init_tbS0(tb, &bi);
+	leaf_paste_in_buffer(&bi, item_pos, pos_in_item, tb->insert_size[0],
+	                     body, zeros_num);
+
+	if (is_indirect_le_ih(pasted)) {
+#if 0
+		RFALSE(tb->insert_size[0] != UNFM_P_SIZE, "PAP-12280",
+		       "insert_size for indirect item must be %d, not %d",
+		       UNFM_P_SIZE, tb->insert_size[0]);
+#endif
+		set_ih_free_space (pasted, 0);
+	}
+	tb->insert_size[0] = 0;
+}
+
+static void
+bl_current_node_paste(struct tree_balance *tb, struct item_head *ih,
+                          const char *body, int flag, int zeros_num,
+                          int item_pos, int pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *pasted = B_N_PITEM_HEAD(tbS0, item_pos);
+	/* when directory, may be new entry already pasted */
+	if (is_direntry_le_ih(pasted))
+		bl_current_node_paste_de_partial(tb, ih, body, flag,
+		                                     zeros_num, item_pos,
+		                                     pos_in_item);
+	else
+		bl_current_node_paste_non_de_partial(tb, ih, body, flag,
+		                                         zeros_num, item_pos,
+		                                         pos_in_item);
+#ifdef CONFIG_REISERFS_CHECK
+	if (tb->insert_size[0]) {
+		print_cur_tb("12290");
+		reiserfs_panic(tb->tb_sb,
+		               "PAP-12290", "insert_size is still not 0 (%d)",
+		               tb->insert_size[0]);
+	}
+#endif				/* CONFIG_REISERFS_CHECK */
+}
+
+/* If the affected item was not wholly shifted then we perform all
+ * necessary operations on that part or whole of the affected item
+ * which remains in S */
+static void
+bl_current_node(struct tree_balance *tb, struct item_head *ih,
+		   const char *body, int flag, int zeros_num, int item_pos,
+		   int pos_in_item)
+{
+	BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+	/* if we must insert or append into buffer S[0] */
+	if (item_pos < 0 || item_pos >= tb->s0num)
+		return;
+
+	if (flag == M_INSERT)
+		bl_current_node_insert(tb, ih, body, flag, zeros_num,
+		                           item_pos);
+	else
+		bl_current_node_paste(tb, ih, body, flag, zeros_num,
+		                          item_pos, pos_in_item);
+}
+
+
 static int balance_leaf(struct tree_balance *tb, struct item_head *ih,	/* item header of inserted item (this is on little endian) */
 			const char *body,	/* body  of inserted item or bytes to paste */
 			int flag,	/* i - insert, d - delete, c - cut, p - paste
@@ -1224,7 +1364,6 @@ static int balance_leaf(struct tree_bala
 	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
 	int item_pos = PATH_LAST_POSITION(tb->tb_path);	/*  index into the array of item headers in S[0]
 							   of the affected item */
-	struct buffer_info bi;
 	int pos_in_item;
 	int zeros_num;
 
@@ -1290,137 +1429,9 @@ static int balance_leaf(struct tree_bala
 	bl_new_nodes(tb, ih, body, flag, insert_key, insert_ptr,
 	                       &zeros_num, item_pos, &pos_in_item);
 
-	/* if the affected item was not wholly shifted then we perform all necessary operations on that part or whole of the
-	   affected item which remains in S */
-	if (0 <= item_pos && item_pos < tb->s0num) {	/* if we must insert or append into buffer S[0] */
-
-		switch (flag) {
-		case M_INSERT:	/* insert item into S[0] */
-			buffer_info_init_tbS0(tb, &bi);
-			leaf_insert_into_buf(&bi, item_pos, ih, body,
-					     zeros_num);
-
-			/* If we insert the first key change the delimiting key */
-			if (item_pos == 0) {
-				if (tb->CFL[0])	/* can be 0 in reiserfsck */
-					replace_key(tb, tb->CFL[0], tb->lkey[0],
-						    tbS0, 0);
-
-			}
-			break;
+	bl_current_node(tb, ih, body, flag, zeros_num, item_pos,
+		          pos_in_item);
 
-		case M_PASTE:{	/* append item in S[0] */
-				struct item_head *pasted;
-
-				pasted = B_N_PITEM_HEAD(tbS0, item_pos);
-				/* when directory, may be new entry already pasted */
-				if (is_direntry_le_ih(pasted)) {
-					if (pos_in_item >= 0 &&
-					    pos_in_item <=
-					    ih_entry_count(pasted)) {
-
-						RFALSE(!tb->insert_size[0],
-						       "PAP-12260: insert_size is 0 already");
-
-						/* prepare space */
-						buffer_info_init_tbS0(tb, &bi);
-						leaf_paste_in_buffer(&bi,
-								     item_pos,
-								     pos_in_item,
-								     tb->
-								     insert_size
-								     [0], body,
-								     zeros_num);
-
-						/* paste entry */
-						leaf_paste_entries(bi.bi_bh,
-								   item_pos,
-								   pos_in_item,
-								   1,
-								   (struct
-								    reiserfs_de_head
-								    *)body,
-								   body +
-								   DEH_SIZE,
-								   tb->
-								   insert_size
-								   [0]
-						    );
-						if (!item_pos && !pos_in_item) {
-							RFALSE(!tb->CFL[0]
-							       || !tb->L[0],
-							       "PAP-12270: CFL[0]/L[0] must be specified");
-							if (tb->CFL[0]) {
-								replace_key(tb,
-									    tb->
-									    CFL
-									    [0],
-									    tb->
-									    lkey
-									    [0],
-									    tbS0,
-									    0);
-
-							}
-						}
-						tb->insert_size[0] = 0;
-					}
-				} else {	/* regular object */
-					if (pos_in_item == ih_item_len(pasted)) {
-
-						RFALSE(tb->insert_size[0] <= 0,
-						       "PAP-12275: insert size must not be %d",
-						       tb->insert_size[0]);
-						buffer_info_init_tbS0(tb, &bi);
-						leaf_paste_in_buffer(&bi,
-								     item_pos,
-								     pos_in_item,
-								     tb->
-								     insert_size
-								     [0], body,
-								     zeros_num);
-
-						if (is_indirect_le_ih(pasted)) {
-#if 0
-							RFALSE(tb->
-							       insert_size[0] !=
-							       UNFM_P_SIZE,
-							       "PAP-12280: insert_size for indirect item must be %d, not %d",
-							       UNFM_P_SIZE,
-							       tb->
-							       insert_size[0]);
-#endif
-							set_ih_free_space
-							    (pasted, 0);
-						}
-						tb->insert_size[0] = 0;
-					}
-#ifdef CONFIG_REISERFS_CHECK
-					else {
-						if (tb->insert_size[0]) {
-							print_cur_tb("12285");
-							reiserfs_panic(tb->
-								       tb_sb,
-								       "PAP-12285", "insert_size must be 0 (%d)",
-								       tb->
-								       insert_size
-								       [0]);
-						}
-					}
-#endif				/* CONFIG_REISERFS_CHECK */
-
-				}
-			}	/* case M_PASTE: */
-		}
-	}
-#ifdef CONFIG_REISERFS_CHECK
-	if (flag == M_PASTE && tb->insert_size[0]) {
-		print_cur_tb("12290");
-		reiserfs_panic(tb->tb_sb,
-		               "PAP-12290", "insert_size is still not 0 (%d)",
-		               tb->insert_size[0]);
-	}
-#endif				/* CONFIG_REISERFS_CHECK */
 	return 0;
 }				/* Leaf level of the tree is balanced (end of balance_leaf) */
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#37 lore raw

PATCH 37/40 reiserfs: clean up bl_when_delete

In reply to [email protected]
---
 fs/reiserfs/do_balan.c |   71 ++++++++++++++++++++++---------------------------
 1 file changed, 33 insertions(+), 38 deletions(-)
fs/reiserfs/do_balan.c +33 -38
@@ -115,6 +115,13 @@ static int balance_leaf_when_delete(stru
 	int n;
 	struct item_head *ih;
 
+	if (flag != M_DELETE && flag != M_CUT) {
+		print_cur_tb("12040");
+		reiserfs_panic(tb->tb_sb, "PAP-12040",
+		               "unexpected mode: %s(%d)",
+			       tb_mode_names(flag), flag);
+	}
+
 	RFALSE(tb->FR[0] && B_LEVEL(tb->FR[0]) != DISK_LEAF_NODE_LEVEL + 1,
 	       "vs- 12000: level: wrong FR %z", tb->FR[0]);
 	RFALSE(tb->blknum[0] > 1,
@@ -127,9 +134,7 @@ static int balance_leaf_when_delete(stru
 
 	/* Delete or truncate the item */
 
-	switch (flag) {
-	case M_DELETE:		/* delete item in S[0] */
-
+	if (flag == M_DELETE) {
 		RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0],
 		       "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
 		       -tb->insert_size[0], ih);
@@ -151,44 +156,34 @@ static int balance_leaf_when_delete(stru
 		RFALSE(!item_pos && !tb->CFL[0],
 		       "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->CFL[0],
 		       tb->L[0]);
+	} else { /* M_CUT */
+		if (is_direntry_le_ih(ih)) {
 
-		break;
-
-	case M_CUT:{		/* cut item in S[0] */
-			if (is_direntry_le_ih(ih)) {
-
-				/* UFS unlink semantics are such that you can only delete one directory entry at a time. */
-				/* when we cut a directory tb->insert_size[0] means number of entries to be cut (always 1) */
-				tb->insert_size[0] = -1;
-				leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
-						     -tb->insert_size[0]);
-
-				RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
-				       "PAP-12030: can not change delimiting key. CFL[0]=%p",
-				       tb->CFL[0]);
-
-				if (!item_pos && !pos_in_item && tb->CFL[0]) {
-					replace_key(tb, tb->CFL[0], tb->lkey[0],
-						    tbS0, 0);
-				}
-			} else {
-				leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
-						     -tb->insert_size[0]);
-
-				RFALSE(!ih_item_len(ih),
-				       "PAP-12035: cut must leave non-zero dynamic length of item");
+			/* UFS unlink semantics are such that
+			 * you can only delete one directory entry
+			 * at a time. */
+			/* when we cut a directory tb->insert_size[0]
+			 * means number of entries to be cut
+			 * (always 1) */
+			tb->insert_size[0] = -1;
+			leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
+					     -tb->insert_size[0]);
+
+			RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
+			       "PAP-12030: can not change delimiting key. CFL[0]=%p",
+			       tb->CFL[0]);
+
+			if (!item_pos && !pos_in_item && tb->CFL[0]) {
+				replace_key(tb, tb->CFL[0], tb->lkey[0],
+					    tbS0, 0);
 			}
-			break;
-		}
+		} else {
+			leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
+					     -tb->insert_size[0]);
 
-	default:
-		print_cur_tb("12040");
-		reiserfs_panic(tb->tb_sb, "PAP-12040",
-		               "unexpected mode: %s(%d)",
-			       (flag ==
-				M_PASTE) ? "PASTE" : ((flag ==
-						       M_INSERT) ? "INSERT" :
-						      "UNKNOWN"), flag);
+			RFALSE(!ih_item_len(ih), "PAP-12035: cut must "
+			       "leave non-zero dynamic length of item");
+		}
 	}
 
 	/* the rule is that no shifting occurs unless by shifting a node can be freed */
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#38 lore raw

PATCH 38/40 reiserfs: clean up balancing modes

In reply to [email protected]

This patch turns the character balancing modes into an enum, since the letter itself is irrelevant.

---
 fs/reiserfs/prints.c        |   17 +++++++++++++++++
 include/linux/reiserfs_fs.h |   34 ++++++++++++++++------------------
 2 files changed, 33 insertions(+), 18 deletions(-)
fs/reiserfs/prints.c +17 -0
@@ -14,6 +14,23 @@ static char error_buf[1024];
 static char fmt_buf[1024];
 static char off_buf[80];
 
+const char *tb_mode_names(enum tb_modes mode)
+{
+	char * const names[] = {
+	"INSERT",
+	"PASTE",
+	"DELETE",
+	"CUT",
+	"INTERNAL",
+	"SKIP_BALANCING",
+	"CONVERT",
+	};
+
+	if (mode >= M_MAX_MODES)
+		return "UNKNOWN";
+	return names[mode];
+}
+
 static char *reiserfs_cpu_offset(struct cpu_key *key)
 {
 	if (cpu_key_k_type(key) == TYPE_DIRENTRY)
include/linux/reiserfs_fs.h +16 -18
@@ -1388,27 +1388,24 @@ struct tree_balance {
 	struct in_core_key key;	/* key pointer, to pass to block allocator or
 				   another low-level subsystem */
 #endif
+	struct bl_context *context;
 };
 
 /* These are modes of balancing */
-
-/* When inserting an item. */
-#define M_INSERT	'i'
-/* When inserting into (directories only) or appending onto an already
-   existant item. */
-#define M_PASTE		'p'
-/* When deleting an item. */
-#define M_DELETE	'd'
-/* When truncating an item or removing an entry from a (directory) item. */
-#define M_CUT 		'c'
-
-/* used when balancing on leaf level skipped (in reiserfsck) */
-#define M_INTERNAL	'n'
-
-/* When further balancing is not needed, then do_balance does not need
-   to be called. */
-#define M_SKIP_BALANCING 		's'
-#define M_CONVERT	'v'
+enum tb_modes {
+	M_INSERT = 0,	/* When inserting an item. */
+	M_PASTE,	/* When inserting into (directories only) or
+			 * appending onto an already existant item. */
+	M_DELETE,	/* When deleting an item. */
+	M_CUT,		/* When truncating an item or removing an entry
+	                 * from a (directory) item. */
+	M_INTERNAL,	/* used when balancing on leaf level
+			 * skipped (in reiserfsck) */
+	M_SKIP_BALANCING, /* When further balancing is not needed,
+			   * then do_balance does not need to be called. */
+	M_CONVERT,
+	M_MAX_MODES
+};
 
 /* modes of leaf_move_items */
 #define LEAF_FROM_S_TO_L 0
@@ -2027,6 +2024,7 @@ void check_leaf(struct buffer_head *bh);
 void check_internal(struct buffer_head *bh);
 void print_statistics(struct super_block *s);
 char *reiserfs_hashname(int code);
+const char *tb_mode_names(enum tb_modes);
 
 /* lbalance.c */
 int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#39 lore raw

PATCH 39/40 reiserfs: split bl_when_delete

In reply to [email protected]

This patch splits bl_when_delete into two functions so that it is more easily readable.

---
 fs/reiserfs/do_balan.c |  147 +++++++++++++++++++++++++------------------------
 1 file changed, 77 insertions(+), 70 deletions(-)
fs/reiserfs/do_balan.c +77 -70
@@ -9,7 +9,7 @@
 /* and using buffers obtained after all above.				*/
 
 /**
- ** balance_leaf_when_delete
+ ** bl_when_delete
  ** balance_leaf
  ** do_balance
  **
@@ -78,7 +78,7 @@ inline void do_balance_mark_leaf_dirty(s
 
 /* summary:
  if deleting something ( tb->insert_size[0] < 0 )
-   return(balance_leaf_when_delete()); (flag d handled here)
+   return(bl_when_delete()); (flag d handled here)
  else
    if lnum is larger than 0 we put items into the left node
    if rnum is larger than 0 we put items into the right node
@@ -88,7 +88,7 @@ Note that all *num* count new items bein
 
 It would be easier to read balance_leaf() if each of these summary
 lines was a separate procedure rather than being inlined.  I think
-that there are many passages here and in balance_leaf_when_delete() in
+that there are many passages here and in bl_when_delete() in
 which two calls to one procedure can replace two passages, and it
 might save cache space and improve software maintenance costs to do so.
 
@@ -99,6 +99,54 @@ be performed by do_balance.
 
 -Hans */
 
+/* L[0] must be joined with S[0] */
+static int bl_delete_merge_left(struct tree_balance *tb)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+
+	/* R[0] must be also joined with S[0] */
+	if (tb->rnum[0] == -1) {
+		if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
+			/* all contents of all the 3 buffers will be in L[0] */
+			if (PATH_H_POSITION(tb->tb_path, 1) == 0 &&
+		            B_NR_ITEMS(tb->FR[0]) > 1)
+				replace_key(tb, tb->CFL[0], tb->lkey[0],
+					    tb->FR[0], 1);
+
+			leaf_move_items(LEAF_FROM_S_TO_L, tb, n, -1, NULL);
+			leaf_move_items(LEAF_FROM_R_TO_L, tb,
+					B_NR_ITEMS(tb->R[0]), -1, NULL);
+
+			reiserfs_invalidate_buffer(tb, tbS0);
+			reiserfs_invalidate_buffer(tb, tb->R[0]);
+
+			return 0;
+		}
+		/* all contents of all the 3 buffers will be in R[0] */
+		leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1, NULL);
+		leaf_move_items(LEAF_FROM_L_TO_R, tb, B_NR_ITEMS(tb->L[0]),
+		                -1, NULL);
+
+		/* right_delimiting_key is correct in R[0] */
+		replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+
+		reiserfs_invalidate_buffer(tb, tbS0);
+		reiserfs_invalidate_buffer(tb, tb->L[0]);
+
+		return -1;
+	}
+
+	RFALSE(tb->rnum[0] != 0,
+	       "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
+
+	/* all contents of L[0] and S[0] will be in L[0] */
+	leaf_shift_left(tb, n, -1);
+	reiserfs_invalidate_buffer(tb, tbS0);
+	return 0;
+
+}
+
 /* Balance leaf node in case of delete or cut: insert_size[0] < 0
  *
  * lnum, rnum can have values >= -1
@@ -106,14 +154,13 @@ be performed by do_balance.
  *	 0 means that nothing should be done with the neighbor
  *	>0 means to shift entirely or partly the specified number of items to the neighbor
  */
-static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
+static int bl_when_delete(struct tree_balance *tb, int flag)
 {
-	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
 	int item_pos = PATH_LAST_POSITION(tb->tb_path);
-	int pos_in_item = tb->tb_path->pos_in_item;
+	int n, pos_in_item = tb->tb_path->pos_in_item;
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *ih = B_N_PITEM_HEAD(tbS0, item_pos);
 	struct buffer_info bi;
-	int n;
-	struct item_head *ih;
 
 	if (flag != M_DELETE && flag != M_CUT) {
 		print_cur_tb("12040");
@@ -129,22 +176,20 @@ static int balance_leaf_when_delete(stru
 	RFALSE(!tb->blknum[0] && !PATH_H_PPARENT(tb->tb_path, 0),
 	       "PAP-12010: tree can not be empty");
 
-	ih = B_N_PITEM_HEAD(tbS0, item_pos);
 	buffer_info_init_tbS0(tb, &bi);
 
 	/* Delete or truncate the item */
-
 	if (flag == M_DELETE) {
 		RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0],
-		       "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
-		       -tb->insert_size[0], ih);
+		       "vs-12013: mode Delete, insert size %d, "
+		       "ih to be deleted %h", -tb->insert_size[0], ih);
 
 		leaf_delete_items(&bi, 0, item_pos, 1, -1);
 
 		if (!item_pos && tb->CFL[0]) {
 			if (B_NR_ITEMS(tbS0)) {
-				replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0,
-					    0);
+				replace_key(tb, tb->CFL[0], tb->lkey[0],
+				            tbS0, 0);
 			} else {
 				if (!PATH_H_POSITION(tb->tb_path, 1))
 					replace_key(tb, tb->CFL[0], tb->lkey[0],
@@ -170,8 +215,8 @@ static int balance_leaf_when_delete(stru
 					     -tb->insert_size[0]);
 
 			RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
-			       "PAP-12030: can not change delimiting key. CFL[0]=%p",
-			       tb->CFL[0]);
+			       "PAP-12030: can not change delimiting key. "
+			       "CFL[0]=%p", tb->CFL[0]);
 
 			if (!item_pos && !pos_in_item && tb->CFL[0]) {
 				replace_key(tb, tb->CFL[0], tb->lkey[0],
@@ -186,69 +231,31 @@ static int balance_leaf_when_delete(stru
 		}
 	}
 
-	/* the rule is that no shifting occurs unless by shifting a node can be freed */
+	/* the rule is that no shifting occurs unless by
+	 * shifting a node can be freed */
 	n = B_NR_ITEMS(tbS0);
-	if (tb->lnum[0]) {	/* L[0] takes part in balancing */
-		if (tb->lnum[0] == -1) {	/* L[0] must be joined with S[0] */
-			if (tb->rnum[0] == -1) {	/* R[0] must be also joined with S[0] */
-				if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
-					/* all contents of all the 3 buffers will be in L[0] */
-					if (PATH_H_POSITION(tb->tb_path, 1) == 0
-					    && 1 < B_NR_ITEMS(tb->FR[0]))
-						replace_key(tb, tb->CFL[0],
-							    tb->lkey[0],
-							    tb->FR[0], 1);
-
-					leaf_move_items(LEAF_FROM_S_TO_L, tb, n,
-							-1, NULL);
-					leaf_move_items(LEAF_FROM_R_TO_L, tb,
-							B_NR_ITEMS(tb->R[0]),
-							-1, NULL);
-
-					reiserfs_invalidate_buffer(tb, tbS0);
-					reiserfs_invalidate_buffer(tb,
-								   tb->R[0]);
-
-					return 0;
-				}
-				/* all contents of all the 3 buffers will be in R[0] */
-				leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1,
-						NULL);
-				leaf_move_items(LEAF_FROM_L_TO_R, tb,
-						B_NR_ITEMS(tb->L[0]), -1, NULL);
-
-				/* right_delimiting_key is correct in R[0] */
-				replace_key(tb, tb->CFR[0], tb->rkey[0],
-					    tb->R[0], 0);
-
-				reiserfs_invalidate_buffer(tb, tbS0);
-				reiserfs_invalidate_buffer(tb, tb->L[0]);
-
-				return -1;
-			}
-
-			RFALSE(tb->rnum[0] != 0,
-			       "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
-			/* all contents of L[0] and S[0] will be in L[0] */
-			leaf_shift_left(tb, n, -1);
-
-			reiserfs_invalidate_buffer(tb, tbS0);
-
-			return 0;
-		}
-		/* a part of contents of S[0] will be in L[0] and the rest part of S[0] will be in R[0] */
+	/* L[0] takes part in balancing */
+	if (tb->lnum[0]) {
+		/* L[0] must be joined with S[0] */
+		if (tb->lnum[0] == -1)
+			return bl_delete_merge_left(tb);
 
+		/* a part of contents of S[0] will be in L[0] and
+		 * the rest part of S[0] will be in R[0] */
 		RFALSE((tb->lnum[0] + tb->rnum[0] < n) ||
 		       (tb->lnum[0] + tb->rnum[0] > n + 1),
-		       "PAP-12050: rnum(%d) and lnum(%d) and item number(%d) in S[0] are not consistent",
+		       "PAP-12050: rnum(%d) and lnum(%d) and "
+		       "item number(%d) in S[0] are not consistent",
 		       tb->rnum[0], tb->lnum[0], n);
 		RFALSE((tb->lnum[0] + tb->rnum[0] == n) &&
 		       (tb->lbytes != -1 || tb->rbytes != -1),
-		       "PAP-12055: bad rbytes (%d)/lbytes (%d) parameters when items are not split",
+		       "PAP-12055: bad rbytes (%d)/lbytes (%d) "
+		       "parameters when items are not split",
 		       tb->rbytes, tb->lbytes);
 		RFALSE((tb->lnum[0] + tb->rnum[0] == n + 1) &&
 		       (tb->lbytes < 1 || tb->rbytes != -1),
-		       "PAP-12060: bad rbytes (%d)/lbytes (%d) parameters when items are split",
+		       "PAP-12060: bad rbytes (%d)/lbytes (%d) "
+		       "parameters when items are split",
 		       tb->rbytes, tb->lbytes);
 
 		leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
@@ -1366,7 +1373,7 @@ static int balance_leaf(struct tree_bala
 
 	/* Make balance in case insert_size[0] < 0 */
 	if (tb->insert_size[0] < 0)
-		return balance_leaf_when_delete(tb, flag);
+		return bl_when_delete(tb, flag);
 
 	zeros_num = 0;
 	if (flag == M_INSERT && body == 0)
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#40 lore raw

PATCH 40/40 reiserfs: reorganize do_balan.c comments

In reply to [email protected]

This patch just shuffles some comments around to make them more useful, as well as formatted in a more readable manner.

---
 fs/reiserfs/do_balan.c |  233 ++++++++++++++++++++++---------------------------
 1 file changed, 108 insertions(+), 125 deletions(-)
fs/reiserfs/do_balan.c +108 -125
@@ -1,20 +1,47 @@
 /*
  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
+ *
+ * Big rule: Nothing performed during balance_leaf() may schedule. This
+ * is to ensure that the tree will be stable during the entire balancing
+ * run. This is clearly suboptimal for multithreaded use, but making
+ * the tree locking more scalable is a huge project that nobody has
+ * decided to take on yet.
+ *
+ * Summary:
+ *  if deleting/cutting something ( tb->insert_size[0] < 0 )
+ *    return(bl_when_delete());
+ *  else
+ *    if lnum is larger than 0 we put items into the left node
+ *    if rnum is larger than 0 we put items into the right node
+ *    if tb->snum[0] is larger than 0 we put items into the new node s1
+ *    if tb->snum[1] is larger than 0 we put items into the new node s2
+ * Note that all *num* count new items being created.
+ *
+ * Some interesting rules of balancing:
+ *
+ * we delete a maximum of two nodes per level per balancing: we never
+ * delete R, when we delete two of three nodes L, S, R then we move
+ * them into R.
+ *
+ * we only delete L if we are deleting two nodes, if we delete only
+ * one node we delete S
+ *
+ * if we shift leaves then we shift as much as we can: this is a
+ * deliberate policy of extremism in node packing which results in
+ * higher average utilization after repeated random balance operations
+ * at the cost of more memory copies and more balancing as a result of
+ * small insertions to full nodes.
+ *
+ * if we shift internal nodes we try to evenly balance the node
+ * utilization, with consequent less balancing at the cost of lower
+ * utilization.
+ *
+ * one could argue that the policy for directories in leaves should be
+ * that of internal nodes, but we will wait until another day to
+ * evaluate this....  It would be nice to someday measure and prove
+ * these assumptions as to what is optimal....
  */
 
-/* Now we have all buffers that must be used in balancing of the tree 	*/
-/* Further calculations can not cause schedule(), and thus the buffer 	*/
-/* tree will be stable until the balancing will be finished 		*/
-/* balance the tree according to the analysis made before,		*/
-/* and using buffers obtained after all above.				*/
-
-/**
- ** bl_when_delete
- ** balance_leaf
- ** do_balance
- **
- **/
-
 #include <asm/uaccess.h>
 #include <linux/time.h>
 #include <linux/reiserfs_fs.h>
@@ -76,29 +103,6 @@ inline void do_balance_mark_leaf_dirty(s
 #define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
 #define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
 
-/* summary:
- if deleting something ( tb->insert_size[0] < 0 )
-   return(bl_when_delete()); (flag d handled here)
- else
-   if lnum is larger than 0 we put items into the left node
-   if rnum is larger than 0 we put items into the right node
-   if tb->snum[0] is larger than 0 we put items into the new node s1
-   if tb->snum[1] is larger than 0 we put items into the new node s2
-Note that all *num* count new items being created.
-
-It would be easier to read balance_leaf() if each of these summary
-lines was a separate procedure rather than being inlined.  I think
-that there are many passages here and in bl_when_delete() in
-which two calls to one procedure can replace two passages, and it
-might save cache space and improve software maintenance costs to do so.
-
-Vladimir made the perceptive comment that we should offload most of
-the decision making in this function into fix_nodes/check_balance, and
-then create some sort of structure in tb that says what actions should
-be performed by do_balance.
-
--Hans */
-
 /* L[0] must be joined with S[0] */
 static int bl_delete_merge_left(struct tree_balance *tb)
 {
@@ -1352,20 +1356,30 @@ bl_current_node(struct tree_ba
 }
 
 
-static int balance_leaf(struct tree_balance *tb, struct item_head *ih,	/* item header of inserted item (this is on little endian) */
-			const char *body,	/* body  of inserted item or bytes to paste */
-			int flag,	/* i - insert, d - delete, c - cut, p - paste
-					   (see comment to do_balance) */
-			struct item_head *insert_key,	/* in our processing of one level we sometimes determine what
-							   must be inserted into the next higher level.  This insertion
-							   consists of a key or two keys and their corresponding
-							   pointers */
-			struct buffer_head **insert_ptr	/* inserted node-ptrs for the next level */
-    )
+/*
+ * balance_leaf(): The core driver for balancing the leaf level of reiserfs
+ *                 s-trees. This function completes successfully or panics.
+ *                 Upon successful completion, the leaf level is balanced.
+ *
+ * @tb:         tree balance struct containing state of this balance
+ * @ih:         item header of inserted item (this is on little endian)
+ * @body:       body of inserted item or bytes to paste
+ * @flag:	One of M_INSERT, M_PASTE, M_DELETE, or M_CUT
+ * @insert_key:	In our processing of one level we sometimes determine what
+ *              must be inserted into the next higher level.  This insertion
+ *              consists of a key or two keys and their corresponding
+ *              pointers
+ * @insert_ptr:	inserted node-ptrs for the next level
+ */
+static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
+                        const char *body, int flag,
+                        struct item_head *insert_key,
+                        struct buffer_head **insert_ptr)
 {
 	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
-	int item_pos = PATH_LAST_POSITION(tb->tb_path);	/*  index into the array of item headers in S[0]
-							   of the affected item */
+	/* index into the array of item headers in S[0]
+         * of the affected item */
+	int item_pos = PATH_LAST_POSITION(tb->tb_path);
 	int pos_in_item;
 	int zeros_num;
 
@@ -1435,7 +1449,7 @@ static int balance_leaf(struct tree_bala
 		          pos_in_item);
 
 	return 0;
-}				/* Leaf level of the tree is balanced (end of balance_leaf) */
+}	/* Leaf level of the tree is balanced (end of balance_leaf) */
 
 /* Make empty node */
 void make_empty_node(struct buffer_info *bi)
@@ -1449,7 +1463,7 @@ void make_empty_node(struct buffer_info 
 	set_blkh_free_space(blkh, MAX_CHILD_SIZE(bi->bi_bh));
 
 	if (bi->bi_parent)
-		B_N_CHILD(bi->bi_parent, bi->bi_position)->dc_size = 0;	/* Endian safe if 0 */
+		B_N_CHILD(bi->bi_parent, bi->bi_position)->dc_size = 0;
 }
 
 /* Get first empty buffer */
@@ -1490,7 +1504,8 @@ static void store_thrown(struct tree_bal
 			get_bh(bh);	/* free_thrown puts this */
 			return;
 		}
-	reiserfs_warning(tb->tb_sb, "reiserfs-12321", "too many thrown buffers");
+	reiserfs_warning(tb->tb_sb, "reiserfs-12321",
+	                 "too many thrown buffers");
 }
 
 static void free_thrown(struct tree_balance *tb)
@@ -1504,7 +1519,8 @@ static void free_thrown(struct tree_bala
 				reiserfs_warning(tb->tb_sb, "reiserfs-12322",
 				                 "called with dirty buffer %d",
 				                 blocknr);
-			brelse(tb->thrown[i]);	/* incremented in store_thrown */
+			/* incremented in store_thrown */
+			brelse(tb->thrown[i]);
 			reiserfs_free_block(tb->transaction_handle, NULL,
 					    blocknr, 0);
 		}
@@ -1530,9 +1546,8 @@ void replace_key(struct tree_balance *tb
 	RFALSE(dest == NULL || src == NULL,
 	       "vs-12305: source or destination buffer is 0 (src=%p, dest=%p)",
 	       src, dest);
-	RFALSE(!B_IS_KEYS_LEVEL(dest),
-	       "vs-12310: invalid level (%z) for destination buffer. dest must be leaf",
-	       dest);
+	RFALSE(!B_IS_KEYS_LEVEL(dest), "vs-12310: invalid level (%z) "
+	       "for destination buffer. dest must be leaf", dest);
 	RFALSE(n_dest < 0 || n_src < 0,
 	       "vs-12315: src(%d) or dest(%d) key number < 0", n_src, n_dest);
 	RFALSE(n_dest >= B_NR_ITEMS(dest) || n_src >= B_NR_ITEMS(src),
@@ -1723,39 +1738,6 @@ static void check_internal_levels(struct
 
 #endif
 
-/* Now we have all of the buffers that must be used in balancing of
-   the tree.  We rely on the assumption that schedule() will not occur
-   while do_balance works. ( Only interrupt handlers are acceptable.)
-   We balance the tree according to the analysis made before this,
-   using buffers already obtained.  For SMP support it will someday be
-   necessary to add ordered locking of tb. */
-
-/* Some interesting rules of balancing:
-
-   we delete a maximum of two nodes per level per balancing: we never
-   delete R, when we delete two of three nodes L, S, R then we move
-   them into R.
-
-   we only delete L if we are deleting two nodes, if we delete only
-   one node we delete S
-
-   if we shift leaves then we shift as much as we can: this is a
-   deliberate policy of extremism in node packing which results in
-   higher average utilization after repeated random balance operations
-   at the cost of more memory copies and more balancing as a result of
-   small insertions to full nodes.
-
-   if we shift internal nodes we try to evenly balance the node
-   utilization, with consequent less balancing at the cost of lower
-   utilization.
-
-   one could argue that the policy for directories in leaves should be
-   that of internal nodes, but we will wait until another day to
-   evaluate this....  It would be nice to someday measure and prove
-   these assumptions as to what is optimal....
-
-*/
-
 static inline void do_balance_starts(struct tree_balance *tb)
 {
 	/* use print_cur_tb() to see initial state of struct
@@ -1794,43 +1776,45 @@ static inline void do_balance_completed(
 	free_thrown(tb);
 }
 
-void do_balance(struct tree_balance *tb,	/* tree_balance structure */
-		struct item_head *ih,	/* item header of inserted item */
-		const char *body,	/* body  of inserted item or bytes to paste */
-		int flag)
-{				/* i - insert, d - delete
-				   c - cut, p - paste
-
-				   Cut means delete part of an item
-				   (includes removing an entry from a
-				   directory).
-
-				   Delete means delete whole item.
-
-				   Insert means add a new item into the
-				   tree.
-
-				   Paste means to append to the end of an
-				   existing file or to insert a directory
-				   entry.  */
-	int child_pos,		/* position of a child node in its parent */
-	 h;			/* level of the tree being processed */
-	struct item_head insert_key[2];	/* in our processing of one level
-					   we sometimes determine what
-					   must be inserted into the next
-					   higher level.  This insertion
-					   consists of a key or two keys
-					   and their corresponding
-					   pointers */
-	struct buffer_head *insert_ptr[2];	/* inserted node-ptrs for the next
-						   level */
+/*
+ * do_balance(): The driver function for tree balancing. We balance the leaf
+ *               level first, and then update the internal tree to match.
+ *
+ * @tb: struct tree_balance containing state of balancing
+ * @ih: item header of inserted item
+ * @body: body of inserted item or bytes to paste
+ * @flag: One of M_INSERT, M_PASTE, M_DELETE, or M_CUT:
+ *        M_INSERT: Add a new item to the tree
+ *        M_PASTE:  Extend an existing item, e.g. appending a file or
+ *                  adding a new directory entry
+ *        M_DELETE: Delete the entire item
+ *        M_CUT:    Delete part of an item, e.g. removing a directory entry
+ */
+void do_balance(struct tree_balance *tb, struct item_head *ih,
+                const char *body, int flag)
+{
+	/* position of a child node in its parent */
+	int child_pos = PATH_H_B_ITEM_ORDER(tb->tb_path, 0);
+
+	/* level of the tree being processed */
+	int h;
+
+	/* in our processing of one level we sometimes determine what
+         * must be inserted into the next higher level.  This insertion
+         * consists of a key or two keys and their corresponding pointers */
+	struct item_head insert_key[2];
+
+	/* Buffers added to the leaf level that must be tracked for
+	 * balancing the internal levels. */
+	struct buffer_head *insert_ptr[2];
 
 	tb->tb_mode = flag;
 	tb->need_balance_dirty = 0;
 
-	if (FILESYSTEM_CHANGED_TB(tb)) {
-		reiserfs_panic(tb->tb_sb, "clm-6000", "fs generation has changed");
-	}
+	if (FILESYSTEM_CHANGED_TB(tb))
+		reiserfs_panic(tb->tb_sb, "clm-6000",
+		               "fs generation has changed");
+
 	/* if we have no real work to do  */
 	if (!tb->insert_size[0]) {
 		reiserfs_warning(tb->tb_sb, "PAP-12350",
@@ -1845,8 +1829,7 @@ void do_balance(struct tree_balance *tb,
 	/* balance leaf returns 0 except if combining L R and S into
 	   one node.  see balance_internal() for explanation of this
 	   line of code. */
-	child_pos = PATH_H_B_ITEM_ORDER(tb->tb_path, 0) +
-	    balance_leaf(tb, ih, body, flag, insert_key, insert_ptr);
+	child_pos += balance_leaf(tb, ih, body, flag, insert_key, insert_ptr);
 
 #ifdef CONFIG_REISERFS_CHECK
 	check_after_balance_leaf(tb);
@@ -1854,8 +1837,8 @@ void do_balance(struct tree_balance *tb,
 
 	/* Balance internal level of the tree. */
 	for (h = 1; h < MAX_HEIGHT && tb->insert_size[h]; h++)
-		child_pos =
-		    balance_internal(tb, h, child_pos, insert_key, insert_ptr);
+		child_pos = balance_internal(tb, h, child_pos,
+		                             insert_key, insert_ptr);
 
 	do_balance_completed(tb);
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#41 lore raw
In reply to [email protected]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · [email protected] wrote:

Hi all -

The following are a series of patches that have been kicking around for a while. I thought I'd just put them out there to gauge interest and to get some testing before submitting to -mm.

I've re-ordered a few of the patches. This is actually four distinct, unrelated, though context-dependent, patch series. I've moved the trivial changes to the front of the list to better reflect that.

Five, of course. :)

The next time I mail the series out, I'll split them up so that I don't need to keep dropping 40 patches on the list. They're divided up on the FTP site now.

- -Jeff

- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFGbaB5LPWxlyuTD7IRAplzAJ9FzNXqFSuUHr93LGIR5vFQ8S/CxgCcDbFS dwHuhG72z3LHuWAG1c403C4=
=Sg9p
-----END PGP SIGNATURE-----

#42 lore raw
In reply to [email protected]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · [email protected] wrote:

* Clean up do_balan.c (31-40)
- Factor out buffer_info initializations.
- Turn tb->s[12]num and tb[12]bytes into an array.
- Split balance_leaf from the 2500 line beast to more manageable chunks.
- Clean up balance_leaf_when_delete.
- Clean up comments.

Consider these unusable. They've been reliably introducing corruption on my local machine.

- -Jeff

- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD4DBQFGcZnULPWxlyuTD7IRAtpmAJd6y6x4+OQ3kvWO2tnsBCfD4SZfAKCZb3E+ sNkwhvMQEugLia0axi/18w==
=MK4x
-----END PGP SIGNATURE-----