@samitouri / QOSamiQemu / commits / 2782a95ed2

migration: convert vmstate_subsection_save/load functions to bool

Convert them to bool return value, as preparation to further convertion of vmstate_save/load_state(). Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260304212303.667141-12-vsementsov@yandex-team.ru Signed-off-by: Fabiano Rosas <farosas@suse.de>

Vladimir Sementsov-Ogievskiy committed Mar 5, 2026 at 00:22 UTC 2782a95ed237af3794fd4bee616be1df3e61d1ae
1 file changed +26 -31
migration/vmstate.c
+26 -31
@@ -21,11 +21,11 @@
21 #include "qemu/error-report.h"
22 #include "trace.h"
23
24 -static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
25 - void *opaque, JSONWriter *vmdesc,
26 - Error **errp);
27 -static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
28 - void *opaque, Error **errp);
24 +static bool vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
25 + void *opaque, JSONWriter *vmdesc,
26 + Error **errp);
27 +static bool vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
28 + void *opaque, Error **errp);
29 static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
30 void *opaque, JSONWriter *vmdesc,
31 int version_id, Error **errp);
@@ -305,10 +305,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
305 }
306 assert(field->flags == VMS_END);
307
308 - ret = vmstate_subsection_load(f, vmsd, opaque, errp);
309 - if (ret != 0) {
310 - qemu_file_set_error(f, ret);
311 - return ret;
308 + if (!vmstate_subsection_load(f, vmsd, opaque, errp)) {
309 + qemu_file_set_error(f, -EINVAL);
310 + return -EINVAL;
311 }
312
313 if (!vmstate_post_load(vmsd, opaque, version_id, errp)) {
@@ -637,7 +636,7 @@ static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
636 json_writer_end_array(vmdesc);
637 }
638
640 - ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp);
639 + ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp) ? 0 : -EINVAL;
640
641 out:
642 if (vmsd->post_save) {
@@ -667,15 +666,14 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
666 errp);
667 }
668
670 -static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
671 - void *opaque, Error **errp)
669 +static bool vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
670 + void *opaque, Error **errp)
671 {
672 ERRP_GUARD();
673 trace_vmstate_subsection_load(vmsd->name);
674
675 while (qemu_peek_byte(f, 0) == QEMU_VM_SUBSECTION) {
676 char idstr[256], *idstr_ret;
678 - int ret;
677 uint8_t version_id, len, size;
678 const VMStateDescription *sub_vmsd;
679
@@ -683,12 +681,12 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
681 if (len < strlen(vmsd->name) + 1) {
682 /* subsection name has to be "section_name/a" */
683 trace_vmstate_subsection_load_bad(vmsd->name, "(short)", "");
686 - return 0;
684 + return true;
685 }
686 size = qemu_peek_buffer(f, (uint8_t **)&idstr_ret, len, 2);
687 if (size != len) {
688 trace_vmstate_subsection_load_bad(vmsd->name, "(peek fail)", "");
691 - return 0;
689 + return true;
690 }
691 memcpy(idstr, idstr_ret, size);
692 idstr[size] = 0;
@@ -696,41 +694,39 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
694 if (strncmp(vmsd->name, idstr, strlen(vmsd->name)) != 0) {
695 trace_vmstate_subsection_load_bad(vmsd->name, idstr, "(prefix)");
696 /* it doesn't have a valid subsection name */
699 - return 0;
697 + return true;
698 }
699 sub_vmsd = vmstate_get_subsection(vmsd->subsections, idstr);
700 if (sub_vmsd == NULL) {
701 trace_vmstate_subsection_load_bad(vmsd->name, idstr, "(lookup)");
702 error_setg(errp, "VM subsection '%s' in '%s' does not exist",
703 idstr, vmsd->name);
706 - return -ENOENT;
704 + return false;
705 }
706 qemu_file_skip(f, 1); /* subsection */
707 qemu_file_skip(f, 1); /* len */
708 qemu_file_skip(f, len); /* idstr */
709 version_id = qemu_get_be32(f);
710
713 - ret = vmstate_load_state(f, sub_vmsd, opaque, version_id, errp);
714 - if (ret) {
711 + if (vmstate_load_state(f, sub_vmsd, opaque, version_id, errp) < 0) {
712 trace_vmstate_subsection_load_bad(vmsd->name, idstr, "(child)");
713 error_prepend(errp,
717 - "Loading VM subsection '%s' in '%s' failed: %d: ",
718 - idstr, vmsd->name, ret);
719 - return ret;
714 + "Loading VM subsection '%s' in '%s' failed: ",
715 + idstr, vmsd->name);
716 + return false;
717 }
718 }
719
720 trace_vmstate_subsection_load_good(vmsd->name);
724 - return 0;
721 + return true;
722 }
723
727 -static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
728 - void *opaque, JSONWriter *vmdesc,
729 - Error **errp)
724 +static bool vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
725 + void *opaque, JSONWriter *vmdesc,
726 + Error **errp)
727 {
728 const VMStateDescription * const *sub = vmsd->subsections;
729 bool vmdesc_has_subsections = false;
733 - int ret = 0;
730
731 trace_vmstate_subsection_save_top(vmsd->name);
732 while (sub && *sub) {
@@ -754,9 +750,8 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
750 qemu_put_byte(f, len);
751 qemu_put_buffer(f, (uint8_t *)vmsdsub->name, len);
752 qemu_put_be32(f, vmsdsub->version_id);
757 - ret = vmstate_save_state(f, vmsdsub, opaque, vmdesc, errp);
758 - if (ret) {
759 - return ret;
753 + if (vmstate_save_state(f, vmsdsub, opaque, vmdesc, errp) < 0) {
754 + return false;
755 }
756
757 if (vmdesc) {
@@ -770,5 +765,5 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
765 json_writer_end_array(vmdesc);
766 }
767
773 - return ret;
768 + return true;
769 }