Skip to content

Commit 5ffb29b

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 5ffb29b

10 files changed

+108
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
19+
[Service]
20+
Type=oneshot
21+
ExecCondition=/usr/bin/grep -qE '/nvidia.ko' /lib/modules/%v/modules.dep
22+
ExecStart=/usr/bin/nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml
23+
CapabilityBoundingSet=CAP_SYS_MODULE CAP_SYS_ADMIN CAP_MKNOD
24+
25+
[Install]
26+
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}

packaging/debian/control

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ Architecture: any
2929
Depends: ${misc:Depends}, nvidia-container-toolkit-base (= @VERSION@)
3030
Description: NVIDIA Container Toolkit Operator Extensions
3131
Provides tools for using the NVIDIA Container Toolkit with the GPU Operator
32+
33+
Package: nvidia-container-toolkit-cdi-refresh
34+
Architecture: any
35+
Depends: ${misc:Depends}, nvidia-container-toolkit-base (= @VERSION@)
36+
Description: NVIDIA CDI Refresh Service
37+
Provides a service to refresh the NVIDIA CDI specification
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nvidia-cdi-refresh.service /etc/systemd/system/
2+
nvidia-cdi-refresh.path /etc/systemd/system/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
case "$1" in
6+
configure)
7+
if command -v systemctl >/dev/null 2>&1 \
8+
&& systemctl --quiet is-system-running 2>/dev/null; then
9+
10+
systemctl daemon-reload || true
11+
12+
if [ -z "$2" ]; then # $2 empty → first install
13+
systemctl enable --now nvidia-cdi-refresh.path || true
14+
fi
15+
fi
16+
;;
17+
18+
abort-upgrade|abort-remove|abort-deconfigure)
19+
# Nothing to do for these dpkg abort cases
20+
;;
21+
22+
*)
23+
echo "postinst called with unknown argument \`$1'" >&2
24+
exit 1
25+
;;
26+
esac
27+
28+
exit 0

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

Lines changed: 19 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,9 @@ fi
6479
%files
6580
%license LICENSE
6681
%{_bindir}/nvidia-container-runtime-hook
82+
%config /etc/systemd/system/nvidia-cdi-refresh.service
83+
%config /etc/systemd/system/nvidia-cdi-refresh.path
84+
%dir /etc/systemd/system
6785

6886
%changelog
6987
# As of 1.10.0-1 we generate the release information automatically

0 commit comments

Comments
 (0)