| 
									
										
										
										
											2021-04-19 03:41:13 +08:00
										 |  |  | // Copyright (c) 2015-2021 MinIO, Inc.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This file is part of MinIO Object Storage stack
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 04:06:49 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2020-03-19 07:19:29 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | 	"io" | 
					
						
							| 
									
										
										
										
											2016-09-17 04:06:49 +08:00
										 |  |  | 	"sync" | 
					
						
							| 
									
										
										
										
											2021-05-12 00:19:15 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2022-04-07 23:10:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-07 05:46:50 +08:00
										 |  |  | 	"github.com/minio/madmin-go/v2" | 
					
						
							| 
									
										
										
										
											2016-09-17 04:06:49 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-09-10 06:32:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | // naughtyDisk wraps a POSIX disk and returns programmed errors
 | 
					
						
							|  |  |  | // specified by the developer. The purpose is to simulate errors
 | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | // that are hard to simulate in practice like DiskNotFound.
 | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | // Programmed errors are stored in errors field.
 | 
					
						
							|  |  |  | type naughtyDisk struct { | 
					
						
							|  |  |  | 	// The real disk
 | 
					
						
							| 
									
										
										
										
											2018-02-16 09:45:57 +08:00
										 |  |  | 	disk StorageAPI | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	// Programmed errors: API call number => error to return
 | 
					
						
							|  |  |  | 	errors map[int]error | 
					
						
							|  |  |  | 	// The error to return when no error value is programmed
 | 
					
						
							|  |  |  | 	defaultErr error | 
					
						
							|  |  |  | 	// The current API call number
 | 
					
						
							|  |  |  | 	callNR int | 
					
						
							| 
									
										
										
										
											2016-09-17 04:06:49 +08:00
										 |  |  | 	// Data protection
 | 
					
						
							|  |  |  | 	mu sync.Mutex | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-16 09:45:57 +08:00
										 |  |  | func newNaughtyDisk(d StorageAPI, errs map[int]error, defaultErr error) *naughtyDisk { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	return &naughtyDisk{disk: d, errors: errs, defaultErr: defaultErr} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | func (d *naughtyDisk) String() string { | 
					
						
							| 
									
										
										
										
											2016-10-20 10:59:48 +08:00
										 |  |  | 	return d.disk.String() | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-16 09:45:57 +08:00
										 |  |  | func (d *naughtyDisk) IsOnline() bool { | 
					
						
							|  |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err == errDiskNotFound | 
					
						
							| 
									
										
										
										
											2016-11-24 07:48:10 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-16 09:45:57 +08:00
										 |  |  | 	return d.disk.IsOnline() | 
					
						
							| 
									
										
										
										
											2016-11-24 07:48:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 00:19:15 +08:00
										 |  |  | func (d *naughtyDisk) LastConn() time.Time { | 
					
						
							|  |  |  | 	return d.disk.LastConn() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 05:27:20 +08:00
										 |  |  | func (d *naughtyDisk) IsLocal() bool { | 
					
						
							|  |  |  | 	return d.disk.IsLocal() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 10:39:32 +08:00
										 |  |  | func (d *naughtyDisk) Endpoint() Endpoint { | 
					
						
							|  |  |  | 	return d.disk.Endpoint() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 05:27:20 +08:00
										 |  |  | func (d *naughtyDisk) Hostname() string { | 
					
						
							|  |  |  | 	return d.disk.Hostname() | 
					
						
							| 
									
										
										
										
											2020-01-14 05:09:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | func (d *naughtyDisk) Healing() *healingTracker { | 
					
						
							| 
									
										
										
										
											2020-09-29 10:39:32 +08:00
										 |  |  | 	return d.disk.Healing() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-24 07:48:10 +08:00
										 |  |  | func (d *naughtyDisk) Close() (err error) { | 
					
						
							|  |  |  | 	if err = d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return d.disk.Close() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | func (d *naughtyDisk) calcError() (err error) { | 
					
						
							| 
									
										
										
										
											2016-09-17 04:06:49 +08:00
										 |  |  | 	d.mu.Lock() | 
					
						
							|  |  |  | 	defer d.mu.Unlock() | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	d.callNR++ | 
					
						
							|  |  |  | 	if err, ok := d.errors[d.callNR]; ok { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if d.defaultErr != nil { | 
					
						
							|  |  |  | 		return d.defaultErr | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | func (d *naughtyDisk) GetDiskLoc() (poolIdx, setIdx, diskIdx int) { | 
					
						
							|  |  |  | 	return -1, -1, -1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (d *naughtyDisk) SetDiskLoc(poolIdx, setIdx, diskIdx int) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-28 05:48:30 +08:00
										 |  |  | func (d *naughtyDisk) GetDiskID() (string, error) { | 
					
						
							|  |  |  | 	return d.disk.GetDiskID() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-26 01:37:53 +08:00
										 |  |  | func (d *naughtyDisk) SetDiskID(id string) { | 
					
						
							| 
									
										
										
										
											2020-03-28 05:48:30 +08:00
										 |  |  | 	d.disk.SetDiskID(id) | 
					
						
							| 
									
										
										
										
											2019-10-26 01:37:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-07 23:10:40 +08:00
										 |  |  | func (d *naughtyDisk) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode) (info dataUsageCache, err error) { | 
					
						
							|  |  |  | 	return d.disk.NSScanner(ctx, cache, updates, scanMode) | 
					
						
							| 
									
										
										
										
											2019-12-12 22:02:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) DiskInfo(ctx context.Context) (info DiskInfo, err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 06:32:08 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return info, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.DiskInfo(ctx) | 
					
						
							| 
									
										
										
										
											2016-09-10 06:32:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) MakeVolBulk(ctx context.Context, volumes ...string) (err error) { | 
					
						
							| 
									
										
										
										
											2019-12-24 08:31:03 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.MakeVolBulk(ctx, volumes...) | 
					
						
							| 
									
										
										
										
											2019-12-24 08:31:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) MakeVol(ctx context.Context, volume string) (err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.MakeVol(ctx, volume) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) ListVols(ctx context.Context) (vols []VolInfo, err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.ListVols(ctx) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) StatVol(ctx context.Context, volume string) (vol VolInfo, err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return VolInfo{}, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.StatVol(ctx, volume) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-01-03 01:15:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.DeleteVol(ctx, volume, forceDelete) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | func (d *naughtyDisk) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writer) error { | 
					
						
							|  |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return d.disk.WalkDir(ctx, opts, wr) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) ListDir(ctx context.Context, volume, dirPath string, count int) (entries []string, err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return []string{}, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.ListDir(ctx, volume, dirPath, count) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return 0, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.ReadFile(ctx, volume, path, offset, buf, verifier) | 
					
						
							| 
									
										
										
										
											2017-05-17 05:21:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error) { | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.ReadFileStream(ctx, volume, path, offset, length) | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) CreateFile(ctx context.Context, volume, path string, size int64, reader io.Reader) error { | 
					
						
							| 
									
										
										
										
											2016-10-30 03:44:44 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.CreateFile(ctx, volume, path, size, reader) | 
					
						
							| 
									
										
										
										
											2016-10-30 03:44:44 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) AppendFile(ctx context.Context, volume string, path string, buf []byte) error { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.AppendFile(ctx, volume, path, buf) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-06 07:51:37 +08:00
										 |  |  | func (d *naughtyDisk) RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string) (uint64, error) { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							| 
									
										
										
										
											2022-09-06 07:51:37 +08:00
										 |  |  | 		return 0, err | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-21 01:44:39 +08:00
										 |  |  | 	return d.disk.RenameData(ctx, srcVolume, srcPath, fi, dstVolume, dstPath) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) error { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.RenameFile(ctx, srcVolume, srcPath, dstVolume, dstPath) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) CheckParts(ctx context.Context, volume string, path string, fi FileInfo) (err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.CheckParts(ctx, volume, path, fi) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-12 00:15:54 +08:00
										 |  |  | func (d *naughtyDisk) Delete(ctx context.Context, volume string, path string, deleteOpts DeleteOptions) (err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-12 00:15:54 +08:00
										 |  |  | 	return d.disk.Delete(ctx, volume, path, deleteOpts) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-02 01:50:07 +08:00
										 |  |  | func (d *naughtyDisk) DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions) []error { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		errs := make([]error, len(versions)) | 
					
						
							|  |  |  | 		for i := range errs { | 
					
						
							|  |  |  | 			errs[i] = err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return errs | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.DeleteVersions(ctx, volume, versions) | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) (err error) { | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.WriteMetadata(ctx, volume, path, fi) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 04:32:31 +08:00
										 |  |  | func (d *naughtyDisk) UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo) (err error) { | 
					
						
							|  |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return d.disk.UpdateMetadata(ctx, volume, path, fi) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 02:33:43 +08:00
										 |  |  | func (d *naughtyDisk) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) (err error) { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-04 02:33:43 +08:00
										 |  |  | 	return d.disk.DeleteVersion(ctx, volume, path, fi, forceDelMarker) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:27:31 +08:00
										 |  |  | func (d *naughtyDisk) ReadVersion(ctx context.Context, volume, path, versionID string, readData bool) (fi FileInfo, err error) { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return FileInfo{}, err | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-08 11:27:31 +08:00
										 |  |  | 	return d.disk.ReadVersion(ctx, volume, path, versionID, readData) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-03 08:14:31 +08:00
										 |  |  | func (d *naughtyDisk) WriteAll(ctx context.Context, volume string, path string, b []byte) (err error) { | 
					
						
							| 
									
										
										
										
											2018-11-14 22:18:35 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-11-03 08:14:31 +08:00
										 |  |  | 	return d.disk.WriteAll(ctx, volume, path, b) | 
					
						
							| 
									
										
										
										
											2018-11-14 22:18:35 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error) { | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.ReadAll(ctx, volume, path) | 
					
						
							| 
									
										
										
										
											2016-09-10 03:53:09 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-21 03:49:05 +08:00
										 |  |  | func (d *naughtyDisk) ReadXL(ctx context.Context, volume string, path string, readData bool) (rf RawFileInfo, err error) { | 
					
						
							|  |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return rf, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return d.disk.ReadXL(ctx, volume, path, readData) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (d *naughtyDisk) VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error { | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return d.disk.VerifyFile(ctx, volume, path, fi) | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-07-10 02:29:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-02 02:50:00 +08:00
										 |  |  | func (d *naughtyDisk) StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error) { | 
					
						
							| 
									
										
										
										
											2021-07-10 02:29:16 +08:00
										 |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return stat, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-10-02 02:50:00 +08:00
										 |  |  | 	return d.disk.StatInfoFile(ctx, volume, path, glob) | 
					
						
							| 
									
										
										
										
											2021-07-10 02:29:16 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-19 23:35:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (d *naughtyDisk) ReadMultiple(ctx context.Context, req ReadMultipleReq, resp chan<- ReadMultipleResp) error { | 
					
						
							|  |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		close(resp) | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return d.disk.ReadMultiple(ctx, req, resp) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-11-29 02:20:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (d *naughtyDisk) CleanAbandonedData(ctx context.Context, volume string, path string) error { | 
					
						
							|  |  |  | 	if err := d.calcError(); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return d.disk.CleanAbandonedData(ctx, volume, path) | 
					
						
							|  |  |  | } |