mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Allow vfs.IterDirentsCallback.Handle() to return an error.
This is easier than storing errors from e.g. CopyOut in the callback. PiperOrigin-RevId: 295230021
This commit is contained in:
@@ -188,14 +188,14 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
childType = fs.ToInodeType(childInode.diskInode.Mode().FileType())
|
||||
}
|
||||
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
if err := cb.Handle(vfs.Dirent{
|
||||
Name: child.diskDirent.FileName(),
|
||||
Type: fs.ToDirentType(childType),
|
||||
Ino: uint64(child.diskDirent.Inode()),
|
||||
NextOff: fd.off + 1,
|
||||
}) {
|
||||
}); err != nil {
|
||||
dir.childList.InsertBefore(child, fd.iter)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
|
||||
@@ -499,9 +499,9 @@ func newIterDirentCb() *iterDirentsCb {
|
||||
}
|
||||
|
||||
// Handle implements vfs.IterDirentsCallback.Handle.
|
||||
func (cb *iterDirentsCb) Handle(dirent vfs.Dirent) bool {
|
||||
func (cb *iterDirentsCb) Handle(dirent vfs.Dirent) error {
|
||||
cb.dirents = append(cb.dirents, dirent)
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestIterDirents tests the FileDescriptionImpl.IterDirents functionality.
|
||||
|
||||
@@ -65,8 +65,8 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
}
|
||||
|
||||
for fd.off < int64(len(fd.dirents)) {
|
||||
if !cb.Handle(fd.dirents[fd.off]) {
|
||||
return nil
|
||||
if err := cb.Handle(fd.dirents[fd.off]); err != nil {
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ func (fd *GenericDirectoryFD) IterDirents(ctx context.Context, cb vfs.IterDirent
|
||||
Ino: stat.Ino,
|
||||
NextOff: 1,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
@@ -132,8 +132,8 @@ func (fd *GenericDirectoryFD) IterDirents(ctx context.Context, cb vfs.IterDirent
|
||||
Ino: stat.Ino,
|
||||
NextOff: 2,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
@@ -153,8 +153,8 @@ func (fd *GenericDirectoryFD) IterDirents(ctx context.Context, cb vfs.IterDirent
|
||||
Ino: stat.Ino,
|
||||
NextOff: fd.off + 1,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ func (i *subtasksInode) IterDirents(ctx context.Context, cb vfs.IterDirentsCallb
|
||||
Ino: i.inoGen.NextIno(),
|
||||
NextOff: offset + 1,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return offset, nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return offset, err
|
||||
}
|
||||
offset++
|
||||
}
|
||||
|
||||
@@ -151,8 +151,8 @@ func (i *tasksInode) IterDirents(ctx context.Context, cb vfs.IterDirentsCallback
|
||||
Ino: i.inoGen.NextIno(),
|
||||
NextOff: offset + 1,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return offset, nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return offset, err
|
||||
}
|
||||
offset++
|
||||
}
|
||||
@@ -163,8 +163,8 @@ func (i *tasksInode) IterDirents(ctx context.Context, cb vfs.IterDirentsCallback
|
||||
Ino: i.inoGen.NextIno(),
|
||||
NextOff: offset + 1,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return offset, nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return offset, err
|
||||
}
|
||||
offset++
|
||||
}
|
||||
@@ -196,8 +196,8 @@ func (i *tasksInode) IterDirents(ctx context.Context, cb vfs.IterDirentsCallback
|
||||
Ino: i.inoGen.NextIno(),
|
||||
NextOff: FIRST_PROCESS_ENTRY + 2 + int64(tid) + 1,
|
||||
}
|
||||
if !cb.Handle(dirent) {
|
||||
return offset, nil
|
||||
if err := cb.Handle(dirent); err != nil {
|
||||
return offset, err
|
||||
}
|
||||
offset++
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ func (d *DirentCollector) SkipDotsChecks(value bool) {
|
||||
}
|
||||
|
||||
// Handle implements vfs.IterDirentsCallback.Handle.
|
||||
func (d *DirentCollector) Handle(dirent vfs.Dirent) bool {
|
||||
func (d *DirentCollector) Handle(dirent vfs.Dirent) error {
|
||||
d.mu.Lock()
|
||||
if d.dirents == nil {
|
||||
d.dirents = make(map[string]*vfs.Dirent)
|
||||
@@ -234,7 +234,7 @@ func (d *DirentCollector) Handle(dirent vfs.Dirent) bool {
|
||||
d.order = append(d.order, &dirent)
|
||||
d.dirents[dirent.Name] = &dirent
|
||||
d.mu.Unlock()
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
// Count returns the number of dirents currently in the collector.
|
||||
|
||||
@@ -74,25 +74,25 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
defer fs.mu.Unlock()
|
||||
|
||||
if fd.off == 0 {
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
if err := cb.Handle(vfs.Dirent{
|
||||
Name: ".",
|
||||
Type: linux.DT_DIR,
|
||||
Ino: vfsd.Impl().(*dentry).inode.ino,
|
||||
NextOff: 1,
|
||||
}) {
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
if fd.off == 1 {
|
||||
parentInode := vfsd.ParentOrSelf().Impl().(*dentry).inode
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
if err := cb.Handle(vfs.Dirent{
|
||||
Name: "..",
|
||||
Type: parentInode.direntType(),
|
||||
Ino: parentInode.ino,
|
||||
NextOff: 2,
|
||||
}) {
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
@@ -111,14 +111,14 @@ func (fd *directoryFD) IterDirents(ctx context.Context, cb vfs.IterDirentsCallba
|
||||
for child != nil {
|
||||
// Skip other directoryFD iterators.
|
||||
if child.inode != nil {
|
||||
if !cb.Handle(vfs.Dirent{
|
||||
if err := cb.Handle(vfs.Dirent{
|
||||
Name: child.vfsd.Name(),
|
||||
Type: child.inode.direntType(),
|
||||
Ino: child.inode.ino,
|
||||
NextOff: fd.off + 1,
|
||||
}) {
|
||||
}); err != nil {
|
||||
dir.childList.InsertBefore(child, fd.iter)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
fd.off++
|
||||
}
|
||||
|
||||
@@ -435,11 +435,11 @@ type Dirent struct {
|
||||
|
||||
// IterDirentsCallback receives Dirents from FileDescriptionImpl.IterDirents.
|
||||
type IterDirentsCallback interface {
|
||||
// Handle handles the given iterated Dirent. It returns true if iteration
|
||||
// should continue, and false if FileDescriptionImpl.IterDirents should
|
||||
// terminate now and restart with the same Dirent the next time it is
|
||||
// called.
|
||||
Handle(dirent Dirent) bool
|
||||
// Handle handles the given iterated Dirent. If Handle returns a non-nil
|
||||
// error, FileDescriptionImpl.IterDirents must stop iteration and return
|
||||
// the error; the next call to FileDescriptionImpl.IterDirents should
|
||||
// restart with the same Dirent.
|
||||
Handle(dirent Dirent) error
|
||||
}
|
||||
|
||||
// OnClose is called when a file descriptor representing the FileDescription is
|
||||
|
||||
Reference in New Issue
Block a user