forked from cubefs/cubefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_store_xattr.go
89 lines (74 loc) · 1.51 KB
/
fs_store_xattr.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
package objectnode
import (
"strings"
"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/util/log"
)
const (
volumeRootInode = uint64(1)
)
type xattrStore struct {
vm *volumeManager //vol *volume
}
func (s *xattrStore) Init(vm *volumeManager) {
s.vm = vm
}
func (s *xattrStore) getInode(vol, path string) (*volume, uint64, error) {
v, err := s.vm.loadVolume(vol)
if err != nil {
return nil, 0, err
}
inode := volumeRootInode
if path != "" && path != "/" {
items := strings.Split(path, "/")
for _, item := range items {
if item == "" {
continue
}
inode, _, err = v.mw.Lookup_ll(inode, item)
if err != nil {
return v, inode, err
}
}
}
return v, inode, nil
}
func (s *xattrStore) Put(vol, path, key string, data []byte) (err error) {
v, err1 := s.vm.loadVolume(vol)
if err1 != nil {
err = err1
return
}
err = v.SetXAttr(path, key, data)
if err != nil {
log.LogErrorf("policy: %v, %v", key, data)
}
return
}
func (s *xattrStore) Get(vol, path, key string) (val []byte, err error) {
var v *volume
v, err = s.vm.loadVolume(vol)
if err != nil {
return
}
var xattrInfo *proto.XAttrInfo
if xattrInfo, err = v.GetXAttr(path, key); err != nil {
return
}
if xattrInfo == nil {
return
}
var strVal string
strVal = xattrInfo.XAttrs[key]
if len(strVal) > 0 {
val = []byte(strVal)
return
}
return
}
func (s *xattrStore) Delete(vol, obj, key string) (err error) {
return
}
func (s *xattrStore) List(vol, obj string) (data [][]byte, err error) {
return
}