Skip to content

Commit c9bfd1c

Browse files
committed
Move cap_device_from_path to a public facing interface
Signed-off-by: Kevin Klues <[email protected]>
1 parent f94be45 commit c9bfd1c

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

pkg/deb/libnvidia-container@[email protected]

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ libnvidia-container.so.1 libnvidia-container1 #MINVER#
1010
nvc_context_new@NVC_1.0 1.2.0~rc.3
1111
nvc_device_info_free@NVC_1.0 1.2.0~rc.3
1212
nvc_device_info_new@NVC_1.0 1.2.0~rc.3
13+
nvc_nvcaps_device_from_proc_path@NVC_1.0 1.2.0~rc.3
1314
nvc_device_mount@NVC_1.0 1.2.0~rc.3
1415
nvc_mig_device_access_caps_mount@NVC_1.0 1.2.0~rc.3
1516
nvc_mig_config_global_caps_mount@NVC_1.0 1.2.0~rc.3

src/libnvidia-container.lds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ VERSION {
3333
nvc_device_info_free;
3434
nvc_driver_mount;
3535
nvc_device_mount;
36+
nvc_nvcaps_device_from_proc_path;
3637
nvc_mig_device_access_caps_mount;
3738
nvc_mig_config_global_caps_mount;
3839
nvc_mig_monitor_global_caps_mount;

src/nvc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void nvc_driver_info_free(struct nvc_driver_info *);
121121
struct nvc_device_info *nvc_device_info_new(struct nvc_context *, const char *);
122122
void nvc_device_info_free(struct nvc_device_info *);
123123

124+
int nvc_nvcaps_device_from_proc_path(struct nvc_context *, const char *, struct nvc_device_node *);
125+
124126
int nvc_driver_mount(struct nvc_context *, const struct nvc_container *, const struct nvc_driver_info *);
125127

126128
int nvc_device_mount(struct nvc_context *, const struct nvc_container *, const struct nvc_device *);

src/nvc_info.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <errno.h>
88
#include <limits.h>
9+
#include <nvidia-modprobe-utils.h>
910
#include <stdio.h>
1011
#include <stdlib.h>
1112
#include <string.h>
@@ -788,3 +789,29 @@ nvc_device_info_free(struct nvc_device_info *info)
788789
free(info->gpus);
789790
free(info);
790791
}
792+
793+
int
794+
nvc_nvcaps_device_from_proc_path(struct nvc_context *ctx, const char *cap_path, struct nvc_device_node *node)
795+
{
796+
char abs_cap_path[PATH_MAX];
797+
char dev_name[PATH_MAX];
798+
int major, minor;
799+
int rv = -1;
800+
801+
if (path_join(&ctx->err, abs_cap_path, ctx->cfg.root, cap_path) < 0)
802+
goto fail;
803+
804+
if (nvidia_cap_get_device_file_attrs(abs_cap_path, &major, &minor, dev_name) == 0) {
805+
error_set(&ctx->err, "unable to get cap device attributes: %s", cap_path);
806+
goto fail;
807+
}
808+
809+
if ((node->path = xstrdup(&ctx->err, dev_name)) == NULL)
810+
goto fail;
811+
node->id = makedev((unsigned int)major, (unsigned int)minor);
812+
813+
rv = 0;
814+
815+
fail:
816+
return (rv);
817+
}

src/nvc_mount.c

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static int symlink_libraries(struct error *, const struct nvc_container *, cons
4040
static void filter_libraries(const struct nvc_driver_info *, char * [], size_t *);
4141
static int device_mount_dxcore(struct nvc_context *, const struct nvc_container *);
4242
static int device_mount_native(struct nvc_context *, const struct nvc_container *, const struct nvc_device *);
43-
static int cap_device_from_path(struct nvc_context *, const char *, struct nvc_device_node *);
4443
static int cap_device_mount(struct nvc_context *, const struct nvc_container *, const char *);
4544
static int setup_mig_minor_cgroups(struct error *, const struct nvc_container *, int, const struct nvc_device_node *);
4645

@@ -643,40 +642,14 @@ device_mount_native(struct nvc_context *ctx, const struct nvc_container *cnt, co
643642
return (rv);
644643
}
645644

646-
static int
647-
cap_device_from_path(struct nvc_context *ctx, const char *cap_path, struct nvc_device_node *node)
648-
{
649-
char abs_cap_path[PATH_MAX];
650-
char dev_name[PATH_MAX];
651-
int major, minor;
652-
int rv = -1;
653-
654-
if (path_join(&ctx->err, abs_cap_path, ctx->cfg.root, cap_path) < 0)
655-
goto fail;
656-
657-
if (nvidia_cap_get_device_file_attrs(abs_cap_path, &major, &minor, dev_name) == 0) {
658-
error_set(&ctx->err, "unable to get cap device attributes: %s", cap_path);
659-
goto fail;
660-
}
661-
662-
if ((node->path = xstrdup(&ctx->err, dev_name)) == NULL)
663-
goto fail;
664-
node->id = makedev((unsigned int)major, (unsigned int)minor);
665-
666-
rv = 0;
667-
668-
fail:
669-
return (rv);
670-
}
671-
672645
static int
673646
cap_device_mount(struct nvc_context *ctx, const struct nvc_container *cnt, const char *cap_path)
674647
{
675648
char *dev_mnt = NULL;
676649
struct nvc_device_node node = {0};
677650
int rv = -1;
678651

679-
if (cap_device_from_path(ctx, cap_path, &node) < 0)
652+
if (nvc_nvcaps_device_from_proc_path(ctx, cap_path, &node) < 0)
680653
goto fail;
681654

682655
if (!(cnt->flags & OPT_NO_DEVBIND)) {
@@ -978,7 +951,7 @@ nvc_mig_config_global_caps_mount(struct nvc_context *ctx, const struct nvc_conta
978951
if ((dev_mnt = mount_directory(&ctx->err, ctx->cfg.root, cnt, NV_CAPS_DEVICE_DIR)) == NULL)
979952
goto fail;
980953

981-
if (cap_device_from_path(ctx, config, &node) < 0)
954+
if (nvc_nvcaps_device_from_proc_path(ctx, config, &node) < 0)
982955
goto fail;
983956

984957
if (!(cnt->flags & OPT_NO_CGROUPS))
@@ -1041,7 +1014,7 @@ nvc_mig_monitor_global_caps_mount(struct nvc_context *ctx, const struct nvc_cont
10411014
if ((dev_mnt = mount_directory(&ctx->err, ctx->cfg.root, cnt, NV_CAPS_DEVICE_DIR)) == NULL)
10421015
goto fail;
10431016

1044-
if (cap_device_from_path(ctx, monitor, &node) < 0)
1017+
if (nvc_nvcaps_device_from_proc_path(ctx, monitor, &node) < 0)
10451018
goto fail;
10461019

10471020
if (!(cnt->flags & OPT_NO_CGROUPS))

0 commit comments

Comments
 (0)