From: Karel Zak Date: Fri, 6 Sep 2019 12:27:42 +0000 (+0200) Subject: sfdisk: add --move-use-fsync, disable fsync() by default X-Git-Tag: v2.35-rc1~228 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7942ba8a799ac7a6c1e9614e60a23c9eefd98de2;p=thirdparty%2Futil-linux.git sfdisk: add --move-use-fsync, disable fsync() by default It's slow, so slooow... Addresses: https://github.com/karelzak/util-linux/issues/848 Signed-off-by: Karel Zak --- diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index c572145fb3..f7f39e393f 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -217,6 +217,8 @@ optional since v2.35. Note that this operation is risky and not atomic. \fBDon't forget to backup your data!\fR +See also \fB\-\-move\-use\-fsync\fR. + In the example below, the first command creates a 100MiB free area before the first partition and moves the data it contains (e.g. a filesystem), the next command creates a new partition from the free space (at offset 2048), @@ -232,6 +234,10 @@ and the last command reorders partitions to match disk order .sp .RE +.TP +.BR \-\-move\-use\-fsync +Use fsync system call after each write when move dara to a new location by +\fB\-\-move\-data\fR. .TP .BR \-o , " \-\-output " \fIlist Specify which output columns to print. Use diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index e7481aab79..cbae88b9a3 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -111,6 +111,7 @@ struct sfdisk { append : 1, /* don't create new PT, append partitions only */ json : 1, /* JSON dump */ movedata: 1, /* move data after resize */ + movefsync: 1, /* use fsync() afetr each write() */ notell : 1, /* don't tell kernel aout new PT */ noact : 1; /* do not write to device */ }; @@ -515,7 +516,8 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa rc = write(fd, buf, step_bytes); if (rc < 0 || rc != (ssize_t) step_bytes) goto fail; - fsync(fd); + if (sf->movefsync) + fsync(fd); } /* write log */ @@ -1898,6 +1900,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -b, --backup backup partition table sectors (see -O)\n"), out); fputs(_(" --bytes print SIZE in bytes rather than in human readable format\n"), out); fputs(_(" --move-data[=] move partition data after relocation (requires -N)\n"), out); + fputs(_(" --move-use-fsync use fsync after each write when move data\n"), out); fputs(_(" -f, --force disable all consistency checking\n"), out); fprintf(out, _(" --color[=] colorize output (%s, %s or %s)\n"), "auto", "always", "never"); @@ -1956,6 +1959,7 @@ int main(int argc, char *argv[]) OPT_BYTES, OPT_COLOR, OPT_MOVEDATA, + OPT_MOVEFSYNC, OPT_DELETE, OPT_NOTELL }; @@ -1981,6 +1985,7 @@ int main(int argc, char *argv[]) { "no-reread", no_argument, NULL, OPT_NOREREAD }, { "no-tell-kernel", no_argument, NULL, OPT_NOTELL }, { "move-data", optional_argument, NULL, OPT_MOVEDATA }, + { "move-use-fsync", no_argument, NULL, OPT_MOVEFSYNC }, { "output", required_argument, NULL, 'o' }, { "partno", required_argument, NULL, 'N' }, { "reorder", no_argument, NULL, 'r' }, @@ -2152,6 +2157,9 @@ int main(int argc, char *argv[]) sf->movedata = 1; sf->move_typescript = optarg; break; + case OPT_MOVEFSYNC: + sf->movefsync = 1; + break; case OPT_DELETE: sf->act = ACT_DELETE; break;