184 |
184 |
return NULL;
|
185 |
185 |
}
|
186 |
186 |
|
187 |
|
int bdrv_create2(BlockDriver *drv,
|
188 |
|
const char *filename, int64_t size_in_sectors,
|
189 |
|
const char *backing_file, const char *backing_format,
|
190 |
|
int flags)
|
191 |
|
{
|
192 |
|
QEMUOptionParameter *options;
|
193 |
|
|
194 |
|
options = parse_option_parameters("", drv->create_options, NULL);
|
195 |
|
|
196 |
|
// Process flags
|
197 |
|
if (flags & ~(BLOCK_FLAG_ENCRYPT | BLOCK_FLAG_COMPAT6 | BLOCK_FLAG_COMPRESS)) {
|
198 |
|
return -ENOTSUP;
|
199 |
|
}
|
200 |
|
|
201 |
|
if (flags & BLOCK_FLAG_ENCRYPT) {
|
202 |
|
set_option_parameter_int(options, BLOCK_OPT_ENCRYPT, 1);
|
203 |
|
}
|
204 |
|
if (flags & BLOCK_FLAG_COMPAT6) {
|
205 |
|
set_option_parameter_int(options, BLOCK_OPT_COMPAT6, 1);
|
206 |
|
}
|
207 |
|
|
208 |
|
// Add size to options
|
209 |
|
set_option_parameter_int(options, BLOCK_OPT_SIZE, size_in_sectors * 512);
|
210 |
|
|
211 |
|
// Backing files
|
212 |
|
if ((backing_file != NULL && set_option_parameter(options,
|
213 |
|
BLOCK_OPT_BACKING_FILE, backing_file))
|
214 |
|
|| (backing_format != NULL && set_option_parameter(options,
|
215 |
|
BLOCK_OPT_BACKING_FMT, backing_format)))
|
216 |
|
{
|
217 |
|
return -ENOTSUP;
|
218 |
|
}
|
219 |
|
|
220 |
|
return bdrv_create(drv, filename, options);
|
221 |
|
}
|
222 |
|
|
223 |
187 |
int bdrv_create(BlockDriver *drv, const char* filename,
|
224 |
188 |
QEMUOptionParameter *options)
|
225 |
189 |
{
|
... | ... | |
392 |
356 |
BlockDriverState *bs1;
|
393 |
357 |
int64_t total_size;
|
394 |
358 |
int is_protocol = 0;
|
|
359 |
BlockDriver *bdrv_qcow2;
|
|
360 |
QEMUOptionParameter *options;
|
395 |
361 |
|
396 |
362 |
/* if snapshot, we create a temporary backing file and open it
|
397 |
363 |
instead of opening 'filename' directly */
|
... | ... | |
419 |
385 |
else
|
420 |
386 |
realpath(filename, backing_filename);
|
421 |
387 |
|
422 |
|
ret = bdrv_create2(bdrv_find_format("qcow2"), tmp_filename,
|
423 |
|
total_size, backing_filename,
|
424 |
|
(drv ? drv->format_name : NULL), 0);
|
|
388 |
bdrv_qcow2 = bdrv_find_format("qcow2");
|
|
389 |
options = parse_option_parameters("", bdrv_qcow2->create_options, NULL);
|
|
390 |
|
|
391 |
set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size * 512);
|
|
392 |
set_option_parameter(options, BLOCK_OPT_BACKING_FILE, backing_filename);
|
|
393 |
if (drv) {
|
|
394 |
set_option_parameter(options, BLOCK_OPT_BACKING_FMT,
|
|
395 |
drv->format_name);
|
|
396 |
}
|
|
397 |
|
|
398 |
ret = bdrv_create(bdrv_qcow2, tmp_filename, options);
|
425 |
399 |
if (ret < 0) {
|
426 |
400 |
return ret;
|
427 |
401 |
}
|
|
402 |
|
428 |
403 |
filename = tmp_filename;
|
429 |
|
drv = bdrv_find_format("qcow2");
|
|
404 |
drv = bdrv_qcow2;
|
430 |
405 |
bs->is_temporary = 1;
|
431 |
406 |
}
|
432 |
407 |
|