You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "slavkap (via GitHub)" <gi...@apache.org> on 2026/09/29 13:22:42 UTC
[PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
slavkap opened a new pull request, #14266:
URL: https://github.com/apache/cloudstack/pull/14266
### Description
#### Problem
Restoring a single volume from backup and hot-attaching it to a running KVM VM (`restoreVolumeFromBackupAndAttachToVM`) fails, regardless of the volume's storage type (NFS, StorPool, RBD, LINSTOR).
####Root cause
`getDeviceToAttachDisk()` picks the target device name via:
` virsh domblklist --domain <vm> | tail -n 3 | head -n 1 | awk '{print $1}'`
This returns the third-from-last line, not the last one — it "works" only by coincidence. Every CloudStack KVM VM has two pre-allocated, empty CD-ROM drives (`hdc`, `hdd`, added by #13101) that sort alphabetically ahead of the real (virtio) disks, so the pipeline picks up a CD-ROM (or an already-attached disk, depending on disk count) instead of computing a truly free name. `virsh attach-disk` then rejects the bogus/duplicate target.
#### Fix
Add `--details` to `domblklist` and filter to `Type == "disk"` rows before picking the last one, so CD-ROMs are never selected.
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] Build/CI
- [ ] Test (unit or integration test code)
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [X] Major
- [ ] Minor
- [ ] Trivial
### Screenshots (if appropriate):
### How Has This Been Tested?
Manually tested with NFS and StorPool as a primary storage
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4280691461
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,19 +431,24 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
- // The commands are executed without a shell, so the awk program must be passed as a plain
- // argument. Keeping the quotes a shell would have stripped makes awk fail with
- // "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
+ // Only virtio (vd*) targets are used: IDE/SATA disks cannot be hot-plugged.
+ String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "$2==\"disk\" && $3 ~ /^vd/ {print $3}" };
+ String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "1" };
+ Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, awkCmd, tailCmd), 0);
Review Comment:
Spawning a separate `tail` process is avoidable here; you can have awk print only the last matching target (e.g., store `$3` per match and print it in an `END` block). This reduces process overhead and simplifies the pipeline while keeping the same behavior.
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,19 +431,24 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
- // The commands are executed without a shell, so the awk program must be passed as a plain
- // argument. Keeping the quotes a shell would have stripped makes awk fail with
- // "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
Review Comment:
The comment about CD-ROM entries being “listed after the virtio disks” appears inconsistent with the PR description (CD-ROM targets like `hdc`/`hdd` sort alphabetically ahead of `vd*`). This is misleading for future maintainers; please update the comment to describe the actual ordering issue (or avoid stating an ordering guarantee and focus on “filter out cdrom rows” as the core requirement).
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,19 +431,24 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
- // The commands are executed without a shell, so the awk program must be passed as a plain
- // argument. Keeping the quotes a shell would have stripped makes awk fail with
- // "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
+ // Only virtio (vd*) targets are used: IDE/SATA disks cannot be hot-plugged.
+ String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "$2==\"disk\" && $3 ~ /^vd/ {print $3}" };
+ String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "1" };
+ Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, awkCmd, tailCmd), 0);
+ if (result.first() == null || result.first() != 0) {
+ throw new CloudRuntimeException(String.format("Failed to determine the device to attach the restored volume to on VM [%s].", vmName));
+ }
// executePipedCommands appends a line separator to every line it reads, so the device
// name has to be trimmed before the last character can be incremented.
String currentDevice = result.second() == null ? "" : result.second().trim();
- if (result.first() == null || result.first() != 0 || StringUtils.isBlank(currentDevice)) {
- throw new CloudRuntimeException(String.format("Failed to determine the device to attach the restored volume to on VM [%s].", vmName));
+ if (StringUtils.isBlank(currentDevice)) {
+ // The VM has no virtio disk yet (e.g. only an IDE or SCSI root disk), so vda is free.
+ return "vda";
}
char lastChar = currentDevice.charAt(currentDevice.length() - 1);
char incrementedChar = (char) (lastChar + 1);
Review Comment:
Incrementing only the last character of the target breaks for boundary cases like `vdz` (would become `{`) and doesn’t handle multi-letter suffixes (`vdaa`, etc.). It can also skip free names if there are gaps (e.g., existing `vda` and `vdc` will choose `vdd` even though `vdb` is free). A more robust approach is to parse all existing `vd*` targets into a set and then pick the first free name from `vda` upward (including rollover past `vdz`), rather than incrementing the last character.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Damans227 (via GitHub)" <gi...@apache.org>.
Damans227 commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4282490037
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,17 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
// The commands are executed without a shell, so the awk program must be passed as a plain
// argument. Keeping the quotes a shell would have stripped makes awk fail with
// "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "$2==\"disk\"{print $3}" };
Review Comment:
that covers it
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "abh1sar (via GitHub)" <gi...@apache.org>.
abh1sar commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4146965973
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,16 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Type column so cdrom slots (hdc, hdd) can be filtered out — they sort
Review Comment:
The comment here is not right. --details doesn't change the ordering in any way:
```
[root@ref-trl-12455-k-Mr9-abhisar-sinha-kvm1 ~]# virsh domblklist --domain i-2-5-VM --details
Type Device Target Source
----------------------------------------------------------------------------------------------------------
file disk vda /mnt/eaae5267-a60a-369d-a4da-a13db16e3aa2/250bd073-3a2c-4875-9ba0-29bf632801b7
file disk vdb /mnt/eaae5267-a60a-369d-a4da-a13db16e3aa2/6f259e43-74a5-461e-b857-e945bcff7b45
file disk vdc /mnt/eaae5267-a60a-369d-a4da-a13db16e3aa2/bca15b84-3acf-4b1d-8466-3866e563c21f
file cdrom hdc -
file cdrom hdd -
[root@ref-trl-12455-k-Mr9-abhisar-sinha-kvm1 ~]# virsh domblklist --domain i-2-5-VM
Target Source
------------------------------------------------------------------------------------------
vda /mnt/eaae5267-a60a-369d-a4da-a13db16e3aa2/250bd073-3a2c-4875-9ba0-29bf632801b7
vdb /mnt/eaae5267-a60a-369d-a4da-a13db16e3aa2/6f259e43-74a5-461e-b857-e945bcff7b45
vdc /mnt/eaae5267-a60a-369d-a4da-a13db16e3aa2/bca15b84-3acf-4b1d-8466-3866e563c21f
hdc -
hdd -
[root@ref-trl-12455-k-Mr9-abhisar-sinha-kvm1 ~]#
```
--details does add the type Device column (not Type) which `awk $2==\"disk\"` uses to filter by type.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "blueorangutan (via GitHub) via commits" <co...@cloudstack.apache.org>.
blueorangutan commented on PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#issuecomment-6837670769
@RosiKyu a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Damans227 (via GitHub)" <gi...@apache.org>.
Damans227 commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4258588233
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,17 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
// The commands are executed without a shell, so the awk program must be passed as a plain
// argument. Keeping the quotes a shell would have stripped makes awk fail with
// "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "$2==\"disk\"{print $3}" };
Review Comment:
what happens on a vm whose disks use the ide bus? the last disk there can be hdb, so the next name is hdc which is already the cdrom
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "slavkap (via GitHub)" <gi...@apache.org>.
slavkap commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4280566828
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,17 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
// The commands are executed without a shell, so the awk program must be passed as a plain
// argument. Keeping the quotes a shell would have stripped makes awk fail with
// "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "$2==\"disk\"{print $3}" };
Review Comment:
@Damans227, thanks. I reproduced it on a running VM with only an IDE root disk (`hda`, `hdc/hdd` cdroms). It picked `hdb`, and `virsh attach-disk` ... `hdb` failed.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#issuecomment-5891333501
## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/14266?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 3.71%. Comparing base ([`510d0ec`](https://app.codecov.io/gh/apache/cloudstack/commit/510d0ec3785efe3cce65ccd1247682b91f4492d0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`132f351`](https://app.codecov.io/gh/apache/cloudstack/commit/132f351df3037d015f02f9b79f68d0cfbdc605b5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
> :exclamation: There is a different number of reports uploaded between BASE (510d0ec) and HEAD (132f351). Click for more details.
>
> <details><summary>HEAD has 1 upload less than BASE</summary>
>
>| Flag | BASE (510d0ec) | HEAD (132f351) |
>|------|------|------|
>|unittests|1|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #14266 +/- ##
=============================================
- Coverage 19.91% 3.71% -16.21%
=============================================
Files 6373 487 -5886
Lines 577230 41992 -535238
Branches 70696 7942 -62754
=============================================
- Hits 114942 1558 -113384
+ Misses 449722 40208 -409514
+ Partials 12566 226 -12340
```
| [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/14266/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/14266/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `3.71% <ø> (ø)` | |
| [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/14266/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/cloudstack/pull/14266?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "slavkap (via GitHub)" <gi...@apache.org>.
slavkap commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4247665688
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,16 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Type column so cdrom slots (hdc, hdd) can be filtered out — they sort
Review Comment:
Thank you @abh1sar! I think the current comment is more accurate
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "blueorangutan (via GitHub) via commits" <co...@cloudstack.apache.org>.
blueorangutan commented on PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#issuecomment-6839311342
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✖️ suse15. SL-JID 20038
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4134116606
##########
plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java:
##########
@@ -655,10 +655,30 @@ public void testGetDeviceToAttachDiskPassesUnquotedAwkProgram() throws Exception
invokeGetDeviceToAttachDisk("test-vm");
- String[] awkCmd = captured[0].get(captured[0].size() - 1);
+ String[] awkCmd = captured[0].get(1);
// The commands are executed without a shell, so the program must carry no shell quotes.
Assert.assertEquals("awk", awkCmd[0]);
- Assert.assertEquals("{print $1}", awkCmd[1]);
+ Assert.assertEquals("$2==\"disk\"{print $3}", awkCmd[1]);
+ }
+ }
+
+ @Test
+ public void testGetDeviceToAttachDiskFiltersOutCdromEntries() throws Exception {
+ try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) {
+ scriptMock.when(() -> Script.getExecutableAbsolutePath(anyString()))
+ .thenAnswer(invocation -> invocation.getArgument(0));
+ final List<String[]>[] captured = new List[1];
+ scriptMock.when(() -> Script.executePipedCommands(anyList(), anyLong()))
+ .thenAnswer(invocation -> {
+ captured[0] = invocation.getArgument(0);
+ return new Pair<>(0, "vdb" + System.lineSeparator());
+ });
+
+ Assert.assertEquals("vdc", invokeGetDeviceToAttachDisk("test-vm"));
+
+ String[] domblkCmd = captured[0].get(0);
+ Assert.assertTrue("domblklist must request --details so the Type column is available to filter on",
+ Arrays.asList(domblkCmd).contains("--details"));
Review Comment:
This test name suggests it verifies CD-ROM entries are filtered out, but the assertions only check that `--details` was included in the `domblklist` command (the filtering behavior is actually covered by the awk-program assertion in the other test). Either rename this test to reflect what it asserts (e.g., `...RequestsDomblklistDetails`) or extend it to explicitly validate the filtering behavior being applied.
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,15 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Type column so cdrom slots (hdc, hdd) can be filtered out — they sort
+ // after the real disks, so without this the last row is always a cdrom, not a free device.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
Review Comment:
The comment claims CD-ROM slots “sort after the real disks”, but the PR description/root cause states they sort alphabetically ahead of virtio disks. Please align the comment with the actual observed ordering and the real failure mode (i.e., that CD-ROM entries must be excluded from consideration regardless of position) so future readers don’t get a contradictory explanation.
##########
plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java:
##########
@@ -655,10 +655,30 @@ public void testGetDeviceToAttachDiskPassesUnquotedAwkProgram() throws Exception
invokeGetDeviceToAttachDisk("test-vm");
- String[] awkCmd = captured[0].get(captured[0].size() - 1);
+ String[] awkCmd = captured[0].get(1);
// The commands are executed without a shell, so the program must carry no shell quotes.
Assert.assertEquals("awk", awkCmd[0]);
- Assert.assertEquals("{print $1}", awkCmd[1]);
+ Assert.assertEquals("$2==\"disk\"{print $3}", awkCmd[1]);
+ }
+ }
+
+ @Test
+ public void testGetDeviceToAttachDiskFiltersOutCdromEntries() throws Exception {
+ try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) {
+ scriptMock.when(() -> Script.getExecutableAbsolutePath(anyString()))
+ .thenAnswer(invocation -> invocation.getArgument(0));
+ final List<String[]>[] captured = new List[1];
Review Comment:
Using an array-of-generic (`new List[1]`) as a mutable holder is not type-safe and typically triggers unchecked warnings. Consider replacing it with an `AtomicReference<List<String[]>>` (or similar typed holder) to avoid compiler warnings and make the intent clearer.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4281746334
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,23 +433,30 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
- // The commands are executed without a shell, so the awk program must be passed as a plain
- // argument. Keeping the quotes a shell would have stripped makes awk fail with
- // "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
- // executePipedCommands appends a line separator to every line it reads, so the device
- // name has to be trimmed before the last character can be incremented.
- String currentDevice = result.second() == null ? "" : result.second().trim();
- if (result.first() == null || result.first() != 0 || StringUtils.isBlank(currentDevice)) {
- throw new CloudRuntimeException(String.format("Failed to determine the device to attach the restored volume to on VM [%s].", vmName));
+ // virsh runs on its own so its exit code is checked; behind a pipe only the last command's is.
+ // --details adds the Device column (disk/cdrom) used below to skip the cdrom slots.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
+ Pair<Integer, String> result = Script.executePipedCommands(Collections.singletonList(domblkCmd), 0);
+ if (result.first() == null || result.first() != 0 || result.second() == null) {
+ throw new CloudRuntimeException(String.format("Failed to list the disks of VM [%s] to determine the device to attach the restored volume to.", vmName));
}
- char lastChar = currentDevice.charAt(currentDevice.length() - 1);
- char incrementedChar = (char) (lastChar + 1);
- return currentDevice.substring(0, currentDevice.length() - 1) + incrementedChar;
+ // Rows are "<Type> <Device> <Target> <Source>". Only virtio (vd*) targets are collected: IDE/SATA
+ // disks cannot be hot-plugged. domblklist follows the domain XML order, where hot-plugged disks
+ // are appended, so the last target is not necessarily the highest one; pick the first free name.
+ Set<String> usedDevices = new HashSet<>();
+ for (String line : result.second().split("\\R")) {
+ String[] columns = line.trim().split("\\s+");
+ if (columns.length >= 3 && "disk".equals(columns[1]) && columns[2].startsWith("vd")) {
+ usedDevices.add(columns[2]);
+ }
+ }
+ for (char c = 'a'; c <= 'z'; c++) {
+ String device = "vd" + c;
+ if (!usedDevices.contains(device)) {
+ return device;
+ }
+ }
+ throw new CloudRuntimeException(String.format("No free virtio device is left to attach the restored volume to on VM [%s].", vmName));
Review Comment:
This limits attachable virtio targets to vda–vdz. Libvirt/QEMU device naming continues with multi-letter suffixes (e.g., vdaa, vdab, ...), so VMs with >26 virtio disks would incorrectly fail to attach. Consider generating `vd` names with a base-26 suffix (a..z, aa..az, ...) and scanning for the first unused value, or converting existing suffixes to an index and iterating indices until a free one is found.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4247806633
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,17 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Device column (disk/cdrom) that the awk below filters on ($2=="disk")
+ // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after the virtio disks in
+ // domblklist's output, so without this filter, taking the last line would select a
+ // cdrom, not the actual disk.
Review Comment:
These lines conflict with the PR description, which states CD-ROM targets sort alphabetically ahead of virtio disks. To keep the rationale consistent and avoid encoding a potentially incorrect ordering assumption, consider rewording to focus on the core issue (CD-ROM rows may appear in the output, and must be excluded via `--details` + filtering) without claiming a specific ordering.
##########
plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java:
##########
@@ -655,10 +656,33 @@ public void testGetDeviceToAttachDiskPassesUnquotedAwkProgram() throws Exception
invokeGetDeviceToAttachDisk("test-vm");
- String[] awkCmd = captured[0].get(captured[0].size() - 1);
+ String[] awkCmd = captured[0].get(1);
// The commands are executed without a shell, so the program must carry no shell quotes.
Assert.assertEquals("awk", awkCmd[0]);
- Assert.assertEquals("{print $1}", awkCmd[1]);
+ Assert.assertEquals("$2==\"disk\"{print $3}", awkCmd[1]);
+ }
+ }
+
+ @Test
+ public void testGetDeviceToAttachDiskRequestsDomblklistDetails() throws Exception {
+ try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) {
+ scriptMock.when(() -> Script.getExecutableAbsolutePath(anyString()))
+ .thenAnswer(invocation -> invocation.getArgument(0));
+ final AtomicReference<List<String[]>> captured = new AtomicReference<>();
+ scriptMock.when(() -> Script.executePipedCommands(anyList(), anyLong()))
+ .thenAnswer(invocation -> {
+ captured.set(invocation.getArgument(0));
+ return new Pair<>(0, "vdb" + System.lineSeparator());
+ });
+
+ Assert.assertEquals("vdc", invokeGetDeviceToAttachDisk("test-vm"));
+
+ // --details adds the Type column the awk program filters on (verified separately in
+ // testGetDeviceToAttachDiskPassesUnquotedAwkProgram); without it cdrom rows can't be
+ // told apart from real disks at all.
+ String[] domblkCmd = captured.get().get(0);
+ Assert.assertTrue("domblklist must request --details so the Type column is available to filter on",
Review Comment:
This comment is inaccurate: the awk filter in the corresponding production code checks `$2==\"disk\"`, which refers to the `Device` column (disk/cdrom), not the `Type` column. Please update the comment to refer to the correct column to avoid misleading future maintainers.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4135425545
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,16 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Type column so cdrom slots (hdc, hdd) can be filtered out — they sort
+ // alphabetically ahead of virtio disks, so without this the selected row is a cdrom, not
+ // an actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
Review Comment:
`virsh domblklist --details` exposes a **Type** column, but the awk filter is currently checking `$2=="disk"`. With the standard `--details` output (`Type Device Target Source`), `Type` is `$1`, so this filter will never match and can yield empty output (breaking device selection). Update the awk program to filter on the correct field (Type) and keep printing the Target field.
##########
plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java:
##########
@@ -655,10 +656,33 @@ public void testGetDeviceToAttachDiskPassesUnquotedAwkProgram() throws Exception
invokeGetDeviceToAttachDisk("test-vm");
- String[] awkCmd = captured[0].get(captured[0].size() - 1);
+ String[] awkCmd = captured[0].get(1);
// The commands are executed without a shell, so the program must carry no shell quotes.
Assert.assertEquals("awk", awkCmd[0]);
- Assert.assertEquals("{print $1}", awkCmd[1]);
+ Assert.assertEquals("$2==\"disk\"{print $3}", awkCmd[1]);
Review Comment:
This test locks in the same incorrect awk field index as the production code. Once the awk program is corrected to filter on the actual `Type` column from `domblklist --details`, update the assertion accordingly so the test validates the intended behavior (filtering by `Type == "disk"`).
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,16 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager storagePoolMgr, String
}
private String getDeviceToAttachDisk(String vmName) {
- String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
- String[] tailCmd = new String[] { Script.getExecutableAbsolutePath("tail"), "-n", "3" };
- String[] headCmd = new String[] { Script.getExecutableAbsolutePath("head"), "-n", "1" };
+ // --details adds a Type column so cdrom slots (hdc, hdd) can be filtered out — they sort
+ // alphabetically ahead of virtio disks, so without this the selected row is a cdrom, not
+ // an actual disk.
+ String[] domblkCmd = new String[] { Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, "--details" };
// The commands are executed without a shell, so the awk program must be passed as a plain
// argument. Keeping the quotes a shell would have stripped makes awk fail with
// "invalid char" and produce no output.
- String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "{print $1}" };
- Pair<Integer, String> result = Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 0);
+ String[] awkCmd = new String[] { Script.getExecutableAbsolutePath("awk"), "$2==\"disk\"{print $3}" };
Review Comment:
`virsh domblklist --details` exposes a **Type** column, but the awk filter is currently checking `$2=="disk"`. With the standard `--details` output (`Type Device Target Source`), `Type` is `$1`, so this filter will never match and can yield empty output (breaking device selection). Update the awk program to filter on the correct field (Type) and keep printing the Target field.
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "Damans227 (via GitHub)" <gi...@apache.org>.
Damans227 commented on PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#issuecomment-6191437393
thanks @slavkap, picking the first free virtio slot fixes the ide case. LGTM
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] kvm: fix restore-attach picking a CD-ROM slot as the target device (NAS backup) [cloudstack]
Posted by "RosiKyu (via GitHub) via commits" <co...@cloudstack.apache.org>.
RosiKyu commented on PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#issuecomment-6837659977
@blueorangutan package
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org