Skip to content

Commit 3b33752

Browse files
committed
nvmecontrol: libxo-ify
1 parent e28529c commit 3b33752

File tree

20 files changed

+596
-496
lines changed

20 files changed

+596
-496
lines changed

sbin/nvmecontrol/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ SRCS+= telemetry.c
3030
CFLAGS+= -I${SRCTOP}/lib/libnvmf
3131
MAN= nvmecontrol.8
3232
LDFLAGS+= -rdynamic
33-
LIBADD+= nvmf sbuf util
33+
LIBADD+= nvmf sbuf util xo
3434
SUBDIR= modules
3535
HAS_TESTS=
3636
SUBDIR.${MK_TESTS}+= tests

sbin/nvmecontrol/devlist.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <stdbool.h>
3737
#include <libnvmf.h>
3838
#include <libutil.h>
39+
#include <libxo/xo.h>
3940
#include <paths.h>
4041
#include <stddef.h>
4142
#include <stdio.h>
@@ -110,9 +111,10 @@ scan_namespace(int fd, int ctrlr, uint32_t nsid)
110111
if (opt.human) {
111112
humanize_number(buf, sizeof(buf), size, "B",
112113
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
113-
printf(" %10s (%s)\n", name, buf);
114+
xo_emit("{P: }{:name/%10s} ({:buffer/%s})\n", name, buf);
114115
} else {
115-
printf(" %10s (%juMB)\n", name, (uintmax_t)size / 1024 / 1024);
116+
xo_emit("{P: }{:name/%10s} ({:buffer-megabytes/%ju}{U:MB})\n", name,
117+
(uintmax_t)size / 1024 / 1024);
116118
}
117119
}
118120

@@ -151,7 +153,7 @@ print_controller_info(const char *name, int fd)
151153
}
152154

153155
nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH);
154-
printf("%6s: %s", name, mn);
156+
xo_emit("{:name/%6s}: {:model-number/%s}", name, mn);
155157
if (connected) {
156158
const struct nvme_discovery_log_entry *dle;
157159
size_t len;
@@ -160,7 +162,8 @@ print_controller_info(const char *name, int fd)
160162
if (nvmf_reconnect_params(fd, &nvl) == 0) {
161163
dle = nvlist_get_binary(nvl, "dle", &len);
162164
if (len == sizeof(*dle)) {
163-
printf(" (connected via %s %.*s:%.*s)",
165+
xo_emit("{P: }(connected via {:trtype/%s} "
166+
"{:traddr/%.*s}:{:trsvcid/%.*s})",
164167
nvmf_transport_type(dle->trtype),
165168
(int)sizeof(dle->traddr), dle->traddr,
166169
(int)sizeof(dle->trsvcid), dle->trsvcid);
@@ -176,10 +179,10 @@ print_controller_info(const char *name, int fd)
176179
last_disconnect.tv_sec = nvlist_get_number(nvl_ts, "tv_sec");
177180
last_disconnect.tv_nsec = nvlist_get_number(nvl_ts, "tv_nsec");
178181
timespecsub(&now, &last_disconnect, &delta);
179-
printf(" (disconnected for %ju seconds)",
182+
xo_emit("{P: }(disconnected for {:seconds/%ju} seconds)",
180183
(uintmax_t)delta.tv_sec);
181184
}
182-
printf("\n");
185+
xo_emit("\n");
183186
nvlist_destroy(nvl);
184187
return (connected);
185188
}
@@ -245,7 +248,7 @@ devlist(const struct cmd *f, int argc, char *argv[])
245248
}
246249

247250
if (found == 0) {
248-
printf("No NVMe controllers found.\n");
251+
xo_emit("{d:No NVMe controllers found.}{e:devlist-page}\n");
249252
exit(EX_UNAVAILABLE);
250253
}
251254

sbin/nvmecontrol/discover.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <err.h>
99
#include <libnvmf.h>
10+
#include <libxo/xo.h>
1011
#include <stdio.h>
1112
#include <stdlib.h>
1213
#include <string.h>
@@ -182,37 +183,43 @@ nvmf_tcp_security_type(uint8_t sectype)
182183
static void
183184
print_discovery_entry(u_int i, struct nvme_discovery_log_entry *entry)
184185
{
185-
printf("Entry %02d\n", i + 1);
186-
printf("========\n");
187-
printf(" Transport type: %s\n",
186+
xo_emit("{T:Entry }{T:entry/%02d}\n", i + 1);
187+
xo_emit("{T:========}\n");
188+
xo_emit("{P: }{Lc:Transport type}{P: }{:transport/%s}\n",
188189
nvmf_transport_type(entry->trtype));
189-
printf(" Address family: %s\n",
190+
xo_emit("{P: }{Lc:Address family}{P: }{:address/%s}\n",
190191
nvmf_address_family(entry->adrfam));
191-
printf(" Subsystem type: %s\n",
192+
xo_emit("{P: }{Lc:Subsystem type}{P: }{:subsystem/%s}\n",
192193
nvmf_subsystem_type(entry->subtype));
193-
printf(" SQ flow control: %s\n",
194+
xo_emit("{P: }{Lc:SQ flow control}{P: }{:sq-flow/%s}\n",
194195
(entry->treq & (1 << 2)) == 0 ? "required" : "optional");
195-
printf(" Secure Channel: %s\n", nvmf_secure_channel(entry->treq));
196-
printf(" Port ID: %u\n", entry->portid);
197-
printf(" Controller ID: %s\n",
196+
xo_emit("{P: }{Lc:Secure Channel}{P: }{:secure-chan/%s}\n",
197+
nvmf_secure_channel(entry->treq));
198+
xo_emit("{P: }{Lc:Port ID}{P: }{:port-id/%u}\n",
199+
entry->portid);
200+
xo_emit("{P: }{Lc:Controller ID}{P: }{:controller-id/%s}\n",
198201
nvmf_controller_id(entry->cntlid));
199-
printf(" Max Admin SQ Size: %u\n", entry->aqsz);
200-
printf(" Sub NQN: %s\n", entry->subnqn);
201-
printf(" Transport address: %s\n", entry->traddr);
202-
printf(" Service identifier: %s\n", entry->trsvcid);
202+
xo_emit("{P: }{Lc:Max Admin SQ Size}{P: }{:max-admin-sq/%u}\n",
203+
entry->aqsz);
204+
xo_emit("{P: }{Lc:Sub NQN}{P: }{:sub-nqn/%s}\n",
205+
entry->subnqn);
206+
xo_emit("{P: }{Lc:Transport address}{P: }{:transport-addr/%s}\n",
207+
entry->traddr);
208+
xo_emit("{P: }{Lc:Service identifier}{P: }{:service-id/%s}\n",
209+
entry->trsvcid);
203210
switch (entry->trtype) {
204211
case NVMF_TRTYPE_RDMA:
205-
printf(" RDMA Service Type: %s\n",
212+
xo_emit("{P: }{Lc:RDMA Service Type}{P: }{:rdma-service-type/%s}\n",
206213
nvmf_rdma_service_type(entry->tsas.rdma.rdma_qptype));
207-
printf(" RDMA Provider Type: %s\n",
214+
xo_emit("{P: }{Lc:RDMA Provider Type}{P: }{:rdma-provider-type/%s}\n",
208215
nvmf_rdma_provider_type(entry->tsas.rdma.rdma_prtype));
209-
printf(" RDMA CMS: %s\n",
216+
xo_emit("{P: }{Lc:RDMA CMS}{P: }{:rdma-cms-type/%s}\n",
210217
nvmf_rdma_cms(entry->tsas.rdma.rdma_cms));
211-
printf(" Partition key: %u\n",
218+
xo_emit("{P: }{Lc:Partition key}{P: }{:part-key/%u}\n",
212219
entry->tsas.rdma.rdma_pkey);
213220
break;
214221
case NVMF_TRTYPE_TCP:
215-
printf(" Security Type: %s\n",
222+
xo_emit("{P: }{Lc:Security Type}{P: }{:security-type/%s}\n",
216223
nvmf_tcp_security_type(entry->tsas.tcp.sectype));
217224
break;
218225
}
@@ -228,10 +235,10 @@ dump_discovery_log_page(struct nvmf_qpair *qp)
228235
if (error != 0)
229236
errc(EX_IOERR, error, "Failed to fetch discovery log page");
230237

231-
printf("Discovery\n");
232-
printf("=========\n");
238+
xo_emit("{T:Discovery}\n");
239+
xo_emit("{T:=========}\n");
233240
if (log->numrec == 0) {
234-
printf("No entries found\n");
241+
xo_emit("No entries found\n");
235242
} else {
236243
for (u_int i = 0; i < log->numrec; i++)
237244
print_discovery_entry(i, &log->entries[i]);
@@ -262,7 +269,7 @@ discover(const struct cmd *f, int argc, char *argv[])
262269
/* Use Identify to fetch controller data */
263270
if (opt.verbose) {
264271
identify_controller(qp);
265-
printf("\n");
272+
xo_emit("\n");
266273
}
267274

268275
/* Fetch Log pages */

sbin/nvmecontrol/firmware.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <err.h>
3939
#include <fcntl.h>
4040
#include <inttypes.h>
41+
#include <libxo/xo.h>
4142
#include <stdbool.h>
4243
#include <stddef.h>
4344
#include <stdio.h>
@@ -308,31 +309,32 @@ firmware(const struct cmd *f, int argc, char *argv[])
308309
read_image_file(opt.fw_img, &buf, &size);
309310

310311
if (opt.fw_img != NULL&& opt.activate)
311-
printf("You are about to download and activate "
312-
"firmware image (%s) to controller %s.\n"
313-
"This may damage your controller and/or "
314-
"overwrite an existing firmware image.\n",
315-
opt.fw_img, opt.dev);
312+
xo_emit("You are about to download and activate "
313+
"firmware image ({:firmware-image/%s}) to "
314+
"controller {:controller/%s}.\n"
315+
"This may damage your controller and/or "
316+
"overwrite an existing firmware image.\n",
317+
opt.fw_img, opt.dev);
316318
else if (opt.activate)
317-
printf("You are about to activate a new firmware "
318-
"image on controller %s.\n"
319-
"This may damage your controller.\n",
320-
opt.dev);
319+
xo_emit("You are about to activate a new firmware "
320+
"image on controller {:controller/%s}.\n"
321+
"This may damage your controller.\n",
322+
opt.dev);
321323
else if (opt.fw_img != NULL)
322-
printf("You are about to download firmware image "
323-
"(%s) to controller %s.\n"
324-
"This may damage your controller and/or "
325-
"overwrite an existing firmware image.\n",
326-
opt.fw_img, opt.dev);
324+
xo_emit("You are about to download firmware image "
325+
"({:firmware-image/%s}) to controller {:controller/%s}.\n"
326+
"This may damage your controller and/or "
327+
"overwrite an existing firmware image.\n",
328+
opt.fw_img, opt.dev);
327329

328-
printf("Are you sure you want to continue? (yes/no) ");
330+
xo_emit("Are you sure you want to continue? (yes/no) ");
329331
while (1) {
330332
fgets(prompt, sizeof(prompt), stdin);
331333
if (strncasecmp(prompt, "yes", 3) == 0)
332334
break;
333335
if (strncasecmp(prompt, "no", 2) == 0)
334336
exit(EX_DATAERR);
335-
printf("Please answer \"yes\" or \"no\". ");
337+
xo_emit("Please answer \"yes\" or \"no\". ");
336338
}
337339

338340
if (opt.fw_img != NULL) {
@@ -349,15 +351,15 @@ firmware(const struct cmd *f, int argc, char *argv[])
349351

350352
if (opt.activate) {
351353
if (reboot_required) {
352-
printf("New firmware image activated but requires "
353-
"conventional reset (i.e. reboot) to "
354-
"complete activation.\n");
354+
xo_emit("New firmware image activated but requires "
355+
"conventional reset (i.e. reboot) to "
356+
"complete activation.\n");
355357
} else {
356-
printf("New firmware image activated and will take "
357-
"effect after next controller reset.\n"
358-
"Controller reset can be initiated via "
359-
"'nvmecontrol reset %s'\n",
360-
opt.dev);
358+
xo_emit("New firmware image activated and will take "
359+
"effect after next controller reset.\n"
360+
"Controller reset can be initiated via "
361+
"'nvmecontrol reset {:nvmecontrol-reset/%s}'\n",
362+
opt.dev);
361363
}
362364
}
363365

0 commit comments

Comments
 (0)