]> git.ozlabs.org Git - petitboot/commitdiff
discover: Add uuid and label parameters to persistent device data
authorJeremy Kerr <jk@ozlabs.org>
Thu, 28 Feb 2013 09:05:06 +0000 (17:05 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 29 Apr 2013 04:31:20 +0000 (14:31 +1000)
Rather than depending on the event (which is only available during
inital discovery) for UUID and label parameters, this change adds uuid
and label members to struct discover_device.

This means that the label and UUID are available during the device's
lifetime, not just during initial discovery. We can also just pass the
device to some of the device handling code, rather than the discover
context.

Also, fix an issue where we don't use the raw label/uuid (instead of the
encoded one) in setup_device_links.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/device-handler.c
discover/device-handler.h

index 6952ddefa6387b18d6f60120b7ba621ca7eae342..7533cfa1d514b0b6f80048ad7362b5b932b3f94f 100644 (file)
@@ -129,36 +129,33 @@ const struct device *device_handler_get_device(
        return handler->devices[index]->device;
 }
 
-static void setup_device_links(struct discover_context *ctx)
+static void setup_device_links(struct discover_device *dev)
 {
-       struct discover_device *dev = ctx->device;
        struct link {
-               char *env, *dir;
+               const char *dir, *val;
        } *link, links[] = {
                {
-                       .env = "ID_FS_UUID",
-                       .dir = "disk/by-uuid"
+                       .dir = "disk/by-uuid",
+                       .val = dev->uuid,
                },
                {
-                       .env = "ID_FS_LABEL",
-                       .dir = "disk/by-label"
+                       .dir = "disk/by-label",
+                       .val = dev->label,
                },
                {
-                       .env = NULL
+                       .dir = NULL
                }
        };
 
-       for (link = links; link->env; link++) {
+       for (link = links; link->dir; link++) {
                char *enc, *dir, *path;
-               const char *value;
 
-               value = event_get_param(ctx->event, link->env);
-               if (!value || !*value)
+               if (!link->val || !*link->val)
                        continue;
 
-               enc = encode_label(ctx, value);
-               dir = join_paths(ctx, mount_base(), link->dir);
-               path = join_paths(dev, dir, value);
+               enc = encode_label(dev, link->val);
+               dir = join_paths(dev, mount_base(), link->dir);
+               path = join_paths(dev, dir, enc);
 
                if (!pb_mkdir_recursive(dir)) {
                        unlink(path);
@@ -190,9 +187,8 @@ static void remove_device_links(struct discover_device *dev)
                unlink(dev->links[i]);
 }
 
-static int mount_device(struct discover_context *ctx)
+static int mount_device(struct discover_device *dev)
 {
-       struct discover_device *dev = ctx->device;
        const char *mountpoint;
        const char *argv[6];
 
@@ -225,7 +221,7 @@ static int mount_device(struct discover_context *ctx)
                        goto out_rmdir;
        }
 
-       setup_device_links(ctx);
+       setup_device_links(dev);
        return 0;
 
 out_rmdir:
@@ -325,6 +321,7 @@ static int handle_add_udev_event(struct device_handler *handler,
 {
        struct discover_context *ctx;
        struct discover_device *dev;
+       const char *param;
        int rc;
 
        /* create our context */
@@ -337,7 +334,16 @@ static int handle_add_udev_event(struct device_handler *handler,
 
        ctx->device = dev;
 
-       rc = mount_device(ctx);
+       /* try to parse UUID and labels */
+       param = event_get_param(ctx->event, "ID_FS_UUID");
+       if (param)
+               dev->uuid = talloc_strdup(dev, param);
+
+       param = event_get_param(ctx->event, "ID_FS_LABEL");
+       if (param)
+               dev->label = talloc_strdup(dev, param);
+
+       rc = mount_device(dev);
        if (rc) {
                talloc_free(ctx);
                return 0;
index 809f88ee727ac1e16e9891c0714121fc802aa6d0..e298fedc9da7edd83a3daa2f6ee136b3f4d95448 100644 (file)
@@ -17,6 +17,9 @@ struct discover_device {
        char                    **links;
        int                     n_links;
 
+       char                    *uuid;
+       char                    *label;
+
        char                    *mount_path;
        char                    *device_path;
 };