Skip to content

Commit

Permalink
Use glob to find device.
Browse files Browse the repository at this point in the history
  • Loading branch information
alakae committed Mar 31, 2021
1 parent 59eb8f7 commit 4a34c77
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions driver/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,15 @@ func (m *mounter) FinalizeVolumeAttachmentAndFindPath(logger *logrus.Entry, volu
for {
probeAttachedVolume(logger)

sourcePathPrefixes := []string{"virtio-", "scsi-", "scsi-0QEMU_QEMU_HARDDISK_", "scsi-SQEMU_QEMU_HARDDISK_"}
// Get the first part of the UUID.
// The linux kernel limits volume serials to 20 bytes:
// include/uapi/linux/virtio_blk.h:#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
idVariants := []string{volumeID, volumeID[:20]}

for _, idVariant := range idVariants {
for _, prefix := range sourcePathPrefixes {
source := filepath.Join(diskIDPath, prefix+idVariant)
_, err := os.Stat(source)
if err == nil {
return &source, nil
}
if !os.IsNotExist(err) {
return nil, err
}
}
linuxSerial := volumeID[:20]

globExpr := diskIDPath + "/*" + linuxSerial + "*"
matches, _ := filepath.Glob(globExpr)
if len(matches) > 0 {
return &matches[0], nil
}

numTries++
Expand Down

0 comments on commit 4a34c77

Please sign in to comment.