From: Karel Zak Date: Wed, 6 Jan 2010 10:12:43 +0000 (+0100) Subject: fdisk: sleep-after-sync and fsync usage X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e90709421ac86e2e81498143f75734e0b79f76d1;p=util-linux fdisk: sleep-after-sync and fsync usage It seems that sleep() after sync() is unnecessary legacy. It's very probably unnecessary since kernel 1.3.20. For example the libparted does not to use sleep() at all. It seems that more important is fsync() usage in fdisks. For more details see http://marc.theaimsgroup.com/?l=linux-kernel&m=105545785306867&w=3 http://marc.theaimsgroup.com/?l=linux-kernel&m=105545848607353&w=3 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=276369 Currently we use fsync() in fdisk only. This patch also add fsync() to sfdisk and cfdisk. Addresses: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=276369 Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=502639 Signed-off-by: Karel Zak --- diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 0405e126..eec16893 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -406,9 +406,11 @@ partition_type_text(int i) { static void fdexit(int ret) { - if (opened) + if (opened) { + if (changed) + fsync(fd); close(fd); - + } if (changed) { fprintf(stderr, _("Disk has been changed.\n")); #if 0 @@ -1912,12 +1914,10 @@ write_part_table(void) { if (is_bdev) { #ifdef BLKRRPART sync(); - sleep(2); if (!ioctl(fd,BLKRRPART)) changed = TRUE; #endif sync(); - sleep(4); clear_warning(); if (changed) diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index af525bad..5ef24f66 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -2519,7 +2519,6 @@ reread_partition_table(int leave) { i = fstat(fd, &statbuf); if (i == 0 && S_ISBLK(statbuf.st_mode)) { sync(); - sleep(2); #ifdef BLKRRPART printf(_("Calling ioctl() to re-read partition table.\n")); i = ioctl(fd, BLKRRPART); @@ -2550,7 +2549,6 @@ reread_partition_table(int leave) { printf(_("Syncing disks.\n")); sync(); - sleep(4); /* for sync() */ exit(!!i); } } diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index 0652cfa3..6ac91f07 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -806,14 +806,13 @@ reread_disk_partition(char *dev, int fd) { printf(_("Re-reading the partition table ...\n")); fflush(stdout); sync(); - sleep(3); /* superfluous since 1.3.20 */ if (reread_ioctl(fd) && is_blockdev(fd)) do_warn(_("The command to re-read the partition table failed.\n" "Run partprobe(8), kpartx(8) or reboot your system now,\n" "before using mkfs\n")); - if (close(fd)) { + if (fsync(fd) || close(fd)) { perror(dev); do_warn(_("Error closing %s\n"), dev); } @@ -3103,6 +3102,5 @@ do_fdisk(char *dev){ "(See fdisk(8).)\n")); sync(); /* superstition */ - sleep(3); exit(exit_status); }