[Libguestfs] [PATCH 1/2] daemon: run 'udevadm settle' with --exit-if-exists option

Pavel Butsykin pbutsykin at virtuozzo.com
Wed Apr 12 14:01:10 UTC 2017


Add udev_settle_file() to run 'udevadm settle' with --exit-if-exists option. It
will slightly reduce the waiting-time for pending events if we need to wait
for events related to a particular device/file.

Signed-off-by: Pavel Butsykin <pbutsykin at virtuozzo.com>
---
 daemon/daemon.h   |  2 ++
 daemon/guestfsd.c | 20 ++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/daemon/daemon.h b/daemon/daemon.h
index 79a5288f6..90ebaafbe 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -141,6 +141,8 @@ extern int parse_btrfsvol (const char *desc, mountable_t *mountable);
 
 extern int prog_exists (const char *prog);
 
+extern void udev_settle_file (const char *file);
+
 extern void udev_settle (void);
 
 extern int random_name (char *template);
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 85ce5d2ad..dccfa15bc 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -1213,13 +1213,18 @@ random_name (char *template)
  * fussed if it fails.
  */
 void
-udev_settle (void)
+udev_settle_file (const char *file)
 {
-  char cmd[80];
+  size_t cmd_size = strlen (str_udevadm) +
+                    sizeof (" settle")   +
+                    sizeof (" --debug")  +
+                    (file ? sizeof (" --exit-if-exists=") + strlen (file) : 0);
+  char *cmd = malloc (cmd_size);
   int r;
 
-  snprintf (cmd, sizeof cmd, "%s%s settle",
-            str_udevadm, verbose ? " --debug" : "");
+  snprintf(cmd, cmd_size, "%s%s settle%s%s",
+           str_udevadm, verbose ? " --debug" : "",
+           file ? " --exit-if-exists=" : "", file ? file : "");
   if (verbose)
     printf ("%s\n", cmd);
   r = system (cmd);
@@ -1227,6 +1232,13 @@ udev_settle (void)
     perror ("system");
   else if (!WIFEXITED (r) || WEXITSTATUS (r) != 0)
     fprintf (stderr, "warning: udevadm command failed\n");
+  free (cmd);
+}
+
+void
+udev_settle (void)
+{
+  udev_settle_file (NULL);
 }
 
 char *
-- 
2.11.0




More information about the Libguestfs mailing list