[parted-devel] [PATCH] Fall back to not using O_DIRECT

Soren Hansen soren at ubuntu.com
Tue Aug 5 16:00:48 UTC 2008


I used to use parted 1.7.7 as this was what was shipped by Ubuntu and
Debian up until very recently. I used parted to add a partition table to
disk images that I'd be using for virtual machines.  
When parted was updated to 1.8.8, this stopped working, since parted had
started to pass O_DIRECT to open(2) when opening disks; tmpfs (on which
I usually place these disk images) does not support O_DIRECT, and thus
open(2) returns -1 and sets errno to EINVAL.

I've tried to ask around, but have not been able to get a clear
explanation of the rationale for adding O_DIRECT to begin with, such as
reference to a specific problems it's meant to fix. Thus, I'm not sure
if I'm reintroducing said bug by introducing this patch.

The patch itself simply retries the open(2) call without O_DIRECT iff
errno is EINVAL, which according to the open(2) man page only ever
happens in the case where you're opening a file on a file system that
does not support it. 

Signed-off-by: Soren Hansen <soren at canonical.com>

diff -urNad parted-1.8.8.git.2008.03.24~/libparted/arch/linux.c parted-1.8.8.git.2008.03.24/libparted/arch/linux.c
--- parted-1.8.8.git.2008.03.24~/libparted/arch/linux.c 2008-08-05 17:02:18.151661314 +0200
+++ parted-1.8.8.git.2008.03.24/libparted/arch/linux.c  2008-08-05 17:02:47.096662006 +0200
@@ -1301,11 +1301,24 @@
 retry:
         arch_specific->fd = open (dev->path, RW_MODE);
 
+#if defined(O_DIRECT)
+        if (arch_specific->fd == -1 && errno == EINVAL && RW_MODE & O_DIRECT) {
+                int rw_mode = RW_MODE;
+                arch_specific->fd = open (dev->path, rw_mode & ~O_DIRECT);
+        }
+#endif
+       
         if (arch_specific->fd == -1) {
                 char*   rw_error_msg = strerror (errno);
 
                 arch_specific->fd = open (dev->path, RD_MODE);
 
+#if defined(O_DIRECT)
+                if (arch_specific->fd == -1 && errno == EINVAL && RD_MODE & O_DIRECT) {
+                        int rd_mode = RD_MODE;
+                        arch_specific->fd = open (dev->path, rd_mode & ~O_DIRECT);
+                }
+#endif
                 if (arch_specific->fd == -1) {
                         if (ped_exception_throw (
                                 PED_EXCEPTION_ERROR,


-- 
Soren Hansen               | 
Virtualisation specialist  | Ubuntu Server Team
Canonical Ltd.             | http://www.ubuntu.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20080805/6f06ad8e/attachment.pgp 


More information about the parted-devel mailing list