Debian Codegraph @

src/lib/plugin_apis/nvdimm.api

raw
1 #include <glib.h>
2 #include <glib-object.h>
3 #include <blockdev/utils.h>
4
5 #ifndef BD_NVDIMM_API
6 #define BD_NVDIMM_API
7
8 GQuark bd_nvdimm_error_quark (void) {
9 return g_quark_from_static_string ("g-bd-nvdimm-error-quark");
10 }
11
12 #define BD_NVDIMM_ERROR bd_nvdimm_error_quark ()
13 typedef enum {
14 BD_NVDIMM_ERROR_TECH_UNAVAIL,
15 BD_NVDIMM_ERROR_NAMESPACE_FAIL,
16 BD_NVDIMM_ERROR_NAMESPACE_PARSE,
17 BD_NVDIMM_ERROR_NAMESPACE_NOEXIST,
18 BD_NVDIMM_ERROR_NAMESPACE_MODE_INVAL,
19 } BDNVDIMMError;
20
21 typedef enum {
22 BD_NVDIMM_NAMESPACE_MODE_RAW,
23 BD_NVDIMM_NAMESPACE_MODE_SECTOR,
24 BD_NVDIMM_NAMESPACE_MODE_MEMORY,
25 BD_NVDIMM_NAMESPACE_MODE_DAX,
26 BD_NVDIMM_NAMESPACE_MODE_FSDAX,
27 BD_NVDIMM_NAMESPACE_MODE_DEVDAX,
28 BD_NVDIMM_NAMESPACE_MODE_UNKNOWN,
29 } BDNVDIMMNamespaceMode;
30
31 #define BD_NVDIMM_TYPE_NAMESPACE_INFO (bd_nvdimm_namespace_info_get_type ())
32 GType bd_nvdimm_namespace_info_get_type();
33
34 /**
35 * BDNVDIMMNamespaceInfo:
36 * @dev: namespace device name ("namespaceX.Y")
37 * @mode: mode of the namespace (BDNVDIMMNamespaceMode)
38 * @size: size of the namespace
39 * @uuid: UUID of the namespace
40 * @sector_size: sector size of the namespace (0 for non-sector namespaces)
41 * @blockdev: name of the block device for the namespace
42 * @enabled: whether the namespace is enabled or not
43 */
44 typedef struct BDNVDIMMNamespaceInfo {
45 gchar *dev;
46 guint64 mode;
47 guint64 size;
48 gchar *uuid;
49 guint64 sector_size;
50 gchar *blockdev;
51 gboolean enabled;
52 } BDNVDIMMNamespaceInfo;
53
54 /**
55 * bd_nvdimm_namespace_info_free: (skip)
56 * @info: (nullable): %BDNVDIMMNamespaceInfo to free
57 *
58 * Frees @info.
59 */
60 void bd_nvdimm_namespace_info_free (BDNVDIMMNamespaceInfo *info) {
61 if (info == NULL)
62 return;
63
64 g_free (info->dev);
65 g_free (info->uuid);
66 g_free (info->blockdev);
67 g_free (info);
68 }
69
70 /**
71 * bd_nvdimm_namespace_info_copy: (skip)
72 * @info: (nullable): %BDNVDIMMNamespaceInfo to copy
73 *
74 * Creates a new copy of @info.
75 */
76 BDNVDIMMNamespaceInfo* bd_nvdimm_namespace_info_copy (BDNVDIMMNamespaceInfo *info) {
77 if (info == NULL)
78 return NULL;
79
80 BDNVDIMMNamespaceInfo *new_info = g_new0 (BDNVDIMMNamespaceInfo, 1);
81
82 new_info->dev = g_strdup (info->dev);
83 new_info->mode = info->mode;
84 new_info->size = info->size;
85 new_info->uuid = g_strdup (info->uuid);
86 new_info->sector_size = info->sector_size;
87 new_info->blockdev = g_strdup (info->blockdev);
88 new_info->enabled = info->enabled;
89
90 return new_info;
91 }
92
93 GType bd_nvdimm_namespace_info_get_type () {
94 static GType type = 0;
95
96 if (G_UNLIKELY(type == 0)) {
97 type = g_boxed_type_register_static("BDNVDIMMNamespaceInfo",
98 (GBoxedCopyFunc) bd_nvdimm_namespace_info_copy,
99 (GBoxedFreeFunc) bd_nvdimm_namespace_info_free);
100 }
101
102 return type;
103 }
104
105 typedef enum {
106 BD_NVDIMM_TECH_NAMESPACE = 0,
107 } BDNVDIMMTech;
108
109 typedef enum {
110 BD_NVDIMM_TECH_MODE_CREATE = 1 << 0,
111 BD_NVDIMM_TECH_MODE_REMOVE = 1 << 1,
112 BD_NVDIMM_TECH_MODE_ACTIVATE_DEACTIVATE = 1 << 2,
113 BD_NVDIMM_TECH_MODE_QUERY = 1 << 3,
114 BD_NVDIMM_TECH_MODE_RECONFIGURE = 1 << 4,
115 } BDNVDIMMTechMode;
116
117 /**
118 * bd_nvdimm_is_tech_avail:
119 * @tech: the queried tech
120 * @mode: a bit mask of queried modes of operation (#BDNVDIMMTechMode) for @tech
121 * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
122 *
123 * Returns: whether the @tech-@mode combination is available -- supported by the
124 * plugin implementation and having all the runtime dependencies available
125 *
126 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
127 */
128 gboolean bd_nvdimm_is_tech_avail (BDNVDIMMTech tech, guint64 mode, GError **error);
129
130 /**
131 * bd_nvdimm_namespace_get_mode_from_str:
132 * @mode_str: string representation of mode
133 * @error: (out) (optional): place to store error (if any)
134 *
135 * Returns: mode matching the @mode_str given or %BD_NVDIMM_NAMESPACE_MODE_UNKNOWN in case of no match
136 *
137 * Tech category: always available
138 *
139 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
140 */
141 BDNVDIMMNamespaceMode bd_nvdimm_namespace_get_mode_from_str (const gchar *mode_str, GError **error);
142
143 /**
144 * bd_nvdimm_namespace_get_mode_str:
145 * @mode: mode to get string representation of
146 * @error: (out) (optional): place to store error (if any)
147 *
148 * Returns: (transfer none): string representation of @mode or %NULL in case of error
149 *
150 * Tech category: always available
151 *
152 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
153 */
154 const gchar* bd_nvdimm_namespace_get_mode_str (BDNVDIMMNamespaceMode mode, GError **error);
155
156 /**
157 * bd_nvdimm_namespace_get_devname:
158 * @device: name or path of a block device (e.g. "/dev/pmem0")
159 * @error: (out) (optional): place to store error (if any)
160 *
161 * Returns: (transfer full): namespace device name (e.g. "namespaceX.Y") for @device
162 * or %NULL if @device is not a NVDIMM namespace
163 * (@error may be set to indicate error)
164 *
165 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_QUERY
166 *
167 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
168 */
169 gchar* bd_nvdimm_namespace_get_devname (const gchar *device, GError **error);
170
171 /**
172 * bd_nvdimm_namespace_enable:
173 * @namespace: name of the namespace to enable
174 * @extra: (nullable) (array zero-terminated=1): extra options (currently unused)
175 * @error: (out) (optional): place to store error (if any)
176 *
177 * Returns: whether the @namespace was successfully enabled or not
178 *
179 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_ACTIVATE_DEACTIVATE
180 *
181 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
182 */
183 gboolean bd_nvdimm_namespace_enable (const gchar *namespace, const BDExtraArg **extra, GError **error);
184
185 /**
186 * bd_nvdimm_namespace_disable:
187 * @namespace: name of the namespace to disable
188 * @extra: (nullable) (array zero-terminated=1): extra options (currently unused)
189 * @error: (out) (optional): place to store error (if any)
190 *
191 * Returns: whether the @namespace was successfully disabled or not
192 *
193 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_ACTIVATE_DEACTIVATE
194 *
195 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
196 */
197 gboolean bd_nvdimm_namespace_disable (const gchar *namespace, const BDExtraArg **extra, GError **error);
198
199 /**
200 * bd_nvdimm_namespace_info:
201 * @namespace: namespace to get information about
202 * @extra: (nullable) (array zero-terminated=1): extra options (currently unused)
203 * @error: (out) (optional): place to store error (if any)
204 *
205 * Returns: (transfer full): information about given namespace or %NULL if no such
206 * namespace was found (@error may be set to indicate error)
207 *
208 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_QUERY
209 *
210 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
211 */
212 BDNVDIMMNamespaceInfo* bd_nvdimm_namespace_info (const gchar *namespace, const BDExtraArg **extra, GError **error);
213
214 /**
215 * bd_nvdimm_list_namespaces:
216 * @bus: (nullable): return only namespaces on given bus (specified by name),
217 * %NULL may be specified to return namespaces from all buses
218 * @region: (nullable): return only namespaces on given region (specified by 'regionX' name),
219 * %NULL may be specified to return namespaces from all regions
220 * @idle: whether to list idle (not enabled) namespaces too
221 * @extra: (nullable) (array zero-terminated=1): extra options (currently unused)
222 * @error: (out) (optional): place to store error (if any)
223 *
224 * Returns: (array zero-terminated=1): information about the namespaces on @bus and @region or
225 * %NULL if no namespaces were found (@error may be set to indicate error)
226 *
227 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_QUERY
228 *
229 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
230 */
231 BDNVDIMMNamespaceInfo** bd_nvdimm_list_namespaces (const gchar *bus, const gchar *region, gboolean idle, const BDExtraArg **extra, GError **error);
232
233 /**
234 * bd_nvdimm_namespace_reconfigure:
235 * @namespace: name of the namespace to reconfigure
236 * @mode: mode type to set (raw/sector/memory/dax/fsdax/devdax)
237 * @force: whether to use force to reconfigure an active namespace
238 * @error: (out) (optional): place to store error if any
239 * @extra: (nullable) (array zero-terminated=1): extra options for the creation (right now
240 * passed to the 'ndctl' utility)
241 *
242 * Returns: whether @namespace was successfully reconfigured or not
243 *
244 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_RECONFIGURE
245 *
246 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
247 */
248 gboolean bd_nvdimm_namespace_reconfigure (const gchar* namespace, BDNVDIMMNamespaceMode mode, gboolean force, const BDExtraArg **extra, GError** error);
249
250 /**
251 * bd_nvdimm_namespace_get_supported_sector_sizes:
252 * @mode: namespace mode
253 * @error: (out) (optional): place to store error if any
254 *
255 * Returns: (transfer none) (array zero-terminated=1): list of supported sector sizes for @mode
256 *
257 * Tech category: %BD_NVDIMM_TECH_NAMESPACE-%BD_NVDIMM_TECH_MODE_QUERY
258 *
259 * Deprecated: 3.1: NVDIMM plugin will be removed in the next major release
260 */
261 const guint64 *bd_nvdimm_namespace_get_supported_sector_sizes (BDNVDIMMNamespaceMode mode, GError **error);
262
263 #endif /* BD_NVDIMM_API */