@@ -44,6 +44,7 @@ const upperdirKey = "containerd.io/snapshot/overlay.upperdir"
4444type SnapshotterConfig struct {
4545 asyncRemove bool
4646 upperdirLabel bool
47+ ms MetaStore
4748 mountOptions []string
4849}
4950
@@ -77,9 +78,24 @@ func WithMountOptions(options []string) Opt {
7778 }
7879}
7980
81+ type MetaStore interface {
82+ TransactionContext (ctx context.Context , writable bool ) (context.Context , storage.Transactor , error )
83+ WithTransaction (ctx context.Context , writable bool , fn storage.TransactionCallback ) error
84+ Close () error
85+ }
86+
87+ // WithMetaStore allows the MetaStore to be created outside the snapshotter
88+ // and passed in.
89+ func WithMetaStore (ms MetaStore ) Opt {
90+ return func (config * SnapshotterConfig ) error {
91+ config .ms = ms
92+ return nil
93+ }
94+ }
95+
8096type snapshotter struct {
8197 root string
82- ms * storage. MetaStore
98+ ms MetaStore
8399 asyncRemove bool
84100 upperdirLabel bool
85101 options []string
@@ -106,9 +122,11 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
106122 if ! supportsDType {
107123 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 )
108124 }
109- ms , err := storage .NewMetaStore (filepath .Join (root , "metadata.db" ))
110- if err != nil {
111- return nil , err
125+ if config .ms == nil {
126+ config .ms , err = storage .NewMetaStore (filepath .Join (root , "metadata.db" ))
127+ if err != nil {
128+ return nil , err
129+ }
112130 }
113131
114132 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) {
132150
133151 return & snapshotter {
134152 root : root ,
135- ms : ms ,
153+ ms : config . ms ,
136154 asyncRemove : config .asyncRemove ,
137155 upperdirLabel : config .upperdirLabel ,
138156 options : config .mountOptions ,
0 commit comments