The --fsync option from Sami Farin.
[rsync/rsync-patches.git] / fsync.diff
CommitLineData
edd5f785
WD
1This patch from Sami Farin lets you specify --fsync if you want fsync()
2to be called on every file we write.
3
4--- options.c 17 Apr 2004 17:07:23 -0000 1.147
5+++ options.c 27 Apr 2004 20:05:03 -0000
6@@ -37,6 +37,7 @@ int make_backups = 0;
7 **/
8 int whole_file = -1;
9
10+int do_fsync = 0;
11 int archive_mode = 0;
12 int copy_links = 0;
13 int preserve_links = 0;
14@@ -230,6 +231,7 @@ void usage(enum logcode F)
15 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
16 rprintf(F," --backup-dir make backups into this directory\n");
17 rprintf(F," --suffix=SUFFIX backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
18+ rprintf(F," --fsync fsync every written file\n");
19 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
20 rprintf(F," -l, --links copy symlinks as symlinks\n");
21 rprintf(F," -L, --copy-links copy the referent of all symlinks\n");
22@@ -332,6 +334,7 @@ static struct poptOption long_options[]
23 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
24 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
25 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
26+ {"fsync", 0, POPT_ARG_NONE, &do_fsync, 0, 0, 0 },
27 {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
28 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
29 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
30@@ -943,6 +946,9 @@ void server_options(char **args,int *arg
31 args[ac++] = "--temp-dir";
32 args[ac++] = tmpdir;
33 }
34+
35+ if (do_fsync && am_sender)
36+ args[ac++] = "--fsync";
37
38 if (compare_dest && am_sender) {
39 /* the server only needs this option if it is not the sender,
40--- receiver.c 27 Apr 2004 19:51:33 -0000 1.76
41+++ receiver.c 27 Apr 2004 20:05:03 -0000
42@@ -45,6 +45,7 @@ extern int cleanup_got_literal;
43 extern int module_id;
44 extern int ignore_errors;
45 extern int orig_umask;
46+extern int do_fsync;
47
48 static void delete_one(char *fn, int is_dir)
49 {
50@@ -264,6 +265,12 @@ static int receive_data(int f_in,struct
51
52 if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
53 rprintf(FERROR, "write failed on %s: %s\n",
54+ full_fname(fname), strerror(errno));
55+ exit_cleanup(RERR_FILEIO);
56+ }
57+
58+ if (do_fsync && (fd != -1) && (fsync(fd) != 0)) {
59+ rprintf(FERROR, "fsync failed on %s: %s\n",
60 full_fname(fname), strerror(errno));
61 exit_cleanup(RERR_FILEIO);
62 }
63--- util.c 27 Apr 2004 19:59:37 -0000 1.141
64+++ util.c 27 Apr 2004 20:05:04 -0000
65@@ -29,6 +29,7 @@
66
67 extern int verbose;
68 extern struct exclude_list_struct server_exclude_list;
69+extern int do_fsync;
70
71 int sanitize_paths = 0;
72
73@@ -296,6 +297,12 @@ int copy_file(char *source, char *dest,
74
75 if (close(ofd) < 0) {
76 rprintf(FERROR, "close failed on %s: %s\n",
77+ full_fname(dest), strerror(errno));
78+ return -1;
79+ }
80+
81+ if (do_fsync && fsync(ofd) < 0) {
82+ rprintf(FERROR, "fsync failed on %s: %s\n",
83 full_fname(dest), strerror(errno));
84 return -1;
85 }