xref: /spdk/module/event/subsystems/iobuf/iobuf.c (revision c6c1234de9e0015e670dd0b51bf6ce39ee0e07bd)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2022 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "spdk/stdinc.h"
7 #include "spdk/bdev.h"
8 #include "spdk/log.h"
9 #include "spdk/thread.h"
10 #include "spdk_internal/init.h"
11 
12 static void
13 iobuf_subsystem_initialize(void)
14 {
15 	int rc;
16 
17 	rc = spdk_iobuf_initialize();
18 	if (rc != 0) {
19 		SPDK_ERRLOG("Failed to initialize iobuf\n");
20 	}
21 
22 	spdk_subsystem_init_next(rc);
23 }
24 
25 static void
26 iobuf_finish_cb(void *ctx)
27 {
28 	spdk_subsystem_fini_next();
29 }
30 
31 static void
32 iobuf_subsystem_finish(void)
33 {
34 	spdk_iobuf_finish(iobuf_finish_cb, NULL);
35 }
36 
37 static void
38 iobuf_write_config_json(struct spdk_json_write_ctx *w)
39 {
40 	struct spdk_iobuf_opts opts;
41 
42 	spdk_iobuf_get_opts(&opts, sizeof(opts));
43 
44 	spdk_json_write_array_begin(w);
45 
46 	spdk_json_write_object_begin(w);
47 	spdk_json_write_named_string(w, "method", "iobuf_set_options");
48 
49 	spdk_json_write_named_object_begin(w, "params");
50 	spdk_json_write_named_uint64(w, "small_pool_count", opts.small_pool_count);
51 	spdk_json_write_named_uint64(w, "large_pool_count", opts.large_pool_count);
52 	spdk_json_write_named_uint32(w, "small_bufsize", opts.small_bufsize);
53 	spdk_json_write_named_uint32(w, "large_bufsize", opts.large_bufsize);
54 	spdk_json_write_object_end(w);
55 	spdk_json_write_object_end(w);
56 
57 	spdk_json_write_array_end(w);
58 }
59 
60 static struct spdk_subsystem g_subsystem_iobuf = {
61 	.name = "iobuf",
62 	.init = iobuf_subsystem_initialize,
63 	.fini = iobuf_subsystem_finish,
64 	.write_config_json = iobuf_write_config_json,
65 };
66 
67 SPDK_SUBSYSTEM_REGISTER(g_subsystem_iobuf);
68