Skip to content

Commit e1ab7af

Browse files
Add nvidia-cdi-refresh service
Automatic regeneration of /var/run/cdi/nvidia.yaml New units: • nvidia-cdi-refresh.service – one-shot wrapper for nvidia-ctk cdi generate (adds sleep + required caps). • nvidia-cdi-refresh.path – fires on driver install/upgrade via modules.dep.bin changes. Packaging • RPM %post reloads systemd and enables the path unit on fresh installs. • DEB postinst does the same (configure, skip on upgrade). Result: CDI spec is always up to date Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent ac8f190 commit e1ab7af

9 files changed

+83
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[Unit]
16+
Description=Trigger CDI refresh on NVIDIA driver install / uninstall events
17+
18+
[Path]
19+
PathChanged=/lib/modules/%v/modules.dep
20+
PathChanged=/lib/modules/%v/modules.dep.bin
21+
22+
[Install]
23+
WantedBy=multi-user.target
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[Unit]
16+
Description=Refresh NVIDIA CDI specification file
17+
ConditionPathExists=/usr/bin/nvidia-smi
18+
ConditionPathExists=/usr/bin/nvidia-ctk
19+
20+
[Service]
21+
Type=oneshot
22+
ExecCondition=/usr/bin/grep -qE '/nvidia.ko' /lib/modules/%v/modules.dep
23+
ExecStart=/usr/bin/nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml
24+
CapabilityBoundingSet=CAP_SYS_MODULE CAP_SYS_ADMIN CAP_MKNOD
25+
26+
[Install]
27+
WantedBy=multi-user.target

docker/Dockerfile.debian

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ RUN make PREFIX=${DIST_DIR} cmds
5555

5656
WORKDIR $DIST_DIR
5757
COPY packaging/debian ./debian
58+
COPY deployments/systemd/ .
5859

5960
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
6061
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}

docker/Dockerfile.opensuse-leap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ RUN make PREFIX=${DIST_DIR} cmds
4646

4747
WORKDIR $DIST_DIR/..
4848
COPY packaging/rpm .
49+
COPY deployments/systemd/ .
4950

5051
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
5152
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}

docker/Dockerfile.rpm-yum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ RUN make PREFIX=${DIST_DIR} cmds
7171

7272
WORKDIR $DIST_DIR/..
7373
COPY packaging/rpm .
74+
COPY deployments/systemd/* ${DIST_DIR}/
7475

7576
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
7677
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}

docker/Dockerfile.ubuntu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ RUN make PREFIX=${DIST_DIR} cmds
5353

5454
WORKDIR $DIST_DIR
5555
COPY packaging/debian ./debian
56+
COPY deployments/systemd/ .
5657

5758
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
5859
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
nvidia-container-runtime /usr/bin
22
nvidia-ctk /usr/bin
33
nvidia-cdi-hook /usr/bin
4+
nvidia-cdi-refresh.service /etc/systemd/system/
5+
nvidia-cdi-refresh.path /etc/systemd/system/

packaging/debian/nvidia-container-toolkit-base.postinst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ set -e
55
case "$1" in
66
configure)
77
/usr/bin/nvidia-ctk --quiet config --config-file=/etc/nvidia-container-runtime/config.toml --in-place
8+
9+
if command -v systemctl >/dev/null 2>&1 \
10+
&& systemctl --quiet is-system-running 2>/dev/null; then
11+
12+
systemctl daemon-reload || true
13+
14+
if [ -z "$2" ]; then # $2 empty → first install
15+
systemctl enable --now nvidia-cdi-refresh.path || true
16+
fi
17+
fi
818
;;
919

1020
abort-upgrade|abort-remove|abort-deconfigure)

packaging/rpm/SPECS/nvidia-container-toolkit.spec

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Source3: nvidia-container-runtime
1717
Source4: nvidia-container-runtime.cdi
1818
Source5: nvidia-container-runtime.legacy
1919
Source6: nvidia-cdi-hook
20+
Source7: nvidia-cdi-refresh.service
21+
Source8: nvidia-cdi-refresh.path
2022

2123
Obsoletes: nvidia-container-runtime <= 3.5.0-1, nvidia-container-runtime-hook <= 1.4.0-2
2224
Provides: nvidia-container-runtime
@@ -28,23 +30,36 @@ Requires: nvidia-container-toolkit-base == %{version}-%{release}
2830
Provides tools and utilities to enable GPU support in containers.
2931

3032
%prep
31-
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} .
33+
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} %{SOURCE7} %{SOURCE8} .
3234

3335
%install
3436
mkdir -p %{buildroot}%{_bindir}
37+
mkdir -p %{buildroot}/etc/systemd/system/
38+
mkdir -p %{buildroot}/etc/udev/rules.d
39+
3540
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime-hook
3641
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime
3742
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime.cdi
3843
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime.legacy
3944
install -m 755 -t %{buildroot}%{_bindir} nvidia-ctk
4045
install -m 755 -t %{buildroot}%{_bindir} nvidia-cdi-hook
46+
install -m 644 -t %{buildroot}/etc/systemd/system %{SOURCE7}
47+
install -m 644 -t %{buildroot}/etc/systemd/system %{SOURCE8}
4148

4249
%post
4350
if [ $1 -gt 1 ]; then # only on package upgrade
4451
mkdir -p %{_localstatedir}/lib/rpm-state/nvidia-container-toolkit
4552
cp -af %{_bindir}/nvidia-container-runtime-hook %{_localstatedir}/lib/rpm-state/nvidia-container-toolkit
4653
fi
4754

55+
# Reload systemd unit cache
56+
/bin/systemctl daemon-reload || :
57+
58+
# On fresh install ($1 == 1) enable the path unit so it starts at boot
59+
if [ "$1" -eq 1 ]; then
60+
/bin/systemctl enable --now nvidia-cdi-refresh.path || :
61+
fi
62+
4863
%posttrans
4964
if [ ! -e %{_bindir}/nvidia-container-runtime-hook ]; then
5065
# repairing lost file nvidia-container-runtime-hook
@@ -64,6 +79,7 @@ fi
6479
%files
6580
%license LICENSE
6681
%{_bindir}/nvidia-container-runtime-hook
82+
%dir /etc/systemd/system
6783

6884
%changelog
6985
# As of 1.10.0-1 we generate the release information automatically

0 commit comments

Comments
 (0)