From 695eb486f102bf2a88233cb72555bd45b1301a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Ma=C5=82ota-W=C3=B3jcik?= <59281144+outofforest@users.noreply.github.com> Date: Wed, 24 Aug 2022 23:07:54 +0200 Subject: [PATCH] Unmount filesystem before dropping to fail early if filesystem is busy (#180) --- infra/storage/zfs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/infra/storage/zfs.go b/infra/storage/zfs.go index b37dd28..04d9070 100644 --- a/infra/storage/zfs.go +++ b/infra/storage/zfs.go @@ -250,6 +250,15 @@ func (d *zfsDriver) Drop(ctx context.Context, buildID types.BuildID) error { if err != nil { return errors.WithStack(fmt.Errorf("build %s does not exist: %w", buildID, types.ErrImageDoesNotExist)) } + mounted, _, err := filesystem.GetProperty(ctx, "mounted") + if err != nil { + return err + } + if mounted == "yes" { + if err := filesystem.Unmount(ctx); err != nil { + return err + } + } if err := filesystem.Destroy(ctx, zfs.DestroyRecursive); err != nil { return errors.WithStack(fmt.Errorf("build %s have children: %w", buildID, ErrImageHasChildren))