mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
[syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal. New hostarch package contains code not dependent on syserror. PiperOrigin-RevId: 365651233
This commit is contained in:
committed by
gVisor bot
parent
b125afba41
commit
8a2f7e716d
@@ -46,6 +46,7 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/context",
|
||||
"//pkg/hostarch",
|
||||
"//pkg/log",
|
||||
"//pkg/marshal",
|
||||
"//pkg/refs",
|
||||
@@ -75,6 +76,7 @@ go_test(
|
||||
library = ":fuse",
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/hostarch",
|
||||
"//pkg/marshal",
|
||||
"//pkg/sentry/fsimpl/testutil",
|
||||
"//pkg/sentry/kernel",
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
// ReadInPages sends FUSE_READ requests for the size after round it up to
|
||||
@@ -43,10 +43,10 @@ func (fs *filesystem) ReadInPages(ctx context.Context, fd *regularFileFD, off ui
|
||||
}
|
||||
|
||||
// Round up to a multiple of page size.
|
||||
readSize, _ := usermem.PageRoundUp(uint64(size))
|
||||
readSize, _ := hostarch.PageRoundUp(uint64(size))
|
||||
|
||||
// One request cannnot exceed either maxRead or maxPages.
|
||||
maxPages := fs.conn.maxRead >> usermem.PageShift
|
||||
maxPages := fs.conn.maxRead >> hostarch.PageShift
|
||||
if maxPages > uint32(fs.conn.maxPages) {
|
||||
maxPages = uint32(fs.conn.maxPages)
|
||||
}
|
||||
@@ -54,9 +54,9 @@ func (fs *filesystem) ReadInPages(ctx context.Context, fd *regularFileFD, off ui
|
||||
var outs [][]byte
|
||||
var sizeRead uint32
|
||||
|
||||
// readSize is a multiple of usermem.PageSize.
|
||||
// readSize is a multiple of hostarch.PageSize.
|
||||
// Always request bytes as a multiple of pages.
|
||||
pagesRead, pagesToRead := uint32(0), uint32(readSize>>usermem.PageShift)
|
||||
pagesRead, pagesToRead := uint32(0), uint32(readSize>>hostarch.PageShift)
|
||||
|
||||
// Reuse the same struct for unmarshalling to avoid unnecessary memory allocation.
|
||||
in := linux.FUSEReadIn{
|
||||
@@ -76,8 +76,8 @@ func (fs *filesystem) ReadInPages(ctx context.Context, fd *regularFileFD, off ui
|
||||
pagesCanRead = maxPages
|
||||
}
|
||||
|
||||
in.Offset = off + (uint64(pagesRead) << usermem.PageShift)
|
||||
in.Size = pagesCanRead << usermem.PageShift
|
||||
in.Offset = off + (uint64(pagesRead) << hostarch.PageShift)
|
||||
in.Size = pagesCanRead << hostarch.PageShift
|
||||
|
||||
// TODO(gvisor.dev/issue/3247): support async read.
|
||||
|
||||
@@ -159,7 +159,7 @@ func (fs *filesystem) Write(ctx context.Context, fd *regularFileFD, off uint64,
|
||||
}
|
||||
|
||||
// One request cannnot exceed either maxWrite or maxPages.
|
||||
maxWrite := uint32(fs.conn.maxPages) << usermem.PageShift
|
||||
maxWrite := uint32(fs.conn.maxPages) << hostarch.PageShift
|
||||
if maxWrite > fs.conn.maxWrite {
|
||||
maxWrite = fs.conn.maxWrite
|
||||
}
|
||||
@@ -188,8 +188,8 @@ func (fs *filesystem) Write(ctx context.Context, fd *regularFileFD, off uint64,
|
||||
// Limit the write size to one page.
|
||||
// Note that the bigWrites flag is obsolete,
|
||||
// latest libfuse always sets it on.
|
||||
if !fs.conn.bigWrites && toWrite > usermem.PageSize {
|
||||
toWrite = usermem.PageSize
|
||||
if !fs.conn.bigWrites && toWrite > hostarch.PageSize {
|
||||
toWrite = hostarch.PageSize
|
||||
}
|
||||
|
||||
// Limit the write size to maxWrite.
|
||||
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
"gvisor.dev/gvisor/pkg/marshal"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
// fuseInitRes is a variable-length wrapper of linux.FUSEInitOut. The FUSE
|
||||
@@ -45,29 +45,29 @@ func (r *fuseInitRes) UnmarshalBytes(src []byte) {
|
||||
out := &r.initOut
|
||||
|
||||
// Introduced before FUSE kernel version 7.13.
|
||||
out.Major = uint32(usermem.ByteOrder.Uint32(src[:4]))
|
||||
out.Major = uint32(hostarch.ByteOrder.Uint32(src[:4]))
|
||||
src = src[4:]
|
||||
out.Minor = uint32(usermem.ByteOrder.Uint32(src[:4]))
|
||||
out.Minor = uint32(hostarch.ByteOrder.Uint32(src[:4]))
|
||||
src = src[4:]
|
||||
out.MaxReadahead = uint32(usermem.ByteOrder.Uint32(src[:4]))
|
||||
out.MaxReadahead = uint32(hostarch.ByteOrder.Uint32(src[:4]))
|
||||
src = src[4:]
|
||||
out.Flags = uint32(usermem.ByteOrder.Uint32(src[:4]))
|
||||
out.Flags = uint32(hostarch.ByteOrder.Uint32(src[:4]))
|
||||
src = src[4:]
|
||||
out.MaxBackground = uint16(usermem.ByteOrder.Uint16(src[:2]))
|
||||
out.MaxBackground = uint16(hostarch.ByteOrder.Uint16(src[:2]))
|
||||
src = src[2:]
|
||||
out.CongestionThreshold = uint16(usermem.ByteOrder.Uint16(src[:2]))
|
||||
out.CongestionThreshold = uint16(hostarch.ByteOrder.Uint16(src[:2]))
|
||||
src = src[2:]
|
||||
out.MaxWrite = uint32(usermem.ByteOrder.Uint32(src[:4]))
|
||||
out.MaxWrite = uint32(hostarch.ByteOrder.Uint32(src[:4]))
|
||||
src = src[4:]
|
||||
|
||||
// Introduced in FUSE kernel version 7.23.
|
||||
if len(src) >= 4 {
|
||||
out.TimeGran = uint32(usermem.ByteOrder.Uint32(src[:4]))
|
||||
out.TimeGran = uint32(hostarch.ByteOrder.Uint32(src[:4]))
|
||||
src = src[4:]
|
||||
}
|
||||
// Introduced in FUSE kernel version 7.28.
|
||||
if len(src) >= 2 {
|
||||
out.MaxPages = uint16(usermem.ByteOrder.Uint16(src[:2]))
|
||||
out.MaxPages = uint16(hostarch.ByteOrder.Uint16(src[:2]))
|
||||
src = src[2:]
|
||||
}
|
||||
_ = src // Remove unused warning.
|
||||
|
||||
@@ -24,7 +24,8 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
)
|
||||
|
||||
func setup(t *testing.T) *testutil.System {
|
||||
@@ -82,12 +83,12 @@ func (t *testPayload) SizeBytes() int {
|
||||
|
||||
// MarshalBytes implements marshal.Marshallable.MarshalBytes.
|
||||
func (t *testPayload) MarshalBytes(dst []byte) {
|
||||
usermem.ByteOrder.PutUint32(dst[:4], t.data)
|
||||
hostarch.ByteOrder.PutUint32(dst[:4], t.data)
|
||||
}
|
||||
|
||||
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
|
||||
func (t *testPayload) UnmarshalBytes(src []byte) {
|
||||
*t = testPayload{data: usermem.ByteOrder.Uint32(src[:4])}
|
||||
*t = testPayload{data: hostarch.ByteOrder.Uint32(src[:4])}
|
||||
}
|
||||
|
||||
// Packed implements marshal.Marshallable.Packed.
|
||||
@@ -106,17 +107,17 @@ func (t *testPayload) UnmarshalUnsafe(src []byte) {
|
||||
}
|
||||
|
||||
// CopyOutN implements marshal.Marshallable.CopyOutN.
|
||||
func (t *testPayload) CopyOutN(task marshal.CopyContext, addr usermem.Addr, limit int) (int, error) {
|
||||
func (t *testPayload) CopyOutN(task marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// CopyOut implements marshal.Marshallable.CopyOut.
|
||||
func (t *testPayload) CopyOut(task marshal.CopyContext, addr usermem.Addr) (int, error) {
|
||||
func (t *testPayload) CopyOut(task marshal.CopyContext, addr hostarch.Addr) (int, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// CopyIn implements marshal.Marshallable.CopyIn.
|
||||
func (t *testPayload) CopyIn(task marshal.CopyContext, addr usermem.Addr) (int, error) {
|
||||
func (t *testPayload) CopyIn(task marshal.CopyContext, addr hostarch.Addr) (int, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user