-
Notifications
You must be signed in to change notification settings - Fork 64
/
nfs_handle_allocator.go
660 lines (578 loc) · 21.4 KB
/
nfs_handle_allocator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
package virtual
import (
"bytes"
"context"
"encoding/binary"
"io"
"sync"
"github.com/buildbarn/bb-storage/pkg/filesystem/path"
"github.com/buildbarn/bb-storage/pkg/random"
)
// fileHandleToInodeNumber converts a file handle to an inode number.
func fileHandleToInodeNumber(fileHandle []byte) uint64 {
hasher := fnv1aHasher{
hash: binary.LittleEndian.Uint64(fileHandle),
}
if _, err := bytes.NewBuffer(fileHandle[8:]).WriteTo(&hasher); err != nil {
panic(err)
}
return hasher.hash
}
// inodeNumberToBaseFileHandle converts the inode number of a
// non-resolvable file to a file handle. File handles for such files are
// simply identical to the inode number.
func inodeNumberToBaseFileHandle(inodeNumber uint64) [8]byte {
var fileHandle [8]byte
binary.LittleEndian.PutUint64(fileHandle[:], inodeNumber)
return fileHandle
}
// setAttributesForFileHandle sets the file handle and inode number
// attributes for a given file.
func setAttributesForFileHandle(fileHandle []byte, requested AttributesMask, attributes *Attributes) {
attributes.SetFileHandle(fileHandle)
if requested&AttributesMaskInodeNumber != 0 {
attributes.SetInodeNumber(fileHandleToInodeNumber(fileHandle))
}
}
type nfsHandlePool struct {
lock sync.RWMutex
randomNumberGenerator random.SingleThreadedGenerator
directories map[uint64]Directory
statefulLeaves map[uint64]*nfsStatefulNativeLeaf
statelessLeaves map[uint64]*nfsStatelessNativeLeaf
resolvers map[uint64]HandleResolver
}
func (hp *nfsHandlePool) createStatelessDirectoryLocked(inodeNumber uint64, underlyingDirectory Directory) Directory {
// Reuse an existing directory if one exists.
if directory, ok := hp.directories[inodeNumber]; ok {
return directory
}
fileHandle := inodeNumberToBaseFileHandle(inodeNumber)
directory := &nfsStatelessDirectory{
Directory: underlyingDirectory,
fileHandle: fileHandle[:],
}
hp.directories[inodeNumber] = directory
return directory
}
func (hp *nfsHandlePool) createResolvableAllocatorLocked(inodeNumber uint64, resolver HandleResolver) ResolvableHandleAllocator {
if _, ok := hp.resolvers[inodeNumber]; !ok {
hp.resolvers[inodeNumber] = resolver
}
fileHandlePrefix := inodeNumberToBaseFileHandle(inodeNumber)
return &nfsResolvableHandleAllocator{
fileHandlePrefix: fileHandlePrefix[:],
}
}
// NFSStatefulHandleAllocator creates a handle allocator for the purpose
// of exposing the virtual file system through NFS. It is responsible
// for decorating all files in the file system, so that they have file
// handles, inode numbers and link counts. File handles and inode
// numbers are unique for stateful (mutable) files, while they are
// identical for stateless files that share the same identifiers,
// meaning they can be deduplicated by the kernel.
//
// The NFS protocol is stateless, in the sense that the client and
// server share no state on which nodes in the file system have been
// resolved. The client does not inform the server that it has released
// files from its cache. This means that the server needs to be able to
// resolve all file handles that are either still present in the file
// system or are still opened by the client. This handle allocator is
// capable of only doing the former. The latter can be supported at a
// higher level.
//
// To work well with infinitely big directory structures (e.g.,
// bb_clientd's "cas" directory), this implementation makes use of the
// handle resolver function provided to AsResolvableAllocator(). Instead
// of tracking these nodes explicitly, it generates longer file handles
// that have the value provided to ResolvableHandleAllocator.New() as
// a suffix, making it possible to regenerate these nodes on the fly.
type NFSStatefulHandleAllocator struct {
pool *nfsHandlePool
}
var _ StatefulHandleAllocator = (*NFSStatefulHandleAllocator)(nil)
// NewNFSHandleAllocator creates a new NFSStatefulHandleAllocator that
// does not have any resolvable objects.
func NewNFSHandleAllocator(randomNumberGenerator random.SingleThreadedGenerator) *NFSStatefulHandleAllocator {
return &NFSStatefulHandleAllocator{
pool: &nfsHandlePool{
randomNumberGenerator: randomNumberGenerator,
directories: map[uint64]Directory{},
statefulLeaves: map[uint64]*nfsStatefulNativeLeaf{},
statelessLeaves: map[uint64]*nfsStatelessNativeLeaf{},
resolvers: map[uint64]HandleResolver{},
},
}
}
// ResolveHandle resolves a directory or leaf object that corresponds
// with a file handle previously returned by Attributes.GetFileHandle().
//
// Only files that are linked into the file system are guaranteed to be
// resolvable. Files that have been unlinked, but are still opened have
// to be tracked at a higher level.
func (hr *NFSStatefulHandleAllocator) ResolveHandle(r io.ByteReader) (DirectoryChild, Status) {
// The first eight bytes of the handle always correspond to a
// base inode number.
var inodeNumberBytes [8]byte
for i := 0; i < len(inodeNumberBytes); i++ {
c, err := r.ReadByte()
if err != nil {
return DirectoryChild{}, StatusErrBadHandle
}
inodeNumberBytes[i] = c
}
inodeNumber := binary.LittleEndian.Uint64(inodeNumberBytes[:])
p := hr.pool
p.lock.RLock()
if directory, ok := p.directories[inodeNumber]; ok {
p.lock.RUnlock()
return DirectoryChild{}.FromDirectory(directory), StatusOK
}
if leaf, ok := p.statefulLeaves[inodeNumber]; ok {
p.lock.RUnlock()
return DirectoryChild{}.FromLeaf(leaf), StatusOK
}
if leaf, ok := p.statelessLeaves[inodeNumber]; ok {
p.lock.RUnlock()
return DirectoryChild{}.FromLeaf(leaf), StatusOK
}
if resolver, ok := p.resolvers[inodeNumber]; ok {
p.lock.RUnlock()
return resolver(r)
}
p.lock.RUnlock()
return DirectoryChild{}, StatusErrStale
}
// New creates a new stateful handle allocation.
func (hr *NFSStatefulHandleAllocator) New() StatefulHandleAllocation {
return &nfsStatefulHandleAllocation{
pool: hr.pool,
}
}
type nfsStatefulHandleAllocation struct {
pool *nfsHandlePool
}
func (hn *nfsStatefulHandleAllocation) AsStatelessAllocator() StatelessHandleAllocator {
hp := hn.pool
hp.lock.Lock()
inodeNumberSeed := hp.randomNumberGenerator.Uint64()
hp.lock.Unlock()
*hn = nfsStatefulHandleAllocation{}
return &nfsStatelessHandleAllocator{
pool: hp,
inodeNumberSeed: inodeNumberSeed,
}
}
func (hn *nfsStatefulHandleAllocation) AsResolvableAllocator(resolver HandleResolver) ResolvableHandleAllocator {
hp := hn.pool
hp.lock.Lock()
hr := hp.createResolvableAllocatorLocked(hp.randomNumberGenerator.Uint64(), resolver)
hp.lock.Unlock()
*hn = nfsStatefulHandleAllocation{}
return hr
}
func (hn *nfsStatefulHandleAllocation) AsStatefulDirectory(directory Directory) StatefulDirectoryHandle {
hp := hn.pool
hp.lock.Lock()
inodeNumber := hp.randomNumberGenerator.Uint64()
hp.directories[inodeNumber] = directory
hp.lock.Unlock()
*hn = nfsStatefulHandleAllocation{}
return &nfsStatefulDirectoryHandle{
pool: hp,
inodeNumber: inodeNumber,
}
}
func (hn *nfsStatefulHandleAllocation) AsStatelessDirectory(underlyingDirectory Directory) Directory {
hp := hn.pool
hp.lock.Lock()
directory := hp.createStatelessDirectoryLocked(hp.randomNumberGenerator.Uint64(), underlyingDirectory)
hp.lock.Unlock()
*hn = nfsStatefulHandleAllocation{}
return directory
}
func (hn *nfsStatefulHandleAllocation) AsNativeLeaf(underlyingLeaf NativeLeaf) NativeLeaf {
hp := hn.pool
hp.lock.Lock()
inodeNumber := hp.randomNumberGenerator.Uint64()
fileHandle := inodeNumberToBaseFileHandle(inodeNumber)
leaf := &nfsStatefulNativeLeaf{
NativeLeaf: underlyingLeaf,
pool: hp,
fileHandle: fileHandle[:],
linkCount: 1,
}
hp.statefulLeaves[inodeNumber] = leaf
hp.lock.Unlock()
*hn = nfsStatefulHandleAllocation{}
return leaf
}
func (hn *nfsStatefulHandleAllocation) AsLeaf(underlyingLeaf Leaf) Leaf {
panic("Regular leaf objects cannot be used in stateful contexts, as they cannot be linked/unlinked")
}
type nfsStatelessHandleAllocator struct {
pool *nfsHandlePool
inodeNumberSeed uint64
}
func (hr *nfsStatelessHandleAllocator) New(w io.WriterTo) StatelessHandleAllocation {
hasher := fnv1aHasher{
hash: hr.inodeNumberSeed,
}
if _, err := w.WriteTo(&hasher); err != nil {
panic(err)
}
return &nfsStatelessHandleAllocation{
pool: hr.pool,
currentInodeNumber: hasher.hash,
}
}
type nfsStatelessHandleAllocation struct {
pool *nfsHandlePool
currentInodeNumber uint64
}
func (hn *nfsStatelessHandleAllocation) AsStatelessAllocator() StatelessHandleAllocator {
hr := &nfsStatelessHandleAllocator{
pool: hn.pool,
inodeNumberSeed: hn.currentInodeNumber,
}
*hn = nfsStatelessHandleAllocation{}
return hr
}
func (hn *nfsStatelessHandleAllocation) AsResolvableAllocator(resolver HandleResolver) ResolvableHandleAllocator {
hp := hn.pool
hp.lock.Lock()
hr := hp.createResolvableAllocatorLocked(hn.currentInodeNumber, resolver)
hp.lock.Unlock()
*hn = nfsStatelessHandleAllocation{}
return hr
}
func (hn *nfsStatelessHandleAllocation) AsStatelessDirectory(underlyingDirectory Directory) Directory {
hp := hn.pool
hp.lock.Lock()
directory := hp.createStatelessDirectoryLocked(hn.currentInodeNumber, underlyingDirectory)
hp.lock.Unlock()
*hn = nfsStatelessHandleAllocation{}
return directory
}
func (hn *nfsStatelessHandleAllocation) AsNativeLeaf(underlyingLeaf NativeLeaf) NativeLeaf {
hp := hn.pool
hp.lock.Lock()
// Reuse an existing leaf if one exists.
if leaf, ok := hp.statelessLeaves[hn.currentInodeNumber]; ok {
leaf.linkCount++
hp.lock.Unlock()
underlyingLeaf.Unlink()
return leaf
}
// None exists. Create a new one.
fileHandle := inodeNumberToBaseFileHandle(hn.currentInodeNumber)
leaf := &nfsStatelessNativeLeaf{
NativeLeaf: underlyingLeaf,
pool: hp,
fileHandle: fileHandle[:],
linkCount: 1,
}
hp.statelessLeaves[hn.currentInodeNumber] = leaf
hp.lock.Unlock()
*hn = nfsStatelessHandleAllocation{}
return leaf
}
func (hn *nfsStatelessHandleAllocation) AsLeaf(underlyingLeaf Leaf) Leaf {
panic("Regular leaf objects cannot be used in stateless contexts, as they cannot be linked/unlinked")
}
type nfsResolvableHandleAllocator struct {
fileHandlePrefix []byte
}
func (hr *nfsResolvableHandleAllocator) New(w io.WriterTo) ResolvableHandleAllocation {
fileHandle := bytes.NewBuffer(hr.fileHandlePrefix[:len(hr.fileHandlePrefix):len(hr.fileHandlePrefix)])
if _, err := w.WriteTo(fileHandle); err != nil {
panic(err)
}
return &nfsResolvableHandleAllocation{
currentFileHandle: fileHandle.Bytes(),
}
}
type nfsResolvableHandleAllocation struct {
currentFileHandle []byte
}
func (hn *nfsResolvableHandleAllocation) AsResolvableAllocator(resolver HandleResolver) ResolvableHandleAllocator {
hr := &nfsResolvableHandleAllocator{
fileHandlePrefix: hn.currentFileHandle,
}
*hn = nfsResolvableHandleAllocation{}
return hr
}
func (hn *nfsResolvableHandleAllocation) AsStatelessDirectory(underlyingDirectory Directory) Directory {
directory := &nfsStatelessDirectory{
Directory: underlyingDirectory,
fileHandle: hn.currentFileHandle,
}
*hn = nfsResolvableHandleAllocation{}
return directory
}
func (hn *nfsResolvableHandleAllocation) AsNativeLeaf(underlyingLeaf NativeLeaf) NativeLeaf {
leaf := &nfsResolvableNativeLeaf{
NativeLeaf: underlyingLeaf,
fileHandle: hn.currentFileHandle,
}
*hn = nfsResolvableHandleAllocation{}
return leaf
}
func (hn *nfsResolvableHandleAllocation) AsLeaf(underlyingLeaf Leaf) Leaf {
leaf := &nfsResolvableLeaf{
Leaf: underlyingLeaf,
fileHandle: hn.currentFileHandle,
}
*hn = nfsResolvableHandleAllocation{}
return leaf
}
// nfsStatefulDirectoryHandle is a handle for stateful directories that
// augments the results of VirtualGetAttributes() to contain a file
// handle and inode number.
type nfsStatefulDirectoryHandle struct {
pool *nfsHandlePool
inodeNumber uint64
}
func (dh *nfsStatefulDirectoryHandle) GetAttributes(requested AttributesMask, attributes *Attributes) {
fileHandle := inodeNumberToBaseFileHandle(dh.inodeNumber)
attributes.SetFileHandle(fileHandle[:])
attributes.SetInodeNumber(dh.inodeNumber)
}
func (dh *nfsStatefulDirectoryHandle) NotifyRemoval(name path.Component) {
// Removal notification could be supported using NFSv4.1's
// CB_NOTIFY operation. Unfortunately, none of the major client
// implementations seem to support it.
// https://github.com/torvalds/linux/blob/b05bf5c63b326ce1da84ef42498d8e0e292e694c/fs/nfs/callback_xdr.c#L779-L783
}
func (dh *nfsStatefulDirectoryHandle) Release() {
hp := dh.pool
hp.lock.Lock()
delete(hp.directories, dh.inodeNumber)
hp.lock.Unlock()
}
// nfsStatelessDirectory is a decorator for stateless Directory objects
// that augments the results of VirtualGetAttributes() to contain a file
// handle and inode number.
type nfsStatelessDirectory struct {
Directory
fileHandle []byte
}
func (d *nfsStatelessDirectory) VirtualGetAttributes(ctx context.Context, requested AttributesMask, attributes *Attributes) {
if remaining := requested &^ (AttributesMaskFileHandle | AttributesMaskInodeNumber); remaining != 0 {
d.Directory.VirtualGetAttributes(ctx, remaining, attributes)
}
setAttributesForFileHandle(d.fileHandle, requested, attributes)
}
func (d *nfsStatelessDirectory) VirtualSetAttributes(ctx context.Context, in *Attributes, requested AttributesMask, attributes *Attributes) Status {
if s := d.Directory.VirtualSetAttributes(ctx, in, requested, attributes); s != StatusOK {
return s
}
setAttributesForFileHandle(d.fileHandle, requested, attributes)
return StatusOK
}
// nfsStatefulNativeLeaf is a decorator for NativeLeaf that augments
// the results of VirtualGetAttributes() to contain a file handle, inode
// number and link count. Link() and Unlink() calls are intercepted, and
// are only forwarded if the link count drops to zero.
type nfsStatefulNativeLeaf struct {
NativeLeaf
pool *nfsHandlePool
fileHandle []byte
// Protected by pool.lock.
linkCount uint32
changeID uint64
}
func (l *nfsStatefulNativeLeaf) Link() Status {
hp := l.pool
hp.lock.Lock()
defer hp.lock.Unlock()
if l.linkCount == 0 {
return StatusErrStale
}
l.linkCount++
l.changeID++
return StatusOK
}
func (l *nfsStatefulNativeLeaf) Unlink() {
inodeNumber := fileHandleToInodeNumber(l.fileHandle)
hp := l.pool
hp.lock.Lock()
if l.linkCount == 0 {
panic("Attempted to unlink file with link count zero")
}
l.linkCount--
l.changeID++
if l.linkCount == 0 {
delete(hp.statefulLeaves, inodeNumber)
hp.lock.Unlock()
l.NativeLeaf.Unlink()
} else {
hp.lock.Unlock()
}
}
func (l *nfsStatefulNativeLeaf) injectAttributes(requested AttributesMask, attributes *Attributes) {
setAttributesForFileHandle(l.fileHandle, requested, attributes)
if requested&(AttributesMaskChangeID|AttributesMaskLinkCount) != 0 {
hp := l.pool
hp.lock.RLock()
if requested&AttributesMaskChangeID != 0 {
attributes.SetChangeID(attributes.GetChangeID() + l.changeID)
}
attributes.SetLinkCount(l.linkCount)
hp.lock.RUnlock()
}
}
func (l *nfsStatefulNativeLeaf) VirtualGetAttributes(ctx context.Context, requested AttributesMask, attributes *Attributes) {
if remaining := requested &^ (AttributesMaskFileHandle | AttributesMaskInodeNumber | AttributesMaskLinkCount); remaining != 0 {
l.NativeLeaf.VirtualGetAttributes(ctx, remaining, attributes)
}
l.injectAttributes(requested, attributes)
}
func (l *nfsStatefulNativeLeaf) VirtualSetAttributes(ctx context.Context, in *Attributes, requested AttributesMask, attributes *Attributes) Status {
if s := l.NativeLeaf.VirtualSetAttributes(ctx, in, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
func (l *nfsStatefulNativeLeaf) VirtualOpenSelf(ctx context.Context, shareAccess ShareMask, options *OpenExistingOptions, requested AttributesMask, attributes *Attributes) Status {
if s := l.NativeLeaf.VirtualOpenSelf(ctx, shareAccess, options, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
// nfsStatelessNativeLeaf is a decorator for NativeLeaf that augments
// the results of VirtualGetAttributes() to contain a file handle, inode
// number and link count.
//
// Even though these files are stateless, we need to track an actual
// link count to determine when it's safe to release the file handle
// from nfsHandlePool. We do report a constant link count back to the
// user, both to prevent invalidation of the attributes and for
// consistency with FUSE.
type nfsStatelessNativeLeaf struct {
NativeLeaf
pool *nfsHandlePool
fileHandle []byte
// Protected by pool.lock.
linkCount uint32
}
func (l *nfsStatelessNativeLeaf) Link() Status {
hp := l.pool
hp.lock.Lock()
defer hp.lock.Unlock()
if l.linkCount == 0 {
return StatusErrStale
}
l.linkCount++
return StatusOK
}
func (l *nfsStatelessNativeLeaf) Unlink() {
inodeNumber := fileHandleToInodeNumber(l.fileHandle)
hp := l.pool
hp.lock.Lock()
if l.linkCount == 0 {
panic("Attempted to unlink file with link count zero")
}
l.linkCount--
if l.linkCount == 0 {
delete(hp.statelessLeaves, inodeNumber)
hp.lock.Unlock()
l.NativeLeaf.Unlink()
} else {
hp.lock.Unlock()
}
}
func (l *nfsStatelessNativeLeaf) injectAttributes(requested AttributesMask, attributes *Attributes) {
setAttributesForFileHandle(l.fileHandle, requested, attributes)
attributes.SetLinkCount(StatelessLeafLinkCount)
}
func (l *nfsStatelessNativeLeaf) VirtualGetAttributes(ctx context.Context, requested AttributesMask, attributes *Attributes) {
if remaining := requested &^ (AttributesMaskFileHandle | AttributesMaskInodeNumber | AttributesMaskLinkCount); remaining != 0 {
l.NativeLeaf.VirtualGetAttributes(ctx, remaining, attributes)
}
l.injectAttributes(requested, attributes)
}
func (l *nfsStatelessNativeLeaf) VirtualSetAttributes(ctx context.Context, in *Attributes, requested AttributesMask, attributes *Attributes) Status {
if s := l.NativeLeaf.VirtualSetAttributes(ctx, in, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
func (l *nfsStatelessNativeLeaf) VirtualOpenSelf(ctx context.Context, shareAccess ShareMask, options *OpenExistingOptions, requested AttributesMask, attributes *Attributes) Status {
if s := l.NativeLeaf.VirtualOpenSelf(ctx, shareAccess, options, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
// nfsResolvableNativeLeaf is a decorator for NativeLeaf that augments
// the results of VirtualGetAttributes() to contain a file handle, inode
// number and link count. For these kinds of files, the link count is
// just a constant.
type nfsResolvableNativeLeaf struct {
NativeLeaf
fileHandle []byte
}
func (l *nfsResolvableNativeLeaf) Link() Status {
return StatusOK
}
func (l *nfsResolvableNativeLeaf) Unlink() {}
func (l *nfsResolvableNativeLeaf) injectAttributes(requested AttributesMask, attributes *Attributes) {
setAttributesForFileHandle(l.fileHandle, requested, attributes)
attributes.SetLinkCount(StatelessLeafLinkCount)
}
func (l *nfsResolvableNativeLeaf) VirtualGetAttributes(ctx context.Context, requested AttributesMask, attributes *Attributes) {
if remaining := requested &^ (AttributesMaskFileHandle | AttributesMaskInodeNumber | AttributesMaskLinkCount); remaining != 0 {
l.NativeLeaf.VirtualGetAttributes(ctx, remaining, attributes)
}
l.injectAttributes(requested, attributes)
}
func (l *nfsResolvableNativeLeaf) VirtualSetAttributes(ctx context.Context, in *Attributes, requested AttributesMask, attributes *Attributes) Status {
if s := l.NativeLeaf.VirtualSetAttributes(ctx, in, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
func (l *nfsResolvableNativeLeaf) VirtualOpenSelf(ctx context.Context, shareAccess ShareMask, options *OpenExistingOptions, requested AttributesMask, attributes *Attributes) Status {
if s := l.NativeLeaf.VirtualOpenSelf(ctx, shareAccess, options, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
// nfsResolvableLeaf is a decorator for Leaf that augments the results
// of VirtualGetAttributes() to contain a file handle, inode number and
// link count. For these kinds of files, the link count is just a
// constant.
type nfsResolvableLeaf struct {
Leaf
fileHandle []byte
}
func (l *nfsResolvableLeaf) injectAttributes(requested AttributesMask, attributes *Attributes) {
setAttributesForFileHandle(l.fileHandle, requested, attributes)
attributes.SetLinkCount(StatelessLeafLinkCount)
}
func (l *nfsResolvableLeaf) VirtualGetAttributes(ctx context.Context, requested AttributesMask, attributes *Attributes) {
if remaining := requested &^ (AttributesMaskFileHandle | AttributesMaskInodeNumber | AttributesMaskLinkCount); remaining != 0 {
l.Leaf.VirtualGetAttributes(ctx, remaining, attributes)
}
l.injectAttributes(requested, attributes)
}
func (l *nfsResolvableLeaf) VirtualSetAttributes(ctx context.Context, in *Attributes, requested AttributesMask, attributes *Attributes) Status {
if s := l.Leaf.VirtualSetAttributes(ctx, in, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}
func (l *nfsResolvableLeaf) VirtualOpenSelf(ctx context.Context, shareAccess ShareMask, options *OpenExistingOptions, requested AttributesMask, attributes *Attributes) Status {
if s := l.Leaf.VirtualOpenSelf(ctx, shareAccess, options, requested, attributes); s != StatusOK {
return s
}
l.injectAttributes(requested, attributes)
return StatusOK
}