]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/include/spdk/nbd.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / include / spdk / nbd.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /** \file
35 * Network block device layer
36 */
37
38 #ifndef SPDK_NBD_H_
39 #define SPDK_NBD_H_
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 struct spdk_bdev;
46 struct spdk_nbd_disk;
47 struct spdk_json_write_ctx;
48
49 /**
50 * Initialize the network block device layer.
51 *
52 * \return 0 on success.
53 */
54 int spdk_nbd_init(void);
55
56 /**
57 * Stop and close all the running network block devices.
58 */
59 void spdk_nbd_fini(void);
60
61 /**
62 * Called when an NBD device has been started.
63 * On success, rc is assigned 0; On failure, rc is assigned negated errno.
64 */
65 typedef void (*spdk_nbd_start_cb)(void *cb_arg, struct spdk_nbd_disk *nbd,
66 int rc);
67
68 /**
69 * Start a network block device backed by the bdev.
70 *
71 * \param bdev_name Name of bdev exposed as a network block device.
72 * \param nbd_path Path to the registered network block device.
73 * \param cb_fn Callback to be always called.
74 * \param cb_arg Passed to cb_fn.
75 */
76 void spdk_nbd_start(const char *bdev_name, const char *nbd_path,
77 spdk_nbd_start_cb cb_fn, void *cb_arg);
78
79 /**
80 * Stop the running network block device safely.
81 *
82 * \param nbd A pointer to the network block device to stop.
83 */
84 void spdk_nbd_stop(struct spdk_nbd_disk *nbd);
85
86 /**
87 * Get the local filesystem path used for the network block device.
88 */
89 const char *spdk_nbd_get_path(struct spdk_nbd_disk *nbd);
90
91 /**
92 * Write NBD subsystem configuration into provided JSON context.
93 *
94 * \param w JSON write context
95 */
96 void spdk_nbd_write_config_json(struct spdk_json_write_ctx *w);
97
98 #ifdef __cplusplus
99 }
100 #endif
101
102 #endif