Permalink
Browse files

WHIRR-721: Improve robustness of volume device detection

  • Loading branch information...
1 parent 1507d99 commit 4c45b6fe4a38f90d6e0eb78d7cab6e2cb147025f @ggear ggear committed May 3, 2013
View
@@ -6,6 +6,8 @@ Release 0.9.0 (Unreleased Changes)
IMPROVEMENTS
+ WHIRR-721. Improve robustness of volume device detection. (graham)
+
BUG FIXES
Release 0.8.2 - 2013-04-23
@@ -18,16 +18,18 @@
package org.apache.whirr.service.hadoop;
-import com.google.common.collect.Maps;
-
import java.util.List;
import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.whirr.Cluster.Instance;
import org.apache.whirr.ClusterSpec;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Volume;
+import com.google.common.collect.Maps;
+
public class VolumeManager {
public static final String MOUNT_PREFIX = "/data";
@@ -41,12 +43,22 @@
if (hardware != null) {
List<? extends Volume> volumes =
instance.getNodeMetadata().getHardware().getVolumes();
+ boolean foundBootDevice = false;
+ SortedSet<String> volumeDevicesSansBoot = new TreeSet<String>();
for (Volume volume : volumes) {
- if (volume.isBootDevice()) {
- continue;
+ if (!volume.isBootDevice()) {
+ volumeDevicesSansBoot.add(volume.getDevice());
+ } else {
+ foundBootDevice = true;
}
-
- mappings.put(MOUNT_PREFIX + number++, volume.getDevice());
+ }
+ // if no boot device is reported from the cloud provider (as is sometimes the case)
+ // assume it is the first in the natural order list of devices
+ if (!foundBootDevice && !volumeDevicesSansBoot.isEmpty()) {
+ volumeDevicesSansBoot.remove(volumeDevicesSansBoot.iterator().next());
+ }
+ for (String device : volumeDevicesSansBoot) {
+ mappings.put(MOUNT_PREFIX + number++, device);
}
}
return mappings;
@@ -55,34 +55,46 @@ function prep_disk() {
device=$(echo "$device"|sed -e 's/\/sd/\/xvd/')
fi
- # is device formatted?
- if [ $(mountpoint -q -x $device) ]; then
- echo "$device is formatted"
- else
- if which dpkg &> /dev/null; then
- apt-get install -y xfsprogs
- elif which rpm &> /dev/null; then
- yum install -y xfsprogs
- fi
- echo "warning: ERASING CONTENTS OF $device"
- mkfs.xfs -f $device
+ # match /dev/sd* devices to their Xen VPS equivalents and set device if found
+ deviceXen=$(echo "$device"|sed -e 's/\/sd/\/xvd/')
+ if [ ! -e $deviceXen ]; then
+ # match /dev/sd(.) to a new RHEL 6.1 Xen VPS naming scheme - https://bugzilla.redhat.com/show_bug.cgi?id=729586
+ deviceXen=$(echo "$device"|sed -e 's/\/sd./\/xvd/'|xargs -I £ echo "£"$(printf \\$(printf '%03o' $(($(printf "%d\n" \'${device:${#device} - 1})+4)) )))
fi
- # is device mounted?
- mount | grep -q $device
- if [ $? == 0 ]; then
- echo "$device is mounted"
- if [ ! -d $mount ]; then
- echo "Symlinking to $mount"
- ln -s $(grep $device /proc/mounts | awk '{print $2}') $mount
- fi
- else
- echo "Mounting $device on $mount"
- if [ ! -e $mount ]; then
- mkdir $mount
+ if [ -e $deviceXen ]; then
+ device=$deviceXen
+ fi
+
+ if [ -e $device ]; then
+ # is device formatted?
+ if [ $(mountpoint -q -x $device) ]; then
+ echo "$device is formatted"
+ else
+ if which dpkg &> /dev/null; then
+ apt-get install -y xfsprogs
+ elif which rpm &> /dev/null; then
+ yum install -y xfsprogs
+ fi
+ echo "warning: ERASING CONTENTS OF $device"
+ mkfs.xfs -f $device
fi
- mount -o defaults,noatime $device $mount
- if $automount ; then
- echo "$device $mount xfs defaults,noatime 0 0" >> /etc/fstab
+ # is device mounted?
+ mount | grep -q $device
+ if [ $? == 0 ]; then
+ echo "$device is mounted"
+ if [ ! -d $mount ]; then
+ echo "Symlinking to $mount"
+ ln -s $(grep $device /proc/mounts | awk '{print $2}') $mount
+ fi
+ else
+ echo "Mounting $device on $mount"
+ if [ ! -e $mount ]; then
+ mkdir $mount
+ fi
+ mount -o defaults,noatime $device $mount
+ if $automount ; then
+ echo "$device $mount xfs defaults,noatime 0 0" >> /etc/fstab
+ fi
fi
fi
}

0 comments on commit 4c45b6f

Please sign in to comment.