Skip to contentSkip to conversation

Remove ->bdrv_pread() internal block layer API

PATCH In review Avi Kivity 2 participants 8 messages Feb 8, 2009

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

cover Remove ->bdrv_pread() internal block layer API

The internal block layer API has a wart in the form of the ->bdrv_pread() and ->bdrv_pwrite() methods. These duplicate bdrv_read() and bdrv_write(), and are unnatural for a block device in that they are not sector oriented.

One of the reasons for their existence is the scsi-generic host support. That is also a wart, as scsi-generic is really a packet (command/response) rather than a block (random access to sectors) API. There is also the wierd negative sector count == byte count thing.

This patchset addresses these warts by adding a new API for scsi-generic and dropping ->bdrv_pread() and bdrv_pwrite(). While the improvement falls short of spectacular, it does make further hacking on the block layer easier as there are fewer callbacks to worry about.

Avi Kivity (3):
Add specialized block driver scsi generic API
Add internal scsi generic block API
Drop internal bdrv_pread()/bdrv_pwrite() APIs

 block-raw-posix.c |   50 +++++++++++++++++++++++++--
 block-raw-win32.c |   20 +++++++----
 block.c           |   95 +++++++++++++++-------------------------------------
 block.h           |    8 ++++
 block_int.h       |   14 +++++--
 hw/scsi-generic.c |   39 ++++++++++++---------
 6 files changed, 126 insertions(+), 100 deletions(-)
author
#1 lore raw

PATCH 1/3 Add specialized block driver scsi generic API

When a scsi device is backed by a scsi generic device instead of an ordinary host block device, the block API is abused in a couple of annoying ways:

- nb_sectors is negative, and specifies a byte count instead of a sector count
- offset is ignored, since scsi-generic is essentially a packet protocol

This overloading makes hacking the block layer difficult. Remove it by introducing a new explicit API for scsi-generic devices. The new API is still backed by the old implementation, but at least the users are insulated.

---
 block.c           |   22 ++++++++++++++++++++++
 block.h           |    8 ++++++++
 hw/scsi-generic.c |   39 ++++++++++++++++++++++-----------------
 3 files changed, 52 insertions(+), 17 deletions(-)
block.c +22 -0
index 4f4bf7c..774ac2d 100644
@@ -1594,3 +1594,25 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
         return drv->bdrv_ioctl(bs, req, buf);
     return -ENOTSUP;
 }
+
+int bdrv_sg_send_command(BlockDriverState *bs, void *buf, int count)
+{
+    return bdrv_pwrite(bs, -1, buf, count);
+}
+
+int bdrv_sg_recv_response(BlockDriverState *bs, void *buf, int count)
+{
+    return bdrv_pread(bs, -1, buf, count);
+}
+
+BlockDriverAIOCB *bdrv_sg_aio_read(BlockDriverState *bs, void *buf, int count,
+                                   BlockDriverCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
+}
+
+BlockDriverAIOCB *bdrv_sg_aio_write(BlockDriverState *bs, void *buf, int count,
+                                    BlockDriverCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
+}
block.h +8 -0
index e1927dd..f06d98a 100644
@@ -103,6 +103,14 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
                                  BlockDriverCompletionFunc *cb, void *opaque);
 void bdrv_aio_cancel(BlockDriverAIOCB *acb);
 
+/* sg packet commands */
+int bdrv_sg_send_command(BlockDriverState *bs, void *buf, int count);
+int bdrv_sg_recv_response(BlockDriverState *bs, void *buf, int count);
+BlockDriverAIOCB *bdrv_sg_aio_read(BlockDriverState *bs, void *buf, int count,
+                                   BlockDriverCompletionFunc *cb, void *opaque);
+BlockDriverAIOCB *bdrv_sg_aio_write(BlockDriverState *bs, void *buf, int count,
+                                    BlockDriverCompletionFunc *cb, void *opaque);
+
 int qemu_key_check(BlockDriverState *bs, const char *name);
 
 /* Ensure contents are flushed to disk.  */
hw/scsi-generic.c +22 -17
index 5bf160a..53e8951 100644
@@ -201,6 +201,7 @@ static int execute_command(BlockDriverState *bdrv,
                            SCSIRequest *r, int direction,
 			   BlockDriverCompletionFunc *complete)
 {
+    int ret;
 
     r->io_header.interface_id = 'S';
     r->io_header.dxfer_direction = direction;
@@ -214,25 +215,27 @@ static int execute_command(BlockDriverState *bdrv,
     r->io_header.usr_ptr = r;
     r->io_header.flags |= SG_FLAG_DIRECT_IO;
 
-    if (bdrv_pwrite(bdrv, -1, &r->io_header, sizeof(r->io_header)) == -1) {
+    ret = bdrv_sg_send_command(bdrv, &r->io_header, sizeof(r->io_header));
+    if (ret < 0) {
         BADF("execute_command: write failed ! (%d)\n", errno);
         return -1;
     }
     if (complete == NULL) {
         int ret;
         r->aiocb = NULL;
-        while ((ret = bdrv_pread(bdrv, -1, &r->io_header,
-                                           sizeof(r->io_header))) == -1 &&
-                      errno == EINTR);
-        if (ret == -1) {
+        while ((ret = bdrv_sg_recv_response(bdrv, &r->io_header,
+                                            sizeof(r->io_header))) < 0 &&
+               ret == -EINTR)
+            ;
+        if (ret < 0) {
             BADF("execute_command: read failed !\n");
             return -1;
         }
         return 0;
     }
 
-    r->aiocb = bdrv_aio_read(bdrv, 0, (uint8_t*)&r->io_header,
-                          -(int64_t)sizeof(r->io_header), complete, r);
+    r->aiocb = bdrv_sg_aio_read(bdrv, (uint8_t*)&r->io_header,
+                                sizeof(r->io_header), complete, r);
     if (r->aiocb == NULL) {
         BADF("execute_command: read failed !\n");
         return -1;
@@ -634,14 +637,15 @@ static int get_blocksize(BlockDriverState *bdrv)
     io_header.sbp = sensebuf;
     io_header.timeout = 6000; /* XXX */
 
-    ret = bdrv_pwrite(bdrv, -1, &io_header, sizeof(io_header));
-    if (ret == -1)
+    ret = bdrv_sg_send_command(bdrv, &io_header, sizeof(io_header));
+    if (ret < 0)
         return -1;
 
-    while ((ret = bdrv_pread(bdrv, -1, &io_header, sizeof(io_header))) == -1 &&
-           errno == EINTR);
+    while ((ret = bdrv_sg_recv_response(bdrv, &io_header, sizeof(io_header))) < 0 &&
+           ret == -EINTR)
+        ;
 
-    if (ret == -1)
+    if (ret < 0)
         return -1;
 
     return (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
@@ -671,14 +675,15 @@ static int get_stream_blocksize(BlockDriverState *bdrv)
     io_header.sbp = sensebuf;
     io_header.timeout = 6000; /* XXX */
 
-    ret = bdrv_pwrite(bdrv, -1, &io_header, sizeof(io_header));
-    if (ret == -1)
+    ret = bdrv_sg_send_command(bdrv, &io_header, sizeof(io_header));
+    if (ret < 0)
         return -1;
 
-    while ((ret = bdrv_pread(bdrv, -1, &io_header, sizeof(io_header))) == -1 &&
-           errno == EINTR);
+    while ((ret = bdrv_sg_recv_response(bdrv, &io_header, sizeof(io_header))) < 0 &&
+           ret == -EINTR)
+        ;
 
-    if (ret == -1)
+    if (ret < 0)
         return -1;
 
     return (buf[9] << 16) | (buf[10] << 8) | buf[11];
Signature · 1 line
1.6.1.1
author
#2 lore raw

PATCH 2/3 Add internal scsi generic block API

In reply to Avi Kivity

Add an internal API for the generic block layer to send scsi generic commands to block format driver. This means block format drivers no longer need to consider overloaded nb_sectors parameters.

---
 block-raw-posix.c |   30 ++++++++++++++++++++++++++++++
 block.c           |    8 ++++----
 block_int.h       |   10 ++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)
block-raw-posix.c +30 -0
index 620791b..6b8adc4 100644
@@ -1164,6 +1164,32 @@ static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 }
 #endif /* !linux */
 
+static int raw_sg_send_command(BlockDriverState *bs, void *buf, int count)
+{
+    return raw_pwrite(bs, -1, buf, count);
+}
+
+static int raw_sg_recv_response(BlockDriverState *bs, void *buf, int count)
+{
+    return raw_pread(bs, -1, buf, count);
+}
+
+static BlockDriverAIOCB *raw_sg_aio_read(BlockDriverState *bs,
+                                         void *buf, int count,
+                                         BlockDriverCompletionFunc *cb,
+                                         void *opaque)
+{
+    return raw_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
+}
+
+static BlockDriverAIOCB *raw_sg_aio_write(BlockDriverState *bs,
+                                          void *buf, int count,
+                                          BlockDriverCompletionFunc *cb,
+                                          void *opaque)
+{
+    return raw_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
+}
+
 BlockDriver bdrv_host_device = {
     "host_device",
     sizeof(BDRVRawState),
@@ -1193,4 +1219,8 @@ BlockDriver bdrv_host_device = {
     .bdrv_set_locked = raw_set_locked,
     /* generic scsi device */
     .bdrv_ioctl = raw_ioctl,
+    .bdrv_sg_send_command = raw_sg_send_command,
+    .bdrv_sg_recv_response = raw_sg_recv_response,
+    .bdrv_sg_aio_read = raw_sg_aio_read,
+    .bdrv_sg_aio_write = raw_sg_aio_write,
 };
block.c +4 -4
index 774ac2d..4aaea09 100644
@@ -1597,22 +1597,22 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 
 int bdrv_sg_send_command(BlockDriverState *bs, void *buf, int count)
 {
-    return bdrv_pwrite(bs, -1, buf, count);
+    return bs->drv->bdrv_sg_send_command(bs, buf, count);
 }
 
 int bdrv_sg_recv_response(BlockDriverState *bs, void *buf, int count)
 {
-    return bdrv_pread(bs, -1, buf, count);
+    return bs->drv->bdrv_sg_recv_response(bs, buf, count);
 }
 
 BlockDriverAIOCB *bdrv_sg_aio_read(BlockDriverState *bs, void *buf, int count,
                                    BlockDriverCompletionFunc *cb, void *opaque)
 {
-    return bdrv_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
+    return bs->drv->bdrv_sg_aio_read(bs, buf, count, cb, opaque);
 }
 
 BlockDriverAIOCB *bdrv_sg_aio_write(BlockDriverState *bs, void *buf, int count,
                                     BlockDriverCompletionFunc *cb, void *opaque)
 {
-    return bdrv_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
+    return bs->drv->bdrv_sg_aio_write(bs, buf, count, cb, opaque);
 }
block_int.h +10 -0
index e83fd2c..e4630f0 100644
@@ -84,6 +84,16 @@ struct BlockDriver {
 
     /* to control generic scsi devices */
     int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
+    int (*bdrv_sg_send_command)(BlockDriverState *bs, void *buf, int count);
+    int (*bdrv_sg_recv_response)(BlockDriverState *bs, void *buf, int count);
+    BlockDriverAIOCB *(*bdrv_sg_aio_read)(BlockDriverState *bs,
+                                          void *buf, int count,
+                                          BlockDriverCompletionFunc *cb,
+                                          void *opaque);
+    BlockDriverAIOCB *(*bdrv_sg_aio_write)(BlockDriverState *bs,
+                                           void *buf, int count,
+                                           BlockDriverCompletionFunc *cb,
+                                           void *opaque);
 
     BlockDriverAIOCB *free_aiocb;
     struct BlockDriver *next;
Signature · 1 line
1.6.1.1
author
#3 lore raw

PATCH 3/3 Drop internal bdrv_pread()/bdrv_pwrite() APIs

In reply to Avi Kivity

Now that scsi generic no longer uses bdrv_pread() and bdrv_pwrite(), we can drop the corresponding internal APIs, which overlap bdrv_read()/bdrv_write() and, being byte oriented, are unnatural for a block device.

---
 block-raw-posix.c |   20 +++++++++++---
 block-raw-win32.c |   20 ++++++++------
 block.c           |   73 ++++------------------------------------------------
 block_int.h       |    4 ---
 4 files changed, 34 insertions(+), 83 deletions(-)
block-raw-posix.c +16 -4
index 6b8adc4..9b32615 100644
@@ -353,6 +353,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
     return raw_pread_aligned(bs, offset, buf, count) + sum;
 }
 
+static int raw_read(BlockDriverState *bs, int64_t sector_num,
+                    uint8_t *buf, int nb_sectors)
+{
+    return raw_pread(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512);
+}
+
 /*
  * offset and count are in bytes and possibly not aligned. For files opened
  * with O_DIRECT, necessary alignments are ensured before calling
@@ -431,6 +437,12 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
     return raw_pwrite_aligned(bs, offset, buf, count) + sum;
 }
 
+static int raw_write(BlockDriverState *bs, int64_t sector_num,
+                     const uint8_t *buf, int nb_sectors)
+{
+    return raw_pwrite(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512);
+}
+
 #ifdef CONFIG_AIO
 /***********************************************************/
 /* Unix AIO using POSIX AIO */
@@ -828,8 +840,8 @@ BlockDriver bdrv_raw = {
     .aiocb_size = sizeof(RawAIOCB),
 #endif
 
-    .bdrv_pread = raw_pread,
-    .bdrv_pwrite = raw_pwrite,
+    .bdrv_read = raw_read,
+    .bdrv_write = raw_write,
     .bdrv_truncate = raw_truncate,
     .bdrv_getlength = raw_getlength,
 };
@@ -1208,8 +1220,8 @@ BlockDriver bdrv_host_device = {
     .aiocb_size = sizeof(RawAIOCB),
 #endif
 
-    .bdrv_pread = raw_pread,
-    .bdrv_pwrite = raw_pwrite,
+    .bdrv_read = raw_read,
+    .bdrv_write = raw_write,
     .bdrv_getlength = raw_getlength,
 
     /* removable device support */
block-raw-win32.c +12 -8
index 892f2d1..f37ab68 100644
@@ -121,13 +121,15 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
     return 0;
 }
 
-static int raw_pread(BlockDriverState *bs, int64_t offset,
-                     uint8_t *buf, int count)
+static int raw_read(BlockDriverState *bs, int64_t sector_num,
+                    uint8_t *buf, int nb_sectors)
 {
     BDRVRawState *s = bs->opaque;
     OVERLAPPED ov;
     DWORD ret_count;
     int ret;
+    int64_t offset = sector_num * 512;
+    int count = nb_sectors * 512;
 
     memset(&ov, 0, sizeof(ov));
     ov.Offset = offset;
@@ -145,13 +147,15 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
     return ret_count;
 }
 
-static int raw_pwrite(BlockDriverState *bs, int64_t offset,
-                      const uint8_t *buf, int count)
+static int raw_write(BlockDriverState *bs, int64_t sector_num,
+                     const uint8_t *buf, int nb_sectors)
 {
     BDRVRawState *s = bs->opaque;
     OVERLAPPED ov;
     DWORD ret_count;
     int ret;
+    int64_t offset = sector_num * 512;
+    int count = nb_sectors * 512;
 
     memset(&ov, 0, sizeof(ov));
     ov.Offset = offset;
@@ -358,8 +362,8 @@ BlockDriver bdrv_raw = {
     .bdrv_aio_cancel = raw_aio_cancel,
     .aiocb_size = sizeof(RawAIOCB);
 #endif
-    .bdrv_pread = raw_pread,
-    .bdrv_pwrite = raw_pwrite,
+    .bdrv_read = raw_read,
+    .bdrv_write = raw_write,
     .bdrv_truncate = raw_truncate,
     .bdrv_getlength = raw_getlength,
 };
@@ -511,7 +515,7 @@ BlockDriver bdrv_host_device = {
     .bdrv_aio_cancel = raw_aio_cancel,
     .aiocb_size = sizeof(RawAIOCB);
 #endif
-    .bdrv_pread = raw_pread,
-    .bdrv_pwrite = raw_pwrite,
+    .bdrv_read = raw_read,
+    .bdrv_write = raw_write,
     .bdrv_getlength = raw_getlength,
 };
block.c +6 -67

106 lines not on this page · raw message

block_int.h +0 -4
index e4630f0..cc9966b 100644
@@ -58,10 +58,6 @@ struct BlockDriver {
     int aiocb_size;
 
     const char *protocol_name;
-    int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
-                      uint8_t *buf, int count);
-    int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
-                       const uint8_t *buf, int count);
     int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
     int64_t (*bdrv_getlength)(BlockDriverState *bs);
     int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
Signature · 1 line
1.6.1.1
#4 lore raw

[Qemu-devel] Re: [PATCH 3/3] Drop internal bdrv_pread()/bdrv_pwrite() APIs

Quoted 12 lines · Avi Kivity

Now that scsi generic no longer uses bdrv_pread() and bdrv_pwrite(), we can drop the corresponding internal APIs, which overlap bdrv_read()/bdrv_write() and, being byte oriented, are unnatural for a block device.

int bdrv_truncate(BlockDriverState *bs, int64_t offset)

block_int.h +0 -0
index e4630f0..cc9966b 100644

block_int.h struct BlockDriver { · line 61

Quoted 8 lines
block_int.h +0 -4
@@ -58,10 +58,6 @@ struct BlockDriver {
     int aiocb_size;
 
     const char *protocol_name;
-    int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
-                      uint8_t *buf, int count);
-    int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
-                       const uint8_t *buf, int count);
 
$ grep -l bdrv_pwrite *.c hw/*.c
block.c
block-qcow2.c
block-qcow.c
block-raw-posix.c
block-raw-win32.c
block-vmdk.c
block-vpc.c
savevm.c
hw/scsi-generic.c

So there's a lot of users other than scsi-generic. Usually, these callers are in the block layer to read/write metadata that isn't always block aligned. Some buffer adjustment could fix savevm.c to ensure alignment.

These users are now relegated to using emulated pread/pwrite? Won't that have a noticable impact on performance if updating small bits of metadata. For instance, I think updating qcow2 refcounts would look bad since you have to read/write the full block to update 4 bytes of data. Granted it'll be cached, but...

Regards,

Anthony Liguori

Quoted 4 lines
block_int.h +0 -0
     int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
     int64_t (*bdrv_getlength)(BlockDriverState *bs);

int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,

author
#5 lore raw

[Qemu-devel] Re: [PATCH 3/3] Drop internal bdrv_pread()/bdrv_pwrite() APIs

Quoted 33 lines · Anthony Liguori
Quoted 12 lines · Avi Kivity

Now that scsi generic no longer uses bdrv_pread() and bdrv_pwrite(), we can drop the corresponding internal APIs, which overlap bdrv_read()/bdrv_write() and, being byte oriented, are unnatural for a block device.

int bdrv_truncate(BlockDriverState *bs, int64_t offset)

block_int.h +0 -0
index e4630f0..cc9966b 100644

block_int.h struct BlockDriver { · line 61

Quoted 8 lines
block_int.h +0 -4
@@ -58,10 +58,6 @@ struct BlockDriver {
     int aiocb_size;
 
     const char *protocol_name;
-    int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
-                      uint8_t *buf, int count);
-    int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
-                       const uint8_t *buf, int count);
 
$ grep -l bdrv_pwrite *.c hw/*.c
block.c
block-qcow2.c
block-qcow.c
block-raw-posix.c
block-raw-win32.c
block-vmdk.c
block-vpc.c
savevm.c
hw/scsi-generic.c
Quoted 1 line

So there's a lot of users other than scsi-generic. Usually, these callers are in the block layer to read/write metadata that isn't always block aligned. Some buffer adjustment could fix savevm.c to ensure alignment.

It's more accurate to say that there are now no users that depend on the request size. The other users will happily allow expansion of a small request to a sector.

Quoted 1 line

These users are now relegated to using emulated pread/pwrite? Won't that have a noticable impact on performance if updating small bits of metadata. For instance, I think updating qcow2 refcounts would look bad since you have to read/write the full block to update 4 bytes of data. Granted it'll be cached, but...

I haven't measured but I'll bet the impact is unnoticable. We're doubling the syscall count for writes, but the actual transfer (if cached) or the I/O (if uncached) will swamp that. For reads, we're copying a bit more data, but that won't even tickle performance.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
author
#6 lore raw

[Qemu-devel] Re: [PATCH 3/3] Drop internal bdrv_pread()/bdrv_pwrite() APIs

In reply to Anthony Liguori
Quoted 33 lines · Anthony Liguori
Quoted 12 lines · Avi Kivity

Now that scsi generic no longer uses bdrv_pread() and bdrv_pwrite(), we can drop the corresponding internal APIs, which overlap bdrv_read()/bdrv_write() and, being byte oriented, are unnatural for a block device.

int bdrv_truncate(BlockDriverState *bs, int64_t offset)

block_int.h +0 -0
index e4630f0..cc9966b 100644

block_int.h struct BlockDriver { · line 61

Quoted 8 lines
block_int.h +0 -4
@@ -58,10 +58,6 @@ struct BlockDriver {
     int aiocb_size;
 
     const char *protocol_name;
-    int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
-                      uint8_t *buf, int count);
-    int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
-                       const uint8_t *buf, int count);
 
$ grep -l bdrv_pwrite *.c hw/*.c
block.c
block-qcow2.c
block-qcow.c
block-raw-posix.c
block-raw-win32.c
block-vmdk.c
block-vpc.c
savevm.c
hw/scsi-generic.c
Quoted 1 line

So there's a lot of users other than scsi-generic. Usually, these callers are in the block layer to read/write metadata that isn't always block aligned. Some buffer adjustment could fix savevm.c to ensure alignment.

It's more accurate to say that there are now no users that depend on the request size. The other users will happily allow expansion of a small request to a sector.

Quoted 1 line

These users are now relegated to using emulated pread/pwrite? Won't that have a noticable impact on performance if updating small bits of metadata. For instance, I think updating qcow2 refcounts would look bad since you have to read/write the full block to update 4 bytes of data. Granted it'll be cached, but...

I haven't measured but I'll bet the impact is unnoticable. We're doubling the syscall count for writes, but the actual transfer (if cached) or the I/O (if uncached) will swamp that. For reads, we're copying a bit more data, but that won't even tickle performance.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#7 lore raw
In reply to Avi Kivity
Quoted 10 lines · Avi Kivity

The internal block layer API has a wart in the form of the ->bdrv_pread() and ->bdrv_pwrite() methods. These duplicate bdrv_read() and bdrv_write(), and are unnatural for a block device in that they are not sector oriented.

One of the reasons for their existence is the scsi-generic host support. That is also a wart, as scsi-generic is really a packet (command/response) rather than a block (random access to sectors) API. There is also the wierd negative sector count == byte count thing.

Great stuff, this has always bugged me.

Regards,

Anthony Liguori

Quoted 19 lines

This patchset addresses these warts by adding a new API for scsi-generic and dropping ->bdrv_pread() and bdrv_pwrite(). While the improvement falls short of spectacular, it does make further hacking on the block layer easier as there are fewer callbacks to worry about.

Avi Kivity (3):
Add specialized block driver scsi generic API
Add internal scsi generic block API
Drop internal bdrv_pread()/bdrv_pwrite() APIs

 block-raw-posix.c |   50 +++++++++++++++++++++++++--
 block-raw-win32.c |   20 +++++++----
 block.c           |   95 +++++++++++++++-------------------------------------
 block.h           |    8 ++++
 block_int.h       |   14 +++++--
 hw/scsi-generic.c |   39 ++++++++++++---------
 6 files changed, 126 insertions(+), 100 deletions(-)