Fix lisafs client bugs for S/R support.

- There was a bug in checking for the availability of STATX_SIZE on restore.
- Make the gofer client resilient to bad open(flags). Like 9P, make lisafs
  default to O_RDONLY when a valid open mode is not available.

PiperOrigin-RevId: 429705352
This commit is contained in:
Ayush Ranjan
2022-02-18 21:06:33 -08:00
committed by gVisor bot
parent 492ea1a04e
commit e4f093f7b1
2 changed files with 7 additions and 4 deletions
+6 -3
View File
@@ -18,6 +18,7 @@ import (
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/lisafs"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/p9"
"gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/hostfd"
@@ -42,7 +43,7 @@ func openHandle(ctx context.Context, file p9file, read, write, trunc bool) (hand
if err != nil {
return handle{fd: -1}, err
}
var flags p9.OpenFlags
flags := p9.ReadOnly
switch {
case read && !write:
flags = p9.ReadOnly
@@ -50,6 +51,8 @@ func openHandle(ctx context.Context, file p9file, read, write, trunc bool) (hand
flags = p9.WriteOnly
case read && write:
flags = p9.ReadWrite
default:
log.Debugf("openHandle called with read = write = false. Falling back to read only FD.")
}
if trunc {
flags |= p9.OpenTruncate
@@ -71,7 +74,7 @@ func openHandle(ctx context.Context, file p9file, read, write, trunc bool) (hand
// Preconditions: read || write.
func openHandleLisa(ctx context.Context, fdLisa lisafs.ClientFD, read, write, trunc bool) (handle, error) {
var flags uint32
flags := uint32(unix.O_RDONLY)
switch {
case read && write:
flags = unix.O_RDWR
@@ -80,7 +83,7 @@ func openHandleLisa(ctx context.Context, fdLisa lisafs.ClientFD, read, write, tr
case write:
flags = unix.O_WRONLY
default:
panic("tried to open unreadable and unwritable handle")
log.Debugf("openHandleLisa called with read = write = false. Falling back to read only FD.")
}
if trunc {
flags |= unix.O_TRUNC
+1 -1
View File
@@ -325,7 +325,7 @@ func (d *dentry) restoreFileLisa(ctx context.Context, inode *lisafs.Inode, opts
defer d.metadataMu.Unlock()
if d.isRegularFile() {
if opts.ValidateFileSizes {
if inode.Stat.Mask&linux.STATX_SIZE != 0 {
if inode.Stat.Mask&linux.STATX_SIZE == 0 {
return vfs.ErrCorruption{fmt.Errorf("gofer.dentry(%q).restoreFile: file size validation failed: file size not available", genericDebugPathname(d))}
}
if d.size != inode.Stat.Size {