Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Configure dmsetup to fallback to managing device nodes without udevd #654

Merged
merged 3 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/dmlegacy/cleanup/deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
func DeactivateSnapshot(vm *api.VM) error {
dmArgs := []string{
"remove",
vm.SnapshotDev(),
"--verifyudev", // if udevd is not running, dmsetup will manage the device node in /dev/mapper
util.NewPrefixer().Prefix(vm.GetUID()),
}

// If the base device is visible in "dmsetup", we should remove it
Expand Down
8 changes: 6 additions & 2 deletions pkg/dmlegacy/loopdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ func (ld *loopDevice) Size512K() (uint64, error) {

// dmsetup uses stdin to read multiline tables, this is a helper function for that
func runDMSetup(name string, table []byte) error {
cmd := exec.Command("dmsetup", "create", name)
cmd := exec.Command(
"dmsetup", "create",
"--verifyudev", // if udevd is not running, dmsetup will manage the device node in /dev/mapper
name,
)
stdin, err := cmd.StdinPipe()
if err != nil {
return err
Expand All @@ -52,7 +56,7 @@ func runDMSetup(name string, table []byte) error {

out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("command %q exited with %q: %v", cmd.Args, out, err)
return fmt.Errorf("command %q exited with %q: %w", cmd.Args, out, err)
}

return nil
Expand Down
11 changes: 7 additions & 4 deletions pkg/dmlegacy/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (

const snapshotLockFileName = "ignite-snapshot.lock"

// ActivateSnapshot sets up the snapshot with devicemapper so that it is active and can be used
func ActivateSnapshot(vm *api.VM) (err error) {
// ActivateSnapshot sets up the snapshot with devicemapper so that it is active and can be used.
// It returns the path of the bootable snapshot device.
func ActivateSnapshot(vm *api.VM) (devicePath string, err error) {
device := util.NewPrefixer().Prefix(vm.GetUID())
devicePath := vm.SnapshotDev()
devicePath = vm.SnapshotDev()

// Return if the snapshot is already setup
if util.FileExists(devicePath) {
Expand All @@ -47,7 +48,8 @@ func ActivateSnapshot(vm *api.VM) (err error) {
// Create a lockfile and obtain a lock.
lock, err := lockfile.New(glpath)
if err != nil {
return fmt.Errorf("failed to create lock: %v", err)
err = fmt.Errorf("failed to create lockfile: %w", err)
return
}
if err = obtainLock(lock); err != nil {
return
Expand Down Expand Up @@ -105,6 +107,7 @@ func ActivateSnapshot(vm *api.VM) (err error) {
// "0 8388608 snapshot /dev/{loop0,mapper/ignite-<uid>-base} /dev/loop1 P 8"
dmTable := []byte(fmt.Sprintf("0 %d snapshot %s %s P 8", overlayLoopSize, basePath, overlayLoop.Path()))

// setup the main boot device
if err = runDMSetup(device, dmTable); err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dmlegacy/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func AllocateAndPopulateOverlay(vm *api.VM) error {
}

func copyToOverlay(vm *api.VM) (err error) {
err = ActivateSnapshot(vm)
_, err = ActivateSnapshot(vm)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/operations/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func CleanupVM(vm *api.VM) error {
// TODO should this function return a proper error?
RemoveVMContainer(inspectResult)

// After remove the VM container, and the SnapshotDev still there
// After removing the VM container, if the Snapshot Device is still there, clean up
if _, err := os.Stat(vm.SnapshotDev()); err == nil {
// try remove it again with DeactivateSnapshot
if err := cleanup.DeactivateSnapshot(vm); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/operations/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func StartVM(vm *api.VM, debug bool) error {
RemoveVMContainer(inspectResult)

// Setup the snapshot overlay filesystem
if err := dmlegacy.ActivateSnapshot(vm); err != nil {
snapshotDevPath, err := dmlegacy.ActivateSnapshot(vm)
if err != nil {
return err
}

Expand Down Expand Up @@ -70,7 +71,7 @@ func StartVM(vm *api.VM, debug bool) error {
runtime.BindBoth("/dev/mapper/control"), // This enables containerized Ignite to remove its own dm snapshot
runtime.BindBoth("/dev/net/tun"), // Needed for creating TAP adapters
runtime.BindBoth("/dev/kvm"), // Pass through virtualization support
runtime.BindBoth(vm.SnapshotDev()), // The block device to boot from
runtime.BindBoth(snapshotDevPath), // The block device to boot from
},
StopTimeout: constants.STOP_TIMEOUT + constants.IGNITE_TIMEOUT,
PortBindings: vm.Spec.Network.Ports, // Add the port mappings to Docker
Expand Down