1
// Copyright 2018 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
23
"github.com/cubefs/cubefs/proto"
26
func (mp *metaPartition) GetUniqID(p *Packet, num uint32) (err error) {
27
idBuf := make([]byte, 4)
28
binary.BigEndian.PutUint32(idBuf, num)
29
resp, err := mp.submit(opFSMUniqID, idBuf)
31
p.PacketErrorWithBody(proto.OpAgain, []byte(err.Error()))
40
idResp := resp.(*UniqIdResp)
41
if idResp.Status == proto.OpOk {
42
resp := &GetUniqIDResp{
46
reply, err = json.Marshal(resp)
49
reply = []byte(err.Error())
52
p.PacketErrorWithBody(status, reply)
56
func (mp *metaPartition) allocateUniqID(num uint32) (start, end uint64) {
58
// cur is the last allocated id
61
end := cur + uint64(num)
62
if atomic.CompareAndSwapUint64(&mp.config.UniqId, cur, end) {
68
func (mp *metaPartition) uniqCheckerEvict() (left int, evict int, err error) {
69
checker := mp.uniqChecker
70
left, idx, op := checker.evictIndex()
75
fsmReq := &fsmEvictUniqCheckerRequest{
79
reqBytes, err := json.Marshal(fsmReq)
83
_, err = mp.submit(opFSMUniqCheckerEvict, reqBytes)
84
return left, idx + 1, err
92
type InodeOnce struct {
94
Inode uint64 // Inode ID
98
func (i *InodeOnce) Marshal() (val []byte) {
99
val = make([]byte, newInodeOnceSize)
100
binary.BigEndian.PutUint64(val[0:8], i.UniqID)
101
binary.BigEndian.PutUint64(val[8:16], i.Inode)
102
binary.BigEndian.PutUint64(val[16:24], i.VerSeq)
106
func InodeOnceUnlinkMarshal(req *UnlinkInoReq) []byte {
107
inoOnce := &InodeOnce{
112
return inoOnce.Marshal()
115
func InodeOnceLinkMarshal(req *LinkInodeReq) []byte {
116
inoOnce := &InodeOnce{
120
return inoOnce.Marshal()
123
func InodeOnceUnmarshal(val []byte) (i *InodeOnce, err error) {
125
if len(val) < inodeOnceSize {
126
return i, fmt.Errorf("size incorrect")
128
i.UniqID = binary.BigEndian.Uint64(val[0:8])
129
i.Inode = binary.BigEndian.Uint64(val[8:16])
131
i.VerSeq = binary.BigEndian.Uint64(val[16:24])