Skip to content

Commit 0d46064

Browse files
committed
fabrics: move URI data struct to private API
Make the URI data structure opaque and provide getter/setters to allow modification and extension later. While at it, also rename it to match the naming scheme and update the helper functions accordingly. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 103205a commit 0d46064

10 files changed

Lines changed: 363 additions & 80 deletions

File tree

libnvme/src/accessors-fabrics.ld

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,23 @@
1111
LIBNVMF_ACCESSORS_3 {
1212
global:
1313
libnvmf_discovery_args_get_lsp;
14-
libnvmf_discovery_args_set_lsp;
1514
libnvmf_discovery_args_get_max_retries;
15+
libnvmf_discovery_args_set_lsp;
1616
libnvmf_discovery_args_set_max_retries;
17+
libnvmf_uri_get_fragment;
18+
libnvmf_uri_get_host;
19+
libnvmf_uri_get_path_segments;
20+
libnvmf_uri_get_port;
21+
libnvmf_uri_get_protocol;
22+
libnvmf_uri_get_query;
23+
libnvmf_uri_get_scheme;
24+
libnvmf_uri_get_userinfo;
25+
libnvmf_uri_set_fragment;
26+
libnvmf_uri_set_host;
27+
libnvmf_uri_set_path_segments;
28+
libnvmf_uri_set_port;
29+
libnvmf_uri_set_protocol;
30+
libnvmf_uri_set_query;
31+
libnvmf_uri_set_scheme;
32+
libnvmf_uri_set_userinfo;
1733
};

libnvme/src/libnvme.ld

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ LIBNVME_3 {
136136
libnvme_ns_write_uncorrectable;
137137
libnvme_ns_write_zeros;
138138
libnvme_open;
139-
libnvme_parse_uri;
140139
libnvme_path_get_ctrl;
141140
libnvme_path_get_ns;
142141
libnvme_path_get_queue_depth;

libnvme/src/libnvmf.ld

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ LIBNVMF_3 {
3131
libnvmf_discovery_nbft;
3232
libnvmf_eflags_str;
3333
libnvmf_exat_ptr_next;
34-
libnvmf_free_uri;
3534
libnvmf_get_default_trsvcid;
3635
libnvmf_get_discovery_log;
3736
libnvmf_is_registration_supported;
@@ -44,6 +43,8 @@ LIBNVMF_3 {
4443
libnvmf_subtype_str;
4544
libnvmf_treq_str;
4645
libnvmf_trtype_str;
46+
libnvmf_uri_free;
47+
libnvmf_uri_parse;
4748
local:
4849
*;
4950
};

libnvme/src/nvme/accessors-fabrics.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,127 @@ __public __u8 libnvmf_discovery_args_get_lsp(
5454
return p->lsp;
5555
}
5656

57+
/****************************************************************************
58+
* Accessors for: struct libnvmf_uri
59+
****************************************************************************/
60+
61+
__public void libnvmf_uri_set_scheme(struct libnvmf_uri *p, const char *scheme)
62+
{
63+
free(p->scheme);
64+
p->scheme = scheme ? strdup(scheme) : NULL;
65+
}
66+
67+
__public const char *libnvmf_uri_get_scheme(const struct libnvmf_uri *p)
68+
{
69+
return p->scheme;
70+
}
71+
72+
__public void libnvmf_uri_set_protocol(
73+
struct libnvmf_uri *p,
74+
const char *protocol)
75+
{
76+
free(p->protocol);
77+
p->protocol = protocol ? strdup(protocol) : NULL;
78+
}
79+
80+
__public const char *libnvmf_uri_get_protocol(const struct libnvmf_uri *p)
81+
{
82+
return p->protocol;
83+
}
84+
85+
__public void libnvmf_uri_set_userinfo(
86+
struct libnvmf_uri *p,
87+
const char *userinfo)
88+
{
89+
free(p->userinfo);
90+
p->userinfo = userinfo ? strdup(userinfo) : NULL;
91+
}
92+
93+
__public const char *libnvmf_uri_get_userinfo(const struct libnvmf_uri *p)
94+
{
95+
return p->userinfo;
96+
}
97+
98+
__public void libnvmf_uri_set_host(struct libnvmf_uri *p, const char *host)
99+
{
100+
free(p->host);
101+
p->host = host ? strdup(host) : NULL;
102+
}
103+
104+
__public const char *libnvmf_uri_get_host(const struct libnvmf_uri *p)
105+
{
106+
return p->host;
107+
}
108+
109+
__public void libnvmf_uri_set_port(struct libnvmf_uri *p, int port)
110+
{
111+
p->port = port;
112+
}
113+
114+
__public int libnvmf_uri_get_port(const struct libnvmf_uri *p)
115+
{
116+
return p->port;
117+
}
118+
119+
__public void libnvmf_uri_set_path_segments(
120+
struct libnvmf_uri *p,
121+
const char *const *path_segments)
122+
{
123+
char **new_array = NULL;
124+
size_t i;
125+
126+
if (path_segments) {
127+
for (i = 0; path_segments[i]; i++)
128+
;
129+
130+
new_array = calloc(i + 1, sizeof(char *));
131+
if (new_array != NULL) {
132+
for (i = 0; path_segments[i]; i++) {
133+
new_array[i] = strdup(path_segments[i]);
134+
if (!new_array[i]) {
135+
while (i > 0)
136+
free(new_array[--i]);
137+
free(new_array);
138+
new_array = NULL;
139+
break;
140+
}
141+
}
142+
}
143+
}
144+
145+
for (i = 0; p->path_segments && p->path_segments[i]; i++)
146+
free(p->path_segments[i]);
147+
free(p->path_segments);
148+
p->path_segments = new_array;
149+
}
150+
151+
__public const char *const *libnvmf_uri_get_path_segments(
152+
const struct libnvmf_uri *p)
153+
{
154+
return (const char *const *)p->path_segments;
155+
}
156+
157+
__public void libnvmf_uri_set_query(struct libnvmf_uri *p, const char *query)
158+
{
159+
free(p->query);
160+
p->query = query ? strdup(query) : NULL;
161+
}
162+
163+
__public const char *libnvmf_uri_get_query(const struct libnvmf_uri *p)
164+
{
165+
return p->query;
166+
}
167+
168+
__public void libnvmf_uri_set_fragment(
169+
struct libnvmf_uri *p,
170+
const char *fragment)
171+
{
172+
free(p->fragment);
173+
p->fragment = fragment ? strdup(fragment) : NULL;
174+
}
175+
176+
__public const char *libnvmf_uri_get_fragment(const struct libnvmf_uri *p)
177+
{
178+
return p->fragment;
179+
}
180+

libnvme/src/nvme/accessors-fabrics.h

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
/* Forward declarations. These are internal (opaque) structs. */
3131
struct libnvmf_discovery_args;
32+
struct libnvmf_uri;
3233

3334
/****************************************************************************
3435
* Accessors for: struct libnvmf_discovery_args
@@ -67,4 +68,130 @@ void libnvmf_discovery_args_set_lsp(struct libnvmf_discovery_args *p, __u8 lsp);
6768
*/
6869
__u8 libnvmf_discovery_args_get_lsp(const struct libnvmf_discovery_args *p);
6970

71+
/****************************************************************************
72+
* Accessors for: struct libnvmf_uri
73+
****************************************************************************/
74+
75+
/**
76+
* libnvmf_uri_set_scheme() - Set scheme.
77+
* @p: The &struct libnvmf_uri instance to update.
78+
* @scheme: New string; a copy is stored. Pass NULL to clear.
79+
*/
80+
void libnvmf_uri_set_scheme(struct libnvmf_uri *p, const char *scheme);
81+
82+
/**
83+
* libnvmf_uri_get_scheme() - Get scheme.
84+
* @p: The &struct libnvmf_uri instance to query.
85+
*
86+
* Return: The value of the scheme field, or NULL if not set.
87+
*/
88+
const char *libnvmf_uri_get_scheme(const struct libnvmf_uri *p);
89+
90+
/**
91+
* libnvmf_uri_set_protocol() - Set protocol.
92+
* @p: The &struct libnvmf_uri instance to update.
93+
* @protocol: New string; a copy is stored. Pass NULL to clear.
94+
*/
95+
void libnvmf_uri_set_protocol(struct libnvmf_uri *p, const char *protocol);
96+
97+
/**
98+
* libnvmf_uri_get_protocol() - Get protocol.
99+
* @p: The &struct libnvmf_uri instance to query.
100+
*
101+
* Return: The value of the protocol field, or NULL if not set.
102+
*/
103+
const char *libnvmf_uri_get_protocol(const struct libnvmf_uri *p);
104+
105+
/**
106+
* libnvmf_uri_set_userinfo() - Set userinfo.
107+
* @p: The &struct libnvmf_uri instance to update.
108+
* @userinfo: New string; a copy is stored. Pass NULL to clear.
109+
*/
110+
void libnvmf_uri_set_userinfo(struct libnvmf_uri *p, const char *userinfo);
111+
112+
/**
113+
* libnvmf_uri_get_userinfo() - Get userinfo.
114+
* @p: The &struct libnvmf_uri instance to query.
115+
*
116+
* Return: The value of the userinfo field, or NULL if not set.
117+
*/
118+
const char *libnvmf_uri_get_userinfo(const struct libnvmf_uri *p);
119+
120+
/**
121+
* libnvmf_uri_set_host() - Set host.
122+
* @p: The &struct libnvmf_uri instance to update.
123+
* @host: New string; a copy is stored. Pass NULL to clear.
124+
*/
125+
void libnvmf_uri_set_host(struct libnvmf_uri *p, const char *host);
126+
127+
/**
128+
* libnvmf_uri_get_host() - Get host.
129+
* @p: The &struct libnvmf_uri instance to query.
130+
*
131+
* Return: The value of the host field, or NULL if not set.
132+
*/
133+
const char *libnvmf_uri_get_host(const struct libnvmf_uri *p);
134+
135+
/**
136+
* libnvmf_uri_set_port() - Set port.
137+
* @p: The &struct libnvmf_uri instance to update.
138+
* @port: Value to assign to the port field.
139+
*/
140+
void libnvmf_uri_set_port(struct libnvmf_uri *p, int port);
141+
142+
/**
143+
* libnvmf_uri_get_port() - Get port.
144+
* @p: The &struct libnvmf_uri instance to query.
145+
*
146+
* Return: The value of the port field.
147+
*/
148+
int libnvmf_uri_get_port(const struct libnvmf_uri *p);
149+
150+
/**
151+
* libnvmf_uri_set_path_segments() - Set path_segments.
152+
* @p: The &struct libnvmf_uri instance to update.
153+
* @path_segments: New NULL-terminated string array; deep-copied.
154+
*/
155+
void libnvmf_uri_set_path_segments(
156+
struct libnvmf_uri *p,
157+
const char *const *path_segments);
158+
159+
/**
160+
* libnvmf_uri_get_path_segments() - Get path_segments.
161+
* @p: The &struct libnvmf_uri instance to query.
162+
*
163+
* Return: The value of the path_segments field.
164+
*/
165+
const char *const *libnvmf_uri_get_path_segments(const struct libnvmf_uri *p);
166+
167+
/**
168+
* libnvmf_uri_set_query() - Set query.
169+
* @p: The &struct libnvmf_uri instance to update.
170+
* @query: New string; a copy is stored. Pass NULL to clear.
171+
*/
172+
void libnvmf_uri_set_query(struct libnvmf_uri *p, const char *query);
173+
174+
/**
175+
* libnvmf_uri_get_query() - Get query.
176+
* @p: The &struct libnvmf_uri instance to query.
177+
*
178+
* Return: The value of the query field, or NULL if not set.
179+
*/
180+
const char *libnvmf_uri_get_query(const struct libnvmf_uri *p);
181+
182+
/**
183+
* libnvmf_uri_set_fragment() - Set fragment.
184+
* @p: The &struct libnvmf_uri instance to update.
185+
* @fragment: New string; a copy is stored. Pass NULL to clear.
186+
*/
187+
void libnvmf_uri_set_fragment(struct libnvmf_uri *p, const char *fragment);
188+
189+
/**
190+
* libnvmf_uri_get_fragment() - Get fragment.
191+
* @p: The &struct libnvmf_uri instance to query.
192+
*
193+
* Return: The value of the fragment field, or NULL if not set.
194+
*/
195+
const char *libnvmf_uri_get_fragment(const struct libnvmf_uri *p);
196+
70197
#endif /* _ACCESSORS_FABRICS_H_ */

0 commit comments

Comments
 (0)