Bläddra i källkod

[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 år sedan
förälder
incheckning
790035f78d

+ 2
- 2
src/arch/i386/interface/syslinux/comboot_call.c Visa fil

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

+ 6
- 2
src/core/image.c Visa fil

224
 	/* Sanity check */
224
 	/* Sanity check */
225
 	assert ( image->flags & IMAGE_REGISTERED );
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
 		return rc;
229
 		return rc;
230
 
230
 
231
 	/* Switch current working directory to be that of the image itself */
231
 	/* Switch current working directory to be that of the image itself */
302
 		return rc;
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
 	/* Clear any existing replacement */
309
 	/* Clear any existing replacement */
306
 	image_put ( image->replacement );
310
 	image_put ( image->replacement );
307
 
311
 

+ 3
- 6
src/hci/commands/image_cmd.c Visa fil

114
  */
114
  */
115
 static int imgfetch_exec ( int argc, char **argv ) {
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
  */
126
  */
128
 static int kernel_exec ( int argc, char **argv ) {
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
  */
138
  */
141
 static int chain_exec ( int argc, char **argv) {
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
 /** "imgselect" options */
144
 /** "imgselect" options */

+ 0
- 5
src/include/usr/imgmgmt.h Visa fil

11
 
11
 
12
 #include <ipxe/image.h>
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
 extern int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
14
 extern int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
20
 			 int ( * action ) ( struct image *image ) );
15
 			 int ( * action ) ( struct image *image ) );
21
 extern int imgdownload_string ( const char *uri_string, const char *name,
16
 extern int imgdownload_string ( const char *uri_string, const char *name,

+ 1
- 1
src/usr/autoboot.c Visa fil

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

+ 24
- 110
src/usr/imgmgmt.c Visa fil

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
  * Download an image
39
  * Download an image
136
  *
40
  *
137
  * @v uri		URI
41
  * @v uri		URI
138
  * @v name		Image name, or NULL to use default
42
  * @v name		Image name, or NULL to use default
139
  * @v cmdline		Command line, or NULL for no command line
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
  * @ret rc		Return status code
45
  * @ret rc		Return status code
142
  */
46
  */
143
 int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
47
 int imgdownload ( struct uri *uri, const char *name, const char *cmdline,
150
 
54
 
151
 	/* Allocate image */
55
 	/* Allocate image */
152
 	image = alloc_image();
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
 	/* Set image name */
62
 	/* Set image name */
157
 	if ( name )
63
 	if ( name )
174
 	/* Create downloader */
80
 	/* Create downloader */
175
 	if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
81
 	if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
176
 					uri ) ) != 0 ) {
82
 					uri ) ) != 0 ) {
177
-		image_put ( image );
178
-		return rc;
83
+		goto err_create_downloader;
179
 	}
84
 	}
180
 
85
 
181
 	/* Wait for download to complete */
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
 /**

Laddar…
Avbryt
Spara