static void parse_drive(DeviceState *dev, const char *str, void **ptr, const char *propname, Error **errp) { BlockBackend *blk; blk = blk_by_name(str); if (!blk) { error_setg(errp, "Property '%s.%s' can't find value '%s'", object_get_typename(OBJECT(dev)), propname, str); return; } if (blk_attach_dev(blk, dev) < 0) { DriveInfo *dinfo = blk_legacy_dinfo(blk); if (dinfo && dinfo->type != IF_NONE) { error_setg(errp, "Drive '%s' is already in use because " "it has been automatically connected to another " "device (did you need 'if=none' in the drive options?)", str); } else { error_setg(errp, "Drive '%s' is already in use by another device", str); } return; } *ptr = blk; }
void blkconf_serial(BlockConf *conf, char **serial) { DriveInfo *dinfo; if (!*serial) { /* try to fall back to value set with legacy -drive serial=... */ dinfo = blk_legacy_dinfo(conf->blk); if (dinfo) { *serial = g_strdup(dinfo->serial); } } }
static void parse_drive(DeviceState *dev, const char *str, void **ptr, const char *propname, Error **errp) { BlockBackend *blk; bool blk_created = false; int ret; blk = blk_by_name(str); if (!blk) { BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL); if (bs) { blk = blk_new(0, BLK_PERM_ALL); blk_created = true; ret = blk_insert_bs(blk, bs, errp); if (ret < 0) { goto fail; } } } if (!blk) { error_setg(errp, "Property '%s.%s' can't find value '%s'", object_get_typename(OBJECT(dev)), propname, str); goto fail; } if (blk_attach_dev(blk, dev) < 0) { DriveInfo *dinfo = blk_legacy_dinfo(blk); if (dinfo && dinfo->type != IF_NONE) { error_setg(errp, "Drive '%s' is already in use because " "it has been automatically connected to another " "device (did you need 'if=none' in the drive options?)", str); } else { error_setg(errp, "Drive '%s' is already in use by another device", str); } goto fail; } *ptr = blk; fail: if (blk_created) { /* If we need to keep a reference, blk_attach_dev() took it */ blk_unref(blk); } }
bool blkconf_geometry(BlockConf *conf, int *ptrans, unsigned cyls_max, unsigned heads_max, unsigned secs_max, Error **errp) { DriveInfo *dinfo; if (!conf->cyls && !conf->heads && !conf->secs) { /* try to fall back to value set with legacy -drive cyls=... */ dinfo = blk_legacy_dinfo(conf->blk); if (dinfo) { conf->cyls = dinfo->cyls; conf->heads = dinfo->heads; conf->secs = dinfo->secs; if (ptrans) { *ptrans = dinfo->trans; } } } if (!conf->cyls && !conf->heads && !conf->secs) { hd_geometry_guess(conf->blk, &conf->cyls, &conf->heads, &conf->secs, ptrans); } else if (ptrans && *ptrans == BIOS_ATA_TRANSLATION_AUTO) { *ptrans = hd_bios_chs_auto_trans(conf->cyls, conf->heads, conf->secs); } if (conf->cyls || conf->heads || conf->secs) { if (conf->cyls < 1 || conf->cyls > cyls_max) { error_setg(errp, "cyls must be between 1 and %u", cyls_max); return false; } if (conf->heads < 1 || conf->heads > heads_max) { error_setg(errp, "heads must be between 1 and %u", heads_max); return false; } if (conf->secs < 1 || conf->secs > secs_max) { error_setg(errp, "secs must be between 1 and %u", secs_max); return false; } } return true; }
static int ide_drive_initfn(IDEDevice *dev) { DriveInfo *dinfo = blk_legacy_dinfo(dev->conf.blk); return ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD); }