xref: /spdk/lib/vhost/vhost_internal.h (revision ef5c1379bef5579b248edb9da8e93fcb631bbe9f)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef SPDK_VHOST_INTERNAL_H
7 #define SPDK_VHOST_INTERNAL_H
8 #include <linux/virtio_config.h>
9 
10 #include "spdk/stdinc.h"
11 
12 #include <rte_vhost.h>
13 
14 #include "spdk_internal/vhost_user.h"
15 #include "spdk/bdev.h"
16 #include "spdk/log.h"
17 #include "spdk/util.h"
18 #include "spdk/rpc.h"
19 #include "spdk/config.h"
20 
21 #define SPDK_VHOST_MAX_VQUEUES	256
22 #define SPDK_VHOST_MAX_VQ_SIZE	1024
23 
24 #define SPDK_VHOST_SCSI_CTRLR_MAX_DEVS 8
25 
26 #define SPDK_VHOST_IOVS_MAX 129
27 
28 #define SPDK_VHOST_VQ_MAX_SUBMISSIONS	32
29 
30 /*
31  * Rate at which stats are checked for interrupt coalescing.
32  */
33 #define SPDK_VHOST_STATS_CHECK_INTERVAL_MS 10
34 /*
35  * Default threshold at which interrupts start to be coalesced.
36  */
37 #define SPDK_VHOST_VQ_IOPS_COALESCING_THRESHOLD 60000
38 
39 /*
40  * Timeout in seconds for vhost-user session stop message.
41  */
42 #define SPDK_VHOST_SESSION_STOP_TIMEOUT_IN_SEC 3
43 /*
44  * Stop retry timeout in seconds, this value should be greater than SPDK_VHOST_SESSION_STOP_TIMEOUT_IN_SEC.
45  */
46 #define SPDK_VHOST_SESSION_STOP_RETRY_TIMEOUT_IN_SEC (SPDK_VHOST_SESSION_STOP_TIMEOUT_IN_SEC + 1)
47 /*
48  * Stop retry period in microseconds
49  */
50 #define SPDK_VHOST_SESSION_STOP_RETRY_PERIOD_IN_US 1000
51 
52 /*
53  * Currently coalescing is not used by default.
54  * Setting this to value > 0 here or by RPC will enable coalescing.
55  */
56 #define SPDK_VHOST_COALESCING_DELAY_BASE_US 0
57 
58 #define SPDK_VHOST_FEATURES ((1ULL << VHOST_F_LOG_ALL) | \
59 	(1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
60 	(1ULL << VIRTIO_F_VERSION_1) | \
61 	(1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \
62 	(1ULL << VIRTIO_RING_F_EVENT_IDX) | \
63 	(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
64 	(1ULL << VIRTIO_F_ANY_LAYOUT))
65 
66 #define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \
67 	(1ULL << VIRTIO_F_NOTIFY_ON_EMPTY))
68 
69 #define VRING_DESC_F_AVAIL	(1ULL << VRING_PACKED_DESC_F_AVAIL)
70 #define VRING_DESC_F_USED	(1ULL << VRING_PACKED_DESC_F_USED)
71 #define VRING_DESC_F_AVAIL_USED	(VRING_DESC_F_AVAIL | VRING_DESC_F_USED)
72 
73 typedef struct rte_vhost_resubmit_desc spdk_vhost_resubmit_desc;
74 typedef struct rte_vhost_resubmit_info spdk_vhost_resubmit_info;
75 typedef struct rte_vhost_inflight_desc_packed	spdk_vhost_inflight_desc;
76 
77 struct spdk_vhost_virtqueue {
78 	struct rte_vhost_vring vring;
79 	struct rte_vhost_ring_inflight vring_inflight;
80 	uint16_t last_avail_idx;
81 	uint16_t last_used_idx;
82 
83 	struct {
84 		/* To mark a descriptor as available in packed ring
85 		 * Equal to avail_wrap_counter in spec.
86 		 */
87 		uint8_t avail_phase	: 1;
88 		/* To mark a descriptor as used in packed ring
89 		 * Equal to used_wrap_counter in spec.
90 		 */
91 		uint8_t used_phase	: 1;
92 		uint8_t padding		: 5;
93 		bool packed_ring	: 1;
94 	} packed;
95 
96 	void *tasks;
97 
98 	/* Request count from last stats check */
99 	uint32_t req_cnt;
100 
101 	/* Request count from last event */
102 	uint16_t used_req_cnt;
103 
104 	/* How long interrupt is delayed */
105 	uint32_t irq_delay_time;
106 
107 	/* Next time when we need to send event */
108 	uint64_t next_event_time;
109 
110 	/* Associated vhost_virtqueue in the virtio device's virtqueue list */
111 	uint32_t vring_idx;
112 
113 	struct spdk_vhost_session *vsession;
114 
115 	struct spdk_interrupt *intr;
116 } __attribute((aligned(SPDK_CACHE_LINE_SIZE)));
117 
118 struct spdk_vhost_session {
119 	struct spdk_vhost_dev *vdev;
120 
121 	/* rte_vhost connection ID. */
122 	int vid;
123 
124 	/* Unique session ID. */
125 	uint64_t id;
126 	/* Unique session name. */
127 	char *name;
128 
129 	bool started;
130 	bool starting;
131 	bool needs_restart;
132 
133 	struct rte_vhost_memory *mem;
134 
135 	int task_cnt;
136 
137 	uint16_t max_queues;
138 	/* Maximum number of queues before restart, used with 'needs_restart' flag */
139 	uint16_t original_max_queues;
140 
141 	uint64_t negotiated_features;
142 
143 	/* Local copy of device coalescing settings. */
144 	uint32_t coalescing_delay_time_base;
145 	uint32_t coalescing_io_rate_threshold;
146 
147 	/* Next time when stats for event coalescing will be checked. */
148 	uint64_t next_stats_check_time;
149 
150 	/* Interval used for event coalescing checking. */
151 	uint64_t stats_check_interval;
152 
153 	/* Session's stop poller will only try limited times to destroy the session. */
154 	uint32_t stop_retry_count;
155 
156 	/**
157 	 * DPDK calls our callbacks synchronously but the work those callbacks
158 	 * perform needs to be async. Luckily, all DPDK callbacks are called on
159 	 * a DPDK-internal pthread and only related to the current session, so we'll
160 	 * just wait on a semaphore of this session in there.
161 	 */
162 	sem_t dpdk_sem;
163 
164 	/** Return code for the current DPDK callback */
165 	int dpdk_response;
166 
167 	struct spdk_vhost_virtqueue virtqueue[SPDK_VHOST_MAX_VQUEUES];
168 
169 	TAILQ_ENTRY(spdk_vhost_session) tailq;
170 };
171 
172 struct spdk_vhost_user_dev {
173 	struct spdk_vhost_dev *vdev;
174 
175 	const struct spdk_vhost_user_dev_backend *user_backend;
176 
177 	/* Saved original values used to setup coalescing to avoid integer
178 	 * rounding issues during save/load config.
179 	 */
180 	uint32_t coalescing_delay_us;
181 	uint32_t coalescing_iops_threshold;
182 
183 	bool registered;
184 
185 	/* Use this lock to protect multiple sessions. */
186 	pthread_mutex_t lock;
187 
188 	/* Current connections to the device */
189 	TAILQ_HEAD(, spdk_vhost_session) vsessions;
190 
191 	/* Increment-only session counter */
192 	uint64_t vsessions_num;
193 
194 	/* Number of pending asynchronous operations */
195 	uint32_t pending_async_op_num;
196 };
197 
198 struct spdk_vhost_dev {
199 	char *name;
200 	char *path;
201 
202 	struct spdk_thread *thread;
203 
204 	uint64_t virtio_features;
205 	uint64_t disabled_features;
206 	uint64_t protocol_features;
207 
208 	const struct spdk_vhost_dev_backend *backend;
209 
210 	/* Context passed from transport */
211 	void *ctxt;
212 
213 	TAILQ_ENTRY(spdk_vhost_dev) tailq;
214 };
215 
216 static inline struct spdk_vhost_user_dev *
217 to_user_dev(struct spdk_vhost_dev *vdev)
218 {
219 	assert(vdev != NULL);
220 	return vdev->ctxt;
221 }
222 
223 /**
224  * \param vdev vhost device.
225  * \param vsession vhost session.
226  * \param arg user-provided parameter.
227  *
228  * \return negative values will break the foreach call, meaning
229  * the function won't be called again. Return codes zero and
230  * positive don't have any effect.
231  */
232 typedef int (*spdk_vhost_session_fn)(struct spdk_vhost_dev *vdev,
233 				     struct spdk_vhost_session *vsession,
234 				     void *arg);
235 
236 /**
237  * \param vdev vhost device.
238  * \param arg user-provided parameter.
239  */
240 typedef void (*spdk_vhost_dev_fn)(struct spdk_vhost_dev *vdev, void *arg);
241 
242 struct spdk_vhost_user_dev_backend {
243 	/**
244 	 * Size of additional per-session context data
245 	 * allocated whenever a new client connects.
246 	 */
247 	size_t session_ctx_size;
248 
249 	spdk_vhost_session_fn start_session;
250 	spdk_vhost_session_fn stop_session;
251 	int (*alloc_vq_tasks)(struct spdk_vhost_session *vsession, uint16_t qid);
252 	int (*enable_vq)(struct spdk_vhost_session *vsession, struct spdk_vhost_virtqueue *vq);
253 };
254 
255 enum vhost_backend_type {
256 	VHOST_BACKEND_BLK = 0,
257 	VHOST_BACKEND_SCSI,
258 };
259 
260 struct spdk_vhost_dev_backend {
261 	enum vhost_backend_type type;
262 
263 	int (*vhost_get_config)(struct spdk_vhost_dev *vdev, uint8_t *config, uint32_t len);
264 	int (*vhost_set_config)(struct spdk_vhost_dev *vdev, uint8_t *config,
265 				uint32_t offset, uint32_t size, uint32_t flags);
266 
267 	void (*dump_info_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
268 	void (*write_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
269 	int (*remove_device)(struct spdk_vhost_dev *vdev);
270 	int (*set_coalescing)(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
271 			      uint32_t iops_threshold);
272 	void (*get_coalescing)(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
273 			       uint32_t *iops_threshold);
274 };
275 
276 void *vhost_gpa_to_vva(struct spdk_vhost_session *vsession, uint64_t addr, uint64_t len);
277 
278 uint16_t vhost_vq_avail_ring_get(struct spdk_vhost_virtqueue *vq, uint16_t *reqs,
279 				 uint16_t reqs_len);
280 
281 /**
282  * Get a virtio split descriptor at given index in given virtqueue.
283  * The descriptor will provide access to the entire descriptor
284  * chain. The subsequent descriptors are accessible via
285  * \c spdk_vhost_vring_desc_get_next.
286  * \param vsession vhost session
287  * \param vq virtqueue
288  * \param req_idx descriptor index
289  * \param desc pointer to be set to the descriptor
290  * \param desc_table descriptor table to be used with
291  * \c spdk_vhost_vring_desc_get_next. This might be either
292  * default virtqueue descriptor table or per-chain indirect
293  * table.
294  * \param desc_table_size size of the *desc_table*
295  * \return 0 on success, -1 if given index is invalid.
296  * If -1 is returned, the content of params is undefined.
297  */
298 int vhost_vq_get_desc(struct spdk_vhost_session *vsession, struct spdk_vhost_virtqueue *vq,
299 		      uint16_t req_idx, struct vring_desc **desc, struct vring_desc **desc_table,
300 		      uint32_t *desc_table_size);
301 
302 /**
303  * Get a virtio packed descriptor at given index in given virtqueue.
304  * The descriptor will provide access to the entire descriptor
305  * chain. The subsequent descriptors are accessible via
306  * \c vhost_vring_packed_desc_get_next.
307  * \param vsession vhost session
308  * \param vq virtqueue
309  * \param req_idx descriptor index
310  * \param desc pointer to be set to the descriptor
311  * \param desc_table descriptor table to be used with
312  * \c spdk_vhost_vring_desc_get_next. This might be either
313  * \c NULL or per-chain indirect table.
314  * \param desc_table_size size of the *desc_table*
315  * \return 0 on success, -1 if given index is invalid.
316  * If -1 is returned, the content of params is undefined.
317  */
318 int vhost_vq_get_desc_packed(struct spdk_vhost_session *vsession,
319 			     struct spdk_vhost_virtqueue *virtqueue,
320 			     uint16_t req_idx, struct vring_packed_desc **desc,
321 			     struct vring_packed_desc **desc_table, uint32_t *desc_table_size);
322 
323 int vhost_inflight_queue_get_desc(struct spdk_vhost_session *vsession,
324 				  spdk_vhost_inflight_desc *desc_array,
325 				  uint16_t req_idx, spdk_vhost_inflight_desc **desc,
326 				  struct vring_packed_desc  **desc_table, uint32_t *desc_table_size);
327 
328 /**
329  * Send IRQ/call client (if pending) for \c vq.
330  * \param vsession vhost session
331  * \param vq virtqueue
332  * \return
333  *   0 - if no interrupt was signalled
334  *   1 - if interrupt was signalled
335  */
336 int vhost_vq_used_signal(struct spdk_vhost_session *vsession, struct spdk_vhost_virtqueue *vq);
337 
338 /**
339  * Send IRQs for the queue that need to be signaled.
340  * \param vq virtqueue
341  */
342 void vhost_session_vq_used_signal(struct spdk_vhost_virtqueue *virtqueue);
343 
344 void vhost_vq_used_ring_enqueue(struct spdk_vhost_session *vsession,
345 				struct spdk_vhost_virtqueue *vq,
346 				uint16_t id, uint32_t len);
347 
348 /**
349  * Enqueue the entry to the used ring when device complete the request.
350  * \param vsession vhost session
351  * \param vq virtqueue
352  * \req_idx descriptor index. It's the first index of this descriptor chain.
353  * \num_descs descriptor count. It's the count of the number of buffers in the chain.
354  * \buffer_id descriptor buffer ID.
355  * \length device write length. Specify the length of the buffer that has been initialized
356  * (written to) by the device
357  * \inflight_head the head idx of this IO inflight desc chain.
358  */
359 void vhost_vq_packed_ring_enqueue(struct spdk_vhost_session *vsession,
360 				  struct spdk_vhost_virtqueue *virtqueue,
361 				  uint16_t num_descs, uint16_t buffer_id,
362 				  uint32_t length, uint16_t inflight_head);
363 
364 /**
365  * Get subsequent descriptor from given table.
366  * \param desc current descriptor, will be set to the
367  * next descriptor (NULL in case this is the last
368  * descriptor in the chain or the next desc is invalid)
369  * \param desc_table descriptor table
370  * \param desc_table_size size of the *desc_table*
371  * \return 0 on success, -1 if given index is invalid
372  * The *desc* param will be set regardless of the
373  * return value.
374  */
375 int vhost_vring_desc_get_next(struct vring_desc **desc,
376 			      struct vring_desc *desc_table, uint32_t desc_table_size);
377 static inline bool
378 vhost_vring_desc_is_wr(struct vring_desc *cur_desc)
379 {
380 	return !!(cur_desc->flags & VRING_DESC_F_WRITE);
381 }
382 
383 int vhost_vring_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec *iov,
384 			    uint16_t *iov_index, const struct vring_desc *desc);
385 
386 bool vhost_vq_packed_ring_is_avail(struct spdk_vhost_virtqueue *virtqueue);
387 
388 /**
389  * Get subsequent descriptor from vq or desc table.
390  * \param desc current descriptor, will be set to the
391  * next descriptor (NULL in case this is the last
392  * descriptor in the chain or the next desc is invalid)
393  * \req_idx index of current desc, will be set to the next
394  * index. If desc_table != NULL the req_idx is the the vring index
395  * or the req_idx is the desc_table index.
396  * \param desc_table descriptor table
397  * \param desc_table_size size of the *desc_table*
398  * \return 0 on success, -1 if given index is invalid
399  * The *desc* param will be set regardless of the
400  * return value.
401  */
402 int vhost_vring_packed_desc_get_next(struct vring_packed_desc **desc, uint16_t *req_idx,
403 				     struct spdk_vhost_virtqueue *vq,
404 				     struct vring_packed_desc *desc_table,
405 				     uint32_t desc_table_size);
406 
407 bool vhost_vring_packed_desc_is_wr(struct vring_packed_desc *cur_desc);
408 
409 int vhost_vring_packed_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec *iov,
410 				   uint16_t *iov_index, const struct vring_packed_desc *desc);
411 
412 bool vhost_vring_inflight_desc_is_wr(spdk_vhost_inflight_desc *cur_desc);
413 
414 int vhost_vring_inflight_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec *iov,
415 				     uint16_t *iov_index, const spdk_vhost_inflight_desc *desc);
416 
417 uint16_t vhost_vring_packed_desc_get_buffer_id(struct spdk_vhost_virtqueue *vq, uint16_t req_idx,
418 		uint16_t *num_descs);
419 
420 static inline bool
421 __attribute__((always_inline))
422 vhost_dev_has_feature(struct spdk_vhost_session *vsession, unsigned feature_id)
423 {
424 	return vsession->negotiated_features & (1ULL << feature_id);
425 }
426 
427 int vhost_scsi_controller_start(const char *name);
428 
429 int vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
430 		       const struct spdk_json_val *params, const struct spdk_vhost_dev_backend *backend,
431 		       const struct spdk_vhost_user_dev_backend *user_backend, bool delay);
432 
433 int vhost_dev_unregister(struct spdk_vhost_dev *vdev);
434 
435 void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
436 
437 /*
438  * Set vhost session to run in interrupt or poll mode
439  */
440 void vhost_user_session_set_interrupt_mode(struct spdk_vhost_session *vsession,
441 		bool interrupt_mode);
442 
443 /*
444  * Memory registration functions used in start/stop device callbacks
445  */
446 void vhost_session_mem_register(struct rte_vhost_memory *mem);
447 void vhost_session_mem_unregister(struct rte_vhost_memory *mem);
448 
449 /*
450  * Call a function for each session of the provided vhost device.
451  * The function will be called one-by-one on each session's thread.
452  *
453  * \param vdev vhost device
454  * \param fn function to call on each session's thread
455  * \param cpl_fn function to be called at the end of the iteration on
456  * the vhost management thread.
457  * Optional, can be NULL.
458  * \param arg additional argument to the both callbacks
459  */
460 void vhost_user_dev_foreach_session(struct spdk_vhost_dev *dev,
461 				    spdk_vhost_session_fn fn,
462 				    spdk_vhost_dev_fn cpl_fn,
463 				    void *arg);
464 
465 /**
466  * Finish a blocking vhost_user_wait_for_session_stop() call and finally
467  * stop the session. This must be called on the session's lcore which
468  * used to receive all session-related messages (e.g. from
469  * vhost_user_dev_foreach_session()). After this call, the session-
470  * related messages will be once again processed by any arbitrary thread.
471  *
472  * Must be called under the vhost user device's session access lock.
473  *
474  * \param vsession vhost session
475  * \param response return code
476  */
477 void vhost_user_session_stop_done(struct spdk_vhost_session *vsession, int response);
478 
479 struct spdk_vhost_session *vhost_session_find_by_vid(int vid);
480 void vhost_session_install_rte_compat_hooks(struct spdk_vhost_session *vsession);
481 int vhost_register_unix_socket(const char *path, const char *ctrl_name,
482 			       uint64_t virtio_features, uint64_t disabled_features, uint64_t protocol_features);
483 int vhost_driver_unregister(const char *path);
484 int vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
485 int vhost_get_negotiated_features(int vid, uint64_t *negotiated_features);
486 
487 int remove_vhost_controller(struct spdk_vhost_dev *vdev);
488 
489 struct spdk_io_channel *vhost_blk_get_io_channel(struct spdk_vhost_dev *vdev);
490 void vhost_blk_put_io_channel(struct spdk_io_channel *ch);
491 
492 /* The spdk_bdev pointer should only be used to retrieve
493  * the device properties, ex. number of blocks or I/O type supported. */
494 struct spdk_bdev *vhost_blk_get_bdev(struct spdk_vhost_dev *vdev);
495 
496 /* Function calls from vhost.c to rte_vhost_user.c,
497  * shall removed once virtio transport abstraction is complete. */
498 int vhost_user_session_set_coalescing(struct spdk_vhost_dev *dev,
499 				      struct spdk_vhost_session *vsession, void *ctx);
500 int vhost_user_dev_set_coalescing(struct spdk_vhost_user_dev *user_dev, uint32_t delay_base_us,
501 				  uint32_t iops_threshold);
502 int vhost_user_dev_create(struct spdk_vhost_dev *vdev, const char *name,
503 			  struct spdk_cpuset *cpumask,
504 			  const struct spdk_vhost_user_dev_backend *user_backend, bool dealy);
505 int vhost_user_dev_init(struct spdk_vhost_dev *vdev, const char *name,
506 			struct spdk_cpuset *cpumask, const struct spdk_vhost_user_dev_backend *user_backend);
507 int vhost_user_dev_start(struct spdk_vhost_dev *vdev);
508 int vhost_user_dev_unregister(struct spdk_vhost_dev *vdev);
509 int vhost_user_init(void);
510 void vhost_user_fini(spdk_vhost_fini_cb vhost_cb);
511 int vhost_user_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
512 			      uint32_t iops_threshold);
513 void vhost_user_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
514 			       uint32_t *iops_threshold);
515 
516 int virtio_blk_construct_ctrlr(struct spdk_vhost_dev *vdev, const char *address,
517 			       struct spdk_cpuset *cpumask, const struct spdk_json_val *params,
518 			       const struct spdk_vhost_user_dev_backend *user_backend);
519 int virtio_blk_destroy_ctrlr(struct spdk_vhost_dev *vdev);
520 
521 struct spdk_vhost_blk_task;
522 
523 typedef void (*virtio_blk_request_cb)(uint8_t status, struct spdk_vhost_blk_task *task,
524 				      void *cb_arg);
525 
526 struct spdk_vhost_blk_task {
527 	struct spdk_bdev_io *bdev_io;
528 	virtio_blk_request_cb cb;
529 	void *cb_arg;
530 
531 	volatile uint8_t *status;
532 
533 	/* for io wait */
534 	struct spdk_bdev_io_wait_entry bdev_io_wait;
535 	struct spdk_io_channel *bdev_io_wait_ch;
536 	struct spdk_vhost_dev *bdev_io_wait_vdev;
537 
538 	/** Number of bytes that were written. */
539 	uint32_t used_len;
540 	uint16_t iovcnt;
541 	struct iovec iovs[SPDK_VHOST_IOVS_MAX];
542 
543 	/** Size of whole payload in bytes */
544 	uint32_t payload_size;
545 };
546 
547 int virtio_blk_process_request(struct spdk_vhost_dev *vdev, struct spdk_io_channel *ch,
548 			       struct spdk_vhost_blk_task *task, virtio_blk_request_cb cb, void *cb_arg);
549 
550 typedef void (*bdev_event_cb_complete)(struct spdk_vhost_dev *vdev, void *ctx);
551 
552 #define SPDK_VIRTIO_BLK_TRSTRING_MAX_LEN 32
553 
554 struct spdk_virtio_blk_transport_ops {
555 	/**
556 	 * Transport name
557 	 */
558 	char name[SPDK_VIRTIO_BLK_TRSTRING_MAX_LEN];
559 
560 	/**
561 	 * Create a transport for the given transport opts
562 	 */
563 	struct spdk_virtio_blk_transport *(*create)(const struct spdk_json_val *params);
564 
565 	/**
566 	 * Dump transport-specific opts into JSON
567 	 */
568 	void (*dump_opts)(struct spdk_virtio_blk_transport *transport, struct spdk_json_write_ctx *w);
569 
570 	/**
571 	 * Destroy the transport
572 	 */
573 	int (*destroy)(struct spdk_virtio_blk_transport *transport,
574 		       spdk_vhost_fini_cb cb_fn);
575 
576 	/**
577 	 * Create vhost block controller
578 	 */
579 	int (*create_ctrlr)(struct spdk_vhost_dev *vdev, struct spdk_cpuset *cpumask,
580 			    const char *address, const struct spdk_json_val *params,
581 			    void *custom_opts);
582 
583 	/**
584 	 * Destroy vhost block controller
585 	 */
586 	int (*destroy_ctrlr)(struct spdk_vhost_dev *vdev);
587 
588 	/*
589 	 * Signal removal of the bdev.
590 	 */
591 	void (*bdev_event)(enum spdk_bdev_event_type type, struct spdk_vhost_dev *vdev,
592 			   bdev_event_cb_complete cb, void *cb_arg);
593 
594 	/**
595 	 * Set coalescing parameters.
596 	 */
597 	int (*set_coalescing)(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
598 			      uint32_t iops_threshold);
599 
600 	/**
601 	 * Get coalescing parameters.
602 	 */
603 	void (*get_coalescing)(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
604 			       uint32_t *iops_threshold);
605 };
606 
607 struct spdk_virtio_blk_transport {
608 	const struct spdk_virtio_blk_transport_ops	*ops;
609 	TAILQ_ENTRY(spdk_virtio_blk_transport)		tailq;
610 };
611 
612 struct virtio_blk_transport_ops_list_element {
613 	struct spdk_virtio_blk_transport_ops			ops;
614 	TAILQ_ENTRY(virtio_blk_transport_ops_list_element)	link;
615 };
616 
617 void virtio_blk_transport_register(const struct spdk_virtio_blk_transport_ops *ops);
618 int virtio_blk_transport_create(const char *transport_name, const struct spdk_json_val *params);
619 int virtio_blk_transport_destroy(struct spdk_virtio_blk_transport *transport,
620 				 spdk_vhost_fini_cb cb_fn);
621 struct spdk_virtio_blk_transport *virtio_blk_transport_get_first(void);
622 struct spdk_virtio_blk_transport *virtio_blk_transport_get_next(
623 	struct spdk_virtio_blk_transport *transport);
624 void virtio_blk_transport_dump_opts(struct spdk_virtio_blk_transport *transport,
625 				    struct spdk_json_write_ctx *w);
626 struct spdk_virtio_blk_transport *virtio_blk_tgt_get_transport(const char *transport_name);
627 const struct spdk_virtio_blk_transport_ops *virtio_blk_get_transport_ops(
628 	const char *transport_name);
629 
630 void vhost_session_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
631 
632 /*
633  * Macro used to register new transports.
634  */
635 #define SPDK_VIRTIO_BLK_TRANSPORT_REGISTER(name, transport_ops) \
636 static void __attribute__((constructor)) _virtio_blk_transport_register_##name(void) \
637 { \
638 	virtio_blk_transport_register(transport_ops); \
639 }
640 
641 #endif /* SPDK_VHOST_INTERNAL_H */
642