[Parted-commits] GNU Parted Official Repository: Changes to 'next'
Jim Meyering
meyering at alioth.debian.org
Thu Aug 6 10:03:01 UTC 2009
libparted/arch/linux.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
New commits:
commit 3b07d017a51a0cf965bd4f4441e9fdf81264c93a
Author: Colin Watson <cjwatson at ubuntu.com>
Date: Fri Jul 24 18:25:22 2009 +0100
Use fsync rather than O_DIRECT
O_DIRECT doesn't work on all filesystems (e.g. tmpfs), and fsync does
just as good a job to ensure that buffers are flushed.
Based on
http://lists.alioth.debian.org/pipermail/parted-devel/2008-August/002392.html
by Olaf Hering, but with added fsync/close error checking.
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index f875581..06b9327 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -66,15 +66,9 @@
#define HDIO_GETGEO 0x0301 /* get device geometry */
#define HDIO_GET_IDENTITY 0x030d /* get IDE identification info */
-#if defined(O_DIRECT) && !(defined(__s390__) || defined(__s390x__))
-#define RD_MODE (O_RDONLY | O_DIRECT)
-#define WR_MODE (O_WRONLY | O_DIRECT)
-#define RW_MODE (O_RDWR | O_DIRECT)
-#else
#define RD_MODE (O_RDONLY)
#define WR_MODE (O_WRONLY)
#define RW_MODE (O_RDWR)
-#endif
struct hd_geometry {
unsigned char heads;
@@ -1408,7 +1402,16 @@ _flush_cache (PedDevice* dev)
fd = open (name, WR_MODE, 0);
if (fd > 0) {
ioctl (fd, BLKFLSBUF);
- close (fd);
+retry:
+ if (fsync (fd) < 0 || close (fd) < 0)
+ if (ped_exception_throw (
+ PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_RETRY +
+ PED_EXCEPTION_IGNORE,
+ _("Error fsyncing/closing %s: %s"),
+ name, strerror (errno))
+ == PED_EXCEPTION_RETRY)
+ goto retry;
}
}
free (name);
@@ -1470,7 +1473,15 @@ linux_close (PedDevice* dev)
if (dev->dirty)
_flush_cache (dev);
- close (arch_specific->fd);
+retry:
+ if (fsync (arch_specific->fd) < 0 || close (arch_specific->fd) < 0)
+ if (ped_exception_throw (
+ PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_RETRY + PED_EXCEPTION_IGNORE,
+ _("Error fsyncing/closing %s: %s"),
+ dev->path, strerror (errno))
+ == PED_EXCEPTION_RETRY)
+ goto retry;
return 1;
}
More information about the Parted-commits
mailing list