diff mbox

[v3,4/8] libxl: add support for disk hotplug scripts on FreeBSD

Message ID 1459436979-7475-5-git-send-email-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Pau Monné March 31, 2016, 3:09 p.m. UTC
Allow FreeBSD to execute hotplug scripts when attaching disk devices.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
Changes since v2:
 - Split the refactoring in a separate patch.
---
 tools/libxl/libxl_freebsd.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Ian Jackson April 1, 2016, 2:07 p.m. UTC | #1
Roger Pau Monne writes ("[PATCH v3 4/8] libxl: add support for disk hotplug scripts on FreeBSD"):
> Allow FreeBSD to execute hotplug scripts when attaching disk devices.

I am going to commit the FreeBSD-only patches without detailed
review, on the basis that you're the expert.

Thanks,
Ian.
diff mbox

Patch

diff --git a/tools/libxl/libxl_freebsd.c b/tools/libxl/libxl_freebsd.c
index 54db3d5..e86e28c 100644
--- a/tools/libxl/libxl_freebsd.c
+++ b/tools/libxl/libxl_freebsd.c
@@ -111,6 +111,35 @@  out:
     return rc;
 }
 
+static int libxl__hotplug_disk(libxl__gc *gc, libxl__device *dev,
+                               char ***args, char ***env,
+                               libxl__device_action action)
+{
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *script;
+    int nr = 0, rc;
+
+    script = libxl__xs_read(gc, XBT_NULL,
+                            GCSPRINTF("%s/%s", be_path, "script"));
+    if (!script) {
+        LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    const int arraysize = 4;
+    GCNEW_ARRAY(*args, arraysize);
+    (*args)[nr++] = script;
+    (*args)[nr++] = be_path;
+    (*args)[nr++] = (char *) libxl__device_action_to_string(action);
+    (*args)[nr++] = NULL;
+    assert(nr == arraysize);
+    rc = 1;
+
+out:
+    return rc;
+}
+
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
@@ -131,6 +160,13 @@  int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
         }
         rc = libxl__hotplug_nic(gc, dev, args, env, action, num_exec);
         break;
+    case LIBXL__DEVICE_KIND_VBD:
+        if (num_exec != 0) {
+            rc = 0;
+            goto out;
+        }
+        rc = libxl__hotplug_disk(gc, dev, args, env, action);
+        break;
     default:
         /* No need to execute any hotplug scripts */
         rc = 0;