diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-02-28 17:05:06 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-04-29 14:31:20 +1000 |
commit | 3b29ff8c2a6489b9517d61c0f63256a1ad0c36f7 (patch) | |
tree | 437303aa325dd4d392f962beca08f6f30c5d216a | |
parent | 06a49ebdfc795a70b938f5aee29f3c488ef9fc21 (diff) | |
download | talos-petitboot-3b29ff8c2a6489b9517d61c0f63256a1ad0c36f7.tar.gz talos-petitboot-3b29ff8c2a6489b9517d61c0f63256a1ad0c36f7.zip |
discover: Add uuid and label parameters to persistent device data
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>
-rw-r--r-- | discover/device-handler.c | 44 | ||||
-rw-r--r-- | discover/device-handler.h | 3 |
2 files changed, 28 insertions, 19 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c index 6952dde..7533cfa 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -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; diff --git a/discover/device-handler.h b/discover/device-handler.h index 809f88e..e298fed 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -17,6 +17,9 @@ struct discover_device { char **links; int n_links; + char *uuid; + char *label; + char *mount_path; char *device_path; }; |