| 
									
										
										
										
											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/>.
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"bytes" | 
					
						
							| 
									
										
										
										
											2019-11-14 04:17:45 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2019-09-26 14:08:24 +08:00
										 |  |  | 	"encoding/gob" | 
					
						
							|  |  |  | 	"encoding/hex" | 
					
						
							| 
									
										
										
										
											2020-06-18 05:49:26 +08:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2021-10-02 02:50:00 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	"io" | 
					
						
							|  |  |  | 	"io/ioutil" | 
					
						
							|  |  |  | 	"net/url" | 
					
						
							|  |  |  | 	"path" | 
					
						
							|  |  |  | 	"strconv" | 
					
						
							| 
									
										
										
										
											2019-12-24 08:31:03 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2020-12-11 05:03:22 +08:00
										 |  |  | 	"sync" | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2019-01-31 02:53:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	xhttp "github.com/minio/minio/internal/http" | 
					
						
							|  |  |  | 	"github.com/minio/minio/internal/logger" | 
					
						
							|  |  |  | 	"github.com/minio/minio/internal/rest" | 
					
						
							| 
									
										
										
										
											2021-06-15 05:54:37 +08:00
										 |  |  | 	xnet "github.com/minio/pkg/net" | 
					
						
							| 
									
										
										
										
											2021-01-08 11:27:31 +08:00
										 |  |  | 	xbufio "github.com/philhofer/fwd" | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	"github.com/tinylib/msgp/msgp" | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 07:29:46 +08:00
										 |  |  | func isNetworkError(err error) bool { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err == nil { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-07-30 05:48:18 +08:00
										 |  |  | 	if nerr, ok := err.(*rest.NetworkError); ok { | 
					
						
							| 
									
										
										
										
											2020-10-30 00:52:11 +08:00
										 |  |  | 		return xnet.IsNetworkOrHostDown(nerr.Err, false) | 
					
						
							| 
									
										
										
										
											2019-05-02 22:09:57 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-05-30 01:21:47 +08:00
										 |  |  | 	return false | 
					
						
							| 
									
										
										
										
											2019-05-02 22:09:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-15 10:45:17 +08:00
										 |  |  | // Converts network error to storageErr. This function is
 | 
					
						
							|  |  |  | // written so that the storageAPI errors are consistent
 | 
					
						
							|  |  |  | // across network disks.
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | func toStorageErr(err error) error { | 
					
						
							|  |  |  | 	if err == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 07:29:46 +08:00
										 |  |  | 	if isNetworkError(err) { | 
					
						
							| 
									
										
										
										
											2019-05-30 01:21:47 +08:00
										 |  |  | 		return errDiskNotFound | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch err.Error() { | 
					
						
							| 
									
										
										
										
											2019-10-02 04:12:15 +08:00
										 |  |  | 	case errFaultyDisk.Error(): | 
					
						
							|  |  |  | 		return errFaultyDisk | 
					
						
							|  |  |  | 	case errFileCorrupt.Error(): | 
					
						
							|  |  |  | 		return errFileCorrupt | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	case errUnexpected.Error(): | 
					
						
							|  |  |  | 		return errUnexpected | 
					
						
							|  |  |  | 	case errDiskFull.Error(): | 
					
						
							|  |  |  | 		return errDiskFull | 
					
						
							|  |  |  | 	case errVolumeNotFound.Error(): | 
					
						
							|  |  |  | 		return errVolumeNotFound | 
					
						
							|  |  |  | 	case errVolumeExists.Error(): | 
					
						
							|  |  |  | 		return errVolumeExists | 
					
						
							|  |  |  | 	case errFileNotFound.Error(): | 
					
						
							|  |  |  | 		return errFileNotFound | 
					
						
							| 
									
										
										
										
											2020-09-22 06:16:16 +08:00
										 |  |  | 	case errFileVersionNotFound.Error(): | 
					
						
							|  |  |  | 		return errFileVersionNotFound | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	case errFileNameTooLong.Error(): | 
					
						
							|  |  |  | 		return errFileNameTooLong | 
					
						
							|  |  |  | 	case errFileAccessDenied.Error(): | 
					
						
							|  |  |  | 		return errFileAccessDenied | 
					
						
							| 
									
										
										
										
											2021-01-03 04:01:29 +08:00
										 |  |  | 	case errPathNotFound.Error(): | 
					
						
							|  |  |  | 		return errPathNotFound | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	case errIsNotRegular.Error(): | 
					
						
							|  |  |  | 		return errIsNotRegular | 
					
						
							|  |  |  | 	case errVolumeNotEmpty.Error(): | 
					
						
							|  |  |  | 		return errVolumeNotEmpty | 
					
						
							|  |  |  | 	case errVolumeAccessDenied.Error(): | 
					
						
							|  |  |  | 		return errVolumeAccessDenied | 
					
						
							|  |  |  | 	case errCorruptedFormat.Error(): | 
					
						
							|  |  |  | 		return errCorruptedFormat | 
					
						
							|  |  |  | 	case errUnformattedDisk.Error(): | 
					
						
							|  |  |  | 		return errUnformattedDisk | 
					
						
							|  |  |  | 	case errInvalidAccessKeyID.Error(): | 
					
						
							|  |  |  | 		return errInvalidAccessKeyID | 
					
						
							|  |  |  | 	case errAuthentication.Error(): | 
					
						
							|  |  |  | 		return errAuthentication | 
					
						
							|  |  |  | 	case errRPCAPIVersionUnsupported.Error(): | 
					
						
							|  |  |  | 		return errRPCAPIVersionUnsupported | 
					
						
							|  |  |  | 	case errServerTimeMismatch.Error(): | 
					
						
							|  |  |  | 		return errServerTimeMismatch | 
					
						
							| 
									
										
										
										
											2019-10-02 04:12:15 +08:00
										 |  |  | 	case io.EOF.Error(): | 
					
						
							|  |  |  | 		return io.EOF | 
					
						
							|  |  |  | 	case io.ErrUnexpectedEOF.Error(): | 
					
						
							|  |  |  | 		return io.ErrUnexpectedEOF | 
					
						
							| 
									
										
										
										
											2019-10-26 01:37:53 +08:00
										 |  |  | 	case errDiskStale.Error(): | 
					
						
							|  |  |  | 		return errDiskNotFound | 
					
						
							| 
									
										
										
										
											2020-07-22 04:54:06 +08:00
										 |  |  | 	case errDiskNotFound.Error(): | 
					
						
							|  |  |  | 		return errDiskNotFound | 
					
						
							| 
									
										
										
										
											2019-01-31 02:53:57 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Abstracts a remote disk.
 | 
					
						
							|  |  |  | type storageRESTClient struct { | 
					
						
							|  |  |  | 	endpoint   Endpoint | 
					
						
							|  |  |  | 	restClient *rest.Client | 
					
						
							| 
									
										
										
										
											2019-10-26 01:37:53 +08:00
										 |  |  | 	diskID     string | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Indexes, will be -1 until assigned a set.
 | 
					
						
							|  |  |  | 	poolIndex, setIndex, diskIndex int | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	diskInfoCache timedValue | 
					
						
							|  |  |  | 	diskHealCache timedValue | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Retrieve location indexes.
 | 
					
						
							|  |  |  | func (client *storageRESTClient) GetDiskLoc() (poolIdx, setIdx, diskIdx int) { | 
					
						
							|  |  |  | 	return client.poolIndex, client.setIndex, client.diskIndex | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Set location indexes.
 | 
					
						
							|  |  |  | func (client *storageRESTClient) SetDiskLoc(poolIdx, setIdx, diskIdx int) { | 
					
						
							|  |  |  | 	client.poolIndex = poolIdx | 
					
						
							|  |  |  | 	client.setIndex = setIdx | 
					
						
							|  |  |  | 	client.diskIndex = diskIdx | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Wrapper to restClient.Call to handle network errors, in case of network error the connection is makred disconnected
 | 
					
						
							|  |  |  | // permanently. The only way to restore the storage connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints()
 | 
					
						
							|  |  |  | // after verifying format.json
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) call(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (io.ReadCloser, error) { | 
					
						
							| 
									
										
										
										
											2019-02-14 07:29:46 +08:00
										 |  |  | 	if values == nil { | 
					
						
							|  |  |  | 		values = make(url.Values) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-26 01:37:53 +08:00
										 |  |  | 	values.Set(storageRESTDiskID, client.diskID) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.restClient.Call(ctx, method, values, body, length) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err == nil { | 
					
						
							|  |  |  | 		return respBody, nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-01-15 10:45:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	err = toStorageErr(err) | 
					
						
							|  |  |  | 	return nil, err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Stringer provides a canonicalized representation of network device.
 | 
					
						
							|  |  |  | func (client *storageRESTClient) String() string { | 
					
						
							|  |  |  | 	return client.endpoint.String() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // IsOnline - returns whether RPC client failed to connect or not.
 | 
					
						
							|  |  |  | func (client *storageRESTClient) IsOnline() bool { | 
					
						
							| 
									
										
										
										
											2020-06-17 09:59:32 +08:00
										 |  |  | 	return client.restClient.IsOnline() | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 00:19:15 +08:00
										 |  |  | // LastConn - returns when the disk is seen to be connected the last time
 | 
					
						
							|  |  |  | func (client *storageRESTClient) LastConn() time.Time { | 
					
						
							|  |  |  | 	return client.restClient.LastConn() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 05:27:20 +08:00
										 |  |  | func (client *storageRESTClient) IsLocal() bool { | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 05:09:10 +08:00
										 |  |  | func (client *storageRESTClient) Hostname() string { | 
					
						
							|  |  |  | 	return client.endpoint.Host | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 10:39:32 +08:00
										 |  |  | func (client *storageRESTClient) Endpoint() Endpoint { | 
					
						
							|  |  |  | 	return client.endpoint | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | func (client *storageRESTClient) Healing() *healingTracker { | 
					
						
							|  |  |  | 	client.diskHealCache.Once.Do(func() { | 
					
						
							|  |  |  | 		// Update at least every second.
 | 
					
						
							|  |  |  | 		client.diskHealCache.TTL = time.Second | 
					
						
							|  |  |  | 		client.diskHealCache.Update = func() (interface{}, error) { | 
					
						
							|  |  |  | 			ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | 
					
						
							|  |  |  | 			defer cancel() | 
					
						
							|  |  |  | 			b, err := client.ReadAll(ctx, minioMetaBucket, | 
					
						
							|  |  |  | 				pathJoin(bucketMetaPrefix, healingTrackerFilename)) | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							|  |  |  | 				// If error, likely not healing.
 | 
					
						
							|  |  |  | 				return (*healingTracker)(nil), nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var h healingTracker | 
					
						
							|  |  |  | 			_, err = h.UnmarshalMsg(b) | 
					
						
							|  |  |  | 			return &h, err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	val, _ := client.diskHealCache.Get() | 
					
						
							|  |  |  | 	return val.(*healingTracker) | 
					
						
							| 
									
										
										
										
											2020-09-29 10:39:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-20 05:38:30 +08:00
										 |  |  | func (client *storageRESTClient) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry) (dataUsageCache, error) { | 
					
						
							|  |  |  | 	defer close(updates) | 
					
						
							| 
									
										
										
										
											2020-12-11 05:03:22 +08:00
										 |  |  | 	pr, pw := io.Pipe() | 
					
						
							|  |  |  | 	go func() { | 
					
						
							|  |  |  | 		pw.CloseWithError(cache.serializeTo(pw)) | 
					
						
							|  |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2021-02-27 07:11:42 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodNSScanner, url.Values{}, pr, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2021-05-12 00:18:37 +08:00
										 |  |  | 	pr.CloseWithError(err) | 
					
						
							| 
									
										
										
										
											2019-12-12 22:02:37 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-03-19 07:19:29 +08:00
										 |  |  | 		return cache, err | 
					
						
							| 
									
										
										
										
											2019-12-12 22:02:37 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-11 05:03:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-20 05:38:30 +08:00
										 |  |  | 	rr, rw := io.Pipe() | 
					
						
							| 
									
										
										
										
											2020-12-11 05:03:22 +08:00
										 |  |  | 	go func() { | 
					
						
							| 
									
										
										
										
											2021-05-20 05:38:30 +08:00
										 |  |  | 		rw.CloseWithError(waitForHTTPStream(respBody, rw)) | 
					
						
							| 
									
										
										
										
											2020-12-11 05:03:22 +08:00
										 |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2021-05-20 05:38:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ms := msgp.NewReader(rr) | 
					
						
							|  |  |  | 	for { | 
					
						
							|  |  |  | 		// Read whether it is an update.
 | 
					
						
							|  |  |  | 		upd, err := ms.ReadBool() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			rr.CloseWithError(err) | 
					
						
							|  |  |  | 			return cache, err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if !upd { | 
					
						
							|  |  |  | 			// No more updates... New cache follows.
 | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		var update dataUsageEntry | 
					
						
							|  |  |  | 		err = update.DecodeMsg(ms) | 
					
						
							|  |  |  | 		if err != nil || err == io.EOF { | 
					
						
							|  |  |  | 			rr.CloseWithError(err) | 
					
						
							|  |  |  | 			return cache, err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		updates <- update | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var newCache dataUsageCache | 
					
						
							|  |  |  | 	err = newCache.DecodeMsg(ms) | 
					
						
							|  |  |  | 	rr.CloseWithError(err) | 
					
						
							|  |  |  | 	if err == io.EOF { | 
					
						
							|  |  |  | 		err = nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-05 00:14:14 +08:00
										 |  |  | 	return newCache, err | 
					
						
							| 
									
										
										
										
											2019-12-12 22:02:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-28 05:48:30 +08:00
										 |  |  | func (client *storageRESTClient) GetDiskID() (string, error) { | 
					
						
							| 
									
										
										
										
											2020-05-29 04:03:04 +08:00
										 |  |  | 	// This call should never be over the network, this is always
 | 
					
						
							|  |  |  | 	// a cached value - caller should make sure to use this
 | 
					
						
							|  |  |  | 	// function on a fresh disk or make sure to look at the error
 | 
					
						
							|  |  |  | 	// from a different networked call to validate the GetDiskID()
 | 
					
						
							|  |  |  | 	return client.diskID, nil | 
					
						
							| 
									
										
										
										
											2020-03-28 05:48:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-26 01:37:53 +08:00
										 |  |  | func (client *storageRESTClient) SetDiskID(id string) { | 
					
						
							|  |  |  | 	client.diskID = id | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-23 16:13:47 +08:00
										 |  |  | func (client *storageRESTClient) diskInfo() (interface{}, error) { | 
					
						
							|  |  |  | 	var info DiskInfo | 
					
						
							|  |  |  | 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | 
					
						
							|  |  |  | 	defer cancel() | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodDiskInfo, nil, nil, -1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return info, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							|  |  |  | 	if err = msgp.Decode(respBody, &info); err != nil { | 
					
						
							|  |  |  | 		return info, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if info.Error != "" { | 
					
						
							|  |  |  | 		return info, toStorageErr(errors.New(info.Error)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return info, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | // DiskInfo - fetch disk information for a remote disk.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) DiskInfo(ctx context.Context) (info DiskInfo, err error) { | 
					
						
							| 
									
										
										
										
											2021-04-30 00:54:16 +08:00
										 |  |  | 	if !client.IsOnline() { | 
					
						
							|  |  |  | 		// make sure to check if the disk is offline, since the underlying
 | 
					
						
							|  |  |  | 		// value is cached we should attempt to invalidate it if such calls
 | 
					
						
							|  |  |  | 		// were attempted. This can lead to false success under certain conditions
 | 
					
						
							|  |  |  | 		// - this change attempts to avoid stale information if the underlying
 | 
					
						
							|  |  |  | 		// transport is already down.
 | 
					
						
							|  |  |  | 		return info, errDiskNotFound | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 	client.diskInfoCache.Once.Do(func() { | 
					
						
							|  |  |  | 		client.diskInfoCache.TTL = time.Second | 
					
						
							| 
									
										
										
										
											2021-08-23 16:13:47 +08:00
										 |  |  | 		client.diskInfoCache.Update = client.diskInfo | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	val, err := client.diskInfoCache.Get() | 
					
						
							| 
									
										
										
										
											2021-08-24 03:53:54 +08:00
										 |  |  | 	if val != nil { | 
					
						
							|  |  |  | 		return val.(DiskInfo), err | 
					
						
							| 
									
										
										
										
											2021-02-13 10:17:52 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 	return info, err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-24 08:31:03 +08:00
										 |  |  | // MakeVolBulk - create multiple volumes in a bulk operation.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) MakeVolBulk(ctx context.Context, volumes ...string) (err error) { | 
					
						
							| 
									
										
										
										
											2019-12-24 08:31:03 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolumes, strings.Join(volumes, ",")) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodMakeVolBulk, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2019-12-24 08:31:03 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | // MakeVol - create a volume on a remote disk.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) MakeVol(ctx context.Context, volume string) (err error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodMakeVol, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ListVols - List all volumes on a remote disk.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) ListVols(ctx context.Context) (vols []VolInfo, err error) { | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodListVols, nil, nil, -1) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-11-05 02:10:54 +08:00
										 |  |  | 	vinfos := VolsInfo(vols) | 
					
						
							|  |  |  | 	err = msgp.Decode(respBody, &vinfos) | 
					
						
							|  |  |  | 	return vinfos, err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // StatVol - get volume info over the network.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) StatVol(ctx context.Context, volume string) (vol VolInfo, err error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodStatVol, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-11-05 02:10:54 +08:00
										 |  |  | 	err = msgp.Decode(respBody, &vol) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	return vol, err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // DeleteVol - Deletes a volume over the network.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							| 
									
										
										
										
											2020-03-28 12:52:59 +08:00
										 |  |  | 	if forceDelete { | 
					
						
							|  |  |  | 		values.Set(storageRESTForceDelete, "true") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodDeleteVol, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | // AppendFile - append to a file.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) AppendFile(ctx context.Context, volume string, path string, buf []byte) error { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	reader := bytes.NewReader(buf) | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodAppendFile, values, reader, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) CreateFile(ctx context.Context, volume, path string, size int64, reader io.Reader) error { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	values.Set(storageRESTLength, strconv.Itoa(int(size))) | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodCreateFile, values, ioutil.NopCloser(reader), size) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2021-08-28 00:16:36 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	_, err = waitForHTTPResponse(respBody) | 
					
						
							| 
									
										
										
										
											2021-03-24 14:47:13 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) error { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var reader bytes.Buffer | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	if err := msgp.Encode(&reader, &fi); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodWriteMetadata, values, &reader, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 04:32:31 +08:00
										 |  |  | func (client *storageRESTClient) UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo) error { | 
					
						
							|  |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var reader bytes.Buffer | 
					
						
							|  |  |  | 	if err := msgp.Encode(&reader, &fi); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodUpdateMetadata, values, &reader, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2021-04-05 04:32:31 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 02:33:43 +08:00
										 |  |  | func (client *storageRESTClient) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) error { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2021-02-04 02:33:43 +08:00
										 |  |  | 	values.Set(storageRESTForceDelMarker, strconv.FormatBool(forceDelMarker)) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 01:20:31 +08:00
										 |  |  | 	var buffer bytes.Buffer | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	if err := msgp.Encode(&buffer, &fi); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-27 07:49:49 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-24 01:20:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 01:09:45 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodDeleteVersion, values, &buffer, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 22:18:35 +08:00
										 |  |  | // WriteAll - write all data to a file.
 | 
					
						
							| 
									
										
										
										
											2020-11-03 08:14:31 +08:00
										 |  |  | func (client *storageRESTClient) WriteAll(ctx context.Context, volume string, path string, b []byte) error { | 
					
						
							| 
									
										
										
										
											2018-11-14 22:18:35 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2020-11-03 08:14:31 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodWriteAll, values, bytes.NewBuffer(b), int64(len(b))) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-11-14 22:18:35 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | // CheckParts - stat all file parts.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) CheckParts(ctx context.Context, volume string, path string, fi FileInfo) error { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var reader bytes.Buffer | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	if err := msgp.Encode(&reader, &fi); err != nil { | 
					
						
							| 
									
										
										
										
											2020-08-25 04:47:01 +08:00
										 |  |  | 		logger.LogIf(context.Background(), err) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodCheckParts, values, &reader, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // RenameData - rename source path to destination path atomically, metadata and data file.
 | 
					
						
							| 
									
										
										
										
											2021-04-21 01:44:39 +08:00
										 |  |  | func (client *storageRESTClient) RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string) (err error) { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTSrcVolume, srcVolume) | 
					
						
							|  |  |  | 	values.Set(storageRESTSrcPath, srcPath) | 
					
						
							|  |  |  | 	values.Set(storageRESTDstVolume, dstVolume) | 
					
						
							|  |  |  | 	values.Set(storageRESTDstPath, dstPath) | 
					
						
							| 
									
										
										
										
											2021-04-21 01:44:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var reader bytes.Buffer | 
					
						
							|  |  |  | 	if err = msgp.Encode(&reader, &fi); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodRenameData, values, &reader, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:27:31 +08:00
										 |  |  | // where we keep old *Readers
 | 
					
						
							|  |  |  | var readMsgpReaderPool = sync.Pool{New: func() interface{} { return &msgp.Reader{} }} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // mspNewReader returns a *Reader that reads from the provided reader.
 | 
					
						
							|  |  |  | // The reader will be buffered.
 | 
					
						
							|  |  |  | func msgpNewReader(r io.Reader) *msgp.Reader { | 
					
						
							|  |  |  | 	p := readMsgpReaderPool.Get().(*msgp.Reader) | 
					
						
							|  |  |  | 	if p.R == nil { | 
					
						
							|  |  |  | 		p.R = xbufio.NewReaderSize(r, 8<<10) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		p.R.Reset(r) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return p | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (client *storageRESTClient) ReadVersion(ctx context.Context, volume, path, versionID string, readData bool) (fi FileInfo, err error) { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							|  |  |  | 	values.Set(storageRESTVersionID, versionID) | 
					
						
							| 
									
										
										
										
											2021-01-08 11:27:31 +08:00
										 |  |  | 	values.Set(storageRESTReadData, strconv.FormatBool(readData)) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodReadVersion, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		return fi, err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2021-01-08 11:27:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dec := msgpNewReader(respBody) | 
					
						
							|  |  |  | 	defer readMsgpReaderPool.Put(dec) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = fi.DecodeMsg(dec) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	return fi, err | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ReadAll - reads all contents of a file.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) ReadAll(ctx context.Context, volume string, path string) ([]byte, error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodReadAll, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return ioutil.ReadAll(respBody) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | // ReadFileStream - returns a reader for the requested file.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error) { | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							|  |  |  | 	values.Set(storageRESTOffset, strconv.Itoa(int(offset))) | 
					
						
							|  |  |  | 	values.Set(storageRESTLength, strconv.Itoa(int(length))) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodReadFileStream, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return respBody, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | // ReadFile - reads section of a file.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (int64, error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							|  |  |  | 	values.Set(storageRESTOffset, strconv.Itoa(int(offset))) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	values.Set(storageRESTLength, strconv.Itoa(len(buf))) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if verifier != nil { | 
					
						
							|  |  |  | 		values.Set(storageRESTBitrotAlgo, verifier.algorithm.String()) | 
					
						
							|  |  |  | 		values.Set(storageRESTBitrotHash, hex.EncodeToString(verifier.sum)) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		values.Set(storageRESTBitrotAlgo, "") | 
					
						
							|  |  |  | 		values.Set(storageRESTBitrotHash, "") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodReadFile, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return 0, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	n, err := io.ReadFull(respBody, buf) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return int64(n), err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ListDir - lists a directory.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) ListDir(ctx context.Context, volume, dirPath string, count int) (entries []string, err error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTDirPath, dirPath) | 
					
						
							|  |  |  | 	values.Set(storageRESTCount, strconv.Itoa(count)) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodListDir, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	err = gob.NewDecoder(respBody).Decode(&entries) | 
					
						
							|  |  |  | 	return entries, err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // DeleteFile - deletes a file.
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | func (client *storageRESTClient) Delete(ctx context.Context, volume string, path string, recursive bool) error { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	values.Set(storageRESTRecursive, strconv.FormatBool(recursive)) | 
					
						
							| 
									
										
										
										
											2020-11-18 01:09:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	respBody, err := client.call(ctx, storageRESTMethodDeleteFile, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | // DeleteVersions - deletes list of specified versions if present
 | 
					
						
							| 
									
										
										
										
											2021-11-02 01:50:07 +08:00
										 |  |  | func (client *storageRESTClient) DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions) (errs []error) { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if len(versions) == 0 { | 
					
						
							|  |  |  | 		return errs | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	values.Set(storageRESTTotalVersions, strconv.Itoa(len(versions))) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var buffer bytes.Buffer | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	encoder := msgp.NewWriter(&buffer) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	for _, version := range versions { | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 		version.EncodeMsg(encoder) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	logger.LogIf(ctx, encoder.Flush()) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	errs = make([]error, len(versions)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodDeleteVersions, values, &buffer, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-01-07 02:47:49 +08:00
										 |  |  | 		if contextCanceled(ctx) { | 
					
						
							|  |  |  | 			err = ctx.Err() | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		for i := range errs { | 
					
						
							|  |  |  | 			errs[i] = err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return errs | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 07:19:29 +08:00
										 |  |  | 	reader, err := waitForHTTPResponse(respBody) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		for i := range errs { | 
					
						
							|  |  |  | 			errs[i] = err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return errs | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	dErrResp := &DeleteVersionsErrsResp{} | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	if err = gob.NewDecoder(reader).Decode(dErrResp); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		for i := range errs { | 
					
						
							|  |  |  | 			errs[i] = err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return errs | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	for i, dErr := range dErrResp.Errs { | 
					
						
							|  |  |  | 		errs[i] = toStorageErr(dErr) | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	return errs | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | // RenameFile - renames a file.
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) (err error) { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTSrcVolume, srcVolume) | 
					
						
							|  |  |  | 	values.Set(storageRESTSrcPath, srcPath) | 
					
						
							|  |  |  | 	values.Set(storageRESTDstVolume, dstVolume) | 
					
						
							|  |  |  | 	values.Set(storageRESTDstPath, dstPath) | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodRenameFile, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | func (client *storageRESTClient) VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error { | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2019-09-13 04:08:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	var reader bytes.Buffer | 
					
						
							| 
									
										
										
										
											2020-11-03 09:07:52 +08:00
										 |  |  | 	if err := msgp.Encode(&reader, &fi); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodVerifyFile, values, &reader, -1) | 
					
						
							| 
									
										
										
										
											2021-04-26 23:59:54 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	respReader, err := waitForHTTPResponse(respBody) | 
					
						
							| 
									
										
										
										
											2020-03-11 23:56:36 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 	verifyResp := &VerifyFileResp{} | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if err = gob.NewDecoder(respReader).Decode(verifyResp); err != nil { | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-09 04:51:18 +08:00
										 |  |  | 	return toStorageErr(verifyResp.Err) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-02 02:50:00 +08:00
										 |  |  | func (client *storageRESTClient) StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error) { | 
					
						
							| 
									
										
										
										
											2021-07-10 02:29:16 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(storageRESTVolume, volume) | 
					
						
							|  |  |  | 	values.Set(storageRESTFilePath, path) | 
					
						
							| 
									
										
										
										
											2021-10-02 02:50:00 +08:00
										 |  |  | 	values.Set(storageRESTGlob, fmt.Sprint(glob)) | 
					
						
							| 
									
										
										
										
											2021-07-10 02:29:16 +08:00
										 |  |  | 	respBody, err := client.call(ctx, storageRESTMethodStatInfoFile, values, nil, -1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return stat, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							|  |  |  | 	respReader, err := waitForHTTPResponse(respBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return stat, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-10-02 02:50:00 +08:00
										 |  |  | 	rd := msgpNewReader(respReader) | 
					
						
							|  |  |  | 	for { | 
					
						
							|  |  |  | 		var st StatInfo | 
					
						
							|  |  |  | 		err = st.DecodeMsg(rd) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			if errors.Is(err, io.EOF) { | 
					
						
							|  |  |  | 				err = nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		stat = append(stat, st) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-10 02:29:16 +08:00
										 |  |  | 	return stat, err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | // Close - marks the client as closed.
 | 
					
						
							|  |  |  | func (client *storageRESTClient) Close() error { | 
					
						
							| 
									
										
										
										
											2018-11-21 03:07:19 +08:00
										 |  |  | 	client.restClient.Close() | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Returns a storage rest client.
 | 
					
						
							| 
									
										
										
										
											2020-10-27 01:29:29 +08:00
										 |  |  | func newStorageRESTClient(endpoint Endpoint, healthcheck bool) *storageRESTClient { | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	serverURL := &url.URL{ | 
					
						
							| 
									
										
										
										
											2019-11-14 04:17:45 +08:00
										 |  |  | 		Scheme: endpoint.Scheme, | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 		Host:   endpoint.Host, | 
					
						
							| 
									
										
										
										
											2019-11-05 01:30:59 +08:00
										 |  |  | 		Path:   path.Join(storageRESTPrefix, endpoint.Path, storageRESTVersion), | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 01:51:53 +08:00
										 |  |  | 	restClient := rest.NewClient(serverURL, globalInternodeTransport, newCachedAuthToken()) | 
					
						
							| 
									
										
										
										
											2020-11-11 01:28:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 01:29:29 +08:00
										 |  |  | 	if healthcheck { | 
					
						
							| 
									
										
										
										
											2020-11-11 01:28:23 +08:00
										 |  |  | 		// Use a separate client to avoid recursive calls.
 | 
					
						
							| 
									
										
										
										
											2021-11-24 01:51:53 +08:00
										 |  |  | 		healthClient := rest.NewClient(serverURL, globalInternodeTransport, newCachedAuthToken()) | 
					
						
							| 
									
										
										
										
											2020-11-11 01:28:23 +08:00
										 |  |  | 		healthClient.ExpectTimeouts = true | 
					
						
							| 
									
										
										
										
											2021-06-09 05:09:26 +08:00
										 |  |  | 		healthClient.NoMetrics = true | 
					
						
							| 
									
										
										
										
											2020-10-27 01:29:29 +08:00
										 |  |  | 		restClient.HealthCheckFn = func() bool { | 
					
						
							| 
									
										
										
										
											2021-01-29 05:38:12 +08:00
										 |  |  | 			ctx, cancel := context.WithTimeout(context.Background(), restClient.HealthCheckTimeout) | 
					
						
							| 
									
										
										
										
											2020-12-14 03:57:08 +08:00
										 |  |  | 			defer cancel() | 
					
						
							| 
									
										
										
										
											2020-11-11 01:28:23 +08:00
										 |  |  | 			respBody, err := healthClient.Call(ctx, storageRESTMethodHealth, nil, nil, -1) | 
					
						
							| 
									
										
										
										
											2020-10-27 01:29:29 +08:00
										 |  |  | 			xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2020-11-20 05:53:49 +08:00
										 |  |  | 			return toStorageErr(err) != errDiskNotFound | 
					
						
							| 
									
										
										
										
											2020-10-27 01:29:29 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-06-18 05:49:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 	return &storageRESTClient{endpoint: endpoint, restClient: restClient, poolIndex: -1, setIndex: -1, diskIndex: -1} | 
					
						
							| 
									
										
										
										
											2018-10-05 08:44:06 +08:00
										 |  |  | } |