Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ boolean waitForDiskToBecomeAvailable(AddressInfo address, KVMStoragePool pool, l
if (waitTimeInSec < 60) {
waitTimeInSec = 60;
}
KVMPhysicalDisk physicalDisk = null;

// Rescan before checking for the physical disk
int tries = 0;
Expand Down Expand Up @@ -463,13 +462,12 @@ boolean waitForDiskToBecomeAvailable(AddressInfo address, KVMStoragePool pool, l
output.append(" ");
}

physicalDisk = getPhysicalDisk(address, pool);
if (physicalDisk != null && physicalDisk.getSize() > 0) {
// check the device directly, going through getPhysicalDisk would start another connect
if (isConnected(address.getPath()) && getPhysicalDiskSize(address.getPath()) > 0) {
LOGGER.debug("Found the volume using id: " + address.getPath() + " of the storage pool: " + pool.getUuid());
return true;
}

break;
LOGGER.debug("Volume " + address.getPath() + " is not usable yet after discovery - try " + tries);
} else {
LOGGER.warn("Failure discovering LUN via " + connectScript);
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
Expand Down Expand Up @@ -504,15 +502,30 @@ boolean waitForDiskToBecomeAvailable(AddressInfo address, KVMStoragePool pool, l
}

boolean isConnected(String path) {
// run a command to test if this is a binary device at this path
if (!isBlockDevice(path)) {
return false;
}
// A multipath map whose paths have all failed still exists as a block device but cannot be read
if (!hasActivePath(path)) {
LOGGER.warn("Device {} exists but has no active paths, treating it as not connected", path);
return false;
}
return true;
}

boolean isBlockDevice(String path) {
Script blockTest = new Script("/bin/test", LOGGER);
blockTest.add("-b", path);
blockTest.execute();
int rc = blockTest.getExitValue();
if (rc == 0) {
return true;
}
return false;
return blockTest.getExitValue() == 0;
}

boolean hasActivePath(String path) {
Script pathTest = new Script("/bin/bash", LOGGER);
pathTest.add("-c");
pathTest.add(String.format("multipath -ll '%s' 2>/dev/null | grep -q 'active ready'", path));
pathTest.execute();
return pathTest.getExitValue() == 0;
}

long getPhysicalDiskSize(String diskPath) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import com.cloud.utils.script.Script;

public class MultipathSCSIAdapterBaseTest {

private static final String PATH = "/dev/mapper/3624a937049646854b0ae410b00011266";

@BeforeClass
public static void loadAdapterClass() {
// the adapter looks up its helper scripts when the class loads
try (MockedStatic<Script> script = mockStatic(Script.class, Mockito.CALLS_REAL_METHODS)) {
script.when(() -> Script.findScript(anyString(), anyString())).thenReturn("/bin/true");
new FiberChannelAdapter();
}
}

private FiberChannelAdapter adapter(boolean blockDevice, boolean activePath) {
FiberChannelAdapter adapter = spy(new FiberChannelAdapter());
doReturn(blockDevice).when(adapter).isBlockDevice(PATH);
doReturn(activePath).when(adapter).hasActivePath(PATH);
return adapter;
}

@Test
public void isConnectedWhenDeviceHasAnActivePath() {
Assert.assertTrue(adapter(true, true).isConnected(PATH));
}

@Test
public void isNotConnectedWhenMapHasNoActivePaths() {
Assert.assertFalse(adapter(true, false).isConnected(PATH));
}

@Test
public void isNotConnectedWhenDeviceIsMissing() {
FiberChannelAdapter adapter = adapter(false, false);
Assert.assertFalse(adapter.isConnected(PATH));
verify(adapter, never()).hasActivePath(PATH);
}
}
6 changes: 6 additions & 0 deletions scripts/storage/multipath/connectVolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ for fchost in $(ls /sys/class/fc_host | sed -e 's/host//g'); do
fi
done

## a map left behind with no working paths would stop the scan below, so flush it first
if [ -b /dev/mapper/3${WWID} ] && ! multipath -ll 3${WWID} 2>/dev/null | grep -q "active ready"; then
logger -t "CS_SCSI_VOL_FIND" "${WWID} has a multipath map with no active paths, flushing it before scanning"
multipath -f 3${WWID} || logger -t "CS_SCSI_VOL_FIND" "${WWID} stale multipath map could not be flushed, it may be in use"
fi

logger -t "CS_SCSI_VOL_FIND" "${WWID} awaiting disk path at /dev/mapper/3${WWID}"

# wait for multipath to map the new lun to the WWID
Expand Down
Loading