Skip to contentSkip to conversation

scsi: Implement get_req_iov callback

PATCH In review Hannes Reinecke 2 participants 2 messages Nov 18, 2010 – Nov 22, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 15/16 scsi: Implement get_req_iov callback

Add callback to create a request with a predefined iovec.

---
 hw/scsi-disk.c    |   25 +++++++++++++++++++++----
 hw/scsi-generic.c |   44 ++++++++++++++++++++++++++++++++++----------
 hw/scsi.h         |    2 ++
 3 files changed, 57 insertions(+), 14 deletions(-)
hw/scsi-disk.c +21 -4
index f9b66ac..0f144f3 100644
@@ -95,14 +95,30 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag,
     return req;
 }
 
+static SCSIRequest *scsi_new_request_iovec(SCSIDevice *d, uint32_t tag,
+        uint32_t lun, struct iovec *iov, int iov_num)
+{
+    SCSIRequest *req;
+    SCSIDiskReq *r;
+
+    req = scsi_req_alloc(sizeof(SCSIDiskReq), d, tag, lun);
+    r = DO_UPCAST(SCSIDiskReq, req, req);
+    r->iov = iov;
+    r->iov_num = iov_num;
+    r->iov_buf = NULL;
+    return req;
+}
+
 static void scsi_remove_request(SCSIRequest *req)
 {
     SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
 
-    qemu_vfree(r->iov);
-    r->iov = NULL;
-    qemu_vfree(r->iov_buf);
-    r->iov_buf = NULL;
+    if (r->iov_buf) {
+        qemu_vfree(r->iov);
+        r->iov = NULL;
+        qemu_vfree(r->iov_buf);
+        r->iov_buf = NULL;
+    }
     scsi_req_free(&r->req);
 }
 
@@ -1217,6 +1233,7 @@ static SCSIDeviceInfo scsi_disk_info = {
     .init         = scsi_disk_initfn,
     .destroy      = scsi_destroy,
     .get_req      = scsi_new_request,
+    .get_req_iov  = scsi_new_request_iovec,
     .put_req      = scsi_remove_request,
     .send_command = scsi_send_command,
     .read_data    = scsi_read_data,
hw/scsi-generic.c +34 -10

75 lines not on this page · raw message

hw/scsi.h +2 -0
index 6c2540e..10594de 100644
@@ -72,6 +72,8 @@ struct SCSIDeviceInfo {
     scsi_qdev_initfn init;
     void (*destroy)(SCSIDevice *s);
     SCSIRequest *(*get_req)(SCSIDevice *s, uint32_t tag, uint32_t lun);
+    SCSIRequest *(*get_req_iov)(SCSIDevice *s, uint32_t tag, uint32_t lun,
+                                struct iovec *iov, int iov_num);
     void (*put_req)(SCSIRequest *req);
     int32_t (*send_command)(SCSIRequest *req, uint8_t *buf);
     void (*read_data)(SCSIRequest *req);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 7 lines
hw/scsi-disk.c +3 -0
@@ -95,14 +95,30 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag,
     return req;
 }
 
+static SCSIRequest *scsi_new_request_iovec(SCSIDevice *d, uint32_t tag,
+        uint32_t lun, struct iovec *iov, int iov_num)
+{

hw/scsi-disk.c static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, · line 110

Quoted 10 lines
hw/scsi-disk.c +10 -0
+    SCSIRequest *req;
+    SCSIDiskReq *r;
+
+    req = scsi_req_alloc(sizeof(SCSIDiskReq), d, tag, lun);
+    r = DO_UPCAST(SCSIDiskReq, req, req);
+    r->iov = iov;
+    r->iov_num = iov_num;
+    r->iov_buf = NULL;
+    return req;
+}

While the amount of duplicated code here is rather small I still hate the duplication.

The simplest step is to implement scsi_new_request on top of scsi_new_request_iovec by just allocation the iovec in scsi_new_request and passing it to scsi_new_request_iovec. The next patch on top would be to move the iovec allocation to the HBA driver and only stick to one interface.