Updated patches to work with the current trunk.
[rsync/rsync-patches.git] / sparse-block.diff
CommitLineData
c0c7984e
WD
1This patch adds the --sparse-block option. Andrea Righi writes:
2
3 In some filesystems, typically optimized for large I/O throughputs (like
4 IBM GPFS, IBM SAN FS, or distributed filesystems in general) a lot of
5 lseek() operations can strongly impact on performances. In this cases it
6 can be helpful to enlarge the block size used to handle sparse files
7 directly from a command line parameter.
8
9 For example, using a sparse write size of 32KB, I've been able to
10 increase the transfer rate of an order of magnitude copying the output
11 files of scientific applications from GPFS to GPFS or GPFS to SAN FS.
12
13 -Andrea
14
15To use this patch, run these commands for a successful build:
16
17 patch -p1 <patches/sparse-block.diff
18 ./configure (optional if already run)
19 make
20
21diff --git a/fileio.c b/fileio.c
fc557362 22index 0faa619..b76dc02 100644
c0c7984e
WD
23--- a/fileio.c
24+++ b/fileio.c
fc557362 25@@ -27,6 +27,7 @@
c0c7984e
WD
26 #endif
27
28 extern int sparse_files;
fc557362 29+extern int sparse_files_block_size;
c0c7984e
WD
30
31 static char last_byte;
abd3adb8 32 static OFF_T sparse_seek = 0;
fc557362 33@@ -116,7 +117,7 @@ int write_file(int f, char *buf, int len)
c0c7984e
WD
34 while (len > 0) {
35 int r1;
36 if (sparse_files > 0) {
37- int len1 = MIN(len, SPARSE_WRITE_SIZE);
fc557362 38+ int len1 = MIN(len, sparse_files_block_size);
c0c7984e
WD
39 r1 = write_sparse(f, buf, len1);
40 } else {
41 if (!wf_writeBuf) {
42diff --git a/options.c b/options.c
fc557362 43index e7c6c61..a0fb2e7 100644
c0c7984e
WD
44--- a/options.c
45+++ b/options.c
46@@ -73,6 +73,7 @@ int remove_source_files = 0;
47 int one_file_system = 0;
48 int protocol_version = PROTOCOL_VERSION;
49 int sparse_files = 0;
50+long sparse_files_block_size = SPARSE_WRITE_SIZE;
51 int do_compression = 0;
52 int def_compress_level = Z_DEFAULT_COMPRESSION;
53 int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */
fc557362 54@@ -703,6 +704,7 @@ void usage(enum logcode F)
c0c7984e
WD
55 rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
56 #endif
57 rprintf(F," -S, --sparse handle sparse files efficiently\n");
58+ rprintf(F," --sparse-block=SIZE set the block size used to handle sparse files\n");
59 rprintf(F," -n, --dry-run perform a trial run with no changes made\n");
60 rprintf(F," -W, --whole-file copy files whole (without delta-xfer algorithm)\n");
61 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
fc557362 62@@ -899,6 +901,7 @@ static struct poptOption long_options[] = {
c0c7984e
WD
63 {"sparse", 'S', POPT_ARG_VAL, &sparse_files, 1, 0, 0 },
64 {"no-sparse", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 },
65 {"no-S", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 },
66+ {"sparse-block", 0, POPT_ARG_LONG, &sparse_files_block_size, 0, 0, 0 },
67 {"inplace", 0, POPT_ARG_VAL, &inplace, 1, 0, 0 },
68 {"no-inplace", 0, POPT_ARG_VAL, &inplace, 0, 0, 0 },
69 {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 },
fc557362 70@@ -2416,6 +2419,12 @@ void server_options(char **args, int *argc_p)
c0c7984e
WD
71 args[ac++] = arg;
72 }
73
74+ if (sparse_files_block_size) {
75+ if (asprintf(&arg, "--sparse-block=%lu", sparse_files_block_size) < 0)
76+ goto oom;
77+ args[ac++] = arg;
78+ }
79+
80 if (io_timeout) {
81 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
82 goto oom;
83diff --git a/rsync.yo b/rsync.yo
fc557362 84index 941f7a5..5fa8396 100644
c0c7984e
WD
85--- a/rsync.yo
86+++ b/rsync.yo
fc557362 87@@ -359,6 +359,7 @@ to the detailed description below for a complete description. verb(
c0c7984e
WD
88 --super receiver attempts super-user activities
89 --fake-super store/recover privileged attrs using xattrs
90 -S, --sparse handle sparse files efficiently
91+ --sparse-block=SIZE set block size used to handle sparse files
92 -n, --dry-run perform a trial run with no changes made
93 -W, --whole-file copy files whole (w/o delta-xfer algorithm)
94 -x, --one-file-system don't cross filesystem boundaries
fc557362 95@@ -1120,6 +1121,15 @@ NOTE: Don't use this option when the destination is a Solaris "tmpfs"
c0c7984e
WD
96 filesystem. It doesn't seem to handle seeks over null regions
97 correctly and ends up corrupting the files.
98
99+dit(bf(--sparse-block=SIZE)) Change the block size used to handle sparse files
100+to SIZE bytes. This option only has an effect if the bf(--sparse) (bf(-S))
101+option was also specified. The default block size used by rsync to detect a
102+file hole is 1024 bytes; when the receiver writes data to the destination file
103+and option bf(--sparse) is used, rsync checks every 1024-bytes chunk to detect
104+if they are actually filled with data or not. With certain filesystems,
105+optimized to receive data streams for example, enlarging this block size can
106+strongly increase performance. The option can be used to tune this block size.
107+
108 dit(bf(-n, --dry-run)) This makes rsync perform a trial run that doesn't
109 make any changes (and produces mostly the same output as a real run). It
110 is most commonly used in combination with the bf(-v, --verbose) and/or