* [PATCH 1/3] btrfs-progs: Add nocow compressed write into prealloc support
@ 2014-09-18 4:22 Qu Wenruo
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
0 siblings, 2 replies; 3+ messages in thread
From: Qu Wenruo @ 2014-09-18 4:22 UTC (permalink / raw)
To: linux-btrfs
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/3] btrfs-progs: Add data_offset and data_len output for print_file_extent_item
2014-09-18 4:22 [PATCH 1/3] btrfs-progs: Add nocow compressed write into prealloc support Qu Wenruo
@ 2014-09-18 4:22 ` Qu Wenruo
2014-09-18 4:22 ` [PATCH 3/3] btrfs: Add btrfsck support for nocow compressed prealloc write Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2014-09-18 4:22 UTC (permalink / raw)
To: linux-btrfs
Add data_offset and data_len output for print_file_extent_item in
print-tree.c
WARNING: because the original output has word 'data' before 'offset',
to avoid confusion, remove the work 'data' before 'offset' and 'disk
bytenr'.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
print-tree.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/print-tree.c b/print-tree.c
index 7df5798..9b416bd 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -277,23 +277,29 @@ static void print_file_extent_item(struct extent_buffer *eb,
return;
}
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
- printf("\t\tprealloc data disk byte %llu nr %llu\n",
+ printf("\t\tprealloc disk byte %llu nr %llu\n",
(unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
(unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
- printf("\t\tprealloc data offset %llu nr %llu\n",
+ printf("\t\tprealloc offset %llu nr %llu\n",
(unsigned long long)btrfs_file_extent_offset(eb, fi),
(unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
return;
}
- printf("\t\textent data disk byte %llu nr %llu\n",
+ printf("\t\textent disk byte %llu nr %llu\n",
(unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
(unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
- printf("\t\textent data offset %llu nr %llu ram %llu\n",
+ printf("\t\textent offset %llu nr %llu ram %llu\n",
(unsigned long long)btrfs_file_extent_offset(eb, fi),
(unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
(unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
printf("\t\textent compression %d\n",
btrfs_file_extent_compression(eb, fi));
+ if (btrfs_item_size_nr(eb, slot) > sizeof(*fi))
+ printf("\t\tdata offset %llu nr %llu\n",
+ (unsigned long long)
+ btrfs_ondemand_file_extent_data_offset(eb, slot, fi),
+ (unsigned long long)
+ btrfs_ondemand_file_extent_data_len(eb, slot, fi));
}
/* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] btrfs: Add btrfsck support for nocow compressed prealloc write.
2014-09-18 4:22 [PATCH 1/3] btrfs-progs: Add nocow compressed write into prealloc support Qu Wenruo
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 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2014-09-18 4:22 UTC (permalink / raw)
To: linux-btrfs
Add support for nocow compressed write into preallocated range.
The main change is the following:
1) use disk_bytenr + data_offset to search csum
2) use offset + num_bytes - data_offset to judge if this is a valid
file extent.
3) add file extent item size check,
Since now regular file extent has 2 sizes(one with appended members
and the old one),
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-check.c | 19 ++++++++++++++++---
ctree.h | 1 -
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/cmds-check.c b/cmds-check.c
index 268e588..7a18ad4 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1175,12 +1175,17 @@ static int process_file_extent(struct btrfs_root *root,
num_bytes = (num_bytes + mask) & ~mask;
} else if (extent_type == BTRFS_FILE_EXTENT_REG ||
extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
+ u32 item_size = btrfs_item_size_nr(eb, slot);
num_bytes = btrfs_file_extent_num_bytes(eb, fi);
- disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi);
+ /* data_offset will fallback to 0 on normal extent */
+ disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi) +
+ btrfs_ondemand_file_extent_data_offset(eb,
+ slot, fi);
extent_offset = btrfs_file_extent_offset(eb, fi);
if (num_bytes == 0 || (num_bytes & mask))
rec->errors |= I_ERR_BAD_FILE_EXTENT;
- if (num_bytes + extent_offset >
+ if (num_bytes + extent_offset -
+ btrfs_ondemand_file_extent_data_offset(eb, slot, fi) >
btrfs_file_extent_ram_bytes(eb, fi))
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
@@ -1190,6 +1195,13 @@ static int process_file_extent(struct btrfs_root *root,
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (disk_bytenr > 0)
rec->found_size += num_bytes;
+ if (item_size != BTRFS_FILE_EXTENT_SIZE_NORMAL &&
+ item_size != BTRFS_FILE_EXTENT_SIZE_MAX)
+ rec->errors |= I_ERR_BAD_FILE_EXTENT;
+ if (!btrfs_fs_incompat(root->fs_info,
+ BTRFS_FEATURE_INCOMPAT_COMPPREALLOC) &&
+ (item_size == BTRFS_FILE_EXTENT_SIZE_MAX))
+ rec->errors |= I_ERR_BAD_FILE_EXTENT;
} else {
rec->errors |= I_ERR_BAD_FILE_EXTENT;
}
@@ -1198,7 +1210,8 @@ static int process_file_extent(struct btrfs_root *root,
if (disk_bytenr > 0) {
u64 found;
if (btrfs_file_extent_compression(eb, fi))
- num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi);
+ num_bytes = btrfs_ondemand_file_extent_data_len(eb,
+ slot, fi);
else
disk_bytenr += extent_offset;
diff --git a/ctree.h b/ctree.h
index ab87133..e11e4d8 100644
--- a/ctree.h
+++ b/ctree.h
@@ -834,7 +834,6 @@ struct __compprealloc_data {
__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))
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-18 4:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-18 4:22 [PATCH 1/3] btrfs-progs: Add nocow compressed write into prealloc support Qu Wenruo
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
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).