Re: [Xen-devel] [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor

2018-04-24 Thread Wei Liu
On Mon, Apr 16, 2018 at 06:32:24PM +0100, Anthony PERARD wrote:
> In case QEMU have restricted access to the system, open the file for it,
> and QEMU will save its state to this file descritor.
> 
> Signed-off-by: Anthony PERARD 

Acked-by: Wei Liu 

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

Re: [Xen-devel] [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor

2018-04-24 Thread Wei Liu
On Mon, Apr 23, 2018 at 04:45:28PM +0100, Anthony PERARD wrote:
> On Mon, Apr 23, 2018 at 10:20:42AM +0100, Wei Liu wrote:
> > On Mon, Apr 16, 2018 at 06:32:24PM +0100, Anthony PERARD wrote:
> > > In case QEMU have restricted access to the system, open the file for it,
> > > and QEMU will save its state to this file descritor.
> > > 
> > > Signed-off-by: Anthony PERARD 
> > 
> > I think this is going to break FreeBSD?
> 
> If the previous patch works on FreeBSD (Learned to send FD through QMP
> to QEMU), this patch shouldn't break anything. Looking at how
> libxl__sendmsg_fds() is implemented, and how the receive side is
> implemented in QEMU, there doesn't seems to be any difference on
> FreeBSD, so I guess it's going to work fine.
> 
> > And what is /dev/fdset exactly? I don't seem to have it on my Debian
> > workstation (with Linux 4.15). So this change can potentially be broken
> > on Linux as well?
> 
> /dev/fdset is a QEMU internal API. You can add a file descriptor to a
> fd-set via QMP or via the command line. And later, you can give a path
> to something in QEMU (maybe a block driver) which refer to a fd-set
> created earlier. The path would be "/dev/fdset/$fdset_number". There can
> be several fd in a fd-set, qemu will just look for the first one which
> have the right permission, like read or write permission.

Oh, I was thinking /dev/fdset was some sort of Linux specific thing. It
is interesting that QEMU actually creates /dev/fdset. That means it
should work fine (at least in theory) for both FreeBSD and Linux.

Wei.

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

Re: [Xen-devel] [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor

2018-04-23 Thread Anthony PERARD
On Mon, Apr 23, 2018 at 10:20:42AM +0100, Wei Liu wrote:
> On Mon, Apr 16, 2018 at 06:32:24PM +0100, Anthony PERARD wrote:
> > In case QEMU have restricted access to the system, open the file for it,
> > and QEMU will save its state to this file descritor.
> > 
> > Signed-off-by: Anthony PERARD 
> 
> I think this is going to break FreeBSD?

If the previous patch works on FreeBSD (Learned to send FD through QMP
to QEMU), this patch shouldn't break anything. Looking at how
libxl__sendmsg_fds() is implemented, and how the receive side is
implemented in QEMU, there doesn't seems to be any difference on
FreeBSD, so I guess it's going to work fine.

> And what is /dev/fdset exactly? I don't seem to have it on my Debian
> workstation (with Linux 4.15). So this change can potentially be broken
> on Linux as well?

/dev/fdset is a QEMU internal API. You can add a file descriptor to a
fd-set via QMP or via the command line. And later, you can give a path
to something in QEMU (maybe a block driver) which refer to a fd-set
created earlier. The path would be "/dev/fdset/$fdset_number". There can
be several fd in a fd-set, qemu will just look for the first one which
have the right permission, like read or write permission.

-- 
Anthony PERARD

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

Re: [Xen-devel] [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor

2018-04-23 Thread Wei Liu
On Mon, Apr 16, 2018 at 06:32:24PM +0100, Anthony PERARD wrote:
> In case QEMU have restricted access to the system, open the file for it,
> and QEMU will save its state to this file descritor.
> 
> Signed-off-by: Anthony PERARD 

I think this is going to break FreeBSD?

And what is /dev/fdset exactly? I don't seem to have it on my Debian
workstation (with Linux 4.15). So this change can potentially be broken
on Linux as well?

Wei.

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

[Xen-devel] [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor

2018-04-16 Thread Anthony PERARD
In case QEMU have restricted access to the system, open the file for it,
and QEMU will save its state to this file descritor.

Signed-off-by: Anthony PERARD 
---
 tools/libxl/libxl_qmp.c | 38 +-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 28bc2cabcd..3bb0f28bea 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -989,25 +989,61 @@ int libxl__qmp_system_wakeup(libxl__gc *gc, int domid)
 return qmp_run_command(gc, domid, "system_wakeup", NULL, NULL, NULL);
 }
 
+/* Find out which fdset have been allocated */
+static int qmp_fdset_add_fd_callback(libxl__qmp_handler *qmp,
+ const libxl__json_object *ret,
+ void *opaque)
+{
+const libxl__json_object *o;
+int fdset;
+
+o = libxl__json_map_get("fdset-id", ret, JSON_INTEGER);
+if (!o)
+return 1;
+
+fdset = libxl__json_object_get_integer(o);
+*(int*)opaque = fdset;
+return 0;
+}
+
 int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename, bool live)
 {
 libxl__json_object *args = NULL;
 libxl__qmp_handler *qmp = NULL;
 int rc;
+int state_fd;
+int new_fdset;
 
 qmp = libxl__qmp_initialize(gc, domid);
 if (!qmp)
 return ERROR_FAIL;
 
-qmp_parameters_add_string(gc, &args, "filename", (char *)filename);
+state_fd = open(filename, O_WRONLY | O_CREAT, 0600);
+if (state_fd < 0) {
+LOGED(ERROR, domid,
+  "Failed to open file %s for QEMU", filename);
+goto out;
+}
+
+qmp->fd_to_send = state_fd;
+
+rc = qmp_synchronous_send(qmp, "add-fd", NULL,
+  qmp_fdset_add_fd_callback, &new_fdset,
+  qmp->timeout);
+if (rc)
+goto out;
 
 /* live parameter was added to QEMU 2.11. It signal QEMU that the save
  * operation is for a live migration rather that for taking a snapshot. */
 if (qmp_qemu_check_version(qmp, 2, 11, 0))
 qmp_parameters_add_bool(gc, &args, "live", live);
 
+QMP_PARAMETERS_SPRINTF(&args, "filename", "/dev/fdset/%d", new_fdset);
 rc = qmp_synchronous_send(qmp, "xen-save-devices-state", args,
   NULL, NULL, qmp->timeout);
+out:
+if (state_fd >= 0)
+close(state_fd);
 libxl__qmp_close(qmp);
 return rc;
 }
-- 
Anthony PERARD


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