Skip to content

Commit

Permalink
actions/image_partition: trigger udev rules after image-partition com…
Browse files Browse the repository at this point in the history
…pletion

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: f91e2b2 ("Fix partition races while partitioning")
Resolves: go-debos#154

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc authored and sjoerdsimons committed May 28, 2020
1 parent 0875e30 commit 77fd246
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 77fd246

Please sign in to comment.