Add WithMetaStore to overlay snapshotter to allow bringing your own
Signed-off-by: Robbie Buxton <138501839+rbpdt@users.noreply.github.com>
This commit is contained in:
parent
6eb90a63e0
commit
23c95359aa
@ -44,6 +44,7 @@ const upperdirKey = "containerd.io/snapshot/overlay.upperdir"
|
|||||||
type SnapshotterConfig struct {
|
type SnapshotterConfig struct {
|
||||||
asyncRemove bool
|
asyncRemove bool
|
||||||
upperdirLabel bool
|
upperdirLabel bool
|
||||||
|
ms MetaStore
|
||||||
mountOptions []string
|
mountOptions []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,9 +78,24 @@ func WithMountOptions(options []string) Opt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MetaStore interface {
|
||||||
|
TransactionContext(ctx context.Context, writable bool) (context.Context, storage.Transactor, error)
|
||||||
|
WithTransaction(ctx context.Context, writable bool, fn storage.TransactionCallback) error
|
||||||
|
Close() error
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMetaStore allows the MetaStore to be created outside the snapshotter
|
||||||
|
// and passed in.
|
||||||
|
func WithMetaStore(ms MetaStore) Opt {
|
||||||
|
return func(config *SnapshotterConfig) error {
|
||||||
|
config.ms = ms
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type snapshotter struct {
|
type snapshotter struct {
|
||||||
root string
|
root string
|
||||||
ms *storage.MetaStore
|
ms MetaStore
|
||||||
asyncRemove bool
|
asyncRemove bool
|
||||||
upperdirLabel bool
|
upperdirLabel bool
|
||||||
options []string
|
options []string
|
||||||
@ -106,9 +122,11 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
|
|||||||
if !supportsDType {
|
if !supportsDType {
|
||||||
return nil, fmt.Errorf("%s does not support d_type. If the backing filesystem is xfs, please reformat with ftype=1 to enable d_type support", root)
|
return nil, fmt.Errorf("%s does not support d_type. If the backing filesystem is xfs, please reformat with ftype=1 to enable d_type support", root)
|
||||||
}
|
}
|
||||||
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
|
if config.ms == nil {
|
||||||
if err != nil {
|
config.ms, err = storage.NewMetaStore(filepath.Join(root, "metadata.db"))
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
|
if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
|
||||||
@ -132,7 +150,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
|
|||||||
|
|
||||||
return &snapshotter{
|
return &snapshotter{
|
||||||
root: root,
|
root: root,
|
||||||
ms: ms,
|
ms: config.ms,
|
||||||
asyncRemove: config.asyncRemove,
|
asyncRemove: config.asyncRemove,
|
||||||
upperdirLabel: config.upperdirLabel,
|
upperdirLabel: config.upperdirLabel,
|
||||||
options: config.mountOptions,
|
options: config.mountOptions,
|
||||||
|
Loading…
Reference in New Issue
Block a user