]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[image] Eliminate the register_and_xxx_image() functions
authorMichael Brown <mcb30@ipxe.org>
Tue, 25 Oct 2011 00:41:41 +0000 (01:41 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 25 Oct 2011 00:41:41 +0000 (01:41 +0100)
All users of imgdownload() require registration of the image, so make
registration an integral part of imgdownload() itself and simplify the
"action" parameter to be one of image_select(), image_exec() et al.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/interface/syslinux/comboot_call.c
src/core/image.c
src/hci/commands/image_cmd.c
src/include/usr/imgmgmt.h
src/usr/autoboot.c
src/usr/imgmgmt.c

index 571ba9e6db3a72effad682ea81c28316fdfcead5..818cae840f27fd9258cc31780d6880e904eb56fa 100644 (file)
@@ -185,7 +185,7 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
 
                /* Fetch initrd */
                if ( ( rc = imgdownload_string ( initrd_file, NULL, NULL,
-                                                register_and_put_image ))!=0){
+                                                NULL ) ) != 0 ) {
                        DBG ( "COMBOOT: could not fetch initrd: %s\n",
                              strerror ( rc ) );
                        return rc;
@@ -200,7 +200,7 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
 
        /* Allocate and fetch kernel */
        if ( ( rc = imgdownload_string ( kernel_file, NULL, cmdline,
-                                        register_and_replace_image ) ) != 0 ) {
+                                        image_replace ) ) != 0 ) {
                DBG ( "COMBOOT: could not fetch kernel: %s\n",
                      strerror ( rc ) );
                return rc;
index 86c264c26634b2626e4c6bdd3347ce03af9dcc94..b1eba4ad4da1d7e2c409394b9ab3405ed8ad4a1b 100644 (file)
@@ -224,8 +224,8 @@ int image_exec ( struct image *image ) {
        /* Sanity check */
        assert ( image->flags & IMAGE_REGISTERED );
 
-       /* Check that this image can be executed */
-       if ( ( rc = image_probe ( image ) ) != 0 )
+       /* Check that this image can be selected for execution */
+       if ( ( rc = image_select ( image ) ) != 0 )
                return rc;
 
        /* Switch current working directory to be that of the image itself */
@@ -302,6 +302,10 @@ int image_replace ( struct image *replacement ) {
                return rc;
        }
 
+       /* Check that the replacement image can be executed */
+       if ( ( rc = image_probe ( replacement ) ) != 0 )
+               return rc;
+
        /* Clear any existing replacement */
        image_put ( image->replacement );
 
index 1ff3ff49be4c8972b97842c3ee3d250aba50a38d..999442ca36bc1ccf16e0f766745ea4d0d91d5afb 100644 (file)
@@ -114,8 +114,7 @@ static int imgfetch_core_exec ( int argc, char **argv,
  */
 static int imgfetch_exec ( int argc, char **argv ) {
 
-       return imgfetch_core_exec ( argc, argv, "fetch",
-                                   register_and_put_image );
+       return imgfetch_core_exec ( argc, argv, "fetch", NULL );
 }
 
 /**
@@ -127,8 +126,7 @@ static int imgfetch_exec ( int argc, char **argv ) {
  */
 static int kernel_exec ( int argc, char **argv ) {
 
-       return imgfetch_core_exec ( argc, argv, "select",
-                                   register_and_select_image );
+       return imgfetch_core_exec ( argc, argv, "select", image_select );
 }
 
 /**
@@ -140,8 +138,7 @@ static int kernel_exec ( int argc, char **argv ) {
  */
 static int chain_exec ( int argc, char **argv) {
 
-       return imgfetch_core_exec ( argc, argv, "boot",
-                                   register_and_boot_image );
+       return imgfetch_core_exec ( argc, argv, "boot", image_exec );
 }
 
 /** "imgselect" options */
index 1c0a212e3d030275c51e4b3ea7b257b8d20f415b..71d587ba4314ca1c3425edeb2a50bd7a8a8e1074 100644 (file)
@@ -11,11 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <ipxe/image.h>
 
-extern int register_and_put_image ( struct image *image );
-extern int register_and_probe_image ( struct image *image );
-extern int register_and_select_image ( struct image *image );
-extern int register_and_boot_image ( struct image *image );
-extern int register_and_replace_image ( struct image *image );
 extern int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
                         int ( * action ) ( struct image *image ) );
 extern int imgdownload_string ( const char *uri_string, const char *name,
index 63ca4c3d08fdabd11fdba51fbe4685f86fb303bf..5bfadec0be2f8dd6c4d71c2f831cddf159b403de 100644 (file)
@@ -158,7 +158,7 @@ int uriboot ( struct uri *filename, struct uri *root_path, int drive,
        /* Attempt filename boot if applicable */
        if ( filename ) {
                if ( ( rc = imgdownload ( filename, NULL, NULL,
-                                         register_and_boot_image ) ) != 0 ) {
+                                         image_exec ) ) != 0 ) {
                        printf ( "\nCould not chain image: %s\n",
                                 strerror ( rc ) );
                        /* Fall through to (possibly) attempt a SAN boot
index dbf792b75c9083252b9b427976aedda6d99b2d3b..e323dd0c56bcb8c5e48a380577efe72aacdf4629 100644 (file)
@@ -35,109 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
  *
  */
 
-/**
- * Register an image and leave it registered
- *
- * @v image            Executable image
- * @ret rc             Return status code
- *
- * This function assumes an ownership of the passed image.
- */
-int register_and_put_image ( struct image *image ) {
-       int rc;
-
-       rc = register_image ( image );
-       image_put ( image );
-       return rc;
-}
-
-/**
- * Register and probe an image
- *
- * @v image            Executable image
- * @ret rc             Return status code
- *
- * This function assumes an ownership of the passed image.
- */
-int register_and_probe_image ( struct image *image ) {
-       int rc;
-
-       if ( ( rc = register_and_put_image ( image ) ) != 0 )
-               return rc;
-
-       if ( ( rc = image_probe ( image ) ) != 0 )
-               return rc;
-
-       return 0;
-}
-
-/**
- * Register and select an image
- *
- * @v image            Executable image
- * @ret rc             Return status code
- *
- * This function assumes an ownership of the passed image.
- */
-int register_and_select_image ( struct image *image ) {
-       int rc;
-
-       if ( ( rc = register_and_probe_image ( image ) ) != 0 )
-               return rc;
-
-       if ( ( rc = image_select ( image ) ) != 0 )
-               return rc;
-
-       return 0;
-}
-
-/**
- * Register and boot an image
- *
- * @v image            Image
- * @ret rc             Return status code
- *
- * This function assumes an ownership of the passed image.
- */
-int register_and_boot_image ( struct image *image ) {
-       int rc;
-
-       if ( ( rc = register_and_select_image ( image ) ) != 0 )
-               return rc;
-
-       if ( ( rc = image_exec ( image ) ) != 0 )
-               return rc;
-
-       return 0;
-}
-
-/**
- * Register and replace image
- *
- * @v image            Image
- * @ret rc             Return status code
- *
- * This function assumes an ownership of the passed image.
- */
-int register_and_replace_image ( struct image *image ) {
-       int rc;
-
-       if ( ( rc = register_and_probe_image ( image ) ) != 0 )
-               return rc;
-
-       if ( ( rc = image_replace ( image ) ) != 0 )
-               return rc;
-
-       return 0;
-}
-
 /**
  * Download an image
  *
  * @v uri              URI
  * @v name             Image name, or NULL to use default
  * @v cmdline          Command line, or NULL for no command line
- * @v action           Action to take upon a successful download
+ * @v action           Action to take upon a successful download, or NULL
  * @ret rc             Return status code
  */
 int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
@@ -150,8 +54,10 @@ int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
 
        /* Allocate image */
        image = alloc_image();
-       if ( ! image )
-               return -ENOMEM;
+       if ( ! image ) {
+               rc = -ENOMEM;
+               goto err_alloc_image;
+       }
 
        /* Set image name */
        if ( name )
@@ -174,23 +80,31 @@ int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
        /* Create downloader */
        if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
                                        uri ) ) != 0 ) {
-               image_put ( image );
-               return rc;
+               goto err_create_downloader;
        }
 
        /* Wait for download to complete */
-       if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 ) {
-               image_put ( image );
-               return rc;
-       }
+       if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
+               goto err_monojob_wait;
+
+       /* Register image */
+       if ( ( rc = register_image ( image ) ) != 0 )
+               goto err_register_image;
 
-       /* Act upon downloaded image.  This action assumes our
-        * ownership of the image.
+       /* Drop local reference to image.  Image is guaranteed to
+        * remain in scope since it is registered.
         */
-       if ( ( rc = action ( image ) ) != 0 )
-               return rc;
+       image_put ( image );
+
+       /* Carry out specified post-download action, if applicable */
+       return ( action ? action ( image ) : 0 );
 
-       return 0;
+ err_register_image:
+ err_monojob_wait:
+ err_create_downloader:
+       image_put ( image );
+ err_alloc_image:
+       return rc;
 }
 
 /**