summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/btrfs-tools
diff options
context:
space:
mode:
authorNitin A Kamble <nitin.a.kamble@intel.com>2011-06-09 18:12:12 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-06-30 20:56:35 +0100
commit0c10be57b72901464d4bb9ea7b5383c42b08bcae (patch)
tree78e8746ac8215577208ce658bfb8001f43d9a6b9 /meta/recipes-devtools/btrfs-tools
parent64497638e70c97f417c2bcdaf99ffcc843ad58ec (diff)
downloadpoky-0c10be57b72901464d4bb9ea7b5383c42b08bcae.tar.gz
btrfs-tools: new recipe for tools to operate on btrfs images
Added these patches to the recipe to get it to work as desired: Upstream patches from tmp & for-dragonn branches of repository http://git.kernel.org/?p=linux/kernel/git/mason/btrfs-progs-unstable.git Also included the debian patches. Nitin's patch to make the makefile cross friendly And Xin Zhong's patch to improve mkfs.btrfs (From OE-Core rev: 57a2140dc9673c65fea088fbd024fbd002e6937b) Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/btrfs-tools')
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/01-labels.patch29
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/02-ftbfs.patch125
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/03-glibc.patch16
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/fix_use_of_gcc.patch84
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/mkfs-xin-fixes.patch183
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0001-Fill-missing-devices-so-degraded-filesystems-can-be-.patch64
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0002-Check-for-RAID10-in-set_avail_alloc_bits.patch35
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0003-Print-the-root-generation-in-btrfs-debug-tree.patch33
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0004-Allow-partial-FS-opens-for-btrfsck-scanning.patch253
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0005-Temporary-debugging-for-dragonn.patch75
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0001-Btrfs-progs-add-a-btrfs-select-super-command-to-over.patch170
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch152
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0003-Btrfs-progs-utils-Informative-errors.patch37
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0004-update-man-page-to-new-defragment-command-interface.patch99
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0005-Improve-error-handling-in-the-btrfs-command.patch510
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0006-Btrfs-progs-update-super-fields-for-space-cache.patch57
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0007-Btrfs-progs-add-support-for-mixed-data-metadata-bloc.patch403
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0008-Update-for-lzo-support.patch203
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0009-Update-clean-up-btrfs-help-and-man-page-V2.patch272
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0010-Deprecate-btrfsctl-btrfs-show-btrfs-vol.patch152
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0011-Add-the-btrfs-filesystem-label-command.patch390
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0012-Btrfs-progs-Update-man-page-for-mixed-data-metadata-.patch42
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0013-btrfs-progs-Add-new-feature-to-mkfs.btrfs-to-make-fi.patch1108
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0014-btrfs-progs-fix-wrong-extent-buffer-size-when-readin.patch33
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0015-btrfs-progs-add-discard-support-to-mkfs.patch110
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools_git.bb52
26 files changed, 4687 insertions, 0 deletions
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/01-labels.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/01-labels.patch
new file mode 100644
index 0000000000..b15a1c98ed
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/01-labels.patch
@@ -0,0 +1,29 @@
1Upstream-Status: Inappropriate [distribution: debian]
2
3Author: Chris Mason <chris.mason@oracle.com>
4Description: Allow /'s in labels.
5
6diff -Naurp btrfs-tools.orig/mkfs.c btrfs-tools/mkfs.c
7--- btrfs-tools.orig/mkfs.c 2009-03-15 13:27:12.000000000 +0100
8+++ btrfs-tools/mkfs.c 2009-04-17 20:53:12.000000000 +0200
9@@ -294,7 +294,6 @@ static u64 parse_profile(char *s)
10
11 static char *parse_label(char *input)
12 {
13- int i;
14 int len = strlen(input);
15
16 if (len > BTRFS_LABEL_SIZE) {
17@@ -302,12 +301,6 @@ static char *parse_label(char *input)
18 BTRFS_LABEL_SIZE);
19 exit(1);
20 }
21- for (i = 0; i < len; i++) {
22- if (input[i] == '/' || input[i] == '\\') {
23- fprintf(stderr, "invalid label %s\n", input);
24- exit(1);
25- }
26- }
27 return strdup(input);
28 }
29
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/02-ftbfs.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/02-ftbfs.patch
new file mode 100644
index 0000000000..7b47190757
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/02-ftbfs.patch
@@ -0,0 +1,125 @@
1Upstream-Status: Inappropriate [distribution: debian]
2
3Authors:
4 Luca Bruno <lucab@debian.org>
5 Alexander Kurtz <kurtz.alex@googlemail.com>
6 Daniel Baumann <daniel@debian.org>
7Description:
8 Patch to properly cast and avoiding compiler warnings. Fixes FTBFS on alpha
9 and ia64 (Closes: #539433, #583768).
10
11diff -Naurp btrfs-tools.orig/btrfsctl.c btrfs-tools/btrfsctl.c
12--- btrfs-tools.orig/btrfsctl.c 2010-06-01 07:22:33.000000000 +0200
13+++ btrfs-tools/btrfsctl.c 2010-06-05 08:44:05.000000000 +0200
14@@ -234,7 +234,7 @@ int main(int ac, char **av)
15 args.fd = fd;
16 ret = ioctl(snap_fd, command, &args);
17 } else if (command == BTRFS_IOC_DEFAULT_SUBVOL) {
18- printf("objectid is %llu\n", objectid);
19+ printf("objectid is %llu\n", (long long unsigned int) objectid);
20 ret = ioctl(fd, command, &objectid);
21 } else
22 ret = ioctl(fd, command, &args);
23diff -Naurp btrfs-tools.orig/btrfs-list.c btrfs-tools/btrfs-list.c
24--- btrfs-tools.orig/btrfs-list.c 2010-06-01 07:22:33.000000000 +0200
25+++ btrfs-tools/btrfs-list.c 2010-06-05 08:47:27.000000000 +0200
26@@ -248,8 +248,9 @@ static int resolve_root(struct root_look
27 break;
28 }
29 }
30- printf("ID %llu top level %llu path %s\n", ri->root_id, top_id,
31- full_path);
32+ printf("ID %llu top level %llu path %s\n",
33+ (long long unsigned int) ri->root_id,
34+ (long long unsigned int) top_id, full_path);
35 free(full_path);
36 return 0;
37 }
38diff -Naurp btrfs-tools.orig/btrfs-map-logical.c btrfs-tools/btrfs-map-logical.c
39--- btrfs-tools.orig/btrfs-map-logical.c 2010-06-01 07:22:33.000000000 +0200
40+++ btrfs-tools/btrfs-map-logical.c 2010-06-05 08:48:10.000000000 +0200
41@@ -65,8 +65,9 @@ struct extent_buffer *debug_read_block(s
42 eb->dev_bytenr = multi->stripes[0].physical;
43
44 fprintf(info_file, "mirror %d logical %Lu physical %Lu "
45- "device %s\n", mirror_num, bytenr, eb->dev_bytenr,
46- device->name);
47+ "device %s\n", mirror_num,
48+ (long long unsigned int) bytenr,
49+ (long long unsigned int) eb->dev_bytenr, device->name);
50 kfree(multi);
51
52 if (!copy || mirror_num == copy)
53diff -Naurp btrfs-tools.orig/convert.c btrfs-tools/convert.c
54--- btrfs-tools.orig/convert.c 2010-06-01 07:22:33.000000000 +0200
55+++ btrfs-tools/convert.c 2010-06-05 08:43:29.000000000 +0200
56@@ -2572,7 +2572,7 @@ int do_rollback(const char *devname, int
57 ext2_root = btrfs_read_fs_root(root->fs_info, &key);
58 if (!ext2_root || IS_ERR(ext2_root)) {
59 fprintf(stderr, "unable to open subvol %llu\n",
60- key.objectid);
61+ (unsigned long long) key.objectid);
62 goto fail;
63 }
64
65diff -Naurp btrfs-tools.orig/debug-tree.c btrfs-tools/debug-tree.c
66--- btrfs-tools.orig/debug-tree.c 2010-06-01 07:22:33.000000000 +0200
67+++ btrfs-tools/debug-tree.c 2010-06-05 08:46:17.000000000 +0200
68@@ -162,7 +162,8 @@ int main(int ac, char **av)
69 root->nodesize, 0);
70 }
71 if (!leaf) {
72- fprintf(stderr, "failed to read %llu\n", block_only);
73+ fprintf(stderr, "failed to read %llu\n",
74+ (long long unsigned int) block_only);
75 return 0;
76 }
77 btrfs_print_tree(root, leaf, 0);
78diff -Naurp btrfs-tools.orig/disk-io.c btrfs-tools/disk-io.c
79--- btrfs-tools.orig/disk-io.c 2010-06-01 07:18:01.000000000 +0200
80+++ btrfs-tools/disk-io.c 2010-06-05 08:43:29.000000000 +0200
81@@ -678,7 +678,8 @@ struct btrfs_root *open_ctree_fd(int fp,
82 ~BTRFS_FEATURE_INCOMPAT_SUPP;
83 if (features) {
84 printk("couldn't open because of unsupported "
85- "option features (%Lx).\n", features);
86+ "option features (%Lx).\n",
87+ (unsigned long long)features);
88 BUG_ON(1);
89 }
90
91@@ -692,7 +693,8 @@ struct btrfs_root *open_ctree_fd(int fp,
92 ~BTRFS_FEATURE_COMPAT_RO_SUPP;
93 if (writes && features) {
94 printk("couldn't open RDWR because of unsupported "
95- "option features (%Lx).\n", features);
96+ "option features (%Lx).\n",
97+ (unsigned long long) features);
98 BUG_ON(1);
99 }
100
101diff -Naurp btrfs-tools.orig/extent-tree.c btrfs-tools/extent-tree.c
102--- btrfs-tools.orig/extent-tree.c 2010-06-01 07:18:01.000000000 +0200
103+++ btrfs-tools/extent-tree.c 2010-06-05 08:43:29.000000000 +0200
104@@ -1448,7 +1448,8 @@ int btrfs_lookup_extent_info(struct btrf
105 goto out;
106 if (ret != 0) {
107 btrfs_print_leaf(root, path->nodes[0]);
108- printk("failed to find block number %Lu\n", bytenr);
109+ printk("failed to find block number %Lu\n",
110+ (unsigned long long) bytenr);
111 BUG();
112 }
113
114diff -Naurp btrfs-tools.orig/print-tree.c btrfs-tools/print-tree.c
115--- btrfs-tools.orig/print-tree.c 2010-06-01 07:22:33.000000000 +0200
116+++ btrfs-tools/print-tree.c 2010-06-05 08:43:29.000000000 +0200
117@@ -494,7 +494,7 @@ void btrfs_print_leaf(struct btrfs_root
118 case BTRFS_DIR_LOG_ITEM_KEY:
119 dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item);
120 printf("\t\tdir log end %Lu\n",
121- btrfs_dir_log_end(l, dlog));
122+ (unsigned long long) btrfs_dir_log_end(l, dlog));
123 break;
124 case BTRFS_ORPHAN_ITEM_KEY:
125 printf("\t\torphan item\n");
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/03-glibc.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/03-glibc.patch
new file mode 100644
index 0000000000..dc26148f17
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/debian/03-glibc.patch
@@ -0,0 +1,16 @@
1Upstream-Status: Inappropriate [distribution: debian]
2
3Author: Colin Watson <cjwatson@debian.org>
4Description: Fixes FTBFS with glibc 2.12 (Closes; #586111).
5
6diff -Naurp btrfs-tools.orig//btrfsck.c btrfs-tools/btrfsck.c
7--- btrfs-tools.orig//btrfsck.c 2010-06-05 09:06:38.000000000 +0200
8+++ btrfs-tools/btrfsck.c 2010-06-16 16:16:10.000000000 +0200
9@@ -21,6 +21,7 @@
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <fcntl.h>
13+#include <sys/stat.h>
14 #include "kerncompat.h"
15 #include "ctree.h"
16 #include "disk-io.h"
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/fix_use_of_gcc.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/fix_use_of_gcc.patch
new file mode 100644
index 0000000000..0a5fb349c0
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/fix_use_of_gcc.patch
@@ -0,0 +1,84 @@
1Nitin A Kamble <nitin.a.kamble@intel.com> 2011/06/09
2UpstreamStatus: Pending
3
4Avoid these kinds of errors while doing cross build:
5
6| ccache i586-poky-linux-gcc -march=i586 --sysroot=/disk0/pokybuild/build0/tmp/sysroots/qemux86 -Wp,-MMD,./.btrfsctl.o.d,-MT,btrfsctl.o -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -O2 -pipe -g -feliminate-unused-debug-types -c btrfsctl.c
7| gcc -O2 -pipe -g -feliminate-unused-debug-types -o btrfsctl btrfsctl.o ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o btrfs-list.o -Wl,-O1 -Wl,--as-needed -luuid
8| /usr/bin/ld: i386 architecture of input file `btrfsctl.o' is incompatible with i386:x86-64 output
9| /usr/bin/ld: i386 architecture of input file `ctree.o' is incompatible with i386:x86-64 output
10
11Index: git/Makefile
12===================================================================
13--- git.orig/Makefile
14+++ git/Makefile
15@@ -38,53 +38,53 @@ version:
16 bash version.sh
17
18 btrfs: $(objects) btrfs.o btrfs_cmds.o
19- gcc $(CFLAGS) -o btrfs btrfs.o btrfs_cmds.o \
20+ $(CC) $(CFLAGS) -o btrfs btrfs.o btrfs_cmds.o \
21 $(objects) $(LDFLAGS) $(LIBS)
22
23 btrfsctl: $(objects) btrfsctl.o
24- gcc $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
25+ $(CC) $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
26
27 btrfs-vol: $(objects) btrfs-vol.o
28- gcc $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS)
29+ $(CC) $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS)
30
31 btrfs-show: $(objects) btrfs-show.o
32- gcc $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS)
33+ $(CC) $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS)
34
35 btrfsck: $(objects) btrfsck.o
36- gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) $(LDFLAGS) $(LIBS)
37+ $(CC) $(CFLAGS) -o btrfsck btrfsck.o $(objects) $(LDFLAGS) $(LIBS)
38
39 mkfs.btrfs: $(objects) mkfs.o
40- gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
41+ $(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
42
43 btrfs-debug-tree: $(objects) debug-tree.o
44- gcc $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
45+ $(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
46
47 btrfs-zero-log: $(objects) btrfs-zero-log.o
48- gcc $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
49+ $(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
50
51 btrfs-select-super: $(objects) btrfs-select-super.o
52- gcc $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
53+ $(CC) $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
54
55 btrfstune: $(objects) btrfstune.o
56- gcc $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
57+ $(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
58
59 btrfs-map-logical: $(objects) btrfs-map-logical.o
60- gcc $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
61+ $(CC) $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
62
63 btrfs-image: $(objects) btrfs-image.o
64- gcc $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
65+ $(CC) $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
66
67 dir-test: $(objects) dir-test.o
68- gcc $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
69+ $(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
70
71 quick-test: $(objects) quick-test.o
72- gcc $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
73+ $(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
74
75 convert: $(objects) convert.o
76- gcc $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
77+ $(CC) $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
78
79 ioctl-test: $(objects) ioctl-test.o
80- gcc $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
81+ $(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
82
83 manpages:
84 cd man; make
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/mkfs-xin-fixes.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/mkfs-xin-fixes.patch
new file mode 100644
index 0000000000..47fc97725a
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/mkfs-xin-fixes.patch
@@ -0,0 +1,183 @@
1Upstream-Status: Pending
2
3This patch is made by xin.zhong@intel.com to implement these supported
4features in mkfs.btrfs:
5 * populate fs image from a directory while creating it
6 * reduce minimum size of the created image from 256MB to around 24MB
7 * while creating image use the specified device name rather than output.img
8
9Patch tested and incorporated in poky by:
10Nitin A Kamble <nitin.a.kamble@intel.com> 2011/06/20
11
12diff --git a/file-item.c b/file-item.c
13index 9732282..aed42c3 100644
14--- a/file-item.c
15+++ b/file-item.c
16@@ -193,7 +193,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
17 struct btrfs_root *root, u64 alloc_end,
18 u64 bytenr, char *data, size_t len)
19 {
20- int ret;
21+ int ret = 0;
22 struct btrfs_key file_key;
23 struct btrfs_key found_key;
24 u64 next_offset = (u64)-1;
25diff --git a/mkfs.c b/mkfs.c
26index 57c88f9..e953a33 100644
27--- a/mkfs.c
28+++ b/mkfs.c
29@@ -36,7 +36,7 @@
30 #include <uuid/uuid.h>
31 #include <linux/fs.h>
32 #include <ctype.h>
33-#include <attr/xattr.h>
34+#include <sys/xattr.h>
35 #include "kerncompat.h"
36 #include "ctree.h"
37 #include "disk-io.h"
38@@ -517,7 +517,6 @@ static int add_inode_items(struct btrfs_trans_handle *trans,
39 fail:
40 return ret;
41 }
42-
43 static int add_xattr_item(struct btrfs_trans_handle *trans,
44 struct btrfs_root *root, u64 objectid,
45 const char *file_name)
46@@ -532,8 +531,10 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
47
48 ret = llistxattr(file_name, xattr_list, XATTR_LIST_MAX);
49 if (ret < 0) {
50- fprintf(stderr, "get a list of xattr failed for %s\n",
51- file_name);
52+ if(errno == ENOTSUP)
53+ return 0;
54+ fprintf(stderr, "get a list of xattr failed for %s errno %d\n",
55+ file_name, errno);
56 return ret;
57 }
58 if (ret == 0)
59@@ -546,8 +547,11 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
60
61 ret = getxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
62 if (ret < 0) {
63- fprintf(stderr, "get a xattr value failed for %s\n",
64- cur_name);
65+ if(errno == ENOTSUP)
66+ return 0;
67+ fprintf(stderr, "get a xattr value failed for %s attr %s errno %d\n",
68+ file_name, cur_name, errno);
69+ return ret;
70 }
71
72 ret = btrfs_insert_xattr_item(trans, root, cur_name,
73@@ -563,7 +567,6 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
74
75 return ret;
76 }
77-
78 static int custom_alloc_extent(struct btrfs_root *root, u64 num_bytes,
79 u64 hint_byte, struct btrfs_key *ins)
80 {
81@@ -923,27 +926,27 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
82 fprintf(stderr, "add_inode_items failed\n");
83 goto fail;
84 }
85-
86 ret = add_xattr_item(trans, root,
87 cur_inum, cur_file->d_name);
88 if (ret) {
89 fprintf(stderr, "add_xattr_item failed\n");
90- goto fail;
91+ if(ret != -ENOTSUP)
92+ goto fail;
93 }
94-
95 if (S_ISDIR(st.st_mode)) {
96 dir_entry = malloc(sizeof(struct directory_name_entry));
97 dir_entry->dir_name = cur_file->d_name;
98 dir_entry->path = make_path(parent_dir_entry->path,
99 cur_file->d_name);
100 dir_entry->inum = cur_inum;
101- list_add_tail(&dir_entry->list, &dir_head->list);
102+ list_add_tail(&dir_entry->list, &dir_head->list);
103 } else if (S_ISREG(st.st_mode)) {
104 ret = add_file_items(trans, root, &cur_inode,
105 cur_inum, parent_inum, &st,
106 cur_file->d_name, out_fd);
107 if (ret) {
108- fprintf(stderr, "add_file_items failed\n");
109+ fprintf(stderr, "add_file_items failed %s\n",
110+ cur_file->d_name);
111 goto fail;
112 }
113 } else if (S_ISLNK(st.st_mode)) {
114@@ -987,7 +990,7 @@ static int create_chunks(struct btrfs_trans_handle *trans,
115 u64 chunk_size;
116 u64 meta_type = BTRFS_BLOCK_GROUP_METADATA;
117 u64 data_type = BTRFS_BLOCK_GROUP_DATA;
118- u64 minimum_data_chunk_size = 64 * 1024 * 1024;
119+ u64 minimum_data_chunk_size = 8 * 1024 * 1024;
120 u64 i;
121 int ret;
122
123@@ -1062,7 +1065,6 @@ static u64 size_sourcedir(char *dir_name, u64 sectorsize,
124 char path[512];
125 char *file_name = "temp_file";
126 FILE *file;
127- u64 minimum_data_size = 256 * 1024 * 1024; /* 256MB */
128 u64 default_chunk_size = 8 * 1024 * 1024; /* 8MB */
129 u64 allocated_meta_size = 8 * 1024 * 1024; /* 8MB */
130 u64 allocated_total_size = 20 * 1024 * 1024; /* 20MB */
131@@ -1101,9 +1103,6 @@ static u64 size_sourcedir(char *dir_name, u64 sectorsize,
132
133 *num_of_meta_chunks_ret = num_of_meta_chunks;
134
135- if (total_size < minimum_data_size)
136- total_size = minimum_data_size;
137-
138 return total_size;
139 }
140
141@@ -1158,9 +1157,9 @@ int main(int ac, char **av)
142
143 char *source_dir = NULL;
144 int source_dir_set = 0;
145- char *output = "output.img";
146 u64 num_of_meta_chunks = 0;
147 u64 size_of_data = 0;
148+ u64 source_dir_size = 0;
149
150 while(1) {
151 int c;
152@@ -1224,8 +1223,6 @@ int main(int ac, char **av)
153 fprintf(stderr, "Illegal nodesize %u\n", nodesize);
154 exit(1);
155 }
156- if (source_dir_set)
157- ac++;
158 ac = ac - optind;
159 if (ac == 0)
160 print_usage();
161@@ -1257,17 +1254,19 @@ int main(int ac, char **av)
162 block_count = dev_block_count;
163 } else {
164 ac = 0;
165- fd = open_target(output);
166+ file = av[optind++];
167+ fd = open_target(file);
168 if (fd < 0) {
169 fprintf(stderr, "unable to open the %s\n", file);
170 exit(1);
171 }
172
173- file = output;
174 first_fd = fd;
175 first_file = file;
176- block_count = size_sourcedir(source_dir, sectorsize,
177+ source_dir_size = size_sourcedir(source_dir, sectorsize,
178 &num_of_meta_chunks, &size_of_data);
179+ if(block_count < source_dir_size)
180+ block_count = source_dir_size;
181 ret = zero_output_file(fd, block_count, sectorsize);
182 if (ret) {
183 fprintf(stderr, "unable to zero the output file\n");
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0001-Fill-missing-devices-so-degraded-filesystems-can-be-.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0001-Fill-missing-devices-so-degraded-filesystems-can-be-.patch
new file mode 100644
index 0000000000..e4665335ee
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0001-Fill-missing-devices-so-degraded-filesystems-can-be-.patch
@@ -0,0 +1,64 @@
1Upstream-Status: Inappropriate [Backport]
2From a6c54702d8973aef081cff81ed8d90427bb21768 Mon Sep 17 00:00:00 2001
3From: Chris Mason <chris.mason@oracle.com>
4Date: Wed, 15 Dec 2010 16:00:23 -0500
5Subject: [PATCH 1/5] Fill missing devices so degraded filesystems can be read
6
7When a device is missing, the btrfs tools need to be able to read alternate
8copies from the remaining devices. This creates placeholder devices
9that always return -EIO so the tools can limp along.
10
11Signed-off-by: Chris Mason <chris.mason@oracle.com>
12---
13 disk-io.c | 1 +
14 volumes.c | 15 +++++++++++++--
15 2 files changed, 14 insertions(+), 2 deletions(-)
16
17diff --git a/disk-io.c b/disk-io.c
18index 5bd9cfc..f4368f3 100644
19--- a/disk-io.c
20+++ b/disk-io.c
21@@ -204,6 +204,7 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
22 eb->dev_bytenr = multi->stripes[0].physical;
23 kfree(multi);
24 ret = read_extent_from_disk(eb);
25+
26 if (ret == 0 && check_tree_block(root, eb) == 0 &&
27 csum_tree_block(root, eb, 1) == 0 &&
28 verify_parent_transid(eb->tree, eb, parent_transid) == 0) {
29diff --git a/volumes.c b/volumes.c
30index 4bb77e2..5773467 100644
31--- a/volumes.c
32+++ b/volumes.c
33@@ -1263,6 +1263,16 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset)
34 return readonly;
35 }
36
37+static struct btrfs_device *fill_missing_device(u64 devid)
38+{
39+ struct btrfs_device *device;
40+
41+ device = kzalloc(sizeof(*device), GFP_NOFS);
42+ device->devid = devid;
43+ device->fd = -1;
44+ return device;
45+}
46+
47 static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
48 struct extent_buffer *leaf,
49 struct btrfs_chunk *chunk)
50@@ -1313,8 +1323,9 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
51 map->stripes[i].dev = btrfs_find_device(root, devid, uuid,
52 NULL);
53 if (!map->stripes[i].dev) {
54- kfree(map);
55- return -EIO;
56+ map->stripes[i].dev = fill_missing_device(devid);
57+ printf("warning, device %llu is missing\n",
58+ (unsigned long long)devid);
59 }
60
61 }
62--
631.7.2.3
64
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0002-Check-for-RAID10-in-set_avail_alloc_bits.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0002-Check-for-RAID10-in-set_avail_alloc_bits.patch
new file mode 100644
index 0000000000..c8557f7863
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0002-Check-for-RAID10-in-set_avail_alloc_bits.patch
@@ -0,0 +1,35 @@
1Upstream-Status: Inappropriate [Backport]
2From 454a0538680bc17656cefadef1f167917ea0b856 Mon Sep 17 00:00:00 2001
3From: Chris Mason <chris.mason@oracle.com>
4Date: Wed, 15 Dec 2010 16:02:45 -0500
5Subject: [PATCH 2/5] Check for RAID10 in set_avail_alloc_bits
6
7When raid is setup with mkfs, it is supposed to cow the initial filesystem
8it creates up to the desired raid level. RAID10 was not in the list
9of RAID levels it checked for, so the initial FS created for RAID10
10actually only lived on the first disk.
11
12This works well enough because all the roots get quickly cowed during the
13first mount. The exception is the data relocation tree, which only gets
14cowed when we do a balance.
15
16Signed-off-by: Chris Mason <chris.mason@oracle.com>
17---
18 extent-tree.c | 1 +
19 1 files changed, 1 insertions(+), 0 deletions(-)
20
21diff --git a/extent-tree.c b/extent-tree.c
22index b2f9bb2..108933f 100644
23--- a/extent-tree.c
24+++ b/extent-tree.c
25@@ -1775,6 +1775,7 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
26 {
27 u64 extra_flags = flags & (BTRFS_BLOCK_GROUP_RAID0 |
28 BTRFS_BLOCK_GROUP_RAID1 |
29+ BTRFS_BLOCK_GROUP_RAID10 |
30 BTRFS_BLOCK_GROUP_DUP);
31 if (extra_flags) {
32 if (flags & BTRFS_BLOCK_GROUP_DATA)
33--
341.7.2.3
35
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0003-Print-the-root-generation-in-btrfs-debug-tree.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0003-Print-the-root-generation-in-btrfs-debug-tree.patch
new file mode 100644
index 0000000000..ad416208b2
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0003-Print-the-root-generation-in-btrfs-debug-tree.patch
@@ -0,0 +1,33 @@
1Upstream-Status: Inappropriate [Backport]
2From d5b8b904ac40e4c5dbff4008accd7e588b697085 Mon Sep 17 00:00:00 2001
3From: Chris Mason <chris.mason@oracle.com>
4Date: Wed, 15 Dec 2010 16:03:00 -0500
5Subject: [PATCH 3/5] Print the root generation in btrfs-debug-tree
6
7Signed-off-by: Chris Mason <chris.mason@oracle.com>
8---
9 print-tree.c | 5 +++--
10 1 files changed, 3 insertions(+), 2 deletions(-)
11
12diff --git a/print-tree.c b/print-tree.c
13index ac575d5..85399aa 100644
14--- a/print-tree.c
15+++ b/print-tree.c
16@@ -505,11 +505,12 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
17 case BTRFS_ROOT_ITEM_KEY:
18 ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
19 read_extent_buffer(l, &root_item, (unsigned long)ri, sizeof(root_item));
20- printf("\t\troot data bytenr %llu level %d dirid %llu refs %u\n",
21+ printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu\n",
22 (unsigned long long)btrfs_root_bytenr(&root_item),
23 btrfs_root_level(&root_item),
24 (unsigned long long)btrfs_root_dirid(&root_item),
25- btrfs_root_refs(&root_item));
26+ btrfs_root_refs(&root_item),
27+ (unsigned long long)btrfs_root_generation(&root_item));
28 if (btrfs_root_refs(&root_item) == 0) {
29 struct btrfs_key drop_key;
30 btrfs_disk_key_to_cpu(&drop_key,
31--
321.7.2.3
33
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0004-Allow-partial-FS-opens-for-btrfsck-scanning.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0004-Allow-partial-FS-opens-for-btrfsck-scanning.patch
new file mode 100644
index 0000000000..cf8700723f
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0004-Allow-partial-FS-opens-for-btrfsck-scanning.patch
@@ -0,0 +1,253 @@
1Upstream-Status: Inappropriate [Backport]
2From 238f88bb6c4b9ebad727c6bffb57f542e7e412c1 Mon Sep 17 00:00:00 2001
3From: Chris Mason <chris.mason@oracle.com>
4Date: Sun, 19 Dec 2010 16:22:31 -0500
5Subject: [PATCH 4/5] Allow partial FS opens for btrfsck scanning
6
7Signed-off-by: Chris Mason <chris.mason@oracle.com>
8---
9 btrfsck.c | 10 ++++++++--
10 convert.c | 20 ++++++++++++++------
11 disk-io.c | 57 +++++++++++++++++++++++++++++++++++++++++----------------
12 disk-io.h | 5 +++--
13 4 files changed, 66 insertions(+), 26 deletions(-)
14
15diff --git a/btrfsck.c b/btrfsck.c
16index 63e44d1..f760706 100644
17--- a/btrfsck.c
18+++ b/btrfsck.c
19@@ -2820,6 +2820,7 @@ int main(int ac, char **av)
20 {
21 struct cache_tree root_cache;
22 struct btrfs_root *root;
23+ struct btrfs_fs_info *info;
24 u64 bytenr = 0;
25 int ret;
26 int num;
27@@ -2856,11 +2857,16 @@ int main(int ac, char **av)
28 return -EBUSY;
29 }
30
31- root = open_ctree(av[optind], bytenr, 0);
32+ info = open_fs_info(av[optind], bytenr, 0, 1);
33
34- if (root == NULL)
35+ if (info == NULL)
36 return 1;
37
38+ root = info->fs_root;
39+ if (!root) {
40+ fprintf(stderr, "failed to read the filesystem\n");
41+ exit(1);
42+ }
43 ret = check_extents(root);
44 if (ret)
45 goto out;
46diff --git a/convert.c b/convert.c
47index fbcf4a3..72e3cdc 100644
48--- a/convert.c
49+++ b/convert.c
50@@ -2342,6 +2342,7 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
51 ext2_filsys ext2_fs;
52 struct btrfs_root *root;
53 struct btrfs_root *ext2_root;
54+ struct btrfs_fs_info *fs_info;
55
56 ret = open_ext2fs(devname, &ext2_fs);
57 if (ret) {
58@@ -2386,11 +2387,12 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
59 fprintf(stderr, "unable to update system chunk\n");
60 goto fail;
61 }
62- root = open_ctree_fd(fd, devname, super_bytenr, O_RDWR);
63- if (!root) {
64+ fs_info = open_ctree_fd(fd, devname, super_bytenr, O_RDWR, 0);
65+ if (!fs_info) {
66 fprintf(stderr, "unable to open ctree\n");
67 goto fail;
68 }
69+ root = fs_info->fs_root;
70 ret = cache_free_extents(root, ext2_fs);
71 if (ret) {
72 fprintf(stderr, "error during cache_free_extents %d\n", ret);
73@@ -2447,11 +2449,13 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
74 goto fail;
75 }
76
77- root = open_ctree_fd(fd, devname, 0, O_RDWR);
78- if (!root) {
79+ fs_info = open_ctree_fd(fd, devname, 0, O_RDWR, 0);
80+ if (!fs_info) {
81 fprintf(stderr, "unable to open ctree\n");
82 goto fail;
83 }
84+ root = fs_info->fs_root;
85+
86 /* move chunk tree into system chunk. */
87 ret = fixup_chunk_mapping(root);
88 if (ret) {
89@@ -2525,6 +2529,7 @@ int do_rollback(const char *devname, int force)
90 struct btrfs_key key;
91 struct btrfs_path path;
92 struct extent_io_tree io_tree;
93+ struct btrfs_fs_info *fs_info;
94 char *buf;
95 char *name;
96 u64 bytenr;
97@@ -2546,11 +2551,14 @@ int do_rollback(const char *devname, int force)
98 fprintf(stderr, "unable to open %s\n", devname);
99 goto fail;
100 }
101- root = open_ctree_fd(fd, devname, 0, O_RDWR);
102- if (!root) {
103+
104+ fs_info = open_ctree_fd(fd, devname, 0, O_RDWR, 0);
105+ if (!fs_info) {
106 fprintf(stderr, "unable to open ctree\n");
107 goto fail;
108 }
109+ root = fs_info->fs_root;
110+
111 ret = may_rollback(root);
112 if (ret < 0) {
113 fprintf(stderr, "unable to do rollback\n");
114diff --git a/disk-io.c b/disk-io.c
115index f4368f3..dc100b0 100644
116--- a/disk-io.c
117+++ b/disk-io.c
118@@ -441,7 +441,8 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
119 btrfs_super_generation(disk_super) + 1);
120
121 fs_info->log_root_tree = log_root;
122- BUG_ON(!log_root->node);
123+ if (!log_root->node)
124+ return -EIO;
125 return 0;
126 }
127
128@@ -571,10 +572,11 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
129 return root;
130 }
131
132-struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
133+struct btrfs_fs_info *open_fs_info(const char *filename, u64 sb_bytenr,
134+ int writes, int partial)
135 {
136 int fp;
137- struct btrfs_root *root;
138+ struct btrfs_fs_info *fs_info;
139 int flags = O_CREAT | O_RDWR;
140
141 if (!writes)
142@@ -585,14 +587,25 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
143 fprintf (stderr, "Could not open %s\n", filename);
144 return NULL;
145 }
146- root = open_ctree_fd(fp, filename, sb_bytenr, writes);
147+ fs_info = open_ctree_fd(fp, filename, sb_bytenr, writes, partial);
148+
149 close(fp);
150+ return fs_info;
151+}
152
153- return root;
154+
155+struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
156+{
157+ struct btrfs_fs_info *fs_info;
158+
159+ fs_info = open_fs_info(filename, sb_bytenr, writes, 0);
160+ if (fs_info)
161+ return fs_info->fs_root;
162+ return NULL;
163 }
164
165-struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
166- int writes)
167+struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
168+ int writes, int partial)
169 {
170 u32 sectorsize;
171 u32 nodesize;
172@@ -727,7 +740,8 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
173
174 if (!(btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_METADUMP)) {
175 ret = btrfs_read_chunk_tree(chunk_root);
176- BUG_ON(ret);
177+ if (ret)
178+ goto fail;
179 }
180
181 blocksize = btrfs_level_size(tree_root,
182@@ -737,25 +751,32 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
183 tree_root->node = read_tree_block(tree_root,
184 btrfs_super_root(disk_super),
185 blocksize, generation);
186- BUG_ON(!tree_root->node);
187+ if (!tree_root->node)
188+ goto fail;
189+
190 ret = find_and_setup_root(tree_root, fs_info,
191 BTRFS_EXTENT_TREE_OBJECTID, extent_root);
192- BUG_ON(ret);
193+ if (ret)
194+ goto fail;
195+
196 extent_root->track_dirty = 1;
197
198 ret = find_and_setup_root(tree_root, fs_info,
199 BTRFS_DEV_TREE_OBJECTID, dev_root);
200- BUG_ON(ret);
201+ if (ret)
202+ goto fail;
203+
204 dev_root->track_dirty = 1;
205
206 ret = find_and_setup_root(tree_root, fs_info,
207 BTRFS_CSUM_TREE_OBJECTID, csum_root);
208- BUG_ON(ret);
209+ if (ret)
210+ goto fail;
211 csum_root->track_dirty = 1;
212
213- BUG_ON(ret);
214-
215- find_and_setup_log_root(tree_root, fs_info, disk_super);
216+ ret = find_and_setup_log_root(tree_root, fs_info, disk_super);
217+ if (ret)
218+ goto fail;
219
220 fs_info->generation = generation + 1;
221 btrfs_read_block_groups(fs_info->tree_root);
222@@ -769,7 +790,11 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
223 fs_info->metadata_alloc_profile = (u64)-1;
224 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
225
226- return fs_info->fs_root;
227+ return fs_info;
228+fail:
229+ if (partial)
230+ return fs_info;
231+ return NULL;
232 }
233
234 int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
235diff --git a/disk-io.h b/disk-io.h
236index 7ebec24..03c5eee 100644
237--- a/disk-io.h
238+++ b/disk-io.h
239@@ -44,8 +44,9 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
240 int clean_tree_block(struct btrfs_trans_handle *trans,
241 struct btrfs_root *root, struct extent_buffer *buf);
242 struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes);
243-struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
244- int writes);
245+struct btrfs_fs_info *open_fs_info(const char *filename, u64 sb_bytenr, int writes, int partial);
246+struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
247+ int writes, int partial);
248 int close_ctree(struct btrfs_root *root);
249 int write_all_supers(struct btrfs_root *root);
250 int write_ctree_super(struct btrfs_trans_handle *trans,
251--
2521.7.2.3
253
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0005-Temporary-debugging-for-dragonn.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0005-Temporary-debugging-for-dragonn.patch
new file mode 100644
index 0000000000..54123f729d
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-for-dragonn/0005-Temporary-debugging-for-dragonn.patch
@@ -0,0 +1,75 @@
1Upstream-Status: Inappropriate [Backport]
2From e3064e90cfd0be823b2da3edff64f97756fcc245 Mon Sep 17 00:00:00 2001
3From: Chris Mason <chris.mason@oracle.com>
4Date: Mon, 25 Apr 2011 16:31:40 -0400
5Subject: [PATCH 5/5] Temporary debugging for dragonn
6
7Signed-off-by: Chris Mason <chris.mason@oracle.com>
8---
9 btrfsck.c | 3 +++
10 disk-io.c | 16 ++++++++--------
11 2 files changed, 11 insertions(+), 8 deletions(-)
12
13diff --git a/btrfsck.c b/btrfsck.c
14index f760706..cb3dee0 100644
15--- a/btrfsck.c
16+++ b/btrfsck.c
17@@ -855,6 +855,7 @@ static u64 count_csum_range(struct btrfs_root *root, u64 start, u64 len)
18 u64 csum_end;
19 u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy);
20
21+ return 0;
22 btrfs_init_path(&path);
23
24 key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
25@@ -2666,6 +2667,8 @@ static int add_root_to_pending(struct extent_buffer *buf,
26 struct cache_tree *nodes,
27 struct btrfs_key *root_key)
28 {
29+ if (root_key->objectid == 7)
30+ return 0;
31 if (btrfs_header_level(buf) > 0)
32 add_pending(nodes, seen, buf->start, buf->len);
33 else
34diff --git a/disk-io.c b/disk-io.c
35index dc100b0..c242364 100644
36--- a/disk-io.c
37+++ b/disk-io.c
38@@ -614,12 +614,12 @@ struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
39 u32 stripesize;
40 u64 generation;
41 struct btrfs_key key;
42- struct btrfs_root *tree_root = malloc(sizeof(struct btrfs_root));
43- struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root));
44- struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root));
45- struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root));
46- struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root));
47- struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info));
48+ struct btrfs_root *tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
49+ struct btrfs_root *extent_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
50+ struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
51+ struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
52+ struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
53+ struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info), GFP_NOFS);
54 int ret;
55 struct btrfs_super_block *disk_super;
56 struct btrfs_fs_devices *fs_devices = NULL;
57@@ -767,13 +767,13 @@ struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
58 goto fail;
59
60 dev_root->track_dirty = 1;
61-
62+#if 0
63 ret = find_and_setup_root(tree_root, fs_info,
64 BTRFS_CSUM_TREE_OBJECTID, csum_root);
65 if (ret)
66 goto fail;
67 csum_root->track_dirty = 1;
68-
69+#endif
70 ret = find_and_setup_log_root(tree_root, fs_info, disk_super);
71 if (ret)
72 goto fail;
73--
741.7.2.3
75
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0001-Btrfs-progs-add-a-btrfs-select-super-command-to-over.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0001-Btrfs-progs-add-a-btrfs-select-super-command-to-over.patch
new file mode 100644
index 0000000000..2102f08e96
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0001-Btrfs-progs-add-a-btrfs-select-super-command-to-over.patch
@@ -0,0 +1,170 @@
1Upstream-Status: Inappropriate [Backport]
2From 70c6c10134b502fa69955746554031939b85fb0c Mon Sep 17 00:00:00 2001
3From: Chris Mason <chris.mason@oracle.com>
4Date: Thu, 9 Dec 2010 16:36:29 -0500
5Subject: [PATCH 01/15] Btrfs-progs: add a btrfs-select-super command to overwrite the super
6
7Btrfs stores multiple copies of the superblock, and for common power-failure
8crashes where barriers were not in use, one of the super copies is often
9valid while the first copy is not.
10
11This adds a btrfs-select-super -s N /dev/xxx command, which can
12overwrite all the super blocks with a copy that you have already
13determined is valid with btrfsck -s
14
15Signed-off-by: Chris Mason <chris.mason@oracle.com>
16---
17 Makefile | 3 ++
18 btrfs-select-super.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++
19 disk-io.c | 2 +-
20 disk-io.h | 1 +
21 4 files changed, 104 insertions(+), 1 deletions(-)
22 create mode 100644 btrfs-select-super.c
23
24diff --git a/Makefile b/Makefile
25index 6e6f6c6..d65f6a2 100644
26--- a/Makefile
27+++ b/Makefile
28@@ -62,6 +62,9 @@ btrfs-debug-tree: $(objects) debug-tree.o
29 btrfs-zero-log: $(objects) btrfs-zero-log.o
30 gcc $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
31
32+btrfs-select-super: $(objects) btrfs-select-super.o
33+ gcc $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
34+
35 btrfstune: $(objects) btrfstune.o
36 gcc $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
37
38diff --git a/btrfs-select-super.c b/btrfs-select-super.c
39new file mode 100644
40index 0000000..f12f36c
41--- /dev/null
42+++ b/btrfs-select-super.c
43@@ -0,0 +1,99 @@
44+/*
45+ * Copyright (C) 2007 Oracle. All rights reserved.
46+ *
47+ * This program is free software; you can redistribute it and/or
48+ * modify it under the terms of the GNU General Public
49+ * License v2 as published by the Free Software Foundation.
50+ *
51+ * This program is distributed in the hope that it will be useful,
52+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
53+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54+ * General Public License for more details.
55+ *
56+ * You should have received a copy of the GNU General Public
57+ * License along with this program; if not, write to the
58+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
59+ * Boston, MA 021110-1307, USA.
60+ */
61+
62+#define _XOPEN_SOURCE 500
63+#define _GNU_SOURCE 1
64+#include <stdio.h>
65+#include <stdlib.h>
66+#include <unistd.h>
67+#include <fcntl.h>
68+#include <sys/stat.h>
69+#include "kerncompat.h"
70+#include "ctree.h"
71+#include "disk-io.h"
72+#include "print-tree.h"
73+#include "transaction.h"
74+#include "list.h"
75+#include "version.h"
76+#include "utils.h"
77+
78+static void print_usage(void)
79+{
80+ fprintf(stderr, "usage: btrfs-select-super -s number dev\n");
81+ fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
82+ exit(1);
83+}
84+
85+int main(int ac, char **av)
86+{
87+ struct btrfs_root *root;
88+ int ret;
89+ int num;
90+ u64 bytenr = 0;
91+
92+ while(1) {
93+ int c;
94+ c = getopt(ac, av, "s:");
95+ if (c < 0)
96+ break;
97+ switch(c) {
98+ case 's':
99+ num = atol(optarg);
100+ bytenr = btrfs_sb_offset(num);
101+ printf("using SB copy %d, bytenr %llu\n", num,
102+ (unsigned long long)bytenr);
103+ break;
104+ default:
105+ print_usage();
106+ }
107+ }
108+ ac = ac - optind;
109+
110+ if (ac != 1)
111+ print_usage();
112+
113+ if (bytenr == 0) {
114+ fprintf(stderr, "Please select the super copy with -s\n");
115+ print_usage();
116+ }
117+
118+ radix_tree_init();
119+
120+ if((ret = check_mounted(av[optind])) < 0) {
121+ fprintf(stderr, "Could not check mount status: %s\n", strerror(ret));
122+ return ret;
123+ } else if(ret) {
124+ fprintf(stderr, "%s is currently mounted. Aborting.\n", av[optind]);
125+ return -EBUSY;
126+ }
127+
128+ root = open_ctree(av[optind], bytenr, 1);
129+
130+ if (root == NULL)
131+ return 1;
132+
133+ /* make the super writing code think we've read the first super */
134+ root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;
135+ ret = write_all_supers(root);
136+
137+ /* we don't close the ctree or anything, because we don't want a real
138+ * transaction commit. We just want the super copy we pulled off the
139+ * disk to overwrite all the other copies
140+ */
141+ return ret;
142+}
143diff --git a/disk-io.c b/disk-io.c
144index a6e1000..5bd9cfc 100644
145--- a/disk-io.c
146+++ b/disk-io.c
147@@ -828,7 +828,7 @@ int write_dev_supers(struct btrfs_root *root, struct btrfs_super_block *sb,
148
149 if (root->fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
150 btrfs_set_super_bytenr(sb, root->fs_info->super_bytenr);
151-
152+printk("speiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n");
153 crc = ~(u32)0;
154 crc = btrfs_csum_data(NULL, (char *)sb + BTRFS_CSUM_SIZE, crc,
155 BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
156diff --git a/disk-io.h b/disk-io.h
157index 49e5692..7ebec24 100644
158--- a/disk-io.h
159+++ b/disk-io.h
160@@ -47,6 +47,7 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes);
161 struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
162 int writes);
163 int close_ctree(struct btrfs_root *root);
164+int write_all_supers(struct btrfs_root *root);
165 int write_ctree_super(struct btrfs_trans_handle *trans,
166 struct btrfs_root *root);
167 int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr);
168--
1691.7.2.3
170
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch
new file mode 100644
index 0000000000..67739be2f4
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch
@@ -0,0 +1,152 @@
1Upstream-Status: Inappropriate [Backport]
2From 2636bf1da17720fc99b14cf4db33f1d1a4c9e0ee Mon Sep 17 00:00:00 2001
3From: Eduardo Silva <eduardo.silva@oracle.com>
4Date: Mon, 7 Feb 2011 08:55:04 -0300
5Subject: [PATCH 02/15] Btrfs-progs use safe string manipulation functions
6
7Signed-off-by: Eduardo Silva <eduardo.silva@oracle.com>
8Signed-off-by: Chris Mason <chris.mason@oracle.com>
9---
10 btrfs_cmds.c | 14 +++++++-------
11 btrfsctl.c | 2 +-
12 convert.c | 2 +-
13 utils.c | 9 +++++----
14 4 files changed, 14 insertions(+), 13 deletions(-)
15
16diff --git a/btrfs_cmds.c b/btrfs_cmds.c
17index 8031c58..fffb423 100644
18--- a/btrfs_cmds.c
19+++ b/btrfs_cmds.c
20@@ -375,7 +375,7 @@ int do_clone(int argc, char **argv)
21 printf("Create a snapshot of '%s' in '%s/%s'\n",
22 subvol, dstdir, newname);
23 args.fd = fd;
24- strcpy(args.name, newname);
25+ strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
26 res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
27
28 close(fd);
29@@ -436,7 +436,7 @@ int do_delete_subvolume(int argc, char **argv)
30 }
31
32 printf("Delete subvolume '%s/%s'\n", dname, vname);
33- strcpy(args.name, vname);
34+ strncpy(args.name, vname, BTRFS_PATH_NAME_MAX);
35 res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
36
37 close(fd);
38@@ -490,7 +490,7 @@ int do_create_subvol(int argc, char **argv)
39 }
40
41 printf("Create subvolume '%s/%s'\n", dstdir, newname);
42- strcpy(args.name, newname);
43+ strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
44 res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
45
46 close(fddst);
47@@ -553,7 +553,7 @@ int do_scan(int argc, char **argv)
48
49 printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]);
50
51- strcpy(args.name, argv[i]);
52+ strncpy(args.name, argv[i], BTRFS_PATH_NAME_MAX);
53 /*
54 * FIXME: which are the error code returned by this ioctl ?
55 * it seems that is impossible to understand if there no is
56@@ -593,7 +593,7 @@ int do_resize(int argc, char **argv)
57 }
58
59 printf("Resize '%s' of '%s'\n", path, amount);
60- strcpy(args.name, amount);
61+ strncpy(args.name, amount, BTRFS_PATH_NAME_MAX);
62 res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
63 close(fd);
64 if( res < 0 ){
65@@ -736,7 +736,7 @@ int do_add_volume(int nargs, char **args)
66 }
67 close(devfd);
68
69- strcpy(ioctl_args.name, args[i]);
70+ strncpy(ioctl_args.name, args[i], BTRFS_PATH_NAME_MAX);
71 res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
72 if(res<0){
73 fprintf(stderr, "ERROR: error adding the device '%s'\n", args[i]);
74@@ -792,7 +792,7 @@ int do_remove_volume(int nargs, char **args)
75 struct btrfs_ioctl_vol_args arg;
76 int res;
77
78- strcpy(arg.name, args[i]);
79+ strncpy(arg.name, args[i], BTRFS_PATH_NAME_MAX);
80 res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
81 if(res<0){
82 fprintf(stderr, "ERROR: error removing the device '%s'\n", args[i]);
83diff --git a/btrfsctl.c b/btrfsctl.c
84index 92bdf39..adfa519 100644
85--- a/btrfsctl.c
86+++ b/btrfsctl.c
87@@ -237,7 +237,7 @@ int main(int ac, char **av)
88 }
89
90 if (name)
91- strcpy(args.name, name);
92+ strncpy(args.name, name, BTRFS_PATH_NAME_MAX + 1);
93 else
94 args.name[0] = '\0';
95
96diff --git a/convert.c b/convert.c
97index d037c98..fbcf4a3 100644
98--- a/convert.c
99+++ b/convert.c
100@@ -857,7 +857,7 @@ static int copy_single_xattr(struct btrfs_trans_handle *trans,
101 data = databuf;
102 datalen = bufsize;
103 }
104- strcpy(namebuf, xattr_prefix_table[name_index]);
105+ strncpy(namebuf, xattr_prefix_table[name_index], XATTR_NAME_MAX);
106 strncat(namebuf, EXT2_EXT_ATTR_NAME(entry), entry->e_name_len);
107 if (name_len + datalen > BTRFS_LEAF_DATA_SIZE(root) -
108 sizeof(struct btrfs_item) - sizeof(struct btrfs_dir_item)) {
109diff --git a/utils.c b/utils.c
110index fd894f3..96ef94d 100644
111--- a/utils.c
112+++ b/utils.c
113@@ -108,7 +108,7 @@ int make_btrfs(int fd, const char *device, const char *label,
114 btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
115 btrfs_set_super_chunk_root_generation(&super, 1);
116 if (label)
117- strcpy(super.label, label);
118+ strncpy(super.label, label, BTRFS_LABEL_SIZE - 1);
119
120 buf = malloc(sizeof(*buf) + max(sectorsize, leafsize));
121
122@@ -828,7 +828,7 @@ void btrfs_register_one_device(char *fname)
123 "skipping device registration\n");
124 return;
125 }
126- strcpy(args.name, fname);
127+ strncpy(args.name, fname, BTRFS_PATH_NAME_MAX);
128 ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
129 close(fd);
130 }
131@@ -971,6 +971,7 @@ static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
132 char *pretty_sizes(u64 size)
133 {
134 int num_divs = 0;
135+ int pretty_len = 16;
136 u64 last_size = size;
137 u64 fract_size = size;
138 float fraction;
139@@ -988,8 +989,8 @@ char *pretty_sizes(u64 size)
140 return NULL;
141
142 fraction = (float)fract_size / 1024;
143- pretty = malloc(16);
144- sprintf(pretty, "%.2f%s", fraction, size_strs[num_divs-1]);
145+ pretty = malloc(pretty_len);
146+ snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
147 return pretty;
148 }
149
150--
1511.7.2.3
152
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0003-Btrfs-progs-utils-Informative-errors.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0003-Btrfs-progs-utils-Informative-errors.patch
new file mode 100644
index 0000000000..afc810573f
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0003-Btrfs-progs-utils-Informative-errors.patch
@@ -0,0 +1,37 @@
1Upstream-Status: Inappropriate [Backport]
2From ac1a80f52434d05230f9933d8f68e28cc09e10b0 Mon Sep 17 00:00:00 2001
3From: Goldwyn Rodrigues <rgoldwyn@gmail.com>
4Date: Mon, 7 Feb 2011 07:34:36 +0000
5Subject: [PATCH 03/15] Btrfs-progs utils Informative errors
6
7Signed-off-by: Chris Mason <chris.mason@oracle.com>
8---
9 utils.c | 5 +++--
10 1 files changed, 3 insertions(+), 2 deletions(-)
11
12diff --git a/utils.c b/utils.c
13index 96ef94d..d8c3dcc 100644
14--- a/utils.c
15+++ b/utils.c
16@@ -867,7 +867,7 @@ again:
17 }
18 dirp = opendir(dirname);
19 if (!dirp) {
20- fprintf(stderr, "Unable to open /sys/block for scanning\n");
21+ fprintf(stderr, "Unable to open %s for scanning\n", dirname);
22 return -ENOENT;
23 }
24 while(1) {
25@@ -902,7 +902,8 @@ again:
26 }
27 fd = open(fullpath, O_RDONLY);
28 if (fd < 0) {
29- fprintf(stderr, "failed to read %s\n", fullpath);
30+ fprintf(stderr, "failed to read %s: %s\n", fullpath,
31+ strerror(errno));
32 continue;
33 }
34 ret = btrfs_scan_one_device(fd, fullpath, &tmp_devices,
35--
361.7.2.3
37
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0004-update-man-page-to-new-defragment-command-interface.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0004-update-man-page-to-new-defragment-command-interface.patch
new file mode 100644
index 0000000000..4080a75d75
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0004-update-man-page-to-new-defragment-command-interface.patch
@@ -0,0 +1,99 @@
1Upstream-Status: Inappropriate [Backport]
2From 0a63a11c3d3bbb7e061daad28435b5eef91a947d Mon Sep 17 00:00:00 2001
3From: Hubert Kario <kario@wit.edu.pl>
4Date: Sun, 23 Jan 2011 15:31:07 +0000
5Subject: [PATCH 04/15] update man page to new defragment command interface
6
7Update
8
9 btrfs filesystem defragment
10
11command explanation. Add explanation of advanced parameters and notes
12about general usage.
13
14Add few notes about the
15
16 btrfs <command> --help
17
18usage, fix related grammar.
19
20Signed-off-by: Hubert Kario <kario@wit.edu.pl>
21Signed-off-by: Chris Mason <chris.mason@oracle.com>
22---
23 man/btrfs.8.in | 33 ++++++++++++++++++++++++++-------
24 1 files changed, 26 insertions(+), 7 deletions(-)
25
26diff --git a/man/btrfs.8.in b/man/btrfs.8.in
27index 26ef982..cba2de1 100644
28--- a/man/btrfs.8.in
29+++ b/man/btrfs.8.in
30@@ -15,7 +15,7 @@ btrfs \- control a btrfs filesystem
31 .PP
32 \fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP
33 .PP
34-\fBbtrfs\fP \fBfilesystem defrag\fP\fI <file>|<dir> [<file>|<dir>...]\fP
35+\fBbtrfs\fP \fBfilesystem defragment\fP\fI [-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\fP
36 .PP
37 \fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP
38 .PP
39@@ -34,6 +34,8 @@ btrfs \- control a btrfs filesystem
40 .PP
41 \fBbtrfs\fP \fBhelp|\-\-help|\-h \fP\fI\fP
42 .PP
43+\fBbtrfs\fP \fB<command> \-\-help \fP\fI\fP
44+.PP
45 .SH DESCRIPTION
46 .B btrfs
47 is used to control the filesystem and the files and directories stored. It is
48@@ -60,12 +62,12 @@ returns an error.
49
50 If a command is terminated by
51 .I --help
52-, the relevant help is showed. If the passed command matches more commands,
53-the help of all the matched commands are showed. For example
54+, the detailed help is showed. If the passed command matches more commands,
55+detailed help of all the matched commands is showed. For example
56 .I btrfs dev --help
57 shows the help of all
58 .I device*
59-command.
60+commands.
61
62 .SH COMMANDS
63 .TP
64@@ -98,12 +100,29 @@ mount time via the \fIsubvol=\fR option.
65
66 \fBsubvolume set-default\fR\fI <id> <path>\fR
67 Set the subvolume of the filesystem \fI<path>\fR which is mounted as
68-\fIdefault\fR. The subvolume is identified by \fB<id>\fR, which
69+\fIdefault\fR. The subvolume is identified by \fI<id>\fR, which
70 is returned by the \fBsubvolume list\fR command.
71 .TP
72
73-\fBfilesystem defragment\fP\fI <file>|<dir> [<file>|<dir>...]\fR
74-Defragment files and/or directories.
75+\fBfilesystem defragment\fP\fI [-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\fR
76+Defragment file data and/or directory metadata. To defragment all files in a
77+directory you have to specify each one on its own or use your shell wildcards.
78+
79+\fB-v\fP be verbose
80+
81+\fB-c\fP compress file contents while defragmenting
82+
83+\fB-f\fP flush filesystem after defragmenting
84+
85+\fB-s start\fP defragment only from byte \fIstart\fR onward
86+
87+\fB-l len\fP defragment only up to \fIlen\fR bytes
88+
89+\fB-t size\fP defragment only files at least \fIsize\fR bytes big
90+
91+NOTE: defragmenting with kernels up to 2.6.37 will unlink COW-ed copies of data, don't
92+use it if you use snapshots, have de-duplicated your data or made copies with
93+\fBcp --reflink\fP.
94 .TP
95
96 \fBdevice scan\fR \fI[<device> [<device>..]]\fR
97--
981.7.2.3
99
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0005-Improve-error-handling-in-the-btrfs-command.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0005-Improve-error-handling-in-the-btrfs-command.patch
new file mode 100644
index 0000000000..e7e3fae332
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0005-Improve-error-handling-in-the-btrfs-command.patch
@@ -0,0 +1,510 @@
1Upstream-Status: Inappropriate [Backport]
2From b3007332100e01ca84c161b6c75f0a414ab4611b Mon Sep 17 00:00:00 2001
3From: Goffredo Baroncelli <kreijack@libero.it>
4Date: Mon, 20 Dec 2010 20:06:19 +0000
5Subject: [PATCH 05/15] Improve error handling in the btrfs command
6
7Hi Chris,
8
9below is enclosed a trivial patch, which has the aim to improve the error
10reporting of the "btrfs" command.
11
12You can pull from
13
14 http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
15
16branch
17
18 strerror
19
20I changed every printf("some-error") to something like:
21
22 e = errno;
23 fprintf(stderr, "ERROR: .... - %s", strerror(e));
24
25so:
26
271) all the error are reported to standard error
282) At the end of the message is printed the error as returned by the system.
29
30The change is quite simple, I replaced every printf("some-error") to the line
31above. I don't touched anything other.
32I also integrated a missing "printf" on the basis of the Ben patch.
33
34This patch leads the btrfs command to be more "user friendly" :-)
35
36Regards
37G.Baroncelli
38
39 btrfs-list.c | 40 ++++++++++++++++++++++--------
40 btrfs_cmds.c | 77 ++++++++++++++++++++++++++++++++++++++++-----------------
41 utils.c | 6 ++++
42 3 files changed, 89 insertions(+), 34 deletions(-)
43
44Signed-off-by: Chris Mason <chris.mason@oracle.com>
45---
46 btrfs-list.c | 40 ++++++++++++++++++++++--------
47 btrfs_cmds.c | 77 ++++++++++++++++++++++++++++++++++++++++-----------------
48 utils.c | 6 ++++
49 3 files changed, 89 insertions(+), 34 deletions(-)
50
51diff --git a/btrfs-list.c b/btrfs-list.c
52index 93766a8..abcc2f4 100644
53--- a/btrfs-list.c
54+++ b/btrfs-list.c
55@@ -265,7 +265,7 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri)
56 static int lookup_ino_path(int fd, struct root_info *ri)
57 {
58 struct btrfs_ioctl_ino_lookup_args args;
59- int ret;
60+ int ret, e;
61
62 if (ri->path)
63 return 0;
64@@ -275,9 +275,11 @@ static int lookup_ino_path(int fd, struct root_info *ri)
65 args.objectid = ri->dir_id;
66
67 ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
68+ e = errno;
69 if (ret) {
70- fprintf(stderr, "ERROR: Failed to lookup path for root %llu\n",
71- (unsigned long long)ri->ref_tree);
72+ fprintf(stderr, "ERROR: Failed to lookup path for root %llu - %s\n",
73+ (unsigned long long)ri->ref_tree,
74+ strerror(e));
75 return ret;
76 }
77
78@@ -320,15 +322,18 @@ static u64 find_root_gen(int fd)
79 unsigned long off = 0;
80 u64 max_found = 0;
81 int i;
82+ int e;
83
84 memset(&ino_args, 0, sizeof(ino_args));
85 ino_args.objectid = BTRFS_FIRST_FREE_OBJECTID;
86
87 /* this ioctl fills in ino_args->treeid */
88 ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args);
89+ e = errno;
90 if (ret) {
91- fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu\n",
92- (unsigned long long)BTRFS_FIRST_FREE_OBJECTID);
93+ fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
94+ (unsigned long long)BTRFS_FIRST_FREE_OBJECTID,
95+ strerror(e));
96 return 0;
97 }
98
99@@ -351,8 +356,10 @@ static u64 find_root_gen(int fd)
100
101 while (1) {
102 ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
103+ e = errno;
104 if (ret < 0) {
105- fprintf(stderr, "ERROR: can't perform the search\n");
106+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
107+ strerror(e));
108 return 0;
109 }
110 /* the ioctl returns the number of item it found in nr_items */
111@@ -407,14 +414,16 @@ static char *__ino_resolve(int fd, u64 dirid)
112 struct btrfs_ioctl_ino_lookup_args args;
113 int ret;
114 char *full;
115+ int e;
116
117 memset(&args, 0, sizeof(args));
118 args.objectid = dirid;
119
120 ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
121+ e = errno;
122 if (ret) {
123- fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu\n",
124- (unsigned long long)dirid);
125+ fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
126+ (unsigned long long)dirid, strerror(e) );
127 return ERR_PTR(ret);
128 }
129
130@@ -472,6 +481,7 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
131 struct btrfs_ioctl_search_header *sh;
132 unsigned long off = 0;
133 int namelen;
134+ int e;
135
136 memset(&args, 0, sizeof(args));
137
138@@ -490,8 +500,10 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
139 sk->nr_items = 1;
140
141 ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
142+ e = errno;
143 if (ret < 0) {
144- fprintf(stderr, "ERROR: can't perform the search\n");
145+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
146+ strerror(e));
147 return NULL;
148 }
149 /* the ioctl returns the number of item it found in nr_items */
150@@ -550,6 +562,7 @@ int list_subvols(int fd)
151 char *name;
152 u64 dir_id;
153 int i;
154+ int e;
155
156 root_lookup_init(&root_lookup);
157
158@@ -578,8 +591,10 @@ int list_subvols(int fd)
159
160 while(1) {
161 ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
162+ e = errno;
163 if (ret < 0) {
164- fprintf(stderr, "ERROR: can't perform the search\n");
165+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
166+ strerror(e));
167 return ret;
168 }
169 /* the ioctl returns the number of item it found in nr_items */
170@@ -747,6 +762,7 @@ int find_updated_files(int fd, u64 root_id, u64 oldest_gen)
171 u64 found_gen;
172 u64 max_found = 0;
173 int i;
174+ int e;
175 u64 cache_dirid = 0;
176 u64 cache_ino = 0;
177 char *cache_dir_name = NULL;
178@@ -773,8 +789,10 @@ int find_updated_files(int fd, u64 root_id, u64 oldest_gen)
179 max_found = find_root_gen(fd);
180 while(1) {
181 ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
182+ e = errno;
183 if (ret < 0) {
184- fprintf(stderr, "ERROR: can't perform the search\n");
185+ fprintf(stderr, "ERROR: can't perform the search- %s\n",
186+ strerror(e));
187 return ret;
188 }
189 /* the ioctl returns the number of item it found in nr_items */
190diff --git a/btrfs_cmds.c b/btrfs_cmds.c
191index fffb423..775bfe1 100644
192--- a/btrfs_cmds.c
193+++ b/btrfs_cmds.c
194@@ -156,6 +156,7 @@ int do_defrag(int ac, char **av)
195 int verbose = 0;
196 int fancy_ioctl = 0;
197 struct btrfs_ioctl_defrag_range_args range;
198+ int e=0;
199
200 optind = 1;
201 while(1) {
202@@ -219,19 +220,21 @@ int do_defrag(int ac, char **av)
203 }
204 if (!fancy_ioctl) {
205 ret = ioctl(fd, BTRFS_IOC_DEFRAG, NULL);
206+ e=errno;
207 } else {
208 ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &range);
209 if (ret && errno == ENOTTY) {
210- fprintf(stderr, "defrag range ioctl not "
211+ fprintf(stderr, "ERROR: defrag range ioctl not "
212 "supported in this kernel, please try "
213 "without any options.\n");
214 errors++;
215+ close(fd);
216 break;
217 }
218 }
219 if (ret) {
220- fprintf(stderr, "ioctl failed on %s ret %d errno %d\n",
221- av[i], ret, errno);
222+ fprintf(stderr, "ERROR: defrag failed on %s - %s\n",
223+ av[i], strerror(e));
224 errors++;
225 }
226 close(fd);
227@@ -310,7 +313,7 @@ int do_subvol_list(int argc, char **argv)
228 int do_clone(int argc, char **argv)
229 {
230 char *subvol, *dst;
231- int res, fd, fddst, len;
232+ int res, fd, fddst, len, e;
233 char *newname;
234 char *dstdir;
235
236@@ -377,12 +380,14 @@ int do_clone(int argc, char **argv)
237 args.fd = fd;
238 strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
239 res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
240+ e = errno;
241
242 close(fd);
243 close(fddst);
244
245 if(res < 0 ){
246- fprintf( stderr, "ERROR: cannot snapshot '%s'\n",subvol);
247+ fprintf( stderr, "ERROR: cannot snapshot '%s' - %s\n",
248+ subvol, strerror(e));
249 return 11;
250 }
251
252@@ -392,7 +397,7 @@ int do_clone(int argc, char **argv)
253
254 int do_delete_subvolume(int argc, char **argv)
255 {
256- int res, fd, len;
257+ int res, fd, len, e;
258 struct btrfs_ioctl_vol_args args;
259 char *dname, *vname, *cpath;
260 char *path = argv[1];
261@@ -438,11 +443,13 @@ int do_delete_subvolume(int argc, char **argv)
262 printf("Delete subvolume '%s/%s'\n", dname, vname);
263 strncpy(args.name, vname, BTRFS_PATH_NAME_MAX);
264 res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
265+ e = errno;
266
267 close(fd);
268
269 if(res < 0 ){
270- fprintf( stderr, "ERROR: cannot delete '%s/%s'\n",dname, vname);
271+ fprintf( stderr, "ERROR: cannot delete '%s/%s' - %s\n",
272+ dname, vname, strerror(e));
273 return 11;
274 }
275
276@@ -452,7 +459,7 @@ int do_delete_subvolume(int argc, char **argv)
277
278 int do_create_subvol(int argc, char **argv)
279 {
280- int res, fddst, len;
281+ int res, fddst, len, e;
282 char *newname;
283 char *dstdir;
284 struct btrfs_ioctl_vol_args args;
285@@ -492,11 +499,13 @@ int do_create_subvol(int argc, char **argv)
286 printf("Create subvolume '%s/%s'\n", dstdir, newname);
287 strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
288 res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
289+ e = errno;
290
291 close(fddst);
292
293 if(res < 0 ){
294- fprintf( stderr, "ERROR: cannot create subvolume\n");
295+ fprintf( stderr, "ERROR: cannot create subvolume - %s\n",
296+ strerror(e));
297 return 11;
298 }
299
300@@ -506,7 +515,7 @@ int do_create_subvol(int argc, char **argv)
301
302 int do_fssync(int argc, char **argv)
303 {
304- int fd, res;
305+ int fd, res, e;
306 char *path = argv[1];
307
308 fd = open_file_or_dir(path);
309@@ -517,9 +526,11 @@ int do_fssync(int argc, char **argv)
310
311 printf("FSSync '%s'\n", path);
312 res = ioctl(fd, BTRFS_IOC_SYNC);
313+ e = errno;
314 close(fd);
315 if( res < 0 ){
316- fprintf(stderr, "ERROR: unable to fs-syncing '%s'\n", path);
317+ fprintf(stderr, "ERROR: unable to fs-syncing '%s' - %s\n",
318+ path, strerror(e));
319 return 16;
320 }
321
322@@ -528,7 +539,7 @@ int do_fssync(int argc, char **argv)
323
324 int do_scan(int argc, char **argv)
325 {
326- int i, fd;
327+ int i, fd, e;
328 if(argc<=1){
329 int ret;
330
331@@ -560,10 +571,12 @@ int do_scan(int argc, char **argv)
332 * a btrfs filesystem from an I/O error !!!
333 */
334 ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
335+ e = errno;
336
337 if( ret < 0 ){
338 close(fd);
339- fprintf(stderr, "ERROR: unable to scan the device '%s'\n", argv[i]);
340+ fprintf(stderr, "ERROR: unable to scan the device '%s' - %s\n",
341+ argv[i], strerror(e));
342 return 11;
343 }
344 }
345@@ -577,7 +590,7 @@ int do_resize(int argc, char **argv)
346 {
347
348 struct btrfs_ioctl_vol_args args;
349- int fd, res, len;
350+ int fd, res, len, e;
351 char *amount=argv[1], *path=argv[2];
352
353 fd = open_file_or_dir(path);
354@@ -595,9 +608,11 @@ int do_resize(int argc, char **argv)
355 printf("Resize '%s' of '%s'\n", path, amount);
356 strncpy(args.name, amount, BTRFS_PATH_NAME_MAX);
357 res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
358+ e = errno;
359 close(fd);
360 if( res < 0 ){
361- fprintf(stderr, "ERROR: unable to resize '%s'\n", path);
362+ fprintf(stderr, "ERROR: unable to resize '%s' - %s\n",
363+ path, strerror(e));
364 return 30;
365 }
366 return 0;
367@@ -691,7 +706,7 @@ int do_add_volume(int nargs, char **args)
368 {
369
370 char *mntpnt = args[nargs-1];
371- int i, fdmnt, ret=0;
372+ int i, fdmnt, ret=0, e;
373
374
375 fdmnt = open_file_or_dir(mntpnt);
376@@ -738,8 +753,10 @@ int do_add_volume(int nargs, char **args)
377
378 strncpy(ioctl_args.name, args[i], BTRFS_PATH_NAME_MAX);
379 res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
380+ e = errno;
381 if(res<0){
382- fprintf(stderr, "ERROR: error adding the device '%s'\n", args[i]);
383+ fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
384+ args[i], strerror(e));
385 ret++;
386 }
387
388@@ -756,7 +773,7 @@ int do_add_volume(int nargs, char **args)
389 int do_balance(int argc, char **argv)
390 {
391
392- int fdmnt, ret=0;
393+ int fdmnt, ret=0, e;
394 struct btrfs_ioctl_vol_args args;
395 char *path = argv[1];
396
397@@ -768,9 +785,11 @@ int do_balance(int argc, char **argv)
398
399 memset(&args, 0, sizeof(args));
400 ret = ioctl(fdmnt, BTRFS_IOC_BALANCE, &args);
401+ e = errno;
402 close(fdmnt);
403 if(ret<0){
404- fprintf(stderr, "ERROR: balancing '%s'\n", path);
405+ fprintf(stderr, "ERROR: error during balancing '%s' - %s\n",
406+ path, strerror(e));
407
408 return 19;
409 }
410@@ -780,7 +799,7 @@ int do_remove_volume(int nargs, char **args)
411 {
412
413 char *mntpnt = args[nargs-1];
414- int i, fdmnt, ret=0;
415+ int i, fdmnt, ret=0, e;
416
417 fdmnt = open_file_or_dir(mntpnt);
418 if (fdmnt < 0) {
419@@ -794,8 +813,10 @@ int do_remove_volume(int nargs, char **args)
420
421 strncpy(arg.name, args[i], BTRFS_PATH_NAME_MAX);
422 res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
423+ e = errno;
424 if(res<0){
425- fprintf(stderr, "ERROR: error removing the device '%s'\n", args[i]);
426+ fprintf(stderr, "ERROR: error removing the device '%s' - %s\n",
427+ args[i], strerror(e));
428 ret++;
429 }
430 }
431@@ -809,7 +830,7 @@ int do_remove_volume(int nargs, char **args)
432
433 int do_set_default_subvol(int nargs, char **argv)
434 {
435- int ret=0, fd;
436+ int ret=0, fd, e;
437 u64 objectid;
438 char *path = argv[2];
439 char *subvolid = argv[1];
440@@ -826,9 +847,11 @@ int do_set_default_subvol(int nargs, char **argv)
441 return 30;
442 }
443 ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
444+ e = errno;
445 close(fd);
446 if( ret < 0 ){
447- fprintf(stderr, "ERROR: unable to set a new default subvolume\n");
448+ fprintf(stderr, "ERROR: unable to set a new default subvolume - %s\n",
449+ strerror(e));
450 return 30;
451 }
452 return 0;
453@@ -840,6 +863,7 @@ int do_df_filesystem(int nargs, char **argv)
454 u64 count = 0, i;
455 int ret;
456 int fd;
457+ int e;
458 char *path = argv[1];
459
460 fd = open_file_or_dir(path);
461@@ -856,7 +880,10 @@ int do_df_filesystem(int nargs, char **argv)
462 sargs->total_spaces = 0;
463
464 ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
465+ e = errno;
466 if (ret) {
467+ fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
468+ path, strerror(e));
469 free(sargs);
470 return ret;
471 }
472@@ -874,7 +901,11 @@ int do_df_filesystem(int nargs, char **argv)
473 sargs->total_spaces = 0;
474
475 ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
476+ e = errno;
477 if (ret) {
478+ fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
479+ path, strerror(e));
480+ close(fd);
481 free(sargs);
482 return ret;
483 }
484diff --git a/utils.c b/utils.c
485index d8c3dcc..2a15d86 100644
486--- a/utils.c
487+++ b/utils.c
488@@ -821,6 +821,7 @@ void btrfs_register_one_device(char *fname)
489 struct btrfs_ioctl_vol_args args;
490 int fd;
491 int ret;
492+ int e;
493
494 fd = open("/dev/btrfs-control", O_RDONLY);
495 if (fd < 0) {
496@@ -830,6 +831,11 @@ void btrfs_register_one_device(char *fname)
497 }
498 strncpy(args.name, fname, BTRFS_PATH_NAME_MAX);
499 ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
500+ e = errno;
501+ if(ret<0){
502+ fprintf(stderr, "ERROR: unable to scan the device '%s' - %s\n",
503+ fname, strerror(e));
504+ }
505 close(fd);
506 }
507
508--
5091.7.2.3
510
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0006-Btrfs-progs-update-super-fields-for-space-cache.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0006-Btrfs-progs-update-super-fields-for-space-cache.patch
new file mode 100644
index 0000000000..d8b8b108e8
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0006-Btrfs-progs-update-super-fields-for-space-cache.patch
@@ -0,0 +1,57 @@
1Upstream-Status: Inappropriate [Backport]
2From c2cefc42ebf8e32e36b1866048a02a579f2cef9a Mon Sep 17 00:00:00 2001
3From: Josef Bacik <josef@redhat.com>
4Date: Thu, 9 Dec 2010 18:27:03 +0000
5Subject: [PATCH 06/15] Btrfs-progs: update super fields for space cache
6
7This patch updates the super field to add the cache_generation member. It also
8makes us set it to -1 on mkfs so any new filesystem will get the space cache
9stuff turned on. Thanks,
10
11Signed-off-by: Josef Bacik <josef@redhat.com>
12Signed-off-by: Chris Mason <chris.mason@oracle.com>
13---
14 ctree.h | 6 +++++-
15 utils.c | 1 +
16 2 files changed, 6 insertions(+), 1 deletions(-)
17
18diff --git a/ctree.h b/ctree.h
19index b79e238..962c510 100644
20--- a/ctree.h
21+++ b/ctree.h
22@@ -340,8 +340,10 @@ struct btrfs_super_block {
23
24 char label[BTRFS_LABEL_SIZE];
25
26+ __le64 cache_generation;
27+
28 /* future expansion */
29- __le64 reserved[32];
30+ __le64 reserved[31];
31 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
32 } __attribute__ ((__packed__));
33
34@@ -1564,6 +1566,8 @@ BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
35 incompat_flags, 64);
36 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
37 csum_type, 16);
38+BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
39+ cache_generation, 64);
40
41 static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
42 {
43diff --git a/utils.c b/utils.c
44index 2a15d86..35e17b8 100644
45--- a/utils.c
46+++ b/utils.c
47@@ -107,6 +107,7 @@ int make_btrfs(int fd, const char *device, const char *label,
48 btrfs_set_super_stripesize(&super, stripesize);
49 btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
50 btrfs_set_super_chunk_root_generation(&super, 1);
51+ btrfs_set_super_cache_generation(&super, -1);
52 if (label)
53 strncpy(super.label, label, BTRFS_LABEL_SIZE - 1);
54
55--
561.7.2.3
57
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0007-Btrfs-progs-add-support-for-mixed-data-metadata-bloc.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0007-Btrfs-progs-add-support-for-mixed-data-metadata-bloc.patch
new file mode 100644
index 0000000000..f533c5b0b4
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0007-Btrfs-progs-add-support-for-mixed-data-metadata-bloc.patch
@@ -0,0 +1,403 @@
1Upstream-Status: Inappropriate [Backport]
2From e7ef1f26a25d06d5606934dced7b52f3e33f1d33 Mon Sep 17 00:00:00 2001
3From: Josef Bacik <josef@redhat.com>
4Date: Thu, 9 Dec 2010 18:31:08 +0000
5Subject: [PATCH 07/15] Btrfs-progs: add support for mixed data+metadata block groups
6
7So alot of crazy people (I'm looking at you Meego) want to use btrfs on phones
8and such with small devices. Unfortunately the way we split out metadata/data
9chunks it makes space usage inefficient for volumes that are smaller than
101gigabyte. So add a -M option for mixing metadata+data, and default to this
11mixed mode if the filesystem is less than or equal to 1 gigabyte. I've tested
12this with xfstests on a 100mb filesystem and everything is a-ok.
13
14Signed-off-by: Josef Bacik <josef@redhat.com>
15Signed-off-by: Chris Mason <chris.mason@oracle.com>
16---
17 btrfs-vol.c | 4 +-
18 btrfs_cmds.c | 13 +++++-
19 ctree.h | 10 +++--
20 mkfs.c | 122 +++++++++++++++++++++++++++++++++++++++++-----------------
21 utils.c | 10 ++--
22 utils.h | 2 +-
23 6 files changed, 112 insertions(+), 49 deletions(-)
24
25diff --git a/btrfs-vol.c b/btrfs-vol.c
26index 4ed799d..f573023 100644
27--- a/btrfs-vol.c
28+++ b/btrfs-vol.c
29@@ -143,7 +143,9 @@ int main(int ac, char **av)
30 exit(1);
31 }
32 if (cmd == BTRFS_IOC_ADD_DEV) {
33- ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count);
34+ int mixed = 0;
35+
36+ ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count, &mixed);
37 if (ret) {
38 fprintf(stderr, "Unable to init %s\n", device);
39 exit(1);
40diff --git a/btrfs_cmds.c b/btrfs_cmds.c
41index 775bfe1..c21a007 100644
42--- a/btrfs_cmds.c
43+++ b/btrfs_cmds.c
44@@ -720,6 +720,7 @@ int do_add_volume(int nargs, char **args)
45 int devfd, res;
46 u64 dev_block_count = 0;
47 struct stat st;
48+ int mixed = 0;
49
50 devfd = open(args[i], O_RDWR);
51 if (!devfd) {
52@@ -742,7 +743,7 @@ int do_add_volume(int nargs, char **args)
53 continue;
54 }
55
56- res = btrfs_prepare_device(devfd, args[i], 1, &dev_block_count);
57+ res = btrfs_prepare_device(devfd, args[i], 1, &dev_block_count, &mixed);
58 if (res) {
59 fprintf(stderr, "ERROR: Unable to init '%s'\n", args[i]);
60 close(devfd);
61@@ -920,8 +921,14 @@ int do_df_filesystem(int nargs, char **argv)
62 memset(description, 0, 80);
63
64 if (flags & BTRFS_BLOCK_GROUP_DATA) {
65- snprintf(description, 5, "%s", "Data");
66- written += 4;
67+ if (flags & BTRFS_BLOCK_GROUP_METADATA) {
68+ snprintf(description, 15, "%s",
69+ "Data+Metadata");
70+ written += 14;
71+ } else {
72+ snprintf(description, 5, "%s", "Data");
73+ written += 4;
74+ }
75 } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
76 snprintf(description, 7, "%s", "System");
77 written += 6;
78diff --git a/ctree.h b/ctree.h
79index 962c510..ed83d02 100644
80--- a/ctree.h
81+++ b/ctree.h
82@@ -352,13 +352,15 @@ struct btrfs_super_block {
83 * ones specified below then we will fail to mount
84 */
85 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
86-#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (2ULL << 0)
87+#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
88+#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
89
90 #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
91 #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
92-#define BTRFS_FEATURE_INCOMPAT_SUPP \
93- (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
94- BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL)
95+#define BTRFS_FEATURE_INCOMPAT_SUPP \
96+ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
97+ BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
98+ BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
99
100 /*
101 * A leaf is full of items. offset and size tell us where to find
102diff --git a/mkfs.c b/mkfs.c
103index 2e99b95..04de93a 100644
104--- a/mkfs.c
105+++ b/mkfs.c
106@@ -69,7 +69,7 @@ static u64 parse_size(char *s)
107 return atol(s) * mult;
108 }
109
110-static int make_root_dir(struct btrfs_root *root)
111+static int make_root_dir(struct btrfs_root *root, int mixed)
112 {
113 struct btrfs_trans_handle *trans;
114 struct btrfs_key location;
115@@ -88,30 +88,47 @@ static int make_root_dir(struct btrfs_root *root)
116 0, BTRFS_MKFS_SYSTEM_GROUP_SIZE);
117 BUG_ON(ret);
118
119- ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
120- &chunk_start, &chunk_size,
121- BTRFS_BLOCK_GROUP_METADATA);
122- BUG_ON(ret);
123- ret = btrfs_make_block_group(trans, root, 0,
124- BTRFS_BLOCK_GROUP_METADATA,
125- BTRFS_FIRST_CHUNK_TREE_OBJECTID,
126- chunk_start, chunk_size);
127- BUG_ON(ret);
128+ if (mixed) {
129+ ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
130+ &chunk_start, &chunk_size,
131+ BTRFS_BLOCK_GROUP_METADATA |
132+ BTRFS_BLOCK_GROUP_DATA);
133+ BUG_ON(ret);
134+ ret = btrfs_make_block_group(trans, root, 0,
135+ BTRFS_BLOCK_GROUP_METADATA |
136+ BTRFS_BLOCK_GROUP_DATA,
137+ BTRFS_FIRST_CHUNK_TREE_OBJECTID,
138+ chunk_start, chunk_size);
139+ BUG_ON(ret);
140+ printf("Created a data/metadata chunk of size %llu\n", chunk_size);
141+ } else {
142+ ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
143+ &chunk_start, &chunk_size,
144+ BTRFS_BLOCK_GROUP_METADATA);
145+ BUG_ON(ret);
146+ ret = btrfs_make_block_group(trans, root, 0,
147+ BTRFS_BLOCK_GROUP_METADATA,
148+ BTRFS_FIRST_CHUNK_TREE_OBJECTID,
149+ chunk_start, chunk_size);
150+ BUG_ON(ret);
151+ }
152
153 root->fs_info->system_allocs = 0;
154 btrfs_commit_transaction(trans, root);
155 trans = btrfs_start_transaction(root, 1);
156 BUG_ON(!trans);
157
158- ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
159- &chunk_start, &chunk_size,
160- BTRFS_BLOCK_GROUP_DATA);
161- BUG_ON(ret);
162- ret = btrfs_make_block_group(trans, root, 0,
163- BTRFS_BLOCK_GROUP_DATA,
164- BTRFS_FIRST_CHUNK_TREE_OBJECTID,
165- chunk_start, chunk_size);
166- BUG_ON(ret);
167+ if (!mixed) {
168+ ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
169+ &chunk_start, &chunk_size,
170+ BTRFS_BLOCK_GROUP_DATA);
171+ BUG_ON(ret);
172+ ret = btrfs_make_block_group(trans, root, 0,
173+ BTRFS_BLOCK_GROUP_DATA,
174+ BTRFS_FIRST_CHUNK_TREE_OBJECTID,
175+ chunk_start, chunk_size);
176+ BUG_ON(ret);
177+ }
178
179 ret = btrfs_make_root_dir(trans, root->fs_info->tree_root,
180 BTRFS_ROOT_TREE_DIR_OBJECTID);
181@@ -200,7 +217,7 @@ static int create_one_raid_group(struct btrfs_trans_handle *trans,
182
183 static int create_raid_groups(struct btrfs_trans_handle *trans,
184 struct btrfs_root *root, u64 data_profile,
185- u64 metadata_profile)
186+ u64 metadata_profile, int mixed)
187 {
188 u64 num_devices = btrfs_super_num_devices(&root->fs_info->super_copy);
189 u64 allowed;
190@@ -215,20 +232,24 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
191 allowed = BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1;
192
193 if (allowed & metadata_profile) {
194+ u64 meta_flags = BTRFS_BLOCK_GROUP_METADATA;
195+
196 ret = create_one_raid_group(trans, root,
197 BTRFS_BLOCK_GROUP_SYSTEM |
198 (allowed & metadata_profile));
199 BUG_ON(ret);
200
201- ret = create_one_raid_group(trans, root,
202- BTRFS_BLOCK_GROUP_METADATA |
203+ if (mixed)
204+ meta_flags |= BTRFS_BLOCK_GROUP_DATA;
205+
206+ ret = create_one_raid_group(trans, root, meta_flags |
207 (allowed & metadata_profile));
208 BUG_ON(ret);
209
210 ret = recow_roots(trans, root);
211 BUG_ON(ret);
212 }
213- if (num_devices > 1 && (allowed & data_profile)) {
214+ if (!mixed && num_devices > 1 && (allowed & data_profile)) {
215 ret = create_one_raid_group(trans, root,
216 BTRFS_BLOCK_GROUP_DATA |
217 (allowed & data_profile));
218@@ -274,6 +295,7 @@ static void print_usage(void)
219 fprintf(stderr, "\t -l --leafsize size of btree leaves\n");
220 fprintf(stderr, "\t -L --label set a label\n");
221 fprintf(stderr, "\t -m --metadata metadata profile, values like data profile\n");
222+ fprintf(stderr, "\t -M --mixed mix metadata and data together\n");
223 fprintf(stderr, "\t -n --nodesize size of btree nodes\n");
224 fprintf(stderr, "\t -s --sectorsize min block allocation\n");
225 fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
226@@ -328,6 +350,7 @@ static struct option long_options[] = {
227 { "leafsize", 1, NULL, 'l' },
228 { "label", 1, NULL, 'L'},
229 { "metadata", 1, NULL, 'm' },
230+ { "mixed", 0, NULL, 'M' },
231 { "nodesize", 1, NULL, 'n' },
232 { "sectorsize", 1, NULL, 's' },
233 { "data", 1, NULL, 'd' },
234@@ -358,10 +381,13 @@ int main(int ac, char **av)
235 int first_fd;
236 int ret;
237 int i;
238+ int mixed = 0;
239+ int data_profile_opt = 0;
240+ int metadata_profile_opt = 0;
241
242 while(1) {
243 int c;
244- c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:V", long_options,
245+ c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:VM", long_options,
246 &option_index);
247 if (c < 0)
248 break;
249@@ -371,6 +397,7 @@ int main(int ac, char **av)
250 break;
251 case 'd':
252 data_profile = parse_profile(optarg);
253+ data_profile_opt = 1;
254 break;
255 case 'l':
256 leafsize = parse_size(optarg);
257@@ -380,6 +407,10 @@ int main(int ac, char **av)
258 break;
259 case 'm':
260 metadata_profile = parse_profile(optarg);
261+ metadata_profile_opt = 1;
262+ break;
263+ case 'M':
264+ mixed = 1;
265 break;
266 case 'n':
267 nodesize = parse_size(optarg);
268@@ -389,12 +420,10 @@ int main(int ac, char **av)
269 break;
270 case 'b':
271 block_count = parse_size(optarg);
272- if (block_count < 256*1024*1024) {
273- fprintf(stderr, "File system size "
274- "%llu bytes is too small, "
275- "256M is required at least\n",
276- (unsigned long long)block_count);
277- exit(1);
278+ if (block_count <= 1024*1024*1024) {
279+ printf("SMALL VOLUME: forcing mixed "
280+ "metadata/data groups\n");
281+ mixed = 1;
282 }
283 zero_end = 0;
284 break;
285@@ -439,9 +468,22 @@ int main(int ac, char **av)
286 }
287 first_fd = fd;
288 first_file = file;
289- ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count);
290+ ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
291+ &mixed);
292 if (block_count == 0)
293 block_count = dev_block_count;
294+ if (mixed) {
295+ if (!metadata_profile_opt)
296+ metadata_profile = 0;
297+ if (!data_profile_opt)
298+ data_profile = 0;
299+
300+ if (metadata_profile != data_profile) {
301+ fprintf(stderr, "With mixed block groups data and metadata "
302+ "profiles must be the same\n");
303+ exit(1);
304+ }
305+ }
306
307 blocks[0] = BTRFS_SUPER_INFO_OFFSET;
308 for (i = 1; i < 7; i++) {
309@@ -459,7 +501,7 @@ int main(int ac, char **av)
310 root = open_ctree(file, 0, O_RDWR);
311 root->fs_info->alloc_start = alloc_start;
312
313- ret = make_root_dir(root);
314+ ret = make_root_dir(root, mixed);
315 if (ret) {
316 fprintf(stderr, "failed to setup the root directory\n");
317 exit(1);
318@@ -478,6 +520,8 @@ int main(int ac, char **av)
319
320 zero_end = 1;
321 while(ac-- > 0) {
322+ int old_mixed = mixed;
323+
324 file = av[optind++];
325 ret = check_mounted(file);
326 if (ret < 0) {
327@@ -503,8 +547,8 @@ int main(int ac, char **av)
328 continue;
329 }
330 ret = btrfs_prepare_device(fd, file, zero_end,
331- &dev_block_count);
332-
333+ &dev_block_count, &mixed);
334+ mixed = old_mixed;
335 BUG_ON(ret);
336
337 ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
338@@ -515,12 +559,20 @@ int main(int ac, char **av)
339
340 raid_groups:
341 ret = create_raid_groups(trans, root, data_profile,
342- metadata_profile);
343+ metadata_profile, mixed);
344 BUG_ON(ret);
345
346 ret = create_data_reloc_tree(trans, root);
347 BUG_ON(ret);
348
349+ if (mixed) {
350+ struct btrfs_super_block *super = &root->fs_info->super_copy;
351+ u64 flags = btrfs_super_incompat_flags(super);
352+
353+ flags |= BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS;
354+ btrfs_set_super_incompat_flags(super, flags);
355+ }
356+
357 printf("fs created label %s on %s\n\tnodesize %u leafsize %u "
358 "sectorsize %u size %s\n",
359 label, first_file, nodesize, leafsize, sectorsize,
360diff --git a/utils.c b/utils.c
361index 35e17b8..ad980ae 100644
362--- a/utils.c
363+++ b/utils.c
364@@ -512,7 +512,8 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
365 return 0;
366 }
367
368-int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret)
369+int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
370+ int *mixed)
371 {
372 u64 block_count;
373 u64 bytenr;
374@@ -532,10 +533,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret)
375 }
376 zero_end = 1;
377
378- if (block_count < 256 * 1024 * 1024) {
379- fprintf(stderr, "device %s is too small "
380- "(must be at least 256 MB)\n", file);
381- exit(1);
382+ if (block_count < 1024 * 1024 * 1024 && !(*mixed)) {
383+ printf("SMALL VOLUME: forcing mixed metadata/data groups\n");
384+ *mixed = 1;
385 }
386 ret = zero_dev_start(fd);
387 if (ret) {
388diff --git a/utils.h b/utils.h
389index 9dce5b0..a28d7f4 100644
390--- a/utils.h
391+++ b/utils.h
392@@ -27,7 +27,7 @@ int make_btrfs(int fd, const char *device, const char *label,
393 int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
394 struct btrfs_root *root, u64 objectid);
395 int btrfs_prepare_device(int fd, char *file, int zero_end,
396- u64 *block_count_ret);
397+ u64 *block_count_ret, int *mixed);
398 int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
399 struct btrfs_root *root, int fd, char *path,
400 u64 block_count, u32 io_width, u32 io_align,
401--
4021.7.2.3
403
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0008-Update-for-lzo-support.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0008-Update-for-lzo-support.patch
new file mode 100644
index 0000000000..a1bd4152fb
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0008-Update-for-lzo-support.patch
@@ -0,0 +1,203 @@
1Upstream-Status: Inappropriate [Backport]
2From 97e64f8cb21685b7359169f3047c0d082b0ff7e8 Mon Sep 17 00:00:00 2001
3From: Li Zefan <lizf@cn.fujitsu.com>
4Date: Thu, 18 Nov 2010 03:49:56 +0000
5Subject: [PATCH 08/15] Update for lzo support
6
7[Btrfs-Progs][V2] Update for lzo support
8
9- Add incompat flag, otherwise btrfs-progs will report error
10 when operating on btrfs filesystems mounted with lzo option.
11
12- Update man page.
13
14- Allow to turn on lzo compression for defrag operation:
15
16 # btrfs filesystem defragment -c[zlib, lzo] <file>
17
18 Note: "-c zlib" will fail, because that's how getopt() works
19 for optional arguments.
20
21Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
22Signed-off-by: Chris Mason <chris.mason@oracle.com>
23---
24 btrfs.c | 2 +-
25 btrfs_cmds.c | 24 ++++++++++++++++++++----
26 ctree.h | 10 +++++++---
27 ioctl.h | 9 ++++++++-
28 man/btrfs.8.in | 10 ++++++----
29 5 files changed, 42 insertions(+), 13 deletions(-)
30
31diff --git a/btrfs.c b/btrfs.c
32index 46314cf..1b4f403 100644
33--- a/btrfs.c
34+++ b/btrfs.c
35@@ -65,7 +65,7 @@ static struct Command commands[] = {
36 "List the recently modified files in a filesystem."
37 },
38 { do_defrag, -1,
39- "filesystem defragment", "[-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
40+ "filesystem defragment", "[-vf] [-c[zlib,lzo]] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
41 "Defragment a file or a directory."
42 },
43 { do_set_default_subvol, 2,
44diff --git a/btrfs_cmds.c b/btrfs_cmds.c
45index c21a007..26d4fcc 100644
46--- a/btrfs_cmds.c
47+++ b/btrfs_cmds.c
48@@ -142,10 +142,21 @@ static u64 parse_size(char *s)
49 return atoll(s) * mult;
50 }
51
52+static int parse_compress_type(char *s)
53+{
54+ if (strcmp(optarg, "zlib") == 0)
55+ return BTRFS_COMPRESS_ZLIB;
56+ else if (strcmp(optarg, "lzo") == 0)
57+ return BTRFS_COMPRESS_LZO;
58+ else {
59+ fprintf(stderr, "Unknown compress type %s\n", s);
60+ exit(1);
61+ };
62+}
63+
64 int do_defrag(int ac, char **av)
65 {
66 int fd;
67- int compress = 0;
68 int flush = 0;
69 u64 start = 0;
70 u64 len = (u64)-1;
71@@ -157,15 +168,18 @@ int do_defrag(int ac, char **av)
72 int fancy_ioctl = 0;
73 struct btrfs_ioctl_defrag_range_args range;
74 int e=0;
75+ int compress_type = BTRFS_COMPRESS_NONE;
76
77 optind = 1;
78 while(1) {
79- int c = getopt(ac, av, "vcfs:l:t:");
80+ int c = getopt(ac, av, "vc::fs:l:t:");
81 if (c < 0)
82 break;
83 switch(c) {
84 case 'c':
85- compress = 1;
86+ compress_type = BTRFS_COMPRESS_ZLIB;
87+ if (optarg)
88+ compress_type = parse_compress_type(optarg);
89 fancy_ioctl = 1;
90 break;
91 case 'f':
92@@ -203,8 +217,10 @@ int do_defrag(int ac, char **av)
93 range.start = start;
94 range.len = len;
95 range.extent_thresh = thresh;
96- if (compress)
97+ if (compress_type) {
98 range.flags |= BTRFS_DEFRAG_RANGE_COMPRESS;
99+ range.compress_type = compress_type;
100+ }
101 if (flush)
102 range.flags |= BTRFS_DEFRAG_RANGE_START_IO;
103
104diff --git a/ctree.h b/ctree.h
105index ed83d02..61eb639 100644
106--- a/ctree.h
107+++ b/ctree.h
108@@ -354,12 +354,14 @@ struct btrfs_super_block {
109 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
110 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
111 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
112+#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
113
114 #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
115 #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
116 #define BTRFS_FEATURE_INCOMPAT_SUPP \
117 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
118 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
119+ BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
120 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
121
122 /*
123@@ -505,9 +507,11 @@ struct btrfs_timespec {
124 } __attribute__ ((__packed__));
125
126 typedef enum {
127- BTRFS_COMPRESS_NONE = 0,
128- BTRFS_COMPRESS_ZLIB = 1,
129- BTRFS_COMPRESS_LAST = 2,
130+ BTRFS_COMPRESS_NONE = 0,
131+ BTRFS_COMPRESS_ZLIB = 1,
132+ BTRFS_COMPRESS_LZO = 2,
133+ BTRFS_COMPRESS_TYPES = 2,
134+ BTRFS_COMPRESS_LAST = 3,
135 } btrfs_compression_type;
136
137 /* we don't understand any encryption methods right now */
138diff --git a/ioctl.h b/ioctl.h
139index 776d7a9..bb7b9e0 100644
140--- a/ioctl.h
141+++ b/ioctl.h
142@@ -116,8 +116,15 @@ struct btrfs_ioctl_defrag_range_args {
143 */
144 __u32 extent_thresh;
145
146+ /*
147+ * which compression method to use if turning on compression
148+ * for this defrag operation. If unspecified, zlib will
149+ * be used
150+ */
151+ __u32 compress_type;
152+
153 /* spare for later */
154- __u32 unused[5];
155+ __u32 unused[4];
156 };
157
158 struct btrfs_ioctl_space_info {
159diff --git a/man/btrfs.8.in b/man/btrfs.8.in
160index cba2de1..1ffed13 100644
161--- a/man/btrfs.8.in
162+++ b/man/btrfs.8.in
163@@ -15,12 +15,12 @@ btrfs \- control a btrfs filesystem
164 .PP
165 \fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP
166 .PP
167-\fBbtrfs\fP \fBfilesystem defragment\fP\fI [-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\fP
168-.PP
169 \fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP
170 .PP
171 \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP
172 .PP
173+\fBbtrfs\fP \fBfilesystem defrag\fP\fI [options] <file>|<dir> [<file>|<dir>...]\fP
174+.PP
175 \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP
176 .PP
177 \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
178@@ -30,7 +30,6 @@ btrfs \- control a btrfs filesystem
179 \fBbtrfs\fP \fBdevice add\fP\fI <dev> [<dev>..] <path> \fP
180 .PP
181 \fBbtrfs\fP \fBdevice delete\fP\fI <dev> [<dev>..] <path> \fP]
182-
183 .PP
184 \fBbtrfs\fP \fBhelp|\-\-help|\-h \fP\fI\fP
185 .PP
186@@ -104,10 +103,13 @@ Set the subvolume of the filesystem \fI<path>\fR which is mounted as
187 is returned by the \fBsubvolume list\fR command.
188 .TP
189
190-\fBfilesystem defragment\fP\fI [-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\fR
191+\fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...]
192+
193 Defragment file data and/or directory metadata. To defragment all files in a
194 directory you have to specify each one on its own or use your shell wildcards.
195
196+The start position and the number of bytes to deframention can be specified by \fIstart\fR and \fIlen\fR. Any extent bigger than \fIthresh\fR will be considered already defragged. Use 0 to take the kernel default, and use 1 to say eveery single extent must be rewritten. You can also turn on compression in defragment operations.
197+
198 \fB-v\fP be verbose
199
200 \fB-c\fP compress file contents while defragmenting
201--
2021.7.2.3
203
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0009-Update-clean-up-btrfs-help-and-man-page-V2.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0009-Update-clean-up-btrfs-help-and-man-page-V2.patch
new file mode 100644
index 0000000000..3b44d20b9f
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0009-Update-clean-up-btrfs-help-and-man-page-V2.patch
@@ -0,0 +1,272 @@
1Upstream-Status: Inappropriate [Backport]
2From 6f81e1197015ab2dc41beec92c347919feb26967 Mon Sep 17 00:00:00 2001
3From: Goffredo Baroncelli <kreijack@libero.it>
4Date: Sun, 5 Dec 2010 17:47:45 +0000
5Subject: [PATCH 09/15] Update/clean up btrfs help and man page V2
6
7Hi all,
8
9enclose you can find a patch which improves the help of the btrfs commands,
10 updates the INSTALL file and the btrfs (command) man page.
11
12Regarding the help of the btrfs command:
13- moved the "subvolume set-default" command in the "subvolume" commands group
14- removed a wrong new line
15- small tweak on the basis of Andreas suggestion
16
17Regarding the btrfs command man page:
18- renaming the command "device balance" in "filesystem balance" (thanks to
19Andreas Phillipp to highlight that)
20- adding the entry "subvolume find-new"
21- document the switches of the command "filesystem defrag"
22- document the <devid> facility of the command "filesystem resize"
23- small tweak on the basis of Andreas suggestion
24
25Regarding the INSTALL file, which was very old, I removed the reference of the
26old btrfsctl utility and changed the examples using the btrfs command.
27I removed the old (and now wrong) statement about the inability to delete a
28subvolume/snapshot
29
30Chris, you can pull the patch from the branch "help_cleanup" of the following
31repository.
32
33http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
34
35(or you can browse the changes at
36http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git/?p=btrfs-
37progs-unstable-all.git;a=summary)
38
39The patch is very simple: only updates the man page, the INSTALL file and
40 moves/updates some lines in the help of btrfs command. Comments are welcome.
41
42Regards
43G.Baroncelli
44
45 INSTALL | 29 ++++++++++++++++++++---------
46 btrfs.c | 24 ++++++++++++------------
47 man/btrfs.8.in | 45 +++++++++++++++++++++++++--------------------
48 3 files changed, 57 insertions(+), 41 deletions(-)
49
50 all the block devices.
51 .TP
52@@ -138,21 +143,21 @@ can expand the partition before enlarging the filesystem
53and shrink the
54 partition after reducing the size of the filesystem.
55 .TP
56
57-\fBfilesystem show\fR [<uuid>|<label>]\fR
58-Show the btrfs filesystem with some additional info. If no UUID or label is
59-passed, \fBbtrfs\fR show info of all the btrfs filesystem.
60+\fBfilesystem show\fR [<device>|<uuid>|<label>]\fR
61+Show the btrfs filesystem with some additional info. If no argument is
62+passed, \fBbtrfs\fR shows info of all the btrfs filesystems.
63 .TP
64
65-\fBdevice balance\fR \fI<path>\fR
66+\fBfilesystem balance\fR \fI<path>\fR
67 Balance the chunks of the filesystem identified by \fI<path>\fR
68 across the devices.
69 .TP
70
71-\fBdevice add\fR\fI <dev> [<dev>..] <path>\fR
72+\fBdevice add\fR\fI <device> [<device>...] <path>\fR
73 Add device(s) to the filesystem identified by \fI<path>\fR.
74 .TP
75
76-\fBdevice delete\fR\fI <dev> [<dev>..] <path>\fR
77+\fBdevice delete\fR\fI <device> [<device>...] <path>\fR
78 Remove device(s) from a filesystem identified by \fI<path>\fR.
79 .PP
80
81Signed-off-by: Chris Mason <chris.mason@oracle.com>
82---
83 INSTALL | 29 ++++++++++++++++++++---------
84 btrfs.c | 24 ++++++++++++------------
85 man/btrfs.8.in | 29 +++++++++++++++++------------
86 3 files changed, 49 insertions(+), 33 deletions(-)
87
88diff --git a/INSTALL b/INSTALL
89index 16b45a5..3840148 100644
90--- a/INSTALL
91+++ b/INSTALL
92@@ -22,23 +22,32 @@ in the e2fsprogs sources, and is usually available as libuuid or
93 e2fsprogs-devel from various distros.
94
95 Building the utilities is just make ; make install. The programs go
96-into /usr/local/bin. The commands available are:
97+into /usr/local/bin. The mains commands available are:
98
99 mkfs.btrfs: create a filesystem
100
101-btrfsctl: control program to create snapshots and subvolumes:
102-
103+btrfs: control program to create snapshots and subvolumes:
104+ # mount a btrfs filesystem
105 mount /dev/sda2 /mnt
106- btrfsctl -s new_subvol_name /mnt
107- btrfsctl -s snapshot_of_default /mnt/default
108- btrfsctl -s snapshot_of_new_subvol /mnt/new_subvol_name
109- btrfsctl -s snapshot_of_a_snapshot /mnt/snapshot_of_new_subvol
110+
111+ # create a subvolume
112+ btrfs subvolume create /mnt/new_subvol_name
113+
114+ # snapshot of a subvolume
115+ btrfs subvolume snapshot /mnt/default /mnt/snapshot_of_default
116+ btrfs subvolume snapshot /mnt/snapshot_of_default \
117+ /mnt/snapshot_of_a_snapshot
118+
119+ # list of the subvolumes
120 ls /mnt
121 default snapshot_of_a_snapshot snapshot_of_new_subvol
122 new_subvol_name snapshot_of_default
123
124- Snapshots and subvolumes cannot be deleted right now, but you can
125- rm -rf all the files and directories inside them.
126+ # removal of a subvolume or a snapshot
127+ btrfs subvolume delete /mn/snapshot_of_a_snapshot
128+
129+ # look a the btrfs man page for further information
130+ man btrfs
131
132 btrfsck: do a limited check of the FS extent trees.</li>
133
134@@ -46,3 +55,5 @@ debug-tree: print all of the FS metadata in text form. Example:
135
136 debug-tree /dev/sda2 >& big_output_file
137
138+
139+
140diff --git a/btrfs.c b/btrfs.c
141index 1b4f403..62140ef 100644
142--- a/btrfs.c
143+++ b/btrfs.c
144@@ -61,6 +61,11 @@ static struct Command commands[] = {
145 { do_subvol_list, 1, "subvolume list", "<path>\n"
146 "List the snapshot/subvolume of a filesystem."
147 },
148+ { do_set_default_subvol, 2,
149+ "subvolume set-default", "<id> <path>\n"
150+ "Set the subvolume of the filesystem <path> which will be mounted\n"
151+ "as default."
152+ },
153 { do_find_newer, 2, "subvolume find-new", "<path> <last_gen>\n"
154 "List the recently modified files in a filesystem."
155 },
156@@ -68,11 +73,6 @@ static struct Command commands[] = {
157 "filesystem defragment", "[-vf] [-c[zlib,lzo]] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
158 "Defragment a file or a directory."
159 },
160- { do_set_default_subvol, 2,
161- "subvolume set-default", "<id> <path>\n"
162- "Set the subvolume of the filesystem <path> which will be mounted\n"
163- "as default."
164- },
165 { do_fssync, 1,
166 "filesystem sync", "<path>\n"
167 "Force a sync on the filesystem <path>."
168@@ -83,29 +83,29 @@ static struct Command commands[] = {
169 "will occupe all available space on the device."
170 },
171 { do_show_filesystem, 999,
172- "filesystem show", "[<uuid>|<label>]\n"
173- "Show the info of a btrfs filesystem. If no <uuid> or <label>\n"
174+ "filesystem show", "[<device>|<uuid>|<label>]\n"
175+ "Show the info of a btrfs filesystem. If no argument\n"
176 "is passed, info of all the btrfs filesystem are shown."
177 },
178 { do_df_filesystem, 1,
179 "filesystem df", "<path>\n"
180- "Show space usage information for a mount point\n."
181+ "Show space usage information for a mount point."
182 },
183 { do_balance, 1,
184 "filesystem balance", "<path>\n"
185 "Balance the chunks across the device."
186 },
187- { do_scan,
188- 999, "device scan", "[<device> [<device>..]\n"
189+ { do_scan, 999,
190+ "device scan", "[<device>...]\n"
191 "Scan all device for or the passed device for a btrfs\n"
192 "filesystem."
193 },
194 { do_add_volume, -2,
195- "device add", "<dev> [<dev>..] <path>\n"
196+ "device add", "<device> [<device>...] <path>\n"
197 "Add a device to a filesystem."
198 },
199 { do_remove_volume, -2,
200- "device delete", "<dev> [<dev>..] <path>\n"
201+ "device delete", "<device> [<device>...] <path>\n"
202 "Remove a device from a filesystem."
203 },
204 /* coming soon
205diff --git a/man/btrfs.8.in b/man/btrfs.8.in
206index 1ffed13..b9b8913 100644
207--- a/man/btrfs.8.in
208+++ b/man/btrfs.8.in
209@@ -21,15 +21,19 @@ btrfs \- control a btrfs filesystem
210 .PP
211 \fBbtrfs\fP \fBfilesystem defrag\fP\fI [options] <file>|<dir> [<file>|<dir>...]\fP
212 .PP
213-\fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP
214+\fBbtrfs\fP \fBsubvolume find-new\fP\fI <subvolume> <last_gen>\fP
215 .PP
216-\fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
217+\fBbtrfs\fP \fBfilesystem balance\fP\fI <path> \fP
218 .PP
219-\fBbtrfs\fP \fBdevice balance\fP\fI <path> \fP
220+\fBbtrfs\fP \fBfilesystem defragment\fP\fI <file>|<dir> [<file>|<dir>...]\fP
221 .PP
222-\fBbtrfs\fP \fBdevice add\fP\fI <dev> [<dev>..] <path> \fP
223+\fBbtrfs\fP \fBdevice scan\fP\fI [<device>...]\fP
224 .PP
225-\fBbtrfs\fP \fBdevice delete\fP\fI <dev> [<dev>..] <path> \fP]
226+\fBbtrfs\fP \fBdevice show\fP\fI [<device>|<uuid>|<label>]\fP
227+.PP
228+\fBbtrfs\fP \fBdevice add\fP\fI <device> [<device>...] <path> \fP
229+.PP
230+\fBbtrfs\fP \fBdevice delete\fP\fI <device> [<device>...] <path> \fP]
231 .PP
232 \fBbtrfs\fP \fBhelp|\-\-help|\-h \fP\fI\fP
233 .PP
234@@ -48,17 +52,16 @@ For example: it is possible to run
235 instead of
236 .I btrfs subvolume snapshot.
237 But
238-.I btrfs dev s
239+.I btrfs file s
240 is not allowed, because
241-.I dev s
242+.I file s
243 may be interpreted both as
244-.I device show
245+.I filesystem show
246 and as
247-.I device scan.
248+.I filesystem sync.
249 In this case
250 .I btrfs
251-returns an error.
252-
253+returnsfilesystem sync
254 If a command is terminated by
255 .I --help
256 , the detailed help is showed. If the passed command matches more commands,
257@@ -125,9 +128,11 @@ The start position and the number of bytes to deframention can be specified by \
258 NOTE: defragmenting with kernels up to 2.6.37 will unlink COW-ed copies of data, don't
259 use it if you use snapshots, have de-duplicated your data or made copies with
260 \fBcp --reflink\fP.
261+\fBsubvolume find-new\fR\fI <subvolume> <last_gen>\fR
262+List the recently modified files in a subvolume, after \fI<last_gen>\fR ID.
263 .TP
264
265-\fBdevice scan\fR \fI[<device> [<device>..]]\fR
266+\fBdevice scan\fR \fI[<device>...]\fR
267 Scan devices for a btrfs filesystem. If no devices are passed, \fBbtrfs\fR scans
268 all the block devices.
269 .TP
270--
2711.7.2.3
272
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0010-Deprecate-btrfsctl-btrfs-show-btrfs-vol.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0010-Deprecate-btrfsctl-btrfs-show-btrfs-vol.patch
new file mode 100644
index 0000000000..17e515d262
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0010-Deprecate-btrfsctl-btrfs-show-btrfs-vol.patch
@@ -0,0 +1,152 @@
1Upstream-Status: Inappropriate [Backport]
2From 36d8ab7002c5707538849a61eaa97cbac262bbc3 Mon Sep 17 00:00:00 2001
3From: Goffredo Baroncelli <kreijack@libero.it>
4Date: Sun, 5 Dec 2010 17:47:36 +0000
5Subject: [PATCH 10/15] Deprecate btrfsctl, btrfs-show, btrfs-vol
6
7Hi all,
8
9the patch below deprecates the following programs
10
11* btrfsctl
12* btrfs-vol
13* btrfs-show
14
15the reason is simple, these programs are superseded by the btrfs utility,
16both in terms of documentation, usability and bug. The goal is to avoid
17to duplicate codes and avoid update two programs.
18
19The patch adds a warning in the man pages, in the INSTALL file and in the
20programs.
21
22$ ./btrfsctl
23**
24** WARNING: this program is considered deprecated
25** Please consider to switch to the btrfs utility
26**
27no valid commands given
28usage: btrfsctl [ -d file|dir] [ -s snap_name subvol|tree ]
29 [-r size] [-A device] [-a] [-c] [-D dir .]
30 -d filename: defragments one file
31 -d directory: defragments the entire Btree
32 -s snap_name dir: creates a new snapshot of dir
33 -S subvol_name dir: creates a new subvolume
34 -r [+-]size[gkm]: resize the FS by size amount
35 -A device: scans the device file for a Btrfs filesystem
36 -a: scans all devices for Btrfs filesystems
37 -c: forces a single FS sync
38 -D: delete snapshot
39 -m [tree id] directory: set the default mounted subvolume to the [tree
40id] or the
41directory
42
43Below the patch, but it is possible to pull the changes from:
44
45 http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
46
47branch
48
49 btrfs-deprecated
50
51Comments are welcome.
52
53G.Baroncelli
54
55 INSTALL | 5 +++++
56 btrfs-show.c | 5 +++++
57 btrfs-vol.c | 5 +++++
58 btrfsctl.c | 5 +++++
59 man/btrfs-show.8.in | 3 +++
60 man/btrfsctl.8.in | 3 +++
61 6 files changed, 26 insertions(+), 0 deletions(-)
62
63the tool to create a new snapshot for the filesystem.
64
65Signed-off-by: Chris Mason <chris.mason@oracle.com>
66---
67 btrfs-show.c | 5 +++++
68 btrfs-vol.c | 5 +++++
69 btrfsctl.c | 5 +++++
70 man/btrfs-show.8.in | 3 +++
71 man/btrfsctl.8.in | 3 +++
72 5 files changed, 21 insertions(+), 0 deletions(-)
73
74diff --git a/btrfs-show.c b/btrfs-show.c
75index c49626c..8210fd2 100644
76--- a/btrfs-show.c
77+++ b/btrfs-show.c
78@@ -117,6 +117,11 @@ int main(int ac, char **av)
79 int ret;
80 int option_index = 0;
81
82+ printf( "**\n"
83+ "** WARNING: this program is considered deprecated\n"
84+ "** Please consider to switch to the btrfs utility\n"
85+ "**\n");
86+
87 while(1) {
88 int c;
89 c = getopt_long(ac, av, "", long_options,
90diff --git a/btrfs-vol.c b/btrfs-vol.c
91index f573023..0efdbc1 100644
92--- a/btrfs-vol.c
93+++ b/btrfs-vol.c
94@@ -78,6 +78,11 @@ int main(int ac, char **av)
95 struct btrfs_ioctl_vol_args args;
96 u64 dev_block_count = 0;
97
98+ printf( "**\n"
99+ "** WARNING: this program is considered deprecated\n"
100+ "** Please consider to switch to the btrfs utility\n"
101+ "**\n");
102+
103 while(1) {
104 int c;
105 c = getopt_long(ac, av, "a:br:", long_options,
106diff --git a/btrfsctl.c b/btrfsctl.c
107index adfa519..73e20ec 100644
108--- a/btrfsctl.c
109+++ b/btrfsctl.c
110@@ -107,6 +107,11 @@ int main(int ac, char **av)
111 char *fullpath;
112 u64 objectid = 0;
113
114+ printf( "**\n"
115+ "** WARNING: this program is considered deprecated\n"
116+ "** Please consider to switch to the btrfs utility\n"
117+ "**\n");
118+
119 if (ac == 2 && strcmp(av[1], "-a") == 0) {
120 fprintf(stderr, "Scanning for Btrfs filesystems\n");
121 btrfs_scan_one_dir("/dev", 1);
122diff --git a/man/btrfs-show.8.in b/man/btrfs-show.8.in
123index dd0b147..cb98b68 100644
124--- a/man/btrfs-show.8.in
125+++ b/man/btrfs-show.8.in
126@@ -3,6 +3,9 @@
127 btrfs-show \- scan the /dev directory for btrfs partitions and print results.
128 .SH SYNOPSIS
129 .B btrfs-show
130+.SH NOTE
131+.B btrfs-show
132+is deprecated. Please consider to switch to the btrfs utility.
133 .SH DESCRIPTION
134 .B btrfs-show
135 is used to scan the /dev directory for btrfs partitions and display brief
136diff --git a/man/btrfsctl.8.in b/man/btrfsctl.8.in
137index c2d4488..8705fa6 100644
138--- a/man/btrfsctl.8.in
139+++ b/man/btrfsctl.8.in
140@@ -10,6 +10,9 @@ btrfsctl \- control a btrfs filesystem
141 [ \fB \-A\fP\fI device\fP ]
142 [ \fB \-a\fP ]
143 [ \fB \-c\fP ]
144+.SH NOTE
145+B btrfsctl
146+is deprecated. Please consider to switch to the btrfs utility.
147 .SH DESCRIPTION
148 .B btrfsctl
149 is used to control the filesystem and the files and directories stored. It is the tool to create a new snapshot for the filesystem.
150--
1511.7.2.3
152
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0011-Add-the-btrfs-filesystem-label-command.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0011-Add-the-btrfs-filesystem-label-command.patch
new file mode 100644
index 0000000000..40ccb5b92a
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0011-Add-the-btrfs-filesystem-label-command.patch
@@ -0,0 +1,390 @@
1Upstream-Status: Inappropriate [Backport]
2From d1dc6a9cff7e2fe4f335ca783a4b033457b3e184 Mon Sep 17 00:00:00 2001
3From: Goffredo Baroncelli <kreijack@inwind.it>
4Date: Sun, 5 Dec 2010 17:46:44 +0000
5Subject: [PATCH 11/15] Add the "btrfs filesystem label" command
6
7Hi all,
8
9this patch adds the command "btrfs filesystem label" to change (or show) the
10label of a filesystem.
11This patch is a subset of the one written previously by Morey Roof. I
12included the user space part only. So it is possible only to change/show a
13label of a *single device* and *unounted* filesystem.
14
15The reason of excluding the kernel space part, is to simplify the patch in
16order to speed the check and then the merging of the patch itself. In fact I
17have to point out that in the past there was almost three attempts to propose
18this patch, without success neither complaints.
19
20Chris, let me know how you want to proceed. I know that you are very busy,
21and you prefer to work to stabilize btrfs instead adding new feature. But I
22think that changing a label is a *essential* feature for a filesystem
23managing tool. Think about a mount by LABEL.
24
25To show a label
26
27$ btrfs filesystem label <device>
28
29To set a label
30
31$ btrfs filesystem label <device> <newlabel>
32
33Please guys, give a look to the source.
34Comments are welcome.
35
36You can pull the source from the branch "label" of the repository
37http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
38
39Regards
40G.Baroncelli
41
42Signed-off-by: Chris Mason <chris.mason@oracle.com>
43---
44 Makefile | 2 +-
45 btrfs.c | 5 --
46 btrfs_cmds.c | 16 +++++++
47 btrfs_cmds.h | 1 +
48 btrfslabel.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 btrfslabel.h | 5 ++
50 man/btrfs.8.in | 19 +++++++++
51 utils.c | 57 ++++++++++++++++++++++++++
52 utils.h | 2 +
53 9 files changed, 222 insertions(+), 6 deletions(-)
54 create mode 100644 btrfslabel.c
55 create mode 100644 btrfslabel.h
56
57diff --git a/Makefile b/Makefile
58index d65f6a2..4b95d2f 100644
59--- a/Makefile
60+++ b/Makefile
61@@ -4,7 +4,7 @@ CFLAGS = -g -Werror -Os
62 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
63 root-tree.o dir-item.o file-item.o inode-item.o \
64 inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \
65- volumes.o utils.o btrfs-list.o
66+ volumes.o utils.o btrfs-list.o btrfslabel.o
67
68 #
69 CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
70diff --git a/btrfs.c b/btrfs.c
71index 62140ef..4cd4210 100644
72--- a/btrfs.c
73+++ b/btrfs.c
74@@ -108,11 +108,6 @@ static struct Command commands[] = {
75 "device delete", "<device> [<device>...] <path>\n"
76 "Remove a device from a filesystem."
77 },
78- /* coming soon
79- { 2, "filesystem label", "<label> <path>\n"
80- "Set the label of a filesystem"
81- }
82- */
83 { 0, 0 , 0 }
84 };
85
86diff --git a/btrfs_cmds.c b/btrfs_cmds.c
87index 26d4fcc..6de73f4 100644
88--- a/btrfs_cmds.c
89+++ b/btrfs_cmds.c
90@@ -40,6 +40,7 @@
91 #include "volumes.h"
92
93 #include "btrfs_cmds.h"
94+#include "btrfslabel.h"
95
96 #ifdef __CHECKER__
97 #define BLKGETSIZE64 0
98@@ -874,6 +875,21 @@ int do_set_default_subvol(int nargs, char **argv)
99 return 0;
100 }
101
102+int do_change_label(int nargs, char **argv)
103+{
104+ /* check the number of argument */
105+ if ( nargs > 3 ){
106+ fprintf(stderr, "ERROR: '%s' requires maximum 2 args\n",
107+ argv[0]);
108+ return -2;
109+ }else if (nargs == 2){
110+ return get_label(argv[1]);
111+ } else { /* nargs == 0 */
112+ return set_label(argv[1], argv[2]);
113+ }
114+}
115+
116+
117 int do_df_filesystem(int nargs, char **argv)
118 {
119 struct btrfs_ioctl_space_args *sargs;
120diff --git a/btrfs_cmds.h b/btrfs_cmds.h
121index 7bde191..ab722d4 100644
122--- a/btrfs_cmds.h
123+++ b/btrfs_cmds.h
124@@ -32,3 +32,4 @@ int list_subvols(int fd);
125 int do_df_filesystem(int nargs, char **argv);
126 int find_updated_files(int fd, u64 root_id, u64 oldest_gen);
127 int do_find_newer(int argc, char **argv);
128+int do_change_label(int argc, char **argv);
129diff --git a/btrfslabel.c b/btrfslabel.c
130new file mode 100644
131index 0000000..c9f4684
132--- /dev/null
133+++ b/btrfslabel.c
134@@ -0,0 +1,121 @@
135+/*
136+ * Copyright (C) 2008 Morey Roof. All rights reserved.
137+ *
138+ * This program is free software; you can redistribute it and/or
139+ * modify it under the terms of the GNU General Public
140+ * License v2 as published by the Free Software Foundation.
141+ *
142+ * This program is distributed in the hope that it will be useful,
143+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
144+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
145+ * General Public License for more details.
146+ *
147+ * You should have received a copy of the GNU General Public
148+ * License along with this program; if not, write to the
149+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
150+ * Boston, MA 021110-1307, USA.
151+ */
152+
153+#define _GNU_SOURCE
154+
155+#ifndef __CHECKER__
156+#include <sys/ioctl.h>
157+#include <sys/mount.h>
158+#include "ioctl.h"
159+#endif /* __CHECKER__ */
160+
161+#include <stdio.h>
162+#include <stdlib.h>
163+#include <sys/types.h>
164+#include <sys/stat.h>
165+#include <dirent.h>
166+#include <fcntl.h>
167+#include <unistd.h>
168+#include <linux/fs.h>
169+#include <linux/limits.h>
170+#include <ctype.h>
171+#include "kerncompat.h"
172+#include "ctree.h"
173+#include "utils.h"
174+#include "version.h"
175+#include "disk-io.h"
176+#include "transaction.h"
177+
178+#define MOUNTED 1
179+#define UNMOUNTED 2
180+#define GET_LABEL 3
181+#define SET_LABEL 4
182+
183+static void change_label_unmounted(char *dev, char *nLabel)
184+{
185+ struct btrfs_root *root;
186+ struct btrfs_trans_handle *trans;
187+
188+ /* Open the super_block at the default location
189+ * and as read-write.
190+ */
191+ root = open_ctree(dev, 0, 1);
192+
193+ trans = btrfs_start_transaction(root, 1);
194+ strncpy(root->fs_info->super_copy.label, nLabel, BTRFS_LABEL_SIZE);
195+ btrfs_commit_transaction(trans, root);
196+
197+ /* Now we close it since we are done. */
198+ close_ctree(root);
199+}
200+
201+static void get_label_unmounted(char *dev)
202+{
203+ struct btrfs_root *root;
204+
205+ /* Open the super_block at the default location
206+ * and as read-only.
207+ */
208+ root = open_ctree(dev, 0, 0);
209+
210+ fprintf(stdout, "%s\n", root->fs_info->super_copy.label);
211+
212+ /* Now we close it since we are done. */
213+ close_ctree(root);
214+}
215+
216+int get_label(char *btrfs_dev)
217+{
218+
219+ int ret;
220+ ret = check_mounted(btrfs_dev);
221+ if (ret < 0)
222+ {
223+ fprintf(stderr, "FATAL: error checking %s mount status\n", btrfs_dev);
224+ return -1;
225+ }
226+
227+ if(ret != 0)
228+ {
229+ fprintf(stderr, "FATAL: the filesystem has to be unmounted\n");
230+ return -2;
231+ }
232+ get_label_unmounted(btrfs_dev);
233+ return 0;
234+}
235+
236+
237+int set_label(char *btrfs_dev, char *nLabel)
238+{
239+
240+ int ret;
241+ ret = check_mounted(btrfs_dev);
242+ if (ret < 0)
243+ {
244+ fprintf(stderr, "FATAL: error checking %s mount status\n", btrfs_dev);
245+ return -1;
246+ }
247+
248+ if(ret != 0)
249+ {
250+ fprintf(stderr, "FATAL: the filesystem has to be unmounted\n");
251+ return -2;
252+ }
253+ change_label_unmounted(btrfs_dev, nLabel);
254+ return 0;
255+}
256diff --git a/btrfslabel.h b/btrfslabel.h
257new file mode 100644
258index 0000000..abf43ad
259--- /dev/null
260+++ b/btrfslabel.h
261@@ -0,0 +1,5 @@
262+/* btrflabel.h */
263+
264+
265+int get_label(char *btrfs_dev);
266+int set_label(char *btrfs_dev, char *nLabel);
267\ No newline at end of file
268diff --git a/man/btrfs.8.in b/man/btrfs.8.in
269index b9b8913..6f92f91 100644
270--- a/man/btrfs.8.in
271+++ b/man/btrfs.8.in
272@@ -19,6 +19,8 @@ btrfs \- control a btrfs filesystem
273 .PP
274 \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP
275 .PP
276+\fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP
277+.PP
278 \fBbtrfs\fP \fBfilesystem defrag\fP\fI [options] <file>|<dir> [<file>|<dir>...]\fP
279 .PP
280 \fBbtrfs\fP \fBsubvolume find-new\fP\fI <subvolume> <last_gen>\fP
281@@ -164,6 +166,23 @@ can expand the partition before enlarging the filesystem and shrink the
282 partition after reducing the size of the filesystem.
283 .TP
284
285+\fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP
286+Show or update the label of a filesystem. \fI<dev>\fR is used to identify the
287+filesystem.
288+If a \fInewlabel\fR optional argument is passed, the label is changed. The
289+following costraints exist for a label:
290+.IP
291+- the maximum allowable lenght shall be less or equal than 256 chars
292+.IP
293+- the label shall not contain the '/' or '\\' characters.
294+
295+NOTE: Currently there are the following limitations:
296+.IP
297+- the filesystem has to be unmounted
298+.IP
299+- the filesystem should not have more than one device.
300+.TP
301+
302 \fBfilesystem show\fR [<uuid>|<label>]\fR
303 Show the btrfs filesystem with some additional info. If no UUID or label is
304 passed, \fBbtrfs\fR show info of all the btrfs filesystem.
305diff --git a/utils.c b/utils.c
306index ad980ae..13373c9 100644
307--- a/utils.c
308+++ b/utils.c
309@@ -812,6 +812,39 @@ out_mntloop_err:
310 return ret;
311 }
312
313+/* Gets the mount point of btrfs filesystem that is using the specified device.
314+ * Returns 0 is everything is good, <0 if we have an error.
315+ * TODO: Fix this fucntion and check_mounted to work with multiple drive BTRFS
316+ * setups.
317+ */
318+int get_mountpt(char *dev, char *mntpt, size_t size)
319+{
320+ struct mntent *mnt;
321+ FILE *f;
322+ int ret = 0;
323+
324+ f = setmntent("/proc/mounts", "r");
325+ if (f == NULL)
326+ return -errno;
327+
328+ while ((mnt = getmntent(f)) != NULL )
329+ {
330+ if (strcmp(dev, mnt->mnt_fsname) == 0)
331+ {
332+ strncpy(mntpt, mnt->mnt_dir, size);
333+ break;
334+ }
335+ }
336+
337+ if (mnt == NULL)
338+ {
339+ /* We didn't find an entry so lets report an error */
340+ ret = -1;
341+ }
342+
343+ return ret;
344+}
345+
346 struct pending_dir {
347 struct list_head list;
348 char name[256];
349@@ -1002,3 +1035,27 @@ char *pretty_sizes(u64 size)
350 return pretty;
351 }
352
353+/*
354+ * Checks to make sure that the label matches our requirements.
355+ * Returns:
356+ 0 if everything is safe and usable
357+ -1 if the label is too long
358+ -2 if the label contains an invalid character
359+ */
360+int check_label(char *input)
361+{
362+ int i;
363+ int len = strlen(input);
364+
365+ if (len > BTRFS_LABEL_SIZE) {
366+ return -1;
367+ }
368+
369+ for (i = 0; i < len; i++) {
370+ if (input[i] == '/' || input[i] == '\\') {
371+ return -2;
372+ }
373+ }
374+
375+ return 0;
376+}
377diff --git a/utils.h b/utils.h
378index a28d7f4..c3004ae 100644
379--- a/utils.h
380+++ b/utils.h
381@@ -40,4 +40,6 @@ int check_mounted(const char *devicename);
382 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
383 int super_offset);
384 char *pretty_sizes(u64 size);
385+int check_label(char *input);
386+int get_mountpt(char *dev, char *mntpt, size_t size);
387 #endif
388--
3891.7.2.3
390
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0012-Btrfs-progs-Update-man-page-for-mixed-data-metadata-.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0012-Btrfs-progs-Update-man-page-for-mixed-data-metadata-.patch
new file mode 100644
index 0000000000..2f3746f23e
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0012-Btrfs-progs-Update-man-page-for-mixed-data-metadata-.patch
@@ -0,0 +1,42 @@
1Upstream-Status: Inappropriate [Backport]
2From 4c6ae809c50d44d4530a211b95b004002b3ba45f Mon Sep 17 00:00:00 2001
3From: Mitch Harder <mitch.harder@sabayonlinux.org>
4Date: Mon, 15 Nov 2010 16:32:12 +0000
5Subject: [PATCH 12/15] Btrfs-progs: Update man page for mixed data+metadata option.
6
7Update the mkfs.btrfs man page for the -M option to mix data and
8metadata chunks.
9
10Signed-off-by: Chris Mason <chris.mason@oracle.com>
11---
12 man/mkfs.btrfs.8.in | 7 +++++++
13 1 files changed, 7 insertions(+), 0 deletions(-)
14
15diff --git a/man/mkfs.btrfs.8.in b/man/mkfs.btrfs.8.in
16index 1e14c6c..432db1b 100644
17--- a/man/mkfs.btrfs.8.in
18+++ b/man/mkfs.btrfs.8.in
19@@ -9,6 +9,7 @@ mkfs.btrfs \- create an btrfs filesystem
20 [ \fB \-l\fP\fI leafsize\fP ]
21 [ \fB \-L\fP\fI label\fP ]
22 [ \fB \-m\fP\fI metadata profile\fP ]
23+[ \fB \-M\fP\fI mixed data+metadata\fP ]
24 [ \fB \-n\fP\fI nodesize\fP ]
25 [ \fB \-s\fP\fI sectorsize\fP ]
26 [ \fB \-h\fP ]
27@@ -45,6 +46,12 @@ Specify a label for the filesystem.
28 Specify how metadata must be spanned across the devices specified. Valid
29 values are raid0, raid1, raid10 or single.
30 .TP
31+\fB\-M\fR, \fB\-\-mixed\fR
32+Mix data and metadata chunks together for more efficient space
33+utilization. This feature incurs a performance penalty in
34+larger filesystems. It is recommended for use with filesystems
35+of 1 GiB or smaller.
36+.TP
37 \fB\-n\fR, \fB\-\-nodesize \fIsize\fR
38 Specify the nodesize. By default the value is set to the pagesize.
39 .TP
40--
411.7.2.3
42
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0013-btrfs-progs-Add-new-feature-to-mkfs.btrfs-to-make-fi.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0013-btrfs-progs-Add-new-feature-to-mkfs.btrfs-to-make-fi.patch
new file mode 100644
index 0000000000..215106edb8
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0013-btrfs-progs-Add-new-feature-to-mkfs.btrfs-to-make-fi.patch
@@ -0,0 +1,1108 @@
1Upstream-Status: Inappropriate [Backport]
2From e3736c698e8b490bea1375576b718a2de6e89603 Mon Sep 17 00:00:00 2001
3From: Donggeun Kim <dg77.kim@samsung.com>
4Date: Thu, 8 Jul 2010 09:17:59 +0000
5Subject: [PATCH 13/15] btrfs-progs: Add new feature to mkfs.btrfs to make file system image file from source directory
6
7Changes from V1 to V2:
8- support extended attributes
9- move btrfs_alloc_data_chunk function to volumes.c
10- fix an execution error when additional useless parameters are specified
11- fix traverse_directory function so that the insertion functions for the common items are invoked in a single point
12
13The extended attributes is implemented through llistxattr and getxattr function calls.
14
15Thanks
16
17Signed-off-by: Donggeun Kim <dg77.kim@samsung.com>
18Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
19Signed-off-by: Chris Mason <chris.mason@oracle.com>
20---
21 mkfs.c | 864 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
22 volumes.c | 104 ++++++++
23 volumes.h | 3 +
24 3 files changed, 947 insertions(+), 24 deletions(-)
25
26diff --git a/mkfs.c b/mkfs.c
27index 04de93a..57c88f9 100644
28--- a/mkfs.c
29+++ b/mkfs.c
30@@ -29,12 +29,14 @@
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34+#include <sys/dir.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <getopt.h>
38 #include <uuid/uuid.h>
39 #include <linux/fs.h>
40 #include <ctype.h>
41+#include <attr/xattr.h>
42 #include "kerncompat.h"
43 #include "ctree.h"
44 #include "disk-io.h"
45@@ -43,6 +45,15 @@
46 #include "utils.h"
47 #include "version.h"
48
49+static u64 index_cnt = 2;
50+
51+struct directory_name_entry {
52+ char *dir_name;
53+ char *path;
54+ ino_t inum;
55+ struct list_head list;
56+};
57+
58 static u64 parse_size(char *s)
59 {
60 int len = strlen(s);
61@@ -298,6 +309,7 @@ static void print_usage(void)
62 fprintf(stderr, "\t -M --mixed mix metadata and data together\n");
63 fprintf(stderr, "\t -n --nodesize size of btree nodes\n");
64 fprintf(stderr, "\t -s --sectorsize min block allocation\n");
65+ fprintf(stderr, "\t -r --rootdir the source directory\n");
66 fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
67 exit(1);
68 }
69@@ -355,9 +367,768 @@ static struct option long_options[] = {
70 { "sectorsize", 1, NULL, 's' },
71 { "data", 1, NULL, 'd' },
72 { "version", 0, NULL, 'V' },
73+ { "rootdir", 1, NULL, 'r' },
74 { 0, 0, 0, 0}
75 };
76
77+static int add_directory_items(struct btrfs_trans_handle *trans,
78+ struct btrfs_root *root, u64 objectid,
79+ ino_t parent_inum, const char *name,
80+ struct stat *st, int *dir_index_cnt)
81+{
82+ int ret;
83+ int name_len;
84+ struct btrfs_key location;
85+ u8 filetype = 0;
86+
87+ name_len = strlen(name);
88+
89+ location.objectid = objectid;
90+ location.offset = 0;
91+ btrfs_set_key_type(&location, BTRFS_INODE_ITEM_KEY);
92+
93+ if (S_ISDIR(st->st_mode))
94+ filetype = BTRFS_FT_DIR;
95+ if (S_ISREG(st->st_mode))
96+ filetype = BTRFS_FT_REG_FILE;
97+ if (S_ISLNK(st->st_mode))
98+ filetype = BTRFS_FT_SYMLINK;
99+
100+ ret = btrfs_insert_dir_item(trans, root, name, name_len,
101+ parent_inum, &location,
102+ filetype, index_cnt);
103+
104+ *dir_index_cnt = index_cnt;
105+ index_cnt++;
106+
107+ return ret;
108+}
109+
110+static int fill_inode_item(struct btrfs_trans_handle *trans,
111+ struct btrfs_root *root,
112+ struct btrfs_inode_item *dst, struct stat *src)
113+{
114+ u64 blocks = 0;
115+ u64 sectorsize = root->sectorsize;
116+
117+ btrfs_set_stack_inode_generation(dst, trans->transid);
118+ btrfs_set_stack_inode_size(dst, src->st_size);
119+ btrfs_set_stack_inode_nbytes(dst, 0);
120+ btrfs_set_stack_inode_block_group(dst, 0);
121+ btrfs_set_stack_inode_nlink(dst, src->st_nlink);
122+ btrfs_set_stack_inode_uid(dst, src->st_uid);
123+ btrfs_set_stack_inode_gid(dst, src->st_gid);
124+ btrfs_set_stack_inode_mode(dst, src->st_mode);
125+ btrfs_set_stack_inode_rdev(dst, 0);
126+ btrfs_set_stack_inode_flags(dst, 0);
127+ btrfs_set_stack_timespec_sec(&dst->atime, src->st_atime);
128+ btrfs_set_stack_timespec_nsec(&dst->atime, 0);
129+ btrfs_set_stack_timespec_sec(&dst->ctime, src->st_ctime);
130+ btrfs_set_stack_timespec_nsec(&dst->ctime, 0);
131+ btrfs_set_stack_timespec_sec(&dst->mtime, src->st_mtime);
132+ btrfs_set_stack_timespec_nsec(&dst->mtime, 0);
133+ btrfs_set_stack_timespec_sec(&dst->otime, 0);
134+ btrfs_set_stack_timespec_nsec(&dst->otime, 0);
135+
136+ if (S_ISDIR(src->st_mode)) {
137+ btrfs_set_stack_inode_size(dst, 0);
138+ btrfs_set_stack_inode_nlink(dst, 1);
139+ }
140+ if (S_ISREG(src->st_mode)) {
141+ btrfs_set_stack_inode_size(dst, (u64)src->st_size);
142+ if (src->st_size <= BTRFS_MAX_INLINE_DATA_SIZE(root))
143+ btrfs_set_stack_inode_nbytes(dst, src->st_size);
144+ else {
145+ blocks = src->st_size / sectorsize;
146+ if (src->st_size % sectorsize)
147+ blocks += 1;
148+ blocks *= sectorsize;
149+ btrfs_set_stack_inode_nbytes(dst, blocks);
150+ }
151+ }
152+ if (S_ISLNK(src->st_mode))
153+ btrfs_set_stack_inode_nbytes(dst, src->st_size + 1);
154+
155+ return 0;
156+}
157+
158+static int directory_select(const struct direct *entry)
159+{
160+ if ((strncmp(entry->d_name, ".", entry->d_reclen) == 0) ||
161+ (strncmp(entry->d_name, "..", entry->d_reclen) == 0))
162+ return 0;
163+ else
164+ return 1;
165+}
166+
167+static u64 calculate_dir_inode_size(char *dirname)
168+{
169+ int count, i;
170+ struct direct **files, *cur_file;
171+ u64 dir_inode_size = 0;
172+
173+ count = scandir(dirname, &files, directory_select, NULL);
174+
175+ for (i = 0; i < count; i++) {
176+ cur_file = files[i];
177+ dir_inode_size += strlen(cur_file->d_name);
178+ }
179+
180+ dir_inode_size *= 2;
181+ return dir_inode_size;
182+}
183+
184+static int add_inode_items(struct btrfs_trans_handle *trans,
185+ struct btrfs_root *root,
186+ struct stat *st, char *name,
187+ u64 self_objectid, ino_t parent_inum,
188+ int dir_index_cnt, struct btrfs_inode_item *inode_ret)
189+{
190+ int ret;
191+ struct btrfs_key inode_key;
192+ struct btrfs_inode_item btrfs_inode;
193+ u64 objectid;
194+ u64 inode_size = 0;
195+ int name_len;
196+
197+ name_len = strlen(name);
198+ fill_inode_item(trans, root, &btrfs_inode, st);
199+ objectid = self_objectid;
200+
201+ if (S_ISDIR(st->st_mode)) {
202+ inode_size = calculate_dir_inode_size(name);
203+ btrfs_set_stack_inode_size(&btrfs_inode, inode_size);
204+ }
205+
206+ inode_key.objectid = objectid;
207+ inode_key.offset = 0;
208+ btrfs_set_key_type(&inode_key, BTRFS_INODE_ITEM_KEY);
209+
210+ ret = btrfs_insert_inode(trans, root, objectid, &btrfs_inode);
211+ if (ret)
212+ goto fail;
213+
214+ ret = btrfs_insert_inode_ref(trans, root, name, name_len,
215+ objectid, parent_inum, dir_index_cnt);
216+ if (ret)
217+ goto fail;
218+
219+ *inode_ret = btrfs_inode;
220+fail:
221+ return ret;
222+}
223+
224+static int add_xattr_item(struct btrfs_trans_handle *trans,
225+ struct btrfs_root *root, u64 objectid,
226+ const char *file_name)
227+{
228+ int ret;
229+ int cur_name_len;
230+ char xattr_list[XATTR_LIST_MAX];
231+ char *cur_name;
232+ char cur_value[XATTR_SIZE_MAX];
233+ char delimiter = '\0';
234+ char *next_location = xattr_list;
235+
236+ ret = llistxattr(file_name, xattr_list, XATTR_LIST_MAX);
237+ if (ret < 0) {
238+ fprintf(stderr, "get a list of xattr failed for %s\n",
239+ file_name);
240+ return ret;
241+ }
242+ if (ret == 0)
243+ return ret;
244+
245+ cur_name = strtok(xattr_list, &delimiter);
246+ while (cur_name != NULL) {
247+ cur_name_len = strlen(cur_name);
248+ next_location += cur_name_len + 1;
249+
250+ ret = getxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
251+ if (ret < 0) {
252+ fprintf(stderr, "get a xattr value failed for %s\n",
253+ cur_name);
254+ }
255+
256+ ret = btrfs_insert_xattr_item(trans, root, cur_name,
257+ cur_name_len, cur_value,
258+ ret, objectid);
259+ if (ret) {
260+ fprintf(stderr, "insert a xattr item failed for %s\n",
261+ file_name);
262+ }
263+
264+ cur_name = strtok(next_location, &delimiter);
265+ }
266+
267+ return ret;
268+}
269+
270+static int custom_alloc_extent(struct btrfs_root *root, u64 num_bytes,
271+ u64 hint_byte, struct btrfs_key *ins)
272+{
273+ u64 start;
274+ u64 end;
275+ u64 last = hint_byte;
276+ int ret;
277+ int wrapped = 0;
278+ struct btrfs_block_group_cache *cache;
279+
280+ while (1) {
281+ ret = find_first_extent_bit(&root->fs_info->free_space_cache,
282+ last, &start, &end, EXTENT_DIRTY);
283+ if (ret) {
284+ if (wrapped++ == 0) {
285+ last = 0;
286+ continue;
287+ } else {
288+ goto fail;
289+ }
290+ }
291+
292+ start = max(last, start);
293+ last = end + 1;
294+ if (last - start < num_bytes)
295+ continue;
296+
297+ last = start + num_bytes;
298+ if (test_range_bit(&root->fs_info->pinned_extents,
299+ start, last - 1, EXTENT_DIRTY, 0))
300+ continue;
301+
302+ cache = btrfs_lookup_block_group(root->fs_info, start);
303+ BUG_ON(!cache);
304+ if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM ||
305+ last > cache->key.objectid + cache->key.offset) {
306+ last = cache->key.objectid + cache->key.offset;
307+ continue;
308+ }
309+
310+ if (cache->flags & (BTRFS_BLOCK_GROUP_SYSTEM |
311+ BTRFS_BLOCK_GROUP_METADATA)) {
312+ last = cache->key.objectid + cache->key.offset;
313+ continue;
314+ }
315+
316+ clear_extent_dirty(&root->fs_info->free_space_cache,
317+ start, start + num_bytes - 1, 0);
318+
319+ ins->objectid = start;
320+ ins->offset = num_bytes;
321+ ins->type = BTRFS_EXTENT_ITEM_KEY;
322+ return 0;
323+ }
324+fail:
325+ fprintf(stderr, "not enough free space\n");
326+ return -ENOSPC;
327+}
328+
329+static int record_file_extent(struct btrfs_trans_handle *trans,
330+ struct btrfs_root *root, u64 objectid,
331+ struct btrfs_inode_item *inode,
332+ u64 file_pos, u64 disk_bytenr,
333+ u64 num_bytes)
334+{
335+ int ret;
336+ struct btrfs_fs_info *info = root->fs_info;
337+ struct btrfs_root *extent_root = info->extent_root;
338+ struct extent_buffer *leaf;
339+ struct btrfs_file_extent_item *fi;
340+ struct btrfs_key ins_key;
341+ struct btrfs_path path;
342+ struct btrfs_extent_item *ei;
343+
344+ btrfs_init_path(&path);
345+
346+ ins_key.objectid = objectid;
347+ ins_key.offset = 0;
348+ btrfs_set_key_type(&ins_key, BTRFS_EXTENT_DATA_KEY);
349+ ret = btrfs_insert_empty_item(trans, root, &path, &ins_key,
350+ sizeof(*fi));
351+ if (ret)
352+ goto fail;
353+ leaf = path.nodes[0];
354+ fi = btrfs_item_ptr(leaf, path.slots[0],
355+ struct btrfs_file_extent_item);
356+ btrfs_set_file_extent_generation(leaf, fi, trans->transid);
357+ btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG);
358+ btrfs_set_file_extent_disk_bytenr(leaf, fi, disk_bytenr);
359+ btrfs_set_file_extent_disk_num_bytes(leaf, fi, num_bytes);
360+ btrfs_set_file_extent_offset(leaf, fi, 0);
361+ btrfs_set_file_extent_num_bytes(leaf, fi, num_bytes);
362+ btrfs_set_file_extent_ram_bytes(leaf, fi, num_bytes);
363+ btrfs_set_file_extent_compression(leaf, fi, 0);
364+ btrfs_set_file_extent_encryption(leaf, fi, 0);
365+ btrfs_set_file_extent_other_encoding(leaf, fi, 0);
366+ btrfs_mark_buffer_dirty(leaf);
367+
368+ btrfs_release_path(root, &path);
369+
370+ ins_key.objectid = disk_bytenr;
371+ ins_key.offset = num_bytes;
372+ ins_key.type = BTRFS_EXTENT_ITEM_KEY;
373+
374+ ret = btrfs_insert_empty_item(trans, extent_root, &path,
375+ &ins_key, sizeof(*ei));
376+ if (ret == 0) {
377+ leaf = path.nodes[0];
378+ ei = btrfs_item_ptr(leaf, path.slots[0],
379+ struct btrfs_extent_item);
380+
381+ btrfs_set_extent_refs(leaf, ei, 0);
382+ btrfs_set_extent_generation(leaf, ei, trans->transid);
383+ btrfs_set_extent_flags(leaf, ei, BTRFS_EXTENT_FLAG_DATA);
384+
385+ btrfs_mark_buffer_dirty(leaf);
386+ ret = btrfs_update_block_group(trans, root, disk_bytenr,
387+ num_bytes, 1, 0);
388+ if (ret)
389+ goto fail;
390+ } else if (ret != -EEXIST) {
391+ goto fail;
392+ }
393+
394+ ret = btrfs_inc_extent_ref(trans, root, disk_bytenr, num_bytes, 0,
395+ root->root_key.objectid,
396+ objectid, 0);
397+fail:
398+ btrfs_release_path(root, &path);
399+ return ret;
400+}
401+
402+static int add_symbolic_link(struct btrfs_trans_handle *trans,
403+ struct btrfs_root *root,
404+ u64 objectid, const char *path_name)
405+{
406+ int ret;
407+ u64 sectorsize = root->sectorsize;
408+ char *buf = malloc(sectorsize);
409+
410+ ret = readlink(path_name, buf, sectorsize);
411+ if (ret <= 0) {
412+ fprintf(stderr, "readlink failed for %s\n", path_name);
413+ goto fail;
414+ }
415+ if (ret > sectorsize) {
416+ fprintf(stderr, "symlink too long for %s", path_name);
417+ ret = -1;
418+ goto fail;
419+ }
420+ ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
421+ buf, ret + 1);
422+fail:
423+ free(buf);
424+ return ret;
425+}
426+
427+static int add_file_items(struct btrfs_trans_handle *trans,
428+ struct btrfs_root *root,
429+ struct btrfs_inode_item *btrfs_inode, u64 objectid,
430+ ino_t parent_inum, struct stat *st,
431+ const char *path_name, int out_fd)
432+{
433+ int ret;
434+ ssize_t ret_read;
435+ u64 bytes_read = 0;
436+ char *buffer = NULL;
437+ struct btrfs_key key;
438+ int blocks;
439+ u32 sectorsize = root->sectorsize;
440+ u64 first_block = 0;
441+ u64 num_blocks = 0;
442+ int fd;
443+
444+ fd = open(path_name, O_RDONLY);
445+ if (fd == -1) {
446+ fprintf(stderr, "%s open failed\n", path_name);
447+ goto end;
448+ }
449+
450+ blocks = st->st_size / sectorsize;
451+ if (st->st_size % sectorsize)
452+ blocks += 1;
453+
454+ if (st->st_size <= BTRFS_MAX_INLINE_DATA_SIZE(root)) {
455+ buffer = malloc(st->st_size);
456+ ret_read = pread64(fd, buffer, st->st_size, bytes_read);
457+ if (ret_read == -1) {
458+ fprintf(stderr, "%s read failed\n", path_name);
459+ goto end;
460+ }
461+
462+ ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
463+ buffer, st->st_size);
464+ goto end;
465+ }
466+
467+ ret = custom_alloc_extent(root, blocks * sectorsize, 0, &key);
468+ if (ret)
469+ goto end;
470+
471+ first_block = key.objectid;
472+ bytes_read = 0;
473+ buffer = malloc(sectorsize);
474+
475+ do {
476+ memset(buffer, 0, sectorsize);
477+ ret_read = pread64(fd, buffer, sectorsize, bytes_read);
478+ if (ret_read == -1) {
479+ fprintf(stderr, "%s read failed\n", path_name);
480+ goto end;
481+ }
482+
483+ ret = pwrite64(out_fd, buffer, sectorsize,
484+ first_block + bytes_read);
485+ if (ret != sectorsize) {
486+ fprintf(stderr, "output file write failed\n");
487+ goto end;
488+ }
489+
490+ /* checksum for file data */
491+ ret = btrfs_csum_file_block(trans, root->fs_info->csum_root,
492+ first_block + (blocks * sectorsize),
493+ first_block + bytes_read,
494+ buffer, sectorsize);
495+ if (ret) {
496+ fprintf(stderr, "%s checksum failed\n", path_name);
497+ goto end;
498+ }
499+
500+ bytes_read += ret_read;
501+ num_blocks++;
502+ } while (ret_read == sectorsize);
503+
504+ if (num_blocks > 0) {
505+ ret = record_file_extent(trans, root, objectid, btrfs_inode,
506+ first_block, first_block,
507+ blocks * sectorsize);
508+ if (ret)
509+ goto end;
510+ }
511+
512+end:
513+ if (buffer)
514+ free(buffer);
515+ close(fd);
516+ return ret;
517+}
518+
519+static char *make_path(char *dir, char *name)
520+{
521+ char *path;
522+
523+ path = malloc(strlen(dir) + strlen(name) + 2);
524+ if (!path)
525+ return NULL;
526+ strcpy(path, dir);
527+ if (dir[strlen(dir) - 1] != '/')
528+ strcat(path, "/");
529+ strcat(path, name);
530+ return path;
531+}
532+
533+static int traverse_directory(struct btrfs_trans_handle *trans,
534+ struct btrfs_root *root, char *dir_name,
535+ struct directory_name_entry *dir_head, int out_fd)
536+{
537+ int ret = 0;
538+
539+ struct btrfs_inode_item cur_inode;
540+ struct btrfs_inode_item *inode_item;
541+ int count, i, dir_index_cnt;
542+ struct direct **files;
543+ struct stat st;
544+ struct directory_name_entry *dir_entry, *parent_dir_entry;
545+ struct direct *cur_file;
546+ ino_t parent_inum, cur_inum;
547+ ino_t highest_inum = 0;
548+ char *parent_dir_name;
549+ struct btrfs_path path;
550+ struct extent_buffer *leaf;
551+ struct btrfs_key root_dir_key;
552+ u64 root_dir_inode_size = 0;
553+
554+ /* Add list for source directory */
555+ dir_entry = malloc(sizeof(struct directory_name_entry));
556+ dir_entry->dir_name = dir_name;
557+ dir_entry->path = malloc(strlen(dir_name) + 1);
558+ strcpy(dir_entry->path, dir_name);
559+
560+ parent_inum = highest_inum + BTRFS_FIRST_FREE_OBJECTID;
561+ dir_entry->inum = parent_inum;
562+ list_add_tail(&dir_entry->list, &dir_head->list);
563+
564+ btrfs_init_path(&path);
565+
566+ root_dir_key.objectid = btrfs_root_dirid(&root->root_item);
567+ root_dir_key.offset = 0;
568+ btrfs_set_key_type(&root_dir_key, BTRFS_INODE_ITEM_KEY);
569+ ret = btrfs_lookup_inode(trans, root, &path, &root_dir_key, 1);
570+ if (ret) {
571+ fprintf(stderr, "root dir lookup error\n");
572+ goto fail;
573+ }
574+
575+ leaf = path.nodes[0];
576+ inode_item = btrfs_item_ptr(leaf, path.slots[0],
577+ struct btrfs_inode_item);
578+
579+ root_dir_inode_size = calculate_dir_inode_size(dir_name);
580+ btrfs_set_inode_size(leaf, inode_item, root_dir_inode_size);
581+ btrfs_mark_buffer_dirty(leaf);
582+
583+ btrfs_release_path(root, &path);
584+
585+ do {
586+ parent_dir_entry = list_entry(dir_head->list.next,
587+ struct directory_name_entry,
588+ list);
589+ list_del(&parent_dir_entry->list);
590+
591+ parent_inum = parent_dir_entry->inum;
592+ parent_dir_name = parent_dir_entry->dir_name;
593+ if (chdir(parent_dir_entry->path)) {
594+ fprintf(stderr, "chdir error for %s\n",
595+ parent_dir_name);
596+ goto fail;
597+ }
598+
599+ count = scandir(parent_dir_entry->path, &files,
600+ directory_select, NULL);
601+
602+ for (i = 0; i < count; i++) {
603+ cur_file = files[i];
604+
605+ if (lstat(cur_file->d_name, &st) == -1) {
606+ fprintf(stderr, "lstat failed for file %s\n",
607+ cur_file->d_name);
608+ goto fail;
609+ }
610+
611+ cur_inum = ++highest_inum + BTRFS_FIRST_FREE_OBJECTID;
612+ ret = add_directory_items(trans, root,
613+ cur_inum, parent_inum,
614+ cur_file->d_name,
615+ &st, &dir_index_cnt);
616+ if (ret) {
617+ fprintf(stderr, "add_directory_items failed\n");
618+ goto fail;
619+ }
620+
621+ ret = add_inode_items(trans, root, &st,
622+ cur_file->d_name, cur_inum,
623+ parent_inum, dir_index_cnt,
624+ &cur_inode);
625+ if (ret) {
626+ fprintf(stderr, "add_inode_items failed\n");
627+ goto fail;
628+ }
629+
630+ ret = add_xattr_item(trans, root,
631+ cur_inum, cur_file->d_name);
632+ if (ret) {
633+ fprintf(stderr, "add_xattr_item failed\n");
634+ goto fail;
635+ }
636+
637+ if (S_ISDIR(st.st_mode)) {
638+ dir_entry = malloc(sizeof(struct directory_name_entry));
639+ dir_entry->dir_name = cur_file->d_name;
640+ dir_entry->path = make_path(parent_dir_entry->path,
641+ cur_file->d_name);
642+ dir_entry->inum = cur_inum;
643+ list_add_tail(&dir_entry->list, &dir_head->list);
644+ } else if (S_ISREG(st.st_mode)) {
645+ ret = add_file_items(trans, root, &cur_inode,
646+ cur_inum, parent_inum, &st,
647+ cur_file->d_name, out_fd);
648+ if (ret) {
649+ fprintf(stderr, "add_file_items failed\n");
650+ goto fail;
651+ }
652+ } else if (S_ISLNK(st.st_mode)) {
653+ ret = add_symbolic_link(trans, root,
654+ cur_inum, cur_file->d_name);
655+ if (ret) {
656+ fprintf(stderr, "add_symbolic_link failed\n");
657+ goto fail;
658+ }
659+ }
660+ }
661+
662+ free(parent_dir_entry->path);
663+ free(parent_dir_entry);
664+
665+ index_cnt = 2;
666+
667+ } while (!list_empty(&dir_head->list));
668+
669+ return 0;
670+fail:
671+ free(parent_dir_entry->path);
672+ free(parent_dir_entry);
673+ return -1;
674+}
675+
676+static int open_target(char *output_name)
677+{
678+ int output_fd;
679+ output_fd = open(output_name, O_CREAT | O_RDWR | O_TRUNC,
680+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
681+
682+ return output_fd;
683+}
684+
685+static int create_chunks(struct btrfs_trans_handle *trans,
686+ struct btrfs_root *root, u64 num_of_meta_chunks,
687+ u64 size_of_data)
688+{
689+ u64 chunk_start;
690+ u64 chunk_size;
691+ u64 meta_type = BTRFS_BLOCK_GROUP_METADATA;
692+ u64 data_type = BTRFS_BLOCK_GROUP_DATA;
693+ u64 minimum_data_chunk_size = 64 * 1024 * 1024;
694+ u64 i;
695+ int ret;
696+
697+ for (i = 0; i < num_of_meta_chunks; i++) {
698+ ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
699+ &chunk_start, &chunk_size, meta_type);
700+ BUG_ON(ret);
701+ ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
702+ meta_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
703+ chunk_start, chunk_size);
704+ BUG_ON(ret);
705+ set_extent_dirty(&root->fs_info->free_space_cache,
706+ chunk_start, chunk_start + chunk_size - 1, 0);
707+ }
708+
709+ if (size_of_data < minimum_data_chunk_size)
710+ size_of_data = minimum_data_chunk_size;
711+ ret = btrfs_alloc_data_chunk(trans, root->fs_info->extent_root,
712+ &chunk_start, size_of_data, data_type);
713+ BUG_ON(ret);
714+ ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
715+ data_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
716+ chunk_start, size_of_data);
717+ BUG_ON(ret);
718+ set_extent_dirty(&root->fs_info->free_space_cache,
719+ chunk_start, chunk_start + size_of_data - 1, 0);
720+ return ret;
721+}
722+
723+static int make_image(char *source_dir, struct btrfs_root *root, int out_fd)
724+{
725+ int ret;
726+ struct btrfs_trans_handle *trans;
727+
728+ struct stat root_st;
729+ int root_len;
730+
731+ struct directory_name_entry dir_head;
732+
733+ ret = lstat(source_dir, &root_st);
734+ if (ret) {
735+ fprintf(stderr, "unable to lstat the %s\n", source_dir);
736+ goto fail;
737+ }
738+
739+ root_len = strlen(source_dir);
740+
741+ INIT_LIST_HEAD(&dir_head.list);
742+
743+ trans = btrfs_start_transaction(root, 1);
744+ ret = traverse_directory(trans, root, source_dir, &dir_head, out_fd);
745+ if (ret) {
746+ fprintf(stderr, "unable to traverse_directory\n");
747+ goto fail;
748+ }
749+ btrfs_commit_transaction(trans, root);
750+
751+ printf("Making image is completed.\n");
752+ return 0;
753+fail:
754+ fprintf(stderr, "Making image is aborted.\n");
755+ return -1;
756+}
757+
758+static u64 size_sourcedir(char *dir_name, u64 sectorsize,
759+ u64 *num_of_meta_chunks_ret, u64 *size_of_data_ret)
760+{
761+ u64 dir_size = 0;
762+ u64 total_size = 0;
763+ int ret;
764+ char command[1024];
765+ char path[512];
766+ char *file_name = "temp_file";
767+ FILE *file;
768+ u64 minimum_data_size = 256 * 1024 * 1024; /* 256MB */
769+ u64 default_chunk_size = 8 * 1024 * 1024; /* 8MB */
770+ u64 allocated_meta_size = 8 * 1024 * 1024; /* 8MB */
771+ u64 allocated_total_size = 20 * 1024 * 1024; /* 20MB */
772+ u64 num_of_meta_chunks = 0;
773+ u64 num_of_allocated_meta_chunks =
774+ allocated_meta_size / default_chunk_size;
775+
776+ ret = sprintf(command, "du -B 4096 -s ");
777+ if (ret < 0) {
778+ fprintf(stderr, "error executing sprintf for du command\n");
779+ return -1;
780+ }
781+ strcat(command, dir_name);
782+ strcat(command, " > ");
783+ strcat(command, file_name);
784+ ret = system(command);
785+
786+ file = fopen(file_name, "r");
787+ ret = fscanf(file, "%lld %s\n", &dir_size, path);
788+ fclose(file);
789+ remove(file_name);
790+
791+ dir_size *= sectorsize;
792+ *size_of_data_ret = dir_size;
793+
794+ num_of_meta_chunks = (dir_size / 2) / default_chunk_size;
795+ if (((dir_size / 2) % default_chunk_size) != 0)
796+ num_of_meta_chunks++;
797+ if (num_of_meta_chunks <= num_of_allocated_meta_chunks)
798+ num_of_meta_chunks = 0;
799+ else
800+ num_of_meta_chunks -= num_of_allocated_meta_chunks;
801+
802+ total_size = allocated_total_size + dir_size +
803+ (num_of_meta_chunks * default_chunk_size);
804+
805+ *num_of_meta_chunks_ret = num_of_meta_chunks;
806+
807+ if (total_size < minimum_data_size)
808+ total_size = minimum_data_size;
809+
810+ return total_size;
811+}
812+
813+static int zero_output_file(int out_fd, u64 size, u32 sectorsize)
814+{
815+ int len = sectorsize;
816+ int loop_num = size / sectorsize;
817+ u64 location = 0;
818+ char *buf = malloc(len);
819+ int ret = 0, i;
820+ ssize_t written;
821+
822+ if (!buf)
823+ return -ENOMEM;
824+ memset(buf, 0, len);
825+ for (i = 0; i < loop_num; i++) {
826+ written = pwrite64(out_fd, buf, len, location);
827+ if (written != len)
828+ ret = -EIO;
829+ location += sectorsize;
830+ }
831+ free(buf);
832+ return ret;
833+}
834+
835 int main(int ac, char **av)
836 {
837 char *file;
838@@ -385,9 +1156,15 @@ int main(int ac, char **av)
839 int data_profile_opt = 0;
840 int metadata_profile_opt = 0;
841
842+ char *source_dir = NULL;
843+ int source_dir_set = 0;
844+ char *output = "output.img";
845+ u64 num_of_meta_chunks = 0;
846+ u64 size_of_data = 0;
847+
848 while(1) {
849 int c;
850- c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:VM", long_options,
851+ c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:r:VM", long_options,
852 &option_index);
853 if (c < 0)
854 break;
855@@ -430,6 +1207,10 @@ int main(int ac, char **av)
856 case 'V':
857 print_version();
858 break;
859+ case 'r':
860+ source_dir = optarg;
861+ source_dir_set = 1;
862+ break;
863 default:
864 print_usage();
865 }
866@@ -443,6 +1224,8 @@ int main(int ac, char **av)
867 fprintf(stderr, "Illegal nodesize %u\n", nodesize);
868 exit(1);
869 }
870+ if (source_dir_set)
871+ ac++;
872 ac = ac - optind;
873 if (ac == 0)
874 print_usage();
875@@ -450,28 +1233,47 @@ int main(int ac, char **av)
876 printf("\nWARNING! - %s IS EXPERIMENTAL\n", BTRFS_BUILD_VERSION);
877 printf("WARNING! - see http://btrfs.wiki.kernel.org before using\n\n");
878
879- file = av[optind++];
880- ret = check_mounted(file);
881- if (ret < 0) {
882- fprintf(stderr, "error checking %s mount status\n", file);
883- exit(1);
884- }
885- if (ret == 1) {
886- fprintf(stderr, "%s is mounted\n", file);
887- exit(1);
888- }
889- ac--;
890- fd = open(file, O_RDWR);
891- if (fd < 0) {
892- fprintf(stderr, "unable to open %s\n", file);
893- exit(1);
894+ if (source_dir == 0) {
895+ file = av[optind++];
896+ ret = check_mounted(file);
897+ if (ret < 0) {
898+ fprintf(stderr, "error checking %s mount status\n", file);
899+ exit(1);
900+ }
901+ if (ret == 1) {
902+ fprintf(stderr, "%s is mounted\n", file);
903+ exit(1);
904+ }
905+ ac--;
906+ fd = open(file, O_RDWR);
907+ if (fd < 0) {
908+ fprintf(stderr, "unable to open %s\n", file);
909+ exit(1);
910+ }
911+ first_fd = fd;
912+ first_file = file;
913+ ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count, &mixed);
914+ if (block_count == 0)
915+ block_count = dev_block_count;
916+ } else {
917+ ac = 0;
918+ fd = open_target(output);
919+ if (fd < 0) {
920+ fprintf(stderr, "unable to open the %s\n", file);
921+ exit(1);
922+ }
923+
924+ file = output;
925+ first_fd = fd;
926+ first_file = file;
927+ block_count = size_sourcedir(source_dir, sectorsize,
928+ &num_of_meta_chunks, &size_of_data);
929+ ret = zero_output_file(fd, block_count, sectorsize);
930+ if (ret) {
931+ fprintf(stderr, "unable to zero the output file\n");
932+ exit(1);
933+ }
934 }
935- first_fd = fd;
936- first_file = file;
937- ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
938- &mixed);
939- if (block_count == 0)
940- block_count = dev_block_count;
941 if (mixed) {
942 if (!metadata_profile_opt)
943 metadata_profile = 0;
944@@ -558,9 +1360,11 @@ int main(int ac, char **av)
945 }
946
947 raid_groups:
948- ret = create_raid_groups(trans, root, data_profile,
949+ if (!source_dir_set) {
950+ ret = create_raid_groups(trans, root, data_profile,
951 metadata_profile, mixed);
952- BUG_ON(ret);
953+ BUG_ON(ret);
954+ }
955
956 ret = create_data_reloc_tree(trans, root);
957 BUG_ON(ret);
958@@ -580,6 +1384,18 @@ raid_groups:
959
960 printf("%s\n", BTRFS_BUILD_VERSION);
961 btrfs_commit_transaction(trans, root);
962+
963+ if (source_dir_set) {
964+ trans = btrfs_start_transaction(root, 1);
965+ ret = create_chunks(trans, root,
966+ num_of_meta_chunks, size_of_data);
967+ BUG_ON(ret);
968+ btrfs_commit_transaction(trans, root);
969+
970+ ret = make_image(source_dir, root, fd);
971+ BUG_ON(ret);
972+ }
973+
974 ret = close_ctree(root);
975 BUG_ON(ret);
976
977diff --git a/volumes.c b/volumes.c
978index 7671855..4bb77e2 100644
979--- a/volumes.c
980+++ b/volumes.c
981@@ -857,6 +857,110 @@ again:
982 return ret;
983 }
984
985+int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
986+ struct btrfs_root *extent_root, u64 *start,
987+ u64 num_bytes, u64 type)
988+{
989+ u64 dev_offset;
990+ struct btrfs_fs_info *info = extent_root->fs_info;
991+ struct btrfs_root *chunk_root = extent_root->fs_info->chunk_root;
992+ struct btrfs_stripe *stripes;
993+ struct btrfs_device *device = NULL;
994+ struct btrfs_chunk *chunk;
995+ struct list_head *dev_list = &extent_root->fs_info->fs_devices->devices;
996+ struct list_head *cur;
997+ struct map_lookup *map;
998+ u64 physical;
999+ u64 calc_size = 8 * 1024 * 1024;
1000+ int num_stripes = 1;
1001+ int sub_stripes = 0;
1002+ int ret;
1003+ int index;
1004+ int stripe_len = 64 * 1024;
1005+ struct btrfs_key key;
1006+
1007+ key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
1008+ key.type = BTRFS_CHUNK_ITEM_KEY;
1009+ ret = find_next_chunk(chunk_root, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
1010+ &key.offset);
1011+ if (ret)
1012+ return ret;
1013+
1014+ chunk = kmalloc(btrfs_chunk_item_size(num_stripes), GFP_NOFS);
1015+ if (!chunk)
1016+ return -ENOMEM;
1017+
1018+ map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
1019+ if (!map) {
1020+ kfree(chunk);
1021+ return -ENOMEM;
1022+ }
1023+
1024+ stripes = &chunk->stripe;
1025+ calc_size = num_bytes;
1026+
1027+ index = 0;
1028+ cur = dev_list->next;
1029+ device = list_entry(cur, struct btrfs_device, dev_list);
1030+
1031+ while (index < num_stripes) {
1032+ struct btrfs_stripe *stripe;
1033+
1034+ ret = btrfs_alloc_dev_extent(trans, device,
1035+ info->chunk_root->root_key.objectid,
1036+ BTRFS_FIRST_CHUNK_TREE_OBJECTID, key.offset,
1037+ calc_size, &dev_offset);
1038+ BUG_ON(ret);
1039+
1040+ device->bytes_used += calc_size;
1041+ ret = btrfs_update_device(trans, device);
1042+ BUG_ON(ret);
1043+
1044+ map->stripes[index].dev = device;
1045+ map->stripes[index].physical = dev_offset;
1046+ stripe = stripes + index;
1047+ btrfs_set_stack_stripe_devid(stripe, device->devid);
1048+ btrfs_set_stack_stripe_offset(stripe, dev_offset);
1049+ memcpy(stripe->dev_uuid, device->uuid, BTRFS_UUID_SIZE);
1050+ physical = dev_offset;
1051+ index++;
1052+ }
1053+
1054+ /* key was set above */
1055+ btrfs_set_stack_chunk_length(chunk, num_bytes);
1056+ btrfs_set_stack_chunk_owner(chunk, extent_root->root_key.objectid);
1057+ btrfs_set_stack_chunk_stripe_len(chunk, stripe_len);
1058+ btrfs_set_stack_chunk_type(chunk, type);
1059+ btrfs_set_stack_chunk_num_stripes(chunk, num_stripes);
1060+ btrfs_set_stack_chunk_io_align(chunk, stripe_len);
1061+ btrfs_set_stack_chunk_io_width(chunk, stripe_len);
1062+ btrfs_set_stack_chunk_sector_size(chunk, extent_root->sectorsize);
1063+ btrfs_set_stack_chunk_sub_stripes(chunk, sub_stripes);
1064+ map->sector_size = extent_root->sectorsize;
1065+ map->stripe_len = stripe_len;
1066+ map->io_align = stripe_len;
1067+ map->io_width = stripe_len;
1068+ map->type = type;
1069+ map->num_stripes = num_stripes;
1070+ map->sub_stripes = sub_stripes;
1071+
1072+ ret = btrfs_insert_item(trans, chunk_root, &key, chunk,
1073+ btrfs_chunk_item_size(num_stripes));
1074+ BUG_ON(ret);
1075+ *start = key.offset;
1076+
1077+ map->ce.start = key.offset;
1078+ map->ce.size = num_bytes;
1079+
1080+ ret = insert_existing_cache_extent(
1081+ &extent_root->fs_info->mapping_tree.cache_tree,
1082+ &map->ce);
1083+ BUG_ON(ret);
1084+
1085+ kfree(chunk);
1086+ return ret;
1087+}
1088+
1089 void btrfs_mapping_init(struct btrfs_mapping_tree *tree)
1090 {
1091 cache_tree_init(&tree->cache_tree);
1092diff --git a/volumes.h b/volumes.h
1093index bb78751..93b0e48 100644
1094--- a/volumes.h
1095+++ b/volumes.h
1096@@ -107,6 +107,9 @@ int btrfs_read_chunk_tree(struct btrfs_root *root);
1097 int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
1098 struct btrfs_root *extent_root, u64 *start,
1099 u64 *num_bytes, u64 type);
1100+int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
1101+ struct btrfs_root *extent_root, u64 *start,
1102+ u64 num_bytes, u64 type);
1103 int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf);
1104 int btrfs_add_device(struct btrfs_trans_handle *trans,
1105 struct btrfs_root *root,
1106--
11071.7.2.3
1108
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0014-btrfs-progs-fix-wrong-extent-buffer-size-when-readin.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0014-btrfs-progs-fix-wrong-extent-buffer-size-when-readin.patch
new file mode 100644
index 0000000000..6a0f9d6952
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0014-btrfs-progs-fix-wrong-extent-buffer-size-when-readin.patch
@@ -0,0 +1,33 @@
1Upstream-Status: Inappropriate [Backport]
2From 32ba8209276d3ac1723ea6373aaec9d6399ce5ca Mon Sep 17 00:00:00 2001
3From: Miao Xie <miaox@cn.fujitsu.com>
4Date: Tue, 13 Jul 2010 09:18:04 +0000
5Subject: [PATCH 14/15] btrfs-progs: fix wrong extent buffer size when reading tree block
6
7the root extent buffer of a tree may not be a leaf, so we must get the right
8size by its level when reading it.
9
10Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
11Signed-off-by: Chris Mason <chris.mason@oracle.com>
12---
13 debug-tree.c | 4 +++-
14 1 files changed, 3 insertions(+), 1 deletions(-)
15
16diff --git a/debug-tree.c b/debug-tree.c
17index 0525354..99c12d6 100644
18--- a/debug-tree.c
19+++ b/debug-tree.c
20@@ -212,7 +212,9 @@ again:
21 read_extent_buffer(leaf, &ri, offset, sizeof(ri));
22 buf = read_tree_block(tree_root_scan,
23 btrfs_root_bytenr(&ri),
24- tree_root_scan->leafsize, 0);
25+ btrfs_level_size(tree_root_scan,
26+ btrfs_root_level(&ri)),
27+ 0);
28 switch(found_key.objectid) {
29 case BTRFS_ROOT_TREE_OBJECTID:
30 if (!skip)
31--
321.7.2.3
33
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0015-btrfs-progs-add-discard-support-to-mkfs.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0015-btrfs-progs-add-discard-support-to-mkfs.patch
new file mode 100644
index 0000000000..7a93b5314f
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0015-btrfs-progs-add-discard-support-to-mkfs.patch
@@ -0,0 +1,110 @@
1Upstream-Status: Inappropriate [Backport]
2From e6bd18d8938986c997c45f0ea95b221d4edec095 Mon Sep 17 00:00:00 2001
3From: Christoph Hellwig <hch@lst.de>
4Date: Thu, 21 Apr 2011 16:24:07 -0400
5Subject: [PATCH 15/15] btrfs-progs: add discard support to mkfs
6
7Discard the whole device before starting to create the filesystem structures.
8Modelled after similar support in mkfs.xfs.
9
10Signed-off-by: Christoph Hellwig <hch@lst.de>
11Signed-off-by: Chris Mason <chris.mason@oracle.com>
12---
13 btrfs_cmds.c | 21 +++++++++++++++++----
14 utils.c | 21 +++++++++++++++++++++
15 2 files changed, 38 insertions(+), 4 deletions(-)
16
17diff --git a/btrfs_cmds.c b/btrfs_cmds.c
18index 6de73f4..32f6b25 100644
19--- a/btrfs_cmds.c
20+++ b/btrfs_cmds.c
21@@ -732,13 +732,26 @@ int do_add_volume(int nargs, char **args)
22 return 12;
23 }
24
25- for(i=1 ; i < (nargs-1) ; i++ ){
26+ for (i = 1; i < (nargs-1); i++ ){
27 struct btrfs_ioctl_vol_args ioctl_args;
28 int devfd, res;
29 u64 dev_block_count = 0;
30 struct stat st;
31 int mixed = 0;
32
33+ res = check_mounted(args[i]);
34+ if (res < 0) {
35+ fprintf(stderr, "error checking %s mount status\n",
36+ args[i]);
37+ ret++;
38+ continue;
39+ }
40+ if (res == 1) {
41+ fprintf(stderr, "%s is mounted\n", args[i]);
42+ ret++;
43+ continue;
44+ }
45+
46 devfd = open(args[i], O_RDWR);
47 if (!devfd) {
48 fprintf(stderr, "ERROR: Unable to open device '%s'\n", args[i]);
49@@ -746,8 +759,8 @@ int do_add_volume(int nargs, char **args)
50 ret++;
51 continue;
52 }
53- ret = fstat(devfd, &st);
54- if (ret) {
55+ res = fstat(devfd, &st);
56+ if (res) {
57 fprintf(stderr, "ERROR: Unable to stat '%s'\n", args[i]);
58 close(devfd);
59 ret++;
60@@ -781,7 +794,7 @@ int do_add_volume(int nargs, char **args)
61 }
62
63 close(fdmnt);
64- if( ret)
65+ if (ret)
66 return ret+20;
67 else
68 return 0;
69diff --git a/utils.c b/utils.c
70index 13373c9..17e5afe 100644
71--- a/utils.c
72+++ b/utils.c
73@@ -50,6 +50,20 @@
74 static inline int ioctl(int fd, int define, u64 *size) { return 0; }
75 #endif
76
77+#ifndef BLKDISCARD
78+#define BLKDISCARD _IO(0x12,119)
79+#endif
80+
81+static int
82+discard_blocks(int fd, u64 start, u64 len)
83+{
84+ u64 range[2] = { start, len };
85+
86+ if (ioctl(fd, BLKDISCARD, &range) < 0)
87+ return errno;
88+ return 0;
89+}
90+
91 static u64 reference_root_table[] = {
92 [1] = BTRFS_ROOT_TREE_OBJECTID,
93 [2] = BTRFS_EXTENT_TREE_OBJECTID,
94@@ -537,6 +551,13 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
95 printf("SMALL VOLUME: forcing mixed metadata/data groups\n");
96 *mixed = 1;
97 }
98+
99+ /*
100+ * We intentionally ignore errors from the discard ioctl. It is
101+ * not necessary for the mkfs functionality but just an optimization.
102+ */
103+ discard_blocks(fd, 0, block_count);
104+
105 ret = zero_dev_start(fd);
106 if (ret) {
107 fprintf(stderr, "failed to zero device start %d\n", ret);
108--
1091.7.2.3
110
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools_git.bb b/meta/recipes-devtools/btrfs-tools/btrfs-tools_git.bb
new file mode 100644
index 0000000000..312dff30f3
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools_git.bb
@@ -0,0 +1,52 @@
1SUMMARY = "Checksumming Copy on Write Filesystem utilities"
2DESCRIPTION = "Btrfs is a new copy on write filesystem for Linux aimed at \
3implementing advanced features while focusing on fault tolerance, repair and \
4easy administration. \
5This package contains utilities (mkfs, fsck, btrfsctl) used to work with \
6btrfs and an utility (btrfs-convert) to make a btrfs filesystem from an ext3."
7
8HOMEPAGE = "https://btrfs.wiki.kernel.org"
9
10LICENSE = "GPLv2"
11LIC_FILES_CHKSUM = "file://COPYING;md5=fcb02dc552a041dee27e4b85c7396067"
12SECTION = "base"
13
14SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs-unstable.git;protocol=git;tag=1b444cd2e6ab8dcafdd47dbaeaae369dd1517c17;branch=master"
15
16S = "${WORKDIR}/git"
17
18PR = "r0"
19
20SRC_URI += "file://upstream-tmp/0001-Btrfs-progs-add-a-btrfs-select-super-command-to-over.patch \
21 file://upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch \
22 file://upstream-tmp/0003-Btrfs-progs-utils-Informative-errors.patch \
23 file://upstream-tmp/0004-update-man-page-to-new-defragment-command-interface.patch \
24 file://upstream-tmp/0005-Improve-error-handling-in-the-btrfs-command.patch \
25 file://upstream-tmp/0006-Btrfs-progs-update-super-fields-for-space-cache.patch \
26 file://upstream-tmp/0007-Btrfs-progs-add-support-for-mixed-data-metadata-bloc.patch \
27 file://upstream-tmp/0008-Update-for-lzo-support.patch \
28 file://upstream-tmp/0009-Update-clean-up-btrfs-help-and-man-page-V2.patch \
29 file://upstream-tmp/0010-Deprecate-btrfsctl-btrfs-show-btrfs-vol.patch \
30 file://upstream-tmp/0011-Add-the-btrfs-filesystem-label-command.patch \
31 file://upstream-tmp/0012-Btrfs-progs-Update-man-page-for-mixed-data-metadata-.patch \
32 file://upstream-tmp/0013-btrfs-progs-Add-new-feature-to-mkfs.btrfs-to-make-fi.patch \
33 file://upstream-tmp/0014-btrfs-progs-fix-wrong-extent-buffer-size-when-readin.patch \
34 file://upstream-tmp/0015-btrfs-progs-add-discard-support-to-mkfs.patch \
35 file://upstream-for-dragonn/0001-Fill-missing-devices-so-degraded-filesystems-can-be-.patch \
36 file://upstream-for-dragonn/0002-Check-for-RAID10-in-set_avail_alloc_bits.patch \
37 file://upstream-for-dragonn/0003-Print-the-root-generation-in-btrfs-debug-tree.patch \
38 file://upstream-for-dragonn/0004-Allow-partial-FS-opens-for-btrfsck-scanning.patch \
39 file://mkfs-xin-fixes.patch \
40 file://debian/01-labels.patch \
41 file://debian/02-ftbfs.patch \
42 file://fix_use_of_gcc.patch \
43 "
44
45SRC_URI[md5sum] = "78b1700d318de8518abfaab71f99a885"
46SRC_URI[sha256sum] = "1285774e0cb72984fac158dd046c8d405324754febd30320cd31e459253e4b65"
47
48do_install () {
49 oe_runmake 'DESTDIR=${D}' install
50}
51
52BBCLASSEXTEND = "native"