waterWang opened a new pull request, #13934:
URL: https://github.com/apache/cloudstack/pull/13934

   ## 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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to