Skip to content

Commit

Permalink
improve fusefs handling (#138)
Browse files Browse the repository at this point in the history
make unmounting more robust


Co-authored-by: craig bender <[email protected]>
  • Loading branch information
alexsander-souza and ThinGuy authored Sep 14, 2023
1 parent 7b3aadc commit 3cc25be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
30 changes: 16 additions & 14 deletions scripts/fuse-nbd
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ if [ ! -f "${PACKER_OUTPUT}" ]; then
exit
fi

sync -f ${PACKER_OUTPUT}
sync -f "${PACKER_OUTPUT}"

TMP_DIR=$(mktemp -d /tmp/packer-maas-XXXX)
cleanup() {
for dev in $(ls -d ${TMP_DIR}/p*); do
fusermount -u ${dev}
for dev in "${TMP_DIR}"/p*/; do
dev=${dev%*/}
fusermount -u -z "${dev}"
grep -qs "${dev} " /proc/mounts && umount -f "${dev}"
done
rm -rf "${TMP_DIR}"
}
Expand All @@ -44,12 +46,12 @@ function mount_part() {
MOUNTPOINT=$2
FUSEDRV=${3:-fuse2fs}
DEV=${TMP_DIR}/p${PART}
[ -d ${MOUNTPOINT} ] || mkdir -p ${MOUNTPOINT}
mkdir ${DEV}
nbdfuse ${DEV} \
mkdir -p "${MOUNTPOINT}"
mkdir -p "${DEV}"
nbdfuse "${DEV}" \
--command nbdkit -s nbd \
socket=$(pwd)/qemu-img.sock \
--filter=partition partition=${PART} &
socket="$(pwd)"/qemu-img.sock \
--filter=partition partition="${PART}" &
retries=0
until [ -f "${DEV}/nbd" ]; do
sleep 1
Expand All @@ -58,15 +60,15 @@ function mount_part() {
fi
done
case "${FUSEDRV}" in
"fusefat") fusefat ${DEV}/nbd ${MOUNTPOINT} -o rw+ -s ;;
"fuse2fs") fuse2fs ${DEV}/nbd ${MOUNTPOINT} -o fakeroot ;;
"fusefat") fusefat "${DEV}"/nbd "${MOUNTPOINT}" -o rw+ -s ;;
"fuse2fs") fuse2fs "${DEV}"/nbd "${MOUNTPOINT}" -o fakeroot ;;
*) echo "Unsupported Fuse driver" && exit 1 ;;
esac
}

qemu-nbd --socket=$(pwd)/qemu-img.sock \
--format=${IMG_FMT} \
qemu-nbd --socket="$(pwd)"/qemu-img.sock \
--format="${IMG_FMT}" \
--shared=10 \
${PACKER_OUTPUT} &
"${PACKER_OUTPUT}" &

mkdir "${TMP_DIR}/root"
mkdir -p "${TMP_DIR}/root"
10 changes: 6 additions & 4 deletions scripts/fuse-tar-root
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ mount_part "${ROOT_PARTITION}" "${ROOT_MOUNT}"

if [ -d curtin ] || [ -d "$CURTIN_HOOKS" ]; then
echo 'Adding Curtin hooks...'
cp -r ${CURTIN_HOOKS:-curtin} ${ROOT_MOUNT}
cp -r "${CURTIN_HOOKS:-curtin}" "${ROOT_MOUNT}"
fi

echo "Creating MAAS image ${OUTPUT}..."
tar -Sczpf "${OUTPUT}" --acls --selinux --xattrs -C $ROOT_MOUNT .
tar -Sczpf "${OUTPUT}" --acls --selinux --xattrs --exclude='agent.*' --exclude='*.socket' -C "$ROOT_MOUNT" .

if [ -n "$MANIFEST" ]; then
echo "Creating manifest..."
# RPM on CentOS/RHEL 7 needs /dev mounted so it can use /dev/urandom
mount -o bind /dev "${ROOT_MOUNT}/dev"
chroot "${ROOT_MOUNT}" rpm -qa | sort -u -o $MANIFEST
chroot "${ROOT_MOUNT}" rpm -qa | sort -u -o "$MANIFEST"
umount "${ROOT_MOUNT}/dev"
grep -qs "${ROOT_MOUNT}/dev " /proc/mounts && umount -f "${ROOT_MOUNT}/dev"
fi

sync
fusermount -u "${ROOT_MOUNT}"
fusermount -z -u "${ROOT_MOUNT}"
grep -qs "${ROOT_MOUNT} " /proc/mounts && umount -f "${ROOT_MOUNT}"
echo 'Done'

0 comments on commit 3cc25be

Please sign in to comment.