Re: [Xen-devel] [PATCH RFC 02/20] libxc/xc_sr: parameterise write_record() on fd

2017-03-31 Thread Wei Liu
On Mon, Mar 27, 2017 at 05:06:14AM -0400, Joshua Otto wrote:
> Right now, write_split_record() - which is delegated to by
> write_record() - implicitly writes to ctx->fd.  This means it can't be
> used with the restore context's send_back_fd, which is unhandy.
> 
> Add an 'fd' parameter to both write_record() and write_split_record(),
> and mechanically update all existing callsites to pass ctx->fd for it.
> 
> No functional change.
> 
> Signed-off-by: Joshua Otto 

Acked-by: Wei Liu 

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC 02/20] libxc/xc_sr: parameterise write_record() on fd

2017-03-28 Thread Andrew Cooper
On 27/03/17 10:06, Joshua Otto wrote:
> Right now, write_split_record() - which is delegated to by
> write_record() - implicitly writes to ctx->fd.  This means it can't be
> used with the restore context's send_back_fd, which is unhandy.

Unhelpful?

>
> Add an 'fd' parameter to both write_record() and write_split_record(),
> and mechanically update all existing callsites to pass ctx->fd for it.
>
> No functional change.
>
> Signed-off-by: Joshua Otto 

Reviewed-by: Andrew Cooper 

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH RFC 02/20] libxc/xc_sr: parameterise write_record() on fd

2017-03-27 Thread Joshua Otto
Right now, write_split_record() - which is delegated to by
write_record() - implicitly writes to ctx->fd.  This means it can't be
used with the restore context's send_back_fd, which is unhandy.

Add an 'fd' parameter to both write_record() and write_split_record(),
and mechanically update all existing callsites to pass ctx->fd for it.

No functional change.

Signed-off-by: Joshua Otto 
---
 tools/libxc/xc_sr_common.c   |  6 +++---
 tools/libxc/xc_sr_common.h   |  8 
 tools/libxc/xc_sr_common_x86.c   |  2 +-
 tools/libxc/xc_sr_save.c |  6 +++---
 tools/libxc/xc_sr_save_x86_hvm.c |  5 +++--
 tools/libxc/xc_sr_save_x86_pv.c  | 17 +
 6 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/tools/libxc/xc_sr_common.c b/tools/libxc/xc_sr_common.c
index 48fa676..c1babf6 100644
--- a/tools/libxc/xc_sr_common.c
+++ b/tools/libxc/xc_sr_common.c
@@ -52,8 +52,8 @@ const char *rec_type_to_str(uint32_t type)
 return "Reserved";
 }
 
-int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
-   void *buf, size_t sz)
+int write_split_record(struct xc_sr_context *ctx, int fd,
+   struct xc_sr_record *rec, void *buf, size_t sz)
 {
 static const char zeroes[(1u << REC_ALIGN_ORDER) - 1] = { 0 };
 
@@ -81,7 +81,7 @@ int write_split_record(struct xc_sr_context *ctx, struct 
xc_sr_record *rec,
 if ( sz )
 assert(buf);
 
-if ( writev_exact(ctx->fd, parts, ARRAY_SIZE(parts)) )
+if ( writev_exact(fd, parts, ARRAY_SIZE(parts)) )
 goto err;
 
 return 0;
diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
index a83f22a..2f33ccc 100644
--- a/tools/libxc/xc_sr_common.h
+++ b/tools/libxc/xc_sr_common.h
@@ -361,8 +361,8 @@ struct xc_sr_record
  *
  * Returns 0 on success and non0 on failure.
  */
-int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
-   void *buf, size_t sz);
+int write_split_record(struct xc_sr_context *ctx, int fd,
+   struct xc_sr_record *rec, void *buf, size_t sz);
 
 /*
  * Writes a record to the stream, applying correct padding where appropriate.
@@ -371,10 +371,10 @@ int write_split_record(struct xc_sr_context *ctx, struct 
xc_sr_record *rec,
  *
  * Returns 0 on success and non0 on failure.
  */
-static inline int write_record(struct xc_sr_context *ctx,
+static inline int write_record(struct xc_sr_context *ctx, int fd,
struct xc_sr_record *rec)
 {
-return write_split_record(ctx, rec, NULL, 0);
+return write_split_record(ctx, fd, rec, NULL, 0);
 }
 
 /*
diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c
index 98f1cef..7b3dd50 100644
--- a/tools/libxc/xc_sr_common_x86.c
+++ b/tools/libxc/xc_sr_common_x86.c
@@ -18,7 +18,7 @@ int write_tsc_info(struct xc_sr_context *ctx)
 return -1;
 }
 
-return write_record(ctx, &rec);
+return write_record(ctx, ctx->fd, &rec);
 }
 
 int handle_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec)
diff --git a/tools/libxc/xc_sr_save.c b/tools/libxc/xc_sr_save.c
index fc63a55..61fc4a4 100644
--- a/tools/libxc/xc_sr_save.c
+++ b/tools/libxc/xc_sr_save.c
@@ -53,7 +53,7 @@ static int write_end_record(struct xc_sr_context *ctx)
 {
 struct xc_sr_record end = { REC_TYPE_END, 0, NULL };
 
-return write_record(ctx, &end);
+return write_record(ctx, ctx->fd, &end);
 }
 
 /*
@@ -63,7 +63,7 @@ static int write_checkpoint_record(struct xc_sr_context *ctx)
 {
 struct xc_sr_record checkpoint = { REC_TYPE_CHECKPOINT, 0, NULL };
 
-return write_record(ctx, &checkpoint);
+return write_record(ctx, ctx->fd, &checkpoint);
 }
 
 /*
@@ -646,7 +646,7 @@ static int verify_frames(struct xc_sr_context *ctx)
 
 DPRINTF("Enabling verify mode");
 
-rc = write_record(ctx, &rec);
+rc = write_record(ctx, ctx->fd, &rec);
 if ( rc )
 goto out;
 
diff --git a/tools/libxc/xc_sr_save_x86_hvm.c b/tools/libxc/xc_sr_save_x86_hvm.c
index e485928..ea4b780 100644
--- a/tools/libxc/xc_sr_save_x86_hvm.c
+++ b/tools/libxc/xc_sr_save_x86_hvm.c
@@ -42,7 +42,7 @@ static int write_hvm_context(struct xc_sr_context *ctx)
 }
 
 hvm_rec.length = hvm_buf_size;
-rc = write_record(ctx, &hvm_rec);
+rc = write_record(ctx, ctx->fd, &hvm_rec);
 if ( rc < 0 )
 {
 PERROR("error write HVM_CONTEXT record");
@@ -112,7 +112,8 @@ static int write_hvm_params(struct xc_sr_context *ctx)
 }
 }
 
-rc = write_split_record(ctx, &rec, entries, hdr.count * sizeof(*entries));
+rc = write_split_record(ctx, ctx->fd, &rec, entries,
+hdr.count * sizeof(*entries));
 if ( rc )
 PERROR("Failed to write HVM_PARAMS record");
 
diff --git a/tools/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_pv.c
index f218d17..2b2c050 100644
--- a/tools/libxc/xc_sr_save_x86_pv.c
+++ b/tools/libxc/xc_sr_save_x86_pv.c
@@ -571,9 +