From 71524cb6b0c2a1b0c5a811cb5bf00eac91d561a8 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 2 Nov 2013 21:42:34 +0100 Subject: [PATCH] reduce FSync option to a boolean there is no use for Thorough mode any more, so simplify the configuration. --- src/config.c | 10 ++-------- src/drv_maildir.c | 4 ++-- src/isync.h | 7 +------ src/mbsync.1 | 25 +++++++++---------------- src/run-tests.pl | 2 +- src/sync.c | 4 ++-- 6 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/config.c b/src/config.c index 5fa665f..0181f7e 100644 --- a/src/config.c +++ b/src/config.c @@ -38,7 +38,7 @@ channel_conf_t global_conf; store_conf_t *stores; channel_conf_t *channels; group_conf_t *groups; -int FSyncLevel = FSYNC_NORMAL; +int UseFSync = 1; #define ARG_OPTIONAL 0 #define ARG_REQUIRED 1 @@ -470,13 +470,7 @@ load_config( const char *where, int pseudo ) } else if (!strcasecmp( "FSync", cfile.cmd )) { - arg = cfile.val; - if (!strcasecmp( "None", arg )) - FSyncLevel = FSYNC_NONE; - else if (!strcasecmp( "Normal", arg )) - FSyncLevel = FSYNC_NORMAL; - else if (!strcasecmp( "Thorough", arg )) - FSyncLevel = FSYNC_THOROUGH; + UseFSync = parse_bool( &cfile ); } else if (!getopt_helper( &cfile, &gcops, &global_conf )) { diff --git a/src/drv_maildir.c b/src/drv_maildir.c index 27d5aec..62c665e 100644 --- a/src/drv_maildir.c +++ b/src/drv_maildir.c @@ -439,7 +439,7 @@ maildir_store_uid( maildir_store_t *ctx ) n = sprintf( buf, "%d\n%d\n", ctx->gen.uidvalidity, ctx->nuid ); lseek( ctx->uvfd, 0, SEEK_SET ); - if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n ) || (FSyncLevel >= FSYNC_NORMAL && fdatasync( ctx->uvfd ))) { + if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n ) || (UseFSync && fdatasync( ctx->uvfd ))) { error( "Maildir error: cannot write UIDVALIDITY.\n" ); return DRV_BOX_BAD; } @@ -1213,7 +1213,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash, } ret = write( fd, data->data, data->len ); free( data->data ); - if (ret != data->len || ((FSyncLevel >= FSYNC_NORMAL) && (ret = fsync( fd )))) { + if (ret != data->len || (UseFSync && (ret = fsync( fd )))) { if (ret < 0) sys_error( "Maildir error: cannot write %s", buf ); else diff --git a/src/isync.h b/src/isync.h index 0bad436..690dab9 100644 --- a/src/isync.h +++ b/src/isync.h @@ -488,12 +488,7 @@ extern driver_t *drivers[N_DRIVERS]; extern channel_conf_t global_conf; extern channel_conf_t *channels; extern group_conf_t *groups; - -#define FSYNC_NONE 0 -#define FSYNC_NORMAL 1 -#define FSYNC_THOROUGH 2 - -extern int FSyncLevel; +extern int UseFSync; int parse_bool( conffile_t *cfile ); int parse_int( conffile_t *cfile ); diff --git a/src/mbsync.1 b/src/mbsync.1 index 10cc81b..867b90b 100644 --- a/src/mbsync.1 +++ b/src/mbsync.1 @@ -534,23 +534,16 @@ times within a Group. .. .SS Global Options .TP -\fBFSync\fR {\fINone\fR|\fINormal\fR|\fIThorough\fR} +\fBFSync\fR \fIyes\fR|\fIno\fR .br -Select the amount of forced flushing \fBmbsync\fR performs, which determines -the level of data safety after system crashes and power outages: -.br -\fBNone\fR - no flushing at all. This is reasonably safe for file systems -which are mounted with data=ordered mode. -.br -\fBNormal\fR - message and critical metadata writes are flushed. No data -should be lost due to crashes, though it is still possible that messages -are duplicated after crashes. This is the default, and is a wise choice for -file systems mounted with data=writeback, in particular modern systems like -ext4, btrfs and xfs. The performance impact on older file systems may be -disproportionate. -.br -\fBThorough\fR - this avoids message duplication after crashes as well, -at some additional performance cost. +Selects whether \fBmbsync\fR performs forced flushing, which determines +the level of data safety after system crashes and power outages. +Disabling it is reasonably safe for file systems which are mounted with +data=ordered mode. +Enabling it is a wise choice for file systems mounted with data=writeback, +in particular modern systems like ext4, btrfs and xfs. The performance impact +on older file systems may be disproportionate. +(Default: \fIyes\fR) .. .SH INHERENT PROBLEMS Changes done after \fBmbsync\fR has retrieved the message list will not be diff --git a/src/run-tests.pl b/src/run-tests.pl index 214af62..7c7d3fd 100755 --- a/src/run-tests.pl +++ b/src/run-tests.pl @@ -249,7 +249,7 @@ sub writecfg($$$) open(FILE, ">", ".mbsyncrc") or die "Cannot open .mbsyncrc.\n"; print FILE -"FSync None +"FSync no MaildirStore master Path ./ diff --git a/src/sync.c b/src/sync.c index e279b22..2ae902b 100644 --- a/src/sync.c +++ b/src/sync.c @@ -44,7 +44,7 @@ const char *str_ms[] = { "master", "slave" }, *str_hl[] = { "push", "pull" }; void Fclose( FILE *f, int safe ) { - if ((safe && (fflush( f ) || (FSyncLevel >= FSYNC_NORMAL && fdatasync( fileno( f ) )))) || fclose( f ) == EOF) { + if ((safe && (fflush( f ) || (UseFSync && fdatasync( fileno( f ) )))) || fclose( f ) == EOF) { sys_error( "Error: cannot close file. Disk full?" ); exit( 1 ); } @@ -1511,7 +1511,7 @@ box_loaded( int sts, void *aux ) } debug( "propagating new messages\n" ); - if (FSyncLevel >= FSYNC_NORMAL) + if (UseFSync) fdatasync( fileno( svars->jfp ) ); for (t = 0; t < 2; t++) { Fprintf( svars->jfp, "%c %d\n", "{}"[t], svars->ctx[t]->uidnext );