@@ -63,20 +63,8 @@ type filesystem struct {
6363 vfsfs vfs.Filesystem
6464
6565 // mf is used to allocate memory that stores regular file contents. mf is
66- // immutable, except it may to changed during restore.
67- mf * pgalloc.MemoryFile `state:"nosave"`
68-
69- // privateMF indicates whether mf is private to this tmpfs mount. If so,
70- // tmpfs takes ownership of mf. privateMF is immutable.
71- privateMF bool
72-
73- // uniqueID is an opaque string used to reassociate the filesystem with its
74- // private MemoryFile during checkpoint and restore.
75- uniqueID vfs.RestoreID
76-
77- // mfp is used to provide mf, when privateMF == false. This is required to
78- // re-provide mf on restore. mfp is immutable.
79- mfp pgalloc.MemoryFileProvider
66+ // immutable, except it is changed during restore.
67+ mf * pgalloc.MemoryFile `state:".(string)"`
8068
8169 // clock is a realtime clock used to set timestamps in file operations.
8270 clock time.Clock
@@ -156,10 +144,6 @@ type FilesystemOpts struct {
156144 // AllowXattrPrefix is a set of xattr namespace prefixes that this
157145 // tmpfs mount will allow.
158146 AllowXattrPrefix []string
159-
160- // If UniqueID is non-empty, it is an opaque string used to reassociate the
161- // filesystem with its private MemoryFile during checkpoint and restore.
162- UniqueID vfs.RestoreID
163147}
164148
165149// Default size limit mount option. It is immutable after initialization.
@@ -186,13 +170,10 @@ func getDefaultSizeLimit(disable bool) uint64 {
186170
187171// GetFilesystem implements vfs.FilesystemType.GetFilesystem.
188172func (fstype FilesystemType ) GetFilesystem (ctx context.Context , vfsObj * vfs.VirtualFilesystem , creds * auth.Credentials , _ string , opts vfs.GetFilesystemOptions ) (* vfs.Filesystem , * vfs.Dentry , error ) {
189- mfp := pgalloc .MemoryFileProviderFromContext (ctx )
190- if mfp == nil {
191- panic ("MemoryFileProviderFromContext returned nil" )
173+ mf := pgalloc .MemoryFileFromContext (ctx )
174+ if mf == nil {
175+ panic ("CtxMemoryFile returned nil" )
192176 }
193- mf := mfp .MemoryFile ()
194- privateMF := false
195- var uniqueID vfs.RestoreID
196177 rootFileType := uint16 (linux .S_IFDIR )
197178 disableDefaultSizeLimit := false
198179 newFSType := vfs .FilesystemType (& fstype )
@@ -218,17 +199,11 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
218199 disableDefaultSizeLimit = tmpfsOpts .DisableDefaultSizeLimit
219200 if tmpfsOpts .MemoryFile != nil {
220201 mf = tmpfsOpts .MemoryFile
221- privateMF = true
222202 }
223- uniqueID = tmpfsOpts .UniqueID
224203 for _ , xattr := range tmpfsOpts .AllowXattrPrefix {
225204 allowXattrPrefix [xattr ] = struct {}{}
226205 }
227206 }
228- if privateMF && len (uniqueID .Path ) == 0 {
229- ctx .Warningf ("tmpfs.FilesystemType.GetFilesystem: privateMF requires uniqueID to be set" )
230- return nil , nil , linuxerr .EINVAL
231- }
232207
233208 mopts := vfs .GenericParseMountOptions (opts .Data )
234209 rootMode := linux .FileMode (0777 )
@@ -311,9 +286,6 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
311286 }
312287 fs := filesystem {
313288 mf : mf ,
314- privateMF : privateMF ,
315- uniqueID : uniqueID ,
316- mfp : mfp ,
317289 clock : clock ,
318290 devMinor : devMinor ,
319291 mopts : opts .Data ,
@@ -351,7 +323,9 @@ func (fs *filesystem) Release(ctx context.Context) {
351323 fs .root .releaseChildrenLocked (ctx )
352324 }
353325 fs .mu .Unlock ()
354- if fs .privateMF {
326+ if fs .mf .RestoreID () != "" {
327+ // If RestoreID is set, then this is a private MemoryFile which needs to be
328+ // destroyed since this tmpfs is the only user.
355329 fs .mf .Destroy ()
356330 }
357331}
0 commit comments