[PATCH 5/5] nodedev: Only set up mdevctl monitors if mdevctl.d exist

Michal Privoznik posted 5 patches 4 years, 10 months ago
[PATCH 5/5] nodedev: Only set up mdevctl monitors if mdevctl.d exist
Posted by Michal Privoznik 4 years, 10 months ago
During its initialization, the nodedev driver tries to set up
monitors for /etc/mdevctl.d directory, so that it can register
mdevs as they come and go. However, if the file doesn't exist
there is nothing to monitor and therefore we can exit early. In
fact, we have to otherwise monitorFileRecursively() fails and
whole driver initialization fails with it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/node_device/node_device_udev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 18219175c5..c4040c2fd6 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -2122,7 +2122,13 @@ monitorFileRecursively(udevEventData *udev,
 static int
 mdevctlEnableMonitor(udevEventData *priv)
 {
-    g_autoptr(GFile) mdevctlConfigDir = g_file_new_for_path("/etc/mdevctl.d");
+    g_autoptr(GFile) mdevctlConfigDir = NULL;
+    const char *mdevctlDir = "/etc/mdevctl.d";
+
+    if (!virFileExists(mdevctlDir))
+        return 0;
+
+    mdevctlConfigDir = g_file_new_for_path("/etc/mdevctl.d");
 
     /* mdevctl may add notification events in the future:
      * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to
-- 
2.26.3

Re: [PATCH 5/5] nodedev: Only set up mdevctl monitors if mdevctl.d exist
Posted by Pavel Hrdina 4 years, 10 months ago
On Mon, Apr 12, 2021 at 06:22:24PM +0200, Michal Privoznik wrote:
> During its initialization, the nodedev driver tries to set up
> monitors for /etc/mdevctl.d directory, so that it can register
> mdevs as they come and go. However, if the file doesn't exist
> there is nothing to monitor and therefore we can exit early. In
> fact, we have to otherwise monitorFileRecursively() fails and
> whole driver initialization fails with it.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/node_device/node_device_udev.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
> index 18219175c5..c4040c2fd6 100644
> --- a/src/node_device/node_device_udev.c
> +++ b/src/node_device/node_device_udev.c
> @@ -2122,7 +2122,13 @@ monitorFileRecursively(udevEventData *udev,
>  static int
>  mdevctlEnableMonitor(udevEventData *priv)
>  {
> -    g_autoptr(GFile) mdevctlConfigDir = g_file_new_for_path("/etc/mdevctl.d");
> +    g_autoptr(GFile) mdevctlConfigDir = NULL;
> +    const char *mdevctlDir = "/etc/mdevctl.d";
> +
> +    if (!virFileExists(mdevctlDir))
> +        return 0;
> +
> +    mdevctlConfigDir = g_file_new_for_path("/etc/mdevctl.d");

s|"/etc/mdevctl.d"|mdevctlDir|

>  
>      /* mdevctl may add notification events in the future:
>       * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to
> -- 
> 2.26.3
>