From patchwork Mon Jun 14 09:44:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2/5,block] : Add BSG qemu_open() in block/raw.c:raw_open() From: "Nicholas A. Bellinger" X-Patchwork-Id: 55512 Message-Id: <1276508664-3043-1-git-send-email-nab@linux-iscsi.org> To: Gerd Hoffmann , Kevin Wolf , FUJITA Tomonori Cc: kvm-devel , qemu-devel , Nicholas Bellinger , Hannes Reinecke , Christoph Hellwig , Paul Brook Date: Mon, 14 Jun 2010 02:44:24 -0700 From: Nicholas Bellinger This patch adds a BSG specific qemu_open() call in block/raw.c:raw_open() that saves the opened file descriptor for BSG AIO into BlockDriverState->fd. It also adds the reverse close() call to block/raw.c:raw_close() Signed-off-by: Nicholas A. Bellinger --- block/raw.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/block/raw.c b/block/raw.c index 4406b8c..7820c78 100644 --- a/block/raw.c +++ b/block/raw.c @@ -5,7 +5,25 @@ static int raw_open(BlockDriverState *bs, int flags) { + int fd, ret; + bs->sg = bs->file->sg; + /* + * scsi-generic and other raw types do not call qemu_open() + */ + if (bs->sg != BDS_BSG) + return 0; + /* + * Obtain a file descriptor for the underlying BSG device for AIO w/ iovecs + */ + fd = qemu_open(bs->filename, flags, 0644); + if (fd < 0) { + ret = -errno; + if (ret == -EROFS) + ret = -EACCES; + return ret; + } + bs->fd = fd; return 0; } @@ -37,6 +55,8 @@ static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs, static void raw_close(BlockDriverState *bs) { + if (bs->fd > 0) + close(bs->fd); } static void raw_flush(BlockDriverState *bs)