Ensure that files created after save are visible after restore.

PiperOrigin-RevId: 615197421
This commit is contained in:
Jamie Liu
2024-03-12 15:50:03 -07:00
committed by gVisor bot
parent 075a9df798
commit f82d927772
2 changed files with 19 additions and 12 deletions
+9 -7
View File
@@ -833,15 +833,17 @@ type dentry struct {
children map[string]*dentry
// If this dentry represents a directory, negativeChildrenCache cache
// names of negative children.
// names of negative children. negativeChildrenCache is not saved since
// dentry.prepareSaveRecursive() drops all negative children.
//
// +checklocks:childrenMu
negativeChildrenCache stringFixedCache
// If this dentry represents a directory, negativeChildren is the number
// of negative children cached in dentry.children
negativeChildrenCache stringFixedCache `state:"nosave"`
// If this dentry represents a directory, negativeChildren is the number of
// negative children cached in dentry.children. negativeChildren is not
// saved since dentry.prepareSaveRecursive() drops all negative children.
//
// +checklocks:childrenMu
negativeChildren int
negativeChildren int `state:"nosave"`
// If this dentry represents a directory, syntheticChildren is the number
// of child dentries for which dentry.isSynthetic() == true.
@@ -857,9 +859,9 @@ type dentry struct {
// childrenSet share the same lifecycle.
//
// +checklocks:childrenMu
dirents []vfs.Dirent
dirents []vfs.Dirent `state:"nosave"`
// +checklocks:childrenMu
childrenSet map[string]struct{}
childrenSet map[string]struct{} `state:"nosave"`
// Cached metadata; protected by metadataMu.
// To access:
+10 -5
View File
@@ -111,11 +111,16 @@ func (d *dentry) prepareSaveRecursive(ctx context.Context) error {
}
d.childrenMu.Lock()
defer d.childrenMu.Unlock()
for _, child := range d.children {
if child != nil {
if err := child.prepareSaveRecursive(ctx); err != nil {
return err
}
for childName, child := range d.children {
if child == nil {
// Unsaved filesystem state may change across save/restore. Remove
// negative entries from d.children to ensure that files created
// after save are visible after restore.
delete(d.children, childName)
continue
}
if err := child.prepareSaveRecursive(ctx); err != nil {
return err
}
}
return nil