Merge pull request #8559 from dmcgowan/blockfile-add-mount-options

This commit is contained in:
Samuel Karp 2023-05-24 14:46:48 -07:00 committed by GitHub
commit b16b0c872d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -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 {

View File

@ -66,6 +66,8 @@ func setupSnapshotter(t *testing.T) ([]Opt, error) {
return []Opt{
WithScratchFile(scratch),
WithFSType("ext4"),
WithMountOptions([]string{"loop", "sync"}),
}, nil
}

View File

@ -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...)
},