Skip to content

Commit 14f8000

Browse files
ayushr2gvisor-bot
authored andcommitted
gofer: Improve restore failure messages.
PiperOrigin-RevId: 873032962
1 parent c50105d commit 14f8000

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

pkg/sentry/fsimpl/gofer/directfs_inode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func (i *directfsInode) restoreFile(ctx context.Context, controlFD int, opts *vf
713713
var stat unix.Stat_t
714714
if err := unix.Fstat(controlFD, &stat); err != nil {
715715
_ = unix.Close(controlFD)
716-
return fmt.Errorf("failed to stat %q: %w", genericDebugPathname(i.fs, d), err)
716+
return fmt.Errorf("failed to stat %q in mount %q: %w", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, err)
717717
}
718718
i.controlFD = controlFD
719719
// We do not preserve inoKey across checkpoint/restore, so:
@@ -737,12 +737,12 @@ func (i *directfsInode) restoreFile(ctx context.Context, controlFD int, opts *vf
737737
if i.isRegularFile() {
738738
if opts.ValidateFileSizes {
739739
if i.size.RacyLoad() != uint64(stat.Size) {
740-
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q).restoreFile: file size validation failed: size changed from %d to %d", genericDebugPathname(i.fs, d), i.size.Load(), stat.Size)}
740+
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q in mount %q).restoreFile: file size validation failed: size changed from %d to %d", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, i.size.Load(), stat.Size)}
741741
}
742742
}
743743
if opts.ValidateFileModificationTimestamps {
744744
if want := dentryTimestampFromUnix(stat.Mtim); i.mtime.RacyLoad() != want {
745-
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q).restoreFile: mtime validation failed: mtime changed from %+v to %+v", genericDebugPathname(i.fs, d), linux.NsecToStatxTimestamp(i.mtime.RacyLoad()), linux.NsecToStatxTimestamp(want))}
745+
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q in mount %q).restoreFile: mtime validation failed: mtime changed from %+v to %+v", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, linux.NsecToStatxTimestamp(i.mtime.RacyLoad()), linux.NsecToStatxTimestamp(want))}
746746
}
747747
}
748748
}
@@ -752,7 +752,7 @@ func (i *directfsInode) restoreFile(ctx context.Context, controlFD int, opts *vf
752752

753753
if rw, ok := i.fs.savedDentryRW[d]; ok {
754754
if err := d.ensureSharedHandle(ctx, rw.read, rw.write, false /* trunc */); err != nil {
755-
return fmt.Errorf("failed to restore file handles (read=%t, write=%t) for %q: %w", rw.read, rw.write, genericDebugPathname(i.fs, d), err)
755+
return fmt.Errorf("failed to restore file handles (read=%t, write=%t) for %q in mount %q: %w", rw.read, rw.write, genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, err)
756756
}
757757
}
758758

pkg/sentry/fsimpl/gofer/inode_impl.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ func (i *inode) statfs(ctx context.Context) (linux.Statfs, error) {
520520
func (fs *filesystem) restoreRoot(ctx context.Context, opts *vfs.CompleteRestoreOptions) error {
521521
rootInode, rootHostFD, err := fs.initClientAndGetRoot(ctx)
522522
if err != nil {
523-
return fmt.Errorf("failed to initialize client and get root: %w", err)
523+
return fmt.Errorf("failed to initialize client and get root in mount %q: %w", fs.iopts.UniqueID, err)
524524
}
525525

526526
// The root is always non-synthetic.
@@ -551,14 +551,14 @@ func (d *dentry) restoreFile(ctx context.Context, opts *vfs.CompleteRestoreOptio
551551
inode, err := controlFD.Walk(ctx, d.name)
552552
if err != nil {
553553
if !d.isDir() || !d.forMountpoint {
554-
return fmt.Errorf("failed to walk %q of type %x: %w", genericDebugPathname(it.fs, d), it.inode.fileType(), err)
554+
return fmt.Errorf("failed to walk %q of type %#o in mount %q: %w", genericDebugPathname(it.fs, d), linux.FileMode(it.inode.fileType()), it.fs.iopts.UniqueID, err)
555555
}
556556

557557
// Recreate directories that were created during volume mounting, since
558558
// during restore we don't attempt to remount them.
559559
inode, err = controlFD.MkdirAt(ctx, d.name, linux.FileMode(it.mode.Load()), lisafs.UID(it.uid.Load()), lisafs.GID(it.gid.Load()))
560560
if err != nil {
561-
return fmt.Errorf("failed to create mountpoint directory at %q: %w", genericDebugPathname(it.fs, d), err)
561+
return fmt.Errorf("failed to create mountpoint directory at %q in mount %q: %w", genericDebugPathname(it.fs, d), it.fs.iopts.UniqueID, err)
562562
}
563563
}
564564
return it.restoreInode(ctx, &inode, opts, d)
@@ -577,21 +577,21 @@ func (d *dentry) restoreFile(ctx context.Context, opts *vfs.CompleteRestoreOptio
577577
})
578578
if err != nil {
579579
if !d.isDir() || !d.forMountpoint {
580-
return fmt.Errorf("failed to walk %q of type %x: %w", genericDebugPathname(it.fs, d), it.inode.fileType(), err)
580+
return fmt.Errorf("failed to walk %q of type %#o in mount %q: %w", genericDebugPathname(it.fs, d), linux.FileMode(it.inode.fileType()), it.fs.iopts.UniqueID, err)
581581
}
582582

583583
// Recreate directories that were created during volume mounting, since
584584
// during restore we don't attempt to remount them.
585585
if err := unix.Mkdirat(controlFD, d.name, it.mode.Load()); err != nil {
586-
return fmt.Errorf("failed to create mountpoint directory at %q: %w", genericDebugPathname(it.fs, d), err)
586+
return fmt.Errorf("failed to create mountpoint directory at %q in mount %q: %w", genericDebugPathname(it.fs, d), it.fs.iopts.UniqueID, err)
587587
}
588588

589589
// Try again...
590590
childFD, err = tryOpen(func(flags int) (int, error) {
591591
return unix.Openat(controlFD, d.name, flags, 0)
592592
})
593593
if err != nil {
594-
return fmt.Errorf("failed to open %q: %w", genericDebugPathname(it.fs, d), err)
594+
return fmt.Errorf("failed to open %q in mount %q: %w", genericDebugPathname(it.fs, d), it.fs.iopts.UniqueID, err)
595595
}
596596
}
597597
return it.restoreFile(ctx, childFD, opts, d)

pkg/sentry/fsimpl/gofer/lisafs_inode.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,18 @@ func (i *lisafsInode) restoreInode(ctx context.Context, inode *lisafs.Inode, opt
628628
if i.isRegularFile() {
629629
if opts.ValidateFileSizes {
630630
if inode.Stat.Mask&linux.STATX_SIZE == 0 {
631-
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q).restoreFile: file size validation failed: file size not available", genericDebugPathname(i.fs, d))}
631+
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q in mount %q).restoreFile: file size validation failed: file size not available", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID)}
632632
}
633633
if i.size.RacyLoad() != inode.Stat.Size {
634-
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q).restoreFile: file size validation failed: size changed from %d to %d", genericDebugPathname(i.fs, d), i.size.Load(), inode.Stat.Size)}
634+
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q in mount %q).restoreFile: file size validation failed: size changed from %d to %d", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, i.size.Load(), inode.Stat.Size)}
635635
}
636636
}
637637
if opts.ValidateFileModificationTimestamps {
638638
if inode.Stat.Mask&linux.STATX_MTIME == 0 {
639-
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q).restoreFile: mtime validation failed: mtime not available", genericDebugPathname(i.fs, d))}
639+
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q in mount %q).restoreFile: mtime validation failed: mtime not available", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID)}
640640
}
641641
if want := dentryTimestamp(inode.Stat.Mtime); i.mtime.RacyLoad() != want {
642-
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q).restoreFile: mtime validation failed: mtime changed from %+v to %+v", genericDebugPathname(i.fs, d), linux.NsecToStatxTimestamp(i.mtime.RacyLoad()), linux.NsecToStatxTimestamp(want))}
642+
return vfs.ErrCorruption{Err: fmt.Errorf("gofer.dentry(%q in mount %q).restoreFile: mtime validation failed: mtime changed from %+v to %+v", genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, linux.NsecToStatxTimestamp(i.mtime.RacyLoad()), linux.NsecToStatxTimestamp(want))}
643643
}
644644
}
645645
}
@@ -649,7 +649,7 @@ func (i *lisafsInode) restoreInode(ctx context.Context, inode *lisafs.Inode, opt
649649

650650
if rw, ok := i.fs.savedDentryRW[d]; ok {
651651
if err := d.ensureSharedHandle(ctx, rw.read, rw.write, false /* trunc */); err != nil {
652-
return fmt.Errorf("failed to restore file handles (read=%t, write=%t) for %q: %w", rw.read, rw.write, genericDebugPathname(i.fs, d), err)
652+
return fmt.Errorf("failed to restore file handles (read=%t, write=%t) for %q in mount %q: %w", rw.read, rw.write, genericDebugPathname(i.fs, d), i.fs.iopts.UniqueID, err)
653653
}
654654
}
655655

0 commit comments

Comments
 (0)