#include "qom/object.h"
#include "hw/fw-path-provider.h"
#include "hw/qdev-core.h"
+#include "hw/qdev-properties.h"
#include "hw/virtio/vhost.h"
#include "hw/virtio/vhost-backend.h"
#include "hw/virtio/vhost-user-scsi.h"
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
VHostUserSCSI *s = VHOST_USER_SCSI(dev);
VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
- VhostUserState *user;
+ struct vhost_virtqueue *vqs = NULL;
Error *err = NULL;
int ret;
return;
}
- user = vhost_user_init();
- if (!user) {
- error_setg(errp, "vhost-user-scsi: failed to init vhost_user");
- return;
+ if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, errp)) {
+ goto free_virtio;
}
- user->chr = &vs->conf.chardev;
vsc->dev.nvqs = 2 + vs->conf.num_queues;
vsc->dev.vqs = g_new(struct vhost_virtqueue, vsc->dev.nvqs);
vsc->dev.vq_index = 0;
vsc->dev.backend_features = 0;
+ vqs = vsc->dev.vqs;
- ret = vhost_dev_init(&vsc->dev, user,
+ ret = vhost_dev_init(&vsc->dev, &s->vhost_user,
VHOST_BACKEND_TYPE_USER, 0);
if (ret < 0) {
error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s",
strerror(-ret));
- vhost_user_cleanup(user);
- g_free(user);
- return;
+ goto free_vhost;
}
- s->vhost_user = user;
-
/* Channel and lun both are 0 for bootable vhost-user-scsi disk */
vsc->channel = 0;
vsc->lun = 0;
vsc->target = vs->conf.boot_tpgt;
+
+ return;
+
+free_vhost:
+ vhost_user_cleanup(&s->vhost_user);
+ g_free(vqs);
+free_virtio:
+ virtio_scsi_common_unrealize(dev);
}
static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)
vhost_dev_cleanup(&vsc->dev);
g_free(vqs);
- virtio_scsi_common_unrealize(dev, errp);
-
- if (s->vhost_user) {
- vhost_user_cleanup(s->vhost_user);
- g_free(s->vhost_user);
- s->vhost_user = NULL;
- }
+ virtio_scsi_common_unrealize(dev);
+ vhost_user_cleanup(&s->vhost_user);
}
static Property vhost_user_scsi_properties[] = {