From: Ian Campbell Subject: Re: [PATCH v3 03/15] libxl: properly lock userdata store Date: Tue, 9 Sep 2014 11:52:14 +0100 Message-ID: <1410259934.8217.113.camel@kazak.uk.xensource.com> References: <1409870601-7538-1-git-send-email-wei.liu2@citrix.com> <1409870601-7538-4-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: <1409870601-7538-4-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 Thu, 2014-09-04 at 23:43 +0100, Wei Liu wrote: > Originally libxl user data store didn't have lock at all. There could be > such race condition as mentioned by Ian Jackson: > > Task 1 Task 2 > Creating the domain Trying to shut down > > actually create domain > observe domid > start domain destruction > delete all userdata > destroy domain > store the userdata > *** forbidden state created: userdata exists but domain doesn't > *** userdata has been leaked > [ would now bomb out ] > > This patch adds in proper locking to libxl user data store. The lock is > associated with a specific domain (i.e. a per-domain lock). > > As for locking hierachy, we first take CTX lock (which is implemented > with pthread recursive mutex so even if the application has taken it > we're fine), then take the file lock. These locks are released in > reversed order. > > A new libxl error code ERROR_LOCK_FAIL is introduced to describe failure > to acquire locks. > > Also factor out libxl__userdata_{retrieve,store}, so that other > functions that already hold the lock can call them to manipulate > user data. > > Signed-off-by: Wei Liu Acked-by: Ian Campbell