Skip to content

fix(vgpu-init): correct source and destination path handling#2018

Open
haitwang-cloud wants to merge 1 commit into
Project-HAMi:masterfrom
haitwang-cloud:fix/vgpu-init-preload-path
Open

fix(vgpu-init): correct source and destination path handling#2018
haitwang-cloud wants to merge 1 commit into
Project-HAMi:masterfrom
haitwang-cloud:fix/vgpu-init-preload-path

Conversation

@haitwang-cloud

@haitwang-cloud haitwang-cloud commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug
What this PR does / why we need it:

When the HAMi vGPU runtime directory is customized away from the default /usr/local/vgpu (for example, changed to /var/lib/hami/vgpu via Helm values), docker/vgpu-init.sh still writes an ld.so.preload whose content points to the old hardcoded path /usr/local/vgpu/libvgpu.so. The dynamic linker fails to preload libvgpu.so at the actual mounted location, and vGPU memory/core isolation is silently not enforced.

Root cause: docker/vgpu-init.sh treats ld.so.preload as a static packaged file and copies it verbatim from /k8s-vgpu/lib/nvidia/ld.so.preload, whose content is hardcoded to /usr/local/vgpu/libvgpu.so. No matter what $DEST_DIR is passed to the script, the resulting preload content never changes.
Which issue(s) this PR fixes:
Fixes # #2017

Special notes for your reviewer:

Does this PR introduce a user-facing change?:
NO

Summary by CodeRabbit

  • Bug Fixes
    • Improved vGPU image setup to handle destination paths more reliably, including cases with trailing slashes or empty paths.
    • Ensured the preload configuration is regenerated at install time so it always points to the correct runtime library location.
    • Prevented packaging of a generated preload pointer file, reducing the chance of incorrect or stale startup behavior.

…init.sh

Signed-off-by: Tim <tim.wang03@sap.com>
@hami-robot hami-robot Bot added kind/bug Something isn't working dco-signoff: yes labels Jul 6, 2026
@hami-robot hami-robot Bot requested a review from chaunceyjiang July 6, 2026 09:09
@hami-robot

hami-robot Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: haitwang-cloud
Once this PR has been reviewed and has the lgtm label, please assign dsfans2014 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot hami-robot Bot requested a review from ouyangluwei163 July 6, 2026 09:09
@hami-robot hami-robot Bot added the size/M label Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The docker/vgpu-init.sh script now normalizes SOURCE_DIR and DEST_DIR by stripping trailing slashes, with a fallback to "/" for an empty DEST_DIR. It skips copying ld.so.preload from the source tree and regenerates it at DEST_DIR pointing to DEST_DIR/libvgpu.so.

Changes

vgpu-init.sh Path Handling Fix

Layer / File(s) Summary
Directory path normalization
docker/vgpu-init.sh
SOURCE_DIR and DEST_DIR are normalized to remove trailing slashes, with DEST_DIR defaulting to "/" when empty.
Copy logic and preload regeneration
docker/vgpu-init.sh
Relative paths are computed from the normalized SOURCE_DIR, ld.so.preload is excluded from source copying, destination paths join via DEST_DIR/relative_path, and ld.so.preload is regenerated at DEST_DIR to point to DEST_DIR/libvgpu.so.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Script as vgpu-init.sh
  participant Source as SOURCE_DIR
  participant Dest as DEST_DIR

  Script->>Source: Traverse files, compute relative_path
  Script->>Script: Skip ld.so.preload from Source
  Script->>Dest: Copy remaining files to DEST_DIR/relative_path
  Script->>Dest: Write ld.so.preload pointing to DEST_DIR/libvgpu.so
Loading

Possibly related issues

Poem

A rabbit hopped through paths anew,
Trimming slashes, one by one, too.
No more preload lost astray,
Now it points the proper way. 🐇
DEST_DIR clean, libvgpu true —
Hooray, the runtime found its cue!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix in vgpu-init.sh: correcting source and destination path handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docker/vgpu-init.sh (1)

31-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Quote the expansion inside the parameter substitution.

${source_file#$SOURCE_DIR/} treats $SOURCE_DIR as a glob pattern. It's harmless today since SOURCE_DIR is a fixed literal path, but quoting is the correct idiom and silences SC2295.

♻️ Proposed fix
-    relative_path="${source_file#$SOURCE_DIR/}"
+    relative_path="${source_file#"$SOURCE_DIR"/}"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/vgpu-init.sh` at line 31, The parameter expansion in the relative_path
assignment should quote the SOURCE_DIR prefix inside the substitution to avoid
treating it as a glob pattern. Update the shell expansion in vgpu-init.sh so the
source_file stripping uses the quoted form of SOURCE_DIR within the parameter
substitution, keeping the existing logic intact while following the correct
shell idiom and silencing SC2295.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docker/vgpu-init.sh`:
- Line 31: The parameter expansion in the relative_path assignment should quote
the SOURCE_DIR prefix inside the substitution to avoid treating it as a glob
pattern. Update the shell expansion in vgpu-init.sh so the source_file stripping
uses the quoted form of SOURCE_DIR within the parameter substitution, keeping
the existing logic intact while following the correct shell idiom and silencing
SC2295.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9cfffe14-e26f-4df9-aed4-34427f6bad95

📥 Commits

Reviewing files that changed from the base of the PR and between 02ac4f0 and 0a33421.

📒 Files selected for processing (1)
  • docker/vgpu-init.sh

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates docker/vgpu-init.sh to dynamically regenerate ld.so.preload at runtime based on the actual DEST_DIR path, rather than copying a static version from the source directory. It also strips trailing slashes from the input destination directory to prevent double slashes during path composition. The review feedback suggests further robust path normalization using tr -s '/' to handle potential duplicate slashes in both the destination directory configuration and the generated ld.so.preload file.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread docker/vgpu-init.sh
Comment on lines +16 to +20
DEST_DIR="${1%/}"

if [ -z "$DEST_DIR" ]; then
DEST_DIR="/"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the path handling extremely robust against any malformed inputs, duplicate slashes, or trailing slashes passed from Helm values, we can normalize the input path using tr -s '/' before stripping the trailing slash.

Suggested change
DEST_DIR="${1%/}"
if [ -z "$DEST_DIR" ]; then
DEST_DIR="/"
fi
DEST_DIR=$(echo "$1" | tr -s '/')
DEST_DIR="${DEST_DIR%/}"
if [ -z "$DEST_DIR" ]; then
DEST_DIR="/"
fi

Comment thread docker/vgpu-init.sh
# libvgpu.so under DEST_DIR. Treating this file as runtime-generated (rather
# than a static packaged asset) is what keeps the preload path aligned with
# whatever runtime directory the chart passes in.
printf '%s/libvgpu.so\n' "$DEST_DIR" > "$DEST_DIR/ld.so.preload"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If DEST_DIR is /, composing the path as "$DEST_DIR/libvgpu.so" will produce a double slash (//libvgpu.so). While the OS kernel generally handles duplicate slashes gracefully, it is much cleaner and more readable to write a fully normalized path to ld.so.preload.

Suggested change
printf '%s/libvgpu.so\n' "$DEST_DIR" > "$DEST_DIR/ld.so.preload"
preload_path=$(echo "${DEST_DIR}/libvgpu.so" | tr -s '/')
printf '%s\n' "$preload_path" > "$DEST_DIR/ld.so.preload"

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 59.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mesutoezdil

mesutoezdil commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

looks good, just 1 thing

fixes # #2017 won't auto-close the issue. should be Fixes #2017

(see on the right side in ui: Development: Successfully merging this pull request may close these issues.
None yet)

@Shouren

Shouren commented Jul 6, 2026

Copy link
Copy Markdown
Member

@haitwang-cloud As the content of ld.so.preload is finally generated by the script, i think we should cleanup the content of ld.so.preload in charts/hami/templates/device-plugin/configmap.yaml to avoid ineffective config changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants