So that applications can find out what's the highest send stream
version supported/implemented by the running kernel:

    $ cat /sys/fs/btrfs/send_stream_version
    2

Signed-off-by: Filipe David Borba Manana <fdman...@gmail.com>
---
 fs/btrfs/send.h  |  1 +
 fs/btrfs/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/fs/btrfs/send.h b/fs/btrfs/send.h
index 987936c..047fd6d 100644
--- a/fs/btrfs/send.h
+++ b/fs/btrfs/send.h
@@ -22,6 +22,7 @@
 #define BTRFS_SEND_STREAM_MAGIC "btrfs-stream"
 #define BTRFS_SEND_STREAM_VERSION_1 1
 #define BTRFS_SEND_STREAM_VERSION_2 2
+#define BTRFS_SEND_STREAM_VERSION_LATEST BTRFS_SEND_STREAM_VERSION_2
 
 #define BTRFS_SEND_BUF_SIZE (1024 * 64)
 #define BTRFS_SEND_READ_SIZE (1024 * 48)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 58a1dd1..2f8fff6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -31,6 +31,7 @@
 #include "transaction.h"
 #include "sysfs.h"
 #include "volumes.h"
+#include "send.h"
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
 
@@ -662,6 +663,36 @@ static int btrfs_init_debugfs(void)
        return 0;
 }
 
+static ssize_t send_stream_version_show(struct kobject *kobj,
+                                       struct kobj_attribute *a,
+                                       char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%d\n",
+                       BTRFS_SEND_STREAM_VERSION_LATEST);
+}
+
+BTRFS_ATTR(send_stream_version, 0444, send_stream_version_show);
+
+static const struct attribute *btrfs_root_attrs[] = {
+       BTRFS_ATTR_PTR(send_stream_version),
+       NULL
+};
+
+static int add_root_attrs(struct kobject *kobj)
+{
+       int error = 0;
+       int i;
+
+       for (i = 0; btrfs_root_attrs[i]; i++) {
+               const struct attribute *a = btrfs_root_attrs[i];
+
+               error = sysfs_add_file_to_group(kobj->parent, a, kobj->name);
+               if (error)
+                       break;
+       }
+       return error;
+}
+
 int btrfs_init_sysfs(void)
 {
        int ret;
@@ -678,8 +709,13 @@ int btrfs_init_sysfs(void)
        ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
        if (ret)
                goto out2;
+       ret = add_root_attrs(&btrfs_kset->kobj);
+       if (ret)
+               goto out3;
 
        return 0;
+out3:
+       sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
 out2:
        debugfs_remove_recursive(btrfs_debugfs_root_dentry);
 out1:
-- 
1.9.1

--
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

Reply via email to