Skip to content

Commit

Permalink
Merge pull request containerd#8559 from dmcgowan/blockfile-add-mount-…
Browse files Browse the repository at this point in the history
…options
  • Loading branch information
samuelkarp authored May 24, 2023
2 parents 5997a65 + 7beaa5e commit b16b0c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
23 changes: 19 additions & 4 deletions snapshots/blockfile/blockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions snapshots/blockfile/blockfile_loopsetup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func setupSnapshotter(t *testing.T) ([]Opt, error) {

return []Opt{
WithScratchFile(scratch),
WithFSType("ext4"),
WithMountOptions([]string{"loop", "sync"}),
}, nil
}

Expand Down
6 changes: 6 additions & 0 deletions snapshots/blockfile/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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...)
},
Expand Down

0 comments on commit b16b0c8

Please sign in to comment.