cubefs
1// Copyright 2020 The Chubao Authors.
2//
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
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
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.
14
15package cmd16
17import (18"encoding/json"19"fmt"20"io"21"net/http"22
23"github.com/cubefs/cubefs/proto"24)
25
26var (27MasterAddr string28VolName string29MetaPort string30VerSeq uint6431)
32
33type Inode struct {34Inode uint6435Type uint3236Size uint6437CreateTime int6438AccessTime int6439ModifyTime int6440NLink uint3241
42Dens []*Dentry43Valid bool44}
45
46func (i *Inode) String() string {47data, err := json.Marshal(i)48if err != nil {49return ""50}51return string(data)52}
53
54type Dentry struct {55ParentId uint6456Name string57Inode uint6458Type uint3259
60Valid bool61}
62
63func (d *Dentry) String() string {64data, err := json.Marshal(d)65if err != nil {66return ""67}68return string(data)69}
70
71func getMetaPartitions(addr, name string) ([]*proto.MetaPartitionView, error) {72resp, err := http.Get(fmt.Sprintf("http://%s%s?name=%s", addr, proto.ClientMetaPartitions, name))73if err != nil {74return nil, fmt.Errorf("Get meta partitions failed: %v", err)75}76defer resp.Body.Close()77
78if resp.StatusCode != 200 {79return nil, fmt.Errorf("Invalid status code: %v", resp.StatusCode)80}81
82data, err := io.ReadAll(resp.Body)83if err != nil {84return nil, fmt.Errorf("Get meta partitions read all body failed: %v", err)85}86
87var mps []*proto.MetaPartitionView88if err = proto.UnmarshalHTTPReply(data, &mps); err != nil {89return nil, fmt.Errorf("Unmarshal meta partitions view failed: %v", err)90}91return mps, nil92}
93