From 77fd246663a7fbc6fb3eeffc6145ef04d9cb3775 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 26 May 2020 10:16:30 +0100 Subject: [PATCH] actions/image_partition: trigger udev rules after image-partition completion The image is locked while partitioning and mounting, which has a side effect of not running udev rules so there are no entries for the freshly partitioned disk under the children of `/dev/disk`. Currently the workaround is to call partprobe in the recipe, which creates the entries but we should do this as part of the image-partition action so that no magic is needed in the recipe. Fixes: f91e2b2c2789 ("Fix partition races while partitioning") Resolves: #154 Signed-off-by: Christopher Obbard --- actions/image_partition_action.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index d3117b50..1a63f0b3 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -255,6 +255,16 @@ func (i ImagePartitionAction) getPartitionDevice(number int, context debos.Debos } } +func (i *ImagePartitionAction) triggerDeviceNodes(context *debos.DebosContext) error { + err := debos.Command{}.Run("udevadm", "udevadm", "trigger", "--settle", context.Image) + if err != nil { + log.Printf("Failed to trigger device nodes") + return err + } + + return nil +} + func (i ImagePartitionAction) PreMachine(context *debos.DebosContext, m *fakemachine.Machine, args *[]string) error { image, err := m.CreateImage(i.ImageName, i.size) @@ -353,7 +363,9 @@ func (i ImagePartitionAction) Run(context *debos.DebosContext) error { } /* Defer will keep the fd open until the function returns, at which points * the filesystems will have been mounted protecting from more udev funnyness - */ + * After the fd is closed the kernel needs to be informed of partition table + * changes (defer calls are executed in LIFO order) */ + defer i.triggerDeviceNodes(context) defer imageFD.Close() err = syscall.Flock(int(imageFD.Fd()), syscall.LOCK_EX)