From 52d3ebbc0dc3c5991c154c70b29b120a6ad3571e Mon Sep 17 00:00:00 2001 From: Matthew Cary Date: Wed, 24 Apr 2024 11:24:02 -0700 Subject: [PATCH] Remove device disable call --- pkg/deviceutils/device-utils_linux.go | 9 ++++++++- pkg/gce-pd-csi-driver/node.go | 4 ---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/deviceutils/device-utils_linux.go b/pkg/deviceutils/device-utils_linux.go index f480359a7..df20b569e 100644 --- a/pkg/deviceutils/device-utils_linux.go +++ b/pkg/deviceutils/device-utils_linux.go @@ -24,9 +24,16 @@ import ( "k8s.io/mount-utils" ) +// DisableDevice asks the kernel to disable a device via /sys. +// NB: this can be dangerous to use. Once a device is disabled, it's unusable, and can't be enabled +// unless the serial number is known. But the serial number cannot be read from the device as it's +// disabled. If a device is disabled in NodeUnstage, and then NodeStage is called without a +// NodeUnpublish & publish sequence, the disabled state of the device will cause NodeStage to fail. +// So this can only be used if we track the serial numbers of disabled devices in a persisent way +// that survives driver restarts. func (_ *deviceUtils) DisableDevice(devicePath string) error { deviceName := filepath.Base(devicePath) - return os.WriteFile(fmt.Sprintf("/sys/block/%s/device/state", deviceName), []byte("offline"), 0644) + return os.WriteFile(fmt.Sprintf("/sys/block/%s/device/state", deviceName), []byte("offline\n"), 0644) } func (_ *deviceUtils) IsDeviceFilesystemInUse(mounter *mount.SafeFormatAndMount, devicePath, devFsPath string) (bool, error) { diff --git a/pkg/gce-pd-csi-driver/node.go b/pkg/gce-pd-csi-driver/node.go index b746be756..641138dde 100644 --- a/pkg/gce-pd-csi-driver/node.go +++ b/pkg/gce-pd-csi-driver/node.go @@ -484,10 +484,6 @@ func (ns *GCENodeServer) safelyDisableDevice(volumeID string) error { return fmt.Errorf("device %s (aka %s) is still in use", devicePath, devFsPath) } - if err := ns.DeviceUtils.DisableDevice(devFsPath); err != nil { - return &ignoreableError{fmt.Errorf("failed to disable device %s (aka %s): %v", devicePath, devFsPath, err)} - } - return nil }