Skip to content

Commit

Permalink
NVMe: Workaround to avoid hanging nvme disconnect
Browse files Browse the repository at this point in the history
With this approach the satellite denies deletion of the initiator if
one of the nvmeVolumes appears in the ouptut of the "mount" command.
  • Loading branch information
ghernadi committed Aug 30, 2019
1 parent 3397d67 commit d70892e
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ public void disconnect(NvmeRscData nvmeRscData) throws StorageException
"NVMe: disconnecting initiator from: " + NVME_SUBSYSTEM_PREFIX + nvmeRscData.getSuffixedResourceName()
);

// workaround to prevent hanging `nvme disconnect`
if (isAnyMounted(nvmeRscData))
{
throw new StorageException("Cannot disconnect mounted nvme-device.");
}

OutputData output = extCmdFactory.create().exec(
"nvme",
"disconnect",
Expand All @@ -366,6 +372,29 @@ public void disconnect(NvmeRscData nvmeRscData) throws StorageException
}
}

private boolean isAnyMounted(NvmeRscData nvmeRscDataRef)
throws ChildProcessTimeoutException, IOException, StorageException
{
boolean mounted = false;
StringBuilder grepArg = new StringBuilder();
for (NvmeVlmData vlm : nvmeRscDataRef.getVlmLayerObjects().values())
{
grepArg.append(vlm.getDevicePath()).append("|");
}
if (grepArg.length() > 0)
{
grepArg.setLength(grepArg.length() - 1);
OutputData output = extCmdFactory.create().exec("/bin/bash", "-c", "mount | grep -Ew " + grepArg);
String outStr = new String(output.stdoutData);
mounted = !outStr.trim().isEmpty();
}
else
{
errorReporter.logTrace("grepArg empty, skipping mount-check");
}
return mounted;
}

/**
* Checks whether the specified subsystem directory exists
*
Expand Down

0 comments on commit d70892e

Please sign in to comment.