diff options
author | Michael Brown <mcb30@ipxe.org> | 2011-03-09 16:55:51 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2011-03-09 16:57:34 +0000 |
commit | 9fa4ac2e9a781861e36e618eb1d461d8dc53a27c (patch) | |
tree | 437a36ae53aa9361f33c3c435c7b0978a9de42f5 /src/usr/imgmgmt.c | |
parent | ae92700fd4594afc50f057ccb07690567327e508 (diff) | |
download | ipxe-9fa4ac2e9a781861e36e618eb1d461d8dc53a27c.zip ipxe-9fa4ac2e9a781861e36e618eb1d461d8dc53a27c.tar.gz ipxe-9fa4ac2e9a781861e36e618eb1d461d8dc53a27c.tar.bz2 |
[image] Simplify use of imgdownload()
Allow imgdownload() to be called without first having to allocate (and
so keep track of) an image.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/usr/imgmgmt.c')
-rw-r--r-- | src/usr/imgmgmt.c | 104 |
1 files changed, 91 insertions, 13 deletions
diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c index f375db8..b1e8cbb 100644 --- a/src/usr/imgmgmt.c +++ b/src/usr/imgmgmt.c @@ -36,20 +36,55 @@ FILE_LICENCE ( GPL2_OR_LATER ); */ /** - * Register and select an image + * 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_select_image ( struct image *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_image ( image ) ) != 0 ) + 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; @@ -61,6 +96,8 @@ int register_and_select_image ( struct image *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; @@ -75,23 +112,56 @@ int register_and_boot_image ( struct image *image ) { } /** - * Download an image + * 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 * @ret rc Return status code */ -int imgdownload ( struct image *image, struct uri *uri, +int imgdownload ( struct uri *uri, const char *name, const char *cmdline, int ( * action ) ( struct image *image ) ) { + struct image *image; size_t len = ( unparse_uri ( NULL, 0, uri, URI_ALL ) + 1 ); char uri_string_redacted[len]; const char *password; int rc; + /* Allocate image */ + image = alloc_image(); + if ( ! image ) + return -ENOMEM; + + /* Set image name */ + image_set_name ( image, name ); + /* Set image URI */ image_set_uri ( image, uri ); + /* Set image command line */ + image_set_cmdline ( image, cmdline ); + /* Redact password portion of URI, if necessary */ password = uri->password; if ( password ) @@ -102,14 +172,20 @@ int imgdownload ( struct image *image, struct uri *uri, /* Create downloader */ if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI, - uri ) ) != 0 ) + uri ) ) != 0 ) { + image_put ( image ); return rc; + } /* Wait for download to complete */ - if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 ) + if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 ) { + image_put ( image ); return rc; + } - /* Act upon downloaded image */ + /* Act upon downloaded image. This action assumes our + * ownership of the image. + */ if ( ( rc = action ( image ) ) != 0 ) return rc; @@ -117,22 +193,24 @@ int imgdownload ( struct image *image, struct uri *uri, } /** - * Fetch an image + * Download an image * - * @v image Image * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz") + * @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 * @ret rc Return status code */ -int imgfetch ( struct image *image, const char *uri_string, - int ( * action ) ( struct image *image ) ) { +int imgdownload_string ( const char *uri_string, const char *name, + const char *cmdline, + int ( * action ) ( struct image *image ) ) { struct uri *uri; int rc; if ( ! ( uri = parse_uri ( uri_string ) ) ) return -ENOMEM; - rc = imgdownload ( image, uri, action ); + rc = imgdownload ( uri, name, cmdline, action ); uri_put ( uri ); return rc; |