2020-09-24 18:26:50 +03:00
|
|
|
/*
|
|
|
|
* 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"
|
2020-09-24 18:27:03 +03:00
|
|
|
#include "qemu/queue.h"
|
2020-09-24 18:26:50 +03:00
|
|
|
|
|
|
|
typedef struct BlockExport BlockExport;
|
|
|
|
|
|
|
|
typedef struct BlockExportDriver {
|
|
|
|
/* The export type that this driver services */
|
|
|
|
BlockExportType type;
|
|
|
|
|
2020-09-24 18:27:02 +03:00
|
|
|
/*
|
|
|
|
* The size of the driver-specific state that contains BlockExport as its
|
|
|
|
* first field.
|
|
|
|
*/
|
|
|
|
size_t instance_size;
|
|
|
|
|
2020-09-24 18:26:50 +03:00
|
|
|
/* Creates and starts a new block export */
|
2020-09-24 18:27:02 +03:00
|
|
|
int (*create)(BlockExport *, BlockExportOptions *, Error **);
|
2020-09-24 18:26:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees a removed block export. This function is only called after all
|
|
|
|
* references have been dropped.
|
|
|
|
*/
|
|
|
|
void (*delete)(BlockExport *);
|
2020-09-24 18:27:03 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start to disconnect all clients and drop other references held
|
|
|
|
* internally by the export driver. When the function returns, there may
|
|
|
|
* still be active references while the export is in the process of
|
|
|
|
* shutting down.
|
|
|
|
*/
|
|
|
|
void (*request_shutdown)(BlockExport *);
|
2020-09-24 18:26:50 +03:00
|
|
|
} BlockExportDriver;
|
|
|
|
|
|
|
|
struct BlockExport {
|
|
|
|
const BlockExportDriver *drv;
|
2020-09-24 18:26:59 +03:00
|
|
|
|
2020-09-24 18:27:04 +03:00
|
|
|
/* Unique identifier for the export */
|
|
|
|
char *id;
|
|
|
|
|
2020-09-24 18:26:59 +03:00
|
|
|
/*
|
|
|
|
* Reference count for this block export. This includes strong references
|
|
|
|
* both from the owner (qemu-nbd or the monitor) and clients connected to
|
|
|
|
* the export.
|
2023-05-16 22:02:32 +03:00
|
|
|
*
|
|
|
|
* Use atomics to access this field.
|
2020-09-24 18:26:59 +03:00
|
|
|
*/
|
|
|
|
int refcount;
|
2020-09-24 18:27:00 +03:00
|
|
|
|
2020-09-24 18:27:05 +03:00
|
|
|
/*
|
|
|
|
* True if one of the references in refcount belongs to the user. After the
|
|
|
|
* user has dropped their reference, they may not e.g. remove the same
|
|
|
|
* export a second time (which would decrease the refcount without having
|
|
|
|
* it incremented first).
|
|
|
|
*/
|
|
|
|
bool user_owned;
|
|
|
|
|
2020-09-24 18:27:00 +03:00
|
|
|
/* The AioContext whose lock protects this BlockExport object. */
|
|
|
|
AioContext *ctx;
|
2020-09-24 18:27:03 +03:00
|
|
|
|
2020-09-24 18:27:08 +03:00
|
|
|
/* The block device to export */
|
|
|
|
BlockBackend *blk;
|
|
|
|
|
2020-09-24 18:27:03 +03:00
|
|
|
/* List entry for block_exports */
|
|
|
|
QLIST_ENTRY(BlockExport) next;
|
2020-09-24 18:26:50 +03:00
|
|
|
};
|
|
|
|
|
2020-09-24 18:26:53 +03:00
|
|
|
BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp);
|
2020-09-24 18:27:06 +03:00
|
|
|
BlockExport *blk_exp_find(const char *id);
|
2020-09-24 18:26:59 +03:00
|
|
|
void blk_exp_ref(BlockExport *exp);
|
|
|
|
void blk_exp_unref(BlockExport *exp);
|
2020-09-24 18:27:03 +03:00
|
|
|
void blk_exp_request_shutdown(BlockExport *exp);
|
|
|
|
void blk_exp_close_all(void);
|
|
|
|
void blk_exp_close_all_type(BlockExportType type);
|
2020-09-24 18:26:53 +03:00
|
|
|
|
2020-09-24 18:26:50 +03:00
|
|
|
#endif
|