Skip to content

Commit 7beaa5e

Browse files
committed
Add mount options to blockfile snapshotter
Signed-off-by: Derek McGowan <[email protected]>
1 parent 773874c commit 7beaa5e

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

snapshots/blockfile/blockfile.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type SnapshotterConfig struct {
4141

4242
// fsType is the filesystem type for the mount (defaults to ext4)
4343
fsType string
44+
45+
// mountOptions are the base options added to the mount (defaults to ["loop"])
46+
mountOptions []string
4447
}
4548

4649
// Opt is an option to configure the overlay snapshotter
@@ -68,10 +71,19 @@ func WithFSType(fsType string) Opt {
6871
}
6972
}
7073

74+
// WithMountOptions defines the mount options used for the mount
75+
func WithMountOptions(options []string) Opt {
76+
return func(root string, config *SnapshotterConfig) {
77+
config.mountOptions = options
78+
}
79+
80+
}
81+
7182
type snapshotter struct {
7283
root string
7384
scratch string
7485
fsType string
86+
options []string
7587
ms *storage.MetaStore
7688
}
7789

@@ -110,6 +122,10 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
110122
config.fsType = "ext4"
111123
}
112124

125+
if config.mountOptions != nil {
126+
config.mountOptions = []string{"loop"}
127+
}
128+
113129
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
114130
if err != nil {
115131
return nil, err
@@ -123,6 +139,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
123139
root: root,
124140
scratch: scratch,
125141
fsType: config.fsType,
142+
options: config.mountOptions,
126143
ms: ms,
127144
}, nil
128145
}
@@ -356,10 +373,8 @@ func (o *snapshotter) getBlockFile(id string) string {
356373

357374
func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount {
358375
var (
359-
mountOptions = []string{
360-
"loop",
361-
}
362-
source string
376+
mountOptions = o.options
377+
source string
363378
)
364379

365380
if s.Kind == snapshots.KindView {

snapshots/blockfile/blockfile_loopsetup_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func setupSnapshotter(t *testing.T) ([]Opt, error) {
6666

6767
return []Opt{
6868
WithScratchFile(scratch),
69+
WithFSType("ext4"),
70+
WithMountOptions([]string{"loop", "sync"}),
6971
}, nil
7072
}
7173

snapshots/blockfile/plugin/plugin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type Config struct {
3434

3535
// FSType is the filesystem type for the mount
3636
FSType string `toml:"fs_type"`
37+
38+
// MountOptions are options used for the mount
39+
MountOptions []string `toml:"mount_options"`
3740
}
3841

3942
func init() {
@@ -60,6 +63,9 @@ func init() {
6063
if config.FSType != "" {
6164
opts = append(opts, blockfile.WithFSType(config.FSType))
6265
}
66+
if len(config.MountOptions) > 0 {
67+
opts = append(opts, blockfile.WithMountOptions(config.MountOptions))
68+
}
6369

6470
return blockfile.NewSnapshotter(root, opts...)
6571
},

0 commit comments

Comments
 (0)