mirror of https://github.com/ipxe/ipxe.git
[image] Allow download job to complete before acting upon image
Allow the monojob controlling the download to complete before calling register_image() and friends. This allows the trailing "ok" from monojob.c to be printed before the image starts executing (and possibly printing output of its own). Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
560cc637f9
commit
3c9c27b8e6
|
@ -50,8 +50,6 @@ struct downloader {
|
||||||
struct image *image;
|
struct image *image;
|
||||||
/** Current position within image buffer */
|
/** Current position within image buffer */
|
||||||
size_t pos;
|
size_t pos;
|
||||||
/** Image registration routine */
|
|
||||||
int ( * register_image ) ( struct image *image );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,10 +73,6 @@ static void downloader_free ( struct refcnt *refcnt ) {
|
||||||
*/
|
*/
|
||||||
static void downloader_finished ( struct downloader *downloader, int rc ) {
|
static void downloader_finished ( struct downloader *downloader, int rc ) {
|
||||||
|
|
||||||
/* Register image if download was successful */
|
|
||||||
if ( rc == 0 )
|
|
||||||
rc = downloader->register_image ( downloader->image );
|
|
||||||
|
|
||||||
/* Shut down interfaces */
|
/* Shut down interfaces */
|
||||||
intf_shutdown ( &downloader->xfer, rc );
|
intf_shutdown ( &downloader->xfer, rc );
|
||||||
intf_shutdown ( &downloader->job, rc );
|
intf_shutdown ( &downloader->job, rc );
|
||||||
|
@ -219,7 +213,6 @@ static struct interface_descriptor downloader_job_desc =
|
||||||
*
|
*
|
||||||
* @v job Job control interface
|
* @v job Job control interface
|
||||||
* @v image Image to fill with downloaded file
|
* @v image Image to fill with downloaded file
|
||||||
* @v register_image Image registration routine
|
|
||||||
* @v type Location type to pass to xfer_open()
|
* @v type Location type to pass to xfer_open()
|
||||||
* @v ... Remaining arguments to pass to xfer_open()
|
* @v ... Remaining arguments to pass to xfer_open()
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
|
@ -229,7 +222,6 @@ static struct interface_descriptor downloader_job_desc =
|
||||||
* image registration routine @c register_image() will be called.
|
* image registration routine @c register_image() will be called.
|
||||||
*/
|
*/
|
||||||
int create_downloader ( struct interface *job, struct image *image,
|
int create_downloader ( struct interface *job, struct image *image,
|
||||||
int ( * register_image ) ( struct image *image ),
|
|
||||||
int type, ... ) {
|
int type, ... ) {
|
||||||
struct downloader *downloader;
|
struct downloader *downloader;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -245,7 +237,6 @@ int create_downloader ( struct interface *job, struct image *image,
|
||||||
intf_init ( &downloader->xfer, &downloader_xfer_desc,
|
intf_init ( &downloader->xfer, &downloader_xfer_desc,
|
||||||
&downloader->refcnt );
|
&downloader->refcnt );
|
||||||
downloader->image = image_get ( image );
|
downloader->image = image_get ( image );
|
||||||
downloader->register_image = register_image;
|
|
||||||
va_start ( args, type );
|
va_start ( args, type );
|
||||||
|
|
||||||
/* Instantiate child objects and attach to our interfaces */
|
/* Instantiate child objects and attach to our interfaces */
|
||||||
|
|
|
@ -13,7 +13,6 @@ struct interface;
|
||||||
struct image;
|
struct image;
|
||||||
|
|
||||||
extern int create_downloader ( struct interface *job, struct image *image,
|
extern int create_downloader ( struct interface *job, struct image *image,
|
||||||
int ( * register_image ) ( struct image *image ),
|
|
||||||
int type, ... );
|
int type, ... );
|
||||||
|
|
||||||
#endif /* _IPXE_DOWNLOADER_H */
|
#endif /* _IPXE_DOWNLOADER_H */
|
||||||
|
|
|
@ -12,9 +12,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
struct image;
|
struct image;
|
||||||
|
|
||||||
extern int imgdownload ( struct image *image, struct uri *uri,
|
extern int imgdownload ( struct image *image, struct uri *uri,
|
||||||
int ( * image_register ) ( struct image *image ) );
|
int ( * action ) ( struct image *image ) );
|
||||||
extern int imgfetch ( struct image *image, const char *uri_string,
|
extern int imgfetch ( struct image *image, const char *uri_string,
|
||||||
int ( * image_register ) ( struct image *image ) );
|
int ( * action ) ( struct image *image ) );
|
||||||
extern int imgload ( struct image *image );
|
extern int imgload ( struct image *image );
|
||||||
extern int imgexec ( struct image *image );
|
extern int imgexec ( struct image *image );
|
||||||
extern struct image * imgautoselect ( void );
|
extern struct image * imgautoselect ( void );
|
||||||
|
|
|
@ -40,11 +40,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
*
|
*
|
||||||
* @v image Image
|
* @v image Image
|
||||||
* @v uri URI
|
* @v uri URI
|
||||||
* @v image_register Action to take upon a successful download
|
* @v action Action to take upon a successful download
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int imgdownload ( struct image *image, struct uri *uri,
|
int imgdownload ( struct image *image, struct uri *uri,
|
||||||
int ( * image_register ) ( struct image *image ) ) {
|
int ( * action ) ( struct image *image ) ) {
|
||||||
size_t len = ( unparse_uri ( NULL, 0, uri, URI_ALL ) + 1 );
|
size_t len = ( unparse_uri ( NULL, 0, uri, URI_ALL ) + 1 );
|
||||||
char uri_string_redacted[len];
|
char uri_string_redacted[len];
|
||||||
const char *password;
|
const char *password;
|
||||||
|
@ -62,14 +62,18 @@ int imgdownload ( struct image *image, struct uri *uri,
|
||||||
uri->password = password;
|
uri->password = password;
|
||||||
|
|
||||||
/* Create downloader */
|
/* Create downloader */
|
||||||
if ( ( rc = create_downloader ( &monojob, image, image_register,
|
if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
|
||||||
LOCATION_URI, uri ) ) != 0 )
|
uri ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Wait for download to complete */
|
/* Wait for download to complete */
|
||||||
if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
|
if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
/* Act upon downloaded image */
|
||||||
|
if ( ( rc = action ( image ) ) != 0 )
|
||||||
|
return rc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,18 +82,18 @@ int imgdownload ( struct image *image, struct uri *uri,
|
||||||
*
|
*
|
||||||
* @v image Image
|
* @v image Image
|
||||||
* @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
|
* @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
|
||||||
* @v image_register Action to take upon a successful fetch
|
* @v action Action to take upon a successful download
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int imgfetch ( struct image *image, const char *uri_string,
|
int imgfetch ( struct image *image, const char *uri_string,
|
||||||
int ( * image_register ) ( struct image *image ) ) {
|
int ( * action ) ( struct image *image ) ) {
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if ( ! ( uri = parse_uri ( uri_string ) ) )
|
if ( ! ( uri = parse_uri ( uri_string ) ) )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
rc = imgdownload ( image, uri, image_register );
|
rc = imgdownload ( image, uri, action );
|
||||||
|
|
||||||
uri_put ( uri );
|
uri_put ( uri );
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue