Skip to contentSkip to conversation

reiserfs: journaled xattrs

PATCH In review Jeff Mahoney 1 participant 1 message Feb 20, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 9/11 reiserfs: journaled xattrs

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            |   55 ++++++++++++++++++++---
 fs/reiserfs/xattr_acl.c        |   98 +++++++++++++++++++++++++++++++----------
 include/linux/reiserfs_acl.h   |    3 -
 include/linux/reiserfs_xattr.h |   31 ++++++++++++
 6 files changed, 163 insertions(+), 41 deletions(-)
fs/reiserfs/inode.c +1 -2
diff -ruNpX ../dontdiff linux-2.6.15-staging1/fs/reiserfs/inode.c linux-2.6.15-staging2/fs/reiserfs/inode.c
@@ -1944,9 +1944,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
diff -ruNpX ../dontdiff linux-2.6.15-staging1/fs/reiserfs/namei.c linux-2.6.15-staging2/fs/reiserfs/namei.c
@@ -615,15 +615,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);
@@ -677,7 +675,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;
@@ -687,8 +684,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);
@@ -745,7 +741,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 */
@@ -757,8 +752,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);
@@ -1045,8 +1039,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_acl.c +76 -22

163 lines not on this page · raw message

fs/reiserfs/xattr.c +50 -5

78 lines not on this page · raw message

include/linux/reiserfs_acl.h +2 -1
diff -ruNpX ../dontdiff linux-2.6.15-staging1/include/linux/reiserfs_acl.h linux-2.6.15-staging2/include/linux/reiserfs_acl.h
@@ -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_xattr.h +31 -0
diff -ruNpX ../dontdiff linux-2.6.15-staging1/include/linux/reiserfs_xattr.h linux-2.6.15-staging2/include/linux/reiserfs_xattr.h
@@ -32,6 +32,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;
@@ -44,6 +45,36 @@ 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) (_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 blocks_per_object = (JOURNAL_PER_BALANCE_CNT * 3 + 2 *
+	                        (REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb) +
+				 REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb)));
+	size_t nblocks = blocks_per_object;
+
+	if (REISERFS_SB(inode->i_sb)->xattr_root == NULL)
+		nblocks += blocks_per_object;
+
+	if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0)
+		nblocks += blocks_per_object;
+
+	return nblocks;
+}
+
 #else
 
 #define is_reiserfs_priv_object(inode) 0