Skip to content

Commit

Permalink
Handle partition names like "loop0p1"
Browse files Browse the repository at this point in the history
This also assumes that the block device for the partition is available
right after "udevadm settle".

Fixes projectatomic#137
  • Loading branch information
mvollmer committed May 17, 2016
1 parent 194eca2 commit a8cf5e7
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions docker-storage-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,11 @@ scan_disks() {
local new_disks=""

for dev in $DEVS_ABS; do
local basename=$(basename $dev)
local p
local part=$(query_first_child $dev)

if is_dev_part_of_vg ${dev}1 $VG; then
Info "Device ${dev} is already partitioned and is part of volume group $VG"
continue
if [ -n "$part" ] && is_dev_part_of_vg ${part} $VG; then
Info "Device ${dev} is already partitioned and is part of volume group $VG"
continue
fi

# If signatures are being overridden, then simply return the disk as new
Expand All @@ -623,9 +622,7 @@ scan_disks() {
continue
fi

# If device does not have partitions, it is a new disk requiring processing.
p=$(awk "\$4 ~ /${basename}./ {print \$4}" /proc/partitions)
if [[ -z "$p" ]]; then
if [ -z "$part" ]; then
new_disks="$dev $new_disks"
continue
fi
Expand All @@ -643,40 +640,40 @@ create_partition() {
# 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
cat <<EOF | strace -o /home/mvo/sfdisk.log sfdisk $dev
unit: sectors
${dev}1 : start= 2048, size= ${size}, Id=8e
start= 2048, size= ${size}, Id=8e
EOF

# Sometimes on slow storage it takes a while for partition device to
# become available. Wait for device node to show up.
if ! udevadm settle;then
Fatal "udevadm settle after partition creation failed. Exiting."
fi
}

if ! wait_for_dev ${dev}1; then
Fatal "Partition device ${dev}1 is not available"
fi
query_first_child() {
lsblk -npl -o NAME "$1" | tail -n +2 | head -1
}

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

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

# 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
Fatal "Failed to wipe signatures on device ${dev}1"
if ! wipefs -a ${part}; then
Fatal "Failed to wipe signatures on device ${part}"
fi
pvcreate ${dev}1
PVS="$PVS ${dev}1"
pvcreate ${part}
PVS="$PVS ${part}"
done
}

Expand Down Expand Up @@ -856,7 +853,7 @@ usage() {
Options:
--help Print help message
--reset Reset your docker storage to init state.
--reset Reset your docker storage to init state.
FOE
}

Expand Down

0 comments on commit a8cf5e7

Please sign in to comment.