Browse Source

[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>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
790035f78d

+ 2
- 2
src/arch/i386/interface/syslinux/comboot_call.c View File

@@ -185,7 +185,7 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
185 185
 
186 186
 		/* Fetch initrd */
187 187
 		if ( ( rc = imgdownload_string ( initrd_file, NULL, NULL,
188
-						 register_and_put_image ))!=0){
188
+						 NULL ) ) != 0 ) {
189 189
 			DBG ( "COMBOOT: could not fetch initrd: %s\n",
190 190
 			      strerror ( rc ) );
191 191
 			return rc;
@@ -200,7 +200,7 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
200 200
 
201 201
 	/* Allocate and fetch kernel */
202 202
 	if ( ( rc = imgdownload_string ( kernel_file, NULL, cmdline,
203
-					 register_and_replace_image ) ) != 0 ) {
203
+					 image_replace ) ) != 0 ) {
204 204
 		DBG ( "COMBOOT: could not fetch kernel: %s\n",
205 205
 		      strerror ( rc ) );
206 206
 		return rc;

+ 6
- 2
src/core/image.c View File

@@ -224,8 +224,8 @@ int image_exec ( struct image *image ) {
224 224
 	/* Sanity check */
225 225
 	assert ( image->flags & IMAGE_REGISTERED );
226 226
 
227
-	/* Check that this image can be executed */
228
-	if ( ( rc = image_probe ( image ) ) != 0 )
227
+	/* Check that this image can be selected for execution */
228
+	if ( ( rc = image_select ( image ) ) != 0 )
229 229
 		return rc;
230 230
 
231 231
 	/* Switch current working directory to be that of the image itself */
@@ -302,6 +302,10 @@ int image_replace ( struct image *replacement ) {
302 302
 		return rc;
303 303
 	}
304 304
 
305
+	/* Check that the replacement image can be executed */
306
+	if ( ( rc = image_probe ( replacement ) ) != 0 )
307
+		return rc;
308
+
305 309
 	/* Clear any existing replacement */
306 310
 	image_put ( image->replacement );
307 311
 

+ 3
- 6
src/hci/commands/image_cmd.c View File

@@ -114,8 +114,7 @@ static int imgfetch_core_exec ( int argc, char **argv,
114 114
  */
115 115
 static int imgfetch_exec ( int argc, char **argv ) {
116 116
 
117
-	return imgfetch_core_exec ( argc, argv, "fetch",
118
-				    register_and_put_image );
117
+	return imgfetch_core_exec ( argc, argv, "fetch", NULL );
119 118
 }
120 119
 
121 120
 /**
@@ -127,8 +126,7 @@ static int imgfetch_exec ( int argc, char **argv ) {
127 126
  */
128 127
 static int kernel_exec ( int argc, char **argv ) {
129 128
 
130
-	return imgfetch_core_exec ( argc, argv, "select",
131
-				    register_and_select_image );
129
+	return imgfetch_core_exec ( argc, argv, "select", image_select );
132 130
 }
133 131
 
134 132
 /**
@@ -140,8 +138,7 @@ static int kernel_exec ( int argc, char **argv ) {
140 138
  */
141 139
 static int chain_exec ( int argc, char **argv) {
142 140
 
143
-	return imgfetch_core_exec ( argc, argv, "boot",
144
-				    register_and_boot_image );
141
+	return imgfetch_core_exec ( argc, argv, "boot", image_exec );
145 142
 }
146 143
 
147 144
 /** "imgselect" options */

+ 0
- 5
src/include/usr/imgmgmt.h View File

@@ -11,11 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12 12
 #include <ipxe/image.h>
13 13
 
14
-extern int register_and_put_image ( struct image *image );
15
-extern int register_and_probe_image ( struct image *image );
16
-extern int register_and_select_image ( struct image *image );
17
-extern int register_and_boot_image ( struct image *image );
18
-extern int register_and_replace_image ( struct image *image );
19 14
 extern int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
20 15
 			 int ( * action ) ( struct image *image ) );
21 16
 extern int imgdownload_string ( const char *uri_string, const char *name,

+ 1
- 1
src/usr/autoboot.c View File

@@ -158,7 +158,7 @@ int uriboot ( struct uri *filename, struct uri *root_path, int drive,
158 158
 	/* Attempt filename boot if applicable */
159 159
 	if ( filename ) {
160 160
 		if ( ( rc = imgdownload ( filename, NULL, NULL,
161
-					  register_and_boot_image ) ) != 0 ) {
161
+					  image_exec ) ) != 0 ) {
162 162
 			printf ( "\nCould not chain image: %s\n",
163 163
 				 strerror ( rc ) );
164 164
 			/* Fall through to (possibly) attempt a SAN boot

+ 24
- 110
src/usr/imgmgmt.c View File

@@ -35,109 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
  *
36 36
  */
37 37
 
38
-/**
39
- * Register an image and leave it registered
40
- *
41
- * @v image		Executable image
42
- * @ret rc		Return status code
43
- *
44
- * This function assumes an ownership of the passed image.
45
- */
46
-int register_and_put_image ( struct image *image ) {
47
-	int rc;
48
-
49
-	rc = register_image ( image );
50
-	image_put ( image );
51
-	return rc;
52
-}
53
-
54
-/**
55
- * Register and probe an image
56
- *
57
- * @v image		Executable image
58
- * @ret rc		Return status code
59
- *
60
- * This function assumes an ownership of the passed image.
61
- */
62
-int register_and_probe_image ( struct image *image ) {
63
-	int rc;
64
-
65
-	if ( ( rc = register_and_put_image ( image ) ) != 0 )
66
-		return rc;
67
-
68
-	if ( ( rc = image_probe ( image ) ) != 0 )
69
-		return rc;
70
-
71
-	return 0;
72
-}
73
-
74
-/**
75
- * Register and select an image
76
- *
77
- * @v image		Executable image
78
- * @ret rc		Return status code
79
- *
80
- * This function assumes an ownership of the passed image.
81
- */
82
-int register_and_select_image ( struct image *image ) {
83
-	int rc;
84
-
85
-	if ( ( rc = register_and_probe_image ( image ) ) != 0 )
86
-		return rc;
87
-
88
-	if ( ( rc = image_select ( image ) ) != 0 )
89
-		return rc;
90
-
91
-	return 0;
92
-}
93
-
94
-/**
95
- * Register and boot an image
96
- *
97
- * @v image		Image
98
- * @ret rc		Return status code
99
- *
100
- * This function assumes an ownership of the passed image.
101
- */
102
-int register_and_boot_image ( struct image *image ) {
103
-	int rc;
104
-
105
-	if ( ( rc = register_and_select_image ( image ) ) != 0 )
106
-		return rc;
107
-
108
-	if ( ( rc = image_exec ( image ) ) != 0 )
109
-		return rc;
110
-
111
-	return 0;
112
-}
113
-
114
-/**
115
- * Register and replace image
116
- *
117
- * @v image		Image
118
- * @ret rc		Return status code
119
- *
120
- * This function assumes an ownership of the passed image.
121
- */
122
-int register_and_replace_image ( struct image *image ) {
123
-	int rc;
124
-
125
-	if ( ( rc = register_and_probe_image ( image ) ) != 0 )
126
-		return rc;
127
-
128
-	if ( ( rc = image_replace ( image ) ) != 0 )
129
-		return rc;
130
-
131
-	return 0;
132
-}
133
-
134 38
 /**
135 39
  * Download an image
136 40
  *
137 41
  * @v uri		URI
138 42
  * @v name		Image name, or NULL to use default
139 43
  * @v cmdline		Command line, or NULL for no command line
140
- * @v action		Action to take upon a successful download
44
+ * @v action		Action to take upon a successful download, or NULL
141 45
  * @ret rc		Return status code
142 46
  */
143 47
 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,
150 54
 
151 55
 	/* Allocate image */
152 56
 	image = alloc_image();
153
-	if ( ! image )
154
-		return -ENOMEM;
57
+	if ( ! image ) {
58
+		rc = -ENOMEM;
59
+		goto err_alloc_image;
60
+	}
155 61
 
156 62
 	/* Set image name */
157 63
 	if ( name )
@@ -174,23 +80,31 @@ int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
174 80
 	/* Create downloader */
175 81
 	if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
176 82
 					uri ) ) != 0 ) {
177
-		image_put ( image );
178
-		return rc;
83
+		goto err_create_downloader;
179 84
 	}
180 85
 
181 86
 	/* Wait for download to complete */
182
-	if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 ) {
183
-		image_put ( image );
184
-		return rc;
185
-	}
87
+	if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
88
+		goto err_monojob_wait;
89
+
90
+	/* Register image */
91
+	if ( ( rc = register_image ( image ) ) != 0 )
92
+		goto err_register_image;
186 93
 
187
-	/* Act upon downloaded image.  This action assumes our
188
-	 * ownership of the image.
94
+	/* Drop local reference to image.  Image is guaranteed to
95
+	 * remain in scope since it is registered.
189 96
 	 */
190
-	if ( ( rc = action ( image ) ) != 0 )
191
-		return rc;
97
+	image_put ( image );
98
+
99
+	/* Carry out specified post-download action, if applicable */
100
+	return ( action ? action ( image ) : 0 );
192 101
 
193
-	return 0;
102
+ err_register_image:
103
+ err_monojob_wait:
104
+ err_create_downloader:
105
+	image_put ( image );
106
+ err_alloc_image:
107
+	return rc;
194 108
 }
195 109
 
196 110
 /**

Loading…
Cancel
Save