···7070 vbr->req->sense_len = vbr->in_hdr.sense_len;7171 vbr->req->errors = vbr->in_hdr.errors;7272 }7373+ if (blk_special_request(vbr->req))7474+ vbr->req->errors = (error != 0);73757476 __blk_end_request_all(vbr->req, error);7577 list_del(&vbr->list);···102100 break;103101 case REQ_TYPE_BLOCK_PC:104102 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;103103+ vbr->out_hdr.sector = 0;104104+ vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);105105+ break;106106+ case REQ_TYPE_SPECIAL:107107+ vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID;105108 vbr->out_hdr.sector = 0;106109 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);107110 break;···194187{195188 req->cmd_type = REQ_TYPE_LINUX_BLOCK;196189 req->cmd[0] = REQ_LB_OP_FLUSH;190190+}191191+192192+/* return id (s/n) string for *disk to *id_str193193+ */194194+static int virtblk_get_id(struct gendisk *disk, char *id_str)195195+{196196+ struct virtio_blk *vblk = disk->private_data;197197+ struct request *req;198198+ struct bio *bio;199199+200200+ bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES,201201+ GFP_KERNEL);202202+ if (IS_ERR(bio))203203+ return PTR_ERR(bio);204204+205205+ req = blk_make_request(vblk->disk->queue, bio, GFP_KERNEL);206206+ if (IS_ERR(req)) {207207+ bio_put(bio);208208+ return PTR_ERR(req);209209+ }210210+211211+ req->cmd_type = REQ_TYPE_SPECIAL;212212+ return blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);197213}198214199215static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
+5
include/linux/virtio_blk.h
···1717#define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */1818#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */19192020+#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */2121+2022struct virtio_blk_config {2123 /* The capacity (in 512-byte sectors). */2224 __u64 capacity;···68666967/* Cache flush command */7068#define VIRTIO_BLK_T_FLUSH 46969+7070+/* Get device ID command */7171+#define VIRTIO_BLK_T_GET_ID 871727273/* Barrier before this op. */7374#define VIRTIO_BLK_T_BARRIER 0x80000000