From a85451addc4e7170673b450c33ddf4c76de7c836 Mon Sep 17 00:00:00 2001 From: Sami Wagiaalla Date: Wed, 6 May 2015 13:40:18 -0400 Subject: [PATCH] Support default udev GCE PD device path The expected GCE PD device name is google-{name of disk}. This is because standard GCE images contain a udev rules file which renames the GCE PD device to google-{name of disk} https://github.com/GoogleCloudPlatform/compute-image-packages/blob/master/google-startup-scripts/lib/udev/rules.d/65-gce-disk-naming.rules. In custome images which do not have that udev rules file the device gets the default rules apply http://cgit.freedesktop.org/systemd/systemd/tree/rules/60-persistent-storage.rules and the GCE PD device ends up with a name which looks like scsi-0Google_PersistentDisk_{name of disk} This patch adds support for that scenario. Signed-off-by: Sami Wagiaalla --- pkg/volume/gce_pd/gce_util.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/volume/gce_pd/gce_util.go b/pkg/volume/gce_pd/gce_util.go index 6ecc712d00e..44dba25c180 100644 --- a/pkg/volume/gce_pd/gce_util.go +++ b/pkg/volume/gce_pd/gce_util.go @@ -42,19 +42,34 @@ func (util *GCEDiskUtil) AttachAndMountDisk(pd *gcePersistentDisk, globalPDPath if err := gce.(*gce_cloud.GCECloud).AttachDisk(pd.pdName, pd.readOnly); err != nil { return err } - devicePath := path.Join("/dev/disk/by-id/", "google-"+pd.pdName) + + devicePaths := []string{ + path.Join("/dev/disk/by-id/", "google-"+pd.pdName), + path.Join("/dev/disk/by-id/", "scsi-0Google_PersistentDisk_"+pd.pdName), + } + if pd.partition != "" { - devicePath = devicePath + "-part" + pd.partition + for i, path := range devicePaths { + devicePaths[i] = path + "-part" + pd.partition + } } //TODO(jonesdl) There should probably be better method than busy-waiting here. numTries := 0 + devicePath := "" + // Wait for the disk device to be created for { - _, err := os.Stat(devicePath) - if err == nil { - break + for _, path := range devicePaths { + _, err := os.Stat(path) + if err == nil { + devicePath = path + break + } + if err != nil && !os.IsNotExist(err) { + return err + } } - if err != nil && !os.IsNotExist(err) { - return err + if devicePath != "" { + break } numTries++ if numTries == 10 {