Skip to content

Commit 253423c

Browse files
authored
Merge pull request #106 from ROCm/users/powderluv/fix-namespace-wrapper
Fix namespace wrapper mount ordering
2 parents 46a36de + 9f20234 commit 253423c

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

crates/spurd/src/executor.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,28 @@ pub async fn launch_job(
280280
.iter()
281281
.map(|id| {
282282
format!(
283-
"if [ -e /host_dev/dri/renderD{r} ]; then\n touch /dev/dri/renderD{r}\n mount --bind /host_dev/dri/renderD{r} /dev/dri/renderD{r}\nfi\n",
283+
" if [ -e $SPUR_HOST_DRI/renderD{r} ]; then\n cp -a $SPUR_HOST_DRI/renderD{r} /dev/dri/renderD{r} 2>/dev/null || true\n fi\n",
284284
r = 128 + id,
285285
)
286286
})
287287
.collect::<Vec<_>>()
288288
.join("");
289289

290290
let wrapper = format!(
291-
"#!/bin/bash\nset -e\nmount -t proc proc /proc 2>/dev/null || true\nmount -t tmpfs tmpfs /tmp 2>/dev/null || true\nmount -t tmpfs tmpfs /dev/shm 2>/dev/null || true\nif [ -d /dev/dri ]; then\n mkdir -p /host_dev/dri\n mount --bind /dev/dri /host_dev/dri 2>/dev/null || true\n mount -t tmpfs tmpfs /dev/dri 2>/dev/null || true\n mkdir -p /dev/dri\n{gpu_mounts}fi\nexec /bin/bash {script}\n",
291+
concat!(
292+
"#!/bin/bash\n",
293+
"# Namespace isolation wrapper — all mounts best-effort\n",
294+
"mount -t proc proc /proc 2>/dev/null || true\n",
295+
"mount -t tmpfs tmpfs /dev/shm 2>/dev/null || true\n",
296+
"# GPU device restriction: save original /dev/dri, replace with\n",
297+
"# tmpfs, then selectively copy only allocated devices back.\n",
298+
"SPUR_HOST_DRI=$(mktemp -d /tmp/.spur_dri_XXXXXX 2>/dev/null || echo /tmp/.spur_dri)\n",
299+
"if [ -d /dev/dri ] && cp -a /dev/dri/. $SPUR_HOST_DRI/ 2>/dev/null; then\n",
300+
" mount -t tmpfs tmpfs /dev/dri 2>/dev/null || true\n",
301+
"{gpu_mounts}",
302+
"fi\n",
303+
"exec /bin/bash {script}\n",
304+
),
292305
gpu_mounts = gpu_mounts,
293306
script = script_path.display(),
294307
);

0 commit comments

Comments
 (0)