Annotation of embedaddon/rsync/patches/fsync.diff, revision 1.1.1.1

1.1       misho       1: This patch from Sami Farin lets you specify --fsync if you want fsync()
                      2: to be called on every file we write.
                      3: 
                      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: 
                     10: based-on: e94bad1c156fc3910f24e2b3b71a81b0b0bdeb70
                     11: diff --git a/options.c b/options.c
                     12: --- a/options.c
                     13: +++ b/options.c
                     14: @@ -66,6 +66,7 @@ int open_noatime = 0;
                     15:  int cvs_exclude = 0;
                     16:  int dry_run = 0;
                     17:  int do_xfers = 1;
                     18: +int do_fsync = 0;
                     19:  int ignore_times = 0;
                     20:  int delete_mode = 0;
                     21:  int delete_during = 0;
                     22: @@ -789,6 +790,7 @@ static struct poptOption long_options[] = {
                     23:    {"no-timeout",       0,  POPT_ARG_VAL,    &io_timeout, 0, 0, 0 },
                     24:    {"contimeout",       0,  POPT_ARG_INT,    &connect_timeout, 0, 0, 0 },
                     25:    {"no-contimeout",    0,  POPT_ARG_VAL,    &connect_timeout, 0, 0, 0 },
                     26: +  {"fsync",            0,  POPT_ARG_NONE,   &do_fsync, 0, 0, 0 },
                     27:    {"stop-after",       0,  POPT_ARG_STRING, 0, OPT_STOP_AFTER, 0, 0 },
                     28:    {"time-limit",       0,  POPT_ARG_STRING, 0, OPT_STOP_AFTER, 0, 0 }, /* earlier stop-after name */
                     29:    {"stop-at",          0,  POPT_ARG_STRING, 0, OPT_STOP_AT, 0, 0 },
                     30: @@ -2845,6 +2847,9 @@ void server_options(char **args, int *argc_p)
                     31:                        args[ac++] = tmpdir;
                     32:                }
                     33:  
                     34: +              if (do_fsync)
                     35: +                      args[ac++] = "--fsync";
                     36: +
                     37:                if (basis_dir[0]) {
                     38:                        /* the server only needs this option if it is not the sender,
                     39:                         *   and it may be an older version that doesn't know this
                     40: diff --git a/receiver.c b/receiver.c
                     41: --- a/receiver.c
                     42: +++ b/receiver.c
                     43: @@ -41,6 +41,7 @@ extern int preserve_hard_links;
                     44:  extern int preserve_perms;
                     45:  extern int write_devices;
                     46:  extern int preserve_xattrs;
                     47: +extern int do_fsync;
                     48:  extern int basis_dir_cnt;
                     49:  extern int make_backups;
                     50:  extern int cleanup_got_literal;
                     51: @@ -394,6 +395,12 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
                     52:  
                     53:        sum_len = sum_end(file_sum1);
                     54:  
                     55: +      if (do_fsync && fd != -1 && fsync(fd) != 0) {
                     56: +              rsyserr(FERROR, errno, "fsync failed on %s",
                     57: +                      full_fname(fname));
                     58: +              exit_cleanup(RERR_FILEIO);
                     59: +      }
                     60: +
                     61:        if (mapbuf)
                     62:                unmap_file(mapbuf);
                     63:  
                     64: diff --git a/rsync.1.md b/rsync.1.md
                     65: --- a/rsync.1.md
                     66: +++ b/rsync.1.md
                     67: @@ -410,6 +410,7 @@ detailed description below for a complete description.
                     68:  --partial-dir=DIR        put a partially transferred file into DIR
                     69:  --delay-updates          put all updated files into place at end
                     70:  --prune-empty-dirs, -m   prune empty directory chains from file-list
                     71: +--fsync                  fsync every written file
                     72:  --numeric-ids            don't map uid/gid values by user/group name
                     73:  --usermap=STRING         custom username mapping
                     74:  --groupmap=STRING        custom groupname mapping
                     75: diff --git a/t_stub.c b/t_stub.c
                     76: --- a/t_stub.c
                     77: +++ b/t_stub.c
                     78: @@ -21,6 +21,7 @@
                     79:  
                     80:  #include "rsync.h"
                     81:  
                     82: +int do_fsync = 0;
                     83:  int inplace = 0;
                     84:  int modify_window = 0;
                     85:  int preallocate_files = 0;
                     86: diff --git a/util.c b/util.c
                     87: --- a/util.c
                     88: +++ b/util.c
                     89: @@ -27,6 +27,7 @@
                     90:  
                     91:  extern int dry_run;
                     92:  extern int module_id;
                     93: +extern int do_fsync;
                     94:  extern int protect_args;
                     95:  extern int modify_window;
                     96:  extern int relative_paths;
                     97: @@ -412,6 +413,13 @@ int copy_file(const char *source, const char *dest, int ofd, mode_t mode)
                     98:                rsyserr(FERROR_XFER, errno, "ftruncate %s", full_fname(dest));
                     99:        }
                    100:  
                    101: +      if (do_fsync && fsync(ofd) < 0) {
                    102: +              rsyserr(FERROR, errno, "fsync failed on %s",
                    103: +                      full_fname(dest));
                    104: +              close(ofd);
                    105: +              return -1;
                    106: +      }
                    107: +
                    108:        if (close(ofd) < 0) {
                    109:                int save_errno = errno;
                    110:                rsyserr(FERROR_XFER, errno, "close failed on %s",
                    111: diff -Nurp a/rsync.1 b/rsync.1
                    112: --- a/rsync.1
                    113: +++ b/rsync.1
                    114: @@ -486,6 +486,7 @@ detailed description below for a complet
                    115:  --partial-dir=DIR        put a partially transferred file into DIR
                    116:  --delay-updates          put all updated files into place at end
                    117:  --prune-empty-dirs, -m   prune empty directory chains from file-list
                    118: +--fsync                  fsync every written file
                    119:  --numeric-ids            don't map uid/gid values by user/group name
                    120:  --usermap=STRING         custom username mapping
                    121:  --groupmap=STRING        custom groupname mapping
                    122: diff -Nurp a/rsync.1.html b/rsync.1.html
                    123: --- a/rsync.1.html
                    124: +++ b/rsync.1.html
                    125: @@ -401,6 +401,7 @@ detailed description below for a complet
                    126:  --partial-dir=DIR        put a partially transferred file into DIR
                    127:  --delay-updates          put all updated files into place at end
                    128:  --prune-empty-dirs, -m   prune empty directory chains from file-list
                    129: +--fsync                  fsync every written file
                    130:  --numeric-ids            don't map uid/gid values by user/group name
                    131:  --usermap=STRING         custom username mapping
                    132:  --groupmap=STRING        custom groupname mapping

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>