]> git.ozlabs.org Git - petitboot/blobdiff - discover/boot.c
discover/boot: Store clean_* in the boot task
[petitboot] / discover / boot.c
index a1e20e64914aac26a7dce5af50fa1c8deed99179..d0b57b5aac03505a306033845072740aa1f4c335 100644 (file)
@@ -31,6 +31,7 @@ enum boot_process_state {
        BOOT_STATE_INITIAL,
        BOOT_STATE_IMAGE_LOADING,
        BOOT_STATE_INITRD_LOADING,
+       BOOT_STATE_DTB_LOADING,
        BOOT_STATE_FINISH,
        BOOT_STATE_UNKNOWN,
 };
@@ -41,6 +42,9 @@ struct boot_task {
        char *local_initrd;
        char *local_dtb;
        char *args;
+       unsigned int clean_image;
+       unsigned int clean_initrd;
+       unsigned int clean_dtb;
        struct pb_url *image, *initrd, *dtb;
        boot_status_fn status_fn;
        void *status_arg;
@@ -287,77 +291,88 @@ static void run_boot_hooks(struct boot_task *task)
        free(hooks);
 }
 
-static void boot_process(void *ctx, int *status)
+static void boot_process(void *ctx, int status)
 {
        struct boot_task *task = ctx;
-       unsigned int clean_image = 0;
-       unsigned int clean_initrd = 0;
-       unsigned int clean_dtb = 0;
        int result = -1;
 
        if (task->state == BOOT_STATE_INITIAL) {
                update_status(task->status_fn, task->status_arg,
                                BOOT_STATUS_INFO, "loading kernel");
                task->local_image = load_url_async(task, task->image,
-                                       &clean_image, boot_process);
+                                       &task->clean_image, boot_process);
                if (!task->local_image) {
                        update_status(task->status_fn, task->status_arg,
                                        BOOT_STATUS_ERROR,
                                        "Couldn't load kernel image");
                        goto no_load;
-               } else {
-                       task->state = BOOT_STATE_IMAGE_LOADING;
-                       *status = 0;
-                       return;
                }
+               task->state = BOOT_STATE_IMAGE_LOADING;
+               return;
        }
 
        if (task->state == BOOT_STATE_IMAGE_LOADING) {
+               if (status) {
+                       update_status(task->status_fn, task->status_arg,
+                                       BOOT_STATUS_ERROR,
+                                       "Error loading kernel image");
+                       goto no_load;
+               }
+               task->state = BOOT_STATE_INITRD_LOADING;
+
                if (task->initrd) {
                        update_status(task->status_fn, task->status_arg,
                                        BOOT_STATUS_INFO, "loading initrd");
                        task->local_initrd = load_url_async(task, task->initrd,
-                                       &clean_initrd, boot_process);
+                                       &task->clean_initrd, boot_process);
                        if (!task->local_initrd) {
                                update_status(task->status_fn, task->status_arg,
                                                BOOT_STATUS_ERROR,
                                                "Couldn't load initrd image");
                                goto no_load;
-                       } else {
-                               task->state = BOOT_STATE_INITRD_LOADING;
-                               *status = 0;
-                               return;
                        }
-               } else {
-                       task->state = BOOT_STATE_INITRD_LOADING;
+                       return;
                }
        }
 
        if (task->state == BOOT_STATE_INITRD_LOADING) {
+               if (status) {
+                       update_status(task->status_fn, task->status_arg,
+                                       BOOT_STATUS_ERROR,
+                                       "Error loading initrd");
+                       goto no_load;
+               }
+               task->state = BOOT_STATE_DTB_LOADING;
+
                if (task->dtb) {
                        update_status(task->status_fn, task->status_arg,
                                        BOOT_STATUS_INFO,
                                        "loading device tree");
                        task->local_dtb = load_url_async(task, task->dtb,
-                                               &clean_dtb, boot_process);
+                                               &task->clean_dtb, boot_process);
                        if (!task->local_dtb) {
                                update_status(task->status_fn, task->status_arg,
                                                BOOT_STATUS_ERROR,
                                                "Couldn't load device tree");
                                goto no_load;
-                       } else {
-                               task->state = BOOT_STATE_FINISH;
-                               *status = 0;
-                               return;
                        }
-               } else {
-                       task->state = BOOT_STATE_FINISH;
+                       return;
+               }
+       }
+
+       if (task->state == BOOT_STATE_DTB_LOADING) {
+               if (status) {
+                       update_status(task->status_fn, task->status_arg,
+                                       BOOT_STATUS_ERROR,
+                                       "Error loading dtb");
+                       goto no_load;
                }
+               task->state = BOOT_STATE_FINISH;
        }
 
+
        if (task->state != BOOT_STATE_FINISH) {
                task->state = BOOT_STATE_UNKNOWN;
-               *status = -1;
                return;
        }
 
@@ -374,11 +389,11 @@ static void boot_process(void *ctx, int *status)
        }
 
 no_load:
-       if (clean_image)
+       if (task->clean_image)
                unlink(task->local_image);
-       if (clean_initrd)
+       if (task->clean_initrd)
                unlink(task->local_initrd);
-       if (clean_dtb)
+       if (task->clean_dtb)
                unlink(task->local_dtb);
 
        if (!result) {
@@ -396,8 +411,6 @@ no_load:
        }
 
        talloc_free(task);
-
-       *status = result;
 }
 
 int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd,
@@ -406,7 +419,6 @@ int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd,
        struct boot_task *boot_task;
        struct pb_url *image = NULL;
        const char *boot_desc;
-       int result;
 
        if (opt && opt->option->name)
                boot_desc = opt->option->name;
@@ -457,7 +469,7 @@ int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd,
                boot_task->args = NULL;
        }
 
-       boot_process(boot_task, &result);
+       boot_process(boot_task, 0);
 
-       return result;
+       return 0;
 }