Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Add virtio disk identification support

Add virtio-blk device id (s/n) support via virtio request.

Signed-off-by: john cooper <john.cooper@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

authored by

john cooper and committed by
Rusty Russell
4cb2ea28 537b60d1

+35
+30
drivers/block/virtio_blk.c
··· 70 70 vbr->req->sense_len = vbr->in_hdr.sense_len; 71 71 vbr->req->errors = vbr->in_hdr.errors; 72 72 } 73 + if (blk_special_request(vbr->req)) 74 + vbr->req->errors = (error != 0); 73 75 74 76 __blk_end_request_all(vbr->req, error); 75 77 list_del(&vbr->list); ··· 102 100 break; 103 101 case REQ_TYPE_BLOCK_PC: 104 102 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD; 103 + vbr->out_hdr.sector = 0; 104 + vbr->out_hdr.ioprio = req_get_ioprio(vbr->req); 105 + break; 106 + case REQ_TYPE_SPECIAL: 107 + vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID; 105 108 vbr->out_hdr.sector = 0; 106 109 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req); 107 110 break; ··· 194 187 { 195 188 req->cmd_type = REQ_TYPE_LINUX_BLOCK; 196 189 req->cmd[0] = REQ_LB_OP_FLUSH; 190 + } 191 + 192 + /* return id (s/n) string for *disk to *id_str 193 + */ 194 + static int virtblk_get_id(struct gendisk *disk, char *id_str) 195 + { 196 + struct virtio_blk *vblk = disk->private_data; 197 + struct request *req; 198 + struct bio *bio; 199 + 200 + bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES, 201 + GFP_KERNEL); 202 + if (IS_ERR(bio)) 203 + return PTR_ERR(bio); 204 + 205 + req = blk_make_request(vblk->disk->queue, bio, GFP_KERNEL); 206 + if (IS_ERR(req)) { 207 + bio_put(bio); 208 + return PTR_ERR(req); 209 + } 210 + 211 + req->cmd_type = REQ_TYPE_SPECIAL; 212 + return blk_execute_rq(vblk->disk->queue, vblk->disk, req, false); 197 213 } 198 214 199 215 static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
+5
include/linux/virtio_blk.h
··· 17 17 #define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */ 18 18 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */ 19 19 20 + #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 21 + 20 22 struct virtio_blk_config { 21 23 /* The capacity (in 512-byte sectors). */ 22 24 __u64 capacity; ··· 68 66 69 67 /* Cache flush command */ 70 68 #define VIRTIO_BLK_T_FLUSH 4 69 + 70 + /* Get device ID command */ 71 + #define VIRTIO_BLK_T_GET_ID 8 71 72 72 73 /* Barrier before this op. */ 73 74 #define VIRTIO_BLK_T_BARRIER 0x80000000