pipe

package
v0.0.0-...-4bf4b70 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2021 License: Apache-2.0, MIT Imports: 21 Imported by: 0

Documentation

Overview

Package pipe provides a pipe implementation.

Index

Constants

View Source
const (
	// MinimumPipeSize is a hard limit of the minimum size of a pipe.
	// It corresponds to fs/pipe.c:pipe_min_size.
	MinimumPipeSize = usermem.PageSize

	// MaximumPipeSize is a hard limit on the maximum size of a pipe.
	// It corresponds to fs/pipe.c:pipe_max_size.
	MaximumPipeSize = 1048576

	// DefaultPipeSize is the system-wide default size of a pipe in bytes.
	// It corresponds to pipe_fs_i.h:PIPE_DEF_BUFFERS.
	DefaultPipeSize = 16 * usermem.PageSize
)

Variables

This section is empty.

Functions

func NewConnectedPipe

func NewConnectedPipe(ctx context.Context, sizeBytes int64) (*fs.File, *fs.File)

NewConnectedPipe initializes a pipe and returns a pair of objects representing the read and write ends of the pipe.

func NewInodeOperations

func NewInodeOperations(ctx context.Context, perms fs.FilePermissions, p *Pipe) *inodeOperations

NewInodeOperations returns a new fs.InodeOperations for a given pipe.

func Splice

func Splice(ctx context.Context, dst, src *VFSPipeFD, count int64) (int64, error)

Splice reads up to count bytes from src and writes them to dst. It returns the number of bytes moved.

Preconditions: count > 0.

func Tee

func Tee(ctx context.Context, dst, src *VFSPipeFD, count int64) (int64, error)

Tee reads up to count bytes from src and writes them to dst, without removing the read bytes from src. It returns the number of bytes copied.

Preconditions: count > 0.

Types

type Pipe

type Pipe struct {
	waiter.Queue `state:"nosave"`
	// contains filtered or unexported fields
}

Pipe is an encapsulation of a platform-independent pipe. It manages a buffered byte queue shared between a reader/writer pair.

+stateify savable

func NewPipe

func NewPipe(isNamed bool, sizeBytes int64) *Pipe

NewPipe initializes and returns a pipe.

N.B. The size will be bounded.

func (*Pipe) FifoSize

func (p *Pipe) FifoSize(context.Context, *fs.File) (int64, error)

FifoSize implements fs.FifoSizer.FifoSize.

func (*Pipe) HasReaders

func (p *Pipe) HasReaders() bool

HasReaders returns whether the pipe has any active readers.

func (*Pipe) HasWriters

func (p *Pipe) HasWriters() bool

HasWriters returns whether the pipe has any active writers.

func (*Pipe) Ioctl

func (p *Pipe) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error)

Ioctl implements ioctls on the Pipe.

func (*Pipe) Open

func (p *Pipe) Open(ctx context.Context, d *fs.Dirent, flags fs.FileFlags) *fs.File

Open opens the pipe and returns a new file.

Precondition: at least one of flags.Read or flags.Write must be set.

func (*Pipe) Read

func (p *Pipe) Read(ctx context.Context, dst usermem.IOSequence) (int64, error)

Read reads from the Pipe into dst.

func (*Pipe) ReadFrom

func (p *Pipe) ReadFrom(ctx context.Context, r io.Reader, count int64) (int64, error)

ReadFrom reads from r to the Pipe.

func (*Pipe) ReadToBlocks

func (p *Pipe) ReadToBlocks(dsts safemem.BlockSeq) (uint64, error)

ReadToBlocks implements safemem.Reader.ReadToBlocks for Pipe.Read.

func (*Pipe) Readiness

func (p *Pipe) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*Pipe) Release

func (p *Pipe) Release(context.Context)

Release cleans up the pipe's state.

func (*Pipe) SetFifoSize

func (p *Pipe) SetFifoSize(size int64) (int64, error)

SetFifoSize implements fs.FifoSizer.SetFifoSize.

func (*Pipe) StateFields

func (p *Pipe) StateFields() []string

func (*Pipe) StateLoad

func (p *Pipe) StateLoad(stateSourceObject state.Source)

func (*Pipe) StateSave

func (p *Pipe) StateSave(stateSinkObject state.Sink)

func (*Pipe) StateTypeName

func (p *Pipe) StateTypeName() string

func (*Pipe) Write

func (p *Pipe) Write(ctx context.Context, src usermem.IOSequence) (int64, error)

Write writes to the Pipe from src.

func (*Pipe) WriteFromBlocks

func (p *Pipe) WriteFromBlocks(srcs safemem.BlockSeq) (uint64, error)

WriteFromBlocks implements safemem.Writer.WriteFromBlocks for Pipe.Write.

func (*Pipe) WriteTo

func (p *Pipe) WriteTo(ctx context.Context, w io.Writer, count int64, dup bool) (int64, error)

WriteTo writes to w from the Pipe.

type Reader

type Reader struct {
	ReaderWriter
}

Reader satisfies the fs.FileOperations interface for read-only pipes. Reader should be used with !fs.FileFlags.Write to reject writes.

+stateify savable

func (*Reader) Readiness

func (r *Reader) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*Reader) Release

func (r *Reader) Release(context.Context)

Release implements fs.FileOperations.Release.

This overrides ReaderWriter.Release.

func (*Reader) StateFields

func (r *Reader) StateFields() []string

func (*Reader) StateLoad

func (r *Reader) StateLoad(stateSourceObject state.Source)

func (*Reader) StateSave

func (r *Reader) StateSave(stateSinkObject state.Sink)

func (*Reader) StateTypeName

func (r *Reader) StateTypeName() string

type ReaderWriter

type ReaderWriter struct {
	fsutil.FilePipeSeek             `state:"nosave"`
	fsutil.FileNotDirReaddir        `state:"nosave"`
	fsutil.FileNoFsync              `state:"nosave"`
	fsutil.FileNoMMap               `state:"nosave"`
	fsutil.FileNoSplice             `state:"nosave"`
	fsutil.FileNoopFlush            `state:"nosave"`
	fsutil.FileUseInodeUnstableAttr `state:"nosave"`
	*Pipe
}

ReaderWriter satisfies the FileOperations interface and services both read and write requests. This should only be used directly for named pipes. pipe(2) and pipe2(2) only support unidirectional pipes and should use either pipe.Reader or pipe.Writer.

+stateify savable

func (*ReaderWriter) Ioctl

func (rw *ReaderWriter) Ioctl(ctx context.Context, _ *fs.File, io usermem.IO, args arch.SyscallArguments) (uintptr, error)

Ioctl implements fs.FileOperations.Ioctl.

func (*ReaderWriter) Read

func (rw *ReaderWriter) Read(ctx context.Context, _ *fs.File, dst usermem.IOSequence, _ int64) (int64, error)

Read implements fs.FileOperations.Read.

func (*ReaderWriter) ReadFrom

func (rw *ReaderWriter) ReadFrom(ctx context.Context, _ *fs.File, r io.Reader, count int64) (int64, error)

ReadFrom implements fs.FileOperations.WriteTo.

func (*ReaderWriter) StateFields

func (rw *ReaderWriter) StateFields() []string

func (*ReaderWriter) StateLoad

func (rw *ReaderWriter) StateLoad(stateSourceObject state.Source)

func (*ReaderWriter) StateSave

func (rw *ReaderWriter) StateSave(stateSinkObject state.Sink)

func (*ReaderWriter) StateTypeName

func (rw *ReaderWriter) StateTypeName() string

func (*ReaderWriter) Write

func (rw *ReaderWriter) Write(ctx context.Context, _ *fs.File, src usermem.IOSequence, _ int64) (int64, error)

Write implements fs.FileOperations.Write.

func (*ReaderWriter) WriteTo

func (rw *ReaderWriter) WriteTo(ctx context.Context, _ *fs.File, w io.Writer, count int64, dup bool) (int64, error)

WriteTo implements fs.FileOperations.WriteTo.

type VFSPipe

type VFSPipe struct {
	// contains filtered or unexported fields
}

VFSPipe represents the actual pipe, analagous to an inode. VFSPipes should not be copied.

+stateify savable

func NewVFSPipe

func NewVFSPipe(isNamed bool, sizeBytes int64) *VFSPipe

NewVFSPipe returns an initialized VFSPipe.

func (*VFSPipe) Allocate

Allocate implements vfs.FileDescriptionImpl.Allocate.

func (*VFSPipe) Open

func (vp *VFSPipe) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, statusFlags uint32, locks *vfs.FileLocks) (*vfs.FileDescription, error)

Open opens the pipe represented by vp.

func (*VFSPipe) ReaderWriterPair

func (vp *VFSPipe) ReaderWriterPair(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, statusFlags uint32) (*vfs.FileDescription, *vfs.FileDescription, error)

ReaderWriterPair returns read-only and write-only FDs for vp.

Preconditions: statusFlags should not contain an open access mode.

func (*VFSPipe) StateFields

func (vp *VFSPipe) StateFields() []string

func (*VFSPipe) StateLoad

func (vp *VFSPipe) StateLoad(stateSourceObject state.Source)

func (*VFSPipe) StateSave

func (vp *VFSPipe) StateSave(stateSinkObject state.Sink)

func (*VFSPipe) StateTypeName

func (vp *VFSPipe) StateTypeName() string

type VFSPipeFD

type VFSPipeFD struct {
	vfs.FileDescriptionDefaultImpl
	vfs.DentryMetadataFileDescriptionImpl
	vfs.LockFD
	// contains filtered or unexported fields
}

VFSPipeFD implements vfs.FileDescriptionImpl for pipes. It also implements non-atomic usermem.IO methods, allowing it to be passed as usermem.IO to other FileDescriptions for splice(2) and tee(2).

+stateify savable

func (*VFSPipeFD) Allocate

func (fd *VFSPipeFD) Allocate(ctx context.Context, mode, offset, length uint64) error

Allocate implements vfs.FileDescriptionImpl.Allocate.

func (*VFSPipeFD) CompareAndSwapUint32

func (fd *VFSPipeFD) CompareAndSwapUint32(ctx context.Context, addr usermem.Addr, old, new uint32, opts usermem.IOOpts) (uint32, error)

CompareAndSwapUint32 implements usermem.IO.CompareAndSwapUint32.

func (*VFSPipeFD) CopyIn

func (fd *VFSPipeFD) CopyIn(ctx context.Context, addr usermem.Addr, dst []byte, opts usermem.IOOpts) (int, error)

CopyIn implements usermem.IO.CopyIn. Note that it is the caller's responsibility to call fd.pipe.consumeLocked() and fd.pipe.Notify(waiter.EventOut) after the read is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) CopyInTo

func (fd *VFSPipeFD) CopyInTo(ctx context.Context, ars usermem.AddrRangeSeq, dst safemem.Writer, opts usermem.IOOpts) (int64, error)

CopyInTo implements usermem.IO.CopyInTo. Note that it is the caller's responsibility to call fd.pipe.consumeLocked() and fd.pipe.Notify(waiter.EventOut) after the read is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) CopyOut

func (fd *VFSPipeFD) CopyOut(ctx context.Context, addr usermem.Addr, src []byte, opts usermem.IOOpts) (int, error)

CopyOut implements usermem.IO.CopyOut. Note that it is the caller's responsibility to call fd.pipe.Notify(waiter.EventIn) after the write is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) CopyOutFrom

func (fd *VFSPipeFD) CopyOutFrom(ctx context.Context, ars usermem.AddrRangeSeq, src safemem.Reader, opts usermem.IOOpts) (int64, error)

CopyOutFrom implements usermem.IO.CopyOutFrom.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) EventRegister

func (fd *VFSPipeFD) EventRegister(e *waiter.Entry, mask waiter.EventMask)

EventRegister implements waiter.Waitable.EventRegister.

func (*VFSPipeFD) EventUnregister

func (fd *VFSPipeFD) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

func (*VFSPipeFD) Ioctl

func (fd *VFSPipeFD) Ioctl(ctx context.Context, uio usermem.IO, args arch.SyscallArguments) (uintptr, error)

Ioctl implements vfs.FileDescriptionImpl.Ioctl.

func (*VFSPipeFD) LoadUint32

func (fd *VFSPipeFD) LoadUint32(ctx context.Context, addr usermem.Addr, opts usermem.IOOpts) (uint32, error)

LoadUint32 implements usermem.IO.LoadUint32.

func (*VFSPipeFD) PipeSize

func (fd *VFSPipeFD) PipeSize() int64

PipeSize implements fcntl(F_GETPIPE_SZ).

func (*VFSPipeFD) Read

Read implements vfs.FileDescriptionImpl.Read.

func (*VFSPipeFD) Readiness

func (fd *VFSPipeFD) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements waiter.Waitable.Readiness.

func (*VFSPipeFD) Release

func (fd *VFSPipeFD) Release(context.Context)

Release implements vfs.FileDescriptionImpl.Release.

func (*VFSPipeFD) SetPipeSize

func (fd *VFSPipeFD) SetPipeSize(size int64) (int64, error)

SetPipeSize implements fcntl(F_SETPIPE_SZ).

func (*VFSPipeFD) SpliceFromNonPipe

func (fd *VFSPipeFD) SpliceFromNonPipe(ctx context.Context, in *vfs.FileDescription, off, count int64) (int64, error)

SpliceFromNonPipe performs a splice operation from a non-pipe file to fd.

func (*VFSPipeFD) SpliceToNonPipe

func (fd *VFSPipeFD) SpliceToNonPipe(ctx context.Context, out *vfs.FileDescription, off, count int64) (int64, error)

SpliceToNonPipe performs a splice operation from fd to a non-pipe file.

func (*VFSPipeFD) StateFields

func (fd *VFSPipeFD) StateFields() []string

func (*VFSPipeFD) StateLoad

func (fd *VFSPipeFD) StateLoad(stateSourceObject state.Source)

func (*VFSPipeFD) StateSave

func (fd *VFSPipeFD) StateSave(stateSinkObject state.Sink)

func (*VFSPipeFD) StateTypeName

func (fd *VFSPipeFD) StateTypeName() string

func (*VFSPipeFD) SwapUint32

func (fd *VFSPipeFD) SwapUint32(ctx context.Context, addr usermem.Addr, new uint32, opts usermem.IOOpts) (uint32, error)

SwapUint32 implements usermem.IO.SwapUint32.

func (*VFSPipeFD) Write

Write implements vfs.FileDescriptionImpl.Write.

func (*VFSPipeFD) ZeroOut

func (fd *VFSPipeFD) ZeroOut(ctx context.Context, addr usermem.Addr, toZero int64, opts usermem.IOOpts) (int64, error)

ZeroOut implements usermem.IO.ZeroOut.

Preconditions: fd.pipe.mu must be locked.

type Writer

type Writer struct {
	ReaderWriter
}

Writer satisfies the fs.FileOperations interface for write-only pipes. Writer should be used with !fs.FileFlags.Read to reject reads.

+stateify savable

func (*Writer) Readiness

func (w *Writer) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*Writer) Release

func (w *Writer) Release(context.Context)

Release implements fs.FileOperations.Release.

This overrides ReaderWriter.Release.

func (*Writer) StateFields

func (w *Writer) StateFields() []string

func (*Writer) StateLoad

func (w *Writer) StateLoad(stateSourceObject state.Source)

func (*Writer) StateSave

func (w *Writer) StateSave(stateSinkObject state.Sink)

func (*Writer) StateTypeName

func (w *Writer) StateTypeName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL