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

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

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

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

12
 struct image;
12
 struct image;
13
 
13
 
14
 extern int imgdownload ( struct image *image, struct uri *uri,
14
 extern int imgdownload ( struct image *image, struct uri *uri,
15
-			 int ( * image_register ) ( struct image *image ) );
15
+			 int ( * action ) ( struct image *image ) );
16
 extern int imgfetch ( struct image *image, const char *uri_string,
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
 extern int imgload ( struct image *image );
18
 extern int imgload ( struct image *image );
19
 extern int imgexec ( struct image *image );
19
 extern int imgexec ( struct image *image );
20
 extern struct image * imgautoselect ( void );
20
 extern struct image * imgautoselect ( void );

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

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

Loading…
Cancel
Save