xref: /spdk/include/spdk/nbd.h (revision a6dbe3721eb3b5990707fc3e378c95e505dd8ab5)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 /** \file
7  * Network block device layer
8  */
9 
10 #ifndef SPDK_NBD_H_
11 #define SPDK_NBD_H_
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 struct spdk_bdev;
18 struct spdk_nbd_disk;
19 struct spdk_json_write_ctx;
20 typedef void (*spdk_nbd_fini_cb)(void *arg);
21 
22 /**
23  * Initialize the network block device layer.
24  *
25  * \return 0 on success.
26  */
27 int spdk_nbd_init(void);
28 
29 /**
30  * Stop and close all the running network block devices.
31  *
32  * \param cb_fn Callback to be always called.
33  * \param cb_arg Passed to cb_fn.
34  */
35 void spdk_nbd_fini(spdk_nbd_fini_cb cb_fn, void *cb_arg);
36 
37 /**
38  * Called when an NBD device has been started.
39  * On success, rc is assigned 0; On failure, rc is assigned negated errno.
40  */
41 typedef void (*spdk_nbd_start_cb)(void *cb_arg, struct spdk_nbd_disk *nbd,
42 				  int rc);
43 
44 /**
45  * Start a network block device backed by the bdev.
46  *
47  * \param bdev_name Name of bdev exposed as a network block device.
48  * \param nbd_path Path to the registered network block device.
49  * \param cb_fn Callback to be always called.
50  * \param cb_arg Passed to cb_fn.
51  */
52 void spdk_nbd_start(const char *bdev_name, const char *nbd_path,
53 		    spdk_nbd_start_cb cb_fn, void *cb_arg);
54 
55 /**
56  * Stop the running network block device safely.
57  *
58  * \param nbd A pointer to the network block device to stop.
59  *
60  * \return 0 on success.
61  */
62 int spdk_nbd_stop(struct spdk_nbd_disk *nbd);
63 
64 /**
65  * Get the local filesystem path used for the network block device.
66  */
67 const char *spdk_nbd_get_path(struct spdk_nbd_disk *nbd);
68 
69 /**
70  * Write NBD subsystem configuration into provided JSON context.
71  *
72  * \param w JSON write context
73  */
74 void spdk_nbd_write_config_json(struct spdk_json_write_ctx *w);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
81