util: fix bug in DeviceEncryptionStatus()

With Luks1 device:
$ cryptsetup status /dev/mapper/crypto-rbd0
/dev/mapper/crypto-rbd0 is active and is in use.
  type:    LUKS1
  cipher:  aes-xts-plain64
  keysize: 512 bits
  key location: dm-crypt
  device:  /dev/rbd0
  sector size:  512
  offset:  4096 sectors
  size:    4190208 sectors
  mode:    read/write

With Luks2 device:
$ cryptsetup status /dev/mapper/crypto-rbd0
/dev/mapper/crypto-rbd0 is active and is in use.
  type:    LUKS2
  cipher:  aes-xts-plain64
  keysize: 512 bits
  key location: dm-crypt
  device:  /dev/rbd0
  sector size:  512
  offset:  32768 sectors
  size:    4161536 sectors
  mode:    read/write

This could lead to failures with unmap in the NodeUnstageVolume path
for the encrypted volumes.

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2021-07-06 12:52:32 +05:30 committed by mergify[bot]
parent 1ae2afe208
commit 812003eb45

View File

@ -294,7 +294,8 @@ func DeviceEncryptionStatus(ctx context.Context, devicePath string) (mappedDevic
if len(lines) < 1 { if len(lines) < 1 {
return "", "", fmt.Errorf("device encryption status returned no stdout for %s", devicePath) return "", "", fmt.Errorf("device encryption status returned no stdout for %s", devicePath)
} }
if !strings.HasSuffix(lines[0], " is active.") { // The line will look like: "/dev/mapper/xxx is active and is in use."
if !strings.Contains(lines[0], " is active") {
// Implies this is not a LUKS device // Implies this is not a LUKS device
return devicePath, "", nil return devicePath, "", nil
} }