|
@@ -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
|
/**
|