char protocol[128];
int len;
const char *p;
+ int is_drive;
/* TODO Drivers without bdrv_file_open must be specified explicitly */
#ifdef _WIN32
- if (is_windows_drive(filename) ||
- is_windows_drive_prefix(filename))
- return bdrv_find_format("file");
+ is_drive = is_windows_drive(filename) ||
+ is_windows_drive_prefix(filename);
+#else
+ is_drive = 0;
#endif
p = strchr(filename, ':');
- if (!p) {
+ if (!p || is_drive) {
drv1 = find_hdev_driver(filename);
if (!drv1) {
drv1 = bdrv_find_format("file");
uint8_t buf[2048];
BlockDriverState *bs;
- drv = find_protocol(filename);
- /* no need to test disk image formats for vvfat */
- if (drv && strcmp(drv->format_name, "vvfat") == 0)
- return drv;
-
ret = bdrv_file_open(&bs, filename, 0);
if (ret < 0)
return NULL;
+
+ /* Return the raw BlockDriver * to scsi-generic devices */
+ if (bs->sg)
+ return bdrv_find_format("raw");
+
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
bdrv_delete(bs);
if (ret < 0) {
{
BlockDriver *drv = bs->drv;
+ /* Do not attempt drv->bdrv_getlength() on scsi-generic devices */
+ if (bs->sg)
+ return 0;
+
/* query actual device if possible, otherwise just trust the hint */
if (drv->bdrv_getlength) {
int64_t length = drv->bdrv_getlength(bs);
}
ret = bdrv_create(bdrv_qcow2, tmp_filename, options);
+ free_option_parameters(options);
if (ret < 0) {
return ret;
}
bdrv_delete(bs->backing_hd);
bs->backing_hd = NULL;
bs_rw = bdrv_new("");
- rw_ret = bdrv_open(bs_rw, filename, open_flags | BDRV_O_RDWR, NULL);
+ rw_ret = bdrv_open(bs_rw, filename, open_flags | BDRV_O_RDWR, drv);
if (rw_ret < 0) {
bdrv_delete(bs_rw);
/* try to re-open read-only */
bs_ro = bdrv_new("");
- ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, NULL);
+ ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, drv);
if (ret < 0) {
bdrv_delete(bs_ro);
/* drive not functional anymore */
bdrv_delete(bs->backing_hd);
bs->backing_hd = NULL;
bs_ro = bdrv_new("");
- ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, NULL);
+ ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, drv);
if (ret < 0) {
bdrv_delete(bs_ro);
/* drive not functional anymore */
* - "wr_operations": write operations
* - "wr_highest_offset": Highest offset of a sector written since the
* BlockDriverState has been opened
- * - "parent": Contains recursively the statistics of the underlying
- * protocol (e.g. the host file for a qcow2 image). If there is no
- * underlying protocol, this field is omitted.
+ * - "parent": A QDict recursively holding the statistics of the underlying
+ * protocol (e.g. the host file for a qcow2 image). If there is no
+ * underlying protocol, this field is omitted.
*
* Example:
*
* "wr_bytes": 0,
* "rd_operations": 1,
* "wr_operations": 0,
- * "wr_highest_offset": 0,
- * "parent": {
- * "stats": { "rd_bytes": 1024,
- * "wr_bytes": 0,
- * "rd_operations": 2,
- * "wr_operations": 0,
- * "wr_highest_offset": 0,
- * }
- * } } },
+ * "wr_highest_offset": 0 },
+ * "parent": {
+ * "stats": { "rd_bytes": 1024,
+ * "wr_bytes": 0,
+ * "rd_operations": 2,
+ * "wr_operations": 0,
+ * "wr_highest_offset": 0,
+ * } } },
* { "device": "ide1-cd0",
* "stats": { "rd_bytes": 0,
* "wr_bytes": 0,
static int multiwrite_req_compare(const void *a, const void *b)
{
- return (((BlockRequest*) a)->sector - ((BlockRequest*) b)->sector);
+ const BlockRequest *req1 = a, *req2 = b;
+
+ /*
+ * Note that we can't simply subtract req2->sector from req1->sector
+ * here as that could overflow the return value.
+ */
+ if (req1->sector > req2->sector) {
+ return 1;
+ } else if (req1->sector < req2->sector) {
+ return -1;
+ } else {
+ return 0;
+ }
}
/*
return 0;
fail:
- free(mcb);
+ qemu_free(mcb);
return -1;
}
static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb)
{
- BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb;
+ BlockDriverAIOCBSync *acb =
+ container_of(blockacb, BlockDriverAIOCBSync, common);
qemu_bh_delete(acb->bh);
acb->bh = NULL;
qemu_aio_release(acb);