Skip to content

Commit

Permalink
Handle partition names like "loop0p1"
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed May 16, 2016
1 parent 194eca2 commit e85d0e1
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions docker-storage-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,11 @@ scan_disks() {
local new_disks=""

for dev in $DEVS_ABS; do
local basename=$(basename $dev)
local part=$(partition_name $dev)
local partition_pattern=$(basename $part | sed -e 's/[0-9]$/\[0-9\]\+/')
local p

if is_dev_part_of_vg ${dev}1 $VG; then
if is_dev_part_of_vg ${part} $VG; then
Info "Device ${dev} is already partitioned and is part of volume group $VG"
continue
fi
Expand All @@ -624,7 +625,7 @@ scan_disks() {
fi

# If device does not have partitions, it is a new disk requiring processing.
p=$(awk "\$4 ~ /${basename}./ {print \$4}" /proc/partitions)
p=$(awk "\$4 ~ /${partition_pattern}/ {print \$4}" /proc/partitions)
if [[ -z "$p" ]]; then
new_disks="$dev $new_disks"
continue
Expand All @@ -637,18 +638,17 @@ scan_disks() {
}

create_partition() {
local dev="$1" size
local dev="$1" part="$2" size

# Use a single partition of a whole device
# TODO:
# * Consider gpt, or unpartitioned volumes
# * Error handling when partition(s) already exist
# * Deal with loop/nbd device names. See growpart code
size=$(( $( awk "\$4 ~ /"$( basename $dev )"/ { print \$3 }" /proc/partitions ) * 2 - 2048 ))
cat <<EOF | sfdisk $dev
unit: sectors
${dev}1 : start= 2048, size= ${size}, Id=8e
${part} : start= 2048, size= ${size}, Id=8e
EOF

# Sometimes on slow storage it takes a while for partition device to
Expand All @@ -657,26 +657,36 @@ EOF
Fatal "udevadm settle after partition creation failed. Exiting."
fi

if ! wait_for_dev ${dev}1; then
Fatal "Partition device ${dev}1 is not available"
if ! wait_for_dev ${part}; then
Fatal "Partition device ${part} is not available"
fi
}

partition_name() {
if echo "$1" | grep -q '[0-9]$'; then
echo "${1}p1"
else
echo "${1}1"
fi
}

create_disk_partitions() {
local devs="$1"
local devs="$1" part

for dev in $devs; do
create_partition $dev
part=$(partition_name $dev)

create_partition $dev $part

# By now we have ownership of disk and we have checked there are no
# signatures on disk or signatures should be wiped. Don't care
# about any signatures found in the middle of disk after creating
# partition and wipe signatures if any are found.
if ! wipefs -a ${dev}1; then
if ! wipefs -a ${part}; then
Fatal "Failed to wipe signatures on device ${dev}1"
fi
pvcreate ${dev}1
PVS="$PVS ${dev}1"
pvcreate ${part}
PVS="$PVS ${part}"
done
}

Expand Down

0 comments on commit e85d0e1

Please sign in to comment.