Skip to content

Commit 7888296

Browse files
committed
Move the driver capabilities to the container options
1 parent 3c1e925 commit 7888296

File tree

5 files changed

+140
-147
lines changed

5 files changed

+140
-147
lines changed

src/nvc_cli.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,27 +245,23 @@ list_parser(int key, char *arg, struct argp_state *state)
245245
goto fatal;
246246
break;
247247
case 'c':
248-
if (strjoin(&err, &ctx->driver_flags, "compute", " ") < 0 ||
249-
strjoin(&err, &ctx->device_flags, "compute", " ") < 0)
248+
if (strjoin(&err, &ctx->container_flags, "compute", " ") < 0)
250249
goto fatal;
251250
break;
252251
case 'u':
253-
if (strjoin(&err, &ctx->driver_flags, "utility", " ") < 0 ||
254-
strjoin(&err, &ctx->device_flags, "utility", " ") < 0)
252+
if (strjoin(&err, &ctx->container_flags, "utility", " ") < 0)
255253
goto fatal;
256254
break;
257255
case 'v':
258-
if (strjoin(&err, &ctx->driver_flags, "video", " ") < 0 ||
259-
strjoin(&err, &ctx->device_flags, "video", " ") < 0)
256+
if (strjoin(&err, &ctx->container_flags, "video", " ") < 0)
260257
goto fatal;
261258
break;
262259
case 'g':
263-
if (strjoin(&err, &ctx->driver_flags, "graphics", " ") < 0 ||
264-
strjoin(&err, &ctx->device_flags, "graphics", " ") < 0)
260+
if (strjoin(&err, &ctx->container_flags, "graphics", " ") < 0)
265261
goto fatal;
266262
break;
267263
case 0x80:
268-
if (strjoin(&err, &ctx->driver_flags, "compat32", " ") < 0)
264+
if (strjoin(&err, &ctx->container_flags, "compat32", " ") < 0)
269265
goto fatal;
270266
break;
271267
default:
@@ -304,27 +300,23 @@ configure_parser(int key, char *arg, struct argp_state *state)
304300
ctx->ldconfig = arg;
305301
break;
306302
case 'c':
307-
if (strjoin(&err, &ctx->driver_flags, "compute", " ") < 0 ||
308-
strjoin(&err, &ctx->device_flags, "compute", " ") < 0)
303+
if (strjoin(&err, &ctx->container_flags, "compute", " ") < 0)
309304
goto fatal;
310305
break;
311306
case 'u':
312-
if (strjoin(&err, &ctx->driver_flags, "utility", " ") < 0 ||
313-
strjoin(&err, &ctx->device_flags, "utility", " ") < 0)
307+
if (strjoin(&err, &ctx->container_flags, "utility", " ") < 0)
314308
goto fatal;
315309
break;
316310
case 'v':
317-
if (strjoin(&err, &ctx->driver_flags, "video", " ") < 0 ||
318-
strjoin(&err, &ctx->device_flags, "video", " ") < 0)
311+
if (strjoin(&err, &ctx->container_flags, "video", " ") < 0)
319312
goto fatal;
320313
break;
321314
case 'g':
322-
if (strjoin(&err, &ctx->driver_flags, "graphics", " ") < 0 ||
323-
strjoin(&err, &ctx->device_flags, "graphics", " ") < 0)
315+
if (strjoin(&err, &ctx->container_flags, "graphics", " ") < 0)
324316
goto fatal;
325317
break;
326318
case 0x80:
327-
if (strjoin(&err, &ctx->driver_flags, "compat32", " ") < 0)
319+
if (strjoin(&err, &ctx->container_flags, "compat32", " ") < 0)
328320
goto fatal;
329321
break;
330322
case 0x81:
@@ -486,8 +478,8 @@ list_command(const struct context *ctx)
486478
warnx("permission error: %s", err.msg);
487479
goto fail;
488480
}
489-
if ((drv = nvc_driver_info_new(nvc, (ctx->driver_flags != NULL) ? ctx->driver_flags : "")) == NULL ||
490-
(dev = nvc_device_info_new(nvc, (ctx->device_flags != NULL) ? ctx->device_flags : "")) == NULL) {
481+
if ((drv = nvc_driver_info_new(nvc, ctx->driver_flags)) == NULL ||
482+
(dev = nvc_device_info_new(nvc, ctx->device_flags)) == NULL) {
491483
warnx("detection error: %s", nvc_error(nvc));
492484
goto fail;
493485
}

src/nvc_info.c

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
nitems(graphics_libs_compat))
3030

3131
static int select_libraries(struct error *, void *, const char *, const char *);
32-
static int find_library_paths(struct error *, struct nvc_driver_info *, int32_t, const char *, const char * const [], size_t);
32+
static int find_library_paths(struct error *, struct nvc_driver_info *, const char *, const char * const [], size_t);
3333
static int find_binary_paths(struct error *, struct nvc_driver_info *, const char * const [], size_t);
3434
static int find_device_node(struct error *, const char *, struct nvc_device_node *);
3535
static int find_ipc_path(struct error *, const char *, char **);
@@ -148,7 +148,7 @@ select_libraries(struct error *err, void *ptr, const char *orig_path, const char
148148
}
149149

150150
static int
151-
find_library_paths(struct error *err, struct nvc_driver_info *info, int32_t flags,
151+
find_library_paths(struct error *err, struct nvc_driver_info *info,
152152
const char *ldcache, const char * const libs[], size_t size)
153153
{
154154
struct ldcache ld;
@@ -166,15 +166,13 @@ find_library_paths(struct error *err, struct nvc_driver_info *info, int32_t flag
166166
info->libs, info->nlibs, select_libraries, info) < 0)
167167
goto fail;
168168

169-
if (flags & OPT_COMPAT32) {
170-
info->nlibs32 = size;
171-
info->libs32 = array_new(err, size);
172-
if (info->libs32 == NULL)
173-
goto fail;
174-
if (ldcache_resolve(&ld, LIB32_ARCH, libs,
175-
info->libs32, info->nlibs32, select_libraries, info) < 0)
176-
goto fail;
177-
}
169+
info->nlibs32 = size;
170+
info->libs32 = array_new(err, size);
171+
if (info->libs32 == NULL)
172+
goto fail;
173+
if (ldcache_resolve(&ld, LIB32_ARCH, libs,
174+
info->libs32, info->nlibs32, select_libraries, info) < 0)
175+
goto fail;
178176
rv = 0;
179177

180178
fail:
@@ -267,24 +265,17 @@ lookup_libraries(struct error *err, struct nvc_driver_info *info, int32_t flags,
267265
const char *libs[MAX_LIBS];
268266
const char **ptr = libs;
269267

270-
if (flags & OPT_UTILITY_LIBS)
271-
ptr = array_append(ptr, utility_libs, nitems(utility_libs));
272-
if (flags & OPT_COMPUTE_LIBS)
273-
ptr = array_append(ptr, compute_libs, nitems(compute_libs));
274-
if (flags & OPT_VIDEO_LIBS)
275-
ptr = array_append(ptr, video_libs, nitems(video_libs));
276-
if (flags & OPT_GRAPHICS_LIBS) {
277-
ptr = array_append(ptr, graphics_libs, nitems(graphics_libs));
278-
if (flags & OPT_NO_GLVND)
279-
ptr = array_append(ptr, graphics_libs_compat, nitems(graphics_libs_compat));
280-
else
281-
ptr = array_append(ptr, graphics_libs_glvnd, nitems(graphics_libs_glvnd));
282-
}
268+
ptr = array_append(ptr, utility_libs, nitems(utility_libs));
269+
ptr = array_append(ptr, compute_libs, nitems(compute_libs));
270+
ptr = array_append(ptr, video_libs, nitems(video_libs));
271+
ptr = array_append(ptr, graphics_libs, nitems(graphics_libs));
272+
if (flags & OPT_NO_GLVND)
273+
ptr = array_append(ptr, graphics_libs_compat, nitems(graphics_libs_compat));
274+
else
275+
ptr = array_append(ptr, graphics_libs_glvnd, nitems(graphics_libs_glvnd));
283276

284-
if (flags & (OPT_UTILITY_LIBS|OPT_COMPUTE_LIBS|OPT_VIDEO_LIBS|OPT_GRAPHICS_LIBS)) {
285-
if (find_library_paths(err, info, flags, ldcache, libs, (size_t)(ptr - libs)) < 0)
286-
return (-1);
287-
}
277+
if (find_library_paths(err, info, ldcache, libs, (size_t)(ptr - libs)) < 0)
278+
return (-1);
288279

289280
for (size_t i = 0; info->libs != NULL && i < info->nlibs; ++i) {
290281
if (info->libs[i] == NULL)
@@ -305,15 +296,12 @@ lookup_binaries(struct error *err, struct nvc_driver_info *info, int32_t flags)
305296
const char *bins[MAX_BINS];
306297
const char **ptr = bins;
307298

308-
if (flags & OPT_UTILITY_BINS)
309-
ptr = array_append(ptr, utility_bins, nitems(utility_bins));
310-
if ((flags & OPT_COMPUTE_BINS) && !(flags & OPT_NO_MPS))
299+
ptr = array_append(ptr, utility_bins, nitems(utility_bins));
300+
if (!(flags & OPT_NO_MPS))
311301
ptr = array_append(ptr, compute_bins, nitems(compute_bins));
312302

313-
if (flags & (OPT_UTILITY_BINS|OPT_COMPUTE_BINS)) {
314-
if (find_binary_paths(err, info, bins, (size_t)(ptr - bins)) < 0)
315-
return (-1);
316-
}
303+
if (find_binary_paths(err, info, bins, (size_t)(ptr - bins)) < 0)
304+
return (-1);
317305

318306
for (size_t i = 0; info->bins != NULL && i < info->nbins; ++i) {
319307
if (info->bins[i] == NULL)
@@ -365,11 +353,11 @@ lookup_ipcs(struct error *err, struct nvc_driver_info *info, int32_t flags)
365353
if (info->ipcs == NULL)
366354
return (-1);
367355

368-
if ((flags & OPT_UTILITY_LIBS) && !(flags & OPT_NO_PERSISTENCED)) {
356+
if (!(flags & OPT_NO_PERSISTENCED)) {
369357
if (find_ipc_path(err, NV_PERSISTENCED_SOCKET, ptr++) < 0)
370358
return (-1);
371359
}
372-
if ((flags & OPT_COMPUTE_LIBS) && !(flags & OPT_NO_MPS)) {
360+
if (!(flags & OPT_NO_MPS)) {
373361
if ((mps = secure_getenv("CUDA_MPS_PIPE_DIRECTORY")) == NULL)
374362
mps = NV_MPS_PIPE_DIR;
375363
if (find_ipc_path(err, mps, ptr++) < 0)
@@ -379,6 +367,32 @@ lookup_ipcs(struct error *err, struct nvc_driver_info *info, int32_t flags)
379367
return (0);
380368
}
381369

370+
bool
371+
match_binary_flags(const char *bin, int32_t flags)
372+
{
373+
if ((flags & OPT_UTILITY_BINS) && strmatch(bin, utility_bins, nitems(utility_bins)))
374+
return (true);
375+
if ((flags & OPT_COMPUTE_BINS) && strmatch(bin, compute_bins, nitems(compute_bins)))
376+
return (true);
377+
return (false);
378+
}
379+
380+
bool
381+
match_library_flags(const char *lib, int32_t flags)
382+
{
383+
if ((flags & OPT_UTILITY_LIBS) && strmatch(lib, utility_libs, nitems(utility_libs)))
384+
return (true);
385+
if ((flags & OPT_COMPUTE_LIBS) && strmatch(lib, compute_libs, nitems(compute_libs)))
386+
return (true);
387+
if ((flags & OPT_VIDEO_LIBS) && strmatch(lib, video_libs, nitems(video_libs)))
388+
return (true);
389+
if ((flags & OPT_GRAPHICS_LIBS) && (strmatch(lib, graphics_libs, nitems(graphics_libs)) ||
390+
strmatch(lib, graphics_libs_glvnd, nitems(graphics_libs_glvnd)) ||
391+
strmatch(lib, graphics_libs_compat, nitems(graphics_libs_compat))))
392+
return (true);
393+
return (false);
394+
}
395+
382396
struct nvc_driver_info *
383397
nvc_driver_info_new(struct nvc_context *ctx, const char *opts)
384398
{

src/nvc_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ validate_args(struct nvc_context *ctx, bool predicate)
127127
return (0);
128128
}
129129

130+
/* Prototypes from nvc.c */
130131
void nvc_entrypoint(void);
131132

133+
/* Prototypes from nvc_info.c */
134+
bool match_binary_flags(const char *, int32_t);
135+
bool match_library_flags(const char *, int32_t);
136+
132137
#endif /* HEADER_NVC_INTERNAL_H */

0 commit comments

Comments
 (0)