diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2013-07-18 17:51:29 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-26 11:47:18 +0100 |
commit | a758b9302145d0a5b8f6b0e7d276b521ccd49061 (patch) | |
tree | a766cda30db56ac9dd0cc6989d3658fb25b6d175 /meta/recipes-devtools | |
parent | f1e6091a1b20f66ede7098e54a2974232943c1c7 (diff) | |
download | poky-a758b9302145d0a5b8f6b0e7d276b521ccd49061.tar.gz |
e2fsprogs: let debugfs do sparse copy
Let debugfs do sparse copy when src is a sparse file, just like
"cp --sparse=auto"
This patch has been reviewed by the linux-ext4 mailing list, but isn't
merged atm.
[YOCTO #3848]
(From OE-Core rev: 723adaf8fbba61b7f1adc8e4a13ddf1cfb5c0bcf)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools')
-rw-r--r-- | meta/recipes-devtools/e2fsprogs/e2fsprogs-1.42.8/debugfs-sparse-copy.patch | 148 | ||||
-rw-r--r-- | meta/recipes-devtools/e2fsprogs/e2fsprogs_1.42.8.bb | 1 |
2 files changed, 149 insertions, 0 deletions
diff --git a/meta/recipes-devtools/e2fsprogs/e2fsprogs-1.42.8/debugfs-sparse-copy.patch b/meta/recipes-devtools/e2fsprogs/e2fsprogs-1.42.8/debugfs-sparse-copy.patch new file mode 100644 index 0000000000..07124702a3 --- /dev/null +++ b/meta/recipes-devtools/e2fsprogs/e2fsprogs-1.42.8/debugfs-sparse-copy.patch | |||
@@ -0,0 +1,148 @@ | |||
1 | debugfs.c: do sparse copy when src is a sparse file | ||
2 | |||
3 | Let debugfs do sparse copy when src is a sparse file, just like | ||
4 | "cp --sparse=auto" | ||
5 | |||
6 | * For the: | ||
7 | #define IO_BUFSIZE 64*1024 | ||
8 | this is a suggested value from gnu coreutils: | ||
9 | http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/ioblksize.h;h=1ae93255e7d0ccf0855208c7ae5888209997bf16;hb=HEAD | ||
10 | |||
11 | * Use malloc() to allocate memory for the buffer since put 64K (or | ||
12 | more) on the stack seems not a good idea. | ||
13 | |||
14 | Upstream-Status: Submitted | ||
15 | |||
16 | Signed-off-by: Robert Yang <liezhi.yang@windriver.com> | ||
17 | Acked-by: Darren Hart <dvhart@linux.intel.com> | ||
18 | --- | ||
19 | debugfs/debugfs.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++---- | ||
20 | 1 file changed, 58 insertions(+), 4 deletions(-) | ||
21 | |||
22 | diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c | ||
23 | --- a/debugfs/debugfs.c | ||
24 | +++ b/debugfs/debugfs.c | ||
25 | @@ -41,6 +41,16 @@ extern char *optarg; | ||
26 | #define BUFSIZ 8192 | ||
27 | #endif | ||
28 | |||
29 | +/* 64KiB is the minimium blksize to best minimize system call overhead. */ | ||
30 | +#ifndef IO_BUFSIZE | ||
31 | +#define IO_BUFSIZE 64*1024 | ||
32 | +#endif | ||
33 | + | ||
34 | +/* Block size for `st_blocks' */ | ||
35 | +#ifndef S_BLKSIZE | ||
36 | +#define S_BLKSIZE 512 | ||
37 | +#endif | ||
38 | + | ||
39 | ss_request_table *extra_cmds; | ||
40 | const char *debug_prog_name; | ||
41 | int sci_idx; | ||
42 | @@ -1563,22 +1573,37 @@ void do_find_free_inode(int argc, char *argv[]) | ||
43 | } | ||
44 | |||
45 | #ifndef READ_ONLY | ||
46 | -static errcode_t copy_file(int fd, ext2_ino_t newfile) | ||
47 | +static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_holes) | ||
48 | { | ||
49 | ext2_file_t e2_file; | ||
50 | errcode_t retval; | ||
51 | int got; | ||
52 | unsigned int written; | ||
53 | - char buf[8192]; | ||
54 | + char *buf; | ||
55 | char *ptr; | ||
56 | + char *zero_buf; | ||
57 | + int cmp; | ||
58 | |||
59 | retval = ext2fs_file_open(current_fs, newfile, | ||
60 | EXT2_FILE_WRITE, &e2_file); | ||
61 | if (retval) | ||
62 | return retval; | ||
63 | |||
64 | + if (!(buf = (char *) malloc(bufsize))){ | ||
65 | + com_err("copy_file", errno, "can't allocate buffer\n"); | ||
66 | + return; | ||
67 | + } | ||
68 | + | ||
69 | + /* This is used for checking whether the whole block is zero */ | ||
70 | + retval = ext2fs_get_memzero(bufsize, &zero_buf); | ||
71 | + if (retval) { | ||
72 | + com_err("copy_file", retval, "can't allocate buffer\n"); | ||
73 | + free(buf); | ||
74 | + return retval; | ||
75 | + } | ||
76 | + | ||
77 | while (1) { | ||
78 | - got = read(fd, buf, sizeof(buf)); | ||
79 | + got = read(fd, buf, bufsize); | ||
80 | if (got == 0) | ||
81 | break; | ||
82 | if (got < 0) { | ||
83 | @@ -1586,6 +1611,21 @@ static errcode_t copy_file(int fd, ext2_ino_t newfile) | ||
84 | goto fail; | ||
85 | } | ||
86 | ptr = buf; | ||
87 | + | ||
88 | + /* Sparse copy */ | ||
89 | + if (make_holes) { | ||
90 | + /* Check whether all is zero */ | ||
91 | + cmp = memcmp(ptr, zero_buf, got); | ||
92 | + if (cmp == 0) { | ||
93 | + /* The whole block is zero, make a hole */ | ||
94 | + retval = ext2fs_file_lseek(e2_file, got, EXT2_SEEK_CUR, NULL); | ||
95 | + if (retval) | ||
96 | + goto fail; | ||
97 | + got = 0; | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + /* Normal copy */ | ||
102 | while (got > 0) { | ||
103 | retval = ext2fs_file_write(e2_file, ptr, | ||
104 | got, &written); | ||
105 | @@ -1596,10 +1636,14 @@ static errcode_t copy_file(int fd, ext2_ino_t newfile) | ||
106 | ptr += written; | ||
107 | } | ||
108 | } | ||
109 | + free(buf); | ||
110 | + ext2fs_free_mem(&zero_buf); | ||
111 | retval = ext2fs_file_close(e2_file); | ||
112 | return retval; | ||
113 | |||
114 | fail: | ||
115 | + free(buf); | ||
116 | + ext2fs_free_mem(&zero_buf); | ||
117 | (void) ext2fs_file_close(e2_file); | ||
118 | return retval; | ||
119 | } | ||
120 | @@ -1612,6 +1656,8 @@ void do_write(int argc, char *argv[]) | ||
121 | ext2_ino_t newfile; | ||
122 | errcode_t retval; | ||
123 | struct ext2_inode inode; | ||
124 | + int bufsize = IO_BUFSIZE; | ||
125 | + int make_holes = 0; | ||
126 | |||
127 | if (common_args_process(argc, argv, 3, 3, "write", | ||
128 | "<native file> <new file>", CHECK_FS_RW)) | ||
129 | @@ -1687,7 +1733,15 @@ void do_write(int argc, char *argv[]) | ||
130 | return; | ||
131 | } | ||
132 | if (LINUX_S_ISREG(inode.i_mode)) { | ||
133 | - retval = copy_file(fd, newfile); | ||
134 | + if (statbuf.st_blocks < statbuf.st_size / S_BLKSIZE) { | ||
135 | + make_holes = 1; | ||
136 | + /* | ||
137 | + * Use I/O blocksize as buffer size when | ||
138 | + * copying sparse files. | ||
139 | + */ | ||
140 | + bufsize = statbuf.st_blksize; | ||
141 | + } | ||
142 | + retval = copy_file(fd, newfile, bufsize, make_holes); | ||
143 | if (retval) | ||
144 | com_err("copy_file", retval, 0); | ||
145 | } | ||
146 | -- | ||
147 | 1.7.10.4 | ||
148 | |||
diff --git a/meta/recipes-devtools/e2fsprogs/e2fsprogs_1.42.8.bb b/meta/recipes-devtools/e2fsprogs/e2fsprogs_1.42.8.bb index 319728ee57..22618e63fb 100644 --- a/meta/recipes-devtools/e2fsprogs/e2fsprogs_1.42.8.bb +++ b/meta/recipes-devtools/e2fsprogs/e2fsprogs_1.42.8.bb | |||
@@ -4,6 +4,7 @@ require e2fsprogs.inc | |||
4 | SRC_URI += "file://acinclude.m4 \ | 4 | SRC_URI += "file://acinclude.m4 \ |
5 | file://remove.ldconfig.call.patch \ | 5 | file://remove.ldconfig.call.patch \ |
6 | file://debugfs-too-short.patch \ | 6 | file://debugfs-too-short.patch \ |
7 | file://debugfs-sparse-copy.patch \ | ||
7 | " | 8 | " |
8 | 9 | ||
9 | SRC_URI[md5sum] = "8ef664b6eb698aa6b733df59b17b9ed4" | 10 | SRC_URI[md5sum] = "8ef664b6eb698aa6b733df59b17b9ed4" |