forked from minio/minio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-storage.go
More file actions
179 lines (154 loc) · 4.72 KB
/
debug-storage.go
File metadata and controls
179 lines (154 loc) · 4.72 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package cmd
import (
"fmt"
"io"
"strings"
)
type debugStorage struct {
path string
s StorageAPI
enable bool
}
func (d *debugStorage) String() string {
return d.s.String()
}
func (d *debugStorage) IsOnline() bool {
return d.s.IsOnline()
}
func (k *debugStorage) LastError() error {
return nil
}
func (d *debugStorage) Close() error {
return nil
}
func errStr(err error) string {
if err == nil {
return "<nil>"
}
return err.Error()
}
func (d *debugStorage) DiskInfo() (info DiskInfo, err error) {
info, err = d.s.DiskInfo()
if d.enable {
fmt.Printf("%s: DiskInfo() (_, %s)\n", d.path, errStr(err))
}
return info, err
}
func (d *debugStorage) MakeVol(volume string) (err error) {
err = d.s.MakeVol(volume)
if d.enable {
fmt.Printf("%s: MakeVol(%s) (%s)\n", d.path, volume, errStr(err))
}
return err
}
func (d *debugStorage) ListVols() (vols []VolInfo, err error) {
vols, err = d.s.ListVols()
var volNames []string
for _, vol := range vols {
volNames = append(volNames, vol.Name)
}
if d.enable {
fmt.Printf("%s: ListVols() (%s, %s)\n", d.path, strings.Join(volNames, ":"), errStr(err))
}
return vols, err
}
func (d *debugStorage) StatVol(volume string) (vol VolInfo, err error) {
vol, err = d.s.StatVol(volume)
if d.enable {
fmt.Printf("%s: StatVol(%s) (_, %s)\n", d.path, volume, errStr(err))
}
return vol, err
}
func (d *debugStorage) DeleteVol(volume string) (err error) {
err = d.s.DeleteVol(volume)
if d.enable {
fmt.Printf("%s: DeleteVol(%s) (%s)\n", d.path, volume, errStr(err))
}
return err
}
func (d *debugStorage) ListDir(volume, dirPath string, count int) ([]string, error) {
entries, err := d.s.ListDir(volume, dirPath, count)
if d.enable {
fmt.Printf("%s: ListDir(%s, %s, %d) (_, %s)\n", d.path, volume, dirPath, count, errStr(err))
}
return entries, err
}
func (d *debugStorage) ReadFile(volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error) {
n, err = d.s.ReadFile(volume, path, offset, buf, verifier)
var algo string
if verifier != nil {
algo = verifier.algorithm.String()
}
if d.enable {
fmt.Printf("%s: ReadFile(%s, %s, %d, len(buf)=%d, verifier={%s}) (_, %s)\n", d.path, volume, path, offset, len(buf), algo, errStr(err))
}
return n, err
}
func (d *debugStorage) AppendFile(volume string, path string, buf []byte) (err error) {
err = d.s.AppendFile(volume, path, buf)
if d.enable {
fmt.Printf("%s: AppendFile(%s, %s, len(buf)=%d) (%s)\n", d.path, volume, path, len(buf), errStr(err))
}
return err
}
func (d *debugStorage) CreateDir(volume, dirPath string) error {
err := d.s.CreateDir(volume, dirPath)
return err
}
func (d *debugStorage) StatDir(volume, dirPath string) error {
err := d.s.StatDir(volume, dirPath)
return err
}
func (d *debugStorage) DeleteDir(volume, dirPath string) error {
err := d.s.DeleteDir(volume, dirPath)
return err
}
func (d *debugStorage) CreateFile(volume, filePath string, size int64, reader io.Reader) error {
err := d.s.CreateFile(volume, filePath, size, reader)
if d.enable {
fmt.Printf("%s: CreateFile(%s, %s, %d) (%s)\n", d.path, volume, filePath, size, errStr(err))
}
return err
}
func (d *debugStorage) ReadFileStream(volume, filePath string, offset, length int64) (io.ReadCloser, error) {
r, err := d.s.ReadFileStream(volume, filePath, offset, length)
if d.enable {
fmt.Printf("%s: ReadFileStream(%s, %s, %d, %d) (_, %s)\n", d.path, volume, filePath, offset, length, errStr(err))
}
return r, err
}
func (d *debugStorage) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) error {
err := d.s.RenameFile(srcVolume, srcPath, dstVolume, dstPath)
if d.enable {
fmt.Printf("%s: RenameFile(%s, %s, %s, %s) (%s)\n", d.path, srcVolume, srcPath, dstVolume, dstPath, errStr(err))
}
return err
}
func (d *debugStorage) StatFile(volume string, path string) (file FileInfo, err error) {
fi, err := d.s.StatFile(volume, path)
if d.enable {
fmt.Printf("%s: StatFile(%s, %s) (_, %s)\n", d.path, volume, path, errStr(err))
}
return fi, err
}
func (d *debugStorage) DeleteFile(volume string, path string) (err error) {
err = d.s.DeleteFile(volume, path)
if d.enable {
fmt.Printf("%s: DeleteFile(%s, %s) (_, %s)\n", d.path, volume, path, errStr(err))
}
return err
}
func (d *debugStorage) WriteAll(volume string, filePath string, buf []byte) (err error) {
err = d.s.WriteAll(volume, filePath, buf)
if d.enable {
fmt.Printf("%s: WriteAll(%s, %s, len(buf)=%d) (%s)\n", d.path, volume, filePath, len(buf), errStr(err))
}
return err
}
func (d *debugStorage) ReadAll(volume string, filePath string) (buf []byte, err error) {
buf, err = d.s.ReadAll(volume, filePath)
if d.enable {
fmt.Printf("%s: ReadAll(%s, %s) (len(buf)=%d, %s)\n", d.path, volume, filePath, len(buf), errStr(err))
}
return buf, err
}