Skip to content

fix: correctly handle NFS metalink templates - mount export dir, compute real file size - #13934

Open
waterWang wants to merge 2 commits into
apache:mainfrom
waterWang:fix-nfs-metalink-template-size
Open

fix: correctly handle NFS metalink templates - mount export dir, compute real file size#13934
waterWang wants to merge 2 commits into
apache:mainfrom
waterWang:fix-nfs-metalink-template-size

Conversation

@waterWang

@waterWang waterWang commented Aug 20, 2026

Copy link
Copy Markdown

Fixes #13916
Fixes #13917

Description

Fixes two related bugs in NFS direct download for metalink templates:

Bug 1: Template size is incorrect (#13916)

NfsDirectTemplateDownloader.getRemoteFileSize() returned null unconditionally, so the template size was never computed for NFS metalink URLs. This caused the template size to be stored as a garbage value (e.g., 7235435666033759572 bytes ≈ 6580590 TB).

Fix: Implement getRemoteFileSize() in NfsDirectTemplateDownloader:

  • Mount the NFS export directory
  • For qcow2 format: read the virtual size from the qcow2 header using QCOW2Utils.getVirtualSize()
  • For other formats: use File.length()
  • Clean up the mount afterwards

Bug 2: Unable to launch VM with NFS metalink template (#13917)

Two issues in the NFS downloader:

  1. Mount path was wrong: NfsDirectTemplateDownloader.parseUrl() used the full NFS path (including the file name) as the mount source. mount -t nfs host:/export/templates/file.qcow2 tries to mount a file as a filesystem, which fails with exit code 32. The fix splits the URL path into the export directory (mountable) and the file name.

  2. Wrong downloader type in metalink: MetalinkDirectTemplateDownloader.getRemoteFileSize() used the metalink-level downloader (typically HttpDirectTemplateDownloader) to check inner URLs of all types, including NFS URLs. This caused checkUrl() and getRemoteFileSize() to be called on the wrong downloader type. The fix creates the correct downloader per URL type using createDownloaderForMetalinks().

Changes

NfsDirectTemplateDownloader.java:

  • Added fileName field to store the file name extracted from the NFS URL
  • parseUrl(): split the NFS path into export directory (srcPath) and file name (fileName)
  • downloadTemplate(): mount the export directory, copy the file from the correct mount point path
  • getRemoteFileSize(): NEW implementation — mount NFS, read file size, unmount. Supports qcow2 virtual size via QCOW2Utils

MetalinkDirectTemplateDownloader.java:

  • getRemoteFileSize(): use createDownloaderForMetalinks() to create the correct downloader type per inner URL, instead of reusing the outer metalink downloader

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to launch a vm with a template which is direct download template and having nfs metalink Direct download template size is incorrect

1 participant