summaryrefslogtreecommitdiff
path: root/samizdat-eject.sh
blob: 04ee6108e1d323071d928f437ac83bf3fd7d06a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

. mdadm-dup.sh || exit 1

btrfs_subdevices()
{
    local mountpoint="$1"
    btrfs filesystem show "$mountpoint" | sed -ne 's/^[ \t]*devid.* path //p'
}

devices=$(btrfs_subdevices /) || exit 1

set --
seen=
for dev in $devices; do
    [ -b "$dev" ] || exit 1
    case "$dev" in
        /dev/mapper/loop*) set -- "$@" "$dev" ;;
        /dev/mapper/samizdatcrypt) seen=y ;;
    esac
done
[ "$seen" ] || exit 1

copy()
{
    mdadm_copy_eject /dev/md55 /root/samizdat.iso
}

remove()
{
    for dev; do
        (set -x; btrfs device remove "$dev" /)
    done
}

# Doing the mdadm copy before removing the devices means our filesystem includes
# devices that are ultimately backed by files ON THE SAME FILESYSTEM. As such, it
# might conceivably put btrfs into a deadlock of some kind.

# If it turns out this doesn't work, the order can be reversed. This will
# perform the read IO twice, though, almost doubling the total installation
# time.

copy & remove "$@"

set -x
wait