Skip to contentSkip to conversation

block: Add BSG qemu_open() in block/raw.c:raw_open()

PATCH In review Nicholas A. Bellinger 1 participant 1 message Nov 24, 2010 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 2/5 block: Add BSG qemu_open() in block/raw.c:raw_open()

From: Nicholas Bellinger <[email protected]>

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()

---
 block/raw.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
block/raw.c +21 -0
index 1980deb..c6c1968 100644
@@ -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)
Signature · 1 line
1.5.6.5