block.c (b92902dfeaafbceaf744ab7473f2d070284f6172) block.c (5a5e7f8cd86b7ced0732b1b6e28c82baa65b09c9)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 584 unchanged lines hidden (view full) ---

593 "Failed to clear the new image's first sector");
594 return ret;
595 }
596 }
597
598 return 0;
599}
600
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 584 unchanged lines hidden (view full) ---

593 "Failed to clear the new image's first sector");
594 return ret;
595 }
596 }
597
598 return 0;
599}
600
601static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
602 QemuOpts *opts, Error **errp)
601/**
602 * Simple implementation of bdrv_co_create_opts for protocol drivers
603 * which only support creation via opening a file
604 * (usually existing raw storage device)
605 */
606int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,
607 const char *filename,
608 QemuOpts *opts,
609 Error **errp)
603{
604 BlockBackend *blk;
605 QDict *options;
606 int64_t size = 0;
607 char *buf = NULL;
608 PreallocMode prealloc;
609 Error *local_err = NULL;
610 int ret;

--- 47 unchanged lines hidden (view full) ---

658{
659 BlockDriver *drv;
660
661 drv = bdrv_find_protocol(filename, true, errp);
662 if (drv == NULL) {
663 return -ENOENT;
664 }
665
610{
611 BlockBackend *blk;
612 QDict *options;
613 int64_t size = 0;
614 char *buf = NULL;
615 PreallocMode prealloc;
616 Error *local_err = NULL;
617 int ret;

--- 47 unchanged lines hidden (view full) ---

665{
666 BlockDriver *drv;
667
668 drv = bdrv_find_protocol(filename, true, errp);
669 if (drv == NULL) {
670 return -ENOENT;
671 }
672
666 if (drv->bdrv_co_create_opts) {
667 return bdrv_create(drv, filename, opts, errp);
668 } else {
669 return bdrv_create_file_fallback(filename, drv, opts, errp);
670 }
673 return bdrv_create(drv, filename, opts, errp);
671}
672
673int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
674{
675 Error *local_err = NULL;
676 int ret;
677
678 assert(bs != NULL);

--- 908 unchanged lines hidden (view full) ---

1587 .name = BDRV_OPT_FORCE_SHARE,
1588 .type = QEMU_OPT_BOOL,
1589 .help = "always accept other writers (default: off)",
1590 },
1591 { /* end of list */ }
1592 },
1593};
1594
674}
675
676int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
677{
678 Error *local_err = NULL;
679 int ret;
680
681 assert(bs != NULL);

--- 908 unchanged lines hidden (view full) ---

1590 .name = BDRV_OPT_FORCE_SHARE,
1591 .type = QEMU_OPT_BOOL,
1592 .help = "always accept other writers (default: off)",
1593 },
1594 { /* end of list */ }
1595 },
1596};
1597
1595static QemuOptsList fallback_create_opts = {
1596 .name = "fallback-create-opts",
1597 .head = QTAILQ_HEAD_INITIALIZER(fallback_create_opts.head),
1598QemuOptsList bdrv_create_opts_simple = {
1599 .name = "simple-create-opts",
1600 .head = QTAILQ_HEAD_INITIALIZER(bdrv_create_opts_simple.head),
1598 .desc = {
1599 {
1600 .name = BLOCK_OPT_SIZE,
1601 .type = QEMU_OPT_SIZE,
1602 .help = "Virtual disk size"
1603 },
1604 {
1605 .name = BLOCK_OPT_PREALLOC,

--- 4352 unchanged lines hidden (view full) ---

5958 }
5959
5960 if (!drv->create_opts) {
5961 error_setg(errp, "Format driver '%s' does not support image creation",
5962 drv->format_name);
5963 return;
5964 }
5965
1601 .desc = {
1602 {
1603 .name = BLOCK_OPT_SIZE,
1604 .type = QEMU_OPT_SIZE,
1605 .help = "Virtual disk size"
1606 },
1607 {
1608 .name = BLOCK_OPT_PREALLOC,

--- 4352 unchanged lines hidden (view full) ---

5961 }
5962
5963 if (!drv->create_opts) {
5964 error_setg(errp, "Format driver '%s' does not support image creation",
5965 drv->format_name);
5966 return;
5967 }
5968
5969 if (!proto_drv->create_opts) {
5970 error_setg(errp, "Protocol driver '%s' does not support image creation",
5971 proto_drv->format_name);
5972 return;
5973 }
5974
5966 /* Create parameter list */
5967 create_opts = qemu_opts_append(create_opts, drv->create_opts);
5975 /* Create parameter list */
5976 create_opts = qemu_opts_append(create_opts, drv->create_opts);
5968 if (proto_drv->create_opts) {
5969 create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
5970 } else {
5971 create_opts = qemu_opts_append(create_opts, &fallback_create_opts);
5972 }
5977 create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
5973
5974 opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
5975
5976 /* Parse -o options */
5977 if (options) {
5978 qemu_opts_do_parse(opts, options, NULL, &local_err);
5979 if (local_err) {
5980 goto out;

--- 807 unchanged lines hidden ---
5978
5979 opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
5980
5981 /* Parse -o options */
5982 if (options) {
5983 qemu_opts_do_parse(opts, options, NULL, &local_err);
5984 if (local_err) {
5985 goto out;

--- 807 unchanged lines hidden ---