qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] oslib: qemu_clear_cloexec
@ 2023-02-07 19:03 Steve Sistare
  2023-06-07 16:42 ` Steven Sistare
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Sistare @ 2023-02-07 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert,
	Daniel P. Berrange, Paolo Bonzini, Steve Sistare

Define qemu_clear_cloexec, analogous to qemu_set_cloexec.  This will be
used to preserve selected descriptors during cpr.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu/osdep.h | 9 +++++++++
 util/oslib-posix.c   | 9 +++++++++
 util/oslib-win32.c   | 4 ++++
 3 files changed, 22 insertions(+)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 88c9fac..9c8c536 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -618,6 +618,15 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
 
 void qemu_set_cloexec(int fd);
 
+/*
+ * Clear FD_CLOEXEC for a descriptor.
+ *
+ * The caller must guarantee that no other fork+exec's occur before the
+ * exec that is intended to inherit this descriptor, eg by suspending CPUs
+ * and blocking monitor commands.
+ */
+void qemu_clear_cloexec(int fd);
+
 /* Return a dynamically allocated directory path that is appropriate for storing
  * local state.
  *
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 59a891b..a8cc3d0 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -273,6 +273,15 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2])
     return ret;
 }
 
+void qemu_clear_cloexec(int fd)
+{
+    int f;
+    f = fcntl(fd, F_GETFD);
+    assert(f != -1);
+    f = fcntl(fd, F_SETFD, f & ~FD_CLOEXEC);
+    assert(f != -1);
+}
+
 char *
 qemu_get_local_state_dir(void)
 {
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 07ade41..756bee3 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -222,6 +222,10 @@ void qemu_set_cloexec(int fd)
 {
 }
 
+void qemu_clear_cloexec(int fd)
+{
+}
+
 int qemu_get_thread_id(void)
 {
     return GetCurrentThreadId();
-- 
1.8.3.1



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

* Re: [PATCH V2] oslib: qemu_clear_cloexec
  2023-02-07 19:03 [PATCH V2] oslib: qemu_clear_cloexec Steve Sistare
@ 2023-06-07 16:42 ` Steven Sistare
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Sistare @ 2023-06-07 16:42 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini; +Cc: Marc-André Lureau, Daniel P. Berrange

Hi Paolo,
  Can I get an RB from you on this patch, since you maintain posix?
This is needed for live update, to preserve vfio device descriptors and
character device descriptors across the exec of the new qemu binary.
If yes, I will rebase to the tip and repost a V3.

- Steve

On 2/7/2023 2:03 PM, Steve Sistare wrote:
> Define qemu_clear_cloexec, analogous to qemu_set_cloexec.  This will be
> used to preserve selected descriptors during cpr.
> 
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  include/qemu/osdep.h | 9 +++++++++
>  util/oslib-posix.c   | 9 +++++++++
>  util/oslib-win32.c   | 4 ++++
>  3 files changed, 22 insertions(+)
> 
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 88c9fac..9c8c536 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -618,6 +618,15 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
>  
>  void qemu_set_cloexec(int fd);
>  
> +/*
> + * Clear FD_CLOEXEC for a descriptor.
> + *
> + * The caller must guarantee that no other fork+exec's occur before the
> + * exec that is intended to inherit this descriptor, eg by suspending CPUs
> + * and blocking monitor commands.
> + */
> +void qemu_clear_cloexec(int fd);
> +
>  /* Return a dynamically allocated directory path that is appropriate for storing
>   * local state.
>   *
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 59a891b..a8cc3d0 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -273,6 +273,15 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2])
>      return ret;
>  }
>  
> +void qemu_clear_cloexec(int fd)
> +{
> +    int f;
> +    f = fcntl(fd, F_GETFD);
> +    assert(f != -1);
> +    f = fcntl(fd, F_SETFD, f & ~FD_CLOEXEC);
> +    assert(f != -1);
> +}
> +
>  char *
>  qemu_get_local_state_dir(void)
>  {
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 07ade41..756bee3 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -222,6 +222,10 @@ void qemu_set_cloexec(int fd)
>  {
>  }
>  
> +void qemu_clear_cloexec(int fd)
> +{
> +}
> +
>  int qemu_get_thread_id(void)
>  {
>      return GetCurrentThreadId();


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

end of thread, other threads:[~2023-06-07 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-07 19:03 [PATCH V2] oslib: qemu_clear_cloexec Steve Sistare
2023-06-07 16:42 ` Steven Sistare

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).