Skip to contentSkip to conversation

Btrfs updates for 3.14-rc - sysfs, ioctl

PATCH In review David Sterba 3 participants 7 messages Feb 7, 2014 – Apr 4, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover Btrfs updates for 3.14-rc - sysfs, ioctl

Two minor fixes to the new sysfs code and a RFC change to replace the GLOBAL_RSV ioctl with the same information exported through SPACE_INFO ioctl.

This requires to reserve a blockgroup type that will become part of ABI.

David Sterba (3):
btrfs: reserve no transaction units in btrfs_ioctl_set_features
btrfs: export global block reserve size as space_info Revert "btrfs: add ioctl to export size of global metadata
reservation"

Jeff Mahoney (1):
btrfs: commit transaction after setting label and features

 fs/btrfs/ctree.h           |  9 ++++++++-
 fs/btrfs/ioctl.c           | 42 +++++++++++++++++++++++-------------------
 include/uapi/linux/btrfs.h |  1 -
 3 files changed, 31 insertions(+), 21 deletions(-)
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH 1/4 btrfs: commit transaction after setting label and features

From: Jeff Mahoney <[email protected]>

The set_fslabel ioctl uses btrfs_end_transaction, which means it's possible that the change will be lost if the system crashes, same for the newly set features. Let's use btrfs_commit_transaction instead.

---
 fs/btrfs/ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.c +2 -2
index b0134892dc70..8e48b81e1515 100644
@@ -4525,7 +4525,7 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
 	spin_lock(&root->fs_info->super_lock);
 	strcpy(super_block->label, label);
 	spin_unlock(&root->fs_info->super_lock);
-	ret = btrfs_end_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans, root);
 
 out_unlock:
 	mnt_drop_write_file(file);
@@ -4689,7 +4689,7 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
 	btrfs_set_super_incompat_flags(super_block, newflags);
 	spin_unlock(&root->fs_info->super_lock);
 
-	return btrfs_end_transaction(trans, root);
+	return btrfs_commit_transaction(trans, root);
 }
 
 long btrfs_ioctl(struct file *file, unsigned int
Signature · 1 line
1.8.5.2
#2 lore raw

PATCH 2/4 btrfs: reserve no transaction units in btrfs_ioctl_set_features

In reply to David Sterba

Added in patch "btrfs: add ioctls to query/change feature bits online" modifications to superblock don't need to reserve metadata blocks when starting a transaction.

---
 fs/btrfs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ioctl.c +1 -1
index 8e48b81e1515..383ab455bfa7 100644
@@ -4668,7 +4668,7 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
 	if (ret)
 		return ret;
 
-	trans = btrfs_start_transaction(root, 1);
+	trans = btrfs_start_transaction(root, 0);
 	if (IS_ERR(trans))
 		return PTR_ERR(trans);
 
Signature · 1 line
1.8.5.2
#3 lore raw

RFC PATCH 3/4 btrfs: export global block reserve size as space_info

In reply to David Sterba

Introduce a block group type bit for a global reserve and fill the space info for SPACE_INFO ioctl. This should replace the newly added ioctl (01e219e8069516cdb98594d417b8bb8d906ed30d) to get just the 'size' part of the global reserve, while the actual usage can be now visible in the 'btrfs fi df' output during ENOSPC stress.

The unpatched userspace tools will show the blockgroup as 'unknown'.

CC Jeff Mahoney <[email protected]>
CC Josef Bacik <[email protected]>
---
 fs/btrfs/ctree.h |  9 ++++++++-
 fs/btrfs/ioctl.c | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
fs/btrfs/ctree.h +8 -1
index 2c1a42ca519f..8bf1890ea21f 100644
@@ -985,7 +985,8 @@ struct btrfs_dev_replace_item {
 #define BTRFS_BLOCK_GROUP_RAID10	(1ULL << 6)
 #define BTRFS_BLOCK_GROUP_RAID5         (1ULL << 7)
 #define BTRFS_BLOCK_GROUP_RAID6         (1ULL << 8)
-#define BTRFS_BLOCK_GROUP_RESERVED	BTRFS_AVAIL_ALLOC_BIT_SINGLE
+#define BTRFS_BLOCK_GROUP_RESERVED	(BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
+					 BTRFS_SPACE_INFO_GLOBAL_RSV)
 
 enum btrfs_raid_types {
 	BTRFS_RAID_RAID10,
@@ -1017,6 +1018,12 @@ enum btrfs_raid_types {
  */
 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE	(1ULL << 48)
 
+/*
+ * A fake block group type that is used to communicate global block reserve
+ * size to userspace via the SPACE_INFO ioctl.
+ */
+#define BTRFS_SPACE_INFO_GLOBAL_RSV	(1ULL << 49)
+
 #define BTRFS_EXTENDED_PROFILE_MASK	(BTRFS_BLOCK_GROUP_PROFILE_MASK | \
 					 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
 
fs/btrfs/ioctl.c +20 -0
index 383ab455bfa7..0d938f8f173e 100644
@@ -3465,6 +3465,11 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
 		up_read(&info->groups_sem);
 	}
 
+	/*
+	 * Global block reserve, exported as a space_info
+	 */
+	slot_count++;
+
 	/* space_slots == 0 means they are asking for a count */
 	if (space_args.space_slots == 0) {
 		space_args.total_spaces = slot_count;
@@ -3523,6 +3528,21 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
 		up_read(&info->groups_sem);
 	}
 
+	/*
+	 * Add global block reserve
+	 */
+	if (slot_count) {
+		struct btrfs_block_rsv *block_rsv = &root->fs_info->global_block_rsv;
+
+		spin_lock(&block_rsv->lock);
+		space.total_bytes = block_rsv->size;
+		space.used_bytes = block_rsv->size - block_rsv->reserved;
+		spin_unlock(&block_rsv->lock);
+		space.flags = BTRFS_SPACE_INFO_GLOBAL_RSV;
+		memcpy(dest, &space, sizeof(space));
+		space_args.total_spaces++;
+	}
+
 	user_dest = (struct btrfs_ioctl_space_info __user *)
 		(arg + sizeof(struct btrfs_ioctl_space_args));
 
Signature · 1 line
1.8.5.2
#4 lore raw

Re: [PATCH 3/4][RFC] btrfs: export global block reserve size as space_info

Quoted 8 lines · David Sterba

Introduce a block group type bit for a global reserve and fill the space info for SPACE_INFO ioctl. This should replace the newly added ioctl (01e219e8069516cdb98594d417b8bb8d906ed30d) to get just the 'size' part of the global reserve, while the actual usage can be now visible in the 'btrfs fi df' output during ENOSPC stress.

The unpatched userspace tools will show the blockgroup as 'unknown'.

This wasn't in my rc2 pull because I wanted to sync up with Jeff on it.
I like the idea of combining this into SPACE_INFO, any objections?

-chris

#5 lore raw

Re: [PATCH 3/4][RFC] btrfs: export global block reserve size as space_info

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

Quoted 8 lines · Chris Mason
Quoted 7 lines · David Sterba

Introduce a block group type bit for a global reserve and fill the space info for SPACE_INFO ioctl. This should replace the newly added ioctl (01e219e8069516cdb98594d417b8bb8d906ed30d) to get just the 'size' part of the global reserve, while the actual usage can be now visible in the 'btrfs fi df' output during ENOSPC stress.

Quoted 7 lines
Quoted 3 lines

The unpatched userspace tools will show the blockgroup as 'unknown'.

This wasn't in my rc2 pull because I wanted to sync up with Jeff on it. I like the idea of combining this into SPACE_INFO, any objections?

Sorry, was on vacation when this went by and just got the ping. Yeah, I have no objections here.

- -Jeff

- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)

iQIcBAEBAgAGBQJTPsgMAAoJEB57S2MheeWyf1EP/158KhPm7KoT9EGeNUwv4+nb Ex2z9hIbTduJ6rT9IG+n0vbV2Ka9IuWJDvYdoLLMIN1SFXOJdNo88MIf6aSTbHfb WWqJJ1nMB/DnDMt1bXp6cZSGyzQuSXvI/u97Pgy3gzMpmjuzXy37c7JkFCABM352 G2IF+bZiHqa6X+eTxSjlimDKvIBOPGw/hOIvegRmqyqDMNIy5dwzDQIsytUuqsgQ rl+fAt+R+VNdSe2ZEjn+FwviOpPrgR8TQL5Qycaoviqzd6apBtutlcJpfEIqCP8m 4guZ7bC/VjsUdJj1cxSYZe+Eh0dEas2T5qjH5DW5uyTmsKJAA3VM4lTaxITvQ0Y8 URxCQGSfAc0IUudpz+nCbLdwhUYtV/yfpA8i3Fnewyu8Jazvup0dxALo56RDu4Kf j7K3kwTFlfB7D9/S10SbsWK3j/NR3qJu1DicG1Wy18Acl3oZvCgB4qGIaxh1vcsV NZfkt+/5V+Mb0ocKEjdudO/sS0XNBJowMxmWOCZz6vGyKQTAWA+VYmZxJ/rKiOoG O/YYmJ2VuzWI8KPFrhNny12UJ9AsyZLhDw4Sbr7iEDI/l/mtrL6WsK/krhMHKDdJ wf4TWtM0CPyZS8ym6f2cgSdmvecaZ3AuK1Hd19DeMZnly6bwZV2TkNSXbfB+oAZO HL7ZLY8oHLj4brTHFOIH
=fiJ0
-----END PGP SIGNATURE-----

#6 lore raw

PATCH 4/4 Revert "btrfs: add ioctl to export size of global metadata reservation"

In reply to David Sterba

This reverts commit 01e219e8069516cdb98594d417b8bb8d906ed30d.

The information from the removed ioctl is newly provided by the existing SPACE_INFO ioctl where it logically belongs and needs only minor changes to the userspace code.

The GLOBAL_RSV ioctl hasn't been used anywhere yet, introduced only in 3.14-rc1 so there is no userspace ABI breakage.

---
 fs/btrfs/ioctl.c           | 16 ----------------
 include/uapi/linux/btrfs.h |  1 -
 2 files changed, 17 deletions(-)
fs/btrfs/ioctl.c +0 -16
index 0d938f8f173e..dc64cc28af29 100644
@@ -3557,20 +3557,6 @@ out:
 	return ret;
 }
 
-static long btrfs_ioctl_global_rsv(struct btrfs_root *root, void __user *arg)
-{
-	struct btrfs_block_rsv *block_rsv = &root->fs_info->global_block_rsv;
-	u64 reserved;
-
-	spin_lock(&block_rsv->lock);
-	reserved = block_rsv->reserved;
-	spin_unlock(&block_rsv->lock);
-
-	if (arg && copy_to_user(arg, &reserved, sizeof(reserved)))
-		return -EFAULT;
-	return 0;
-}
-
 /*
  * there are many ways the trans_start and trans_end ioctls can lead
  * to deadlocks.  They should only be used by applications that
@@ -4777,8 +4763,6 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_logical_to_ino(root, argp);
 	case BTRFS_IOC_SPACE_INFO:
 		return btrfs_ioctl_space_info(root, argp);
-	case BTRFS_IOC_GLOBAL_RSV:
-		return btrfs_ioctl_global_rsv(root, argp);
 	case BTRFS_IOC_SYNC: {
 		int ret;
 
include/uapi/linux/btrfs.h +0 -1
index 1b8a0f4c9590..b4d69092fbdb 100644
@@ -558,7 +558,6 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
 				    struct btrfs_ioctl_space_args)
-#define BTRFS_IOC_GLOBAL_RSV _IOR(BTRFS_IOCTL_MAGIC, 20, __u64)
 #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
 #define BTRFS_IOC_WAIT_SYNC  _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
Signature · 1 line
1.8.5.2