From 4ef62526ffb1c215fba04a8ddf90bfe7435ba075 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 30 Sep 2024 15:47:19 +0200 Subject: [PATCH 1/2] [no-relnote] Address Dockerfile lint errors Signed-off-by: Evan Lezar --- mk/Dockerfile.centos | 8 ++++---- mk/Dockerfile.debian | 10 +++++----- mk/Dockerfile.opensuse-leap | 8 ++++---- mk/Dockerfile.ubuntu | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/mk/Dockerfile.centos b/mk/Dockerfile.centos index c2d40948..5ee2f3b3 100644 --- a/mk/Dockerfile.centos +++ b/mk/Dockerfile.centos @@ -43,8 +43,8 @@ ENV OS_ARCH=${OS_ARCH} RUN OS_ARCH=${OS_ARCH/x86_64/amd64} && OS_ARCH=${OS_ARCH/aarch64/arm64} && \ curl https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${OS_ARCH}.tar.gz \ | tar -C /usr/local -xz -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH +ENV GOPATH=/go +ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH ARG WITH_NVCGO=no ARG WITH_LIBELF=yes @@ -75,8 +75,8 @@ ENV LIB_BUILD=${LIB_BUILD} RUN make distclean && make -j"$(nproc)" # Use the revision as the package version for the time being -ENV PKG_NAME libnvidia-container -ENV PKG_VERS ${REVISION} +ENV PKG_NAME=libnvidia-container +ENV PKG_VERS=${REVISION} ENV DIST_DIR=/tmp/${PKG_NAME}-${PKG_VERS} RUN mkdir -p $DIST_DIR /dist CMD make dist && \ diff --git a/mk/Dockerfile.debian b/mk/Dockerfile.debian index daac997d..7536e275 100644 --- a/mk/Dockerfile.debian +++ b/mk/Dockerfile.debian @@ -32,10 +32,10 @@ ENV OS_ARCH=${OS_ARCH} RUN OS_ARCH=${OS_ARCH/x86_64/amd64} && OS_ARCH=${OS_ARCH/aarch64/arm64} && \ curl https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${OS_ARCH}.tar.gz \ | tar -C /usr/local -xz -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH +ENV GOPATH=/go +ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH -ENV GPG_TTY /dev/console +ENV GPG_TTY=/dev/console WORKDIR /tmp/libnvidia-container COPY . . @@ -61,8 +61,8 @@ ENV LIB_BUILD=${LIB_BUILD} RUN make distclean && make -j"$(nproc)" # Use the revision as the package version for the time being -ENV PKG_NAME libnvidia-container -ENV PKG_VERS ${REVISION} +ENV PKG_NAME=libnvidia-container +ENV PKG_VERS=${REVISION} ENV DIST_DIR=/tmp/${PKG_NAME}-${PKG_VERS} RUN mkdir -p $DIST_DIR /dist diff --git a/mk/Dockerfile.opensuse-leap b/mk/Dockerfile.opensuse-leap index 82654386..26e0ddbd 100644 --- a/mk/Dockerfile.opensuse-leap +++ b/mk/Dockerfile.opensuse-leap @@ -29,8 +29,8 @@ ENV OS_ARCH=${OS_ARCH} RUN OS_ARCH=${OS_ARCH/x86_64/amd64} && OS_ARCH=${OS_ARCH/aarch64/arm64} && \ curl https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${OS_ARCH}.tar.gz \ | tar -C /usr/local -xz -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH +ENV GOPATH=/go +ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH ARG WITH_NVCGO=no ARG WITH_LIBELF=no @@ -59,8 +59,8 @@ RUN export META_NOECHO=echo && \ make distclean && make -j"$(nproc)" # Use the revision as the package version for the time being -ENV PKG_NAME libnvidia-container -ENV PKG_VERS ${REVISION} +ENV PKG_NAME=libnvidia-container +ENV PKG_VERS=${REVISION} ENV DIST_DIR=/tmp/${PKG_NAME}-${PKG_VERS} RUN mkdir -p $DIST_DIR /dist CMD make dist && \ diff --git a/mk/Dockerfile.ubuntu b/mk/Dockerfile.ubuntu index c0719df2..2b424edf 100644 --- a/mk/Dockerfile.ubuntu +++ b/mk/Dockerfile.ubuntu @@ -31,10 +31,10 @@ ENV OS_ARCH=${OS_ARCH} RUN OS_ARCH=${OS_ARCH/x86_64/amd64} && OS_ARCH=${OS_ARCH/aarch64/arm64} && \ curl https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${OS_ARCH}.tar.gz \ | tar -C /usr/local -xz -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH +ENV GOPATH=/go +ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH -ENV GPG_TTY /dev/console +ENV GPG_TTY=/dev/console WORKDIR /tmp/libnvidia-container COPY . . @@ -60,8 +60,8 @@ ENV LIB_BUILD=${LIB_BUILD} RUN make distclean && make -j"$(nproc)" # Use the revision as the package version for the time being -ENV PKG_NAME libnvidia-container -ENV PKG_VERS ${REVISION} +ENV PKG_NAME=libnvidia-container +ENV PKG_VERS=${REVISION} ENV DIST_DIR=/tmp/${PKG_NAME}-${PKG_VERS} RUN mkdir -p $DIST_DIR /dist From 1f2ad796e20fd8ac5454aaabda13013c1e48d3e3 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 30 Sep 2024 15:35:20 +0200 Subject: [PATCH 2/2] Add no-create-imex-channels command line option This change adds a no-create-imex-channels command line option to opt-out of the creation of imex channel device nodes. Note that the creation of device nodes is only triggered if --load-kmods is specified. Signed-off-by: Evan Lezar --- src/cli/main.c | 5 +++++ src/nvc.c | 17 ++++++++++------- src/options.h | 4 +++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cli/main.c b/src/cli/main.c index 6347765d..9695d645 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -32,6 +32,7 @@ static struct argp usage = { {"user", 'u', "UID[:GID]", OPTION_ARG_OPTIONAL, "User and group to use for privilege separation", -1}, {"root", 'r', "PATH", 0, "Path to the driver root directory", -1}, {"ldcache", 'l', "FILE", 0, "Path to the system's DSO cache", -1}, + {"no-create-imex-channels", 0x80, NULL, 0, "Don't automatically create IMEX channel device nodes", -1}, {NULL, 0, NULL, 0, "Commands:", 0}, {"info", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "Report information about the driver and devices", 0}, {"list", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "List driver components", 0}, @@ -112,6 +113,10 @@ parser(int key, char *arg, struct argp_state *state) case 'l': ctx->ldcache = arg; break; + case 0x80: + if (str_join(&err, &ctx->init_flags, "no-create-imex-channels", " ") < 0) + goto fatal; + break; case ARGP_KEY_ARGS: state->argv += state->next; state->argc -= state->next; diff --git a/src/nvc.c b/src/nvc.c index 51c81725..54f0d3ac 100644 --- a/src/nvc.c +++ b/src/nvc.c @@ -33,7 +33,7 @@ #include "xfuncs.h" static int init_within_userns(struct error *); -static int load_kernel_modules(struct error *, const char *, const struct nvc_imex_info *); +static int load_kernel_modules(struct error *, const char *, const struct nvc_imex_info *, int32_t); static int copy_config(struct error *, struct nvc_context *, const struct nvc_config *); const char interpreter[] __attribute__((section(".interp"))) = LIB_DIR "/" LD_SO; @@ -229,7 +229,7 @@ mig_nvcaps_mknodes(struct error *err, int num_gpus) { } static int -load_kernel_modules(struct error *err, const char *root, const struct nvc_imex_info *imex) +load_kernel_modules(struct error *err, const char *root, const struct nvc_imex_info *imex, int32_t flags) { int userns; pid_t pid; @@ -290,10 +290,13 @@ load_kernel_modules(struct error *err, const char *root, const struct nvc_imex_i log_info("running mknod for all nvcaps in " NV_CAPS_DEVICE_DIR); if (mig_nvcaps_mknodes(err, devs.num_matches) < 0) log_errf("could not create kernel module device nodes: %s", err->msg); - for (int i = 0; i < (int)imex->nchans; ++i) { - log_infof("running mknod for " NV_CAPS_IMEX_DEVICE_PATH, imex->chans[i].id); - if (nvidia_cap_imex_channel_mknod(imex->chans[i].id) == 0) - log_errf("could not mknod for IMEX channel %d", imex->chans[i].id); + + if (!(flags & OPT_NO_CREATE_IMEX_CHANNELS)) { + for (int i = 0; i < (int)imex->nchans; ++i) { + log_infof("running mknod for " NV_CAPS_IMEX_DEVICE_PATH, imex->chans[i].id); + if (nvidia_cap_imex_channel_mknod(imex->chans[i].id) == 0) + log_errf("could not mknod for IMEX channel %d", imex->chans[i].id); + } } error_reset(err); } @@ -420,7 +423,7 @@ nvc_init(struct nvc_context *ctx, const struct nvc_config *cfg, const char *opts if (flags & OPT_LOAD_KMODS) { if (ctx->dxcore.initialized) log_warn("skipping kernel modules load on WSL"); - else if (load_kernel_modules(&ctx->err, ctx->cfg.root, &ctx->cfg.imex) < 0) + else if (load_kernel_modules(&ctx->err, ctx->cfg.root, &ctx->cfg.imex, flags) < 0) goto fail; } diff --git a/src/options.h b/src/options.h index df5ae5e1..236ccbbb 100644 --- a/src/options.h +++ b/src/options.h @@ -16,11 +16,13 @@ struct option { /* Library options */ enum { - OPT_LOAD_KMODS = 1 << 0, + OPT_LOAD_KMODS = 1 << 0, + OPT_NO_CREATE_IMEX_CHANNELS = 1 << 1, }; static const struct option library_opts[] = { {"load-kmods", OPT_LOAD_KMODS}, + {"no-create-imex-channels", OPT_NO_CREATE_IMEX_CHANNELS} }; static const char * const default_library_opts = "";