qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] keep the PID file locked for the lifetime of the process
@ 2012-01-26 21:36 Laszlo Ersek
  2012-01-27  6:36 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  2012-01-27 13:17 ` [Qemu-devel] " Markus Armbruster
  0 siblings, 2 replies; 8+ messages in thread
From: Laszlo Ersek @ 2012-01-26 21:36 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial

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

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
Please keep me CC'd, I'm not subscribed. Thanks!

 os-posix.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 5c437ca..f4940c8 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -348,6 +348,5 @@ int qemu_create_pidfile(const char *filename)
         return -1;
     }
 
-    close(fd);
     return 0;
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] keep the PID file locked for the lifetime of the process
  2012-01-26 21:36 [Qemu-devel] [PATCH] keep the PID file locked for the lifetime of the process Laszlo Ersek
@ 2012-01-27  6:36 ` Stefan Hajnoczi
  2012-01-27  8:56   ` Laszlo Ersek
  2012-01-27 10:26   ` Daniel P. Berrange
  2012-01-27 13:17 ` [Qemu-devel] " Markus Armbruster
  1 sibling, 2 replies; 8+ messages in thread
From: Stefan Hajnoczi @ 2012-01-27  6:36 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-trivial, qemu-devel

On Thu, Jan 26, 2012 at 10:36:41PM +0100, Laszlo Ersek wrote:
> 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
> 
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] keep the PID file locked for the lifetime of the process
  2012-01-27  6:36 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
@ 2012-01-27  8:56   ` Laszlo Ersek
  2012-01-27 10:26   ` Daniel P. Berrange
  1 sibling, 0 replies; 8+ messages in thread
From: Laszlo Ersek @ 2012-01-27  8:56 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-trivial, qemu-devel

On 01/27/12 07:36, Stefan Hajnoczi wrote:
> On Thu, Jan 26, 2012 at 10:36:41PM +0100, Laszlo Ersek wrote:
>> 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
>>
>> Signed-off-by: Laszlo Ersek<lersek@redhat.com>
>> ---
>
> Isn't the normal way to do pidfiles O_CREAT | O_EXCL?

Yes, it is.

> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] keep the PID file locked for the lifetime of the process
  2012-01-27  6:36 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  2012-01-27  8:56   ` Laszlo Ersek
@ 2012-01-27 10:26   ` Daniel P. Berrange
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel P. Berrange @ 2012-01-27 10:26 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-trivial, Laszlo Ersek, qemu-devel

On Fri, Jan 27, 2012 at 06:36:39AM +0000, Stefan Hajnoczi wrote:
> On Thu, Jan 26, 2012 at 10:36:41PM +0100, Laszlo Ersek wrote:
> > 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
> > 
> > Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> > ---
> 
> 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
-- 
|: 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 :|

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] keep the PID file locked for the lifetime of the process
  2012-01-26 21:36 [Qemu-devel] [PATCH] keep the PID file locked for the lifetime of the process Laszlo Ersek
  2012-01-27  6:36 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
@ 2012-01-27 13:17 ` Markus Armbruster
  2012-01-27 13:34   ` [Qemu-devel] [PATCH v2] " Laszlo Ersek
  1 sibling, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2012-01-27 13:17 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-trivial, qemu-devel

Laszlo Ersek <lersek@redhat.com> writes:

> 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

Broken in commit 1bbd1592 by yours truly %-}  Suitable pointer could be
added to the commit message.

> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> Please keep me CC'd, I'm not subscribed. Thanks!
>
>  os-posix.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/os-posix.c b/os-posix.c
> index 5c437ca..f4940c8 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -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.

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2] keep the PID file locked for the lifetime of the process
  2012-01-27 13:17 ` [Qemu-devel] " Markus Armbruster
@ 2012-01-27 13:34   ` Laszlo Ersek
  2012-01-27 14:48     ` Markus Armbruster
  2012-02-03 17:21     ` Anthony Liguori
  0 siblings, 2 replies; 8+ messages in thread
From: Laszlo Ersek @ 2012-01-27 13:34 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial, armbru

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

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 os-posix.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 5c437ca..e3ed497 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -348,6 +348,6 @@ int qemu_create_pidfile(const char *filename)
         return -1;
     }
 
-    close(fd);
+    /* keep pidfile open & locked forever */
     return 0;
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] keep the PID file locked for the lifetime of the process
  2012-01-27 13:34   ` [Qemu-devel] [PATCH v2] " Laszlo Ersek
@ 2012-01-27 14:48     ` Markus Armbruster
  2012-02-03 17:21     ` Anthony Liguori
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Armbruster @ 2012-01-27 14:48 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-trivial, qemu-devel

Laszlo Ersek <lersek@redhat.com> writes:

> 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
>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>

Thanks for cleaning up the mess I made!

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] keep the PID file locked for the lifetime of the process
  2012-01-27 13:34   ` [Qemu-devel] [PATCH v2] " Laszlo Ersek
  2012-01-27 14:48     ` Markus Armbruster
@ 2012-02-03 17:21     ` Anthony Liguori
  1 sibling, 0 replies; 8+ messages in thread
From: Anthony Liguori @ 2012-02-03 17:21 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-trivial, qemu-devel, armbru

On 01/27/2012 07:34 AM, Laszlo Ersek wrote:
> 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

Applied.  Thanks.

Regards,

Anthony Liguori

>
> Signed-off-by: Laszlo Ersek<lersek@redhat.com>
> ---
>   os-posix.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/os-posix.c b/os-posix.c
> index 5c437ca..e3ed497 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -348,6 +348,6 @@ int qemu_create_pidfile(const char *filename)
>           return -1;
>       }
>
> -    close(fd);
> +    /* keep pidfile open&  locked forever */
>       return 0;
>   }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-02-03 17:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-26 21:36 [Qemu-devel] [PATCH] keep the PID file locked for the lifetime of the process Laszlo Ersek
2012-01-27  6:36 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2012-01-27  8:56   ` Laszlo Ersek
2012-01-27 10:26   ` Daniel P. Berrange
2012-01-27 13:17 ` [Qemu-devel] " Markus Armbruster
2012-01-27 13:34   ` [Qemu-devel] [PATCH v2] " Laszlo Ersek
2012-01-27 14:48     ` Markus Armbruster
2012-02-03 17:21     ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).