xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@citrix.com>
To: Anthony PERARD <anthony.perard@citrix.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Wei Liu <wei.liu2@citrix.com>
Subject: Re: [Xen-devel] [PATCH 4/9] libxl_internal: Create new lock for devices hotplug via QMP
Date: Tue, 4 Jun 2019 18:11:23 +0100	[thread overview]
Message-ID: <23798.42555.428964.824573@mariner.uk.xensource.com> (raw)
In-Reply-To: <20190409164542.30274-5-anthony.perard@citrix.com>

Anthony PERARD writes ("[PATCH 4/9] libxl_internal: Create new lock for devices hotplug via QMP"):
> The current lock `domain_userdata_lock' can't be used when modification
> to a guest is done by sending command to QEMU, this is a slow process
> and requires to call CTX_UNLOCK, which is not possible while holding
> the `domain_userdata_lock'.
...
> +struct libxl__domain_qmp_lock {
> +    libxl__generic_lock lock;
> +};
> +
> +libxl__domain_qmp_lock *libxl__lock_domain_qmp(libxl__gc *gc,
> +                                               libxl_domid domid)
> +{
> +    libxl__domain_qmp_lock *lock = NULL;
> +    int rc;
> +
> +    lock = libxl__zalloc(NOGC, sizeof(*lock));
> +    rc = libxl__lock_generic(gc, domid, &lock->lock,
> +                             "libxl-device-changes-lock");
> +    if (rc) {
> +        libxl__unlock_domain_qmp(lock);
> +        return NULL;
> +    }
> +
> +    return lock;

This is almost identical to the libxl__lock_domain_userdata which
appeared in the previous patch.  That suggests that the factorisation
here is at the wrong layer.

> +void libxl__unlock_domain_qmp(libxl__domain_qmp_lock *lock)
> +{
> +    libxl__unlock_generic(&lock->lock);
> +    free(lock);
> +}

This is completely identical to libxl__unlock_domain_userdata.  The
only reason we have to two of these is so that the two locks are
distinguished by the type of the lock struct.  That means that you
have to call
   libxl__unlock_domain_qmp(foo->qmp_lock)
but
   libxl__unlock_domain_userdate(foo->userdata_lock)
or some such, and the compiler will spot if you write
   libxl__unlock_domain_userdata(foo->qmp_lock)
or something.  But is it really useful to have to write the `qmp' vs
`userdata' thing twice ?

> + * It is to be acquired by an ao event callback.

I think there is a worse problem here, though.  This lock is probably
*inside* some lock from the caller.  So usual libxl rules apply and
you may not block to acquaire it.

Ie libxl__lock_domain_qmp must be one of these things that takes a
little ev state struct and makes a callback.

At the syscall level, acquiring an fcntl lock cannot be selected on.
The options are to poll, or to spawn a thread, or to fork.

Currently libxl does not call pthread_create, although maybe it could
do.  To safely create a thread you have to do a dance with
sigprocmask, to avoid signal delivery onto your thread.

Maybe it would be better to try once with LOCK_NB, and to fork if this
is not successful.  But it would be simpler to always fork...

> + * Or in case QEMU is the primary config, this pattern can be use:
> + *   lock qmp (qmp_lock)
> + *      lock json config (json_lock)
> + *          read json config
> + *          update in-memory json config with new entry, replacing
> + *             any stale entry
> + *      unlock json config
> + *      apply new config to primary config
> + *      lock json config (json_lock)
> + *          read json config
> + *          update in-memory json config with new entry, replacing
> + *             any stale entry
> + *          write in-memory json config to disk
> + *      unlock json config
> + *   unlock qmp

This doesn't show the ctx locks but I think that is fine.  So I think
this description is correct.

Ian.

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

  parent reply	other threads:[~2019-06-04 17:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 16:45 [PATCH 0/9] libxl: New slow lock + fix libxl_cdrom_insert with QEMU depriv Anthony PERARD
2019-04-09 16:45 ` [Xen-devel] " Anthony PERARD
2019-04-09 16:45 ` [PATCH 1/9] libxl_internal: Remove lost comment Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-04-10  9:18   ` Wei Liu
2019-04-10  9:18     ` [Xen-devel] " Wei Liu
2019-06-04 16:42   ` Ian Jackson
2019-04-09 16:45 ` [PATCH 2/9] libxl: Pointer on usage of libxl__domain_userdata_lock Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 16:46   ` Ian Jackson
2019-04-09 16:45 ` [PATCH 3/9] libxl_internal: Split out userdata lock function Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 16:55   ` Ian Jackson
2019-04-09 16:45 ` [PATCH 4/9] libxl_internal: Create new lock for devices hotplug via QMP Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 17:11   ` Ian Jackson [this message]
2019-06-05 14:10     ` Anthony PERARD
2019-06-05 14:32       ` Ian Jackson
2019-04-09 16:45 ` [PATCH 5/9] libxl_disk: Reorganise libxl_cdrom_insert Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 17:16   ` Ian Jackson
2019-04-09 16:45 ` [PATCH 6/9] libxl_disk: Cut libxl_cdrom_insert into steps Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 17:29   ` Ian Jackson
2019-06-07 17:22     ` Anthony PERARD
2019-04-09 16:45 ` [PATCH 7/9] libxl: Move qmp_parameters_* prototypes to libxl_internal.h Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 17:32   ` Ian Jackson
2019-04-09 16:45 ` [PATCH 8/9] libxl_disk: Use ev_qmp in libxl_cdrom_insert Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 17:45   ` Ian Jackson
2019-04-09 16:45 ` [PATCH 9/9] libxl_disk: Implement missing timeout for libxl_cdrom_insert Anthony PERARD
2019-04-09 16:45   ` [Xen-devel] " Anthony PERARD
2019-06-04 17:47   ` Ian Jackson
2019-06-05 14:22     ` Anthony PERARD
2019-06-05 14:33       ` Ian Jackson
2019-06-04 10:54 ` [Xen-devel] Ping: [PATCH 0/9] libxl: New slow lock + fix libxl_cdrom_insert with QEMU depriv Anthony PERARD

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=23798.42555.428964.824573@mariner.uk.xensource.com \
    --to=ian.jackson@citrix.com \
    --cc=anthony.perard@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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).