Revision 2930b313

b/hw/virtio-blk.c
26 26
    QEMUBH *bh;
27 27
    BlockConf *conf;
28 28
    unsigned short sector_mask;
29
    char sn[BLOCK_SERIAL_STRLEN];
29 30
} VirtIOBlock;
30 31

  
31 32
static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
......
324 325
        virtio_blk_handle_flush(req, mrb);
325 326
    } else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) {
326 327
        virtio_blk_handle_scsi(req);
328
    } else if (req->out->type & VIRTIO_BLK_T_GET_ID) {
329
        VirtIOBlock *s = req->dev;
330

  
331
        memcpy(req->elem.in_sg[0].iov_base, s->sn,
332
               MIN(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
333
        virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
327 334
    } else if (req->out->type & VIRTIO_BLK_T_OUT) {
328 335
        qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
329 336
                                 req->elem.out_num - 1);
......
481 488
    VirtIOBlock *s;
482 489
    int cylinders, heads, secs;
483 490
    static int virtio_blk_id;
491
    DriveInfo *dinfo;
484 492

  
485 493
    s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
486 494
                                          sizeof(struct virtio_blk_config),
......
495 503
    s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
496 504
    bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
497 505

  
506
    /* NB: per existing s/n string convention the string is terminated
507
     * by '\0' only when less than sizeof (s->sn)
508
     */
509
    dinfo = drive_get_by_blockdev(s->bs);
510
    strncpy(s->sn, dinfo->serial, sizeof (s->sn));
511

  
498 512
    s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
499 513

  
500 514
    qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
b/hw/virtio-blk.h
59 59
/* Flush the volatile write cache */
60 60
#define VIRTIO_BLK_T_FLUSH      4
61 61

  
62
/* return the device ID string */
63
#define VIRTIO_BLK_T_GET_ID     8
64

  
62 65
/* Barrier before this op. */
63 66
#define VIRTIO_BLK_T_BARRIER    0x80000000
64 67

  

Also available in: Unified diff