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 is the filesystem type for the mount (defaults to ext4)
fsType string 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 // 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 { type snapshotter struct {
root string root string
scratch string scratch string
fsType string fsType string
options []string
ms *storage.MetaStore ms *storage.MetaStore
} }
@ -110,6 +122,10 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
config.fsType = "ext4" config.fsType = "ext4"
} }
if config.mountOptions != nil {
config.mountOptions = []string{"loop"}
}
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db")) ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
if err != nil { if err != nil {
return nil, err return nil, err
@ -123,6 +139,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
root: root, root: root,
scratch: scratch, scratch: scratch,
fsType: config.fsType, fsType: config.fsType,
options: config.mountOptions,
ms: ms, ms: ms,
}, nil }, nil
} }
@ -356,10 +373,8 @@ func (o *snapshotter) getBlockFile(id string) string {
func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount { func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount {
var ( var (
mountOptions = []string{ mountOptions = o.options
"loop", source string
}
source string
) )
if s.Kind == snapshots.KindView { if s.Kind == snapshots.KindView {

View File

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

View File

@ -34,6 +34,9 @@ type Config struct {
// FSType is the filesystem type for the mount // FSType is the filesystem type for the mount
FSType string `toml:"fs_type"` FSType string `toml:"fs_type"`
// MountOptions are options used for the mount
MountOptions []string `toml:"mount_options"`
} }
func init() { func init() {
@ -60,6 +63,9 @@ func init() {
if config.FSType != "" { if config.FSType != "" {
opts = append(opts, blockfile.WithFSType(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...) return blockfile.NewSnapshotter(root, opts...)
}, },