A little more cleanup.
[rsync/rsync-patches.git] / fsync.diff
... / ...
CommitLineData
1This patch from Sami Farin lets you specify --fsync if you want fsync()
2to be called on every file we write.
3
4To use this patch, run these commands for a successful build:
5
6 patch -p1 <patches/fsync.diff
7 ./configure (optional if already run)
8 make
9
10--- old/options.c
11+++ new/options.c
12@@ -45,6 +45,7 @@ int append_mode = 0;
13 int keep_dirlinks = 0;
14 int copy_dirlinks = 0;
15 int copy_links = 0;
16+int do_fsync = 0;
17 int preserve_links = 0;
18 int preserve_hard_links = 0;
19 int preserve_acls = 0;
20@@ -375,6 +376,7 @@ void usage(enum logcode F)
21 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
22 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
23 rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
24+ rprintf(F," --fsync fsync every written file\n");
25 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
26 rprintf(F," --timeout=TIME set I/O timeout in seconds\n");
27 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
28@@ -600,6 +602,7 @@ static struct poptOption long_options[]
29 {"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
30 {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
31 {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
32+ {"fsync", 0, POPT_ARG_NONE, &do_fsync, 0, 0, 0 },
33 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
34 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
35 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
36@@ -1934,6 +1937,9 @@ void server_options(char **args, int *ar
37 args[ac++] = tmpdir;
38 }
39
40+ if (do_fsync)
41+ args[ac++] = "--fsync";
42+
43 if (basis_dir[0]) {
44 /* the server only needs this option if it is not the sender,
45 * and it may be an older version that doesn't know this
46--- old/receiver.c
47+++ new/receiver.c
48@@ -39,6 +39,7 @@ extern int relative_paths;
49 extern int preserve_hard_links;
50 extern int preserve_perms;
51 extern int preserve_xattrs;
52+extern int do_fsync;
53 extern int basis_dir_cnt;
54 extern int make_backups;
55 extern int cleanup_got_literal;
56@@ -261,6 +262,12 @@ static int receive_data(int f_in, char *
57 exit_cleanup(RERR_FILEIO);
58 }
59
60+ if (do_fsync && fd != -1 && fsync(fd) != 0) {
61+ rsyserr(FERROR, errno, "fsync failed on %s",
62+ full_fname(fname));
63+ exit_cleanup(RERR_FILEIO);
64+ }
65+
66 sum_len = sum_end(file_sum1);
67
68 if (mapbuf)
69--- old/t_stub.c
70+++ new/t_stub.c
71@@ -21,6 +21,7 @@
72
73 #include "rsync.h"
74
75+int do_fsync = 0;
76 int modify_window = 0;
77 int module_id = -1;
78 int relative_paths = 0;
79--- old/util.c
80+++ new/util.c
81@@ -25,6 +25,7 @@
82 extern int verbose;
83 extern int dry_run;
84 extern int module_id;
85+extern int do_fsync;
86 extern int modify_window;
87 extern int relative_paths;
88 extern int human_readable;
89@@ -310,6 +311,13 @@ int copy_file(const char *source, const
90 full_fname(source));
91 }
92
93+ if (do_fsync && fsync(ofd) < 0) {
94+ rsyserr(FERROR, errno, "fsync failed on %s",
95+ full_fname(dest));
96+ close(ofd);
97+ return -1;
98+ }
99+
100 if (close(ofd) < 0) {
101 rsyserr(FERROR, errno, "close failed on %s",
102 full_fname(dest));