linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 1/3] btrfs-progs: Add nocow compressed write into prealloc support
Date: Thu, 18 Sep 2014 12:22:16 +0800	[thread overview]
Message-ID: <1411014138-20124-1-git-send-email-quwenruo@cn.fujitsu.com> (raw)

Add basic nocow compressed write into preallocated range support in
mkfs and headers.

Now we can use mkfs to create a btrfs which supports nocow compressed
prealloc write.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 ctree.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 mkfs.c  |  2 ++
 2 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/ctree.h b/ctree.h
index fa73c4a..ab87133 100644
--- a/ctree.h
+++ b/ctree.h
@@ -473,6 +473,7 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_RAID56		(1ULL << 7)
 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA	(1ULL << 8)
 #define BTRFS_FEATURE_INCOMPAT_NO_HOLES		(1ULL << 9)
+#define BTRFS_FEATURE_INCOMPAT_COMPPREALLOC	(1ULL << 10)
 
 
 #define BTRFS_FEATURE_COMPAT_SUPP		0ULL
@@ -486,7 +487,8 @@ struct btrfs_super_block {
 	 BTRFS_FEATURE_INCOMPAT_RAID56 |		\
 	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
 	 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |	\
-	 BTRFS_FEATURE_INCOMPAT_NO_HOLES)
+	 BTRFS_FEATURE_INCOMPAT_NO_HOLES |		\
+	 BTRFS_FEATURE_INCOMPAT_COMPPREALLOC)
 
 /*
  * A leaf is full of items. offset and size tell us where to find
@@ -825,6 +827,18 @@ struct btrfs_file_extent_item {
 
 } __attribute__ ((__packed__));
 
+struct __compprealloc_data {
+	/* extent offset where we read data from disk. */
+	__le64 data_offset;
+	/* extent len that we need read into memory. */
+	__le64 data_len;
+
+} __attribute__ ((__packed__));
+
+#define BTRFS_FILE_EXTENT_SIZE_NORMAL (sizeof(struct btrfs_file_extent_item))
+#define BTRFS_FILE_EXTENT_SIZE_MAX (sizeof(struct btrfs_file_extent_item) + \
+				    sizeof(struct __compprealloc_data))
+
 struct btrfs_csum_item {
 	u8 csum;
 } __attribute__ ((__packed__));
@@ -2146,6 +2160,59 @@ static inline int btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
 	return !!(btrfs_super_incompat_flags(disk_super) & flag);
 }
 
+/* struct __compprealloc_data, don't use them directly!!! */
+BTRFS_SETGET_FUNCS(__compprealloc_data_offset, struct __compprealloc_data,
+		   data_offset, 64);
+BTRFS_SETGET_FUNCS(__compprealloc_data_len, struct __compprealloc_data,
+		   data_len, 64);
+
+/*
+ * functions for appended data after a original structure
+ * unlike kernel part, eb has no member fs_info, so caller should check
+ * the incompatible flag manually
+ */
+#define BTRFS_SETGET_APPEND_FUNCS(name, type, new_type, func, bits,	\
+				  flag, fallback)			\
+static inline u##bits btrfs_##name(struct extent_buffer *eb,		\
+				   int slot, type *s)			\
+{									\
+	if (btrfs_item_size_nr(eb, slot) > sizeof(*s))			\
+		return btrfs_##func(eb, (new_type *)(s + 1));		\
+	return fallback(eb, s);						\
+}									\
+static inline void btrfs_set_##name(struct extent_buffer *eb,		\
+				    int slot, type *s, u##bits val)	\
+{									\
+	if (btrfs_item_size_nr(eb, slot) > sizeof(*s))			\
+		btrfs_set_##func(eb, (new_type *)(s + 1), val);		\
+}									\
+
+/* appended data for btrfs_file_extent_item */
+static inline u64
+data_offset_fallback(struct extent_buffer *eb,
+		     struct btrfs_file_extent_item *fi)
+{
+	return 0;
+}
+BTRFS_SETGET_APPEND_FUNCS(ondemand_file_extent_data_offset,
+			  struct btrfs_file_extent_item,
+			  struct __compprealloc_data,
+			  __compprealloc_data_offset,
+			  64, COMPPREALLOC, data_offset_fallback);
+
+static inline u64
+data_len_fallback(struct extent_buffer *eb,
+		  struct btrfs_file_extent_item *fi)
+{
+	return btrfs_file_extent_disk_num_bytes(eb, fi);
+}
+BTRFS_SETGET_APPEND_FUNCS(ondemand_file_extent_data_len,
+			  struct btrfs_file_extent_item,
+			  struct __compprealloc_data,
+			  __compprealloc_data_len,
+			  64, COMPPREALLOC, data_len_fallback);
+
+
 /* helper function to cast into the data area of the leaf. */
 #define btrfs_item_ptr(leaf, slot, type) \
 	((type *)(btrfs_leaf_data(leaf) + \
diff --git a/mkfs.c b/mkfs.c
index 9de61e1..da1e586 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1163,6 +1163,8 @@ static const struct btrfs_fs_feature {
 		"reduced-size metadata extent refs" },
 	{ "no-holes", BTRFS_FEATURE_INCOMPAT_NO_HOLES,
 		"no explicit hole extents for files" },
+	{ "compressed-prealloc", BTRFS_FEATURE_INCOMPAT_COMPPREALLOC,
+		"alloc nocow compressed write into preallocated space"},
 	/* Keep this one last */
 	{ "list-all", BTRFS_FEATURE_LIST_ALL, NULL }
 };
-- 
2.1.0


             reply	other threads:[~2014-09-18  4:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18  4:22 Qu Wenruo [this message]
2014-09-18  4:22 ` [PATCH 2/3] btrfs-progs: Add data_offset and data_len output for print_file_extent_item Qu Wenruo
2014-09-18  4:22 ` [PATCH 3/3] btrfs: Add btrfsck support for nocow compressed prealloc write Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1411014138-20124-1-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).