2017-07-14 22:20:19 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2018-03-30 06:15:13 +00:00
|
|
|
/** \file
|
|
|
|
* Network block device layer
|
|
|
|
*/
|
|
|
|
|
2017-07-14 22:20:19 +00:00
|
|
|
#ifndef SPDK_NBD_H_
|
|
|
|
#define SPDK_NBD_H_
|
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-07-14 22:20:19 +00:00
|
|
|
struct spdk_bdev;
|
2017-08-02 17:40:38 +00:00
|
|
|
struct spdk_nbd_disk;
|
2018-04-19 15:48:48 +00:00
|
|
|
struct spdk_json_write_ctx;
|
2017-07-14 22:20:19 +00:00
|
|
|
|
2018-03-30 06:15:13 +00:00
|
|
|
/**
|
|
|
|
* Initialize the network block device layer.
|
|
|
|
*
|
|
|
|
* \return 0 on success.
|
|
|
|
*/
|
2017-12-02 10:15:34 +00:00
|
|
|
int spdk_nbd_init(void);
|
|
|
|
|
2018-03-30 06:15:13 +00:00
|
|
|
/**
|
|
|
|
* Stop and close all the running network block devices.
|
|
|
|
*/
|
2017-12-02 10:15:34 +00:00
|
|
|
void spdk_nbd_fini(void);
|
|
|
|
|
2018-11-19 20:44:03 +00:00
|
|
|
/**
|
|
|
|
* Called when an NBD device has been started.
|
2019-02-18 13:16:11 +00:00
|
|
|
* On success, rc is assigned 0; On failure, rc is assigned negated errno.
|
2018-11-19 20:44:03 +00:00
|
|
|
*/
|
|
|
|
typedef void (*spdk_nbd_start_cb)(void *cb_arg, struct spdk_nbd_disk *nbd,
|
|
|
|
int rc);
|
|
|
|
|
2018-03-30 06:15:13 +00:00
|
|
|
/**
|
|
|
|
* Start a network block device backed by the bdev.
|
|
|
|
*
|
|
|
|
* \param bdev_name Name of bdev exposed as a network block device.
|
|
|
|
* \param nbd_path Path to the registered network block device.
|
2019-02-18 13:16:11 +00:00
|
|
|
* \param cb_fn Callback to be always called.
|
2018-11-19 20:44:03 +00:00
|
|
|
* \param cb_arg Passed to cb_fn.
|
2018-03-30 06:15:13 +00:00
|
|
|
*/
|
2018-11-19 20:44:03 +00:00
|
|
|
void spdk_nbd_start(const char *bdev_name, const char *nbd_path,
|
|
|
|
spdk_nbd_start_cb cb_fn, void *cb_arg);
|
2017-08-02 21:37:53 +00:00
|
|
|
|
2018-03-30 06:15:13 +00:00
|
|
|
/**
|
|
|
|
* Stop the running network block device safely.
|
|
|
|
*
|
|
|
|
* \param nbd A pointer to the network block device to stop.
|
|
|
|
*/
|
2017-08-02 17:40:38 +00:00
|
|
|
void spdk_nbd_stop(struct spdk_nbd_disk *nbd);
|
2017-07-14 22:20:19 +00:00
|
|
|
|
2018-11-19 20:14:56 +00:00
|
|
|
/**
|
|
|
|
* Get the local filesystem path used for the network block device.
|
|
|
|
*/
|
|
|
|
const char *spdk_nbd_get_path(struct spdk_nbd_disk *nbd);
|
|
|
|
|
2018-04-19 15:48:48 +00:00
|
|
|
/**
|
|
|
|
* Write NBD subsystem configuration into provided JSON context.
|
|
|
|
*
|
|
|
|
* \param w JSON write context
|
|
|
|
*/
|
2018-08-31 20:39:11 +00:00
|
|
|
void spdk_nbd_write_config_json(struct spdk_json_write_ctx *w);
|
2018-04-19 15:48:48 +00:00
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-14 22:20:19 +00:00
|
|
|
#endif
|