Skip to contentSkip to conversation

ivshmem-server: Clean up shmem on shutdown

PATCH Applied Jan Kiszka 5 participants 5 messages Aug 5, 2019 – Nov 12, 2019

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH v2 1/1 ivshmem-server: Clean up shmem on shutdown

From: Jan Kiszka <[email protected]>

So far, the server leaves the posix shared memory object behind when terminating, requiring the user to explicitly remove it in order to start a new instance.

---

Changes in v2:
- respect use_shm_open
- also clean up in ivshmem_server_start error path

 contrib/ivshmem-server/ivshmem-server.c | 6 ++++++
 1 file changed, 6 insertions(+)
contrib/ivshmem-server/ivshmem-server.c +6 -0
index 77f97b209c..88daee812d 100644
@@ -353,6 +353,9 @@ ivshmem_server_start(IvshmemServer *server)
 err_close_sock:
     close(sock_fd);
 err_close_shm:
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
     close(shm_fd);
     return -1;
 }
@@ -370,6 +373,9 @@ ivshmem_server_close(IvshmemServer *server)
     }
 
     unlink(server->unix_sock_path);
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
     close(server->sock_fd);
     close(server->shm_fd);
     server->sock_fd = -1;

--
2.16.4

Reviewed-by on v2 1/1
#1 lore raw
Quoted 41 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

So far, the server leaves the posix shared memory object behind when terminating, requiring the user to explicitly remove it in order to start a new instance.

---

Changes in v2:
- respect use_shm_open
- also clean up in ivshmem_server_start error path

 contrib/ivshmem-server/ivshmem-server.c | 6 ++++++
 1 file changed, 6 insertions(+)
contrib/ivshmem-server/ivshmem-server.c +6 -1
index 77f97b209c..88daee812d 100644
@@ -353,6 +353,9 @@ ivshmem_server_start(IvshmemServer *server)
 err_close_sock:
     close(sock_fd);
 err_close_shm:
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
     close(shm_fd);
     return -1;
 }
@@ -370,6 +373,9 @@ ivshmem_server_close(IvshmemServer *server)
     }
 
     unlink(server->unix_sock_path);
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
     close(server->sock_fd);
     close(server->shm_fd);
     server->sock_fd = -1;
--
Quoted 3 lines

2.16.4

#2 lore raw
Quoted 34 lines · Claudio Fontana
Quoted 33 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

So far, the server leaves the posix shared memory object behind when terminating, requiring the user to explicitly remove it in order to start a new instance.

---

Changes in v2:
- respect use_shm_open
- also clean up in ivshmem_server_start error path

  contrib/ivshmem-server/ivshmem-server.c | 6 ++++++
  1 file changed, 6 insertions(+)
contrib/ivshmem-server/ivshmem-server.c +3 -0
index 77f97b209c..88daee812d 100644
@@ -353,6 +353,9 @@ ivshmem_server_start(IvshmemServer *server)
  err_close_sock:
      close(sock_fd);
  err_close_shm:
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
      close(shm_fd);
      return -1;
  }
@@ -370,6 +373,9 @@ ivshmem_server_close(IvshmemServer *server)
      }
 
Quoted 16 lines
Quoted 11 lines
contrib/ivshmem-server/ivshmem-server.c +3 -1
      unlink(server->unix_sock_path);
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
      close(server->sock_fd);
      close(server->shm_fd);
      server->sock_fd = -1;
--

2.16.4

Markus, would you take this?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 49 lines · Jan Kiszka
Quoted 34 lines · Claudio Fontana
Quoted 33 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

So far, the server leaves the posix shared memory object behind when terminating, requiring the user to explicitly remove it in order to start a new instance.

---

Changes in v2:
- respect use_shm_open
- also clean up in ivshmem_server_start error path

  contrib/ivshmem-server/ivshmem-server.c | 6 ++++++
  1 file changed, 6 insertions(+)
contrib/ivshmem-server/ivshmem-server.c +3 -0
index 77f97b209c..88daee812d 100644
@@ -353,6 +353,9 @@ ivshmem_server_start(IvshmemServer *server)
  err_close_sock:
      close(sock_fd);
  err_close_shm:
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
      close(shm_fd);
      return -1;
  }
@@ -370,6 +373,9 @@ ivshmem_server_close(IvshmemServer *server)
      }
 
Quoted 13 lines
Quoted 11 lines
contrib/ivshmem-server/ivshmem-server.c +3 -1
      unlink(server->unix_sock_path);
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
      close(server->sock_fd);
      close(server->shm_fd);
      server->sock_fd = -1;
--

2.16.4

Quoted 1 line

Markus, would you take this?

ivshmem has no maintainer. I you need me to serve as a pull request monkey of last resort, I can do that. However, for this one, qemu-trivial (cc'ed) should do.

#4 lore raw

Le 08/11/2019 à 16:14, Markus Armbruster a écrit :

Quoted 51 lines
Quoted 49 lines · Jan Kiszka
Quoted 47 lines · Claudio Fontana
Quoted 41 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

So far, the server leaves the posix shared memory object behind when terminating, requiring the user to explicitly remove it in order to start a new instance.

---

Changes in v2:
- respect use_shm_open
- also clean up in ivshmem_server_start error path

  contrib/ivshmem-server/ivshmem-server.c | 6 ++++++
  1 file changed, 6 insertions(+)
contrib/ivshmem-server/ivshmem-server.c +6 -1
index 77f97b209c..88daee812d 100644
@@ -353,6 +353,9 @@ ivshmem_server_start(IvshmemServer *server)
  err_close_sock:
      close(sock_fd);
  err_close_shm:
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
      close(shm_fd);
      return -1;
  }
@@ -370,6 +373,9 @@ ivshmem_server_close(IvshmemServer *server)
      }
 
      unlink(server->unix_sock_path);
+    if (server->use_shm_open) {
+        shm_unlink(server->shm_path);
+    }
      close(server->sock_fd);
      close(server->shm_fd);
      server->sock_fd = -1;
--
Quoted 3 lines

2.16.4

Quoted 7 lines
Quoted 1 line

Markus, would you take this?

ivshmem has no maintainer. I you need me to serve as a pull request monkey of last resort, I can do that. However, for this one, qemu-trivial (cc'ed) should do.

Applied to my trivial-patches branch.

Thanks,
Laurent