mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Implement Sync() to directories
Updates #1035, #1199 PiperOrigin-RevId: 317028108
This commit is contained in:
committed by
gVisor bot
parent
22b0bb2138
commit
6e0c170522
@@ -299,3 +299,8 @@ func (fd *directoryFD) Seek(ctx context.Context, offset int64, whence int32) (in
|
||||
return 0, syserror.EINVAL
|
||||
}
|
||||
}
|
||||
|
||||
// Sync implements vfs.FileDescriptionImpl.Sync.
|
||||
func (fd *directoryFD) Sync(ctx context.Context) error {
|
||||
return fd.dentry().handle.sync(ctx)
|
||||
}
|
||||
|
||||
@@ -690,7 +690,8 @@ func (f *fileDescription) Seek(_ context.Context, offset int64, whence int32) (i
|
||||
|
||||
// Sync implements FileDescriptionImpl.
|
||||
func (f *fileDescription) Sync(context.Context) error {
|
||||
// TODO(gvisor.dev/issue/1672): Currently we do not support the SyncData optimization, so we always sync everything.
|
||||
// TODO(gvisor.dev/issue/1672): Currently we do not support the SyncData
|
||||
// optimization, so we always sync everything.
|
||||
return unix.Fsync(f.inode.hostFD)
|
||||
}
|
||||
|
||||
|
||||
@@ -263,3 +263,25 @@ func (fd *directoryFD) Seek(ctx context.Context, offset int64, whence int32) (in
|
||||
return 0, syserror.EINVAL
|
||||
}
|
||||
}
|
||||
|
||||
// Sync implements vfs.FileDescriptionImpl.Sync. Forwards sync to the upper
|
||||
// layer, if there is one. The lower layer doesn't need to sync because it
|
||||
// never changes.
|
||||
func (fd *directoryFD) Sync(ctx context.Context) error {
|
||||
d := fd.dentry()
|
||||
if !d.isCopiedUp() {
|
||||
return nil
|
||||
}
|
||||
vfsObj := d.fs.vfsfs.VirtualFilesystem()
|
||||
pop := vfs.PathOperation{
|
||||
Root: d.upperVD,
|
||||
Start: d.upperVD,
|
||||
}
|
||||
upperFD, err := vfsObj.OpenAt(ctx, d.fs.creds, &pop, &vfs.OpenOptions{Flags: linux.O_RDONLY | linux.O_DIRECTORY})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = upperFD.Sync(ctx)
|
||||
upperFD.DecRef()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -360,11 +360,6 @@ func (fd *regularFileFD) Seek(ctx context.Context, offset int64, whence int32) (
|
||||
return offset, nil
|
||||
}
|
||||
|
||||
// Sync implements vfs.FileDescriptionImpl.Sync.
|
||||
func (fd *regularFileFD) Sync(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.
|
||||
func (fd *regularFileFD) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error {
|
||||
file := fd.inode().impl.(*regularFile)
|
||||
|
||||
@@ -778,3 +778,9 @@ func (fd *fileDescription) LockPOSIX(ctx context.Context, uid fslock.UniqueID, t
|
||||
func (fd *fileDescription) UnlockPOSIX(ctx context.Context, uid fslock.UniqueID, start, length uint64, whence int16) error {
|
||||
return fd.Locks().UnlockPOSIX(ctx, &fd.vfsfd, uid, start, length, whence)
|
||||
}
|
||||
|
||||
// Sync implements vfs.FileDescriptionImpl.Sync. It does nothing because all
|
||||
// filesystem state is in-memory.
|
||||
func (*fileDescription) Sync(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user