[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] tools/migration: Fix iovec handling in send_checkpoint_dirty_pfn_list()


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 6 Jul 2021 12:23:31 +0100
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Olaf Hering <olaf@xxxxxxxxx>
  • Delivery-date: Tue, 06 Jul 2021 11:23:47 +0000
  • Ironport-hdrordr: A9a23:lf5To6jEoRhZK+xUoMKfhC8VmXBQXt4ji2hC6mlwRA09TySZ// rOoB17726NtN9/YgBCpTntAsa9qDbnhPpICOoqTM6ftWvdyQmVxehZhOOIqVCNJ8S9zJ876U 4JSdkZNDSaNzhHZKjBjjVQa+xQpeW6zA==
  • Ironport-sdr: cJG1nD6OlySdVDO7OU4ZcDYtinLX1HmYx2Sdn+YbdnWe6ytqItuFdPSiiC1oXplhmHHUsfIT+J nEQXt27PAMAXSnIyXAPeif3PyZ17bLnm4G+33DbO7HJD7Q7A0z2qEpcOXKH4e6Wj7ejmGIVje0 FIi3tIrTdS02SeDmwAfPaYbSKXoXHL0OvMBcRue3GIXjRCPWise7o0RgyPEFRHpRyrWyx9xk9S 211G5EjGjgm4CotTN3GM+Z0g0ckgFyNr32Ei69yX6Oj1QmVKUpQVusBDavHp2tYxw/KGiFoeQt KbY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

We shouldn't be using two struct iovec's to write half of 'rec' each, and
there is no need to malloc() for two struct iovec's at all.

Simplify down to just two - one covering the whole of 'rec', and one covering
the pfns array.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Ian Jackson <iwj@xxxxxxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Juergen Gross <jgross@xxxxxxxx>
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Olaf Hering <olaf@xxxxxxxxx>
---
 tools/libs/guest/xg_sr_restore.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_restore.c
index aa4113d7f679..07c9e291610b 100644
--- a/tools/libs/guest/xg_sr_restore.c
+++ b/tools/libs/guest/xg_sr_restore.c
@@ -425,11 +425,13 @@ static int send_checkpoint_dirty_pfn_list(struct 
xc_sr_context *ctx)
     int rc = -1;
     unsigned int count, written;
     uint64_t i, *pfns = NULL;
-    struct iovec *iov = NULL;
     xc_shadow_op_stats_t stats = { 0, ctx->restore.p2m_size };
     struct xc_sr_record rec = {
         .type = REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST,
     };
+    struct iovec iov[2] = {
+        { &rec, sizeof(rec) },
+    };
     DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                     &ctx->restore.dirty_bitmap_hbuf);
 
@@ -471,26 +473,12 @@ static int send_checkpoint_dirty_pfn_list(struct 
xc_sr_context *ctx)
         pfns[written++] = i;
     }
 
-    /* iovec[] for writev(). */
-    iov = malloc(3 * sizeof(*iov));
-    if ( !iov )
-    {
-        ERROR("Unable to allocate memory for sending dirty bitmap");
-        goto err;
-    }
-
     rec.length = count * sizeof(*pfns);
 
-    iov[0].iov_base = &rec.type;
-    iov[0].iov_len = sizeof(rec.type);
-
-    iov[1].iov_base = &rec.length;
-    iov[1].iov_len = sizeof(rec.length);
-
-    iov[2].iov_base = pfns;
-    iov[2].iov_len = count * sizeof(*pfns);
+    iov[1].iov_base = pfns;
+    iov[1].iov_len = rec.length;
 
-    if ( writev_exact(ctx->restore.send_back_fd, iov, 3) )
+    if ( writev_exact(ctx->restore.send_back_fd, iov, ARRAY_SIZE(iov)) )
     {
         PERROR("Failed to write dirty bitmap to stream");
         goto err;
@@ -499,7 +487,6 @@ static int send_checkpoint_dirty_pfn_list(struct 
xc_sr_context *ctx)
     rc = 0;
  err:
     free(pfns);
-    free(iov);
     return rc;
 }
 
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.