|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/2] libxl_internal: comment on domain userdata unlock function
Discuss why we need to unlink file path before closes fd.
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
tools/libxl/libxl_internal.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 9d8025d..a70214b 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -458,6 +458,20 @@ out:
void libxl__unlock_domain_userdata(libxl__domain_userdata_lock *lock)
{
+ /* It's important to unlink the file before closing fd to avoid
+ * such race (if close before unlink):
+ *
+ * P1 LOCK P2 UNLOCK
+ * fd1 = open(lockfile)
+ * close(fd2)
+ * flock(fd1)
+ * fstat and stat check success
+ * unlink(lockfile)
+ * return lock
+ *
+ * In above case P1 thinks it has got hold of the lock but
+ * actually lock is released by P2 (lockfile unlinked).
+ */
if (lock->path) unlink(lock->path);
if (lock->carefd) libxl__carefd_close(lock->carefd);
free(lock->path);
--
1.7.10.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |