xref: /spdk/include/spdk_internal/fuse_dispatcher.h (revision 43c35d804cc3f84a164f54a32eb57fc61a9856b2)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  */
4 
5 /** \file
6  * Operations on a FUSE fsdev dispatcher
7  */
8 
9 #ifndef SPDK_FUSE_DISPATCHER_H
10 #define SPDK_FUSE_DISPATCHER_H
11 
12 #include "spdk/stdinc.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 struct spdk_fuse_dispatcher;
19 
20 enum spdk_fuse_arch {
21 	SPDK_FUSE_ARCH_NATIVE,
22 	SPDK_FUSE_ARCH_X86,
23 	SPDK_FUSE_ARCH_X86_64,
24 	SPDK_FUSE_ARCH_ARM,
25 	SPDK_FUSE_ARCH_ARM64,
26 	_SPDK_FUSE_ARCH_LAST,
27 };
28 
29 /**
30  * FUSE fsdev dispatcher create completion callback.
31  *
32  * \param cb_arg Callback argument specified upon create operation.
33  * \param disp FUSE fsdev dispatcher object. NULL if creation failed.
34  */
35 typedef void (*spdk_fuse_dispatcher_create_cpl_cb)(void *cb_arg, struct spdk_fuse_dispatcher *disp);
36 
37 /**
38  * FUSE fsdev dispatcher submit completion callback.
39  *
40  * \param cb_arg Callback argument specified upon submit operation.
41  * \param error 0 if the operation succeeded, a negative error code otherwise.
42  */
43 typedef void (*spdk_fuse_dispatcher_submit_cpl_cb)(void *cb_arg, int error);
44 
45 /**
46  * FUSE fsdev dispatcher delete completion callback.
47  *
48  * \param cb_arg Callback argument specified upon delete operation.
49  * \param error 0 if the operation succeeded, a negative error code otherwise.
50  */
51 typedef void (*spdk_fuse_dispatcher_delete_cpl_cb)(void *cb_arg, int error);
52 
53 
54 /** Asynchronous event type */
55 enum spdk_fuse_dispatcher_event_type {
56 	SPDK_FUSE_DISP_EVENT_FSDEV_REMOVE,
57 };
58 
59 /**
60  * FUSE fsdev dispatcher event callback.
61  *
62  * \param type Event type.
63  * \param disp FUSE fsdev dispatcher object.
64  * \param event_ctx Context for the filesystem device event.
65  */
66 typedef void (*spdk_fuse_dispatcher_event_cb)(enum spdk_fuse_dispatcher_event_type type,
67 		struct spdk_fuse_dispatcher *disp, void *event_ctx);
68 
69 /**
70  * Create a FUSE fsdev dispatcher
71  *
72  * \param fsdev_name Name of the fsdev to work with.
73  * \param event_cb Dispatcher event callback.
74  * \param event_ctx Dispatcher event callback's context.
75  * \param cb Completion callback.
76  * \param cb_arg Context to be passed to the completion callback.
77  *
78  * \return 0 on success, a negative error code otherwise.
79  * On success, the callback will always be called (even if the request ultimately failed).
80  */
81 int spdk_fuse_dispatcher_create(const char *fsdev_name, spdk_fuse_dispatcher_event_cb event_cb,
82 				void *event_ctx, spdk_fuse_dispatcher_create_cpl_cb cb, void *cb_arg);
83 
84 /**
85  * Set a FUSE request source's HW architecture.
86  *
87  * Unless this function is called explicitly, the arch set to SPDK_FUSE_ARCH_NATIVE.
88  *
89  * \param disp FUSE fsdev dispatcher object.
90  * \param fuse_arch FUSE request source's HW architecture
91  *
92  * \return 0 on success or -EINVAL if the architecture is not supported
93  */
94 int spdk_fuse_dispatcher_set_arch(struct spdk_fuse_dispatcher *disp, enum spdk_fuse_arch fuse_arch);
95 
96 /**
97  * Get underlying fsdev name
98  *
99  * \param disp FUSE fsdev dispatcher object.
100  *
101  * \return fsdev name
102  */
103 const char *spdk_fuse_dispatcher_get_fsdev_name(struct spdk_fuse_dispatcher *disp);
104 
105 /**
106  * Obtain an I/O channel for the FUSE fsdev dispatcher object. I/O channels are
107  * bound to threads, so the resulting I/O channel may only be used from the thread
108  * it was originally obtained from.
109  *
110  * \param disp FUSE fsdev dispatcher object.
111  *
112  * \return A handle to the I/O channel or NULL on failure.
113  */
114 struct spdk_io_channel *spdk_fuse_dispatcher_get_io_channel(struct spdk_fuse_dispatcher *disp);
115 
116 /**
117  * Submit FUSE request
118  *
119  * \param disp FUSE fsdev dispatcher object.
120  * \param ch I/O channel obtained from the \p spdk_fuse_dispatcher_get_io_channel.
121  * \param in_iov Input IO vectors array.
122  * \param in_iovcnt Size of the input IO vectors array.
123  * \param out_iov Output IO vectors array.
124  * \param out_iovcnt Size of the output IO vectors array.
125  * \param cb Completion callback.
126  * \param cb_arg Context to be passed to the completion callback.
127  *
128  * \return 0 on success. On success, the callback will always
129  * be called (even if the request ultimately failed). Return
130  * negated errno on failure, in which case the callback will not be called.
131  *  -ENOBUFS - the request cannot be submitted due to a lack of the internal IO objects
132  *  -EINVAL - the request cannot be submitted as some FUSE request data is incorrect
133  */
134 int spdk_fuse_dispatcher_submit_request(struct spdk_fuse_dispatcher *disp,
135 					struct spdk_io_channel *ch,
136 					struct iovec *in_iov, int in_iovcnt,
137 					struct iovec *out_iov, int out_iovcnt,
138 					spdk_fuse_dispatcher_submit_cpl_cb cb, void *cb_arg);
139 
140 /**
141  * Delete a FUSE fsdev dispatcher
142  *
143  * \param disp FUSE fsdev dispatcher object.
144  * \param cb Completion callback.
145  * \param cb_arg Context to be passed to the completion callback.
146  *
147  * \return 0 on success, a negative error code otherwise.
148  * On success, the callback will always be called (even if the request ultimately failed).
149  */
150 int spdk_fuse_dispatcher_delete(struct spdk_fuse_dispatcher *disp,
151 				spdk_fuse_dispatcher_delete_cpl_cb cb, void *cb_arg);
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #endif /* SPDK_FUSE_DISPATCHER_H */
158