[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 16/19] block/nbd: Implement bdrv_dirname()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH 16/19] block/nbd: Implement bdrv_dirname() |
Date: |
Tue, 26 Apr 2016 23:32:15 +0200 |
The idea behind this implementation is that the export name might be
interpreted as a path (which is the only apparent interpretation of
relative filenames for NBD paths).
The default implementation of bdrv_dirname() would handle that just fine
for nbd+tcp, but not for nbd+unix, because in that case, the last
element of the path is the Unix socket path and not the export name.
Therefore, we need to implement an own bdrv_dirname() which uses the
legacy NBD URL which has the export name at the end.
Signed-off-by: Max Reitz <address@hidden>
---
block/nbd.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/block/nbd.c b/block/nbd.c
index f7ea3b3..64534bb 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -469,6 +469,32 @@ static void nbd_refresh_filename(BlockDriverState *bs,
QDict *options)
bs->full_open_options = opts;
}
+static char *nbd_dirname(BlockDriverState *bs, Error **errp)
+{
+ const char *path = qdict_get_try_str(bs->options, "path");
+ const char *host = qdict_get_try_str(bs->options, "host");
+ const char *port = qdict_get_try_str(bs->options, "port");
+ const char *export = qdict_get_try_str(bs->options, "export");
+
+ if (path && export) {
+ return g_strdup_printf("nbd:unix:%s:exportname=%s/", path, export);
+ } else if (path && !export) {
+ return g_strdup_printf("nbd:unix:%s:exportname=", path);
+ } else if (!path && export && port) {
+ return g_strdup_printf("nbd://%s:%s/%s/", host, port, export);
+ } else if (!path && export && !port) {
+ return g_strdup_printf("nbd://%s/%s/", host, export);
+ } else if (!path && !export && port) {
+ return g_strdup_printf("nbd://%s:%s/", host, port);
+ } else if (!path && !export && !port) {
+ return g_strdup_printf("nbd://%s/", host);
+ }
+
+ error_setg(errp, "Cannot generate a base directory for NBD node '%s'",
+ bs->filename);
+ return NULL;
+}
+
static BlockDriver bdrv_nbd = {
.format_name = "nbd",
.protocol_name = "nbd",
@@ -487,6 +513,7 @@ static BlockDriver bdrv_nbd = {
.bdrv_detach_aio_context = nbd_detach_aio_context,
.bdrv_attach_aio_context = nbd_attach_aio_context,
.bdrv_refresh_filename = nbd_refresh_filename,
+ .bdrv_dirname = nbd_dirname,
};
static BlockDriver bdrv_nbd_tcp = {
@@ -507,6 +534,7 @@ static BlockDriver bdrv_nbd_tcp = {
.bdrv_detach_aio_context = nbd_detach_aio_context,
.bdrv_attach_aio_context = nbd_attach_aio_context,
.bdrv_refresh_filename = nbd_refresh_filename,
+ .bdrv_dirname = nbd_dirname,
};
static BlockDriver bdrv_nbd_unix = {
@@ -527,6 +555,7 @@ static BlockDriver bdrv_nbd_unix = {
.bdrv_detach_aio_context = nbd_detach_aio_context,
.bdrv_attach_aio_context = nbd_attach_aio_context,
.bdrv_refresh_filename = nbd_refresh_filename,
+ .bdrv_dirname = nbd_dirname,
};
static void bdrv_nbd_init(void)
--
2.8.0
- [Qemu-block] [PATCH 11/19] block: Add bdrv_make_absolute_filename(), (continued)
- [Qemu-block] [PATCH 11/19] block: Add bdrv_make_absolute_filename(), Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 08/19] block: Make path_combine() return the path, Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 09/19] block: bdrv_get_full_backing_filename_from_...'s ret. val., Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 10/19] block: bdrv_get_full_backing_filename's ret. val., Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 12/19] block: Fix bdrv_find_backing_image(), Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 14/19] blkverify: Make bdrv_dirname() return NULL, Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 13/19] block: Add bdrv_dirname(), Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 17/19] block: Use bdrv_dirname() for relative filenames, Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 19/19] iotests: Add quorum case to test 110, Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 15/19] quorum: Make bdrv_dirname() return NULL, Max Reitz, 2016/04/26
- [Qemu-block] [PATCH 16/19] block/nbd: Implement bdrv_dirname(),
Max Reitz <=
- [Qemu-block] [PATCH 18/19] block: Add 'base-directory' BDS option, Max Reitz, 2016/04/26