Browse Source
We want to have a common set of commands for all types of block exports. Currently, this is only NBD, but we're going to add more types. This patch adds the basic BlockExport and BlockExportDriver structs and a QMP command block-export-add that creates a new export based on the given BlockExportOptions. qmp_nbd_server_add() becomes a wrapper around qmp_block_export_add(). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20200924152717.287415-5-kwolf@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>pull/99/head
9 changed files with 134 additions and 10 deletions
@ -0,0 +1,48 @@ |
|||
/*
|
|||
* Common block export infrastructure |
|||
* |
|||
* Copyright (c) 2012, 2020 Red Hat, Inc. |
|||
* |
|||
* Authors: |
|||
* Paolo Bonzini <pbonzini@redhat.com> |
|||
* Kevin Wolf <kwolf@redhat.com> |
|||
* |
|||
* This work is licensed under the terms of the GNU GPL, version 2 or |
|||
* later. See the COPYING file in the top-level directory. |
|||
*/ |
|||
|
|||
#include "qemu/osdep.h" |
|||
|
|||
#include "block/export.h" |
|||
#include "block/nbd.h" |
|||
#include "qapi/error.h" |
|||
#include "qapi/qapi-commands-block-export.h" |
|||
|
|||
static const BlockExportDriver *blk_exp_drivers[] = { |
|||
&blk_exp_nbd, |
|||
}; |
|||
|
|||
static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) |
|||
{ |
|||
int i; |
|||
|
|||
for (i = 0; i < ARRAY_SIZE(blk_exp_drivers); i++) { |
|||
if (blk_exp_drivers[i]->type == type) { |
|||
return blk_exp_drivers[i]; |
|||
} |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
void qmp_block_export_add(BlockExportOptions *export, Error **errp) |
|||
{ |
|||
const BlockExportDriver *drv; |
|||
|
|||
drv = blk_exp_find_driver(export->type); |
|||
if (!drv) { |
|||
error_setg(errp, "No driver found for the requested export type"); |
|||
return; |
|||
} |
|||
|
|||
drv->create(export, errp); |
|||
} |
|||
@ -0,0 +1 @@ |
|||
block_ss.add(files('export.c')) |
|||
@ -0,0 +1,33 @@ |
|||
/*
|
|||
* Declarations for block exports |
|||
* |
|||
* Copyright (c) 2012, 2020 Red Hat, Inc. |
|||
* |
|||
* Authors: |
|||
* Paolo Bonzini <pbonzini@redhat.com> |
|||
* Kevin Wolf <kwolf@redhat.com> |
|||
* |
|||
* This work is licensed under the terms of the GNU GPL, version 2 or |
|||
* later. See the COPYING file in the top-level directory. |
|||
*/ |
|||
|
|||
#ifndef BLOCK_EXPORT_H |
|||
#define BLOCK_EXPORT_H |
|||
|
|||
#include "qapi/qapi-types-block-export.h" |
|||
|
|||
typedef struct BlockExport BlockExport; |
|||
|
|||
typedef struct BlockExportDriver { |
|||
/* The export type that this driver services */ |
|||
BlockExportType type; |
|||
|
|||
/* Creates and starts a new block export */ |
|||
BlockExport *(*create)(BlockExportOptions *, Error **); |
|||
} BlockExportDriver; |
|||
|
|||
struct BlockExport { |
|||
const BlockExportDriver *drv; |
|||
}; |
|||
|
|||
#endif |
|||
Loading…
Reference in new issue