keep the PID file locked for the lifetime of the process
PATCH 1/1 keep the PID file locked for the lifetime of the process
The lockf() call in qemu_create_pidfile() aims at ensuring mutual exclusion. We shouldn't close the pidfile on success, because that drops the lock as well [1]:
"File locks shall be released on first close by the locking process of any file descriptor for the file."
Coverity may complain again about the leaked file descriptor; let's worry about that later.
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
---
Please keep me CC'd, I'm not subscribed. Thanks!
os-posix.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
os-posix.c +0 -1
@@ -348,6 +348,5 @@ int qemu_create_pidfile(const char *filename)return -1 ; } -close (fd);return 0 ; }
Signature · 1 line
1.7.1
Quoted 7 lines · Laszlo Ersek
The
lockf()call inqemu_create_pidfile()aims at ensuring mutual exclusion. We shouldn't close the pidfile on success, because that drops the lock as well [1]:"File locks shall be released on first close by the locking process of any file descriptor for the file."
Quoted 7 lines
Coverity may complain again about the leaked file descriptor; let's worry about that later.
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
Signed-off-by Laszlo Ersek <[email protected]>---
Isn't the normal way to do pidfiles O_CREAT | O_EXCL? It may not work on all NFS versions but putting the pidfile on NFS doesn't really make sense.
Then we can drop the lockf(3) completely.
Stefan
Quoted 11 lines · Stefan Hajnoczi
Quoted 10 lines · Laszlo Ersek
The
lockf()call inqemu_create_pidfile()aims at ensuring mutual exclusion. We shouldn't close the pidfile on success, because that drops the lock as well [1]:"File locks shall be released on first close by the locking process of any file descriptor for the file."
Coverity may complain again about the leaked file descriptor; let's worry about that later.
Quoted 6 lines
Quoted 4 lines
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
Signed-off-by Laszlo Ersek<[email protected]>---
Isn't the normal way to do pidfiles
O_CREAT|O_EXCL?
Yes, it is.
Quoted 5 lines
It may not work
on all NFS versions but putting the pidfile on NFS doesn't really make sense.Then we can drop the lockf(3) completely.
When you rely on O_EXCL to ensure mutual exclusion, and an abruptly terminated process leaves the lockfile lying around, then the user has to clean it up manually before starting the next instance (and double check if the pid file is in fact stale or not). I'm personally OK with that, but I reckoned the qemu code tried to avoid that intentionally. Record locks can't remain stale when the process dies.
Laszlo
Quoted 13 lines · Stefan Hajnoczi
Quoted 12 lines · Laszlo Ersek
The
lockf()call inqemu_create_pidfile()aims at ensuring mutual exclusion. We shouldn't close the pidfile on success, because that drops the lock as well [1]:"File locks shall be released on first close by the locking process of any file descriptor for the file."
Coverity may complain again about the leaked file descriptor; let's worry about that later.
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
Quoted 8 lines
Quoted 2 lines
Signed-off-by Laszlo Ersek <[email protected]>---
Isn't the normal way to do pidfiles
O_CREAT|O_EXCL? It may not work on all NFS versions but putting the pidfile on NFS doesn't really make sense.Then we can drop the lockf(3) completely.
IMHO it is preferable to use lockf because that makes sure you are crash safe, so you don't get later bogus startup failures due to stale pidfiles
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 11 lines · Laszlo Ersek
The
lockf()call inqemu_create_pidfile()aims at ensuring mutual exclusion. We shouldn't close the pidfile on success, because that drops the lock as well [1]:"File locks shall be released on first close by the locking process of any file descriptor for the file."
Coverity may complain again about the leaked file descriptor; let's worry about that later.
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
Broken in commit 1bbd1592 by yours truly %-} Suitable pointer could be added to the commit message.
Quoted 12 lines
Signed-off-by Laszlo Ersek <[email protected]>---
Please keep me CC'd, I'm not subscribed. Thanks!os-posix.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)os-posix.c +0
-0
os-posix.c int qemu_create_pidfile(const char *filename) · line 352
Quoted 6 lines
os-posix.c +0
-1@@ -348,6 +348,5 @@ int qemu_create_pidfile(const char *filename)return -1 ; } -close (fd);return 0 ; }
We intentionally leak fd here. A comment would be nice.
PATCH v2 1/1 keep the PID file locked for the lifetime of the process
The lockf() call in qemu_create_pidfile() aims at ensuring mutual exclusion. We shouldn't close the pidfile on success (as introduced by commit 1bbd1592), because that drops the lock as well [1]:
"File locks shall be released on first close by the locking process of any file descriptor for the file."
Coverity may complain again about the leaked file descriptor; let's worry about that later.
v1->v2:
- add reference to 1bbd1592
- explain the intentional fd leak in the source
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
--- os-posix.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
os-posix.c +1 -1
@@ -348,6 +348,6 @@ int qemu_create_pidfile(const char *filename)return -1 ; } -close (fd); +/* keep pidfile open & locked forever */ return 0 ; }
Signature · 1 line
1.7.1
Quoted 10 lines · Laszlo Ersek
The
lockf()call inqemu_create_pidfile()aims at ensuring mutual exclusion. We shouldn't close the pidfile on success (as introduced by commit1bbd1592), because that drops the lock as well [1]:"File locks shall be released on first close by the locking process of any file descriptor for the file."
Coverity may complain again about the leaked file descriptor; let's worry about that later.
Quoted 7 lines
v1->v2:
- add reference to1bbd1592
- explain the intentional fd leak in the source[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
Signed-off-by Laszlo Ersek <[email protected]>
Thanks for cleaning up the mess I made!
Anthony Liguori
AppliedQuoted 7 lines · Laszlo Ersek
The
lockf()call inqemu_create_pidfile()aims at ensuring mutual exclusion. We shouldn't close the pidfile on success (as introduced by commit1bbd1592), because that drops the lock as well [1]:"File locks shall be released on first close by the locking process of any file descriptor for the file."
Quoted 8 lines
Coverity may complain again about the leaked file descriptor; let's worry about that later.
v1->v2:
- add reference to1bbd1592
- explain the intentional fd leak in the source[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 18 lines
Signed-off-by Laszlo Ersek<[email protected]>--- os-posix.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)os-posix.c +1
-1@@ -348,6 +348,6 @@ int qemu_create_pidfile(const char *filename)return -1 ; } -close (fd); +/* keep pidfile open& locked forever */ return 0 ; }