From: Jon Doron <arilou@gmail.com>
To: qemu-devel@nongnu.org
Cc: mail@maciej.szmigiero.name, eyakovlev@virtuozzo.com,
ehabkost@redhat.com, rvkagan@gmail.com, liran.alon@oracle.com,
Roman Kagan <rkagan@virtuozzo.com>,
pbonzini@redhat.com, vkuznets@redhat.com,
"Maciej S . Szmigiero" <maciej.szmigiero@oracle.com>,
Jon Doron <arilou@gmail.com>
Subject: [PATCH v4 6/6] vmbus: add infrastructure to save/load vmbus requests
Date: Fri, 24 Apr 2020 15:34:44 +0300 [thread overview]
Message-ID: <20200424123444.3481728-7-arilou@gmail.com> (raw)
In-Reply-To: <20200424123444.3481728-1-arilou@gmail.com>
This can be allow to include controller-specific data while
saving/loading in-flight scsi requests of the vmbus scsi controller.
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Signed-off-by: Jon Doron <arilou@gmail.com>
---
hw/hyperv/vmbus.c | 99 +++++++++++++++++++++++++++++++++++++++
include/hw/hyperv/vmbus.h | 3 ++
2 files changed, 102 insertions(+)
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index 0df7afe0ca..ab72a59a4a 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -1272,6 +1272,105 @@ void vmbus_free_req(void *req)
g_free(req);
}
+static const VMStateDescription vmstate_sgent = {
+ .name = "vmbus/sgentry",
+ .version_id = 0,
+ .minimum_version_id = 0,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT64(base, ScatterGatherEntry),
+ VMSTATE_UINT64(len, ScatterGatherEntry),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+typedef struct VMBusChanReqSave {
+ uint16_t chan_idx;
+ uint16_t pkt_type;
+ uint32_t msglen;
+ void *msg;
+ uint64_t transaction_id;
+ bool need_comp;
+ uint32_t num;
+ ScatterGatherEntry *sgl;
+} VMBusChanReqSave;
+
+static const VMStateDescription vmstate_vmbus_chan_req = {
+ .name = "vmbus/vmbus_chan_req",
+ .version_id = 0,
+ .minimum_version_id = 0,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT16(chan_idx, VMBusChanReqSave),
+ VMSTATE_UINT16(pkt_type, VMBusChanReqSave),
+ VMSTATE_UINT32(msglen, VMBusChanReqSave),
+ VMSTATE_VBUFFER_ALLOC_UINT32(msg, VMBusChanReqSave, 0, NULL, msglen),
+ VMSTATE_UINT64(transaction_id, VMBusChanReqSave),
+ VMSTATE_BOOL(need_comp, VMBusChanReqSave),
+ VMSTATE_UINT32(num, VMBusChanReqSave),
+ VMSTATE_STRUCT_VARRAY_POINTER_UINT32(sgl, VMBusChanReqSave, num,
+ vmstate_sgent, ScatterGatherEntry),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+void vmbus_save_req(QEMUFile *f, VMBusChanReq *req)
+{
+ VMBusChanReqSave req_save;
+
+ req_save.chan_idx = req->chan->subchan_idx;
+ req_save.pkt_type = req->pkt_type;
+ req_save.msglen = req->msglen;
+ req_save.msg = req->msg;
+ req_save.transaction_id = req->transaction_id;
+ req_save.need_comp = req->need_comp;
+ req_save.num = req->sgl.nsg;
+ req_save.sgl = g_memdup(req->sgl.sg,
+ req_save.num * sizeof(ScatterGatherEntry));
+
+ vmstate_save_state(f, &vmstate_vmbus_chan_req, &req_save, NULL);
+
+ g_free(req_save.sgl);
+}
+
+void *vmbus_load_req(QEMUFile *f, VMBusDevice *dev, uint32_t size)
+{
+ VMBusChanReqSave req_save;
+ VMBusChanReq *req = NULL;
+ VMBusChannel *chan = NULL;
+ uint32_t i;
+
+ vmstate_load_state(f, &vmstate_vmbus_chan_req, &req_save, 0);
+
+ if (req_save.chan_idx >= dev->num_channels) {
+ error_report("%s: %u(chan_idx) > %u(num_channels)", __func__,
+ req_save.chan_idx, dev->num_channels);
+ goto out;
+ }
+ chan = &dev->channels[req_save.chan_idx];
+
+ if (vmbus_channel_reserve(chan, 0, req_save.msglen)) {
+ goto out;
+ }
+
+ req = vmbus_alloc_req(chan, size, req_save.pkt_type, req_save.msglen,
+ req_save.transaction_id, req_save.need_comp);
+ if (req_save.msglen) {
+ memcpy(req->msg, req_save.msg, req_save.msglen);
+ }
+
+ for (i = 0; i < req_save.num; i++) {
+ qemu_sglist_add(&req->sgl, req_save.sgl[i].base, req_save.sgl[i].len);
+ }
+
+out:
+ if (req_save.msglen) {
+ g_free(req_save.msg);
+ }
+ if (req_save.num) {
+ g_free(req_save.sgl);
+ }
+ return req;
+}
+
static void channel_event_cb(EventNotifier *e)
{
VMBusChannel *chan = container_of(e, VMBusChannel, notifier);
diff --git a/include/hw/hyperv/vmbus.h b/include/hw/hyperv/vmbus.h
index 63a5b807b6..9219f34d6b 100644
--- a/include/hw/hyperv/vmbus.h
+++ b/include/hw/hyperv/vmbus.h
@@ -224,4 +224,7 @@ int vmbus_map_sgl(VMBusChanReq *req, DMADirection dir, struct iovec *iov,
void vmbus_unmap_sgl(VMBusChanReq *req, DMADirection dir, struct iovec *iov,
unsigned iov_cnt, size_t accessed);
+void vmbus_save_req(QEMUFile *f, VMBusChanReq *req);
+void *vmbus_load_req(QEMUFile *f, VMBusDevice *dev, uint32_t size);
+
#endif
--
2.24.1
next prev parent reply other threads:[~2020-04-24 12:40 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 12:34 [PATCH v4 0/6] hyperv: VMBus implementation Jon Doron
2020-04-24 12:34 ` [PATCH v4 1/6] hyperv: expose API to determine if synic is enabled Jon Doron
2020-04-24 12:34 ` [PATCH v4 2/6] vmbus: add vmbus protocol definitions Jon Doron
2020-04-24 12:34 ` [PATCH v4 3/6] vmbus: vmbus implementation Jon Doron
2020-04-24 12:34 ` [PATCH v4 4/6] i386:pc: whitelist dynamic vmbus-bridge Jon Doron
2020-04-24 12:34 ` [PATCH v4 5/6] i386: Hyper-V VMBus ACPI DSDT entry Jon Doron
2020-05-05 13:06 ` Igor Mammedov
2020-05-05 15:38 ` Jon Doron
2020-05-06 13:37 ` Maciej S. Szmigiero
2020-05-07 3:14 ` Jon Doron
2020-05-11 20:11 ` Roman Kagan
2020-05-13 15:37 ` Igor Mammedov
2020-05-15 8:56 ` Jon Doron
2020-05-15 12:35 ` Roman Kagan
2020-05-11 18:21 ` Roman Kagan
2020-05-13 15:34 ` Igor Mammedov
2020-05-21 16:02 ` Paolo Bonzini
2020-05-22 8:40 ` Igor Mammedow
2020-05-28 5:26 ` Jon Doron
2020-05-28 5:36 ` Jon Doron
2020-05-28 10:37 ` Igor Mammedov
2020-05-28 11:02 ` Jon Doron
2020-06-14 14:11 ` Jon Doron
2020-06-14 15:20 ` Jon Doron
2020-06-14 21:40 ` Maciej S. Szmigiero
2020-06-15 2:40 ` Jon Doron
2020-06-15 6:54 ` Maciej S. Szmigiero
2020-04-24 12:34 ` Jon Doron [this message]
2020-05-21 16:03 ` [PATCH v4 0/6] hyperv: VMBus implementation Paolo Bonzini
2020-05-22 2:53 ` Jon Doron
2020-05-22 7:19 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200424123444.3481728-7-arilou@gmail.com \
--to=arilou@gmail.com \
--cc=ehabkost@redhat.com \
--cc=eyakovlev@virtuozzo.com \
--cc=liran.alon@oracle.com \
--cc=maciej.szmigiero@oracle.com \
--cc=mail@maciej.szmigiero.name \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.com \
--cc=rvkagan@gmail.com \
--cc=vkuznets@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).