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 <kzak@redhat.com>
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
if (is_bdev) {
#ifdef BLKRRPART
sync();
- sleep(2);
if (!ioctl(fd,BLKRRPART))
changed = TRUE;
#endif
sync();
- sleep(4);
clear_warning();
if (changed)
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);
printf(_("Syncing disks.\n"));
sync();
- sleep(4); /* for sync() */
exit(!!i);
}
}
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);
}
"(See fdisk(8).)\n"));
sync(); /* superstition */
- sleep(3);
exit(exit_status);
}