-
Notifications
You must be signed in to change notification settings - Fork 4
/
lorder.go
70 lines (65 loc) · 1.77 KB
/
lorder.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
package nfs
import (
"sort"
"github.com/mit-pdos/go-journal/common"
"github.com/mit-pdos/go-journal/util"
"github.com/mit-pdos/go-nfsd/dir"
"github.com/mit-pdos/go-nfsd/fh"
"github.com/mit-pdos/go-nfsd/fstxn"
"github.com/mit-pdos/go-nfsd/inode"
"github.com/mit-pdos/go-nfsd/nfstypes"
)
// Lock inodes in sorted order, but return the pointers in the same order as in inums
// Caller must revalidate inodes.
func lockInodes(op *fstxn.FsTxn, inums []common.Inum) []*inode.Inode {
util.DPrintf(1, "lock inodes %v\n", inums)
sorted := make([]common.Inum, len(inums))
copy(sorted, inums)
sort.Slice(sorted, func(i, j int) bool { return inums[i] < inums[j] })
var inodes = make([]*inode.Inode, len(inums))
for _, inm := range sorted {
ip := op.GetInodeInum(inm)
if ip == nil {
op.Abort()
return nil
}
// put in same position as in inums
pos := func(inm common.Inum) int {
for i, v := range inums {
if v == inm {
return i
}
}
panic("func")
}(inm)
inodes[pos] = ip
}
return inodes
}
func twoInums(inum1, inum2 common.Inum) []common.Inum {
inums := make([]common.Inum, 2)
inums[0] = inum1
inums[1] = inum2
return inums
}
// First lookup inode up for child, then for parent, because parent
// inum > child inum and then revalidate that child is still in parent
// directory.
func lookupOrdered(op *fstxn.FsTxn, name nfstypes.Filename3, parent fh.Fh, inm common.Inum) []*inode.Inode {
util.DPrintf(5, "NFS lookupOrdered child %d parent %v\n", inm, parent)
inodes := lockInodes(op, twoInums(inm, parent.Ino))
if inodes == nil {
return nil
}
dip := inodes[1]
if dip.Gen != parent.Gen {
op.Abort()
return nil
}
child, _ := dir.LookupName(dip, op, name)
if child == common.NULLINUM || child != inm {
op.Abort()
return nil
}
return inodes
}