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 Feb 27, 2017
1 parent 0f60770 commit 03c6aca
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions container-storage-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,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 @@ -699,8 +698,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)
if [[ -z "$p" ]]; then
if [ -z "$part" ]; then
new_disks="$dev $new_disks"
continue
fi
Expand All @@ -717,12 +715,11 @@ create_partition_sfdisk(){
# 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
start= 2048, size= ${size}, Id=8e
EOF
}

Expand All @@ -745,27 +742,28 @@ create_partition() {
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

0 comments on commit 03c6aca

Please sign in to comment.