Skip to content

Commit

Permalink
Merge pull request #286 from elezar/add-no-create-imex-channels-option
Browse files Browse the repository at this point in the history
Add no-create-imex-channels command line option
  • Loading branch information
elezar authored Oct 17, 2024
2 parents 921e2f3 + 1f2ad79 commit 63d366e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
8 changes: 4 additions & 4 deletions mk/Dockerfile.centos
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 && \
Expand Down
10 changes: 5 additions & 5 deletions mk/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions mk/Dockerfile.opensuse-leap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 && \
Expand Down
10 changes: 5 additions & 5 deletions mk/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions src/nvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down

0 comments on commit 63d366e

Please sign in to comment.