yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-raw-posix-Open-file-descriptor-O_RDWR-to-work-.patch

34b321
From 9452583824b50cb6f095c5ec1894b38df7b01175 Mon Sep 17 00:00:00 2001
34b321
Message-Id: <9452583824b50cb6f095c5ec1894b38df7b01175.1464449390.git.jen@redhat.com>
34b321
In-Reply-To: <c7936395ecf322b3de37662c7c6b772e36866cc7.1464449390.git.jen@redhat.com>
34b321
References: <c7936395ecf322b3de37662c7c6b772e36866cc7.1464449390.git.jen@redhat.com>
34b321
From: Kevin Wolf <kwolf@redhat.com>
34b321
Date: Mon, 23 May 2016 11:28:41 -0400
34b321
Subject: [CHANGE 3/3] block/raw-posix: Open file descriptor O_RDWR to work
34b321
 around glibc posix_fallocate emulation issue.
34b321
To: rhvirt-patches@redhat.com,
34b321
    jen@redhat.com
34b321
34b321
RH-Author: Kevin Wolf <kwolf@redhat.com>
34b321
Message-id: <1464002921-1079-2-git-send-email-kwolf@redhat.com>
34b321
Patchwork-id: 70425
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH 1/1] block/raw-posix: Open file descriptor O_RDWR to work around glibc posix_fallocate emulation issue.
34b321
Bugzilla: 1268345
34b321
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Richard Jones <rjones@redhat.com>
34b321
34b321
From: "Richard W.M. Jones" <rjones@redhat.com>
34b321
34b321
The following command fails on an NFS mountpoint:
34b321
34b321
  $ qemu-img create -f qcow2 -o preallocation=falloc disk.img 262144
34b321
  Formatting 'disk.img', fmt=qcow2 size=262144 encryption=off cluster_size=65536 preallocation='falloc' lazy_refcounts=off
34b321
  qemu-img: disk.img: Could not preallocate data for the new file: Bad file descriptor
34b321
34b321
The reason turns out to be because NFS doesn't support the
34b321
posix_fallocate call.  glibc emulates it instead.  However glibc's
34b321
emulation involves using the pread(2) syscall.  The pread syscall
34b321
fails with EBADF if the file descriptor is opened without the read
34b321
open-flag (ie. open (..., O_WRONLY)).
34b321
34b321
I contacted glibc upstream about this, and their response is here:
34b321
34b321
  https://bugzilla.redhat.com/show_bug.cgi?id=1265196#c9
34b321
34b321
There are two possible fixes: Use Linux fallocate directly, or (this
34b321
fix) work around the problem in qemu by opening the file with O_RDWR
34b321
instead of O_WRONLY.
34b321
34b321
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
34b321
Reviewed-by: Jeff Cody <jcody@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
(cherry picked from commit 73ba05d936e82fe01b2b2cf987bf3aecb4792af5)
34b321
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
34b321
---
34b321
 block/raw-posix.c | 2 +-
34b321
 1 file changed, 1 insertion(+), 1 deletion(-)
34b321
34b321
diff --git a/block/raw-posix.c b/block/raw-posix.c
34b321
index 1f5275f..92fcb6c 100644
34b321
--- a/block/raw-posix.c
34b321
+++ b/block/raw-posix.c
34b321
@@ -1265,7 +1265,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
34b321
         options++;
34b321
     }
34b321
 
34b321
-    fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
34b321
+    fd = qemu_open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
34b321
                    0644);
34b321
     if (fd < 0) {
34b321
         result = -errno;
34b321
-- 
34b321
2.5.5
34b321