diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java
index f37ae3d2a3c4..bd53aabde4ce 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java
@@ -27,19 +27,26 @@
import org.libvirt.LibvirtException;
import java.io.File;
+import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class IscsiStorageCleanupMonitor implements Runnable{
- protected Logger logger = LogManager.getLogger(getClass());
+ protected static final Logger LOGGER = LogManager.getLogger(IscsiStorageCleanupMonitor.class);
+ protected Logger logger = LOGGER;
private static final int CLEANUP_INTERVAL_SEC = 60; // check every X seconds
- private static final String ISCSI_PATH_PREFIX = "/dev/disk/by-path";
- private static final String KEYWORD_ISCSI = "iscsi";
- private static final String KEYWORD_IQN = "iqn";
- private static final String REGEX_PART = "\\S+part\\d+$";
+ static final String ISCSI_PATH_PREFIX = "/dev/disk/by-path";
+ static final String KEYWORD_ISCSI = "iscsi";
+ static final String KEYWORD_IQN = "iqn";
+ static final String REGEX_PART = "\\S+part\\d+$";
+ static final String DEV_PREFIX = "/dev";
+ static final String LUN_MARKER = "-lun-";
private IscsiAdmStorageAdaptor iscsiStorageAdaptor;
@@ -51,6 +58,68 @@ public IscsiStorageCleanupMonitor() {
iscsiStorageAdaptor = new IscsiAdmStorageAdaptor();
}
+ /**
+ * True if {@code path} is an iSCSI by-path symlink for a whole LUN (not a partition entry).
+ * udev creates a sibling {@code -partN} by-path entry for every partition on a LUN; because
+ * {@code iscsiadm --logout} is session-scoped, acting on a partition entry would tear down
+ * the whole LUN's session. The monitor must operate only on whole-disk entries.
+ *
+ * Visible for testing.
+ */
+ static boolean isIscsiDisk(String path) {
+ return path != null
+ && path.startsWith(ISCSI_PATH_PREFIX)
+ && path.contains(KEYWORD_ISCSI)
+ && path.contains(KEYWORD_IQN)
+ && !path.matches(REGEX_PART);
+ }
+
+ /**
+ * Resolves a {@code /dev/disk/by-*} symlink (or any path under {@code /dev}) to its
+ * underlying kernel device absolute path (e.g. {@code /dev/sdb}). Returns {@code null}
+ * when the input is null, the symlink is dangling, the file is missing, or the real
+ * path is not under {@code /dev} (which filters out file-backed VM disks).
+ *
+ * Visible for testing.
+ */
+ static String resolveToKernelDevice(String path) {
+ if (path == null) {
+ return null;
+ }
+ try {
+ Path real = Paths.get(path).toRealPath();
+ if (real.startsWith(DEV_PREFIX)) {
+ return real.toString();
+ }
+ } catch (IOException e) {
+ LOGGER.debug("Could not resolve [{}] to a kernel device: {}", path, e.getMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Returns the target identifier shared by all LUNs of a by-path iSCSI entry — everything up
+ * to the {@code -lun-} suffix (portal + target IQN). Returns {@code null} when {@code path}
+ * is not an iSCSI by-path for a specific LUN.
+ *
+ *
{@code iscsiadm --logout} is session-scoped (keyed on target IQN + portal), so logging
+ * out any one by-path tears down the session for every LUN on the same target. On shared-
+ * target backends (e.g. ONTAP SVMs, where many LUNs map to one IQN) the monitor must
+ * preserve a session whenever another LUN on the same target is still in use by a VM.
+ *
+ *
Visible for testing.
+ */
+ static String extractTargetKey(String path) {
+ if (path == null) {
+ return null;
+ }
+ int idx = path.lastIndexOf(LUN_MARKER);
+ if (idx < 0) {
+ return null;
+ }
+ return path.substring(0, idx);
+ }
+
private class Monitor extends ManagedContextRunnable {
@@ -81,10 +150,6 @@ protected void runInContext() {
}
}
- private boolean isIscsiDisk(String path) {
- return path.startsWith(ISCSI_PATH_PREFIX) && path.contains(KEYWORD_ISCSI) && path.contains(KEYWORD_IQN);
- }
-
/**
* for each volume if the volume is path is of type iscsi, add to diskstatusmap and set status to false.
* @param iscsiVolumes
@@ -92,7 +157,7 @@ private boolean isIscsiDisk(String path) {
private void initializeDiskStatusMap(File[] iscsiVolumes){
diskStatusMap.clear();
for( File v : iscsiVolumes) {
- if (isIscsiDisk(v.getAbsolutePath())) {
+ if (IscsiStorageCleanupMonitor.isIscsiDisk(v.getAbsolutePath())) {
logger.debug("found iscsi disk by cleanup thread, marking inactive: " + v.getAbsolutePath());
diskStatusMap.put(v.getAbsolutePath(), false);
}
@@ -104,6 +169,21 @@ private void initializeDiskStatusMap(File[] iscsiVolumes){
* @param conn
*/
private void updateDiskStatusMapWithInactiveIscsiSessions(Connect conn){
+ // VM XML and diskStatusMap keys can reference the same iSCSI LUN through
+ // different udev symlinks: by-path (ip-...-iscsi-...-lun-N) vs by-id
+ // (wwn-0x... for storage providers that identify LUNs by NAA WWID, such as
+ // ONTAP). A raw string compare misses that match and the session gets
+ // disconnected while VMs are still using it. Resolve both sides to the
+ // underlying kernel block device (e.g. /dev/sdb) so the match works for
+ // any symlink form.
+ Map kernelDeviceToByPath = new HashMap<>();
+ for (String byPath : diskStatusMap.keySet()) {
+ String kernelDevice = IscsiStorageCleanupMonitor.resolveToKernelDevice(byPath);
+ if (kernelDevice != null) {
+ kernelDeviceToByPath.put(kernelDevice, byPath);
+ }
+ }
+
try {
int[] domains = conn.listDomains();
logger.debug(String.format("found %d domains", domains.length));
@@ -116,9 +196,18 @@ private void updateDiskStatusMapWithInactiveIscsiSessions(Connect conn){
//check the volume map. If an entry exists change the status to True
for (final LibvirtVMDef.DiskDef disk : disks) {
- if (diskStatusMap.containsKey(disk.getDiskPath())&&!disk.getDiskPath().matches(REGEX_PART)) {
- diskStatusMap.put(disk.getDiskPath(), true);
- logger.debug("active disk found by cleanup thread" + disk.getDiskPath());
+ final String diskPath = disk.getDiskPath();
+ if (diskPath == null || diskPath.matches(REGEX_PART)) {
+ continue;
+ }
+ String kernelDevice = IscsiStorageCleanupMonitor.resolveToKernelDevice(diskPath);
+ if (kernelDevice == null) {
+ continue;
+ }
+ String byPath = kernelDeviceToByPath.get(kernelDevice);
+ if (byPath != null) {
+ diskStatusMap.put(byPath, true);
+ logger.debug("active disk found by cleanup thread " + diskPath + " -> " + byPath);
}
}
}
@@ -135,12 +224,33 @@ private void updateDiskStatusMapWithInactiveIscsiSessions(Connect conn){
* XXX: It is possible that someone had manually added an iSCSI volume.
* we would not be able to detect that
+ *
+ * {@code iscsiadm --logout} is target-scoped. On shared-target backends (e.g. ONTAP SVMs
+ * that expose many LUNs under one IQN) logging out one inactive LUN would also kill the
+ * session for sibling LUNs still in use by other VMs on this host. Before disconnecting
+ * an inactive by-path entry, confirm no active LUN remains on the same target.
*/
private void disconnectInactiveSessions(){
+ Set activeTargets = new HashSet<>();
+ for (Map.Entry e : diskStatusMap.entrySet()) {
+ if (Boolean.TRUE.equals(e.getValue())) {
+ String targetKey = IscsiStorageCleanupMonitor.extractTargetKey(e.getKey());
+ if (targetKey != null) {
+ activeTargets.add(targetKey);
+ }
+ }
+ }
for (String diskPath : diskStatusMap.keySet()) {
if (!diskStatusMap.get(diskPath)) {
if (Files.exists(Paths.get(diskPath))) {
+ String targetKey = IscsiStorageCleanupMonitor.extractTargetKey(diskPath);
+ if (targetKey != null && activeTargets.contains(targetKey)) {
+ logger.debug("Preserving iSCSI session for inactive LUN [{}]: " +
+ "sibling LUN on target [{}] is still in use by a VM on this host",
+ diskPath, targetKey);
+ continue;
+ }
try {
logger.info("Cleaning up disk " + diskPath);
iscsiStorageAdaptor.disconnectPhysicalDiskByPath(diskPath);
diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitorTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitorTest.java
new file mode 100644
index 000000000000..a7be28a073ce
--- /dev/null
+++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitorTest.java
@@ -0,0 +1,327 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.kvm.storage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Covers the testable seams carved out of {@link IscsiStorageCleanupMonitor}:
+ *
+ * isIscsiDisk — the phase-1 scan filter, including the partition-suffix
+ * exclusion that stops the monitor from passing udev
+ * {@code -partN} symlinks into {@code iscsiadm --logout}
+ * (which is session-scoped and would kill the whole LUN).
+ *
+ * resolveToKernelDevice — the symlink-chain resolution that lets phase 2 match
+ * VM XML paths (by-id form, as used by ONTAP) against the
+ * by-path keys from phase 1 even though their strings
+ * differ. Both forms must resolve to the same kernel
+ * block device under /dev for the match to succeed.
+ *
+ * extractTargetKey — the shared-target guard used by phase 3 to avoid
+ * tearing down a session whose other LUNs are still in
+ * use by VMs on this host. {@code iscsiadm --logout} is
+ * target-scoped (portal + IQN), so for backends that
+ * expose many LUNs under one IQN (e.g. an ONTAP SVM)
+ * the monitor must keep the session when a sibling LUN
+ * is still active.
+ */
+public class IscsiStorageCleanupMonitorTest {
+
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ // A representative path echoed from the field reproduction on cstack58. The IQN,
+ // portal, SVM UUID, and LUN number are preserved verbatim so the test documents
+ // the exact shape the monitor sees in production for ONTAP iSCSI.
+ private static final String ONTAP_WHOLE_DISK =
+ "/dev/disk/by-path/ip-10.196.34.138:3260-iscsi-iqn.1992-08.com.netapp:sn.6dedd379dd0411f18be4005056bd8428:vs.3-lun-0";
+
+ private static final String ONTAP_PART1 = ONTAP_WHOLE_DISK + "-part1";
+
+ // ----------------------------------------------------------------------------
+ // isIscsiDisk
+ // ----------------------------------------------------------------------------
+
+ @Test
+ public void isIscsiDiskAcceptsWholeDiskByPathEntry() {
+ assertTrue("whole-disk iSCSI by-path must be accepted",
+ IscsiStorageCleanupMonitor.isIscsiDisk(ONTAP_WHOLE_DISK));
+ }
+
+ /**
+ * The bug fix. Before the partition filter was added, udev's {@code -part1} sibling
+ * of a whole-LUN by-path entry was passed to {@code IscsiAdmStorageAdaptor
+ * .disconnectPhysicalDiskByPath}. That method parses host/port/IQN/LUN and runs
+ * {@code iscsiadm --logout} against the parent target, which is session-scoped
+ * and tears down every LUN sharing the session. Rejecting partition entries at
+ * scan time prevents the entire class of regression.
+ */
+ @Test
+ public void isIscsiDiskRejectsPartitionByPathEntry() {
+ assertFalse("partition by-path (-part1) must be rejected",
+ IscsiStorageCleanupMonitor.isIscsiDisk(ONTAP_PART1));
+ }
+
+ @Test
+ public void isIscsiDiskRejectsMultiDigitPartitionEntry() {
+ String part15 = ONTAP_WHOLE_DISK + "-part15";
+ assertFalse("multi-digit partition suffix must still match REGEX_PART",
+ IscsiStorageCleanupMonitor.isIscsiDisk(part15));
+ }
+
+ @Test
+ public void isIscsiDiskRejectsByIdPath() {
+ // VM XMLs for ONTAP use by-id form. They should never land in diskStatusMap
+ // (keyed on by-path scans). The by-id match happens later via kernel-device
+ // resolution, not raw path equality.
+ assertFalse("by-id path is not a by-path scan entry",
+ IscsiStorageCleanupMonitor.isIscsiDisk(
+ "/dev/disk/by-id/wwn-0x600a098078304d35503f61316c425743"));
+ }
+
+ @Test
+ public void isIscsiDiskRejectsNonIscsiByPathEntry() {
+ // A SATA disk also has a by-path entry; neither 'iscsi' nor 'iqn' appears in it.
+ assertFalse("non-iscsi by-path (SATA) must be rejected",
+ IscsiStorageCleanupMonitor.isIscsiDisk("/dev/disk/by-path/pci-0000:00:1f.2-ata-1"));
+ }
+
+ @Test
+ public void isIscsiDiskRejectsPathWithoutIqnSubstring() {
+ // Hypothetical malformed entry that contains 'iscsi' but no 'iqn'.
+ assertFalse("iscsi path without iqn must be rejected",
+ IscsiStorageCleanupMonitor.isIscsiDisk(
+ "/dev/disk/by-path/ip-10.196.34.138:3260-iscsi-lun-0"));
+ }
+
+ @Test
+ public void isIscsiDiskRejectsNull() {
+ assertFalse("null must be rejected (defensive)",
+ IscsiStorageCleanupMonitor.isIscsiDisk(null));
+ }
+
+ @Test
+ public void isIscsiDiskRejectsPathOutsideByPathPrefix() {
+ // Even with iscsi/iqn substrings present, only /dev/disk/by-path/... is in scope.
+ assertFalse("paths outside /dev/disk/by-path must be rejected",
+ IscsiStorageCleanupMonitor.isIscsiDisk(
+ "/tmp/by-path/ip-10.196.34.138:3260-iscsi-iqn.test:vol-lun-0"));
+ }
+
+ /**
+ * Documents the field repro directly: 6 ONTAP LUNs × (1 whole-disk entry + 1 partition
+ * entry) = 12 udev symlinks. Only the 6 whole-disk entries should pass the scan filter.
+ * The 6 partition entries are what triggered the bug before the fix.
+ */
+ @Test
+ public void scanFilterSelectsOnlyWholeDiskEntriesForOntapRepro() {
+ String[] scanned = new String[12];
+ for (int lun = 0; lun < 6; lun++) {
+ String base = "/dev/disk/by-path/ip-10.196.34.138:3260-iscsi-iqn.1992-08.com.netapp:sn.6dedd379dd0411f18be4005056bd8428:vs.3-lun-" + lun;
+ scanned[lun * 2] = base;
+ scanned[lun * 2 + 1] = base + "-part1";
+ }
+
+ int accepted = 0;
+ int rejected = 0;
+ for (String path : scanned) {
+ if (IscsiStorageCleanupMonitor.isIscsiDisk(path)) {
+ accepted++;
+ assertFalse("accepted entries must not look like partitions: " + path,
+ path.matches(IscsiStorageCleanupMonitor.REGEX_PART));
+ } else {
+ rejected++;
+ assertTrue("every rejection in this scan must be a partition entry: " + path,
+ path.matches(IscsiStorageCleanupMonitor.REGEX_PART));
+ }
+ }
+ assertEquals("6 whole-disk entries must be accepted", 6, accepted);
+ assertEquals("6 partition entries must be rejected", 6, rejected);
+ }
+
+ // ----------------------------------------------------------------------------
+ // resolveToKernelDevice
+ // ----------------------------------------------------------------------------
+
+ /**
+ * Happy path: a symlink whose target lives under /dev resolves to that target's
+ * absolute path. /dev/null is used because it exists on every Linux host and under
+ * macOS/BSD too, so the test is portable without a Linux-only setup.
+ */
+ @Test
+ public void resolveToKernelDeviceFollowsSymlinkInsideDev() throws IOException {
+ Path link = tempFolder.newFolder().toPath().resolve("fake-by-id");
+ Files.createSymbolicLink(link, Paths.get("/dev/null"));
+
+ assertEquals("/dev/null", IscsiStorageCleanupMonitor.resolveToKernelDevice(link.toString()));
+ }
+
+ /**
+ * A dangling symlink is common during cleanup races (session logged out but udev
+ * hasn't removed the by-path symlink yet). toRealPath throws NoSuchFileException;
+ * the helper must swallow it and return null so the monitor doesn't mistake the
+ * stale entry for an active device.
+ */
+ @Test
+ public void resolveToKernelDeviceReturnsNullForDanglingSymlink() throws IOException {
+ File target = tempFolder.newFile("target");
+ Path link = tempFolder.getRoot().toPath().resolve("dangling-link");
+ Files.createSymbolicLink(link, target.toPath());
+ assertTrue("target removal must succeed to make the link dangle", target.delete());
+
+ assertNull("dangling symlink must resolve to null, not throw",
+ IscsiStorageCleanupMonitor.resolveToKernelDevice(link.toString()));
+ }
+
+ /**
+ * File-backed VM disk: VM XML points at a qcow2 under /var/lib/libvirt/images.
+ * toRealPath succeeds but the real path is not under /dev — the helper must
+ * reject so this disk never collides with a by-path entry's kernel device.
+ */
+ @Test
+ public void resolveToKernelDeviceReturnsNullWhenRealPathNotInDev() throws IOException {
+ File backing = tempFolder.newFile("vm.qcow2");
+
+ assertNull("non-/dev real path must not be considered a kernel device",
+ IscsiStorageCleanupMonitor.resolveToKernelDevice(backing.getAbsolutePath()));
+ }
+
+ @Test
+ public void resolveToKernelDeviceReturnsNullForNullInput() {
+ assertNull(IscsiStorageCleanupMonitor.resolveToKernelDevice(null));
+ }
+
+ @Test
+ public void resolveToKernelDeviceReturnsNullForNonExistentPath() {
+ String absent = tempFolder.getRoot().toPath().resolve("does-not-exist").toString();
+
+ assertNull("non-existent path must return null, not throw",
+ IscsiStorageCleanupMonitor.resolveToKernelDevice(absent));
+ }
+
+ /**
+ * Confirms the invariant that makes the fix's phase-2 index work: two different
+ * symlinks pointing at the same kernel device resolve to the same string. This is
+ * the whole premise behind matching by-path keys to by-id VM disk paths — they
+ * meet at /dev/sdX (or in this test, /dev/null) even though their strings differ.
+ */
+ @Test
+ public void resolveToKernelDeviceConvergesForTwoSymlinksToSameTarget() throws IOException {
+ Path byIdLike = tempFolder.newFolder("by-id-dir").toPath().resolve("wwn-0xDEADBEEF");
+ Path byPathLike = tempFolder.newFolder("by-path-dir").toPath().resolve("ip-...-iscsi-...-lun-0");
+ Files.createSymbolicLink(byIdLike, Paths.get("/dev/null"));
+ Files.createSymbolicLink(byPathLike, Paths.get("/dev/null"));
+
+ String resolvedById = IscsiStorageCleanupMonitor.resolveToKernelDevice(byIdLike.toString());
+ String resolvedByPath = IscsiStorageCleanupMonitor.resolveToKernelDevice(byPathLike.toString());
+
+ assertEquals("by-id form and by-path form must converge at the kernel device",
+ resolvedById, resolvedByPath);
+ assertEquals("/dev/null", resolvedById);
+ }
+
+ // ----------------------------------------------------------------------------
+ // extractTargetKey
+ // ----------------------------------------------------------------------------
+
+ /**
+ * Strips the per-LUN suffix and returns the (portal + IQN) prefix all LUNs of
+ * the same iSCSI target share. This key is what {@code iscsiadm --logout} acts
+ * on; collisions here mean "same session".
+ */
+ @Test
+ public void extractTargetKeyStripsLunSuffix() {
+ String key = IscsiStorageCleanupMonitor.extractTargetKey(ONTAP_WHOLE_DISK);
+ assertEquals(
+ "/dev/disk/by-path/ip-10.196.34.138:3260-iscsi-iqn.1992-08.com.netapp:sn.6dedd379dd0411f18be4005056bd8428:vs.3",
+ key);
+ }
+
+ @Test
+ public void extractTargetKeyReturnsNullForPathWithoutLunMarker() {
+ assertNull(IscsiStorageCleanupMonitor.extractTargetKey(
+ "/dev/disk/by-id/wwn-0x600a098078304d35503f61316c425743"));
+ }
+
+ @Test
+ public void extractTargetKeyReturnsNullForNull() {
+ assertNull(IscsiStorageCleanupMonitor.extractTargetKey(null));
+ }
+
+ /**
+ * Defensive: the key is cut at the LAST {@code -lun-} occurrence, so an iSCSI
+ * target whose IQN itself contained the substring would still yield a usable
+ * key rather than being mangled. Not observed in the wild, but costs nothing.
+ */
+ @Test
+ public void extractTargetKeyUsesLastLunMarkerOccurrence() {
+ String key = IscsiStorageCleanupMonitor.extractTargetKey(
+ "/dev/disk/by-path/ip-10.1.1.1:3260-iscsi-iqn.test:odd-lun-name-lun-7");
+ assertEquals(
+ "/dev/disk/by-path/ip-10.1.1.1:3260-iscsi-iqn.test:odd-lun-name",
+ key);
+ }
+
+ /**
+ * The field scenario the fix is for: all 6 LUNs of one ONTAP SVM share a single
+ * target key, so if any one of them is still in use by a VM the monitor must
+ * preserve the session rather than log out and tear down the sibling LUNs.
+ */
+ @Test
+ public void siblingOntapLunsShareOneTargetKey() {
+ String base = "/dev/disk/by-path/ip-10.196.34.138:3260-iscsi-iqn.1992-08.com.netapp:sn.6dedd379dd0411f18be4005056bd8428:vs.3";
+ String firstKey = null;
+ for (int lun = 0; lun < 6; lun++) {
+ String key = IscsiStorageCleanupMonitor.extractTargetKey(base + "-lun-" + lun);
+ if (firstKey == null) {
+ firstKey = key;
+ }
+ assertEquals("every LUN under one SVM target must collapse to the same key",
+ firstKey, key);
+ }
+ assertEquals("the shared key is portal + IQN, no trailing LUN", base, firstKey);
+ }
+
+ /**
+ * SolidFire / IscsiAdm-style backends give each volume its own target IQN (the
+ * IQN encodes the volume id). Two such by-paths produce distinct keys, so the
+ * shared-target guard is a no-op and behavior for that backend is unchanged.
+ */
+ @Test
+ public void iscsiAdmStyleTargetsAreOneLunEachSoKeysAreDistinct() {
+ String a = IscsiStorageCleanupMonitor.extractTargetKey(
+ "/dev/disk/by-path/ip-192.168.233.10:3260-iscsi-iqn.2012-03.com.test:volume1-lun-0");
+ String b = IscsiStorageCleanupMonitor.extractTargetKey(
+ "/dev/disk/by-path/ip-192.168.233.10:3260-iscsi-iqn.2012-03.com.test:volume2-lun-0");
+
+ assertFalse("per-volume target IQNs must produce distinct keys", a.equals(b));
+ }
+}