Skip to content

Commit d4ee216

Browse files
committed
Rework the CLI list command
1 parent b0c4865 commit d4ee216

File tree

5 files changed

+60
-57
lines changed

5 files changed

+60
-57
lines changed

src/cli/cli.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,28 @@ struct command {
2222
};
2323

2424
struct context {
25+
/* main */
2526
uid_t uid;
2627
gid_t gid;
28+
bool load_kmods;
29+
char *init_flags;
30+
const struct command *command;
31+
32+
/* configure */
2733
pid_t pid;
2834
char *rootfs;
29-
char *devices;
3035
char *reqs[32];
3136
size_t nreqs;
3237
char *ldconfig;
33-
bool load_kmods;
34-
bool list_info;
35-
char *init_flags;
36-
char *driver_flags;
37-
char *device_flags;
3838
char *container_flags;
3939

40-
const struct command *command;
40+
/* list */
41+
bool compat32;
42+
bool list_bins;
43+
bool list_libs;
44+
bool list_ipcs;
45+
46+
char *devices;
4147
};
4248

4349
int select_devices(struct error *, char *, const struct nvc_device *[],

src/cli/configure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ configure_command(const struct context *ctx)
226226
warnx("permission error: %s", err.msg);
227227
goto fail;
228228
}
229-
if ((drv = nvc_driver_info_new(nvc, ctx->driver_flags)) == NULL ||
230-
(dev = nvc_device_info_new(nvc, ctx->device_flags)) == NULL) {
229+
if ((drv = nvc_driver_info_new(nvc, NULL)) == NULL ||
230+
(dev = nvc_device_info_new(nvc, NULL)) == NULL) {
231231
warnx("detection error: %s", nvc_error(nvc));
232232
goto fail;
233233
}

src/cli/dsl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ enum dsl_comparator {
1919
};
2020

2121
struct dsl_data {
22-
struct nvc_driver_info *drv;
23-
const struct nvc_device *dev;
22+
struct nvc_driver_info *drv;
23+
const struct nvc_device *dev;
2424
};
2525

2626
struct dsl_rule {
27-
const char *name;
28-
int (*func)(const struct dsl_data *, enum dsl_comparator, const char *);
27+
const char *name;
28+
int (*func)(const struct dsl_data *, enum dsl_comparator, const char *);
2929
};
3030

3131
int dsl_compare_version(const char *, enum dsl_comparator, const char *);

src/cli/list.c

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ static error_t list_parser(int, char *, struct argp_state *);
1313
const struct argp list_usage = {
1414
(const struct argp_option[]){
1515
{NULL, 0, NULL, 0, "Options:", -1},
16-
{"info", 'i', NULL, 0, "List driver version information", -1},
1716
{"device", 'd', "ID", 0, "Device UUID(s) or index(es) to list", -1},
18-
{"compute", 'c', NULL, 0, "List compute components", -1},
19-
{"utility", 'u', NULL, 0, "List utility components", -1},
20-
{"video", 'v', NULL, 0, "List video components", -1},
21-
{"graphics", 'g', NULL, 0, "List graphics components", -1},
22-
{"compat32", 0x80, NULL, 0, "List 32bits components", -1},
17+
{"libraries", 'l', NULL, 0, "List driver libraries", -1},
18+
{"binaries", 'b', NULL, 0, "List driver binaries", -1},
19+
{"ipcs", 'i', NULL, 0, "List driver ipcs", -1},
20+
{"compat32", 0x80, NULL, 0, "Enable 32bits compatibility", -1},
2321
{0},
2422
},
2523
list_parser,
2624
NULL,
27-
"Query the host driver and list the components required in order to configure a container with GPU support.",
25+
"Query the driver and list the components required in order to configure a container with GPU support.",
2826
NULL,
2927
NULL,
3028
NULL,
@@ -37,32 +35,31 @@ list_parser(int key, char *arg, struct argp_state *state)
3735
struct error err = {0};
3836

3937
switch (key) {
40-
case 'i':
41-
ctx->list_info = true;
42-
break;
4338
case 'd':
4439
if (strjoin(&err, &ctx->devices, arg, ",") < 0)
4540
goto fatal;
4641
break;
47-
case 'c':
48-
if (strjoin(&err, &ctx->container_flags, "compute", " ") < 0)
49-
goto fatal;
42+
case 'l':
43+
ctx->list_libs = true;
5044
break;
51-
case 'u':
52-
if (strjoin(&err, &ctx->container_flags, "utility", " ") < 0)
53-
goto fatal;
45+
case 'b':
46+
ctx->list_bins = true;
5447
break;
55-
case 'v':
56-
if (strjoin(&err, &ctx->container_flags, "video", " ") < 0)
57-
goto fatal;
58-
break;
59-
case 'g':
60-
if (strjoin(&err, &ctx->container_flags, "graphics", " ") < 0)
61-
goto fatal;
48+
case 'i':
49+
ctx->list_ipcs = true;
6250
break;
6351
case 0x80:
64-
if (strjoin(&err, &ctx->container_flags, "compat32", " ") < 0)
65-
goto fatal;
52+
ctx->compat32 = true;
53+
break;
54+
case ARGP_KEY_END:
55+
if (state->argc == 1) {
56+
if ((ctx->devices = xstrdup(&err, "all")) == NULL)
57+
goto fatal;
58+
ctx->compat32 = true;
59+
ctx->list_libs = true;
60+
ctx->list_bins = true;
61+
ctx->list_ipcs = true;
62+
}
6663
break;
6764
default:
6865
return (ARGP_ERR_UNKNOWN);
@@ -128,18 +125,12 @@ list_command(const struct context *ctx)
128125
warnx("permission error: %s", err.msg);
129126
goto fail;
130127
}
131-
if ((drv = nvc_driver_info_new(nvc, ctx->driver_flags)) == NULL ||
132-
(dev = nvc_device_info_new(nvc, ctx->device_flags)) == NULL) {
128+
if ((drv = nvc_driver_info_new(nvc, NULL)) == NULL ||
129+
(dev = nvc_device_info_new(nvc, NULL)) == NULL) {
133130
warnx("detection error: %s", nvc_error(nvc));
134131
goto fail;
135132
}
136133

137-
/* List the driver information. */
138-
if (ctx->list_info) {
139-
printf("NVRM version: %s\n", drv->nvrm_version);
140-
printf("CUDA version: %s\n", drv->cuda_version);
141-
}
142-
143134
/* List the visible GPU devices. */
144135
if (dev->ngpus > 0) {
145136
gpus = alloca(dev->ngpus * sizeof(*gpus));
@@ -159,14 +150,22 @@ list_command(const struct context *ctx)
159150
}
160151

161152
/* List the driver components */
162-
for (size_t i = 0; i < drv->nbins; ++i)
163-
printf("%s\n", drv->bins[i]);
164-
for (size_t i = 0; i < drv->nlibs; ++i)
165-
printf("%s\n", drv->libs[i]);
166-
for (size_t i = 0; i < drv->nlibs32; ++i)
167-
printf("%s\n", drv->libs32[i]);
168-
for (size_t i = 0; i < drv->nipcs; ++i)
169-
printf("%s\n", drv->ipcs[i]);
153+
if (ctx->list_bins) {
154+
for (size_t i = 0; i < drv->nbins; ++i)
155+
printf("%s\n", drv->bins[i]);
156+
}
157+
if (ctx->list_libs) {
158+
for (size_t i = 0; i < drv->nlibs; ++i)
159+
printf("%s\n", drv->libs[i]);
160+
if (ctx->compat32) {
161+
for (size_t i = 0; i < drv->nlibs32; ++i)
162+
printf("%s\n", drv->libs32[i]);
163+
}
164+
}
165+
if (ctx->list_ipcs) {
166+
for (size_t i = 0; i < drv->nipcs; ++i)
167+
printf("%s\n", drv->ipcs[i]);
168+
}
170169

171170
if (run_as_root && perm_set_capabilities(&err, CAP_EFFECTIVE, effective_caps[CAPS_SHUTDOWN], effective_caps_size(CAPS_SHUTDOWN)) < 0) {
172171
warnx("permission error: %s", err.msg);

src/cli/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static struct argp usage = {
3030
{"load-kmods", 'k', NULL, 0, "Load kernel modules", -1},
3131
{"user", 'u', "UID[:GID]", OPTION_ARG_OPTIONAL, "User and group to use for privilege separation", -1},
3232
{NULL, 0, NULL, 0, "Commands:", 0},
33-
{"list", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "List host driver components", 0},
33+
{"list", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "List driver components", 0},
3434
{"configure", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "Configure a container with GPU support", 0},
3535
{0},
3636
},
@@ -126,8 +126,6 @@ main(int argc, char *argv[])
126126

127127
free(ctx.devices);
128128
free(ctx.init_flags);
129-
free(ctx.driver_flags);
130-
free(ctx.device_flags);
131129
free(ctx.container_flags);
132130
return (rv);
133131
}

0 commit comments

Comments
 (0)