shithub: lwext4

Download patch

ref: 716af5fa6399c4a8be1a87331fc70b5d3cf537ae
parent: 5372f03b3a0947f9c14a8bf015404f2fa0c71db2
author: ngkaho1234 <[email protected]>
date: Mon May 16 06:19:41 EDT 2016

ext4_xattr: allow more entries to be inserted when space is small

--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -458,23 +458,6 @@
 		return NULL;
 	}
 
-	if ((xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
-		EXT4_XATTR_LEN(item->name_len)
-			>
-	    ext4_xattr_inode_space(xattr_ref) -
-	    	sizeof(struct ext4_xattr_ibody_header))
-		&&
-	    (xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
-		EXT4_XATTR_LEN(item->name_len) >
-	    ext4_xattr_block_space(xattr_ref) -
-	    	sizeof(struct ext4_xattr_header))) {
-		ext4_xattr_item_free(item);
-
-		if (err)
-			*err = ENOSPC;
-
-		return NULL;
-	}
 	item->in_inode = true;
 	if (xattr_ref->inode_size_rem <
 	    EXT4_XATTR_SIZE(data_size) +
@@ -562,24 +545,8 @@
 
 	/*
 	 * Check if we can hold this entry in both in-inode and
-	 * on-block form
-	 */
-	if ((xattr_ref->ea_size - EXT4_XATTR_SIZE(old_data_size) +
-		EXT4_XATTR_SIZE(new_data_size)
-			>
-	    ext4_xattr_inode_space(xattr_ref) -
-		sizeof(struct ext4_xattr_ibody_header))
-		&&
-	    (xattr_ref->ea_size - EXT4_XATTR_SIZE(old_data_size) +
-		EXT4_XATTR_SIZE(new_data_size)
-			>
-	    ext4_xattr_block_space(xattr_ref) -
-		sizeof(struct ext4_xattr_header))) {
-
-		return ENOSPC;
-	}
-
-	/*
+	 * on-block form.
+	 *
 	 * More complicated case: we do not allow entries stucking in
 	 * the middle between in-inode space and on-block space, so
 	 * the entry has to stay in either inode space or block space.
@@ -836,9 +803,7 @@
 	}
 	RB_FOREACH_SAFE(item, ext4_xattr_tree, &xattr_ref->root, save_item)
 	{
-		if (EXT4_XATTR_SIZE(item->data_size) +
-			EXT4_XATTR_LEN(item->name_len) <=
-		    inode_size_rem) {
+		if (item->in_inode) {
 			ibody_data = (char *)ibody_data -
 				     EXT4_XATTR_SIZE(item->data_size);
 			ext4_xattr_set_inode_entry(item, ibody_header, entry,