summaryrefslogtreecommitdiffstats
path: root/src/usr/imgmgmt.c
diff options
context:
space:
mode:
authorMichael Brown2011-10-25 02:41:41 +0200
committerMichael Brown2011-10-25 02:41:41 +0200
commit790035f78d6a3b11e049c9df3df41155fd3a12ef (patch)
treee1f81cbf2fbe1fdd5a12062b88b10fd55ca7a668 /src/usr/imgmgmt.c
parent[cmdline] Allow "sleep" command to be interrupted (diff)
downloadipxe-790035f78d6a3b11e049c9df3df41155fd3a12ef.tar.gz
ipxe-790035f78d6a3b11e049c9df3df41155fd3a12ef.tar.xz
ipxe-790035f78d6a3b11e049c9df3df41155fd3a12ef.zip
[image] Eliminate the register_and_xxx_image() functions
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>
Diffstat (limited to 'src/usr/imgmgmt.c')
-rw-r--r--src/usr/imgmgmt.c134
1 files changed, 24 insertions, 110 deletions
diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c
index dbf792b7..e323dd0c 100644
--- a/src/usr/imgmgmt.c
+++ b/src/usr/imgmgmt.c
@@ -36,108 +36,12 @@ 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;
}
/**