qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] block: introduce BlockDriver.bdrv_needs_filename to


From: Benoît Canet
Subject: [Qemu-devel] [PATCH] block: introduce BlockDriver.bdrv_needs_filename to enable some drivers.
Date: Fri, 20 Sep 2013 22:24:28 +0200

Some drivers will have driver specifics options but no filename.
This new bool allow the block layer to treat them correctly.

The first driver of this type will be the quorum driver.

Signed-off-by: Benoit Canet <address@hidden>
---
 block.c                   | 6 ++++--
 block/bochs.c             | 1 +
 block/cloop.c             | 1 +
 block/cow.c               | 1 +
 block/dmg.c               | 1 +
 block/gluster.c           | 4 ++++
 block/iscsi.c             | 1 +
 block/parallels.c         | 1 +
 block/qcow.c              | 1 +
 block/qcow2.c             | 1 +
 block/qed.c               | 1 +
 block/raw-posix.c         | 5 +++++
 block/raw-win32.c         | 2 ++
 block/raw_bsd.c           | 1 +
 block/rbd.c               | 1 +
 block/sheepdog.c          | 3 +++
 block/vdi.c               | 1 +
 block/vhdx.c              | 1 +
 block/vmdk.c              | 1 +
 block/vpc.c               | 1 +
 include/block/block_int.h | 1 +
 21 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 827549c..88099a1 100644
--- a/block.c
+++ b/block.c
@@ -760,7 +760,8 @@ static int bdrv_open_common(BlockDriverState *bs, 
BlockDriverState *file,
     /* Open the image, either directly or using a protocol */
     if (drv->bdrv_file_open) {
         assert(file == NULL);
-        assert(drv->bdrv_parse_filename || filename != NULL);
+        assert(drv->bdrv_parse_filename || !drv->bdrv_needs_filename ||
+               filename != NULL);
         ret = drv->bdrv_file_open(bs, options, open_flags);
     } else {
         if (file == NULL) {
@@ -870,7 +871,8 @@ int bdrv_file_open(BlockDriverState **pbs, const char 
*filename,
             goto fail;
         }
         qdict_del(options, "filename");
-    } else if (!drv->bdrv_parse_filename && !filename) {
+    } else if (!drv->bdrv_parse_filename && drv->bdrv_needs_filename &&
+               !filename) {
         qerror_report(ERROR_CLASS_GENERIC_ERROR,
                       "The '%s' block driver requires a file name",
                       drv->format_name);
diff --git a/block/bochs.c b/block/bochs.c
index d7078c0..72a73aa 100644
--- a/block/bochs.c
+++ b/block/bochs.c
@@ -237,6 +237,7 @@ static void bochs_close(BlockDriverState *bs)
 static BlockDriver bdrv_bochs = {
     .format_name       = "bochs",
     .instance_size     = sizeof(BDRVBochsState),
+    .bdrv_needs_filename = true,
     .bdrv_probe                = bochs_probe,
     .bdrv_open         = bochs_open,
     .bdrv_read          = bochs_co_read,
diff --git a/block/cloop.c b/block/cloop.c
index 6ea7cf4..1e615ab 100644
--- a/block/cloop.c
+++ b/block/cloop.c
@@ -190,6 +190,7 @@ static void cloop_close(BlockDriverState *bs)
 static BlockDriver bdrv_cloop = {
     .format_name    = "cloop",
     .instance_size  = sizeof(BDRVCloopState),
+    .bdrv_needs_filename = true,
     .bdrv_probe     = cloop_probe,
     .bdrv_open      = cloop_open,
     .bdrv_read      = cloop_co_read,
diff --git a/block/cow.c b/block/cow.c
index 764b93f..c38a242 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -379,6 +379,7 @@ static BlockDriver bdrv_cow = {
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,
     .bdrv_create    = cow_create,
+    .bdrv_needs_filename = true,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
diff --git a/block/dmg.c b/block/dmg.c
index 3141cb5..770350f 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -377,6 +377,7 @@ static void dmg_close(BlockDriverState *bs)
 static BlockDriver bdrv_dmg = {
     .format_name       = "dmg",
     .instance_size     = sizeof(BDRVDMGState),
+    .bdrv_needs_filename = true,
     .bdrv_probe                = dmg_probe,
     .bdrv_open         = dmg_open,
     .bdrv_read          = dmg_co_read,
diff --git a/block/gluster.c b/block/gluster.c
index dbb03f4..c124400 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -611,6 +611,7 @@ static BlockDriver bdrv_gluster = {
     .format_name                  = "gluster",
     .protocol_name                = "gluster",
     .instance_size                = sizeof(BDRVGlusterState),
+    .bdrv_needs_filename          = true,
     .bdrv_file_open               = qemu_gluster_open,
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
@@ -631,6 +632,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .format_name                  = "gluster",
     .protocol_name                = "gluster+tcp",
     .instance_size                = sizeof(BDRVGlusterState),
+    .bdrv_needs_filename          = true,
     .bdrv_file_open               = qemu_gluster_open,
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
@@ -651,6 +653,7 @@ static BlockDriver bdrv_gluster_unix = {
     .format_name                  = "gluster",
     .protocol_name                = "gluster+unix",
     .instance_size                = sizeof(BDRVGlusterState),
+    .bdrv_needs_filename          = true,
     .bdrv_file_open               = qemu_gluster_open,
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
@@ -671,6 +674,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .format_name                  = "gluster",
     .protocol_name                = "gluster+rdma",
     .instance_size                = sizeof(BDRVGlusterState),
+    .bdrv_needs_filename          = true,
     .bdrv_file_open               = qemu_gluster_open,
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
diff --git a/block/iscsi.c b/block/iscsi.c
index 813abd8..cbe0c84 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1304,6 +1304,7 @@ static BlockDriver bdrv_iscsi = {
     .protocol_name   = "iscsi",
 
     .instance_size   = sizeof(IscsiLun),
+    .bdrv_needs_filename = true,
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
     .bdrv_create     = iscsi_create,
diff --git a/block/parallels.c b/block/parallels.c
index 18b3ac0..c3853d7 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -163,6 +163,7 @@ static void parallels_close(BlockDriverState *bs)
 static BlockDriver bdrv_parallels = {
     .format_name       = "parallels",
     .instance_size     = sizeof(BDRVParallelsState),
+    .bdrv_needs_filename = true,
     .bdrv_probe                = parallels_probe,
     .bdrv_open         = parallels_open,
     .bdrv_read          = parallels_co_read,
diff --git a/block/qcow.c b/block/qcow.c
index 93a993b..d1a576c 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -894,6 +894,7 @@ static QEMUOptionParameter qcow_create_options[] = {
 static BlockDriver bdrv_qcow = {
     .format_name       = "qcow",
     .instance_size     = sizeof(BDRVQcowState),
+    .bdrv_needs_filename = true,
     .bdrv_probe                = qcow_probe,
     .bdrv_open         = qcow_open,
     .bdrv_close                = qcow_close,
diff --git a/block/qcow2.c b/block/qcow2.c
index 578792f..3e2754b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1872,6 +1872,7 @@ static QEMUOptionParameter qcow2_create_options[] = {
 static BlockDriver bdrv_qcow2 = {
     .format_name        = "qcow2",
     .instance_size      = sizeof(BDRVQcowState),
+    .bdrv_needs_filename = true,
     .bdrv_probe         = qcow2_probe,
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
diff --git a/block/qed.c b/block/qed.c
index 49b3a37..b25d538 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1587,6 +1587,7 @@ static QEMUOptionParameter qed_create_options[] = {
 static BlockDriver bdrv_qed = {
     .format_name              = "qed",
     .instance_size            = sizeof(BDRVQEDState),
+    .bdrv_needs_filename      = true,
     .create_options           = qed_create_options,
 
     .bdrv_probe               = bdrv_qed_probe,
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 1b41ea3..7ac6b97 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1198,6 +1198,7 @@ static BlockDriver bdrv_file = {
     .format_name = "file",
     .protocol_name = "file",
     .instance_size = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_probe = NULL, /* no probe for protocols */
     .bdrv_file_open = raw_open,
     .bdrv_reopen_prepare = raw_reopen_prepare,
@@ -1538,6 +1539,7 @@ static BlockDriver bdrv_host_device = {
     .format_name        = "host_device",
     .protocol_name        = "host_device",
     .instance_size      = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_probe_device  = hdev_probe_device,
     .bdrv_file_open     = hdev_open,
     .bdrv_close         = raw_close,
@@ -1662,6 +1664,7 @@ static BlockDriver bdrv_host_floppy = {
     .format_name        = "host_floppy",
     .protocol_name      = "host_floppy",
     .instance_size      = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_probe_device = floppy_probe_device,
     .bdrv_file_open     = floppy_open,
     .bdrv_close         = raw_close,
@@ -1763,6 +1766,7 @@ static BlockDriver bdrv_host_cdrom = {
     .format_name        = "host_cdrom",
     .protocol_name      = "host_cdrom",
     .instance_size      = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_probe_device = cdrom_probe_device,
     .bdrv_file_open     = cdrom_open,
     .bdrv_close         = raw_close,
@@ -1884,6 +1888,7 @@ static BlockDriver bdrv_host_cdrom = {
     .format_name        = "host_cdrom",
     .protocol_name      = "host_cdrom",
     .instance_size      = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_probe_device = cdrom_probe_device,
     .bdrv_file_open     = cdrom_open,
     .bdrv_close         = raw_close,
diff --git a/block/raw-win32.c b/block/raw-win32.c
index d2d2d9f..ac38cf9 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -456,6 +456,7 @@ static BlockDriver bdrv_file = {
     .format_name       = "file",
     .protocol_name     = "file",
     .instance_size     = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_file_open    = raw_open,
     .bdrv_close                = raw_close,
     .bdrv_create       = raw_create,
@@ -597,6 +598,7 @@ static BlockDriver bdrv_host_device = {
     .format_name       = "host_device",
     .protocol_name     = "host_device",
     .instance_size     = sizeof(BDRVRawState),
+    .bdrv_needs_filename = true,
     .bdrv_probe_device = hdev_probe_device,
     .bdrv_file_open    = hdev_open,
     .bdrv_close                = raw_close,
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index a9060ca..0ca30ec 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -155,6 +155,7 @@ static int raw_probe(const uint8_t *buf, int buf_size, 
const char *filename)
 
 static BlockDriver bdrv_raw = {
     .format_name          = "raw",
+    .bdrv_needs_filename  = true,
     .bdrv_probe           = &raw_probe,
     .bdrv_reopen_prepare  = &raw_reopen_prepare,
     .bdrv_open            = &raw_open,
diff --git a/block/rbd.c b/block/rbd.c
index e798e19..7c42744 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -981,6 +981,7 @@ static QEMUOptionParameter qemu_rbd_create_options[] = {
 static BlockDriver bdrv_rbd = {
     .format_name        = "rbd",
     .instance_size      = sizeof(BDRVRBDState),
+    .bdrv_needs_filename = true,
     .bdrv_file_open     = qemu_rbd_open,
     .bdrv_close         = qemu_rbd_close,
     .bdrv_create        = qemu_rbd_create,
diff --git a/block/sheepdog.c b/block/sheepdog.c
index f9988d3..26b0f23 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2327,6 +2327,7 @@ static BlockDriver bdrv_sheepdog = {
     .format_name    = "sheepdog",
     .protocol_name  = "sheepdog",
     .instance_size  = sizeof(BDRVSheepdogState),
+    .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
     .bdrv_create    = sd_create,
@@ -2355,6 +2356,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .format_name    = "sheepdog",
     .protocol_name  = "sheepdog+tcp",
     .instance_size  = sizeof(BDRVSheepdogState),
+    .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
     .bdrv_create    = sd_create,
@@ -2383,6 +2385,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .format_name    = "sheepdog",
     .protocol_name  = "sheepdog+unix",
     .instance_size  = sizeof(BDRVSheepdogState),
+    .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
     .bdrv_create    = sd_create,
diff --git a/block/vdi.c b/block/vdi.c
index 1bf7dc5..d044821 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -785,6 +785,7 @@ static QEMUOptionParameter vdi_create_options[] = {
 static BlockDriver bdrv_vdi = {
     .format_name = "vdi",
     .instance_size = sizeof(BDRVVdiState),
+    .bdrv_needs_filename = true,
     .bdrv_probe = vdi_probe,
     .bdrv_open = vdi_open,
     .bdrv_close = vdi_close,
diff --git a/block/vhdx.c b/block/vhdx.c
index e9704b1..951c79f 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -956,6 +956,7 @@ static void vhdx_close(BlockDriverState *bs)
 static BlockDriver bdrv_vhdx = {
     .format_name            = "vhdx",
     .instance_size          = sizeof(BDRVVHDXState),
+    .bdrv_needs_filename    = true,
     .bdrv_probe             = vhdx_probe,
     .bdrv_open              = vhdx_open,
     .bdrv_close             = vhdx_close,
diff --git a/block/vmdk.c b/block/vmdk.c
index fb5b529..b6427e7 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1845,6 +1845,7 @@ static QEMUOptionParameter vmdk_create_options[] = {
 static BlockDriver bdrv_vmdk = {
     .format_name                  = "vmdk",
     .instance_size                = sizeof(BDRVVmdkState),
+    .bdrv_needs_filename          = true,
     .bdrv_probe                   = vmdk_probe,
     .bdrv_open                    = vmdk_open,
     .bdrv_reopen_prepare          = vmdk_reopen_prepare,
diff --git a/block/vpc.c b/block/vpc.c
index fe4f311..0e9aba0 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -830,6 +830,7 @@ static BlockDriver bdrv_vpc = {
     .format_name    = "vpc",
     .instance_size  = sizeof(BDRVVPCState),
 
+    .bdrv_needs_filename    = true,
     .bdrv_probe             = vpc_probe,
     .bdrv_open              = vpc_open,
     .bdrv_close             = vpc_close,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 7c35198..b62f950 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -73,6 +73,7 @@ struct BlockDriver {
     /* Any driver implementing this callback is expected to be able to handle
      * NULL file names in its .bdrv_open() implementation */
     void (*bdrv_parse_filename)(const char *filename, QDict *options, Error 
**errp);
+    bool bdrv_needs_filename;
 
     /* For handling image reopen for split or non-split files */
     int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,
-- 
1.8.1.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]