Revision 2ce40099 src/rm/RequestManagerSaveDisk.cc
src/rm/RequestManagerSaveDisk.cc | ||
---|---|---|
39 | 39 |
int rc; |
40 | 40 |
int uid; |
41 | 41 |
string estr; |
42 |
char * error_str; |
|
42 |
char * error_char; |
|
43 |
string error_str; |
|
43 | 44 |
|
44 | 45 |
const string method_name = "VirtualMachineSaveDisk"; |
45 | 46 |
|
... | ... | |
48 | 49 |
ImageTemplate * img_template; |
49 | 50 |
User * user; |
50 | 51 |
|
52 |
Image * source_img; |
|
53 |
int source_img_id; |
|
54 |
bool source_img_persistent = false; |
|
55 |
|
|
51 | 56 |
vector<xmlrpc_c::value> arrayData; |
52 | 57 |
xmlrpc_c::value_array * arrayresult; |
53 | 58 |
|
... | ... | |
92 | 97 |
|
93 | 98 |
if ( image != 0 ) |
94 | 99 |
{ |
95 |
goto error_image_get;
|
|
100 |
goto error_image_exists;
|
|
96 | 101 |
} |
97 | 102 |
|
98 | 103 |
oss << "NAME= " << img_name << endl; |
... | ... | |
101 | 106 |
|
102 | 107 |
img_template = new ImageTemplate; |
103 | 108 |
|
104 |
img_template->parse(oss.str(),&error_str);
|
|
109 |
img_template->parse(oss.str(),&error_char);
|
|
105 | 110 |
|
106 | 111 |
oss.str(""); |
107 | 112 |
|
... | ... | |
158 | 163 |
oss.str(""); |
159 | 164 |
|
160 | 165 |
//-------------------------------------------------------------------------- |
161 |
// Store image id to save the disk in the VM template
|
|
166 |
// Get the VM
|
|
162 | 167 |
//-------------------------------------------------------------------------- |
163 | 168 |
vm = VirtualMachineSaveDisk::vmpool->get(vm_id,true); |
164 | 169 |
|
... | ... | |
167 | 172 |
goto error_vm_get; |
168 | 173 |
} |
169 | 174 |
|
170 |
rc = vm->save_disk(disk_id, iid); |
|
175 |
//-------------------------------------------------------------------------- |
|
176 |
// Check if the disk has a persistent source image |
|
177 |
//-------------------------------------------------------------------------- |
|
178 |
oss << "/VM/TEMPLATE/DISK[DISK_ID=" << disk_id << "]/IMAGE_ID"; |
|
179 |
rc = vm->xpath(source_img_id, oss.str().c_str(), -1); |
|
180 |
oss.str(""); |
|
181 |
|
|
182 |
if( rc == 0 ) // The disk was created from an Image |
|
183 |
{ |
|
184 |
source_img = VirtualMachineSaveDisk::ipool->get(source_img_id, true); |
|
185 |
|
|
186 |
if( source_img != 0 ) // The Image still exists |
|
187 |
{ |
|
188 |
source_img_persistent = source_img->isPersistent(); |
|
189 |
source_img->unlock(); |
|
190 |
|
|
191 |
if( source_img_persistent ) |
|
192 |
{ |
|
193 |
vm->unlock(); |
|
194 |
goto error_img_persistent; |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
//-------------------------------------------------------------------------- |
|
200 |
// Store image id to save the disk in the VM template |
|
201 |
//-------------------------------------------------------------------------- |
|
202 |
|
|
203 |
rc = vm->save_disk(disk_id, iid, error_str); |
|
171 | 204 |
|
172 | 205 |
if ( rc == -1 ) |
173 | 206 |
{ |
... | ... | |
193 | 226 |
|
194 | 227 |
return; |
195 | 228 |
|
196 |
error_image_get:
|
|
229 |
error_image_exists:
|
|
197 | 230 |
oss << action_error(method_name, "CREATE", "IMAGE", -2, 0); |
198 |
oss << ". Image " << img_name << " already exists in the repository.";
|
|
231 |
oss << " Image " << img_name << " already exists in the repository."; |
|
199 | 232 |
goto error_common; |
200 | 233 |
|
201 | 234 |
error_vm_get: |
202 | 235 |
oss.str(get_error(method_name, "VM", vm_id)); |
203 | 236 |
goto error_common; |
204 | 237 |
|
238 |
error_img_persistent: |
|
239 |
oss << action_error(method_name, "SAVEDISK", "DISK", disk_id, 0); |
|
240 |
oss << " Source IMAGE " << source_img_id << " is persistent."; |
|
241 |
|
|
242 |
goto error_common; |
|
243 |
|
|
205 | 244 |
error_vm_get_disk_id: |
206 | 245 |
oss.str(get_error(method_name, "DISK from VM", vm_id)); |
207 |
oss << ". Deleting Image " << img_name; |
|
246 |
oss << " " << error_str; |
|
247 |
oss << " Deleting Image " << img_name; |
|
208 | 248 |
imagem->delete_image(iid); |
209 | 249 |
goto error_common; |
210 | 250 |
|
Also available in: Unified diff