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

Re: [PATCH v10 06/25] tools/xenstore: add live update command to xenstore-control

  • To: "jgross@xxxxxxxx" <jgross@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Torok <edvin.torok@xxxxxxxxxx>
  • Date: Wed, 6 Jan 2021 14:42:05 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8dMb9EJaOWVqqPPxP4lqTFSV/+mSoUIq+yV8BMS3F34=; b=oWszoN74hY8ySe77YTLfGg/Vh307hSp1ioXCXp5Vx1QMKJBcC+wF+ixmbVVzdfGvJuVmX0uemv8R21GvJUMEd9wk49B5mUcB0a4/NrCzPGdwzjqwHZgtOdggvws+lLlTDqpH2C6HHRc0TnZryaaXBVfM+e74Yz5GPQF4dIdY4kA4lbfHNZt2/9bt5CRSPlKFRO96c/TVdoman8LpRzXl9YALNoylnAnn5+T0Yu0/R7YOF5iqXP9TgBGkFOVqvt9IeuMdcwNzmK9fnizXEFW+8I2lCWJis+StA87fL1q041OGsW5cVsHnmAIyCD0EMR7TYToP1VJWfJxc3X0d5IFj5w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YW8shd+qy1zF4Gvsc8SLfarmng5gg5RGnN6+6A+J8JWV2jS1bFxu4QoZFLa2qDNI1A1EFlf4FECL41kA60Q9K8kpvSOLkgvaxthr/Anc/D+FHslP8e2udcH7xqjFqqRhAYoC6JTgTYqL4B5MSjUYJ2AOZeaFmioxS0936sjMEjxXf07JGHSSekXH/MqaS5AmtF5s+5lY+6fJDUq9ndv54Z5rNlC9d5dF70BT0BwCeul7WbnYMNpia6OibHo1mKbvZVPrfpru1NA4GHGhzz//MmrQ41lrGTrmw2abBZpeHEoLjQiHP2HrRQgGrb/K+LbQauN5vXuFipfPETVd+uHLfw==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "jbeulich@xxxxxxxx" <jbeulich@xxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "wl@xxxxxxx" <wl@xxxxxxx>, "iwj@xxxxxxxxxxxxxx" <iwj@xxxxxxxxxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, "jgrall@xxxxxxxxxx" <jgrall@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxx>, "paul@xxxxxxx" <paul@xxxxxxx>, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Delivery-date: Wed, 06 Jan 2021 14:42:21 +0000
  • Ironport-sdr: DsGA/0Gpvef2Ct1vFUGdi7bcpg/SnaA6SsAif0ffwib8XpgaDoNGkFG+1rrR5TjJ/52zdyDYZF 35y68aiNXdvlu7gGm3L4StOc3FT1HofF01jhZ2HMjGifN3SOa2UJVDzjRTbZeHMe3eUxW/hY3S dGHw2CND+NSIssgo+QOMa3DgQEtTDNuXDvrEiLGktE1hqM8QKzzMns2T053eBJ5xU3bC1n54Tx Thwdj6ZwBtqAKpgueV3J/kfjtl7PGpbWacZLqs34dA0IAM0GjYPc5+kJxqildNXjTn/SNdjMok 4qU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHW5DasU1BxCsIJ+UqM32f3+7Ll9aoaq8UA
  • Thread-topic: [PATCH v10 06/25] tools/xenstore: add live update command to xenstore-control

On Tue, 2020-12-15 at 17:35 +0100, Juergen Gross wrote:

> [...] 
> +static int live_update_start(struct xs_handle *xsh, bool force,
> unsigned int to)
> +{
> +    int len = 0;
> +    char *buf = NULL, *ret;
> +    time_t time_start;
> +
> +    if (asprintf(&ret, "%u", to) < 0)
> +        return 1;
> +    len = add_to_buf(&buf, "-s", len);
> +    len = add_to_buf(&buf, "-t", len);
> +    len = add_to_buf(&buf, ret, len);
> +    free(ret);
> +    if (force)
> +        len = add_to_buf(&buf, "-F", len);
> +    if (len < 0)
> +        return 1;
> +
> +    for (time_start = time(NULL); time(NULL) - time_start < to;) {
> +        ret = xs_control_command(xsh, "live-update", buf, len);
> +        if (!ret)
> +            goto err;
> +        if (strcmp(ret, "BUSY"))
> +            break;
> +    }

We've discovered issues with this during testing: when a live-update is
not possible (e.g. guest with active transaction held open on purpose)
xenstored gets flooded with live-update requests until the timeout is

This is problematic for multiple reasons:
* flooding xenstored reduces its throughput, and makes it use 100% CPU.
Depending on the implementation and configuration it may also flood the
logs (which isn't fatal, the system still stays alive if you ENOSPC on
/var/log, but it makes it difficult to debug issues if a live update
gets you to ENOSPC as you may not see actual failures from after the
live update).
* flooding xenstored causes the evtchn to overflow and AFAICT neither
xenstored or oxenstored is capable of coping with that (oxenstored
infinite loops when that happens). IIUC this needs to be fixed in the
kernel, so it doesn't return EFBIG in the first place. As a workaround
I added a sleep(1) in this loop
* the timeout is hit on both client and server sides, but depending on
rounding almost always happens on the client side first which prevents
us from displaying a more informative error message from the server. As
a workaround I increased the client side timeout by 2s to cope with
rounding and give the server a chance to reply. Oxenstored can reply
with a list of domains preventing the live-update for example.

My workarounds looked like this:
@@ -42,6 +43,9 @@ static int live_update_start(struct xs_handle *xsh,
bool force, unsigned int to)
         len = add_to_buf(&buf, "-F", len);
     if (len < 0)
         return 1;
+    /* +1 for rounding issues
+     * +1 to give oxenstored a chance to timeout and report back first
+    to += 2;
     for (time_start = time(NULL); time(NULL) - time_start < to;) {
         ret = xs_control_command(xsh, "live-update", buf, len);
@@ -49,6 +53,12 @@ static int live_update_start(struct xs_handle *xsh,
bool force, unsigned int to)
             goto err;
         if (strcmp(ret, "BUSY"))
+        /* TODO: use task ID for commands, avoid busy loop polling
+         * oxenstored checks BUSY condition internally on every main
loop iteration anyway.
+         * Avoid flooding xenstored with live-update requests.
+         * The flooding can also cause the evtchn to overflow in
xenstored which makes
+         * xenstored enter an infinite loop */
+        sleep(1);

This also required various heuristics in oxenstored to differentiate
between a new live-update command and querying the status of an already
completed live-update command, otherwise I almost always ended up doing
2 live-updates in a row (first one queued up, returned BUSY, completed
after a while, and then another one from all the repeated live-update

I'd prefer it if there was a more asynchronous protocol available for
* the live-update on its own queues up the live update request and
returns a generation ID. xenstored retries on its own during each of
its main loop iterations whether the conditions for live-update are now
* when a generation ID is specified with the live-update command it
acts as a query to return the status. A query for generation ID <
current ID return success, and for generation ID = current ID it
returns either BUSY, or a specific error if known (e.g. timeout reached
and list of domains preventing live update)
* the generation ID gets incremented every time a live update succeeds
This would eliminiate the need for a client-side timeout, since each of
these commands would be non-blocking.
It'd also avoid the busy-poll flood.

Obviously any change here has to be backwards compatible with the
already deployed xenstored and oxenstored which doesn't know about
generation IDs, but you can tell them apart based on the reply: if you
get back OK/BUSY/some error it is the old version, if you get back a
generation ID it is the new version.

I ran out of time to implement this before the embargo was up, should I
go ahead with prototyping a patch for this now, or do you see an
alternative way to make the live-update command more robust?

Best regards,



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