Two libxl misc patches
cover Two libxl misc patches
These changes were requested by Ian Campbell when relevant patches were posted but they didn't warrant a resend at that time.
Wei Liu (2):
libxl_internal: lock_carefd -> carefd
libxl_internal: comment on domain userdata unlock function
tools/libxl/libxl_internal.c | 20 +++++++++++++++++--- tools/libxl/libxl_internal.h | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/2 libxl_internal: lock_carefd -> carefd
lock_ prefix is redundant.
--- tools/libxl/libxl_internal.c | 6 +++--- tools/libxl/libxl_internal.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl_internal.c +3 -3
@@ -405,7 +405,7 @@ libxl__domain_userdata_lock *libxl__lock_domain_userdata(libxl__gc *gc, fd =open (lockfile,O_RDWR |O_CREAT ,0666 );if (fd <0 )LOGE (ERROR ,"cannot open lockfile %s, errno=%d" , lockfile, errno); - lock->lock_carefd =libxl__carefd_opened (CTX , fd); + lock->carefd =libxl__carefd_opened (CTX , fd);if (fd <0 ) goto out;/* Lock the file in exclusive mode, wait indefinitely to
@@ -440,7 +440,7 @@ libxl__domain_userdata_lock *libxl__lock_domain_userdata(libxl__gc *gc,break ; } -libxl__carefd_close (lock->lock_carefd); +libxl__carefd_close (lock->carefd); }/* Check the domain is still there, if not we should release the
@@ -459,7 +459,7 @@ out:void libxl__unlock_domain_userdata (libxl__domain_userdata_lock *lock) {if (lock->path)unlink (lock->path); -if (lock->lock_carefd)libxl__carefd_close (lock->lock_carefd); +if (lock->carefd)libxl__carefd_close (lock->carefd);free (lock->path);free (lock); }
tools/libxl/libxl_internal.h +1 -1
@@ -3522,7 +3522,7 @@ int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl);/* Portability note: a proper flock(2) implementation is required */ typedef struct { -libxl__carefd *lock_carefd; +libxl__carefd *carefd;char *path;/* path of the lock file itself */ }libxl__domain_userdata_lock ; libxl__domain_userdata_lock *libxl__lock_domain_userdata(libxl__gc *gc,
Signature · 1 line
1.7.10.4
PATCH 2/2 libxl_internal: comment on domain userdata unlock function
In reply to Wei LiuDiscuss why we need to unlink file path before closes fd.
--- tools/libxl/libxl_internal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/libxl/libxl_internal.c +14 -0
@@ -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);
Signature · 1 line
1.7.10.4
Re: [PATCH 1/2] libxl_internal: lock_carefd -> carefd
In reply to Wei LiuWei Liu writes ("[PATCH 1/2] libxl_internal: lock_carefd -> carefd"):
Quoted 1 line
lock_prefix is redundant.
(for 4.6)
Re: [PATCH 2/2] libxl_internal: comment on domain userdata unlock function
In reply to Wei LiuWei Liu writes ("[PATCH 2/2] libxl_internal: comment on domain userdata unlock function"):
Quoted 1 line
Discuss why we need to unlink file path before closes fd.
subject to minor grammar complaint:
Potential backport candidate for 4.5.1 ?
tools/libxl/libxl_internal.c out: · line 462
Quoted 10 lines
tools/libxl/libxl_internal.c +2
-0@@ -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):
^^^^
"to avoid the following race". "Such" must refer to a thing which precedes.
Ian.
Re: [PATCH 2/2] libxl_internal: comment on domain userdata unlock function
Quoted 8 lines · Ian Jackson
Wei Liu writes ("[PATCH 2/2]
libxl_internal: comment on domain userdata unlock function"):Quoted 1 line
Discuss why we need to unlink file path before closes fd.
Acked-by Ian Jackson <[email protected]>subject to minor grammar complaint:
Potential backport candidate for 4.5.1 ?
Sure, if you feel this is important.
Quoted 6 lines
Quoted 6 lines
tools/libxl/libxl_internal.c +0
-0@@ -458,6 +458,20 @@ out:
Quoted 9 lines
tools/libxl/libxl_internal.c out: · line 462
Quoted 4 lines
tools/libxl/libxl_internal.c +2
-0void 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): ^^^^"to avoid the following race". "Such" must refer to a thing which precedes.
I suppose you (or Ian C) can fix this when committing? Do I need to resend?
Wei.
Quoted 1 line
Ian.
Re: [PATCH 2/2] libxl_internal: comment on domain userdata unlock function
Quoted 12 lines · Wei Liu
Quoted 12 lines
tools/libxl/libxl_internal.c out: · line 462
Quoted 10 lines
tools/libxl/libxl_internal.c +2
-0@@ -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): ^^^^
Quoted 6 lines
Quoted 3 lines
"to avoid the following race". "Such" must refer to a thing which precedes.
I suppose you (or Ian C) can fix this when committing? Do I need to resend?
I've applied both patches and fixed this up.