Skip to content

Commit ec6bec6

Browse files
Add support for removable devices and minor refactor (#614)
1 parent 82fc509 commit ec6bec6

File tree

10 files changed

+936
-307
lines changed

10 files changed

+936
-307
lines changed

pkg/node/uevent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func TestUpdateHandler(t *testing.T) {
635635
PTUUID: "7e3bf265-0396-440b-88fd-dc2003505583",
636636
PTType: "gpt",
637637
PartUUID: "d895e5a6-c5cb-49d7-ae0d-a3946f4f1a3a",
638-
FSUUID: "e79dff9e-2884-46f2-8919-dada2eecb12d",
638+
FSUUID: "d79dff9e-2884-46f2-8919-dada2eecb12d",
639639
FSType: "xfs",
640640
UeventSerial: "12345ABCD678",
641641
UeventFSUUID: "e79dff9e-2884-46f2-8919-dada2eecb12d",

pkg/node/uevent_utils.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ func (d *driveEventHandler) setDriveStatus(device *sys.Device, drive *directcsi.
5353
updatedDrive := drive.DeepCopy()
5454
updatedDrive.Status.NodeName = d.nodeID
5555
updatedDrive.Status.Topology = d.topology
56-
updatedDrive.Status.Filesystem = device.FSType
57-
updatedDrive.Status.FilesystemUUID = device.FSUUID
5856
updatedDrive.Status.UeventFSUUID = device.UeventFSUUID
5957
updatedDrive.Status.MajorNumber = uint32(device.Major)
6058
updatedDrive.Status.MinorNumber = uint32(device.Minor)
@@ -72,6 +70,14 @@ func (d *driveEventHandler) setDriveStatus(device *sys.Device, drive *directcsi.
7270
updatedDrive.Status.Partitioned = device.Partitioned
7371
updatedDrive.Status.PCIPath = device.PCIPath
7472

73+
// do not update FS info for managed drives
74+
if updatedDrive.Status.Filesystem == "" || !utils.IsManagedDrive(updatedDrive) {
75+
updatedDrive.Status.Filesystem = device.FSType
76+
}
77+
if updatedDrive.Status.FilesystemUUID == "" || !utils.IsManagedDrive(updatedDrive) {
78+
updatedDrive.Status.FilesystemUUID = device.FSUUID
79+
}
80+
7581
// populate mount infos
7682
updatedDrive.Status.MountOptions = device.FirstMountOptions
7783
updatedDrive.Status.Mountpoint = device.FirstMountPoint
@@ -93,6 +99,10 @@ func (d *driveEventHandler) setDriveStatus(device *sys.Device, drive *directcsi.
9399
if strings.EqualFold(updatedDrive.Status.PartitionUUID, device.PartUUID) {
94100
updatedDrive.Status.PartitionUUID = device.PartUUID
95101
}
102+
// bugfix: for versions < 3.0.0, the partitionUUID has to be unset or set to empty for root partitions
103+
if device.Partition == int(0) {
104+
updatedDrive.Status.PartitionUUID = device.PartUUID
105+
}
96106
}
97107

98108
if updatedDrive.Status.DMUUID == "" || !utils.IsManagedDrive(updatedDrive) {
@@ -149,22 +159,27 @@ func validateDrive(drive *directcsi.DirectCSIDrive, device *sys.Device) error {
149159
var err error
150160
switch drive.Status.DriveStatus {
151161
case directcsi.DriveStatusInUse, directcsi.DriveStatusReady:
152-
if !mount.ValidDirectPVMounts(device.MountPoints) {
162+
// Check if the drive is umounted or if the directpv mount is not found
163+
if device.FirstMountPoint == "" || !mount.ValidDirectPVMounts(device.MountPoints) {
153164
err = multierr.Append(err, errInvalidMount)
154165
}
155-
if device.FirstMountPoint != filepath.Join(sys.MountRoot, drive.Name) &&
156-
device.FirstMountPoint != filepath.Join(sys.MountRoot, drive.Status.FilesystemUUID) {
157-
err = multierr.Append(err, errInvalidDrive(
158-
"Mountpoint",
159-
filepath.Join(sys.MountRoot, drive.Name),
160-
device.FirstMountPoint))
161-
}
162-
if !mount.ValidDirectPVMountOpts(device.FirstMountOptions) {
163-
err = multierr.Append(err, errInvalidDrive(
164-
"MountpointOptions",
165-
mount.MountOptRW,
166-
device.FirstMountOptions))
166+
// Verify drive mount and mountopts
167+
if device.FirstMountPoint != "" {
168+
if device.FirstMountPoint != filepath.Join(sys.MountRoot, drive.Name) &&
169+
device.FirstMountPoint != filepath.Join(sys.MountRoot, drive.Status.FilesystemUUID) {
170+
err = multierr.Append(err, errInvalidDrive(
171+
"Mountpoint",
172+
filepath.Join(sys.MountRoot, drive.Name),
173+
device.FirstMountPoint))
174+
}
175+
if !mount.ValidDirectPVMountOpts(device.FirstMountOptions) {
176+
err = multierr.Append(err, errInvalidDrive(
177+
"MountpointOptions",
178+
mount.MountOptRW,
179+
device.FirstMountOptions))
180+
}
167181
}
182+
// Check other device attributes
168183
if device.Size < sys.MinSupportedDeviceSize {
169184
err = multierr.Append(err, fmt.Errorf(
170185
"the size of the drive is less than %v",
@@ -182,12 +197,6 @@ func validateDrive(drive *directcsi.DirectCSIDrive, device *sys.Device) error {
182197
false,
183198
device.Hidden))
184199
}
185-
if device.Removable {
186-
err = multierr.Append(err, errInvalidDrive(
187-
"Removable",
188-
false,
189-
device.Removable))
190-
}
191200
if device.SwapOn {
192201
err = multierr.Append(err, errInvalidDrive(
193202
"SwapOn",

0 commit comments

Comments
 (0)