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>
return handler->devices[index]->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;
- .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,
- for (link = links; link->env; link++) {
+ for (link = links; link->dir; link++) {
- value = event_get_param(ctx->event, link->env);
- if (!value || !*value)
+ if (!link->val || !*link->val)
- 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);
if (!pb_mkdir_recursive(dir)) {
unlink(path);
-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];
const char *mountpoint;
const char *argv[6];
- setup_device_links(ctx);
+ setup_device_links(dev);
{
struct discover_context *ctx;
struct discover_device *dev;
{
struct discover_context *ctx;
struct discover_device *dev;
int rc;
/* create our context */
int rc;
/* create our context */
- 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;
if (rc) {
talloc_free(ctx);
return 0;
char **links;
int n_links;
char **links;
int n_links;
+ char *uuid;
+ char *label;
+
char *mount_path;
char *device_path;
};
char *mount_path;
char *device_path;
};