From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=43477 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLAtk-0000S6-N1 for qemu-devel@nongnu.org; Wed, 24 Nov 2010 03:40:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLAtj-0007Jo-J5 for qemu-devel@nongnu.org; Wed, 24 Nov 2010 03:40:16 -0500 Received: from smtp128.sbc.mail.sp1.yahoo.com ([69.147.65.187]:32520) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PLAtj-0007Jj-AP for qemu-devel@nongnu.org; Wed, 24 Nov 2010 03:40:15 -0500 From: "Nicholas A. Bellinger" Date: Wed, 24 Nov 2010 00:40:12 -0800 Message-Id: <1290588012-8893-1-git-send-email-nab@linux-iscsi.org> Subject: [Qemu-devel] [PATCH 2/5] block: Add BSG qemu_open() in block/raw.c:raw_open() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hannes Reinecke , Kevin Wolf Cc: qemu-devel , Stefan Hajnoczi , Gerd Hoffmann , Nicholas Bellinger , Paolo Bonzini 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 | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/block/raw.c b/block/raw.c index 1980deb..c6c1968 100644 --- a/block/raw.c +++ b/block/raw.c @@ -5,7 +5,26 @@ 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 +56,8 @@ static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs, static void raw_close(BlockDriverState *bs) { + if (bs->fd > 0) + close(bs->fd); } static int raw_flush(BlockDriverState *bs) -- 1.5.6.5