diff mbox

[8/8] slirp: VMStatify remaining except for loop

Message ID 20161027153217.16984-9-dgilbert@redhat.com
State New
Headers show

Commit Message

Dr. David Alan Gilbert Oct. 27, 2016, 3:32 p.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

This converts the remaining components, except for the loop, to VMState.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 slirp/slirp.c | 49 ++++++++++++++++++++-----------------------------
 1 file changed, 20 insertions(+), 29 deletions(-)

Comments

Samuel Thibault Oct. 30, 2016, 2:51 p.m. UTC | #1
Hello,

Dr. David Alan Gilbert (git), on Thu 27 Oct 2016 16:32:17 +0100, wrote:
> This converts the remaining components, except for the loop, to VMState.
> 
> +        /* TODO: Add loop */
> +        VMSTATE_UINT16_V(ip_id, Slirp, 2),
> +        VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3,
> +                             vmstate_slirp_bootp_client, BOOTPClient),

I don't understand: doesn't the NB_BOOTP_CLIENTS parameter here
implement the loop?

Samuel
Dr. David Alan Gilbert Nov. 7, 2016, 7:30 p.m. UTC | #2
* Samuel Thibault (samuel.thibault@gnu.org) wrote:
> Hello,
> 
> Dr. David Alan Gilbert (git), on Thu 27 Oct 2016 16:32:17 +0100, wrote:
> > This converts the remaining components, except for the loop, to VMState.
> > 
> > +        /* TODO: Add loop */
> > +        VMSTATE_UINT16_V(ip_id, Slirp, 2),
> > +        VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3,
> > +                             vmstate_slirp_bootp_client, BOOTPClient),
> 
> I don't understand: doesn't the NB_BOOTP_CLIENTS parameter here
> implement the loop?

That implements one loop; the TODO is to add the loop over slirp->exec_list
that's at the top of slirp_state_save;  once we find a way of adding that
loop then the whole of slirp_state_save/load disappears and we're left
with just the VMStateDescription.

Dave

> Samuel
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Juan Quintela Feb. 13, 2017, 12:09 p.m. UTC | #3
"Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> This converts the remaining components, except for the loop, to VMState.
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
diff mbox

Patch

diff --git a/slirp/slirp.c b/slirp/slirp.c
index d9532d6..efb3476 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -1325,15 +1325,26 @@  static const VMStateDescription vmstate_slirp_socket = {
     }
 };
 
-static void slirp_bootp_save(QEMUFile *f, Slirp *slirp)
-{
-    int i;
+static const VMStateDescription vmstate_slirp_bootp_client = {
+    .name = "slirp_bootpclient",
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT16(allocated, BOOTPClient),
+        VMSTATE_BUFFER(macaddr, BOOTPClient),
+        VMSTATE_END_OF_LIST()
+    }
+};
 
-    for (i = 0; i < NB_BOOTP_CLIENTS; i++) {
-        qemu_put_be16(f, slirp->bootp_clients[i].allocated);
-        qemu_put_buffer(f, slirp->bootp_clients[i].macaddr, 6);
+static const VMStateDescription vmstate_slirp = {
+    .name = "slirp",
+    .version_id = 4,
+    .fields = (VMStateField[]) {
+        /* TODO: Add loop */
+        VMSTATE_UINT16_V(ip_id, Slirp, 2),
+        VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3,
+                             vmstate_slirp_bootp_client, BOOTPClient),
+        VMSTATE_END_OF_LIST()
     }
-}
+};
 
 static void slirp_state_save(QEMUFile *f, void *opaque)
 {
@@ -1353,22 +1364,10 @@  static void slirp_state_save(QEMUFile *f, void *opaque)
         }
     qemu_put_byte(f, 0);
 
-    qemu_put_be16(f, slirp->ip_id);
-
-    slirp_bootp_save(f, slirp);
+    vmstate_save_state(f, &vmstate_slirp, slirp, NULL);
 }
 
 
-static void slirp_bootp_load(QEMUFile *f, Slirp *slirp)
-{
-    int i;
-
-    for (i = 0; i < NB_BOOTP_CLIENTS; i++) {
-        slirp->bootp_clients[i].allocated = qemu_get_be16(f);
-        qemu_get_buffer(f, slirp->bootp_clients[i].macaddr, 6);
-    }
-}
-
 static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
 {
     Slirp *slirp = opaque;
@@ -1403,13 +1402,5 @@  static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
         so->extra = (void *)ex_ptr->ex_exec;
     }
 
-    if (version_id >= 2) {
-        slirp->ip_id = qemu_get_be16(f);
-    }
-
-    if (version_id >= 3) {
-        slirp_bootp_load(f, slirp);
-    }
-
-    return 0;
+    return vmstate_load_state(f, &vmstate_slirp, slirp, version_id);
 }