]> git.proxmox.com Git - qemu.git/blobdiff - hw/xen_disk.c
kill drives_table
[qemu.git] / hw / xen_disk.c
index 527f84b3e58b62b2f99ce0cf51437f609e040b80..100ef8e9bc414a640006ac90663dcb199f5140bb 100644 (file)
@@ -13,8 +13,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <stdio.h>
@@ -108,7 +107,7 @@ struct XenBlkDev {
     int                 requests_finished;
 
     /* qemu block driver */
-    int                 index;
+    DriveInfo           *dinfo;
     BlockDriverState    *bs;
     QEMUBH              *bh;
 };
@@ -179,10 +178,6 @@ static int ioreq_parse(struct ioreq *ioreq)
     switch (ioreq->req.operation) {
     case BLKIF_OP_READ:
        ioreq->prot = PROT_WRITE; /* to memory */
-       if (BLKIF_OP_READ != ioreq->req.operation && blkdev->mode[0] != 'w') {
-           xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n");
-           goto err;
-       }
        break;
     case BLKIF_OP_WRITE_BARRIER:
        if (!syncwrite)
@@ -199,6 +194,11 @@ static int ioreq_parse(struct ioreq *ioreq)
        goto err;
     };
 
+    if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') {
+        xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n");
+        goto err;
+    }
+
     ioreq->start = ioreq->req.sector_number * blkdev->file_blk;
     for (i = 0; i < ioreq->req.nr_segments; i++) {
        if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
@@ -440,10 +440,12 @@ static int blk_send_response_one(struct ioreq *ioreq)
        dst = RING_GET_RESPONSE(&blkdev->rings.native, blkdev->rings.native.rsp_prod_pvt);
        break;
     case BLKIF_PROTOCOL_X86_32:
-       dst = RING_GET_RESPONSE(&blkdev->rings.x86_32, blkdev->rings.x86_32.rsp_prod_pvt);
+        dst = RING_GET_RESPONSE(&blkdev->rings.x86_32_part,
+                                blkdev->rings.x86_32_part.rsp_prod_pvt);
        break;
     case BLKIF_PROTOCOL_X86_64:
-       dst = RING_GET_RESPONSE(&blkdev->rings.x86_64, blkdev->rings.x86_64.rsp_prod_pvt);
+        dst = RING_GET_RESPONSE(&blkdev->rings.x86_64_part,
+                                blkdev->rings.x86_64_part.rsp_prod_pvt);
        break;
     default:
        dst = NULL;
@@ -491,10 +493,12 @@ static int blk_get_request(struct XenBlkDev *blkdev, struct ioreq *ioreq, RING_I
               sizeof(ioreq->req));
        break;
     case BLKIF_PROTOCOL_X86_32:
-       blkif_get_x86_32_req(&ioreq->req, RING_GET_REQUEST(&blkdev->rings.x86_32, rc));
+        blkif_get_x86_32_req(&ioreq->req,
+                             RING_GET_REQUEST(&blkdev->rings.x86_32_part, rc));
        break;
     case BLKIF_PROTOCOL_X86_64:
-       blkif_get_x86_64_req(&ioreq->req, RING_GET_REQUEST(&blkdev->rings.x86_64, rc));
+        blkif_get_x86_64_req(&ioreq->req,
+                             RING_GET_REQUEST(&blkdev->rings.x86_64_part, rc));
        break;
     }
     return 0;
@@ -513,7 +517,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev)
 
     if (use_aio)
         blk_send_response_all(blkdev);
-    while ((rc != rp)) {
+    while (rc != rp) {
         /* pull request from ring */
         if (RING_REQUEST_CONS_OVERFLOW(&blkdev->rings.common, rc))
             break;
@@ -571,7 +575,7 @@ static void blk_alloc(struct XenDevice *xendev)
 static int blk_init(struct XenDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
-    int mode, qflags, have_barriers, info = 0;
+    int index, mode, qflags, have_barriers, info = 0;
     char *h;
 
     /* read xenstore entries */
@@ -618,9 +622,9 @@ static int blk_init(struct XenDevice *xendev)
        info  |= VDISK_CDROM;
 
     /* init qemu block driver */
-    blkdev->index = (blkdev->xendev.dev - 202 * 256) / 16;
-    blkdev->index = drive_get_index(IF_XEN, 0, blkdev->index);
-    if (blkdev->index == -1) {
+    index = (blkdev->xendev.dev - 202 * 256) / 16;
+    blkdev->dinfo = drive_get(IF_XEN, 0, index);
+    if (!blkdev->dinfo) {
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
        blkdev->bs = bdrv_new(blkdev->dev);
@@ -636,7 +640,7 @@ static int blk_init(struct XenDevice *xendev)
     } else {
         /* setup via qemu cmdline -> already setup for us */
         xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
-       blkdev->bs = drives_table[blkdev->index].bdrv;
+       blkdev->bs = blkdev->dinfo->bdrv;
     }
     blkdev->file_blk  = BLOCK_SIZE;
     blkdev->file_size = bdrv_getlength(blkdev->bs);
@@ -698,13 +702,15 @@ static int blk_connect(struct XenDevice *xendev)
     case BLKIF_PROTOCOL_X86_32:
     {
        blkif_x86_32_sring_t *sring_x86_32 = blkdev->sring;
-       BACK_RING_INIT(&blkdev->rings.x86_32, sring_x86_32, XC_PAGE_SIZE);
+
+        BACK_RING_INIT(&blkdev->rings.x86_32_part, sring_x86_32, XC_PAGE_SIZE);
        break;
     }
     case BLKIF_PROTOCOL_X86_64:
     {
        blkif_x86_64_sring_t *sring_x86_64 = blkdev->sring;
-       BACK_RING_INIT(&blkdev->rings.x86_64, sring_x86_64, XC_PAGE_SIZE);
+
+        BACK_RING_INIT(&blkdev->rings.x86_64_part, sring_x86_64, XC_PAGE_SIZE);
        break;
     }
     }
@@ -723,7 +729,7 @@ static void blk_disconnect(struct XenDevice *xendev)
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
 
     if (blkdev->bs) {
-        if (blkdev->index == -1) {
+        if (!blkdev->dinfo) {
             /* close/delete only if we created it ourself */
             bdrv_close(blkdev->bs);
             bdrv_delete(blkdev->bs);