Commit | Line | Data |
---|---|---|
edd5f785 WD |
1 | This patch from Sami Farin lets you specify --fsync if you want fsync() |
2 | to be called on every file we write. | |
3 | ||
03019e41 WD |
4 | To 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 | ||
9a7eef96 WD |
10 | --- old/options.c |
11 | +++ new/options.c | |
7cf8a551 | 12 | @@ -45,6 +45,7 @@ int append_mode = 0; |
125d7fca | 13 | int keep_dirlinks = 0; |
d42637db | 14 | int copy_dirlinks = 0; |
edd5f785 | 15 | int copy_links = 0; |
994f69cd WD |
16 | +int do_fsync = 0; |
17 | int preserve_links = 0; | |
18 | int preserve_hard_links = 0; | |
19 | int preserve_perms = 0; | |
03019e41 | 20 | @@ -339,6 +340,7 @@ void usage(enum logcode F) |
a7219d20 WD |
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"); | |
4a65fe72 | 23 | rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n"); |
edd5f785 | 24 | + rprintf(F," --fsync fsync every written file\n"); |
a7219d20 WD |
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"); | |
03019e41 | 28 | @@ -525,6 +527,7 @@ static struct poptOption long_options[] |
489b0a72 WD |
29 | {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 }, |
30 | {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 }, | |
31 | {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0}, | |
edd5f785 | 32 | + {"fsync", 0, POPT_ARG_NONE, &do_fsync, 0, 0, 0 }, |
489b0a72 WD |
33 | {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 }, |
34 | {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 }, | |
35 | {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 }, | |
03019e41 | 36 | @@ -1727,6 +1730,9 @@ void server_options(char **args,int *arg |
edd5f785 WD |
37 | args[ac++] = tmpdir; |
38 | } | |
7b675ff5 | 39 | |
edd5f785 WD |
40 | + if (do_fsync && am_sender) |
41 | + args[ac++] = "--fsync"; | |
7b675ff5 | 42 | + |
0808daa5 | 43 | if (basis_dir[0] && am_sender) { |
edd5f785 | 44 | /* the server only needs this option if it is not the sender, |
7b675ff5 | 45 | * and it may be an older version that doesn't know this |
9a7eef96 WD |
46 | --- old/receiver.c |
47 | +++ new/receiver.c | |
03019e41 | 48 | @@ -37,6 +37,7 @@ extern int protocol_version; |
d42637db | 49 | extern int relative_paths; |
b76d92e6 | 50 | extern int preserve_hard_links; |
f6c3b300 | 51 | extern int preserve_perms; |
edd5f785 | 52 | +extern int do_fsync; |
1d15f8d9 WD |
53 | extern int basis_dir_cnt; |
54 | extern int make_backups; | |
55 | extern int cleanup_got_literal; | |
03019e41 | 56 | @@ -258,6 +259,12 @@ static int receive_data(int f_in, char * |
7b675ff5 WD |
57 | exit_cleanup(RERR_FILEIO); |
58 | } | |
edd5f785 | 59 | |
67c08134 | 60 | + if (do_fsync && fd != -1 && fsync(fd) != 0) { |
7b675ff5 | 61 | + rsyserr(FERROR, errno, "fsync failed on %s", |
fe6407b5 | 62 | + full_fname(fname)); |
edd5f785 WD |
63 | + exit_cleanup(RERR_FILEIO); |
64 | + } | |
65 | + | |
7b675ff5 | 66 | sum_end(file_sum1); |
edd5f785 | 67 | |
dc3ae351 | 68 | if (mapbuf) |
9a7eef96 WD |
69 | --- old/t_stub.c |
70 | +++ new/t_stub.c | |
7cf8a551 WD |
71 | @@ -22,6 +22,7 @@ |
72 | ||
73 | #include "rsync.h" | |
d9a67109 WD |
74 | |
75 | +int do_fsync = 0; | |
76 | int modify_window = 0; | |
01c39596 | 77 | int module_id = -1; |
56208f7b | 78 | int relative_paths = 0; |
9a7eef96 WD |
79 | --- old/util.c |
80 | +++ new/util.c | |
7cf8a551 | 81 | @@ -26,6 +26,7 @@ |
91f798a7 WD |
82 | extern int verbose; |
83 | extern int dry_run; | |
56208f7b | 84 | extern int module_id; |
91f798a7 | 85 | +extern int do_fsync; |
7b675ff5 | 86 | extern int modify_window; |
56208f7b | 87 | extern int relative_paths; |
91f798a7 | 88 | extern int human_readable; |
03019e41 | 89 | @@ -314,6 +315,12 @@ int copy_file(const char *source, const |
7b675ff5 WD |
90 | return -1; |
91 | } | |
edd5f785 | 92 | |
7b675ff5 WD |
93 | + if (do_fsync && fsync(ofd) < 0) { |
94 | + rsyserr(FERROR, errno, "fsync failed on %s", | |
fe6407b5 | 95 | + full_fname(dest)); |
edd5f785 WD |
96 | + return -1; |
97 | + } | |
98 | + | |
7b675ff5 WD |
99 | return 0; |
100 | } | |
101 |