qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: qemu-devel@nongnu.org
Cc: xen-devel@lists.xensource.com, Ian.Jackson@eu.citrix.com,
	Ian.Campbell@citrix.com,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [Qemu-devel] [PATCH v2 1/2] xen: separate the xenstore_record_dm_state calls for pv and hvm machines
Date: Thu, 4 Jun 2015 12:21:55 +0100	[thread overview]
Message-ID: <1433416916-3255-1-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1506041218360.19838@kaball.uk.xensource.com>

The following patch will introduce a new option to restrict the
privilege of the xenstore connection. In that case, we do not want to
use multiple xenstore connections, but just the one, with lower
privileges.

For this reason, split the xenstore_record_dm_state calls for pv and hvm
machines, so that in the hvm case QEMU will reuse the same xenstore
connection. (At the moment it opens two and uses the second one for the
xenstore_record_dm_state call.)

As the xenstore_record_dm_state is not very useful anymore, just remove
it.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---
Changes in v2:

- remove xenstore_record_dm_state and open code the xenstore write
instead
---
 hw/xenpv/xen_machine_pv.c |   10 ++++++++++
 xen-common.c              |   29 -----------------------------
 xen-hvm.c                 |    7 +++++++
 3 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c
index 2e545d2..68758a0 100644
--- a/hw/xenpv/xen_machine_pv.c
+++ b/hw/xenpv/xen_machine_pv.c
@@ -45,6 +45,16 @@ static void xen_init_pv(MachineState *machine)
     switch (xen_mode) {
     case XEN_ATTACH:
         /* nothing to do, xend handles everything */
+        {
+            char path[50];
+            /* record state running */
+            snprintf(path, sizeof (path), "device-model/%u/state", xen_domid);
+            if (!xs_write(xenstore, XBT_NULL, path, "running", strlen("running"))) {
+                fprintf(stderr, "error recording state\n");
+                exit(1);
+            }
+        }
+
         break;
     case XEN_CREATE:
         if (xen_domain_build_pv(kernel_filename, initrd_filename,
diff --git a/xen-common.c b/xen-common.c
index 56359ca..5573c9e 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -83,33 +83,6 @@ void xenstore_store_pv_console_info(int i, CharDriverState *chr)
     }
 }
 
-
-static void xenstore_record_dm_state(struct xs_handle *xs, const char *state)
-{
-    char path[50];
-
-    if (xs == NULL) {
-        fprintf(stderr, "xenstore connection not initialized\n");
-        exit(1);
-    }
-
-    snprintf(path, sizeof (path), "device-model/%u/state", xen_domid);
-    if (!xs_write(xs, XBT_NULL, path, state, strlen(state))) {
-        fprintf(stderr, "error recording dm state\n");
-        exit(1);
-    }
-}
-
-
-static void xen_change_state_handler(void *opaque, int running,
-                                     RunState state)
-{
-    if (running) {
-        /* record state running */
-        xenstore_record_dm_state(xenstore, "running");
-    }
-}
-
 static int xen_init(MachineState *ms)
 {
     xen_xc = xen_xc_interface_open(0, 0, 0);
@@ -117,8 +90,6 @@ static int xen_init(MachineState *ms)
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         return -1;
     }
-    qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
-
     return 0;
 }
 
diff --git a/xen-hvm.c b/xen-hvm.c
index 315864c..8079b8e 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -1107,7 +1107,14 @@ static void xen_hvm_change_state_handler(void *opaque, int running,
     XenIOState *state = opaque;
 
     if (running) {
+        char path[50];
         xen_main_loop_prepare(state);
+
+        snprintf(path, sizeof (path), "device-model/%u/state", xen_domid);
+        if (!xs_write(state->xenstore, XBT_NULL, path, "running", strlen("running"))) {
+            fprintf(stderr, "error recording state\n");
+            exit(1);
+        }
     }
 
     xen_set_ioreq_server_state(xen_xc, xen_domid,
-- 
1.7.10.4

  reply	other threads:[~2015-06-04 11:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-04 11:20 [Qemu-devel] [PATCH v2 0/2] restrict the privilege of the xenstore connection Stefano Stabellini
2015-06-04 11:21 ` Stefano Stabellini [this message]
2015-06-04 11:21 ` [Qemu-devel] [PATCH v2 2/2] xen: introduce xsrestrict Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1433416916-3255-1-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).