xref: /openbmc/qemu/block/export/export.c (revision 56ee86261e0ffa151e82b383d9628cf5660be355)
1*56ee8626SKevin Wolf /*
2*56ee8626SKevin Wolf  * Common block export infrastructure
3*56ee8626SKevin Wolf  *
4*56ee8626SKevin Wolf  * Copyright (c) 2012, 2020 Red Hat, Inc.
5*56ee8626SKevin Wolf  *
6*56ee8626SKevin Wolf  * Authors:
7*56ee8626SKevin Wolf  * Paolo Bonzini <pbonzini@redhat.com>
8*56ee8626SKevin Wolf  * Kevin Wolf <kwolf@redhat.com>
9*56ee8626SKevin Wolf  *
10*56ee8626SKevin Wolf  * This work is licensed under the terms of the GNU GPL, version 2 or
11*56ee8626SKevin Wolf  * later.  See the COPYING file in the top-level directory.
12*56ee8626SKevin Wolf  */
13*56ee8626SKevin Wolf 
14*56ee8626SKevin Wolf #include "qemu/osdep.h"
15*56ee8626SKevin Wolf 
16*56ee8626SKevin Wolf #include "block/export.h"
17*56ee8626SKevin Wolf #include "block/nbd.h"
18*56ee8626SKevin Wolf #include "qapi/error.h"
19*56ee8626SKevin Wolf #include "qapi/qapi-commands-block-export.h"
20*56ee8626SKevin Wolf 
21*56ee8626SKevin Wolf static const BlockExportDriver *blk_exp_drivers[] = {
22*56ee8626SKevin Wolf     &blk_exp_nbd,
23*56ee8626SKevin Wolf };
24*56ee8626SKevin Wolf 
25*56ee8626SKevin Wolf static const BlockExportDriver *blk_exp_find_driver(BlockExportType type)
26*56ee8626SKevin Wolf {
27*56ee8626SKevin Wolf     int i;
28*56ee8626SKevin Wolf 
29*56ee8626SKevin Wolf     for (i = 0; i < ARRAY_SIZE(blk_exp_drivers); i++) {
30*56ee8626SKevin Wolf         if (blk_exp_drivers[i]->type == type) {
31*56ee8626SKevin Wolf             return blk_exp_drivers[i];
32*56ee8626SKevin Wolf         }
33*56ee8626SKevin Wolf     }
34*56ee8626SKevin Wolf     return NULL;
35*56ee8626SKevin Wolf }
36*56ee8626SKevin Wolf 
37*56ee8626SKevin Wolf void qmp_block_export_add(BlockExportOptions *export, Error **errp)
38*56ee8626SKevin Wolf {
39*56ee8626SKevin Wolf     const BlockExportDriver *drv;
40*56ee8626SKevin Wolf 
41*56ee8626SKevin Wolf     drv = blk_exp_find_driver(export->type);
42*56ee8626SKevin Wolf     if (!drv) {
43*56ee8626SKevin Wolf         error_setg(errp, "No driver found for the requested export type");
44*56ee8626SKevin Wolf         return;
45*56ee8626SKevin Wolf     }
46*56ee8626SKevin Wolf 
47*56ee8626SKevin Wolf     drv->create(export, errp);
48*56ee8626SKevin Wolf }
49