Received: from eggs.gnu.org ([2001:4830:134:3::10]:57590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4o6h-0007hk-Uj for qemu-devel@nongnu.org; Thu, 10 Nov 2016 07:05:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4o6d-0002xG-Sh for qemu-devel@nongnu.org; Thu, 10 Nov 2016 07:05:27 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39307 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c4o6d-0002wQ-MP for qemu-devel@nongnu.org; Thu, 10 Nov 2016 07:05:23 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAAC3cXG080543 for ; Thu, 10 Nov 2016 07:05:22 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 26mr1ek3bd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 10 Nov 2016 07:05:22 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Nov 2016 12:05:20 -0000 References: <1478563599-4228-1-git-send-email-duanj@linux.vnet.ibm.com> <1478563599-4228-3-git-send-email-duanj@linux.vnet.ibm.com> From: Halil Pasic Date: Thu, 10 Nov 2016 13:04:50 +0100 MIME-Version: 1.0 In-Reply-To: <1478563599-4228-3-git-send-email-duanj@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qjGjc7HQGlKHlEn7ej2srnbnBVCtEXUpM" Message-Id: <9f503432-46b8-2e6a-8d8a-3cc1d628e8b8@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [QEMU PATCH v12 2/4] migration: migrate QTAILQ List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jianjun Duan , qemu-devel@nongnu.org Cc: veroniabahaa@gmail.com, peter.maydell@linaro.org, dgilbert@redhat.com, mst@redhat.com, quintela@redhat.com, mark.cave-ayland@ilande.co.uk, mdroth@linux.vnet.ibm.com, mreitz@redhat.com, blauwirbel@gmail.com, amit.shah@redhat.com, qemu-ppc@nongnu.org, kraxel@redhat.com, kwolf@redhat.com, dmitry@daynix.com, pbonzini@redhat.com, rth@twiddle.net, leon.alrae@imgtec.com, aurelien@aurel32.net, david@gibson.dropbear.id.au This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --qjGjc7HQGlKHlEn7ej2srnbnBVCtEXUpM From: Halil Pasic To: Jianjun Duan , qemu-devel@nongnu.org Cc: veroniabahaa@gmail.com, peter.maydell@linaro.org, dgilbert@redhat.com, mst@redhat.com, quintela@redhat.com, mark.cave-ayland@ilande.co.uk, mdroth@linux.vnet.ibm.com, mreitz@redhat.com, blauwirbel@gmail.com, amit.shah@redhat.com, qemu-ppc@nongnu.org, kraxel@redhat.com, kwolf@redhat.com, dmitry@daynix.com, pbonzini@redhat.com, rth@twiddle.net, leon.alrae@imgtec.com, aurelien@aurel32.net, david@gibson.dropbear.id.au Message-ID: <9f503432-46b8-2e6a-8d8a-3cc1d628e8b8@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [QEMU PATCH v12 2/4] migration: migrate QTAILQ References: <1478563599-4228-1-git-send-email-duanj@linux.vnet.ibm.com> <1478563599-4228-3-git-send-email-duanj@linux.vnet.ibm.com> In-Reply-To: <1478563599-4228-3-git-send-email-duanj@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 11/08/2016 01:06 AM, Jianjun Duan wrote: > Currently we cannot directly transfer a QTAILQ instance because of the > limitation in the migration code. Here we introduce an approach to > transfer such structures. We created VMStateInfo vmstate_info_qtailq > for QTAILQ. Similar VMStateInfo can be created for other data structure= s > such as list. >=20 > When a QTAILQ is migrated from source to target, it is appended to the > corresponding QTAILQ structure, which is assumed to have been properly > initialized. >=20 > This approach will be used to transfer pending_events and ccs_list in s= papr > state. >=20 > We also create some macros in qemu/queue.h to access a QTAILQ using poi= nter > arithmetic. This ensures that we do not depend on the implementation > details about QTAILQ in the migration code. >=20 > Signed-off-by: Jianjun Duan > --- > include/migration/vmstate.h | 20 +++++++++++++ > include/qemu/queue.h | 60 +++++++++++++++++++++++++++++++++++++= ++ > migration/trace-events | 4 +++ > migration/vmstate.c | 69 +++++++++++++++++++++++++++++++++++++= ++++++++ > 4 files changed, 153 insertions(+) >=20 > diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h > index eafc8f2..6289327 100644 > --- a/include/migration/vmstate.h > +++ b/include/migration/vmstate.h > @@ -253,6 +253,7 @@ extern const VMStateInfo vmstate_info_timer; > extern const VMStateInfo vmstate_info_buffer; > extern const VMStateInfo vmstate_info_unused_buffer; > extern const VMStateInfo vmstate_info_bitmap; > +extern const VMStateInfo vmstate_info_qtailq; >=20 > #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) > #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) > @@ -664,6 +665,25 @@ extern const VMStateInfo vmstate_info_bitmap; > .offset =3D offsetof(_state, _field), = \ > } >=20 > +/* For QTAILQ that need customized handling. What do you mean by customized handling? How does non-customized handling look like? I would also add something like works only for movable elements/nodes to make it clear that scenarios like Juan has pointed out previously are not currently supported. > + * Target QTAILQ needs be properly initialized. Could this restriction be avoided by doing (1)? > + * _type: type of QTAILQ element > + * _next: name of QTAILQ entry field in QTAILQ element > + * _vmsd: VMSD for QTAILQ element > + * size: size of QTAILQ element > + * start: offset of QTAILQ entry in QTAILQ element > + */ > +#define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next= ) \ > +{ = \ > + .name =3D (stringify(_field)), = \ > + .version_id =3D (_version), = \ > + .vmsd =3D &(_vmsd), = \ > + .size =3D sizeof(_type), = \ > + .info =3D &vmstate_info_qtailq, = \ > + .offset =3D offsetof(_state, _field), = \ > + .start =3D offsetof(_type, _next), = \ > +} > + > /* _f : field name > _f_n : num of elements field_name > _n : num of elements > diff --git a/include/qemu/queue.h b/include/qemu/queue.h > index 342073f..75616e1 100644 > --- a/include/qemu/queue.h > +++ b/include/qemu/queue.h > @@ -438,4 +438,64 @@ struct { = \ > #define QTAILQ_PREV(elm, headname, field) \ > (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) >=20 > +#define field_at_offset(base, offset, type) = \ > + ((type) (((char *) (base)) + (offset))) > + > +typedef struct DUMMY_Q_ENTRY DUMMY_Q_ENTRY; > +typedef struct DUMMY_Q DUMMY_Q; > + > +struct DUMMY_Q_ENTRY { > + QTAILQ_ENTRY(DUMMY_Q_ENTRY) next; > +}; > + > +struct DUMMY_Q { > + QTAILQ_HEAD(DUMMY_Q_HEAD, DUMMY_Q_ENTRY) head; > +}; > + > +#define dummy_q ((DUMMY_Q *) 0) > +#define dummy_qe ((DUMMY_Q_ENTRY *) 0) > + > +/* > + * Offsets of layout of a tail queue head. > + */ > +#define QTAILQ_FIRST_OFFSET (offsetof(typeof(dummy_q->head), tqh_first= )) > +#define QTAILQ_LAST_OFFSET (offsetof(typeof(dummy_q->head), tqh_last)= ) > +/* > + * Raw access of elements of a tail queue > + */ > +#define QTAILQ_RAW_FIRST(head) = \ > + (*field_at_offset(head, QTAILQ_FIRST_OFFSET, void **)) > +#define QTAILQ_RAW_LAST(head) = \ > + (*field_at_offset(head, QTAILQ_LAST_OFFSET, void ***)) > + > +/* > + * Offsets of layout of a tail queue element. > + */ > +#define QTAILQ_NEXT_OFFSET (offsetof(typeof(dummy_qe->next), tqe_next)= ) > +#define QTAILQ_PREV_OFFSET (offsetof(typeof(dummy_qe->next), tqe_prev)= ) > + > +/* > + * Raw access of elements of a tail entry > + */ > +#define QTAILQ_RAW_NEXT(elm, entry) = \ > + (*field_at_offset(elm, entry + QTAILQ_NEXT_OFFSET, void **)) > +#define QTAILQ_RAW_PREV(elm, entry) = \ > + (*field_at_offset(elm, entry + QTAILQ_PREV_OFFSET, void ***)) AFAIU QTAILQ_RAW_PREV and QTAILQ_PREV have completely different semantic.= Don't think its quite likely anybody will need QTAILQ_RAW_PREV with the QTAILQ_PREV semantic (that is pointer to the previous element -- and not to the prev next), nevertheless I think picking a different name would be a good idea. How about using QTAILQ_RAW_TQE_NEXT and QTAILQ_RAW_TQE_PR= EV instead? > +/* > + * Tail queue tranversal using pointer arithmetic. > + */ > +#define QTAILQ_RAW_FOREACH(elm, head, entry) = \ > + for ((elm) =3D QTAILQ_RAW_FIRST(head); = \ > + (elm); = \ > + (elm) =3D QTAILQ_RAW_NEXT(elm, entry)) > +/* > + * Tail queue insertion using pointer arithmetic. > + */ > +#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry) do { = \ > + QTAILQ_RAW_NEXT(elm, entry) =3D NULL; = \ > + QTAILQ_RAW_PREV(elm, entry) =3D QTAILQ_RAW_LAST(head); = \ > + *QTAILQ_RAW_LAST(head) =3D (elm); = \ > + QTAILQ_RAW_LAST(head) =3D &QTAILQ_RAW_NEXT(elm, entry); = \ > +} while (/*CONSTCOND*/0) > + > #endif /* QEMU_SYS_QUEUE_H */ > diff --git a/migration/trace-events b/migration/trace-events > index 94134f7..c46f9e9 100644 > --- a/migration/trace-events > +++ b/migration/trace-events > @@ -52,6 +52,10 @@ vmstate_n_elems(const char *name, int n_elems) "%s: = %d" > vmstate_subsection_load(const char *parent) "%s" > vmstate_subsection_load_bad(const char *parent, const char *sub, cons= t char *sub2) "%s: %s/%s" > vmstate_subsection_load_good(const char *parent) "%s" > +get_qtailq(const char *name, int version_id) "%s v%d" > +get_qtailq_end(const char *name, const char *reason, int val) "%s %s/%= d" > +put_qtailq(const char *name, int version_id) "%s v%d" > +put_qtailq_end(const char *name, const char *reason) "%s %s" >=20 > # migration/qemu-file.c > qemu_file_fclose(void) "" > diff --git a/migration/vmstate.c b/migration/vmstate.c > index 7b4bd6e..2f9d4ba 100644 > --- a/migration/vmstate.c > +++ b/migration/vmstate.c > @@ -5,6 +5,7 @@ > #include "migration/vmstate.h" > #include "qemu/bitops.h" > #include "qemu/error-report.h" > +#include "qemu/queue.h" > #include "trace.h" > #include "migration/qjson.h" >=20 > @@ -965,3 +966,71 @@ const VMStateInfo vmstate_info_bitmap =3D { > .get =3D get_bitmap, > .put =3D put_bitmap, > }; > + > +/* get for QTAILQ > + * meta data about the QTAILQ is encoded in a VMStateField structure > + */ > +static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size, > + VMStateField *field) > +{ > + int ret =3D 0; > + const VMStateDescription *vmsd =3D field->vmsd; > + /* size of a QTAILQ element */ > + size_t size =3D field->size; > + /* offset of the QTAILQ entry in a QTAILQ element */ > + size_t entry_offset =3D field->start; > + int version_id =3D field->version_id; > + void *elm; > + > + trace_get_qtailq(vmsd->name, version_id); > + if (version_id > vmsd->version_id) { > + error_report("%s %s", vmsd->name, "too new"); > + trace_get_qtailq_end(vmsd->name, "too new", -EINVAL); > + > + return -EINVAL; > + } > + if (version_id < vmsd->minimum_version_id) { > + error_report("%s %s", vmsd->name, "too old"); > + trace_get_qtailq_end(vmsd->name, "too old", -EINVAL); > + return -EINVAL; > + } > + (1) Why not do =20 + QTAILQ_INIT((DUMMY_Q *)pv); Halil > + while (qemu_get_byte(f)) { > + elm =3D g_malloc(size); > + ret =3D vmstate_load_state(f, vmsd, elm, version_id); > + if (ret) { > + return ret; > + } > + QTAILQ_RAW_INSERT_TAIL(pv, elm, entry_offset); > + } > + > + trace_get_qtailq_end(vmsd->name, "end", ret); > + return ret; > +} > + > +/* put for QTAILQ */ > +static int put_qtailq(QEMUFile *f, void *pv, size_t unused_size, > + VMStateField *field, QJSON *vmdesc) > +{ > + const VMStateDescription *vmsd =3D field->vmsd; > + /* offset of the QTAILQ entry in a QTAILQ element*/ > + size_t entry_offset =3D field->start; > + void *elm; > + > + trace_put_qtailq(vmsd->name, vmsd->version_id); > + > + QTAILQ_RAW_FOREACH(elm, pv, entry_offset) { > + qemu_put_byte(f, true); > + vmstate_save_state(f, vmsd, elm, vmdesc); > + } > + qemu_put_byte(f, false); > + > + trace_put_qtailq_end(vmsd->name, "end"); > + > + return 0; > +} > +const VMStateInfo vmstate_info_qtailq =3D { > + .name =3D "qtailq", > + .get =3D get_qtailq, > + .put =3D put_qtailq, > +}; >=20 --qjGjc7HQGlKHlEn7ej2srnbnBVCtEXUpM Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iQIcBAEBAgAGBQJYJGJ7AAoJEA0vhuyXGx0At1AQALJ4RiE+pzDTu+wGPUfOL9W5 7ROb59S99S+kJ68bCsrx12WyW1zS41do8Qo7iVukgMAPUFDc1mnHhrpAo0OTCmYV 7i6iE4FKJMPXXcfavuUQaMN2b0ahooGK+/hYoGZSJzv0tGtYlfQ9TgyRikYMTVL5 qs/NnYzPSKh41/04SMBN3PvoHPuzwPA/LOM1Wcv94yf8ABn83kPbd5Wyxc5YYzB9 FJ+4Z+oC1KJyZL/Qdx+ogkb2tDMdkivYEtCqRkhkp9xUbngvw0/maKAve+Tzpq5O cM7/Q6L+FWOthRcCxCrQRh24vOJbG1InbVhs/9HEvdDeaaEs/PXeE6AK0NyghlzY X7rZ6qPEybIuaPa2wVoYsPOdpIEkDQQ53mlVEelatGMBP4zR35IznpWOuGliAiHq sMTj+8SgiCqZZRNvPYXp6zcXcr7axz8sREwVFDZXc06RtHAx/gB10qikJicepS0Q 3L42AF0T24TAzVX26IDDUAzGBj62goKKema9rOVaBQgPvs01K+fxGbcoMvZw9t0h FREg+I2//2P8yRt+Jk4hhjHC+KU6PL3o32XdsFfU1AAvzUJN4BUuznkqlYws/XfZ GH3XF9eksqsWH4UmqrgexqxBqfvdILNflbwaCEeaD9m8hxRQ4MKRiWgB7/BIFRSH 0TRFpglw7DeglWbpyBzr =dR6c -----END PGP SIGNATURE----- --qjGjc7HQGlKHlEn7ej2srnbnBVCtEXUpM--