summaryrefslogtreecommitdiff
path: root/common/dmdust
blob: 56fcc0e0fffa1e3380d14abd8f4543010817d637 (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
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 Facebook.  All Rights Reserved.
#
# common functions for setting up and tearing down a dmdust device

_init_dust()
{
	local DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
	DUST_DEV=/dev/mapper/dust-test
	DUST_TABLE="0 $DEV_SIZE dust $SCRATCH_DEV 0 512"
	_dmsetup_create dust-test --table "$DUST_TABLE" || \
		_fatal "failed to create dust device"
}

_mount_dust()
{
	_scratch_options mount
	_mount -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
		$DUST_DEV $SCRATCH_MNT
}

_unmount_dust()
{
	$UMOUNT_PROG $SCRATCH_MNT
}

_cleanup_dust()
{
	# If dmsetup load fails then we need to make sure to do resume here
	# otherwise the umount will hang
	$DMSETUP_PROG resume dust-test > /dev/null 2>&1
	$UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
	_dmsetup_remove dust-test
}