From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH v2 09/18] libxl: disallow attaching the same device more than once Date: Wed, 27 Aug 2014 02:48:30 +0100 Message-ID: <1409104110.28009.68.camel@citrix.com> References: <1406744639-28782-1-git-send-email-wei.liu2@citrix.com> <1406744639-28782-10-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1406744639-28782-10-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Wed, 2014-07-30 at 19:23 +0100, Wei Liu wrote: > Originally the code allowed users to attach the same device more than > once. It just stupidly overwrites xenstore entries. This is bogus as > frontend will be very confused. > > Introduce a helper function to check if the device to be written to > xenstore already exists. A new error code is also introduced. > > Signed-off-by: Wei Liu > --- > tools/libxl/libxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++ > tools/libxl/libxl_device.c | 19 ++++++++++++++++ > tools/libxl/libxl_internal.h | 3 +++ > tools/libxl/libxl_pci.c | 12 ++++++++++ > tools/libxl/libxl_types.idl | 1 + > 5 files changed, 85 insertions(+) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index 01dffa0..e6fe238 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -1906,6 +1906,15 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, > rc = libxl__device_from_vtpm(gc, domid, vtpm, device); > if ( rc != 0 ) goto out; > > + rc = libxl__device_exists(gc, XBT_NULL, device); Do we hold any locks from here until the code which actually creates the device? I don't think we have an active transaction either which would serve a similar purpose. Otherwise can't another thread come and create another device after the check and similarly confuse us? (likewise for the other cases). Ian.