@@ -18,8 +18,10 @@ import (
18
18
"fmt"
19
19
"io"
20
20
"os"
21
+ "sync"
21
22
22
23
"gvisor.dev/gvisor/pkg/abi/linux"
24
+ "gvisor.dev/gvisor/pkg/log"
23
25
"gvisor.dev/gvisor/pkg/sentry/context"
24
26
"gvisor.dev/gvisor/pkg/sentry/fs"
25
27
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
@@ -29,6 +31,8 @@ import (
29
31
"gvisor.dev/gvisor/pkg/sentry/safemem"
30
32
"gvisor.dev/gvisor/pkg/sentry/usermem"
31
33
"gvisor.dev/gvisor/pkg/syserror"
34
+ "gvisor.dev/gvisor/pkg/sentry/kernel"
35
+ "gvisor.dev/gvisor/pkg/sentry/usage"
32
36
)
33
37
// inodeOperations implements fs.InodeOperations for an fs.Inodes backed
34
38
// by a host file descriptor.
@@ -41,6 +45,7 @@ type fileInodeOperations struct {
41
45
fsutil.InodeNotSocket `state:"nosave"`
42
46
fsutil.InodeNotSymlink `state:"nosave"`
43
47
48
+
44
49
fsutil.InodeSimpleExtendedAttributes
45
50
46
51
attr fs.UnstableAttr
@@ -52,6 +57,40 @@ type fileInodeOperations struct {
52
57
offsetEnd int64
53
58
54
59
packageFD int
60
+
61
+ // kernel is used to allocate memory that stores the file's contents.
62
+ kernel * kernel.Kernel
63
+
64
+ // memUsage is the default memory usage that will be reported by this file.
65
+ memUsage usage.MemoryKind
66
+
67
+ attrMu sync.Mutex `state:"nosave"`
68
+
69
+ mapsMu sync.Mutex `state:"nosave"`
70
+
71
+ // writableMappingPages tracks how many pages of virtual memory are mapped
72
+ // as potentially writable from this file. If a page has multiple mappings,
73
+ // each mapping is counted separately.
74
+ //
75
+ // This counter is susceptible to overflow as we can potentially count
76
+ // mappings from many VMAs. We count pages rather than bytes to slightly
77
+ // mitigate this.
78
+ //
79
+ // Protected by mapsMu.
80
+ writableMappingPages uint64
81
+
82
+ dataMu sync.RWMutex `state:"nosave"`
83
+
84
+ // data maps offsets into the file to offsets into platform.Memory() that
85
+ // store the file's data.
86
+ //
87
+ // data is protected by dataMu.
88
+ data fsutil.FileRangeSet
89
+
90
+ // seals represents file seals on this inode.
91
+ //
92
+ // Protected by dataMu.
93
+ seals uint32
55
94
}
56
95
57
96
type Symlink struct {
@@ -96,8 +135,14 @@ func (f *fileInodeOperations) Mappable(*fs.Inode) memmap.Mappable {
96
135
}
97
136
98
137
// Rename implements fs.InodeOperations.Rename.
99
- func (* fileInodeOperations ) Rename (ctx context.Context , oldParent * fs.Inode , oldName string , newParent * fs.Inode , newName string , replacement bool ) error {
100
- return syserror .EPERM
138
+ func (* fileInodeOperations ) Rename (ctx context.Context , inode * fs.Inode , oldParent * fs.Inode , oldName string , newParent * fs.Inode , newName string , replacement bool ) error {
139
+ return rename (ctx , oldParent , oldName , newParent , newName , replacement )
140
+ }
141
+
142
+ // rename implements fs.InodeOperations.Rename for tmpfs nodes.
143
+ func rename (ctx context.Context , oldParent * fs.Inode , oldName string , newParent * fs.Inode , newName string , replacement bool ) error {
144
+ log .Infof ("Called rename, not supported in imgfs" )
145
+ return syserror .EXDEV
101
146
}
102
147
103
148
// GetFile implements fs.InodeOperations.GetFile.
@@ -239,6 +284,12 @@ func (f *fileInodeOperations) MapInternal(fr platform.FileRange, at usermem.Acce
239
284
return seq , nil
240
285
}
241
286
287
+ // Allocate implements fs.InodeOperations.Allocate.
288
+ func (f * fileInodeOperations ) Allocate (ctx context.Context , _ * fs.Inode , offset , length int64 ) error {
289
+ log .Infof ("Calling unimplemented method in imgfs" )
290
+ return nil
291
+ }
292
+
242
293
// Translate implements memmap.Mappable.Translate.
243
294
func (f * fileInodeOperations ) Translate (ctx context.Context , required , optional memmap.MappableRange , at usermem.AccessType ) ([]memmap.Translation , error ) {
244
295
return []memmap.Translation {
@@ -267,13 +318,13 @@ func newInode(ctx context.Context, msrc *fs.MountSource, begin int64, end int64,
267
318
offsetEnd : end ,
268
319
packageFD : packageFD ,
269
320
}
270
- return fs .NewInode (iops , msrc , sattr ), nil
321
+ return fs .NewInode (ctx , iops , msrc , sattr ), nil
271
322
}
272
323
273
324
// newSymlink returns a new fs.Inode
274
325
func newSymlink (ctx context.Context , msrc * fs.MountSource , target string ) * fs.Inode {
275
326
s := & Symlink {Symlink : * ramfs .NewSymlink (ctx , fs .RootOwner , target )}
276
- return fs .NewInode (s , msrc , fs.StableAttr {
327
+ return fs .NewInode (ctx , s , msrc , fs.StableAttr {
277
328
DeviceID : imgfsFileDevice .DeviceID (),
278
329
InodeID : imgfsFileDevice .NextIno (),
279
330
BlockSize : usermem .PageSize ,
0 commit comments