[Libguestfs] [PATCH libnbd] lib: Kill subprocess in nbd_close.

Richard W.M. Jones rjones at redhat.com
Thu Jul 25 17:43:03 UTC 2019


$ time nbdsh -c 'h.connect_command (["nbdkit", "-s", "null", "size=512", "--filter=delay", "delay-read=10"]); b = nbd.aio_buffer(1); h.aio_pread (b, 0); del (h)'
real	0m10.499s
user	0m0.065s
sys	0m0.023s

With this patch the elapsed time is near instantaneous.
---
 lib/handle.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/handle.c b/lib/handle.c
index 1fe4467..111cfc5 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -124,8 +124,10 @@ nbd_close (struct nbd_handle *h)
     freeaddrinfo (h->result);
   if (h->sock)
     h->sock->ops->close (h->sock);
-  if (h->pid >= 0) /* XXX kill it? */
+  if (h->pid >= 0) {
+    kill (h->pid, SIGHUP);
     waitpid (h->pid, NULL, 0);
+  }
 
   free (h->export_name);
   free (h->tls_certificates);
-- 
2.22.0




More information about the Libguestfs mailing list