Skip to content

Subsequent VM Creation is failing for ISCSI Storage Pool on Oracle Linux - #88

Open
suryag1201 wants to merge 4 commits into
mainfrom
bugfix/CSTACKEX-233
Open

Subsequent VM Creation is failing for ISCSI Storage Pool on Oracle Linux#88
suryag1201 wants to merge 4 commits into
mainfrom
bugfix/CSTACKEX-233

Conversation

@suryag1201

@suryag1201 suryag1201 commented Aug 7, 2026

Copy link
Copy Markdown

Description

Subsequent VM Creation is failing for ISCSI Storage Pool on Oracle Linux

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • 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)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Tested on both Oracle and Unbuntu and tried creating multiple VMs

How did you try to break this feature and the system with this change?

Copilot AI lite review requested due to automatic review settings August 7, 2026 10:46

Copilot AI 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.

Pull request overview

This PR addresses failures when creating subsequent VMs on iSCSI primary storage with KVM (notably on Oracle Linux) by making iSCSI login/rescan behavior more robust and adding additional readiness checks before proceeding.

Changes:

  • Adds explicit handling for iscsiadm exit codes and a pre-login session existence check to decide when a rescan is needed.
  • Updates iSCSI login result handling to be idempotent across distros (Ubuntu vs Oracle Linux behavior) and triggers rescans when a session pre-exists.
  • Adds extra validation for device readiness and improves by-path filesystem checks before calling blockdev.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings August 11, 2026 18:46

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (2)

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java:177

  • The warning uses volumeUuid as the “target” identifier, but the log message is about the iSCSI target/portal; this can be misleading when troubleshooting. Use the computed IQN (iqn) in the message (and optionally include the volume path separately).
        if (getPhysicalDisk(volumeUuid, pool).getSize() <= 0) {
            logger.warn("iSCSI device not ready for target {} at {}:{} after wait", volumeUuid, host, port);
            return false;

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java:366

  • Files.isRegularFile(devicePath) follows symlinks by default, so a by-path symlink that (incorrectly) points to a regular file will be reported as a “regular file at by-path”, and the subsequent isSymbolicLink check becomes unreachable in that case. Check isSymbolicLink first, or use NOFOLLOW_LINKS to test the path itself.
            if (Files.isRegularFile(devicePath)) {
                logger.warn("Found a corrupt regular file at iSCSI by-path {} (expected block device symlink); it must be removed manually", deviceByPath);
                return 0L;
            }
            if (!Files.isSymbolicLink(devicePath)) {

@github-actions

Copy link
Copy Markdown

🔴 Test Coverage Grade: D — Marginal

Metric Value
Line coverage 24.58%
Branch coverage 18.75%

Grade Scale

Grade Line Coverage Meaning
🟢 A ≥ 80% Excellent - this code sleeps well at night 😴
🟡 B 60-79% Good - almost there, don't stop now 😉
🟠 C 40-59% Acceptable - your code is wearing a seatbelt, but no airbags 😬
🔴 D 20-39% Marginal - boldly shipping where no test has gone before 🖖
⛔ F < 20% Failing - tests? what tests? 🔥

Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run


OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();

sessionCmd.executeIgnoreExitValue(parser, ISCSI_ERR_NO_OBJS_FOUND);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to have this code ISCSI_SESSION_EXISTS_CODE check here itself? Instead of having a separate check in ln 147?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done!


String portal = host + ":" + port;

for (String line : sessions.split("\n")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

as per this method, session is active if you see a any output line containing iqn and portal but we are parsing it using "\n". How are we sure if this parsing will not break on different OS flavour ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Line splitting on "\n" is safe here and not OS-dependent.
isIscsiSessionActive() does not parse raw iscsiadm bytes with native line endings. Output goes through OutputInterpreter.AllLinesParser, which uses BufferedReader.readLine() (handles \n, \r\n, and \r) and then rejoins lines with "\n":

logger.debug("Device by-path does not exist yet: {}", deviceByPath);
return 0L;
}
if (Files.isRegularFile(devicePath)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

how is this change required for ubuntu vs linux ?or is it agnostic to that ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this change is not Ubuntu-vs-Linux/Oracle specific

@github-actions

Copy link
Copy Markdown

🔴 Test Coverage Grade: D — Marginal

Metric Value
Line coverage 24.57%
Branch coverage 18.75%

Grade Scale

Grade Line Coverage Meaning
🟢 A ≥ 80% Excellent - this code sleeps well at night 😴
🟡 B 60-79% Good - almost there, don't stop now 😉
🟠 C 40-59% Acceptable - your code is wearing a seatbelt, but no airbags 😬
🔴 D 20-39% Marginal - boldly shipping where no test has gone before 🖖
⛔ F < 20% Failing - tests? what tests? 🔥

Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run

OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
sessionCmd.executeIgnoreExitValue(parser, ISCSI_ERR_NO_OBJS_FOUND);
int exitValue = sessionCmd.getExitValue();
if (exitValue != 0 && exitValue != ISCSI_ERR_NO_OBJS_FOUND) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We are anyways ignoring ISCSI_ERR_NO_OBJS_FOUND in sessionCmd.executeIgnoreExitValue(parser, ISCSI_ERR_NO_OBJS_FOUND);, so, maybe we can remove this recheck

@suryag1201 suryag1201 Aug 18, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

executeIgnoreExitValue only allows exit 21 in addition to 0 so “no sessions” is not treated as a Script failure.
If we do not put, we will see the exception in the logs if there is no existing session. Please check this bug, i have updated the logs https://jira.ngage.netapp.com/browse/CSTACKEX-233
Above check is required to handle other exits code.

Thread.sleep(timeBetweenTries);
} catch (Exception ex) {
// don't do anything
} catch (InterruptedException ex) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is it important for us to handle an exception due to interruption? Do we get any additional info from this while debugging?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We handle InterruptedException because Thread.sleep() can throw it when the thread is interrupted. In that case we stop waiting and fail the connect immediately, instead of continuing retries until the timeout.

// this method could still return (it should not block indefinitely) (the race condition
// isn't solved here, but made highly unlikely to be a problem).
waitForDiskToBecomeAvailable(volumeUuid, pool);
if (!waitForDiskToBecomeAvailable(volumeUuid, pool)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

They have mentioned in the comment that there could be a race condition between iSCSI login and device discovery. Unfortunately, this change doesn't seem to be fixing the race-condition, rather adding a strict check in waitForDiskToBecomeAvailable for device availability. Please see if this could be modified.

@suryag1201 suryag1201 Aug 18, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The race, login success before the by-path device appears is still addressed by the existing retry loop in waitForDiskToBecomeAvailable, but this can still happen (rare case). Previously, after timeout with size 0, connectPhysicalDisk still returned true. Now it returns false so we don’t treat an unavailable disk as a successful connect and end up creating a raw file.
Also, Will wait for community reply on this change

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.

5 participants