From: Wei Liu Subject: Re: [PATCH v2 09/18] libxl: disallow attaching the same device more than once Date: Thu, 28 Aug 2014 11:55:24 +0100 Message-ID: <20140828105524.GH13165@zion.uk.xensource.com> References: <1406744639-28782-1-git-send-email-wei.liu2@citrix.com> <1406744639-28782-10-git-send-email-wei.liu2@citrix.com> <1409104110.28009.68.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1409104110.28009.68.camel@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: Ian Campbell Cc: ian.jackson@eu.citrix.com, Wei Liu , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Wed, Aug 27, 2014 at 02:48:30AM +0100, Ian Campbell wrote: > 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. > At this point we hold libxl context lock, so it should be safe against other threads in the same process. But I can see there's problem WRT to other processes trying to manipulate device. I think we need to have a xs transaction here. What do you think? Wei. > Otherwise can't another thread come and create another device after the > check and similarly confuse us? > > (likewise for the other cases). > > Ian. >