Skip to content

Commit

Permalink
fix(encrypt): close encrypted volume if it is opened
Browse files Browse the repository at this point in the history
In normal process of attaching a volume via CSI, the encrypted volume
should be in closed or inactivated state before Longhorn attempts to
open it.

ref: longhorn/longhorn 9385

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz committed Sep 4, 2024
1 parent 1cd29fd commit 2c50b01
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions csi/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ func EncryptVolume(devicePath, passphrase string, cryptoParams *EncryptParams) e
// OpenVolume opens volume so that it can be used by the client.
func OpenVolume(volume, devicePath, passphrase string) error {
if isOpen, _ := IsDeviceOpen(VolumeMapper(volume)); isOpen {
logrus.Infof("Device %s is already opened at %s", devicePath, VolumeMapper(volume))
return nil
logrus.Infof("Device %s is already opened at %s, and close it first", devicePath, VolumeMapper(volume))
if err := CloseVolume(volume); err != nil {
return err
}
}

namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceIpc}
Expand Down

0 comments on commit 2c50b01

Please sign in to comment.