Browse Source

[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>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
3c9c27b8e6
4 changed files with 13 additions and 19 deletions
  1. 0
    9
      src/core/downloader.c
  2. 0
    1
      src/include/ipxe/downloader.h
  3. 2
    2
      src/include/usr/imgmgmt.h
  4. 11
    7
      src/usr/imgmgmt.c

+ 0
- 9
src/core/downloader.c View File

@@ -50,8 +50,6 @@ struct downloader {
50 50
 	struct image *image;
51 51
 	/** Current position within image buffer */
52 52
 	size_t pos;
53
-	/** Image registration routine */
54
-	int ( * register_image ) ( struct image *image );
55 53
 };
56 54
 
57 55
 /**
@@ -75,10 +73,6 @@ static void downloader_free ( struct refcnt *refcnt ) {
75 73
  */
76 74
 static void downloader_finished ( struct downloader *downloader, int rc ) {
77 75
 
78
-	/* Register image if download was successful */
79
-	if ( rc == 0 )
80
-		rc = downloader->register_image ( downloader->image );
81
-
82 76
 	/* Shut down interfaces */
83 77
 	intf_shutdown ( &downloader->xfer, rc );
84 78
 	intf_shutdown ( &downloader->job, rc );
@@ -219,7 +213,6 @@ static struct interface_descriptor downloader_job_desc =
219 213
  *
220 214
  * @v job		Job control interface
221 215
  * @v image		Image to fill with downloaded file
222
- * @v register_image	Image registration routine
223 216
  * @v type		Location type to pass to xfer_open()
224 217
  * @v ...		Remaining arguments to pass to xfer_open()
225 218
  * @ret rc		Return status code
@@ -229,7 +222,6 @@ static struct interface_descriptor downloader_job_desc =
229 222
  * image registration routine @c register_image() will be called.
230 223
  */
231 224
 int create_downloader ( struct interface *job, struct image *image,
232
-			int ( * register_image ) ( struct image *image ),
233 225
 			int type, ... ) {
234 226
 	struct downloader *downloader;
235 227
 	va_list args;
@@ -245,7 +237,6 @@ int create_downloader ( struct interface *job, struct image *image,
245 237
 	intf_init ( &downloader->xfer, &downloader_xfer_desc,
246 238
 		    &downloader->refcnt );
247 239
 	downloader->image = image_get ( image );
248
-	downloader->register_image = register_image;
249 240
 	va_start ( args, type );
250 241
 
251 242
 	/* Instantiate child objects and attach to our interfaces */

+ 0
- 1
src/include/ipxe/downloader.h View File

@@ -13,7 +13,6 @@ struct interface;
13 13
 struct image;
14 14
 
15 15
 extern int create_downloader ( struct interface *job, struct image *image,
16
-			       int ( * register_image ) ( struct image *image ),
17 16
 			       int type, ... );
18 17
 
19 18
 #endif /* _IPXE_DOWNLOADER_H */

+ 2
- 2
src/include/usr/imgmgmt.h View File

@@ -12,9 +12,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 struct image;
13 13
 
14 14
 extern int imgdownload ( struct image *image, struct uri *uri,
15
-			 int ( * image_register ) ( struct image *image ) );
15
+			 int ( * action ) ( struct image *image ) );
16 16
 extern int imgfetch ( struct image *image, const char *uri_string,
17
-		      int ( * image_register ) ( struct image *image ) );
17
+		      int ( * action ) ( struct image *image ) );
18 18
 extern int imgload ( struct image *image );
19 19
 extern int imgexec ( struct image *image );
20 20
 extern struct image * imgautoselect ( void );

+ 11
- 7
src/usr/imgmgmt.c View File

@@ -40,11 +40,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
40 40
  *
41 41
  * @v image		Image
42 42
  * @v uri		URI
43
- * @v image_register	Action to take upon a successful download
43
+ * @v action		Action to take upon a successful download
44 44
  * @ret rc		Return status code
45 45
  */
46 46
 int imgdownload ( struct image *image, struct uri *uri,
47
-		  int ( * image_register ) ( struct image *image ) ) {
47
+		  int ( * action ) ( struct image *image ) ) {
48 48
 	size_t len = ( unparse_uri ( NULL, 0, uri, URI_ALL ) + 1 );
49 49
 	char uri_string_redacted[len];
50 50
 	const char *password;
@@ -62,14 +62,18 @@ int imgdownload ( struct image *image, struct uri *uri,
62 62
 	uri->password = password;
63 63
 
64 64
 	/* Create downloader */
65
-	if ( ( rc = create_downloader ( &monojob, image, image_register,
66
-					LOCATION_URI, uri ) ) != 0 )
65
+	if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
66
+					uri ) ) != 0 )
67 67
 		return rc;
68 68
 
69 69
 	/* Wait for download to complete */
70 70
 	if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
71 71
 		return rc;
72 72
 
73
+	/* Act upon downloaded image */
74
+	if ( ( rc = action ( image ) ) != 0 )
75
+		return rc;
76
+
73 77
 	return 0;
74 78
 }
75 79
 
@@ -78,18 +82,18 @@ int imgdownload ( struct image *image, struct uri *uri,
78 82
  *
79 83
  * @v image		Image
80 84
  * @v uri_string	URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
81
- * @v image_register	Action to take upon a successful fetch
85
+ * @v action		Action to take upon a successful download
82 86
  * @ret rc		Return status code
83 87
  */
84 88
 int imgfetch ( struct image *image, const char *uri_string,
85
-	       int ( * image_register ) ( struct image *image ) ) {
89
+	       int ( * action ) ( struct image *image ) ) {
86 90
 	struct uri *uri;
87 91
 	int rc;
88 92
 
89 93
 	if ( ! ( uri = parse_uri ( uri_string ) ) )
90 94
 		return -ENOMEM;
91 95
 
92
-	rc = imgdownload ( image, uri, image_register );
96
+	rc = imgdownload ( image, uri, action );
93 97
 
94 98
 	uri_put ( uri );
95 99
 	return rc;

Loading…
Cancel
Save