virtio-blk: define VirtIOBlkConf
We will have to add another field to the virtio-blk configuration in the next patch. Avoid a proliferation of arguments to virtio_blk_init. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
0e47931b88
commit
12c5674b84
|
@ -163,8 +163,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
|
||||||
{
|
{
|
||||||
VirtIODevice *vdev;
|
VirtIODevice *vdev;
|
||||||
|
|
||||||
vdev = virtio_blk_init((DeviceState *)dev, &dev->block,
|
vdev = virtio_blk_init((DeviceState *)dev, &dev->blk);
|
||||||
&dev->block_serial);
|
|
||||||
if (!vdev) {
|
if (!vdev) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -400,8 +399,8 @@ static TypeInfo s390_virtio_net = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static Property s390_virtio_blk_properties[] = {
|
static Property s390_virtio_blk_properties[] = {
|
||||||
DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
|
DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, blk.conf),
|
||||||
DEFINE_PROP_STRING("serial", VirtIOS390Device, block_serial),
|
DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial),
|
||||||
DEFINE_PROP_END_OF_LIST(),
|
DEFINE_PROP_END_OF_LIST(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "virtio-blk.h"
|
||||||
#include "virtio-net.h"
|
#include "virtio-net.h"
|
||||||
#include "virtio-serial.h"
|
#include "virtio-serial.h"
|
||||||
#include "virtio-scsi.h"
|
#include "virtio-scsi.h"
|
||||||
|
@ -64,8 +65,7 @@ struct VirtIOS390Device {
|
||||||
ram_addr_t feat_offs;
|
ram_addr_t feat_offs;
|
||||||
uint8_t feat_len;
|
uint8_t feat_len;
|
||||||
VirtIODevice *vdev;
|
VirtIODevice *vdev;
|
||||||
BlockConf block;
|
VirtIOBlkConf blk;
|
||||||
char *block_serial;
|
|
||||||
NICConf nic;
|
NICConf nic;
|
||||||
uint32_t host_features;
|
uint32_t host_features;
|
||||||
virtio_serial_conf serial;
|
virtio_serial_conf serial;
|
||||||
|
|
|
@ -29,7 +29,7 @@ typedef struct VirtIOBlock
|
||||||
void *rq;
|
void *rq;
|
||||||
QEMUBH *bh;
|
QEMUBH *bh;
|
||||||
BlockConf *conf;
|
BlockConf *conf;
|
||||||
char *serial;
|
VirtIOBlkConf *blk;
|
||||||
unsigned short sector_mask;
|
unsigned short sector_mask;
|
||||||
DeviceState *qdev;
|
DeviceState *qdev;
|
||||||
} VirtIOBlock;
|
} VirtIOBlock;
|
||||||
|
@ -389,7 +389,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
|
||||||
* terminated by '\0' only when shorter than buffer.
|
* terminated by '\0' only when shorter than buffer.
|
||||||
*/
|
*/
|
||||||
strncpy(req->elem.in_sg[0].iov_base,
|
strncpy(req->elem.in_sg[0].iov_base,
|
||||||
s->serial ? s->serial : "",
|
s->blk->serial ? s->blk->serial : "",
|
||||||
MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
|
MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
|
||||||
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
|
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
|
||||||
g_free(req);
|
g_free(req);
|
||||||
|
@ -563,28 +563,27 @@ static const BlockDevOps virtio_block_ops = {
|
||||||
.resize_cb = virtio_blk_resize,
|
.resize_cb = virtio_blk_resize,
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
|
VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
|
||||||
char **serial)
|
|
||||||
{
|
{
|
||||||
VirtIOBlock *s;
|
VirtIOBlock *s;
|
||||||
int cylinders, heads, secs;
|
int cylinders, heads, secs;
|
||||||
static int virtio_blk_id;
|
static int virtio_blk_id;
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo;
|
||||||
|
|
||||||
if (!conf->bs) {
|
if (!blk->conf.bs) {
|
||||||
error_report("drive property not set");
|
error_report("drive property not set");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!bdrv_is_inserted(conf->bs)) {
|
if (!bdrv_is_inserted(blk->conf.bs)) {
|
||||||
error_report("Device needs media, but drive is empty");
|
error_report("Device needs media, but drive is empty");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*serial) {
|
if (!blk->serial) {
|
||||||
/* try to fall back to value set with legacy -drive serial=... */
|
/* try to fall back to value set with legacy -drive serial=... */
|
||||||
dinfo = drive_get_by_blockdev(conf->bs);
|
dinfo = drive_get_by_blockdev(blk->conf.bs);
|
||||||
if (*dinfo->serial) {
|
if (*dinfo->serial) {
|
||||||
*serial = strdup(dinfo->serial);
|
blk->serial = strdup(dinfo->serial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,9 +594,9 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
|
||||||
s->vdev.get_config = virtio_blk_update_config;
|
s->vdev.get_config = virtio_blk_update_config;
|
||||||
s->vdev.get_features = virtio_blk_get_features;
|
s->vdev.get_features = virtio_blk_get_features;
|
||||||
s->vdev.reset = virtio_blk_reset;
|
s->vdev.reset = virtio_blk_reset;
|
||||||
s->bs = conf->bs;
|
s->bs = blk->conf.bs;
|
||||||
s->conf = conf;
|
s->conf = &blk->conf;
|
||||||
s->serial = *serial;
|
s->blk = blk;
|
||||||
s->rq = NULL;
|
s->rq = NULL;
|
||||||
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
|
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
|
||||||
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
|
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
|
||||||
|
@ -609,10 +608,10 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
|
||||||
register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
|
register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
|
||||||
virtio_blk_save, virtio_blk_load, s);
|
virtio_blk_save, virtio_blk_load, s);
|
||||||
bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
|
bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
|
||||||
bdrv_set_buffer_alignment(s->bs, conf->logical_block_size);
|
bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
|
||||||
|
|
||||||
bdrv_iostatus_enable(s->bs);
|
bdrv_iostatus_enable(s->bs);
|
||||||
add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
|
add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
|
||||||
|
|
||||||
return &s->vdev;
|
return &s->vdev;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,12 @@ struct virtio_scsi_inhdr
|
||||||
uint32_t residual;
|
uint32_t residual;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct VirtIOBlkConf
|
||||||
|
{
|
||||||
|
BlockConf conf;
|
||||||
|
char *serial;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
|
#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
|
||||||
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
|
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
|
||||||
|
@ -105,4 +111,5 @@ struct virtio_scsi_inhdr
|
||||||
#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
|
#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
|
||||||
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
|
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -697,8 +697,7 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
|
||||||
proxy->class_code != PCI_CLASS_STORAGE_OTHER)
|
proxy->class_code != PCI_CLASS_STORAGE_OTHER)
|
||||||
proxy->class_code = PCI_CLASS_STORAGE_SCSI;
|
proxy->class_code = PCI_CLASS_STORAGE_SCSI;
|
||||||
|
|
||||||
vdev = virtio_blk_init(&pci_dev->qdev, &proxy->block,
|
vdev = virtio_blk_init(&pci_dev->qdev, &proxy->blk);
|
||||||
&proxy->block_serial);
|
|
||||||
if (!vdev) {
|
if (!vdev) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -813,8 +812,8 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev)
|
||||||
|
|
||||||
static Property virtio_blk_properties[] = {
|
static Property virtio_blk_properties[] = {
|
||||||
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
|
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
|
||||||
DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
|
DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
|
||||||
DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
|
DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
|
||||||
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
|
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
|
||||||
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
||||||
DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
|
DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef QEMU_VIRTIO_PCI_H
|
#ifndef QEMU_VIRTIO_PCI_H
|
||||||
#define QEMU_VIRTIO_PCI_H
|
#define QEMU_VIRTIO_PCI_H
|
||||||
|
|
||||||
|
#include "virtio-blk.h"
|
||||||
#include "virtio-net.h"
|
#include "virtio-net.h"
|
||||||
#include "virtio-serial.h"
|
#include "virtio-serial.h"
|
||||||
#include "virtio-scsi.h"
|
#include "virtio-scsi.h"
|
||||||
|
@ -32,8 +33,7 @@ typedef struct {
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t class_code;
|
uint32_t class_code;
|
||||||
uint32_t nvectors;
|
uint32_t nvectors;
|
||||||
BlockConf block;
|
VirtIOBlkConf blk;
|
||||||
char *block_serial;
|
|
||||||
NICConf nic;
|
NICConf nic;
|
||||||
uint32_t host_features;
|
uint32_t host_features;
|
||||||
#ifdef CONFIG_LINUX
|
#ifdef CONFIG_LINUX
|
||||||
|
|
|
@ -191,8 +191,8 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
||||||
/* Base devices. */
|
/* Base devices. */
|
||||||
VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
|
typedef struct VirtIOBlkConf VirtIOBlkConf;
|
||||||
char **serial);
|
VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk);
|
||||||
struct virtio_net_conf;
|
struct virtio_net_conf;
|
||||||
VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
|
VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
|
||||||
struct virtio_net_conf *net);
|
struct virtio_net_conf *net);
|
||||||
|
|
Loading…
Reference in a new issue