From 96b01a7d2a5dce55e0ba2f3a87e406a791b8027d Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 10 Jun 2015 18:35:45 -0400 Subject: [PATCH] Revert "Remove unused map_nbd function" This reverts commit ea4a823810c4b7794bf540bd26f2e3b1b8788fbb. This function was actually still in use in lib/common-functions and removing it causes the disk-image-get-kernel /bin to fail entirely. Change-Id: Icddb3ca369922a6ea915af8b1b62c434cb1bdf28 Closes-bug: 1464031 --- lib/common-functions | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/common-functions b/lib/common-functions index 3eb6e38f..c0e7ffb9 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -121,6 +121,36 @@ function eval_run_d () { fi } +# Usage: map_nbd $image +# Returns nbd device path +function map_nbd { + (lsmod | grep '^nbd ' >/dev/null) || sudo modprobe nbd max_part=16 + + if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then + CACHE="--cache=writeback" + else + echo "Warning: qemu-nbd without --cache=writeback is /slow/." + CACHE="" + fi + NBD_DEV= + for i in `seq 0 15`; do + if [ ! -e /sys/block/nbd$i/pid ]; then + NBD_DEV=/dev/nbd$i + # Connect to nbd and wait till it is ready + sudo qemu-nbd -c $NBD_DEV $CACHE $1 + if ! timeout 60 sh -c "while ! [ -e /sys/block/nbd$i/pid ]; do sleep 1; done"; then + echo "Couldn't connect $NBD_DEV" + exit 1 + fi + break + fi + done + if [ -z "$NBD_DEV" ]; then + echo "No free NBD slots" + exit 1 + fi +} + # Delete and unmount the working dir used in extracting kernel/initrd function unmount_qcow_image () { sudo umount $WORK_DIR || true