[PATCH 01/13] btrfs: add ioctls to query/change feature bits online

2013-11-15 Thread Jeff Mahoney
There are some feature bits that require no offline setup and can
be enabled online. I've only reviewed extended irefs, but there will
probably be more.

We introduce three new ioctls:
- BTRFS_IOC_GET_SUPPORTED_FEATURES: query the kernel for supported features.
- BTRFS_IOC_GET_FEATURES: query the kernel for enabled features on a per-fs
  basis, as well as querying for which features are changeable with mounted.
- BTRFS_IOC_SET_FEATURES: change features on a per-fs basis.

We introduce two new masks per feature set (_SAFE_SET and _SAFE_CLEAR) that
allow us to define which features are safe to change at runtime.

The failure modes for BTRFS_IOC_SET_FEATURES are as follows:
- Enabling a completely unsupported feature: warns and returns -ENOTSUPP
- Enabling a feature that can only be done offline: warns and returns -EPERM

Signed-off-by: Jeff Mahoney je...@suse.com
---
 fs/btrfs/ctree.h   |9 ++
 fs/btrfs/ioctl.c   |  143 +
 include/uapi/linux/btrfs.h |   12 +++
 3 files changed, 164 insertions(+)

--- a/fs/btrfs/ctree.h  2013-11-03 16:50:38.800686715 -0500
+++ b/fs/btrfs/ctree.h  2013-11-03 16:51:24.715977991 -0500
@@ -517,7 +517,12 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL  8)
 
 #define BTRFS_FEATURE_COMPAT_SUPP  0ULL
+#define BTRFS_FEATURE_COMPAT_SAFE_SET  0ULL
+#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR0ULL
 #define BTRFS_FEATURE_COMPAT_RO_SUPP   0ULL
+#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET   0ULL
+#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
+
 #define BTRFS_FEATURE_INCOMPAT_SUPP\
(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |\
@@ -528,6 +533,10 @@ struct btrfs_super_block {
 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
 
+#define BTRFS_FEATURE_INCOMPAT_SAFE_SET\
+   (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
+#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR  0ULL
+
 /*
  * A leaf is full of items. offset and size tell us where to find
  * the item in the leaf (relative to the start of the data area)
--- a/fs/btrfs/ioctl.c  2013-11-03 16:50:43.464615049 -0500
+++ b/fs/btrfs/ioctl.c  2013-11-03 16:51:56.811492378 -0500
@@ -4492,6 +4492,142 @@ out_unlock:
return ret;
 }
 
+#define INIT_FEATURE_FLAGS(suffix) \
+   { .compat_flags = BTRFS_FEATURE_COMPAT_##suffix, \
+ .compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_##suffix, \
+ .incompat_flags = BTRFS_FEATURE_INCOMPAT_##suffix }
+
+static int btrfs_ioctl_get_supported_features(struct file *file,
+ void __user *arg)
+{
+   static struct btrfs_ioctl_feature_flags features[3] = {
+   INIT_FEATURE_FLAGS(SUPP),
+   INIT_FEATURE_FLAGS(SAFE_SET),
+   INIT_FEATURE_FLAGS(SAFE_CLEAR)
+   };
+
+   if (copy_to_user(arg, features, sizeof(features)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static int btrfs_ioctl_get_features(struct file *file, void __user *arg)
+{
+   struct btrfs_root *root = BTRFS_I(file_inode(file))-root;
+   struct btrfs_super_block *super_block = root-fs_info-super_copy;
+   struct btrfs_ioctl_feature_flags features;
+
+   features.compat_flags = btrfs_super_compat_flags(super_block);
+   features.compat_ro_flags = btrfs_super_compat_ro_flags(super_block);
+   features.incompat_flags = btrfs_super_incompat_flags(super_block);
+
+   if (copy_to_user(arg, features, sizeof(features)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static int check_feature_bits(struct btrfs_root *root, const char *type,
+ u64 change_mask, u64 flags, u64 supported_flags,
+ u64 safe_set, u64 safe_clear)
+{
+   u64 disallowed, unsupported;
+   u64 set_mask = flags  change_mask;
+   u64 clear_mask = ~flags  change_mask;
+
+   unsupported = set_mask  ~supported_flags;
+   if (unsupported) {
+   btrfs_warn(root-fs_info,
+  this kernel does not support %s bits 0x%llx,
+  type, unsupported);
+   return -EOPNOTSUPP;
+   }
+
+   disallowed = set_mask  ~safe_set;
+   if (disallowed) {
+   btrfs_warn(root-fs_info,
+  can't set %s bits 0x%llx while mounted,
+  type, disallowed);
+   return -EPERM;
+   }
+
+   disallowed = clear_mask  ~safe_clear;
+   if (disallowed) {
+   btrfs_warn(root-fs_info,
+  can't clear %s bits 0x%llx while mounted,
+  type, disallowed);
+   return -EPERM;
+   }
+
+   return 0;
+}
+
+#define check_feature(root, change_mask, flags, mask_base) 

Re: [PATCH 01/13] btrfs: add ioctls to query/change feature bits online

2013-11-03 Thread Jeff Mahoney
On 11/1/13, 4:56 PM, Zach Brown wrote:
 +static int btrfs_ioctl_get_supported_features(struct file *file,
 +  void __user *arg)
 +{
 +struct btrfs_ioctl_feature_flags features[3];
 +
 +features[0].compat_flags = BTRFS_FEATURE_COMPAT_SUPP;
 +features[0].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SUPP;
 +features[0].incompat_flags = BTRFS_FEATURE_INCOMPAT_SUPP;
 +
 +features[1].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_SET;
 +features[1].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_SET;
 +features[1].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_SET;
 +
 +features[2].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_CLEAR;
 +features[2].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR;
 +features[2].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR;
 +
 +if (copy_to_user(arg, features, sizeof(features)))
 +return -EFAULT;
 
 If these are all constants shouldn't that just copy out of a static
 built flags array?

Works for me. Change added.

-Jeff

 #define cpp4ever(suff) \
   BTRFS_FEATURE_COMPAT_#suff, BTRFS_FEATURE_COMPAT_RO_#suff, \
   BTRFS_FEATURE_INCOMPAT_#suff
 
   static struct btrfs_ioctl_feature_flags features[3] = {
   { cpp4ever(SUPP) }, { cpp4ever(SAFE_SET) },
   { cpp4ever(SAFE_CLEAR) },
   };
 
   if (copy_to_user(arg, features, sizeof(features)))
   return -EFAULT;
 
 ?
 
 - z
 --
 To unsubscribe from this list: send the line unsubscribe linux-btrfs in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 


-- 
Jeff Mahoney
SUSE Labs



signature.asc
Description: OpenPGP digital signature


[PATCH 01/13] btrfs: add ioctls to query/change feature bits online

2013-11-01 Thread Jeff Mahoney
There are some feature bits that require no offline setup and can
be enabled online. I've only reviewed extended irefs, but there will
probably be more.

We introduce three new ioctls:
- BTRFS_IOC_GET_SUPPORTED_FEATURES: query the kernel for supported features.
- BTRFS_IOC_GET_FEATURES: query the kernel for enabled features on a per-fs
  basis, as well as querying for which features are changeable with mounted.
- BTRFS_IOC_SET_FEATURES: change features on a per-fs basis.

We introduce two new masks per feature set (_SAFE_SET and _SAFE_CLEAR) that
allow us to define which features are safe to change at runtime.

The failure modes for BTRFS_IOC_SET_FEATURES are as follows:
- Enabling a completely unsupported feature: warns and returns -ENOTSUPP
- Enabling a feature that can only be done offline: warns and returns -EPERM

Signed-off-by: Jeff Mahoney je...@suse.com
---
 fs/btrfs/ctree.h   |9 ++
 fs/btrfs/ioctl.c   |  145 +
 include/uapi/linux/btrfs.h |   12 +++
 3 files changed, 166 insertions(+)

--- a/fs/btrfs/ctree.h  2013-09-11 21:40:48.939758689 -0400
+++ b/fs/btrfs/ctree.h  2013-09-16 13:37:13.020197254 -0400
@@ -512,7 +512,12 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL  8)
 
 #define BTRFS_FEATURE_COMPAT_SUPP  0ULL
+#define BTRFS_FEATURE_COMPAT_SAFE_SET  0ULL
+#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR0ULL
 #define BTRFS_FEATURE_COMPAT_RO_SUPP   0ULL
+#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET   0ULL
+#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
+
 #define BTRFS_FEATURE_INCOMPAT_SUPP\
(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |\
@@ -523,6 +528,10 @@ struct btrfs_super_block {
 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
 
+#define BTRFS_FEATURE_INCOMPAT_SAFE_SET\
+   (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
+#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR  0ULL
+
 /*
  * A leaf is full of items. offset and size tell us where to find
  * the item in the leaf (relative to the start of the data area)
--- a/fs/btrfs/ioctl.c  2013-09-11 21:40:48.991757905 -0400
+++ b/fs/btrfs/ioctl.c  2013-09-16 13:37:09.720237996 -0400
@@ -4098,6 +4098,145 @@ out_unlock:
return ret;
 }
 
+static int btrfs_ioctl_get_supported_features(struct file *file,
+ void __user *arg)
+{
+   struct btrfs_ioctl_feature_flags features[3];
+
+   features[0].compat_flags = BTRFS_FEATURE_COMPAT_SUPP;
+   features[0].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SUPP;
+   features[0].incompat_flags = BTRFS_FEATURE_INCOMPAT_SUPP;
+
+   features[1].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_SET;
+   features[1].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_SET;
+   features[1].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_SET;
+
+   features[2].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_CLEAR;
+   features[2].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR;
+   features[2].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR;
+
+   if (copy_to_user(arg, features, sizeof(features)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static int btrfs_ioctl_get_features(struct file *file, void __user *arg)
+{
+   struct btrfs_root *root = BTRFS_I(file_inode(file))-root;
+   struct btrfs_super_block *super_block = root-fs_info-super_copy;
+   struct btrfs_ioctl_feature_flags features;
+
+   features.compat_flags = btrfs_super_compat_flags(super_block);
+   features.compat_ro_flags = btrfs_super_compat_ro_flags(super_block);
+   features.incompat_flags = btrfs_super_incompat_flags(super_block);
+
+   if (copy_to_user(arg, features, sizeof(features)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static int check_feature_bits(struct btrfs_root *root, const char *type,
+ u64 change_mask, u64 flags, u64 supported_flags,
+ u64 safe_set, u64 safe_clear)
+{
+   u64 disallowed, unsupported;
+   u64 set_mask = flags  change_mask;
+   u64 clear_mask = ~flags  change_mask;
+
+   unsupported = set_mask  ~supported_flags;
+   if (unsupported) {
+   btrfs_warn(root-fs_info,
+  this kernel does not support %s bits 0x%llx,
+  type, unsupported);
+   return -EOPNOTSUPP;
+   }
+
+   disallowed = set_mask  ~safe_set;
+   if (disallowed) {
+   btrfs_warn(root-fs_info,
+  can't set %s bits 0x%llx while mounted,
+  type, disallowed);
+   return -EPERM;
+   }
+
+   disallowed = clear_mask  ~safe_clear;
+   if (disallowed) {
+   

Re: [PATCH 01/13] btrfs: add ioctls to query/change feature bits online

2013-11-01 Thread Zach Brown
 +static int btrfs_ioctl_get_supported_features(struct file *file,
 +   void __user *arg)
 +{
 + struct btrfs_ioctl_feature_flags features[3];
 +
 + features[0].compat_flags = BTRFS_FEATURE_COMPAT_SUPP;
 + features[0].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SUPP;
 + features[0].incompat_flags = BTRFS_FEATURE_INCOMPAT_SUPP;
 +
 + features[1].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_SET;
 + features[1].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_SET;
 + features[1].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_SET;
 +
 + features[2].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_CLEAR;
 + features[2].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR;
 + features[2].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR;
 +
 + if (copy_to_user(arg, features, sizeof(features)))
 + return -EFAULT;

If these are all constants shouldn't that just copy out of a static
built flags array?

#define cpp4ever(suff) \
BTRFS_FEATURE_COMPAT_#suff, BTRFS_FEATURE_COMPAT_RO_#suff, \
BTRFS_FEATURE_INCOMPAT_#suff

static struct btrfs_ioctl_feature_flags features[3] = {
{ cpp4ever(SUPP) }, { cpp4ever(SAFE_SET) },
{ cpp4ever(SAFE_CLEAR) },
};

if (copy_to_user(arg, features, sizeof(features)))
return -EFAULT;

?

- z
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 01/13] btrfs: add ioctls to query/change feature bits online

2013-10-21 Thread Jeff Mahoney
There are some feature bits that require no offline setup and can
be enabled online. I've only reviewed extended irefs, but there will
probably be more.

We introduce three new ioctls:
- BTRFS_IOC_GET_SUPPORTED_FEATURES: query the kernel for supported features.
- BTRFS_IOC_GET_FEATURES: query the kernel for enabled features on a per-fs
  basis, as well as querying for which features are changeable with mounted.
- BTRFS_IOC_SET_FEATURES: change features on a per-fs basis.

We introduce two new masks per feature set (_SAFE_SET and _SAFE_CLEAR) that
allow us to define which features are safe to change at runtime.

The failure modes for BTRFS_IOC_SET_FEATURES are as follows:
- Enabling a completely unsupported feature: warns and returns -ENOTSUPP
- Enabling a feature that can only be done offline: warns and returns -EPERM

Signed-off-by: Jeff Mahoney je...@suse.com
---
 fs/btrfs/ctree.h   |9 ++
 fs/btrfs/ioctl.c   |  145 +
 include/uapi/linux/btrfs.h |   12 +++
 3 files changed, 166 insertions(+)

--- a/fs/btrfs/ctree.h  2013-09-11 21:40:48.939758689 -0400
+++ b/fs/btrfs/ctree.h  2013-09-16 13:37:13.020197254 -0400
@@ -512,7 +512,12 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL  8)
 
 #define BTRFS_FEATURE_COMPAT_SUPP  0ULL
+#define BTRFS_FEATURE_COMPAT_SAFE_SET  0ULL
+#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR0ULL
 #define BTRFS_FEATURE_COMPAT_RO_SUPP   0ULL
+#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET   0ULL
+#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
+
 #define BTRFS_FEATURE_INCOMPAT_SUPP\
(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |\
@@ -523,6 +528,10 @@ struct btrfs_super_block {
 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
 
+#define BTRFS_FEATURE_INCOMPAT_SAFE_SET\
+   (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
+#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR  0ULL
+
 /*
  * A leaf is full of items. offset and size tell us where to find
  * the item in the leaf (relative to the start of the data area)
--- a/fs/btrfs/ioctl.c  2013-09-11 21:40:48.991757905 -0400
+++ b/fs/btrfs/ioctl.c  2013-09-16 13:37:09.720237996 -0400
@@ -4098,6 +4098,145 @@ out_unlock:
return ret;
 }
 
+static int btrfs_ioctl_get_supported_features(struct file *file,
+ void __user *arg)
+{
+   struct btrfs_ioctl_feature_flags features[3];
+
+   features[0].compat_flags = BTRFS_FEATURE_COMPAT_SUPP;
+   features[0].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SUPP;
+   features[0].incompat_flags = BTRFS_FEATURE_INCOMPAT_SUPP;
+
+   features[1].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_SET;
+   features[1].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_SET;
+   features[1].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_SET;
+
+   features[2].compat_flags = BTRFS_FEATURE_COMPAT_SAFE_CLEAR;
+   features[2].compat_ro_flags = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR;
+   features[2].incompat_flags = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR;
+
+   if (copy_to_user(arg, features, sizeof(features)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static int btrfs_ioctl_get_features(struct file *file, void __user *arg)
+{
+   struct btrfs_root *root = BTRFS_I(file_inode(file))-root;
+   struct btrfs_super_block *super_block = root-fs_info-super_copy;
+   struct btrfs_ioctl_feature_flags features;
+
+   features.compat_flags = btrfs_super_compat_flags(super_block);
+   features.compat_ro_flags = btrfs_super_compat_ro_flags(super_block);
+   features.incompat_flags = btrfs_super_incompat_flags(super_block);
+
+   if (copy_to_user(arg, features, sizeof(features)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static int check_feature_bits(struct btrfs_root *root, const char *type,
+ u64 change_mask, u64 flags, u64 supported_flags,
+ u64 safe_set, u64 safe_clear)
+{
+   u64 disallowed, unsupported;
+   u64 set_mask = flags  change_mask;
+   u64 clear_mask = ~flags  change_mask;
+
+   unsupported = set_mask  ~supported_flags;
+   if (unsupported) {
+   btrfs_warn(root-fs_info,
+  this kernel does not support %s bits 0x%llx,
+  type, unsupported);
+   return -EOPNOTSUPP;
+   }
+
+   disallowed = set_mask  ~safe_set;
+   if (disallowed) {
+   btrfs_warn(root-fs_info,
+  can't set %s bits 0x%llx while mounted,
+  type, disallowed);
+   return -EPERM;
+   }
+
+   disallowed = clear_mask  ~safe_clear;
+   if (disallowed) {
+