]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
Remove device handler test code
[petitboot] / discover / device-handler.c
index 98194ad46cea86434b9fdf8217b8876106cbbe16..29c237131a4a267c25c11ce28e3f55d1b7c3ec95 100644 (file)
@@ -8,11 +8,13 @@
 
 #include <talloc/talloc.h>
 #include <list/list.h>
+#include <log/log.h>
 #include <pb-protocol/pb-protocol.h>
 
 #include "device-handler.h"
+#include "discover-server.h"
+#include "parser.h"
 #include "udev.h"
-#include "log.h"
 #include "paths.h"
 
 #define MOUNT_BIN "/bin/mount"
@@ -28,49 +30,16 @@ struct device_handler {
        struct list contexts;
 };
 
-struct discover_context {
-       char *id;
-       char *device_path;
-       char *mount_path;
-       struct udev_event *event;
-       struct device *device;
-       char **links;
-       int n_links;
-
-       struct list_item list;
-};
-
 struct mount_map {
        char *device_path;
        char *mount_point;
 };
 
-
-static struct boot_option options[] = {
-       {
-               .id = "1.1",
-               .name = "meep one",
-               .description = "meep description one",
-               .icon_file = "meep.one.png",
-               .boot_args = "root=/dev/sda1",
-       },
-};
-
-static struct device device = {
-       .id = "1",
-       .name = "meep",
-       .description = "meep description",
-       .icon_file = "meep.png",
-       .n_options = 1,
-       .options = options,
-};
-
 int device_handler_get_current_devices(struct device_handler *handler,
-               struct device **devices)
-
+       const struct device **devices)
 {
-       *devices = &device;
-       return 1;
+       *devices = handler->devices;
+       return handler->n_devices;
 }
 
 static int mkdir_recursive(const char *dir)
@@ -238,8 +207,11 @@ static int mount_device(struct discover_context *ctx)
                goto out_rmdir;
        }
 
-       if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+       if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+               pb_log("%s: mount failed (%d): %s\n", __func__,
+                       WEXITSTATUS(status), ctx->event->device);
                goto out_rmdir;
+       }
 
        setup_device_links(ctx);
        return 0;
@@ -294,7 +266,6 @@ static struct discover_context *find_context(struct device_handler *handler,
        return NULL;
 }
 
-
 static int destroy_context(void *arg)
 {
        struct discover_context *ctx = arg;
@@ -331,15 +302,23 @@ static int handle_add_event(struct device_handler *handler,
 
        rc = mount_device(ctx);
        if (rc) {
-               pb_log("mount_device failed for %s\n", event->device);
                talloc_free(ctx);
                return 0;
        }
 
        list_add(&handler->contexts, &ctx->list);
-
        talloc_set_destructor(ctx, destroy_context);
 
+       /* set up the top-level device */
+       ctx->device = talloc_zero(ctx, struct device);
+       ctx->device->id = talloc_strdup(ctx->device, ctx->id);
+       list_init(&ctx->device->boot_options);
+
+       /* run the parsers */
+       iterate_parsers(ctx);
+
+       discover_server_notify_add(handler->server, ctx->device);
+
        return 0;
 }
 
@@ -352,6 +331,8 @@ static int handle_remove_event(struct device_handler *handler,
        if (!ctx)
                return 0;
 
+       discover_server_notify_remove(handler->server, ctx->device);
+
        talloc_free(ctx);
 
        return 0;
@@ -382,12 +363,15 @@ struct device_handler *device_handler_init(struct discover_server *server)
        handler = talloc(NULL, struct device_handler);
        handler->devices = NULL;
        handler->n_devices = 0;
+       handler->server = server;
 
        list_init(&handler->contexts);
 
        /* set up our mount point base */
        mkdir_recursive(mount_base());
 
+       parser_init();
+
        return handler;
 }
 
@@ -395,4 +379,3 @@ void device_handler_destroy(struct device_handler *handler)
 {
        talloc_free(handler);
 }
-