From 7beaa5e8594f088b97f637cc98a871c16634225c Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 23 May 2023 10:33:23 -0700 Subject: [PATCH] Add mount options to blockfile snapshotter Signed-off-by: Derek McGowan --- snapshots/blockfile/blockfile.go | 23 +++++++++++++++---- .../blockfile/blockfile_loopsetup_test.go | 2 ++ snapshots/blockfile/plugin/plugin.go | 6 +++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/snapshots/blockfile/blockfile.go b/snapshots/blockfile/blockfile.go index 9886272e2..a504a62ef 100644 --- a/snapshots/blockfile/blockfile.go +++ b/snapshots/blockfile/blockfile.go @@ -41,6 +41,9 @@ type SnapshotterConfig struct { // fsType is the filesystem type for the mount (defaults to ext4) fsType string + + // mountOptions are the base options added to the mount (defaults to ["loop"]) + mountOptions []string } // Opt is an option to configure the overlay snapshotter @@ -68,10 +71,19 @@ func WithFSType(fsType string) Opt { } } +// WithMountOptions defines the mount options used for the mount +func WithMountOptions(options []string) Opt { + return func(root string, config *SnapshotterConfig) { + config.mountOptions = options + } + +} + type snapshotter struct { root string scratch string fsType string + options []string ms *storage.MetaStore } @@ -110,6 +122,10 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) { config.fsType = "ext4" } + if config.mountOptions != nil { + config.mountOptions = []string{"loop"} + } + ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db")) if err != nil { return nil, err @@ -123,6 +139,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) { root: root, scratch: scratch, fsType: config.fsType, + options: config.mountOptions, ms: ms, }, nil } @@ -356,10 +373,8 @@ func (o *snapshotter) getBlockFile(id string) string { func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount { var ( - mountOptions = []string{ - "loop", - } - source string + mountOptions = o.options + source string ) if s.Kind == snapshots.KindView { diff --git a/snapshots/blockfile/blockfile_loopsetup_test.go b/snapshots/blockfile/blockfile_loopsetup_test.go index 816f12ffd..06b4dd306 100644 --- a/snapshots/blockfile/blockfile_loopsetup_test.go +++ b/snapshots/blockfile/blockfile_loopsetup_test.go @@ -66,6 +66,8 @@ func setupSnapshotter(t *testing.T) ([]Opt, error) { return []Opt{ WithScratchFile(scratch), + WithFSType("ext4"), + WithMountOptions([]string{"loop", "sync"}), }, nil } diff --git a/snapshots/blockfile/plugin/plugin.go b/snapshots/blockfile/plugin/plugin.go index a3c0f0d52..8381537cf 100644 --- a/snapshots/blockfile/plugin/plugin.go +++ b/snapshots/blockfile/plugin/plugin.go @@ -34,6 +34,9 @@ type Config struct { // FSType is the filesystem type for the mount FSType string `toml:"fs_type"` + + // MountOptions are options used for the mount + MountOptions []string `toml:"mount_options"` } func init() { @@ -60,6 +63,9 @@ func init() { if config.FSType != "" { opts = append(opts, blockfile.WithFSType(config.FSType)) } + if len(config.MountOptions) > 0 { + opts = append(opts, blockfile.WithMountOptions(config.MountOptions)) + } return blockfile.NewSnapshotter(root, opts...) },