forked from cubefs/cubefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_store_xattr.go
110 lines (95 loc) · 2.32 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2019 The CubeFS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package objectnode
import (
"strings"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/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.Volume(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.Volume(vol)
if err1 != nil {
err = err1
return
}
err = v.SetXAttr(path, key, data, false)
if err != nil {
log.LogErrorf("put xattr failed: vol[%v], key[%v], data[%v]", vol, key, data)
}
return
}
func (s *xattrStore) Get(vol, path, key string) (val []byte, err error) {
var v *Volume
v, err = s.vm.Volume(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, path, key string) (err error) {
var v *Volume
if v, err = s.vm.Volume(vol); err != nil {
return
}
if err = v.DeleteXAttr(path, key); err != nil {
log.LogErrorf("delete xattr failed: vol[%v], key[%v]", vol, key)
return
}
return nil
}
func (s *xattrStore) List(vol, obj string) (data [][]byte, err error) {
return
}