cubefs

Форк
0
/
common.go 
92 строки · 2.0 Кб
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

15
package cmd
16

17
import (
18
	"encoding/json"
19
	"fmt"
20
	"io"
21
	"net/http"
22

23
	"github.com/cubefs/cubefs/proto"
24
)
25

26
var (
27
	MasterAddr string
28
	VolName    string
29
	MetaPort   string
30
	VerSeq     uint64
31
)
32

33
type Inode struct {
34
	Inode      uint64
35
	Type       uint32
36
	Size       uint64
37
	CreateTime int64
38
	AccessTime int64
39
	ModifyTime int64
40
	NLink      uint32
41

42
	Dens  []*Dentry
43
	Valid bool
44
}
45

46
func (i *Inode) String() string {
47
	data, err := json.Marshal(i)
48
	if err != nil {
49
		return ""
50
	}
51
	return string(data)
52
}
53

54
type Dentry struct {
55
	ParentId uint64
56
	Name     string
57
	Inode    uint64
58
	Type     uint32
59

60
	Valid bool
61
}
62

63
func (d *Dentry) String() string {
64
	data, err := json.Marshal(d)
65
	if err != nil {
66
		return ""
67
	}
68
	return string(data)
69
}
70

71
func getMetaPartitions(addr, name string) ([]*proto.MetaPartitionView, error) {
72
	resp, err := http.Get(fmt.Sprintf("http://%s%s?name=%s", addr, proto.ClientMetaPartitions, name))
73
	if err != nil {
74
		return nil, fmt.Errorf("Get meta partitions failed: %v", err)
75
	}
76
	defer resp.Body.Close()
77

78
	if resp.StatusCode != 200 {
79
		return nil, fmt.Errorf("Invalid status code: %v", resp.StatusCode)
80
	}
81

82
	data, err := io.ReadAll(resp.Body)
83
	if err != nil {
84
		return nil, fmt.Errorf("Get meta partitions read all body failed: %v", err)
85
	}
86

87
	var mps []*proto.MetaPartitionView
88
	if err = proto.UnmarshalHTTPReply(data, &mps); err != nil {
89
		return nil, fmt.Errorf("Unmarshal meta partitions view failed: %v", err)
90
	}
91
	return mps, nil
92
}
93

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.