Skip to contentSkip to conversation

cleanup btrfs_ioctl_setflags and btrfs_set_prop

PATCH In review Anand Jain 2 participants 14 messages Apr 20, 2019 – Apr 26, 2019 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover cleanup btrfs_ioctl_setflags and btrfs_set_prop

A set of pathes to clean up btrfs_ioctl_setflags(), btrfs_set_prop_trans() and btrfs_set_prop(). So as to avoidi duplicate code in btrfs_ioctl_setflags() and killing of btrfs_set_prop_trans().

Anand Jain (10):
btrfs: refactor btrfs_set_props to validate externally
btrfs: export btrfs_set_prop
btrfs: start transaction in btrfs_ioctl_setflags()
btrfs: drop useless inode i_flags copy and restore
btrfs: make a local copy of btrfs_inode flags before update
btrfs: drop old_fsflags in btrfs_ioctl_setflags
btrfs: drop local copy of inode i_mode
btrfs: start transaction in xattr_handler_set_prop
btrfs: delete unused function btrfs_set_prop_trans
btrfs: btrfs_set_prop trans is never null

 fs/btrfs/ioctl.c | 111 ++++++++++++++++++++++-------------------------
 fs/btrfs/props.c |  56 ++++++++++--------------
 fs/btrfs/props.h |   6 ++-
 fs/btrfs/xattr.c |  26 ++++++++++-
 4 files changed, 105 insertions(+), 94 deletions(-)
Signature · 1 line
2.20.1 (Apple Git-117)
author
#1 lore raw

PATCH 1/10 btrfs: refactor btrfs_set_props to validate externally

In preparation to merge multiple transactions when setting the compression flags, split btrfs_set_props() validation part outside of it.

---
 fs/btrfs/ioctl.c |  3 +++
 fs/btrfs/props.c | 23 +++++++++++++++++------
 fs/btrfs/props.h |  1 +
 fs/btrfs/xattr.c |  5 +++++
 4 files changed, 26 insertions(+), 6 deletions(-)
fs/btrfs/ioctl.c +3 -0
index 8c9a908d3acc..63e6e2f5b659 100644
@@ -284,6 +284,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 		binode->flags &= ~BTRFS_INODE_COMPRESS;
 		binode->flags |= BTRFS_INODE_NOCOMPRESS;
 
+		/* set no-compression no need to validate prop here */
 		ret = btrfs_set_prop_trans(inode, "btrfs.compression", NULL,
 					   0, 0);
 		if (ret && ret != -ENODATA)
@@ -299,6 +300,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 		binode->flags |= BTRFS_INODE_COMPRESS;
 		binode->flags &= ~BTRFS_INODE_NOCOMPRESS;
 
+		/* compress_type is already validated during mount options */
 		comp = btrfs_compress_type2str(fs_info->compress_type);
 		if (!comp || comp[0] == 0)
 			comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB);
@@ -309,6 +311,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 			goto out_drop;
 
 	} else {
+		/* reset prop, no need of validate prop here */
 		ret = btrfs_set_prop_trans(inode, "btrfs.compression", NULL,
 					   0, 0);
 		if (ret && ret != -ENODATA)
fs/btrfs/props.c +17 -6
index 44b7bf647ab3..e356dd2a0f73 100644
@@ -55,6 +55,23 @@ find_prop_handler(const char *name,
 	return NULL;
 }
 
+int btrfs_validate_prop(const char *name, const char *value, size_t value_len)
+{
+	const struct prop_handler *handler;
+
+	if (strlen(name) <= XATTR_BTRFS_PREFIX_LEN)
+		return -EINVAL;
+
+	handler = find_prop_handler(name, NULL);
+	if (!handler)
+		return -EINVAL;
+
+	if (value_len == 0)
+		return 0;
+
+	return handler->validate(value, value_len);
+}
+
 static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 			  const char *name, const char *value, size_t value_len,
 			  int flags)
@@ -62,9 +79,6 @@ static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 	const struct prop_handler *handler;
 	int ret;
 
-	if (strlen(name) <= XATTR_BTRFS_PREFIX_LEN)
-		return -EINVAL;
-
 	handler = find_prop_handler(name, NULL);
 	if (!handler)
 		return -EINVAL;
@@ -85,9 +99,6 @@ static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 		return ret;
 	}
 
-	ret = handler->validate(value, value_len);
-	if (ret)
-		return ret;
 	if (trans)
 		ret = btrfs_setxattr(trans, inode, handler->xattr_name, value,
 				     value_len, flags);
fs/btrfs/props.h +1 -0
index b1a6b233b774..01d2c1899bc7 100644
@@ -12,6 +12,7 @@ void __init btrfs_props_init(void);
 
 int btrfs_set_prop_trans(struct inode *inode, const char *name,
 			 const char *value, size_t value_len, int flags);
+int btrfs_validate_prop(const char *name, const char *value, size_t value_len);
 
 int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path);
 
fs/btrfs/xattr.c +5 -0
index 10da873d11f5..807cc24dc885 100644
@@ -373,7 +373,12 @@ static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler,
 					const char *name, const void *value,
 					size_t size, int flags)
 {
+	int ret;
+
 	name = xattr_full_name(handler, name);
+	ret = btrfs_validate_prop(name, value, size);
+	if (ret)
+		return ret;
 	return btrfs_set_prop_trans(inode, name, value, size, flags);
 }
 
Signature · 1 line
2.20.1 (Apple Git-117)
author
#2 lore raw

PATCH 2/10 btrfs: export btrfs_set_prop

In reply to Anand Jain

Make btrfs_set_prop() a non static function, so that it can be called from btrfs_ioctl_setflags(). We need btrfs_set_prop() instead of btrfs_set_prop_trans() so that we can use the transaction which is already started in the current thread.

---
 fs/btrfs/props.c | 6 +++---
 fs/btrfs/props.h | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/btrfs/props.c +3 -3
index e356dd2a0f73..aedf5a7d69c9 100644
@@ -72,9 +72,9 @@ int btrfs_validate_prop(const char *name, const char *value, size_t value_len)
 	return handler->validate(value, value_len);
 }
 
-static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
-			  const char *name, const char *value, size_t value_len,
-			  int flags)
+int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
+		   const char *name, const char *value, size_t value_len,
+		   int flags)
 {
 	const struct prop_handler *handler;
 	int ret;
fs/btrfs/props.h +3 -0
index 01d2c1899bc7..30b99348977d 100644
@@ -12,6 +12,9 @@ void __init btrfs_props_init(void);
 
 int btrfs_set_prop_trans(struct inode *inode, const char *name,
 			 const char *value, size_t value_len, int flags);
+int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
+		   const char *name, const char *value, size_t value_len,
+		   int flags);
 int btrfs_validate_prop(const char *name, const char *value, size_t value_len);
 
 int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path);
Signature · 1 line
2.20.1 (Apple Git-117)
author
#3 lore raw

PATCH 3/10 btrfs: start transaction in btrfs_ioctl_setflags()

In reply to Anand Jain

Inode attribute can be set through the FS_IOC_SETFLAGS ioctl. This flags also includes compression attribute for which we would set/reset the compression extended attribute. While doing this there is a bit of duplicate code, the following things happens twice- start/end_transaction, inode_inc_iversion(), current_time update to inode->i_ctime, and btrfs_update_inode(). These are updated both at btrfs_ioctl_setflags() and btrfs_set_props() as well.

This patch merges these two duplicate codes at btrfs_ioctl_setflags().

---
RFC->v1: call btrfs_transaction_abort() at the place of error return

 fs/btrfs/ioctl.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
fs/btrfs/ioctl.c +21 -20
index 63e6e2f5b659..fc3f75c9a210 100644
@@ -192,6 +192,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	u64 old_flags;
 	unsigned int old_i_flags;
 	umode_t mode;
+	const char *comp = NULL;
 
 	if (!inode_owner_or_capable(inode))
 		return -EPERM;
@@ -283,14 +284,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	if (fsflags & FS_NOCOMP_FL) {
 		binode->flags &= ~BTRFS_INODE_COMPRESS;
 		binode->flags |= BTRFS_INODE_NOCOMPRESS;
-
-		/* set no-compression no need to validate prop here */
-		ret = btrfs_set_prop_trans(inode, "btrfs.compression", NULL,
-					   0, 0);
-		if (ret && ret != -ENODATA)
-			goto out_drop;
 	} else if (fsflags & FS_COMPR_FL) {
-		const char *comp;
 
 		if (IS_SWAPFILE(inode)) {
 			ret = -ETXTBSY;
@@ -300,36 +294,43 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 		binode->flags |= BTRFS_INODE_COMPRESS;
 		binode->flags &= ~BTRFS_INODE_NOCOMPRESS;
 
-		/* compress_type is already validated during mount options */
 		comp = btrfs_compress_type2str(fs_info->compress_type);
 		if (!comp || comp[0] == 0)
 			comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB);
-
-		ret = btrfs_set_prop_trans(inode, "btrfs.compression", comp,
-					   strlen(comp), 0);
-		if (ret)
-			goto out_drop;
-
 	} else {
-		/* reset prop, no need of validate prop here */
-		ret = btrfs_set_prop_trans(inode, "btrfs.compression", NULL,
-					   0, 0);
-		if (ret && ret != -ENODATA)
-			goto out_drop;
 		binode->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
 	}
 
-	trans = btrfs_start_transaction(root, 1);
+	trans = btrfs_start_transaction(root, 3);
 	if (IS_ERR(trans)) {
 		ret = PTR_ERR(trans);
 		goto out_drop;
 	}
 
+	if (comp) {
+		ret = btrfs_set_prop(trans, inode, "btrfs.compression", comp,
+				     strlen(comp), 0);
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			goto out_end_trans;
+		}
+		set_bit(BTRFS_INODE_COPY_EVERYTHING,
+			&BTRFS_I(inode)->runtime_flags);
+	} else {
+		ret = btrfs_set_prop(trans, inode, "btrfs.compression", NULL,
+				     0, 0);
+		if (ret && ret != -ENODATA) {
+			btrfs_abort_transaction(trans, ret);
+			goto out_end_trans;
+		}
+	}
+
 	btrfs_sync_inode_flags_to_i_flags(inode);
 	inode_inc_iversion(inode);
 	inode->i_ctime = current_time(inode);
 	ret = btrfs_update_inode(trans, root, inode);
 
+ out_end_trans:
 	btrfs_end_transaction(trans);
  out_drop:
 	if (ret) {
Signature · 1 line
2.20.1 (Apple Git-117)
author
#4 lore raw

PATCH 4/10 btrfs: drop useless inode i_flags copy and restore

In reply to Anand Jain

The patch (btrfs: start transaction in btrfs_ioctl_setflags()) used btrfs_set_prop() instead of btrfs_set_prop_trans() by which now the inode::i_flags update functions such as btrfs_sync_inode_flags_to_i_flags() and btrfs_update_inode() is called in btrfs_ioctl_setflags() instead of btrfs_set_prop_trans()->btrfs_setxattr() as earlier. So the inode::i_flags remains unmodified until the thread has checked all the conditions. So drop the saved inode::i_flags in out_i_flags.

---
 fs/btrfs/ioctl.c | 3 ---
 1 file changed, 3 deletions(-)
fs/btrfs/ioctl.c +0 -3
index fc3f75c9a210..1834b576d1cb 100644
@@ -190,7 +190,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	unsigned int fsflags, old_fsflags;
 	int ret;
 	u64 old_flags;
-	unsigned int old_i_flags;
 	umode_t mode;
 	const char *comp = NULL;
 
@@ -214,7 +213,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	inode_lock(inode);
 
 	old_flags = binode->flags;
-	old_i_flags = inode->i_flags;
 	mode = inode->i_mode;
 
 	fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
@@ -335,7 +333,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
  out_drop:
 	if (ret) {
 		binode->flags = old_flags;
-		inode->i_flags = old_i_flags;
 	}
 
  out_unlock:
Signature · 1 line
2.20.1 (Apple Git-117)
author
#5 lore raw

PATCH 5/10 btrfs: make a local copy of btrfs_inode flags before update

In reply to Anand Jain

Instead of updating the binode::flags directly, update a local copy, and then at the point of no error-return copy it to the binode::flags.

---
 fs/btrfs/ioctl.c | 57 ++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 31 deletions(-)
fs/btrfs/ioctl.c +26 -31
index 1834b576d1cb..b87a249642f7 100644
@@ -189,9 +189,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	struct btrfs_trans_handle *trans;
 	unsigned int fsflags, old_fsflags;
 	int ret;
-	u64 old_flags;
 	umode_t mode;
 	const char *comp = NULL;
+	u32 binode_flags = binode->flags;
 
 	if (!inode_owner_or_capable(inode))
 		return -EPERM;
@@ -212,7 +212,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 
 	inode_lock(inode);
 
-	old_flags = binode->flags;
 	mode = inode->i_mode;
 
 	fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
@@ -225,29 +224,29 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	}
 
 	if (fsflags & FS_SYNC_FL)
-		binode->flags |= BTRFS_INODE_SYNC;
+		binode_flags |= BTRFS_INODE_SYNC;
 	else
-		binode->flags &= ~BTRFS_INODE_SYNC;
+		binode_flags &= ~BTRFS_INODE_SYNC;
 	if (fsflags & FS_IMMUTABLE_FL)
-		binode->flags |= BTRFS_INODE_IMMUTABLE;
+		binode_flags |= BTRFS_INODE_IMMUTABLE;
 	else
-		binode->flags &= ~BTRFS_INODE_IMMUTABLE;
+		binode_flags &= ~BTRFS_INODE_IMMUTABLE;
 	if (fsflags & FS_APPEND_FL)
-		binode->flags |= BTRFS_INODE_APPEND;
+		binode_flags |= BTRFS_INODE_APPEND;
 	else
-		binode->flags &= ~BTRFS_INODE_APPEND;
+		binode_flags &= ~BTRFS_INODE_APPEND;
 	if (fsflags & FS_NODUMP_FL)
-		binode->flags |= BTRFS_INODE_NODUMP;
+		binode_flags |= BTRFS_INODE_NODUMP;
 	else
-		binode->flags &= ~BTRFS_INODE_NODUMP;
+		binode_flags &= ~BTRFS_INODE_NODUMP;
 	if (fsflags & FS_NOATIME_FL)
-		binode->flags |= BTRFS_INODE_NOATIME;
+		binode_flags |= BTRFS_INODE_NOATIME;
 	else
-		binode->flags &= ~BTRFS_INODE_NOATIME;
+		binode_flags &= ~BTRFS_INODE_NOATIME;
 	if (fsflags & FS_DIRSYNC_FL)
-		binode->flags |= BTRFS_INODE_DIRSYNC;
+		binode_flags |= BTRFS_INODE_DIRSYNC;
 	else
-		binode->flags &= ~BTRFS_INODE_DIRSYNC;
+		binode_flags &= ~BTRFS_INODE_DIRSYNC;
 	if (fsflags & FS_NOCOW_FL) {
 		if (S_ISREG(mode)) {
 			/*
@@ -256,10 +255,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 			 * status of the file and will not set it.
 			 */
 			if (inode->i_size == 0)
-				binode->flags |= BTRFS_INODE_NODATACOW
-					      | BTRFS_INODE_NODATASUM;
+				binode_flags |= BTRFS_INODE_NODATACOW |
+						BTRFS_INODE_NODATASUM;
 		} else {
-			binode->flags |= BTRFS_INODE_NODATACOW;
+			binode_flags |= BTRFS_INODE_NODATACOW;
 		}
 	} else {
 		/*
@@ -267,10 +266,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 		 */
 		if (S_ISREG(mode)) {
 			if (inode->i_size == 0)
-				binode->flags &= ~(BTRFS_INODE_NODATACOW
-				             | BTRFS_INODE_NODATASUM);
+				binode_flags &= ~(BTRFS_INODE_NODATACOW |
+						  BTRFS_INODE_NODATASUM);
 		} else {
-			binode->flags &= ~BTRFS_INODE_NODATACOW;
+			binode_flags &= ~BTRFS_INODE_NODATACOW;
 		}
 	}
 
@@ -280,8 +279,8 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	 * things smaller.
 	 */
 	if (fsflags & FS_NOCOMP_FL) {
-		binode->flags &= ~BTRFS_INODE_COMPRESS;
-		binode->flags |= BTRFS_INODE_NOCOMPRESS;
+		binode_flags &= ~BTRFS_INODE_COMPRESS;
+		binode_flags |= BTRFS_INODE_NOCOMPRESS;
 	} else if (fsflags & FS_COMPR_FL) {
 
 		if (IS_SWAPFILE(inode)) {
@@ -289,20 +288,20 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 			goto out_unlock;
 		}
 
-		binode->flags |= BTRFS_INODE_COMPRESS;
-		binode->flags &= ~BTRFS_INODE_NOCOMPRESS;
+		binode_flags |= BTRFS_INODE_COMPRESS;
+		binode_flags &= ~BTRFS_INODE_NOCOMPRESS;
 
 		comp = btrfs_compress_type2str(fs_info->compress_type);
 		if (!comp || comp[0] == 0)
 			comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB);
 	} else {
-		binode->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
+		binode_flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
 	}
 
 	trans = btrfs_start_transaction(root, 3);
 	if (IS_ERR(trans)) {
 		ret = PTR_ERR(trans);
-		goto out_drop;
+		goto out_unlock;
 	}
 
 	if (comp) {
@@ -323,6 +322,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 		}
 	}
 
+	binode->flags = binode_flags;
 	btrfs_sync_inode_flags_to_i_flags(inode);
 	inode_inc_iversion(inode);
 	inode->i_ctime = current_time(inode);
@@ -330,11 +330,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 
  out_end_trans:
 	btrfs_end_transaction(trans);
- out_drop:
-	if (ret) {
-		binode->flags = old_flags;
-	}
-
  out_unlock:
 	inode_unlock(inode);
 	mnt_drop_write_file(file);
Signature · 1 line
2.20.1 (Apple Git-117)
author
#6 lore raw

PATCH 6/10 btrfs: drop old_fsflags in btrfs_ioctl_setflags

In reply to Anand Jain

btrfs_inode_flags_to_fsflags() is copied into %old_fsflags and used only once. Instead used it directly.

---
 fs/btrfs/ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +3 -3
index b87a249642f7..e83412d7363a 100644
@@ -187,7 +187,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	struct btrfs_inode *binode = BTRFS_I(inode);
 	struct btrfs_root *root = binode->root;
 	struct btrfs_trans_handle *trans;
-	unsigned int fsflags, old_fsflags;
+	unsigned int fsflags;
 	int ret;
 	umode_t mode;
 	const char *comp = NULL;
@@ -215,8 +215,8 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	mode = inode->i_mode;
 
 	fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
-	old_fsflags = btrfs_inode_flags_to_fsflags(binode->flags);
-	if ((fsflags ^ old_fsflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
+	if ((fsflags ^ btrfs_inode_flags_to_fsflags(binode->flags)) &
+	    (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
 		if (!capable(CAP_LINUX_IMMUTABLE)) {
 			ret = -EPERM;
 			goto out_unlock;
Signature · 1 line
2.20.1 (Apple Git-117)
author
#7 lore raw

PATCH 7/10 btrfs: drop local copy of inode i_mode

In reply to Anand Jain

There isn't real use of making struct inode::i_mode a local copy, it saves a dereference one time, not much. Just use it directly.

---
 fs/btrfs/ioctl.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/ioctl.c +2 -5
index e83412d7363a..142fcdaf6a93 100644
@@ -189,7 +189,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	struct btrfs_trans_handle *trans;
 	unsigned int fsflags;
 	int ret;
-	umode_t mode;
 	const char *comp = NULL;
 	u32 binode_flags = binode->flags;
 
@@ -212,8 +211,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 
 	inode_lock(inode);
 
-	mode = inode->i_mode;
-
 	fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
 	if ((fsflags ^ btrfs_inode_flags_to_fsflags(binode->flags)) &
 	    (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
@@ -248,7 +245,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	else
 		binode_flags &= ~BTRFS_INODE_DIRSYNC;
 	if (fsflags & FS_NOCOW_FL) {
-		if (S_ISREG(mode)) {
+		if (S_ISREG(inode->i_mode)) {
 			/*
 			 * It's safe to turn csums off here, no extents exist.
 			 * Otherwise we want the flag to reflect the real COW
@@ -264,7 +261,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 		/*
 		 * Revert back under same assumptions as above
 		 */
-		if (S_ISREG(mode)) {
+		if (S_ISREG(inode->i_mode)) {
 			if (inode->i_size == 0)
 				binode_flags &= ~(BTRFS_INODE_NODATACOW |
 						  BTRFS_INODE_NODATASUM);
Signature · 1 line
2.20.1 (Apple Git-117)
author
#8 lore raw

PATCH 8/10 btrfs: start transaction in xattr_handler_set_prop

In reply to Anand Jain

btrfs specific extended attributes on the inode are set using btrfs_xattr_handler_set_prop(), and the required transaction for this update is started by btrfs_setxattr(). For better visibility of the transaction start and end, do this in btrfs_xattr_handler_set_prop(). For which this patch copied code of btrfs_setxattr() as it is in the original, which needs proper error handling.

---
 fs/btrfs/xattr.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
fs/btrfs/xattr.c +20 -1
index 807cc24dc885..46ad7b5cf209 100644
@@ -374,12 +374,31 @@ static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler,
 					size_t size, int flags)
 {
 	int ret;
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
 
 	name = xattr_full_name(handler, name);
 	ret = btrfs_validate_prop(name, value, size);
 	if (ret)
 		return ret;
-	return btrfs_set_prop_trans(inode, name, value, size, flags);
+
+	trans = btrfs_start_transaction(root, 2);
+	if (IS_ERR(trans))
+		return PTR_ERR(trans);
+
+	ret = btrfs_set_prop(trans, inode, name, value, size, flags);
+	if (!ret) {
+		inode_inc_iversion(inode);
+		inode->i_ctime = current_time(inode);
+		set_bit(BTRFS_INODE_COPY_EVERYTHING,
+			&BTRFS_I(inode)->runtime_flags);
+		ret = btrfs_update_inode(trans, root, inode);
+		BUG_ON(ret);
+	}
+
+	btrfs_end_transaction(trans);
+
+	return ret;
 }
 
 static const struct xattr_handler btrfs_security_xattr_handler = {
Signature · 1 line
2.20.1 (Apple Git-117)
author
#9 lore raw

PATCH 9/10 btrfs: delete unused function btrfs_set_prop_trans

In reply to Anand Jain

The last consumer of btrfs_set_prop_trans() was taken away by the patch
btrfs: start transaction in xattr_handler_set_prop
so now this function can be deleted.

---
 fs/btrfs/props.c | 6 ------
 fs/btrfs/props.h | 2 --
 2 files changed, 8 deletions(-)
fs/btrfs/props.c +0 -6
index aedf5a7d69c9..c41ed2a6347e 100644
@@ -124,12 +124,6 @@ int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 	return 0;
 }
 
-int btrfs_set_prop_trans(struct inode *inode, const char *name,
-			 const char *value, size_t value_len, int flags)
-{
-	return btrfs_set_prop(NULL, inode, name, value, value_len, flags);
-}
-
 static int iterate_object_props(struct btrfs_root *root,
 				struct btrfs_path *path,
 				u64 objectid,
fs/btrfs/props.h +0 -2
index 30b99348977d..40b2c65b518c 100644
@@ -10,8 +10,6 @@
 
 void __init btrfs_props_init(void);
 
-int btrfs_set_prop_trans(struct inode *inode, const char *name,
-			 const char *value, size_t value_len, int flags);
 int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 		   const char *name, const char *value, size_t value_len,
 		   int flags);
Signature · 1 line
2.20.1 (Apple Git-117)
author
#10 lore raw

PATCH 10/10 btrfs: btrfs_set_prop trans is never null

In reply to Anand Jain

Since now the trans argument is never null we don't have to check if its null. So delete it.

---
 fs/btrfs/props.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)
fs/btrfs/props.c +6 -19
index c41ed2a6347e..ca2716917e37 100644
@@ -84,12 +84,8 @@ int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 		return -EINVAL;
 
 	if (value_len == 0) {
-		if (trans)
-			ret = btrfs_setxattr(trans, inode, handler->xattr_name,
-					     NULL, 0, flags);
-		else
-			ret = btrfs_setxattr_trans(inode, handler->xattr_name,
-						   NULL, 0, flags);
+		ret = btrfs_setxattr(trans, inode, handler->xattr_name,
+				     NULL, 0, flags);
 		if (ret)
 			return ret;
 
@@ -99,23 +95,14 @@ int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
 		return ret;
 	}
 
-	if (trans)
-		ret = btrfs_setxattr(trans, inode, handler->xattr_name, value,
-				     value_len, flags);
-	else
-		ret = btrfs_setxattr_trans(inode, handler->xattr_name, value,
-					   value_len, flags);
-
+	ret = btrfs_setxattr(trans, inode, handler->xattr_name, value,
+			     value_len, flags);
 	if (ret)
 		return ret;
 	ret = handler->apply(inode, value, value_len);
 	if (ret) {
-		if (trans)
-			btrfs_setxattr(trans, inode, handler->xattr_name, NULL,
-				       0, flags);
-		else
-			btrfs_setxattr_trans(inode, handler->xattr_name, NULL,
-					     0, flags);
+		btrfs_setxattr(trans, inode, handler->xattr_name, NULL,
+			       0, flags);
 		return ret;
 	}
 
Signature · 1 line
2.20.1 (Apple Git-117)
#11 lore raw
In reply to Anand Jain
Quoted 4 lines · Anand Jain

A set of pathes to clean up btrfs_ioctl_setflags(), btrfs_set_prop_trans() and btrfs_set_prop(). So as to avoidi duplicate code in btrfs_ioctl_setflags() and killing of btrfs_set_prop_trans().

Quoted 11 lines

Anand Jain (10):
btrfs: refactor btrfs_set_props to validate externally
btrfs: export btrfs_set_prop
btrfs: start transaction in btrfs_ioctl_setflags()
btrfs: drop useless inode i_flags copy and restore
btrfs: make a local copy of btrfs_inode flags before update
btrfs: drop old_fsflags in btrfs_ioctl_setflags
btrfs: drop local copy of inode i_mode
btrfs: start transaction in xattr_handler_set_prop
btrfs: delete unused function btrfs_set_prop_trans
btrfs: btrfs_set_prop trans is never null

Looks good to me, I'll add it to misc-next as it's only a cleanup series, now that we're getting close to 5.2 code freeze.

author
#12 lore raw
Quoted 17 lines · David Sterba
Quoted 4 lines · Anand Jain

A set of pathes to clean up btrfs_ioctl_setflags(), btrfs_set_prop_trans() and btrfs_set_prop(). So as to avoidi duplicate code in btrfs_ioctl_setflags() and killing of btrfs_set_prop_trans().

Quoted 11 lines

Anand Jain (10):
btrfs: refactor btrfs_set_props to validate externally
btrfs: export btrfs_set_prop
btrfs: start transaction in btrfs_ioctl_setflags()
btrfs: drop useless inode i_flags copy and restore
btrfs: make a local copy of btrfs_inode flags before update
btrfs: drop old_fsflags in btrfs_ioctl_setflags
btrfs: drop local copy of inode i_mode
btrfs: start transaction in xattr_handler_set_prop
btrfs: delete unused function btrfs_set_prop_trans
btrfs: btrfs_set_prop trans is never null

Quoted 3 lines

Looks good to me, I'll add it to misc-next as it's only a cleanup series, now that we're getting close to 5.2 code freeze.

Thanks.
I thought I will take a look, looks like its not yet pushed? Which is the most updated? repo gitlab/github? -Anand

#13 lore raw
Quoted 18 lines · Anand Jain
Quoted 17 lines · David Sterba
Quoted 15 lines · Anand Jain

A set of pathes to clean up btrfs_ioctl_setflags(), btrfs_set_prop_trans() and btrfs_set_prop(). So as to avoidi duplicate code in btrfs_ioctl_setflags() and killing of btrfs_set_prop_trans().

Anand Jain (10):
btrfs: refactor btrfs_set_props to validate externally
btrfs: export btrfs_set_prop
btrfs: start transaction in btrfs_ioctl_setflags()
btrfs: drop useless inode i_flags copy and restore
btrfs: make a local copy of btrfs_inode flags before update
btrfs: drop old_fsflags in btrfs_ioctl_setflags
btrfs: drop local copy of inode i_mode
btrfs: start transaction in xattr_handler_set_prop
btrfs: delete unused function btrfs_set_prop_trans
btrfs: btrfs_set_prop trans is never null

Quoted 6 lines
Quoted 3 lines

Looks good to me, I'll add it to misc-next as it's only a cleanup series, now that we're getting close to 5.2 code freeze.

Thanks.
I thought I will take a look, looks like its not yet pushed? Which is the most updated? repo gitlab/github?

It's been in for-next until yesterday and I've merged it to misc-next after that so it'll be out today.