-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: wait untill btrfs multidevice gets assembled
And only after that proceed with mounting Fixes #194
- Loading branch information
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
const ( | ||
directionNone = 0 | ||
directionWrite = 1 | ||
directionRead = 2 | ||
|
||
numberBits = 8 | ||
typeBits = 8 | ||
sizeBits = 14 | ||
directionBits = 2 | ||
|
||
numberMask = (1 << numberBits) - 1 | ||
typeMask = (1 << typeBits) - 1 | ||
sizeMask = (1 << sizeBits) - 1 | ||
directionMask = (1 << directionBits) - 1 | ||
|
||
numberShift = 0 | ||
typeShift = numberShift + numberBits | ||
sizeShift = typeShift + typeBits | ||
directionShift = sizeShift + sizeBits | ||
) | ||
|
||
// ioc calculates the ioctl command for the specified direction, type, number and size | ||
func ioc(dir, t, nr, size uintptr) uintptr { | ||
return (dir << directionShift) | (t << typeShift) | (nr << numberShift) | (size << sizeShift) | ||
} | ||
|
||
// ior calculates the ioctl command for a read-ioctl of the specified type, number and size | ||
func ior(t, nr, size uintptr) uintptr { | ||
return ioc(directionRead, t, nr, size) | ||
} | ||
|
||
// iow calculates the ioctl command for a write-ioctl of the specified type, number and size | ||
func iow(t, nr, size uintptr) uintptr { | ||
return ioc(directionWrite, t, nr, size) | ||
} | ||
|
||
// iowr calculates the ioctl command for a read/write-ioctl of the specified type, number and size | ||
func iowr(t, nr, size uintptr) uintptr { | ||
return ioc(directionWrite|directionRead, t, nr, size) | ||
} | ||
|
||
// ioctl executes an ioctl command on the specified file descriptor | ||
func ioctl(fd, cmd, ptr uintptr) error { | ||
_, _, errno := unix.Syscall(unix.SYS_IOCTL, fd, cmd, ptr) | ||
if errno != 0 { | ||
return fmt.Errorf("ioctl(0x%x): %v", cmd, errno) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBtrfsRaid0(t *testing.T) { | ||
vm, err := buildVmInstance(t, Opts{ | ||
disk: "assets/btrfs_raid0.img", | ||
kernelArgs: []string{"root=UUID=5eaa0c1c-e1dc-4be7-9b03-9f1ed5a87289"}, | ||
}) | ||
require.NoError(t, err) | ||
defer vm.Shutdown() | ||
|
||
require.NoError(t, vm.ConsoleExpect("Hello, booster!")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
trap 'quit' EXIT ERR | ||
|
||
quit() { | ||
set +o errexit | ||
sudo umount "${dir}" | ||
rm -r "${dir}" | ||
} | ||
|
||
truncate --size 650M "${OUTPUT}" | ||
lodev=$(sudo losetup -f -P --show "${OUTPUT}") | ||
# create 2 partitions equal size | ||
sudo fdisk "${lodev}" <<< "g | ||
n | ||
+300M | ||
t | ||
29 | ||
n | ||
+300M | ||
t | ||
29 | ||
w | ||
" | ||
|
||
sudo mkfs.btrfs --uuid=$FS_UUID -d raid0 "${lodev}p1" "${lodev}p2" | ||
dir=$(mktemp -d) | ||
sudo mount "${lodev}p1" "${dir}" | ||
sudo chown "${USER}" "${dir}" | ||
mkdir "${dir}/sbin" | ||
cp assets/init "${dir}/sbin/init" |