| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-24 05:54:28 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016-2019 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2019-05-23 04:47:15 +08:00
										 |  |  | 	"bytes" | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	"encoding/hex" | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2019-03-01 03:01:25 +08:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 	"path" | 
					
						
							|  |  |  | 	"sort" | 
					
						
							|  |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-07 13:50:24 +08:00
										 |  |  | 	xhttp "github.com/minio/minio/cmd/http" | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	"github.com/minio/minio/cmd/logger" | 
					
						
							| 
									
										
										
										
											2019-10-15 00:44:51 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/sync/errgroup" | 
					
						
							| 
									
										
										
										
											2019-10-07 13:50:24 +08:00
										 |  |  | 	"github.com/minio/sha256-simd" | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | const erasureAlgorithmKlauspost = "klauspost/reedsolomon/vandermonde" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | // ObjectPartInfo Info of each part kept in the multipart metadata
 | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | // file after CompleteMultipartUpload() is called.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | type ObjectPartInfo struct { | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 	Number     int    `json:"number"` | 
					
						
							|  |  |  | 	Name       string `json:"name"` | 
					
						
							|  |  |  | 	ETag       string `json:"etag"` | 
					
						
							|  |  |  | 	Size       int64  `json:"size"` | 
					
						
							|  |  |  | 	ActualSize int64  `json:"actualSize"` | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | // byObjectPartNumber is a collection satisfying sort.Interface.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | type byObjectPartNumber []ObjectPartInfo | 
					
						
							| 
									
										
										
										
											2016-05-31 07:51:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | func (t byObjectPartNumber) Len() int           { return len(t) } | 
					
						
							|  |  |  | func (t byObjectPartNumber) Swap(i, j int)      { t[i], t[j] = t[j], t[i] } | 
					
						
							|  |  |  | func (t byObjectPartNumber) Less(i, j int) bool { return t[i].Number < t[j].Number } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | // ChecksumInfo - carries checksums of individual scattered parts per disk.
 | 
					
						
							|  |  |  | type ChecksumInfo struct { | 
					
						
							|  |  |  | 	Name      string | 
					
						
							|  |  |  | 	Algorithm BitrotAlgorithm | 
					
						
							|  |  |  | 	Hash      []byte | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-31 07:51:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | type checksumInfoJSON struct { | 
					
						
							|  |  |  | 	Name      string `json:"name"` | 
					
						
							|  |  |  | 	Algorithm string `json:"algorithm"` | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | 	Hash      string `json:"hash,omitempty"` | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | // MarshalJSON marshals the ChecksumInfo struct
 | 
					
						
							|  |  |  | func (c ChecksumInfo) MarshalJSON() ([]byte, error) { | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | 	info := checksumInfoJSON{ | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 		Name:      c.Name, | 
					
						
							|  |  |  | 		Algorithm: c.Algorithm.String(), | 
					
						
							|  |  |  | 		Hash:      hex.EncodeToString(c.Hash), | 
					
						
							| 
									
										
										
										
											2017-05-17 05:21:52 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	return json.Marshal(info) | 
					
						
							| 
									
										
										
										
											2017-05-17 05:21:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | // UnmarshalJSON - should never be called, instead xlMetaV1UnmarshalJSON() should be used.
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | func (c *ChecksumInfo) UnmarshalJSON(data []byte) error { | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | 	var info checksumInfoJSON | 
					
						
							|  |  |  | 	if err := json.Unmarshal(data, &info); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | 	sum, err := hex.DecodeString(info.Hash) | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | 	c.Name = info.Name | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	c.Algorithm = BitrotAlgorithmFromString(info.Algorithm) | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | 	c.Hash = sum | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	if !c.Algorithm.Available() { | 
					
						
							| 
									
										
										
										
											2018-08-07 06:14:08 +08:00
										 |  |  | 		logger.LogIf(context.Background(), errBitrotHashAlgoInvalid) | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 		return errBitrotHashAlgoInvalid | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2016-12-23 00:25:03 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | // ErasureInfo holds erasure coding and bitrot related information.
 | 
					
						
							|  |  |  | type ErasureInfo struct { | 
					
						
							|  |  |  | 	// Algorithm is the string representation of erasure-coding-algorithm
 | 
					
						
							|  |  |  | 	Algorithm string `json:"algorithm"` | 
					
						
							|  |  |  | 	// DataBlocks is the number of data blocks for erasure-coding
 | 
					
						
							|  |  |  | 	DataBlocks int `json:"data"` | 
					
						
							|  |  |  | 	// ParityBlocks is the number of parity blocks for erasure-coding
 | 
					
						
							|  |  |  | 	ParityBlocks int `json:"parity"` | 
					
						
							|  |  |  | 	// BlockSize is the size of one erasure-coded block
 | 
					
						
							|  |  |  | 	BlockSize int64 `json:"blockSize"` | 
					
						
							|  |  |  | 	// Index is the index of the current disk
 | 
					
						
							|  |  |  | 	Index int `json:"index"` | 
					
						
							|  |  |  | 	// Distribution is the distribution of the data and parity blocks
 | 
					
						
							|  |  |  | 	Distribution []int `json:"distribution"` | 
					
						
							|  |  |  | 	// Checksums holds all bitrot checksums of all erasure encoded blocks
 | 
					
						
							|  |  |  | 	Checksums []ChecksumInfo `json:"checksum,omitempty"` | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | // AddChecksumInfo adds a checksum of a part.
 | 
					
						
							|  |  |  | func (e *ErasureInfo) AddChecksumInfo(ckSumInfo ChecksumInfo) { | 
					
						
							|  |  |  | 	for i, sum := range e.Checksums { | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | 		if sum.Name == ckSumInfo.Name { | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 			e.Checksums[i] = ckSumInfo | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	e.Checksums = append(e.Checksums, ckSumInfo) | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | // GetChecksumInfo - get checksum of a part.
 | 
					
						
							|  |  |  | func (e ErasureInfo) GetChecksumInfo(partName string) (ckSum ChecksumInfo) { | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | 	// Return the checksum.
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	for _, sum := range e.Checksums { | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | 		if sum.Name == partName { | 
					
						
							| 
									
										
										
										
											2016-10-19 02:13:25 +08:00
										 |  |  | 			return sum | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	return ChecksumInfo{} | 
					
						
							| 
									
										
										
										
											2016-07-28 17:20:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | // statInfo - carries stat information of the object.
 | 
					
						
							|  |  |  | type statInfo struct { | 
					
						
							|  |  |  | 	Size    int64     `json:"size"`    // Size of the object `xl.json`.
 | 
					
						
							|  |  |  | 	ModTime time.Time `json:"modTime"` // ModTime of the object `xl.json`.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A xlMetaV1 represents `xl.json` metadata header.
 | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | type xlMetaV1 struct { | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | 	Version string   `json:"version"` // Version of the current `xl.json`.
 | 
					
						
							|  |  |  | 	Format  string   `json:"format"`  // Format of the current `xl.json`.
 | 
					
						
							|  |  |  | 	Stat    statInfo `json:"stat"`    // Stat of the current object `xl.json`.
 | 
					
						
							|  |  |  | 	// Erasure coded info for the current object `xl.json`.
 | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	Erasure ErasureInfo `json:"erasure"` | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  | 	// MinIO release tag for current object `xl.json`.
 | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 	Minio struct { | 
					
						
							|  |  |  | 		Release string `json:"release"` | 
					
						
							|  |  |  | 	} `json:"minio"` | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | 	// Metadata map for current object `xl.json`.
 | 
					
						
							| 
									
										
										
										
											2016-07-22 08:31:14 +08:00
										 |  |  | 	Meta map[string]string `json:"meta,omitempty"` | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | 	// Captures all the individual object `xl.json`.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	Parts []ObjectPartInfo `json:"parts,omitempty"` | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 04:24:34 +08:00
										 |  |  | // XL metadata constants.
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	// XL meta version.
 | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 	xlMetaVersion = "1.0.1" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XL meta version.
 | 
					
						
							|  |  |  | 	xlMetaVersion100 = "1.0.0" | 
					
						
							| 
									
										
										
										
											2017-01-19 04:24:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XL meta format string.
 | 
					
						
							|  |  |  | 	xlMetaFormat = "xl" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Add new constants here.
 | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-09 06:28:09 +08:00
										 |  |  | // newXLMetaV1 - initializes new xlMetaV1, adds version, allocates a fresh erasure info.
 | 
					
						
							|  |  |  | func newXLMetaV1(object string, dataBlocks, parityBlocks int) (xlMeta xlMetaV1) { | 
					
						
							| 
									
										
										
										
											2016-05-31 07:51:59 +08:00
										 |  |  | 	xlMeta = xlMetaV1{} | 
					
						
							| 
									
										
										
										
											2017-01-19 04:24:34 +08:00
										 |  |  | 	xlMeta.Version = xlMetaVersion | 
					
						
							|  |  |  | 	xlMeta.Format = xlMetaFormat | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | 	xlMeta.Minio.Release = ReleaseTag | 
					
						
							| 
									
										
										
										
											2017-08-15 09:08:42 +08:00
										 |  |  | 	xlMeta.Erasure = ErasureInfo{ | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | 		Algorithm:    erasureAlgorithmKlauspost, | 
					
						
							|  |  |  | 		DataBlocks:   dataBlocks, | 
					
						
							|  |  |  | 		ParityBlocks: parityBlocks, | 
					
						
							|  |  |  | 		BlockSize:    blockSizeV1, | 
					
						
							| 
									
										
										
										
											2016-07-09 06:28:09 +08:00
										 |  |  | 		Distribution: hashOrder(object, dataBlocks+parityBlocks), | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-31 07:51:59 +08:00
										 |  |  | 	return xlMeta | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | // Return a new xlMetaV1 initialized using the given xlMetaV1. Used in healing to make sure that we do not copy
 | 
					
						
							|  |  |  | // over any part's checksum info which will differ for different disks.
 | 
					
						
							|  |  |  | func newXLMetaFromXLMeta(meta xlMetaV1) xlMetaV1 { | 
					
						
							| 
									
										
										
										
											2019-01-20 10:28:40 +08:00
										 |  |  | 	xlMeta := meta | 
					
						
							|  |  |  | 	xlMeta.Erasure.Checksums = nil | 
					
						
							|  |  |  | 	xlMeta.Parts = nil | 
					
						
							| 
									
										
										
										
											2019-01-17 20:58:18 +08:00
										 |  |  | 	return xlMeta | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-02 07:43:31 +08:00
										 |  |  | // IsValid - tells if the format is sane by validating the version
 | 
					
						
							| 
									
										
										
										
											2018-01-12 20:46:30 +08:00
										 |  |  | // string, format and erasure info fields.
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | func (m xlMetaV1) IsValid() bool { | 
					
						
							| 
									
										
										
										
											2018-01-12 20:46:30 +08:00
										 |  |  | 	return isXLMetaFormatValid(m.Version, m.Format) && | 
					
						
							|  |  |  | 		isXLMetaErasureInfoValid(m.Erasure.DataBlocks, m.Erasure.ParityBlocks) | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Verifies if the backend format metadata is sane by validating
 | 
					
						
							|  |  |  | // the version string and format style.
 | 
					
						
							| 
									
										
										
										
											2018-01-12 20:46:30 +08:00
										 |  |  | func isXLMetaFormatValid(version, format string) bool { | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 	return ((version == xlMetaVersion || version == xlMetaVersion100) && | 
					
						
							|  |  |  | 		format == xlMetaFormat) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 20:46:30 +08:00
										 |  |  | // Verifies if the backend format metadata is sane by validating
 | 
					
						
							|  |  |  | // the ErasureInfo, i.e. data and parity blocks.
 | 
					
						
							|  |  |  | func isXLMetaErasureInfoValid(data, parity int) bool { | 
					
						
							|  |  |  | 	return ((data >= parity) && (data != 0) && (parity != 0)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | // Converts metadata to object info.
 | 
					
						
							|  |  |  | func (m xlMetaV1) ToObjectInfo(bucket, object string) ObjectInfo { | 
					
						
							|  |  |  | 	objInfo := ObjectInfo{ | 
					
						
							|  |  |  | 		IsDir:           false, | 
					
						
							|  |  |  | 		Bucket:          bucket, | 
					
						
							|  |  |  | 		Name:            object, | 
					
						
							|  |  |  | 		Size:            m.Stat.Size, | 
					
						
							|  |  |  | 		ModTime:         m.Stat.ModTime, | 
					
						
							|  |  |  | 		ContentType:     m.Meta["content-type"], | 
					
						
							|  |  |  | 		ContentEncoding: m.Meta["content-encoding"], | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-01 03:01:25 +08:00
										 |  |  | 	// Update expires
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		t time.Time | 
					
						
							|  |  |  | 		e error | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 	if exp, ok := m.Meta["expires"]; ok { | 
					
						
							|  |  |  | 		if t, e = time.Parse(http.TimeFormat, exp); e == nil { | 
					
						
							|  |  |  | 			objInfo.Expires = t.UTC() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-16 02:07:36 +08:00
										 |  |  | 	objInfo.backendType = BackendErasure | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 	// Extract etag from metadata.
 | 
					
						
							|  |  |  | 	objInfo.ETag = extractETag(m.Meta) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// etag/md5Sum has already been extracted. We need to
 | 
					
						
							|  |  |  | 	// remove to avoid it from appearing as part of
 | 
					
						
							|  |  |  | 	// response headers. e.g, X-Minio-* or X-Amz-*.
 | 
					
						
							| 
									
										
										
										
											2018-01-04 14:14:45 +08:00
										 |  |  | 	objInfo.UserDefined = cleanMetadata(m.Meta) | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 	// All the parts per object.
 | 
					
						
							|  |  |  | 	objInfo.Parts = m.Parts | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 01:56:28 +08:00
										 |  |  | 	// Update storage class
 | 
					
						
							| 
									
										
										
										
											2019-10-07 13:50:24 +08:00
										 |  |  | 	if sc, ok := m.Meta[xhttp.AmzStorageClass]; ok { | 
					
						
							| 
									
										
										
										
											2018-04-06 01:56:28 +08:00
										 |  |  | 		objInfo.StorageClass = sc | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		objInfo.StorageClass = globalMinioDefaultStorageClass | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 	// Success.
 | 
					
						
							|  |  |  | 	return objInfo | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | // objectPartIndex - returns the index of matching object part number.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | func objectPartIndex(parts []ObjectPartInfo, partNumber int) int { | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 	for i, part := range parts { | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 		if partNumber == part.Number { | 
					
						
							| 
									
										
										
										
											2016-08-16 22:57:14 +08:00
										 |  |  | 			return i | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // AddObjectPart - add a new object part in order.
 | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | func (m *xlMetaV1) AddObjectPart(partNumber int, partName string, partETag string, partSize int64, actualSize int64) { | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	partInfo := ObjectPartInfo{ | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 		Number:     partNumber, | 
					
						
							|  |  |  | 		Name:       partName, | 
					
						
							|  |  |  | 		ETag:       partETag, | 
					
						
							|  |  |  | 		Size:       partSize, | 
					
						
							|  |  |  | 		ActualSize: actualSize, | 
					
						
							| 
									
										
										
										
											2016-05-25 12:24:20 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Update part info if it already exists.
 | 
					
						
							| 
									
										
										
										
											2016-05-25 12:24:20 +08:00
										 |  |  | 	for i, part := range m.Parts { | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 		if partNumber == part.Number { | 
					
						
							| 
									
										
										
										
											2016-05-25 12:24:20 +08:00
										 |  |  | 			m.Parts[i] = partInfo | 
					
						
							|  |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Proceed to include new part info.
 | 
					
						
							| 
									
										
										
										
											2016-05-25 12:24:20 +08:00
										 |  |  | 	m.Parts = append(m.Parts, partInfo) | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Parts in xlMeta should be in sorted order by part number.
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | 	sort.Sort(byObjectPartNumber(m.Parts)) | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | // ObjectToPartOffset - translate offset of an object to offset of its individual part.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func (m xlMetaV1) ObjectToPartOffset(ctx context.Context, offset int64) (partIndex int, partOffset int64, err error) { | 
					
						
							| 
									
										
										
										
											2016-07-11 08:12:22 +08:00
										 |  |  | 	if offset == 0 { | 
					
						
							|  |  |  | 		// Special case - if offset is 0, then partIndex and partOffset are always 0.
 | 
					
						
							|  |  |  | 		return 0, 0, nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 	partOffset = offset | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 	// Seek until object offset maps to a particular part offset.
 | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 	for i, part := range m.Parts { | 
					
						
							| 
									
										
										
										
											2016-05-25 12:24:20 +08:00
										 |  |  | 		partIndex = i | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 		// Offset is smaller than size we have reached the proper part offset.
 | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 		if partOffset < part.Size { | 
					
						
							| 
									
										
										
										
											2016-05-25 12:24:20 +08:00
										 |  |  | 			return partIndex, partOffset, nil | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 		// Continue to towards the next part.
 | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 		partOffset -= part.Size | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	logger.LogIf(ctx, InvalidRange{}) | 
					
						
							| 
									
										
										
										
											2016-05-26 18:15:01 +08:00
										 |  |  | 	// Offset beyond the size of the object return InvalidRange.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	return 0, 0, InvalidRange{} | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-18 05:42:04 +08:00
										 |  |  | func getXLMetaInQuorum(ctx context.Context, metaArr []xlMetaV1, modTime time.Time, quorum int) (xmv xlMetaV1, e error) { | 
					
						
							|  |  |  | 	metaHashes := make([]string, len(metaArr)) | 
					
						
							|  |  |  | 	for i, meta := range metaArr { | 
					
						
							| 
									
										
										
										
											2016-10-19 02:13:25 +08:00
										 |  |  | 		if meta.IsValid() && meta.Stat.ModTime.Equal(modTime) { | 
					
						
							| 
									
										
										
										
											2018-08-18 05:42:04 +08:00
										 |  |  | 			h := sha256.New() | 
					
						
							|  |  |  | 			for _, p := range meta.Parts { | 
					
						
							|  |  |  | 				h.Write([]byte(p.Name)) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			metaHashes[i] = hex.EncodeToString(h.Sum(nil)) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	metaHashCountMap := make(map[string]int) | 
					
						
							|  |  |  | 	for _, hash := range metaHashes { | 
					
						
							|  |  |  | 		if hash == "" { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		metaHashCountMap[hash]++ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	maxHash := "" | 
					
						
							|  |  |  | 	maxCount := 0 | 
					
						
							|  |  |  | 	for hash, count := range metaHashCountMap { | 
					
						
							|  |  |  | 		if count > maxCount { | 
					
						
							|  |  |  | 			maxCount = count | 
					
						
							|  |  |  | 			maxHash = hash | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if maxCount < quorum { | 
					
						
							|  |  |  | 		return xlMetaV1{}, errXLReadQuorum | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, hash := range metaHashes { | 
					
						
							|  |  |  | 		if hash == maxHash { | 
					
						
							|  |  |  | 			return metaArr[i], nil | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-18 05:42:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return xlMetaV1{}, errXLReadQuorum | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // pickValidXLMeta - picks one valid xlMeta content and returns from a
 | 
					
						
							|  |  |  | // slice of xlmeta content.
 | 
					
						
							|  |  |  | func pickValidXLMeta(ctx context.Context, metaArr []xlMetaV1, modTime time.Time, quorum int) (xmv xlMetaV1, e error) { | 
					
						
							|  |  |  | 	return getXLMetaInQuorum(ctx, metaArr, modTime, quorum) | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-08 13:10:27 +08:00
										 |  |  | // list of all errors that can be ignored in a metadata operation.
 | 
					
						
							| 
									
										
										
										
											2017-06-01 11:03:32 +08:00
										 |  |  | var objMetadataOpIgnoredErrs = append(baseIgnoredErrs, errDiskAccessDenied, errVolumeNotFound, errFileNotFound, errFileAccessDenied, errCorruptedFormat) | 
					
						
							| 
									
										
										
										
											2016-07-08 13:10:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | // readXLMetaParts - returns the XL Metadata Parts from xl.json of one of the disks picked at random.
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | func (xl xlObjects) readXLMetaParts(ctx context.Context, bucket, object string) (xlMetaParts []ObjectPartInfo, xlMeta map[string]string, err error) { | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 	var ignoredErrs []error | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 	for _, disk := range xl.getLoadBalancedDisks() { | 
					
						
							|  |  |  | 		if disk == nil { | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 			ignoredErrs = append(ignoredErrs, errDiskNotFound) | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 		xlMetaParts, xlMeta, err = readXLMetaParts(ctx, disk, bucket, object) | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 		if err == nil { | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 			return xlMetaParts, xlMeta, nil | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		// For any reason disk or bucket is not available continue
 | 
					
						
							|  |  |  | 		// and read from other disks.
 | 
					
						
							| 
									
										
										
										
											2018-04-11 00:36:37 +08:00
										 |  |  | 		if IsErrIgnored(err, objMetadataOpIgnoredErrs...) { | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 			ignoredErrs = append(ignoredErrs, err) | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 		// Error is not ignored, return right here.
 | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 		return nil, nil, err | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 	// If all errors were ignored, reduce to maximal occurrence
 | 
					
						
							|  |  |  | 	// based on the read quorum.
 | 
					
						
							| 
									
										
										
										
											2018-02-16 09:45:57 +08:00
										 |  |  | 	readQuorum := len(xl.getDisks()) / 2 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	return nil, nil, reduceReadQuorumErrs(ctx, ignoredErrs, nil, readQuorum) | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // readXLMetaStat - return xlMetaV1.Stat and xlMetaV1.Meta from  one of the disks picked at random.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func (xl xlObjects) readXLMetaStat(ctx context.Context, bucket, object string) (xlStat statInfo, xlMeta map[string]string, err error) { | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 	var ignoredErrs []error | 
					
						
							| 
									
										
										
										
											2016-07-21 15:27:08 +08:00
										 |  |  | 	for _, disk := range xl.getLoadBalancedDisks() { | 
					
						
							| 
									
										
										
										
											2016-06-03 07:34:15 +08:00
										 |  |  | 		if disk == nil { | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 			ignoredErrs = append(ignoredErrs, errDiskNotFound) | 
					
						
							| 
									
										
										
										
											2016-06-03 07:34:15 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 		// parses only xlMetaV1.Meta and xlMeta.Stat
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 		xlStat, xlMeta, err = readXLMetaStat(ctx, disk, bucket, object) | 
					
						
							| 
									
										
										
										
											2016-07-08 13:10:27 +08:00
										 |  |  | 		if err == nil { | 
					
						
							| 
									
										
										
										
											2016-09-09 13:38:18 +08:00
										 |  |  | 			return xlStat, xlMeta, nil | 
					
						
							| 
									
										
										
										
											2016-07-08 13:10:27 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		// For any reason disk or bucket is not available continue
 | 
					
						
							|  |  |  | 		// and read from other disks.
 | 
					
						
							| 
									
										
										
										
											2018-04-11 00:36:37 +08:00
										 |  |  | 		if IsErrIgnored(err, objMetadataOpIgnoredErrs...) { | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 			ignoredErrs = append(ignoredErrs, err) | 
					
						
							| 
									
										
										
										
											2016-07-08 13:10:27 +08:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2016-05-25 16:33:39 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 		// Error is not ignored, return right here.
 | 
					
						
							|  |  |  | 		return statInfo{}, nil, err | 
					
						
							| 
									
										
										
										
											2016-05-25 16:33:39 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-14 16:46:16 +08:00
										 |  |  | 	// If all errors were ignored, reduce to maximal occurrence
 | 
					
						
							|  |  |  | 	// based on the read quorum.
 | 
					
						
							| 
									
										
										
										
											2018-02-16 09:45:57 +08:00
										 |  |  | 	readQuorum := len(xl.getDisks()) / 2 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	return statInfo{}, nil, reduceReadQuorumErrs(ctx, ignoredErrs, nil, readQuorum) | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | // writeXLMetadata - writes `xl.json` to a single disk.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func writeXLMetadata(ctx context.Context, disk StorageAPI, bucket, prefix string, xlMeta xlMetaV1) error { | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | 	jsonFile := path.Join(prefix, xlMetaJSONFile) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Marshal json.
 | 
					
						
							|  |  |  | 	metadataBytes, err := json.Marshal(&xlMeta) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 		logger.LogIf(ctx, err) | 
					
						
							|  |  |  | 		return err | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-14 22:18:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 07:02:02 +08:00
										 |  |  | 	// Persist marshaled data.
 | 
					
						
							| 
									
										
										
										
											2019-05-23 04:47:15 +08:00
										 |  |  | 	err = disk.WriteAll(bucket, jsonFile, bytes.NewReader(metadataBytes)) | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	logger.LogIf(ctx, err) | 
					
						
							|  |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-27 08:29:26 +08:00
										 |  |  | // Rename `xl.json` content to destination location for each disk in order.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func renameXLMetadata(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, quorum int) ([]StorageAPI, error) { | 
					
						
							| 
									
										
										
										
											2016-12-27 08:29:26 +08:00
										 |  |  | 	isDir := false | 
					
						
							|  |  |  | 	srcXLJSON := path.Join(srcEntry, xlMetaJSONFile) | 
					
						
							|  |  |  | 	dstXLJSON := path.Join(dstEntry, xlMetaJSONFile) | 
					
						
							| 
									
										
										
										
											2018-04-12 08:15:42 +08:00
										 |  |  | 	return rename(ctx, disks, srcBucket, srcXLJSON, dstBucket, dstXLJSON, isDir, quorum, []error{errFileNotFound}) | 
					
						
							| 
									
										
										
										
											2016-12-27 08:29:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | // writeUniqueXLMetadata - writes unique `xl.json` content for each disk in order.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func writeUniqueXLMetadata(ctx context.Context, disks []StorageAPI, bucket, prefix string, xlMetas []xlMetaV1, quorum int) ([]StorageAPI, error) { | 
					
						
							| 
									
										
										
										
											2019-10-15 00:44:51 +08:00
										 |  |  | 	g := errgroup.WithNErrs(len(disks)) | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Start writing `xl.json` to all disks in parallel.
 | 
					
						
							| 
									
										
										
										
											2019-10-15 00:44:51 +08:00
										 |  |  | 	for index := range disks { | 
					
						
							|  |  |  | 		index := index | 
					
						
							|  |  |  | 		g.Go(func() error { | 
					
						
							|  |  |  | 			if disks[index] == nil { | 
					
						
							|  |  |  | 				return errDiskNotFound | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// Pick one xlMeta for a disk at index.
 | 
					
						
							|  |  |  | 			xlMetas[index].Erasure.Index = index + 1 | 
					
						
							|  |  |  | 			return writeXLMetadata(ctx, disks[index], bucket, prefix, xlMetas[index]) | 
					
						
							|  |  |  | 		}, index) | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Wait for all the routines.
 | 
					
						
							| 
									
										
										
										
											2019-10-15 00:44:51 +08:00
										 |  |  | 	mErrs := g.Wait() | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-12 01:22:12 +08:00
										 |  |  | 	err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, quorum) | 
					
						
							| 
									
										
										
										
											2017-06-15 08:14:27 +08:00
										 |  |  | 	return evalDisks(disks, mErrs), err | 
					
						
							| 
									
										
										
										
											2016-05-21 11:48:47 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-10-07 13:50:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Returns per object readQuorum and writeQuorum
 | 
					
						
							|  |  |  | // readQuorum is the min required disks to read data.
 | 
					
						
							|  |  |  | // writeQuorum is the min required disks to write data.
 | 
					
						
							|  |  |  | func objectQuorumFromMeta(ctx context.Context, xl xlObjects, partsMetaData []xlMetaV1, errs []error) (objectReadQuorum, objectWriteQuorum int, err error) { | 
					
						
							|  |  |  | 	// get the latest updated Metadata and a count of all the latest updated xlMeta(s)
 | 
					
						
							|  |  |  | 	latestXLMeta, err := getLatestXLMeta(ctx, partsMetaData, errs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return 0, 0, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Since all the valid erasure code meta updated at the same time are equivalent, pass dataBlocks
 | 
					
						
							|  |  |  | 	// from latestXLMeta to get the quorum
 | 
					
						
							|  |  |  | 	return latestXLMeta.Erasure.DataBlocks, latestXLMeta.Erasure.DataBlocks + 1, nil | 
					
						
							|  |  |  | } |