migration: Propagate error in postcopy setup functions
Modernize error handling in postcopy_ram_incoming_setup() and postcopy_temp_pages_setup() by replacing error_reports and local error handling with standard Error propagation. Replace use of strerror() on errno with error_setg_errno() for modular handling of errors and change return values to -1 on failure as no caller checks the actual return value. Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Juraj Marcin <jmarcin@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de>
Aadeshveer Singh committed
Aug 16, 2026 at 23:16 UTC
abde49761ab12a8c5b00ba06e7075f0a9aa76b95
2 files changed
+19
-26
migration/postcopy-ram.c
+18
-25
@@ -1462,10 +1462,9 @@ retry:
1462
return NULL;
1463
}
1464
1465
-static int postcopy_temp_pages_setup(MigrationIncomingState *mis)
1465
+static int postcopy_temp_pages_setup(MigrationIncomingState *mis, Error **errp)
1466
{
1467
PostcopyTmpPage *tmp_page;
1468
- int err;
1468
unsigned i, channels;
1469
void *temp_page;
1470
@@ -1485,11 +1484,11 @@ static int postcopy_temp_pages_setup(MigrationIncomingState *mis)
1484
temp_page = mmap(NULL, mis->largest_page_size, PROT_READ | PROT_WRITE,
1485
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1486
if (temp_page == MAP_FAILED) {
1488
- err = errno;
1489
- error_report("%s: Failed to map postcopy_tmp_pages[%d]: %s",
1490
- __func__, i, strerror(err));
1487
+ error_setg_errno(errp, errno,
1488
+ "%s: Failed to map postcopy_tmp_pages[%d]",
1489
+ __func__, i);
1490
/* Clean up will be done later */
1492
- return -err;
1491
+ return -1;
1492
}
1493
tmp_page->tmp_huge_page = temp_page;
1494
/* Initialize default states for each tmp page */
@@ -1503,11 +1502,10 @@ static int postcopy_temp_pages_setup(MigrationIncomingState *mis)
1502
PROT_READ | PROT_WRITE,
1503
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1504
if (mis->postcopy_tmp_zero_page == MAP_FAILED) {
1506
- err = errno;
1505
mis->postcopy_tmp_zero_page = NULL;
1508
- error_report("%s: Failed to map large zero page %s",
1509
- __func__, strerror(err));
1510
- return -err;
1506
+ error_setg_errno(errp, errno, "%s: Failed to map large zero page",
1507
+ __func__);
1508
+ return -1;
1509
}
1510
1511
memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size);
@@ -1515,15 +1513,13 @@ static int postcopy_temp_pages_setup(MigrationIncomingState *mis)
1513
return 0;
1514
}
1515
1518
-int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
1516
+int postcopy_ram_incoming_setup(MigrationIncomingState *mis, Error **errp)
1517
{
1520
- Error *local_err = NULL;
1521
-
1518
/* Open the fd for the kernel to give us userfaults */
1519
mis->userfault_fd = uffd_open(O_CLOEXEC | O_NONBLOCK);
1520
if (mis->userfault_fd == -1) {
1525
- error_report("%s: Failed to open userfault fd: %s", __func__,
1526
- strerror(errno));
1521
+ error_setg_errno(errp, errno, "%s: Failed to open userfault fd",
1522
+ __func__);
1523
return -1;
1524
}
1525
@@ -1531,8 +1527,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
1527
* Although the host check already tested the API, we need to
1528
* do the check again as an ABI handshake on the new fd.
1529
*/
1534
- if (!ufd_check_and_apply(mis->userfault_fd, mis, &local_err)) {
1535
- error_report_err(local_err);
1530
+ if (!ufd_check_and_apply(mis->userfault_fd, mis, errp)) {
1531
return -1;
1532
}
1533
@@ -1544,8 +1539,8 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
1539
/* Now an eventfd we use to tell the fault-thread to quit */
1540
mis->userfault_event_fd = eventfd(0, EFD_CLOEXEC);
1541
if (mis->userfault_event_fd == -1) {
1547
- error_report("%s: Opening userfault_event_fd: %s", __func__,
1548
- strerror(errno));
1542
+ error_setg_errno(errp, errno, "%s: Opening userfault_event_fd",
1543
+ __func__);
1544
close(mis->userfault_fd);
1545
return -1;
1546
}
@@ -1557,12 +1552,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
1552
1553
/* Mark so that we get notified of accesses to unwritten areas */
1554
if (foreach_not_ignored_block(ram_block_enable_notify, mis)) {
1560
- error_report("ram_block_enable_notify failed");
1555
+ error_setg(errp, "ram_block_enable_notify failed");
1556
return -1;
1557
}
1558
1564
- if (postcopy_temp_pages_setup(mis)) {
1565
- /* Error dumped in the sub-function */
1559
+ if (postcopy_temp_pages_setup(mis, errp)) {
1560
return -1;
1561
}
1562
@@ -1727,7 +1721,7 @@ int postcopy_request_shared_page(struct PostCopyFD *pcfd, RAMBlock *rb,
1721
g_assert_not_reached();
1722
}
1723
1730
-int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
1724
+int postcopy_ram_incoming_setup(MigrationIncomingState *mis, Error **errp)
1725
{
1726
g_assert_not_reached();
1727
}
@@ -2199,9 +2193,8 @@ int postcopy_incoming_setup(MigrationIncomingState *mis, Error **errp)
2193
* shouldn't be doing anything yet so don't actually expect requests
2194
*/
2195
if (migrate_postcopy_ram()) {
2202
- if (postcopy_ram_incoming_setup(mis)) {
2196
+ if (postcopy_ram_incoming_setup(mis, errp)) {
2197
postcopy_ram_incoming_cleanup(mis);
2204
- error_setg(errp, "Failed to setup incoming postcopy RAM blocks");
2198
return -1;
2199
}
2200
}
migration/postcopy-ram.h
+1
-1
@@ -23,7 +23,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis,
23
* Make all of RAM sensitive to accesses to areas that haven't yet been written
24
* and wire up anything necessary to deal with it.
25
*/
26
-int postcopy_ram_incoming_setup(MigrationIncomingState *mis);
26
+int postcopy_ram_incoming_setup(MigrationIncomingState *mis, Error **errp);
27
28
/*
29
* Initialise postcopy-ram, setting the RAM to a state where we can go into