From f44cfb2863a1dfa4f184fdf75560f0ca14ce8ec2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 9 Apr 2020 09:30:02 -0700 Subject: [PATCH] use GlobalContext whenever possible (#9280) This change is throughout the codebase to ensure that all codepaths honor GlobalContext --- cmd/admin-handlers-config-kv.go | 4 +- cmd/admin-handlers.go | 2 +- cmd/admin-handlers_test.go | 7 +- cmd/admin-heal-ops.go | 2 +- cmd/bitrot-streaming.go | 3 +- cmd/bitrot-whole.go | 9 +- cmd/bitrot.go | 5 +- cmd/bootstrap-peer-server.go | 2 +- cmd/bucket-encryption.go | 6 +- cmd/bucket-handlers.go | 9 +- cmd/bucket-handlers_test.go | 5 +- cmd/bucket-policy-handlers_test.go | 3 +- cmd/common-main.go | 3 +- cmd/config-current.go | 7 +- cmd/config-encrypted.go | 12 +-- cmd/config-migrate.go | 23 +++--- cmd/disk-cache-backend.go | 10 +-- cmd/disk-cache.go | 2 +- cmd/disk-cache_test.go | 3 +- cmd/encryption-v1.go | 4 +- cmd/endpoint.go | 9 +- cmd/format-xl.go | 4 +- cmd/fs-v1-helpers_test.go | 81 +++++++++--------- cmd/fs-v1-metadata_test.go | 13 ++- cmd/fs-v1-multipart_test.go | 44 +++++----- cmd/fs-v1-rwpool.go | 3 +- cmd/fs-v1.go | 4 +- cmd/fs-v1_test.go | 77 +++++++++--------- cmd/gateway-main.go | 5 +- cmd/gateway-startup-msg.go | 3 +- cmd/gateway/azure/gateway-azure_test.go | 11 ++- cmd/gateway/b2/gateway-b2.go | 2 +- cmd/gateway/gcs/gateway-gcs.go | 10 +-- cmd/gateway/hdfs/gateway-hdfs.go | 4 +- cmd/gateway/oss/gateway-oss_test.go | 5 +- cmd/gateway/s3/gateway-s3-metadata_test.go | 5 +- cmd/gateway/s3/gateway-s3.go | 2 +- cmd/generic-handlers.go | 3 +- cmd/handler-utils.go | 4 +- cmd/jwt.go | 3 +- cmd/lifecycle.go | 6 +- cmd/lock-rest-client.go | 3 +- cmd/metrics.go | 11 ++- cmd/namespace-lock.go | 2 +- cmd/notification.go | 52 ++++++------ cmd/object-api-utils.go | 3 +- cmd/object-lock.go | 2 +- cmd/peer-rest-client.go | 14 ++-- cmd/peer-rest-server.go | 4 +- cmd/policy.go | 10 +-- cmd/posix-list-dir_other.go | 3 +- cmd/posix.go | 8 +- cmd/prepare-storage.go | 5 +- cmd/server-main.go | 4 +- cmd/server-startup-msg.go | 7 +- cmd/signature-v4-utils.go | 3 +- cmd/storage-rest-client.go | 2 +- cmd/storage-rest-server.go | 3 +- cmd/update.go | 6 +- cmd/utils.go | 2 +- cmd/web-handler-context.go | 2 +- cmd/web-handlers.go | 4 +- cmd/xl-sets.go | 10 +-- cmd/xl-v1-common.go | 2 +- cmd/xl-v1-common_test.go | 7 +- cmd/xl-v1-healing-common_test.go | 15 ++-- cmd/xl-v1-healing.go | 2 +- cmd/xl-v1-healing_test.go | 43 +++++----- cmd/xl-v1-metadata.go | 2 +- cmd/xl-v1-metadata_test.go | 5 +- cmd/xl-v1-multipart_test.go | 10 +-- cmd/xl-v1-object_test.go | 95 +++++++++++----------- cmd/xl-v1-utils.go | 2 +- cmd/xl-v1-utils_test.go | 13 ++- cmd/xl-v1.go | 2 +- cmd/xl-zones.go | 6 +- 76 files changed, 374 insertions(+), 409 deletions(-) diff --git a/cmd/admin-handlers-config-kv.go b/cmd/admin-handlers-config-kv.go index 7477ae4cc..2bdc6e8f7 100644 --- a/cmd/admin-handlers-config-kv.go +++ b/cmd/admin-handlers-config-kv.go @@ -162,7 +162,7 @@ func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Requ // Make sure to write backend is encrypted if globalConfigEncrypted { - saveConfig(context.Background(), objectAPI, backendEncryptedFile, backendEncryptedMigrationComplete) + saveConfig(GlobalContext, objectAPI, backendEncryptedFile, backendEncryptedMigrationComplete) } writeSuccessResponseHeadersOnly(w) @@ -403,7 +403,7 @@ func (a adminAPIHandlers) SetConfigHandler(w http.ResponseWriter, r *http.Reques // Make sure to write backend is encrypted if globalConfigEncrypted { - saveConfig(context.Background(), objectAPI, backendEncryptedFile, backendEncryptedMigrationComplete) + saveConfig(GlobalContext, objectAPI, backendEncryptedFile, backendEncryptedMigrationComplete) } writeSuccessResponseHeadersOnly(w) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 43f058979..d0a262f48 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -790,7 +790,7 @@ func extractHealInitParams(vars map[string]string, qParms url.Values, r io.Reade if hip.clientToken == "" { jerr := json.NewDecoder(r).Decode(&hip.hs) if jerr != nil { - logger.LogIf(context.Background(), jerr, logger.Application) + logger.LogIf(GlobalContext, jerr, logger.Application) err = ErrRequestBodyParse return } diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index 0b7c1f48a..faf6dade7 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "encoding/json" "io" "io/ioutil" @@ -72,7 +71,7 @@ func prepareAdminXLTestBed() (*adminXLTestBed, error) { globalIAMSys = NewIAMSys() globalIAMSys.Init(GlobalContext, objLayer) - buckets, err := objLayer.ListBuckets(context.Background()) + buckets, err := objLayer.ListBuckets(GlobalContext) if err != nil { return nil, err } @@ -314,12 +313,12 @@ func TestToAdminAPIErrCode(t *testing.T) { // 3. Non-admin API specific error. { err: errDiskNotFound, - expectedAPIErr: toAPIErrorCode(context.Background(), errDiskNotFound), + expectedAPIErr: toAPIErrorCode(GlobalContext, errDiskNotFound), }, } for i, test := range testCases { - actualErr := toAdminAPIErrCode(context.Background(), test.err) + actualErr := toAdminAPIErrCode(GlobalContext, test.err) if actualErr != test.expectedAPIErr { t.Errorf("Test %d: Expected %v but received %v", i+1, test.expectedAPIErr, actualErr) diff --git a/cmd/admin-heal-ops.go b/cmd/admin-heal-ops.go index ba99084f9..4696ff74b 100644 --- a/cmd/admin-heal-ops.go +++ b/cmd/admin-heal-ops.go @@ -183,7 +183,7 @@ func (ahs *allHealState) stopHealSequence(path string) ([]byte, APIError) { } b, err := json.Marshal(&hsp) - return b, toAdminAPIErr(context.Background(), err) + return b, toAdminAPIErr(GlobalContext, err) } // LaunchNewHealSequence - launches a background routine that performs diff --git a/cmd/bitrot-streaming.go b/cmd/bitrot-streaming.go index f6d55705b..b05fbe170 100644 --- a/cmd/bitrot-streaming.go +++ b/cmd/bitrot-streaming.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "encoding/hex" "fmt" "hash" @@ -142,7 +141,7 @@ func (b *streamingBitrotReader) ReadAt(buf []byte, offset int64) (int, error) { if !bytes.Equal(b.h.Sum(nil), b.hashBytes) { err := &errHashMismatch{fmt.Sprintf("hashes do not match expected %s, got %s", hex.EncodeToString(b.hashBytes), hex.EncodeToString(b.h.Sum(nil)))} - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return 0, err } b.currOffset += int64(len(buf)) diff --git a/cmd/bitrot-whole.go b/cmd/bitrot-whole.go index 2416e687c..fc016b56f 100644 --- a/cmd/bitrot-whole.go +++ b/cmd/bitrot-whole.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "hash" "io" @@ -36,12 +35,12 @@ type wholeBitrotWriter struct { func (b *wholeBitrotWriter) Write(p []byte) (int, error) { err := b.disk.AppendFile(b.volume, b.filePath, p) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return 0, err } _, err = b.Hash.Write(p) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return 0, err } return len(p), nil @@ -70,14 +69,14 @@ func (b *wholeBitrotReader) ReadAt(buf []byte, offset int64) (n int, err error) if b.buf == nil { b.buf = make([]byte, b.tillOffset-offset) if _, err := b.disk.ReadFile(b.volume, b.filePath, offset, b.buf, b.verifier); err != nil { - ctx := context.Background() + ctx := GlobalContext logger.GetReqInfo(ctx).AppendTags("disk", b.disk.String()) logger.LogIf(ctx, err) return 0, err } } if len(b.buf) < len(buf) { - logger.LogIf(context.Background(), errLessData) + logger.LogIf(GlobalContext, errLessData) return 0, errLessData } n = copy(buf, b.buf) diff --git a/cmd/bitrot.go b/cmd/bitrot.go index 481a26255..bfdecfbd3 100644 --- a/cmd/bitrot.go +++ b/cmd/bitrot.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "errors" "hash" "io" @@ -72,7 +71,7 @@ func (a BitrotAlgorithm) New() hash.Hash { hh, _ := highwayhash.New(magicHighwayHash256Key) // New will never return error since key is 256 bit return hh default: - logger.CriticalIf(context.Background(), errors.New("Unsupported bitrot algorithm")) + logger.CriticalIf(GlobalContext, errors.New("Unsupported bitrot algorithm")) return nil } } @@ -88,7 +87,7 @@ func (a BitrotAlgorithm) Available() bool { func (a BitrotAlgorithm) String() string { name, ok := bitrotAlgorithms[a] if !ok { - logger.CriticalIf(context.Background(), errors.New("Unsupported bitrot algorithm")) + logger.CriticalIf(GlobalContext, errors.New("Unsupported bitrot algorithm")) } return name } diff --git a/cmd/bootstrap-peer-server.go b/cmd/bootstrap-peer-server.go index 64942d9ff..c9d4150fd 100644 --- a/cmd/bootstrap-peer-server.go +++ b/cmd/bootstrap-peer-server.go @@ -126,7 +126,7 @@ func (client *bootstrapRESTClient) reConnect() { // permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints() // after verifying format.json func (client *bootstrapRESTClient) call(method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) { - return client.callWithContext(context.Background(), method, values, body, length) + return client.callWithContext(GlobalContext, method, values, body, length) } // Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected diff --git a/cmd/bucket-encryption.go b/cmd/bucket-encryption.go index a28fecb36..365087d4f 100644 --- a/cmd/bucket-encryption.go +++ b/cmd/bucket-encryption.go @@ -44,7 +44,7 @@ func NewBucketSSEConfigSys() *BucketSSEConfigSys { // load - Loads the bucket encryption configuration for the given list of buckets func (sys *BucketSSEConfigSys) load(buckets []BucketInfo, objAPI ObjectLayer) error { for _, bucket := range buckets { - config, err := objAPI.GetBucketSSEConfig(context.Background(), bucket.Name) + config, err := objAPI.GetBucketSSEConfig(GlobalContext, bucket.Name) if err != nil { if _, ok := err.(BucketSSEConfigNotFound); ok { sys.Remove(bucket.Name) @@ -81,7 +81,7 @@ func (sys *BucketSSEConfigSys) Get(bucket string) (config bucketsse.BucketSSECon return } - cfg, err := objAPI.GetBucketSSEConfig(context.Background(), bucket) + cfg, err := objAPI.GetBucketSSEConfig(GlobalContext, bucket) if err != nil { return } @@ -130,7 +130,7 @@ func saveBucketSSEConfig(ctx context.Context, objAPI ObjectLayer, bucket string, func getBucketSSEConfig(objAPI ObjectLayer, bucket string) (*bucketsse.BucketSSEConfig, error) { // Path to bucket-encryption.xml for the given bucket. configFile := path.Join(bucketConfigPrefix, bucket, bucketSSEConfig) - configData, err := readConfig(context.Background(), objAPI, configFile) + configData, err := readConfig(GlobalContext, objAPI, configFile) if err != nil { if err == errConfigNotFound { err = BucketSSEConfigNotFound{Bucket: bucket} diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index fdd4781d7..e1276a21d 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "encoding/base64" "encoding/xml" "fmt" @@ -70,7 +69,7 @@ func initFederatorBackend(buckets []BucketInfo, objLayer ObjectLayer) { // Get buckets in the DNS dnsBuckets, err := globalDNSConfig.List() if err != nil && err != dns.ErrNoEntriesFound { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return } @@ -118,12 +117,12 @@ func initFederatorBackend(buckets []BucketInfo, objLayer ObjectLayer) { for _, err := range g.Wait() { if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) } } for _, bucket := range bucketsInConflict.ToSlice() { - logger.LogIf(context.Background(), fmt.Errorf("Unable to add bucket DNS entry for bucket %s, an entry exists for the same bucket. Use one of these IP addresses %v to access the bucket", bucket, globalDomainIPs.ToSlice())) + logger.LogIf(GlobalContext, fmt.Errorf("Unable to add bucket DNS entry for bucket %s, an entry exists for the same bucket. Use one of these IP addresses %v to access the bucket", bucket, globalDomainIPs.ToSlice())) } // Remove buckets that are in DNS for this server, but aren't local @@ -140,7 +139,7 @@ func initFederatorBackend(buckets []BucketInfo, objLayer ObjectLayer) { // We go to here, so we know the bucket no longer exists, // but is registered in DNS to this server if err = globalDNSConfig.Delete(bucket); err != nil { - logger.LogIf(context.Background(), fmt.Errorf("Failed to remove DNS entry for %s due to %w", + logger.LogIf(GlobalContext, fmt.Errorf("Failed to remove DNS entry for %s due to %w", bucket, err)) } } diff --git a/cmd/bucket-handlers_test.go b/cmd/bucket-handlers_test.go index b223010df..19ac4aba8 100644 --- a/cmd/bucket-handlers_test.go +++ b/cmd/bucket-handlers_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "encoding/xml" "io/ioutil" "net/http" @@ -36,7 +35,7 @@ func TestRemoveBucketHandler(t *testing.T) { func testRemoveBucketHandler(obj ObjectLayer, instanceType, bucketName string, apiRouter http.Handler, credentials auth.Credentials, t *testing.T) { - _, err := obj.PutObject(context.Background(), bucketName, "test-object", mustGetPutObjReader(t, bytes.NewBuffer([]byte{}), int64(0), "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), ObjectOptions{}) + _, err := obj.PutObject(GlobalContext, bucketName, "test-object", mustGetPutObjReader(t, bytes.NewBuffer([]byte{}), int64(0), "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), ObjectOptions{}) // if object upload fails stop the test. if err != nil { t.Fatalf("Error uploading object: %v", err) @@ -670,7 +669,7 @@ func testAPIDeleteMultipleObjectsHandler(obj ObjectLayer, instanceType, bucketNa for i := 0; i < 10; i++ { objectName := "test-object-" + strconv.Itoa(i) // uploading the object. - _, err = obj.PutObject(context.Background(), bucketName, objectName, mustGetPutObjReader(t, bytes.NewBuffer(contentBytes), int64(len(contentBytes)), "", sha256sum), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewBuffer(contentBytes), int64(len(contentBytes)), "", sha256sum), ObjectOptions{}) // if object upload fails stop the test. if err != nil { t.Fatalf("Put Object %d: Error uploading object: %v", i, err) diff --git a/cmd/bucket-policy-handlers_test.go b/cmd/bucket-policy-handlers_test.go index 055dc9ea2..63b66520a 100644 --- a/cmd/bucket-policy-handlers_test.go +++ b/cmd/bucket-policy-handlers_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "fmt" "io" "io/ioutil" @@ -103,7 +102,7 @@ func testPutBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string credentials auth.Credentials, t *testing.T) { bucketName1 := fmt.Sprintf("%s-1", bucketName) - if err := obj.MakeBucketWithLocation(context.Background(), bucketName1, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName1, ""); err != nil { t.Fatal(err) } diff --git a/cmd/common-main.go b/cmd/common-main.go index ed69db9ba..7ab8e7397 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "crypto/x509" "encoding/gob" "errors" @@ -42,7 +41,7 @@ func init() { logger.RegisterError(config.FmtError) // Initialize globalConsoleSys system - globalConsoleSys = NewConsoleLogger(context.Background()) + globalConsoleSys = NewConsoleLogger(GlobalContext) logger.AddTarget(globalConsoleSys) gob.Register(StorageErr("")) diff --git a/cmd/config-current.go b/cmd/config-current.go index aeedd7f98..d7a19bc62 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "fmt" "strings" "sync" @@ -302,7 +301,7 @@ func validateConfig(s config.Config) error { } func lookupConfigs(s config.Config) { - ctx := context.Background() + ctx := GlobalContext var err error if !globalActiveCred.IsValid() { @@ -553,11 +552,11 @@ func newSrvConfig(objAPI ObjectLayer) error { globalServerConfigMu.Unlock() // Save config into file. - return saveServerConfig(context.Background(), objAPI, globalServerConfig) + return saveServerConfig(GlobalContext, objAPI, globalServerConfig) } func getValidConfig(objAPI ObjectLayer) (config.Config, error) { - return readServerConfig(context.Background(), objAPI) + return readServerConfig(GlobalContext, objAPI) } // loadConfig - loads a new config from disk, overrides params diff --git a/cmd/config-encrypted.go b/cmd/config-encrypted.go index f75bd76b0..b55074c72 100644 --- a/cmd/config-encrypted.go +++ b/cmd/config-encrypted.go @@ -139,7 +139,7 @@ func checkBackendEtcdEncrypted(ctx context.Context, client *etcd.Client) (bool, } func checkBackendEncrypted(objAPI ObjectLayer) (bool, error) { - data, err := readConfig(context.Background(), objAPI, backendEncryptedFile) + data, err := readConfig(GlobalContext, objAPI, backendEncryptedFile) if err != nil && err != errConfigNotFound { return false, err } @@ -288,14 +288,14 @@ func migrateConfigPrefixToEncrypted(objAPI ObjectLayer, activeCredOld auth.Crede logger.Info("Attempting encryption of all config, IAM users and policies on MinIO backend") } - err := saveConfig(context.Background(), objAPI, backendEncryptedFile, backendEncryptedMigrationIncomplete) + err := saveConfig(GlobalContext, objAPI, backendEncryptedFile, backendEncryptedMigrationIncomplete) if err != nil { return err } var marker string for { - res, err := objAPI.ListObjects(context.Background(), minioMetaBucket, + res, err := objAPI.ListObjects(GlobalContext, minioMetaBucket, minioConfigPrefix, marker, "", maxObjectList) if err != nil { return err @@ -306,7 +306,7 @@ func migrateConfigPrefixToEncrypted(objAPI ObjectLayer, activeCredOld auth.Crede cencdata []byte ) - cdata, err = readConfig(context.Background(), objAPI, obj.Name) + cdata, err = readConfig(GlobalContext, objAPI, obj.Name) if err != nil { return err } @@ -339,7 +339,7 @@ func migrateConfigPrefixToEncrypted(objAPI ObjectLayer, activeCredOld auth.Crede return err } - if err = saveConfig(context.Background(), objAPI, obj.Name, cencdata); err != nil { + if err = saveConfig(GlobalContext, objAPI, obj.Name, cencdata); err != nil { return err } } @@ -355,5 +355,5 @@ func migrateConfigPrefixToEncrypted(objAPI ObjectLayer, activeCredOld auth.Crede logger.Info("Rotation complete, please make sure to unset MINIO_ACCESS_KEY_OLD and MINIO_SECRET_KEY_OLD envs") } - return saveConfig(context.Background(), objAPI, backendEncryptedFile, backendEncryptedMigrationComplete) + return saveConfig(GlobalContext, objAPI, backendEncryptedFile, backendEncryptedMigrationComplete) } diff --git a/cmd/config-migrate.go b/cmd/config-migrate.go index 0a090d056..23e56c795 100644 --- a/cmd/config-migrate.go +++ b/cmd/config-migrate.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "encoding/json" "fmt" "os" @@ -2430,7 +2429,7 @@ func migrateConfigToMinioSys(objAPI ObjectLayer) (err error) { defer func() { if err == nil { if globalEtcdClient != nil { - deleteKeyEtcd(context.Background(), globalEtcdClient, configFile) + deleteKeyEtcd(GlobalContext, globalEtcdClient, configFile) } else { // Rename config.json to config.json.deprecated only upon // success of this function. @@ -2440,7 +2439,7 @@ func migrateConfigToMinioSys(objAPI ObjectLayer) (err error) { }() // Verify if backend already has the file (after holding lock) - if err = checkConfig(context.Background(), objAPI, configFile); err != errConfigNotFound { + if err = checkConfig(GlobalContext, objAPI, configFile); err != errConfigNotFound { return err } // if errConfigNotFound proceed to migrate.. @@ -2466,7 +2465,7 @@ func migrateConfigToMinioSys(objAPI ObjectLayer) (err error) { // Initialize the server config, if no config exists. return newSrvConfig(objAPI) } - return saveServerConfig(context.Background(), objAPI, config) + return saveServerConfig(GlobalContext, objAPI, config) } // Migrates '.minio.sys/config.json' to v33. @@ -2502,7 +2501,7 @@ func migrateMinioSysConfig(objAPI ObjectLayer) error { } func checkConfigVersion(objAPI ObjectLayer, configFile string, version string) (bool, []byte, error) { - data, err := readConfig(context.Background(), objAPI, configFile) + data, err := readConfig(GlobalContext, objAPI, configFile) if err != nil { return false, nil, err } @@ -2548,7 +2547,7 @@ func migrateV27ToV28MinioSys(objAPI ObjectLayer) error { cfg.Version = "28" cfg.KMS = crypto.KMSConfig{} - if err = saveServerConfig(context.Background(), objAPI, cfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, cfg); err != nil { return fmt.Errorf("Failed to migrate config from ‘27’ to ‘28’. %w", err) } @@ -2575,7 +2574,7 @@ func migrateV28ToV29MinioSys(objAPI ObjectLayer) error { } cfg.Version = "29" - if err = saveServerConfig(context.Background(), objAPI, cfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, cfg); err != nil { return fmt.Errorf("Failed to migrate config from ‘28’ to ‘29’. %w", err) } @@ -2607,7 +2606,7 @@ func migrateV29ToV30MinioSys(objAPI ObjectLayer) error { cfg.Compression.Extensions = strings.Split(compress.DefaultExtensions, config.ValueSeparator) cfg.Compression.MimeTypes = strings.Split(compress.DefaultMimeTypes, config.ValueSeparator) - if err = saveServerConfig(context.Background(), objAPI, cfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, cfg); err != nil { return fmt.Errorf("Failed to migrate config from ‘29’ to ‘30’. %w", err) } @@ -2642,7 +2641,7 @@ func migrateV30ToV31MinioSys(objAPI ObjectLayer) error { AuthToken: "", } - if err = saveServerConfig(context.Background(), objAPI, cfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, cfg); err != nil { return fmt.Errorf("Failed to migrate config from ‘30’ to ‘31’. %w", err) } @@ -2672,7 +2671,7 @@ func migrateV31ToV32MinioSys(objAPI ObjectLayer) error { cfg.Notify.NSQ = make(map[string]target.NSQArgs) cfg.Notify.NSQ["1"] = target.NSQArgs{} - if err = saveServerConfig(context.Background(), objAPI, cfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, cfg); err != nil { return fmt.Errorf("Failed to migrate config from ‘31’ to ‘32’. %w", err) } @@ -2700,7 +2699,7 @@ func migrateV32ToV33MinioSys(objAPI ObjectLayer) error { cfg.Version = "33" - if err = saveServerConfig(context.Background(), objAPI, cfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, cfg); err != nil { return fmt.Errorf("Failed to migrate config from '32' to '33' . %w", err) } @@ -2777,7 +2776,7 @@ func migrateMinioSysConfigToKV(objAPI ObjectLayer) error { notify.SetNotifyWebhook(newCfg, k, args) } - if err = saveServerConfig(context.Background(), objAPI, newCfg); err != nil { + if err = saveServerConfig(GlobalContext, objAPI, newCfg); err != nil { return err } diff --git a/cmd/disk-cache-backend.go b/cmd/disk-cache-backend.go index 54987d501..728987af9 100644 --- a/cmd/disk-cache-backend.go +++ b/cmd/disk-cache-backend.go @@ -178,7 +178,7 @@ func (c *diskCache) diskUsageLow() bool { di, err := disk.GetInfo(c.dir) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("cachePath", c.dir) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) return false } @@ -193,7 +193,7 @@ func (c *diskCache) diskUsageHigh() bool { di, err := disk.GetInfo(c.dir) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("cachePath", c.dir) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) return false } @@ -207,7 +207,7 @@ func (c *diskCache) diskAvailable(size int64) bool { di, err := disk.GetInfo(c.dir) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("cachePath", c.dir) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) return false } @@ -221,7 +221,7 @@ func (c *diskCache) toClear() uint64 { di, err := disk.GetInfo(c.dir) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("cachePath", c.dir) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) return 0 } @@ -800,7 +800,7 @@ func (c *diskCache) bitrotReadFromCache(ctx context.Context, filePath string, of if !bytes.Equal(hashBytes, checksumHash) { err = fmt.Errorf("hashes do not match expected %s, got %s", hex.EncodeToString(checksumHash), hex.EncodeToString(hashBytes)) - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return err } diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index 71ef8aa3e..a0bcf6522 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -501,7 +501,7 @@ func (c *cacheObjects) hashIndex(bucket, object string) int { // or the global env overrides. func newCache(config cache.Config) ([]*diskCache, bool, error) { var caches []*diskCache - ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{}) + ctx := logger.SetReqInfo(GlobalContext, &logger.ReqInfo{}) formats, migrating, err := loadAndValidateCacheFormat(ctx, config.Drives) if err != nil { return nil, false, err diff --git a/cmd/disk-cache_test.go b/cmd/disk-cache_test.go index 8226df5fd..d19020b83 100644 --- a/cmd/disk-cache_test.go +++ b/cmd/disk-cache_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "io" "testing" @@ -184,7 +183,7 @@ func TestDiskCacheMaxUse(t *testing.T) { t.Fatal(err) } cache := d[0] - ctx := context.Background() + ctx := GlobalContext bucketName := "testbucket" objectName := "testobject" content := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" diff --git a/cmd/encryption-v1.go b/cmd/encryption-v1.go index 3b3ef045b..4e15767a9 100644 --- a/cmd/encryption-v1.go +++ b/cmd/encryption-v1.go @@ -817,7 +817,7 @@ func (o *ObjectInfo) EncryptedSize() int64 { // This cannot happen since AWS S3 allows parts to be 5GB at most // sio max. size is 256 TB reqInfo := (&logger.ReqInfo{}).AppendTags("size", strconv.FormatUint(size, 10)) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.CriticalIf(ctx, err) } return int64(size) @@ -845,7 +845,7 @@ func DecryptCopyObjectInfo(info *ObjectInfo, headers http.Header) (errCode APIEr } var err error if info.Size, err = info.DecryptedSize(); err != nil { - errCode = toAPIErrorCode(context.Background(), err) + errCode = toAPIErrorCode(GlobalContext, err) } } return diff --git a/cmd/endpoint.go b/cmd/endpoint.go index 9429925ad..bbb39905f 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "fmt" "net" "net/url" @@ -271,7 +270,7 @@ func hostResolveToLocalhost(endpoint Endpoint) bool { "host", endpoint.Hostname(), ) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err, logger.Application) return false } @@ -341,7 +340,7 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { startTime.Add(timeElapsed), "elapsed", "")) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err, logger.Application) } continue @@ -368,7 +367,7 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { "elapsed", "", )) - ctx := logger.SetReqInfo(context.Background(), + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err, logger.Application) } @@ -399,7 +398,7 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { "elapsed", "", )) - ctx := logger.SetReqInfo(context.Background(), + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err, logger.Application) } diff --git a/cmd/format-xl.go b/cmd/format-xl.go index 421d8a82b..c5f3408fd 100644 --- a/cmd/format-xl.go +++ b/cmd/format-xl.go @@ -529,7 +529,7 @@ func formatXLFixDeploymentID(endpoints Endpoints, storageDisks []StorageAPI, ref } // Deployment ID needs to be set on all the disks. // Save `format.json` across all disks. - return saveFormatXLAll(context.Background(), storageDisks, formats) + return saveFormatXLAll(GlobalContext, storageDisks, formats) } @@ -559,7 +559,7 @@ func formatXLFixLocalDeploymentID(endpoints Endpoints, storageDisks []StorageAPI } format.ID = refFormat.ID if err := saveFormatXL(storageDisks[index], format, format.XL.This); err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return fmt.Errorf("Unable to save format.json, %w", err) } } diff --git a/cmd/fs-v1-helpers_test.go b/cmd/fs-v1-helpers_test.go index 87fb8d293..972616ce2 100644 --- a/cmd/fs-v1-helpers_test.go +++ b/cmd/fs-v1-helpers_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "io" "io/ioutil" "os" @@ -36,19 +35,19 @@ func TestFSRenameFile(t *testing.T) { } defer os.RemoveAll(path) - if err = fsMkdir(context.Background(), pathJoin(path, "testvolume1")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "testvolume1")); err != nil { t.Fatal(err) } - if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil { + if err = fsRenameFile(GlobalContext, pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil { t.Fatal(err) } - if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != errFileNotFound { + if err = fsRenameFile(GlobalContext, pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != errFileNotFound { t.Fatal(err) } - if err = fsRenameFile(context.Background(), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); err != errFileNameTooLong { + if err = fsRenameFile(GlobalContext, pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); err != errFileNameTooLong { t.Fatal("Unexpected error", err) } - if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong { + if err = fsRenameFile(GlobalContext, pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong { t.Fatal("Unexpected error", err) } } @@ -63,30 +62,30 @@ func TestFSStats(t *testing.T) { // Setup test environment. - if err = fsMkdir(context.Background(), ""); err != errInvalidArgument { + if err = fsMkdir(GlobalContext, ""); err != errInvalidArgument { t.Fatal("Unexpected error", err) } - if err = fsMkdir(context.Background(), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong { + if err = fsMkdir(GlobalContext, pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong { t.Fatal("Unexpected error", err) } - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil { t.Fatalf("Unable to create volume, %s", err) } var reader = bytes.NewReader([]byte("Hello, world")) - if _, err = fsCreateFile(context.Background(), pathJoin(path, "success-vol", "success-file"), reader, nil, 0); err != nil { + if _, err = fsCreateFile(GlobalContext, pathJoin(path, "success-vol", "success-file"), reader, nil, 0); err != nil { t.Fatalf("Unable to create file, %s", err) } // Seek back. reader.Seek(0, 0) - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol", "success-file")); err != errVolumeExists { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol", "success-file")); err != errVolumeExists { t.Fatal("Unexpected error", err) } - if _, err = fsCreateFile(context.Background(), pathJoin(path, "success-vol", "path/to/success-file"), reader, nil, 0); err != nil { + if _, err = fsCreateFile(GlobalContext, pathJoin(path, "success-vol", "path/to/success-file"), reader, nil, 0); err != nil { t.Fatalf("Unable to create file, %s", err) } // Seek back. @@ -169,12 +168,12 @@ func TestFSStats(t *testing.T) { for i, testCase := range testCases { if testCase.srcPath != "" { - if _, err := fsStatFile(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, + if _, err := fsStatFile(GlobalContext, pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } } else { - if _, err := fsStatVolume(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol)); err != testCase.expectedErr { + if _, err := fsStatVolume(GlobalContext, pathJoin(testCase.srcFSPath, testCase.srcVol)); err != testCase.expectedErr { t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } } @@ -189,20 +188,20 @@ func TestFSCreateAndOpen(t *testing.T) { } defer os.RemoveAll(path) - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil { t.Fatalf("Unable to create directory, %s", err) } - if _, err = fsCreateFile(context.Background(), "", nil, nil, 0); err != errInvalidArgument { + if _, err = fsCreateFile(GlobalContext, "", nil, nil, 0); err != errInvalidArgument { t.Fatal("Unexpected error", err) } - if _, _, err = fsOpenFile(context.Background(), "", -1); err != errInvalidArgument { + if _, _, err = fsOpenFile(GlobalContext, "", -1); err != errInvalidArgument { t.Fatal("Unexpected error", err) } var reader = bytes.NewReader([]byte("Hello, world")) - if _, err = fsCreateFile(context.Background(), pathJoin(path, "success-vol", "success-file"), reader, nil, 0); err != nil { + if _, err = fsCreateFile(GlobalContext, pathJoin(path, "success-vol", "success-file"), reader, nil, 0); err != nil { t.Fatalf("Unable to create file, %s", err) } // Seek back. @@ -230,18 +229,18 @@ func TestFSCreateAndOpen(t *testing.T) { } for i, testCase := range testCases { - _, err = fsCreateFile(context.Background(), pathJoin(path, testCase.srcVol, testCase.srcPath), reader, nil, 0) + _, err = fsCreateFile(GlobalContext, pathJoin(path, testCase.srcVol, testCase.srcPath), reader, nil, 0) if err != testCase.expectedErr { t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } - _, _, err = fsOpenFile(context.Background(), pathJoin(path, testCase.srcVol, testCase.srcPath), 0) + _, _, err = fsOpenFile(GlobalContext, pathJoin(path, testCase.srcVol, testCase.srcPath), 0) if err != testCase.expectedErr { t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } } // Attempt to open a directory. - if _, _, err = fsOpenFile(context.Background(), pathJoin(path), 0); err != errIsNotRegular { + if _, _, err = fsOpenFile(GlobalContext, pathJoin(path), 0); err != errIsNotRegular { t.Fatal("Unexpected error", err) } } @@ -255,20 +254,20 @@ func TestFSDeletes(t *testing.T) { defer os.RemoveAll(path) // Setup test environment. - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil { t.Fatalf("Unable to create directory, %s", err) } var buf = make([]byte, 4096) var reader = bytes.NewReader([]byte("Hello, world")) - if _, err = fsCreateFile(context.Background(), pathJoin(path, "success-vol", "success-file"), reader, buf, reader.Size()); err != nil { + if _, err = fsCreateFile(GlobalContext, pathJoin(path, "success-vol", "success-file"), reader, buf, reader.Size()); err != nil { t.Fatalf("Unable to create file, %s", err) } // Seek back. reader.Seek(0, io.SeekStart) // folder is not empty - err = fsMkdir(context.Background(), pathJoin(path, "success-vol", "not-empty")) + err = fsMkdir(GlobalContext, pathJoin(path, "success-vol", "not-empty")) if err != nil { t.Fatal(err) } @@ -278,10 +277,10 @@ func TestFSDeletes(t *testing.T) { } // recursive - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol", "parent")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol", "parent")); err != nil { t.Fatal(err) } - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol", "parent", "dir")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol", "parent", "dir")); err != nil { t.Fatal(err) } @@ -343,7 +342,7 @@ func TestFSDeletes(t *testing.T) { } for i, testCase := range testCases { - if err = fsDeleteFile(context.Background(), testCase.basePath, pathJoin(testCase.basePath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { + if err = fsDeleteFile(GlobalContext, testCase.basePath, pathJoin(testCase.basePath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } } @@ -358,7 +357,7 @@ func BenchmarkFSDeleteFile(b *testing.B) { defer os.RemoveAll(path) // Setup test environment. - if err = fsMkdir(context.Background(), pathJoin(path, "benchmark")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "benchmark")); err != nil { b.Fatalf("Unable to create directory, %s", err) } @@ -375,7 +374,7 @@ func BenchmarkFSDeleteFile(b *testing.B) { } b.StartTimer() - err = fsDeleteFile(context.Background(), benchDir, filename) + err = fsDeleteFile(GlobalContext, benchDir, filename) if err != nil { b.Fatal(err) } @@ -392,18 +391,18 @@ func TestFSRemoves(t *testing.T) { defer os.RemoveAll(path) // Setup test environment. - if err = fsMkdir(context.Background(), pathJoin(path, "success-vol")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil { t.Fatalf("Unable to create directory, %s", err) } var reader = bytes.NewReader([]byte("Hello, world")) - if _, err = fsCreateFile(context.Background(), pathJoin(path, "success-vol", "success-file"), reader, nil, 0); err != nil { + if _, err = fsCreateFile(GlobalContext, pathJoin(path, "success-vol", "success-file"), reader, nil, 0); err != nil { t.Fatalf("Unable to create file, %s", err) } // Seek back. reader.Seek(0, 0) - if _, err = fsCreateFile(context.Background(), pathJoin(path, "success-vol", "success-file-new"), reader, nil, 0); err != nil { + if _, err = fsCreateFile(GlobalContext, pathJoin(path, "success-vol", "success-file-new"), reader, nil, 0); err != nil { t.Fatalf("Unable to create file, %s", err) } // Seek back. @@ -477,25 +476,25 @@ func TestFSRemoves(t *testing.T) { for i, testCase := range testCases { if testCase.srcPath != "" { - if err = fsRemoveFile(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { + if err = fsRemoveFile(GlobalContext, pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } } else { - if err = fsRemoveDir(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { + if err = fsRemoveDir(GlobalContext, pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { t.Error(err) } } } - if err = fsRemoveAll(context.Background(), pathJoin(path, "success-vol")); err != nil { + if err = fsRemoveAll(GlobalContext, pathJoin(path, "success-vol")); err != nil { t.Fatal(err) } - if err = fsRemoveAll(context.Background(), ""); err != errInvalidArgument { + if err = fsRemoveAll(GlobalContext, ""); err != errInvalidArgument { t.Fatal(err) } - if err = fsRemoveAll(context.Background(), "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); err != errFileNameTooLong { + if err = fsRemoveAll(GlobalContext, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); err != errFileNameTooLong { t.Fatal(err) } } @@ -509,14 +508,14 @@ func TestFSRemoveMeta(t *testing.T) { defer os.RemoveAll(fsPath) // Setup test environment. - if err = fsMkdir(context.Background(), pathJoin(fsPath, "success-vol")); err != nil { + if err = fsMkdir(GlobalContext, pathJoin(fsPath, "success-vol")); err != nil { t.Fatalf("Unable to create directory, %s", err) } filePath := pathJoin(fsPath, "success-vol", "success-file") var reader = bytes.NewReader([]byte("Hello, world")) - if _, err = fsCreateFile(context.Background(), filePath, reader, nil, 0); err != nil { + if _, err = fsCreateFile(GlobalContext, filePath, reader, nil, 0); err != nil { t.Fatalf("Unable to create file, %s", err) } @@ -535,7 +534,7 @@ func TestFSRemoveMeta(t *testing.T) { t.Fatal(tmpErr) } - if err := fsRemoveMeta(context.Background(), fsPath, filePath, tmpDir); err != nil { + if err := fsRemoveMeta(GlobalContext, fsPath, filePath, tmpDir); err != nil { t.Fatalf("Unable to remove file, %s", err) } @@ -561,7 +560,7 @@ func TestFSIsFile(t *testing.T) { t.Fatalf("Unable to create file %s", filePath) } - if !fsIsFile(context.Background(), filePath) { + if !fsIsFile(GlobalContext, filePath) { t.Fatalf("Expected %s to be a file", filePath) } } diff --git a/cmd/fs-v1-metadata_test.go b/cmd/fs-v1-metadata_test.go index 32840bac3..ee82a1eb2 100644 --- a/cmd/fs-v1-metadata_test.go +++ b/cmd/fs-v1-metadata_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "os" "path/filepath" "reflect" @@ -54,10 +53,10 @@ func TestReadFSMetadata(t *testing.T) { bucketName := "bucket" objectName := "object" - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Unexpected err: ", err) } - if _, err := obj.PutObject(context.Background(), bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}); err != nil { + if _, err := obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}); err != nil { t.Fatal("Unexpected err: ", err) } @@ -73,7 +72,7 @@ func TestReadFSMetadata(t *testing.T) { // Regular fs metadata reading, no errors expected fsMeta := fsMetaV1{} - if _, err = fsMeta.ReadFrom(context.Background(), rlk.LockedFile); err != nil { + if _, err = fsMeta.ReadFrom(GlobalContext, rlk.LockedFile); err != nil { t.Fatal("Unexpected error ", err) } } @@ -89,10 +88,10 @@ func TestWriteFSMetadata(t *testing.T) { bucketName := "bucket" objectName := "object" - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Unexpected err: ", err) } - if _, err := obj.PutObject(context.Background(), bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}); err != nil { + if _, err := obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}); err != nil { t.Fatal("Unexpected err: ", err) } @@ -108,7 +107,7 @@ func TestWriteFSMetadata(t *testing.T) { // FS metadata reading, no errors expected (healthy disk) fsMeta := fsMetaV1{} - _, err = fsMeta.ReadFrom(context.Background(), rlk.LockedFile) + _, err = fsMeta.ReadFrom(GlobalContext, rlk.LockedFile) if err != nil { t.Fatal("Unexpected error ", err) } diff --git a/cmd/fs-v1-multipart_test.go b/cmd/fs-v1-multipart_test.go index 741c33670..9ac60d14b 100644 --- a/cmd/fs-v1-multipart_test.go +++ b/cmd/fs-v1-multipart_test.go @@ -39,7 +39,7 @@ func TestFSCleanupMultipartUploadsInRoutine(t *testing.T) { objectName := "object" // Create a context we can cancel. - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(GlobalContext) obj.MakeBucketWithLocation(ctx, bucketName, "") uploadID, err := obj.NewMultipartUpload(ctx, bucketName, objectName, ObjectOptions{}) @@ -51,7 +51,7 @@ func TestFSCleanupMultipartUploadsInRoutine(t *testing.T) { cleanupWg.Add(1) go func() { defer cleanupWg.Done() - fs.cleanupStaleMultipartUploads(context.Background(), time.Millisecond, 0, ctx.Done()) + fs.cleanupStaleMultipartUploads(GlobalContext, time.Millisecond, 0, ctx.Done()) }() // Wait for 100ms such that - we have given enough time for @@ -61,7 +61,7 @@ func TestFSCleanupMultipartUploadsInRoutine(t *testing.T) { cleanupWg.Wait() // Check if upload id was already purged. - if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil { + if err = obj.AbortMultipartUpload(GlobalContext, bucketName, objectName, uploadID); err != nil { if _, ok := err.(InvalidUploadID); !ok { t.Fatal("Unexpected err: ", err) } @@ -81,13 +81,13 @@ func TestNewMultipartUploadFaultyDisk(t *testing.T) { bucketName := "bucket" objectName := "object" - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Cannot create bucket, err: ", err) } // Test with disk removed. os.RemoveAll(disk) - if _, err := fs.NewMultipartUpload(context.Background(), bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}); err != nil { + if _, err := fs.NewMultipartUpload(GlobalContext, bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error ", err) } @@ -106,11 +106,11 @@ func TestPutObjectPartFaultyDisk(t *testing.T) { data := []byte("12345") dataLen := int64(len(data)) - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Cannot create bucket, err: ", err) } - uploadID, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) + uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) if err != nil { t.Fatal("Unexpected error ", err) } @@ -121,7 +121,7 @@ func TestPutObjectPartFaultyDisk(t *testing.T) { newDisk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) defer os.RemoveAll(newDisk) obj = initFSObjects(newDisk, t) - if _, err = obj.PutObjectPart(context.Background(), bucketName, objectName, uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(data), dataLen, md5Hex, sha256sum), ObjectOptions{}); err != nil { + if _, err = obj.PutObjectPart(GlobalContext, bucketName, objectName, uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(data), dataLen, md5Hex, sha256sum), ObjectOptions{}); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error ", err) } @@ -139,11 +139,11 @@ func TestCompleteMultipartUploadFaultyDisk(t *testing.T) { objectName := "object" data := []byte("12345") - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Cannot create bucket, err: ", err) } - uploadID, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) + uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) if err != nil { t.Fatal("Unexpected error ", err) } @@ -154,7 +154,7 @@ func TestCompleteMultipartUploadFaultyDisk(t *testing.T) { newDisk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) defer os.RemoveAll(newDisk) obj = initFSObjects(newDisk, t) - if _, err := obj.CompleteMultipartUpload(context.Background(), bucketName, objectName, uploadID, parts, ObjectOptions{}); err != nil { + if _, err := obj.CompleteMultipartUpload(GlobalContext, bucketName, objectName, uploadID, parts, ObjectOptions{}); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error ", err) } @@ -172,23 +172,23 @@ func TestCompleteMultipartUpload(t *testing.T) { objectName := "object" data := []byte("12345") - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Cannot create bucket, err: ", err) } - uploadID, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) + uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) if err != nil { t.Fatal("Unexpected error ", err) } md5Hex := getMD5Hash(data) - if _, err := obj.PutObjectPart(context.Background(), bucketName, objectName, uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(data), 5, md5Hex, ""), ObjectOptions{}); err != nil { + if _, err := obj.PutObjectPart(GlobalContext, bucketName, objectName, uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(data), 5, md5Hex, ""), ObjectOptions{}); err != nil { t.Fatal("Unexpected error ", err) } parts := []CompletePart{{PartNumber: 1, ETag: md5Hex}} - if _, err := obj.CompleteMultipartUpload(context.Background(), bucketName, objectName, uploadID, parts, ObjectOptions{}); err != nil { + if _, err := obj.CompleteMultipartUpload(GlobalContext, bucketName, objectName, uploadID, parts, ObjectOptions{}); err != nil { t.Fatal("Unexpected error ", err) } } @@ -204,22 +204,22 @@ func TestAbortMultipartUpload(t *testing.T) { objectName := "object" data := []byte("12345") - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Cannot create bucket, err: ", err) } - uploadID, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) + uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) if err != nil { t.Fatal("Unexpected error ", err) } md5Hex := getMD5Hash(data) - if _, err := obj.PutObjectPart(context.Background(), bucketName, objectName, uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(data), 5, md5Hex, ""), ObjectOptions{}); err != nil { + if _, err := obj.PutObjectPart(GlobalContext, bucketName, objectName, uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(data), 5, md5Hex, ""), ObjectOptions{}); err != nil { t.Fatal("Unexpected error ", err) } time.Sleep(time.Second) // Without Sleep on windows, the fs.AbortMultipartUpload() fails with "The process cannot access the file because it is being used by another process." - if err := obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil { + if err := obj.AbortMultipartUpload(GlobalContext, bucketName, objectName, uploadID); err != nil { t.Fatal("Unexpected error ", err) } } @@ -235,11 +235,11 @@ func TestListMultipartUploadsFaultyDisk(t *testing.T) { bucketName := "bucket" objectName := "object" - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Cannot create bucket, err: ", err) } - _, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) + _, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, ObjectOptions{UserDefined: map[string]string{"X-Amz-Meta-xid": "3f"}}) if err != nil { t.Fatal("Unexpected error ", err) } @@ -247,7 +247,7 @@ func TestListMultipartUploadsFaultyDisk(t *testing.T) { newDisk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) defer os.RemoveAll(newDisk) obj = initFSObjects(newDisk, t) - if _, err := obj.ListMultipartUploads(context.Background(), bucketName, objectName, "", "", "", 1000); err != nil { + if _, err := obj.ListMultipartUploads(GlobalContext, bucketName, objectName, "", "", "", 1000); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error ", err) } diff --git a/cmd/fs-v1-rwpool.go b/cmd/fs-v1-rwpool.go index e8677524c..6c5eb1be1 100644 --- a/cmd/fs-v1-rwpool.go +++ b/cmd/fs-v1-rwpool.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "os" pathutil "path" "sync" @@ -51,7 +50,7 @@ func (fsi *fsIOPool) lookupToRead(path string) (*lock.RLockedFile, bool) { if rlkFile.IsClosed() { // Log this as an error. reqInfo := (&logger.ReqInfo{}).AppendTags("path", path) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, errUnexpected) // Purge the cached lock path from map. diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 81008b533..58f9f3e92 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -121,7 +121,7 @@ func initMetaVolumeFS(fsPath, fsUUID string) error { // NewFSObjectLayer - initialize new fs object layer. func NewFSObjectLayer(fsPath string) (ObjectLayer, error) { - ctx := context.Background() + ctx := GlobalContext if fsPath == "" { return nil, errInvalidArgument } @@ -1089,7 +1089,7 @@ func (fs *FSObjects) listDirFactory() ListDirFunc { var err error entries, err = readDir(pathJoin(fs.fsPath, bucket, prefixDir)) if err != nil && err != errFileNotFound { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return false, nil } if len(entries) == 0 { diff --git a/cmd/fs-v1_test.go b/cmd/fs-v1_test.go index 439605593..f0b5dfb1a 100644 --- a/cmd/fs-v1_test.go +++ b/cmd/fs-v1_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "os" "path/filepath" "testing" @@ -37,11 +36,11 @@ func TestFSParentDirIsObject(t *testing.T) { bucketName := "testbucket" objectName := "object" - if err = obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err = obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal(err) } objectContent := "12345" - objInfo, err := obj.PutObject(context.Background(), bucketName, objectName, + objInfo, err := obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{}) if err != nil { t.Fatal(err) @@ -84,7 +83,7 @@ func TestFSParentDirIsObject(t *testing.T) { }, } for i, testCase := range testCases { - gotValue := fs.parentDirIsObject(context.Background(), bucketName, testCase.objectName) + gotValue := fs.parentDirIsObject(GlobalContext, bucketName, testCase.objectName) if testCase.parentIsObject != gotValue { t.Errorf("Test %d: Unexpected value returned got %t, expected %t", i+1, gotValue, testCase.parentIsObject) } @@ -125,23 +124,23 @@ func TestFSShutdown(t *testing.T) { fs := obj.(*FSObjects) objectContent := "12345" - obj.MakeBucketWithLocation(context.Background(), bucketName, "") - obj.PutObject(context.Background(), bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{}) + obj.MakeBucketWithLocation(GlobalContext, bucketName, "") + obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{}) return fs, disk } // Test Shutdown with regular conditions fs, disk := prepareTest() - if err := fs.Shutdown(context.Background()); err != nil { + if err := fs.Shutdown(GlobalContext); err != nil { t.Fatal("Cannot shutdown the FS object: ", err) } os.RemoveAll(disk) // Test Shutdown with faulty disk fs, disk = prepareTest() - fs.DeleteObject(context.Background(), bucketName, objectName) + fs.DeleteObject(GlobalContext, bucketName, objectName) os.RemoveAll(disk) - if err := fs.Shutdown(context.Background()); err != nil { + if err := fs.Shutdown(GlobalContext); err != nil { t.Fatal("Got unexpected fs shutdown error: ", err) } } @@ -156,18 +155,18 @@ func TestFSGetBucketInfo(t *testing.T) { fs := obj.(*FSObjects) bucketName := "bucket" - err := obj.MakeBucketWithLocation(context.Background(), "a", "") + err := obj.MakeBucketWithLocation(GlobalContext, "a", "") if !isSameType(err, BucketNameInvalid{}) { t.Fatal("BucketNameInvalid error not returned") } - err = obj.MakeBucketWithLocation(context.Background(), bucketName, "") + err = obj.MakeBucketWithLocation(GlobalContext, bucketName, "") if err != nil { t.Fatal(err) } // Test with valid parameters - info, err := fs.GetBucketInfo(context.Background(), bucketName) + info, err := fs.GetBucketInfo(GlobalContext, bucketName) if err != nil { t.Fatal(err) } @@ -176,7 +175,7 @@ func TestFSGetBucketInfo(t *testing.T) { } // Test with non-existent bucket - _, err = fs.GetBucketInfo(context.Background(), "a") + _, err = fs.GetBucketInfo(GlobalContext, "a") if !isSameType(err, BucketNotFound{}) { t.Fatal("BucketNotFound error not returned") } @@ -184,7 +183,7 @@ func TestFSGetBucketInfo(t *testing.T) { // Check for buckets and should get disk not found. os.RemoveAll(disk) - if _, err = fs.GetBucketInfo(context.Background(), bucketName); err != nil { + if _, err = fs.GetBucketInfo(GlobalContext, bucketName); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("BucketNotFound error not returned") } @@ -200,12 +199,12 @@ func TestFSPutObject(t *testing.T) { bucketName := "bucket" objectName := "1/2/3/4/object" - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal(err) } // With a regular object. - _, err := obj.PutObject(context.Background(), bucketName+"non-existent", objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) + _, err := obj.PutObject(GlobalContext, bucketName+"non-existent", objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) if err == nil { t.Fatal("Unexpected should fail here, bucket doesn't exist") } @@ -214,7 +213,7 @@ func TestFSPutObject(t *testing.T) { } // With a directory object. - _, err = obj.PutObject(context.Background(), bucketName+"non-existent", objectName+SlashSeparator, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), 0, "", ""), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucketName+"non-existent", objectName+SlashSeparator, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), 0, "", ""), ObjectOptions{}) if err == nil { t.Fatal("Unexpected should fail here, bucket doesn't exist") } @@ -222,11 +221,11 @@ func TestFSPutObject(t *testing.T) { t.Fatalf("Expected error type BucketNotFound, got %#v", err) } - _, err = obj.PutObject(context.Background(), bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) if err != nil { t.Fatal(err) } - _, err = obj.PutObject(context.Background(), bucketName, objectName+"/1", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucketName, objectName+"/1", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) if err == nil { t.Fatal("Unexpected should fail here, backend corruption occurred") } @@ -241,7 +240,7 @@ func TestFSPutObject(t *testing.T) { } } - _, err = obj.PutObject(context.Background(), bucketName, objectName+"/1/", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), 0, "", ""), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucketName, objectName+"/1/", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), 0, "", ""), ObjectOptions{}) if err == nil { t.Fatal("Unexpected should fail here, backned corruption occurred") } @@ -268,33 +267,33 @@ func TestFSDeleteObject(t *testing.T) { bucketName := "bucket" objectName := "object" - obj.MakeBucketWithLocation(context.Background(), bucketName, "") - obj.PutObject(context.Background(), bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) + obj.MakeBucketWithLocation(GlobalContext, bucketName, "") + obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) // Test with invalid bucket name - if err := fs.DeleteObject(context.Background(), "fo", objectName); !isSameType(err, BucketNameInvalid{}) { + if err := fs.DeleteObject(GlobalContext, "fo", objectName); !isSameType(err, BucketNameInvalid{}) { t.Fatal("Unexpected error: ", err) } // Test with bucket does not exist - if err := fs.DeleteObject(context.Background(), "foobucket", "fooobject"); !isSameType(err, BucketNotFound{}) { + if err := fs.DeleteObject(GlobalContext, "foobucket", "fooobject"); !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error: ", err) } // Test with invalid object name - if err := fs.DeleteObject(context.Background(), bucketName, "\\"); !isSameType(err, ObjectNotFound{}) { + if err := fs.DeleteObject(GlobalContext, bucketName, "\\"); !isSameType(err, ObjectNotFound{}) { t.Fatal("Unexpected error: ", err) } // Test with object does not exist. - if err := fs.DeleteObject(context.Background(), bucketName, "foooobject"); !isSameType(err, ObjectNotFound{}) { + if err := fs.DeleteObject(GlobalContext, bucketName, "foooobject"); !isSameType(err, ObjectNotFound{}) { t.Fatal("Unexpected error: ", err) } // Test with valid condition - if err := fs.DeleteObject(context.Background(), bucketName, objectName); err != nil { + if err := fs.DeleteObject(GlobalContext, bucketName, objectName); err != nil { t.Fatal("Unexpected error: ", err) } // Delete object should err disk not found. os.RemoveAll(disk) - if err := fs.DeleteObject(context.Background(), bucketName, objectName); err != nil { + if err := fs.DeleteObject(GlobalContext, bucketName, objectName); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error: ", err) } @@ -312,30 +311,30 @@ func TestFSDeleteBucket(t *testing.T) { fs := obj.(*FSObjects) bucketName := "bucket" - err := obj.MakeBucketWithLocation(context.Background(), bucketName, "") + err := obj.MakeBucketWithLocation(GlobalContext, bucketName, "") if err != nil { t.Fatal("Unexpected error: ", err) } // Test with an invalid bucket name - if err = fs.DeleteBucket(context.Background(), "fo", false); !isSameType(err, BucketNotFound{}) { + if err = fs.DeleteBucket(GlobalContext, "fo", false); !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error: ", err) } // Test with an inexistant bucket - if err = fs.DeleteBucket(context.Background(), "foobucket", false); !isSameType(err, BucketNotFound{}) { + if err = fs.DeleteBucket(GlobalContext, "foobucket", false); !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error: ", err) } // Test with a valid case - if err = fs.DeleteBucket(context.Background(), bucketName, false); err != nil { + if err = fs.DeleteBucket(GlobalContext, bucketName, false); err != nil { t.Fatal("Unexpected error: ", err) } - obj.MakeBucketWithLocation(context.Background(), bucketName, "") + obj.MakeBucketWithLocation(GlobalContext, bucketName, "") // Delete bucket should get error disk not found. os.RemoveAll(disk) - if err = fs.DeleteBucket(context.Background(), bucketName, false); err != nil { + if err = fs.DeleteBucket(GlobalContext, bucketName, false); err != nil { if !isSameType(err, BucketNotFound{}) { t.Fatal("Unexpected error: ", err) } @@ -352,7 +351,7 @@ func TestFSListBuckets(t *testing.T) { fs := obj.(*FSObjects) bucketName := "bucket" - if err := obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal("Unexpected error: ", err) } @@ -367,7 +366,7 @@ func TestFSListBuckets(t *testing.T) { f.Close() // Test list buckets to have only one entry. - buckets, err := fs.ListBuckets(context.Background()) + buckets, err := fs.ListBuckets(GlobalContext) if err != nil { t.Fatal("Unexpected error: ", err) } @@ -377,7 +376,7 @@ func TestFSListBuckets(t *testing.T) { // Test ListBuckets with disk not found. os.RemoveAll(disk) - if _, err := fs.ListBuckets(context.Background()); err != nil { + if _, err := fs.ListBuckets(GlobalContext); err != nil { if err != errDiskNotFound { t.Fatal("Unexpected error: ", err) } @@ -390,7 +389,7 @@ func TestFSHealObject(t *testing.T) { defer os.RemoveAll(disk) obj := initFSObjects(disk, t) - _, err := obj.HealObject(context.Background(), "bucket", "object", madmin.HealOpts{}) + _, err := obj.HealObject(GlobalContext, "bucket", "object", madmin.HealOpts{}) if err == nil || !isSameType(err, NotImplemented{}) { t.Fatalf("Heal Object should return NotImplemented error ") } @@ -402,7 +401,7 @@ func TestFSHealObjects(t *testing.T) { defer os.RemoveAll(disk) obj := initFSObjects(disk, t) - err := obj.HealObjects(context.Background(), "bucket", "prefix", madmin.HealOpts{}, nil) + err := obj.HealObjects(GlobalContext, "bucket", "prefix", madmin.HealOpts{}, nil) if err == nil || !isSameType(err, NotImplemented{}) { t.Fatalf("Heal Object should return NotImplemented error ") } diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 8a1aa2300..b5a299079 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "fmt" "net/url" "os" @@ -134,7 +133,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { gatewayHandleEnvVars() // Set system resources to maximum. - logger.LogIf(context.Background(), setMaxResources()) + logger.LogIf(GlobalContext, setMaxResources()) // Set when gateway is enabled globalIsGateway = true @@ -237,7 +236,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // sub-systems, make sure that we do not move the above codeblock elsewhere. if enableConfigOps { logger.FatalIf(globalConfigSys.Init(newObject), "Unable to initialize config system") - buckets, err := newObject.ListBuckets(context.Background()) + buckets, err := newObject.ListBuckets(GlobalContext) if err != nil { logger.Fatal(err, "Unable to list buckets") } diff --git a/cmd/gateway-startup-msg.go b/cmd/gateway-startup-msg.go index 193bc34c5..6403518bd 100644 --- a/cmd/gateway-startup-msg.go +++ b/cmd/gateway-startup-msg.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "fmt" "strings" @@ -30,7 +29,7 @@ func printGatewayStartupMessage(apiEndPoints []string, backendType string) { // If cache layer is enabled, print cache capacity. cacheAPI := newCachedObjectLayerFn() if cacheAPI != nil { - printCacheStorageInfo(cacheAPI.StorageInfo(context.Background())) + printCacheStorageInfo(cacheAPI.StorageInfo(GlobalContext)) } // Prints credential. printGatewayCommonMsg(strippedAPIEndpoints) diff --git a/cmd/gateway/azure/gateway-azure_test.go b/cmd/gateway/azure/gateway-azure_test.go index a159325c1..b23812f21 100644 --- a/cmd/gateway/azure/gateway-azure_test.go +++ b/cmd/gateway/azure/gateway-azure_test.go @@ -17,7 +17,6 @@ package azure import ( - "context" "encoding/base64" "fmt" "net/http" @@ -84,7 +83,7 @@ func TestS3MetaToAzureProperties(t *testing.T) { "X_Amz_Matdesc": "{}", "X_Amz_Iv": "eWmyryl8kq+EVnnsE7jpOg==", } - meta, _, err := s3MetaToAzureProperties(context.Background(), headers) + meta, _, err := s3MetaToAzureProperties(minio.GlobalContext, headers) if err != nil { t.Fatalf("Test failed, with %s", err) } @@ -94,7 +93,7 @@ func TestS3MetaToAzureProperties(t *testing.T) { headers = map[string]string{ "invalid--meta": "value", } - _, _, err = s3MetaToAzureProperties(context.Background(), headers) + _, _, err = s3MetaToAzureProperties(minio.GlobalContext, headers) if err != nil { if _, ok := err.(minio.UnsupportedMetadata); !ok { t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err) @@ -104,7 +103,7 @@ func TestS3MetaToAzureProperties(t *testing.T) { headers = map[string]string{ "content-md5": "Dce7bmCX61zvxzP5QmfelQ==", } - _, props, err := s3MetaToAzureProperties(context.Background(), headers) + _, props, err := s3MetaToAzureProperties(minio.GlobalContext, headers) if err != nil { t.Fatalf("Test failed, with %s", err) } @@ -286,7 +285,7 @@ func TestCheckAzureUploadID(t *testing.T) { } for _, uploadID := range invalidUploadIDs { - if err := checkAzureUploadID(context.Background(), uploadID); err == nil { + if err := checkAzureUploadID(minio.GlobalContext, uploadID); err == nil { t.Fatalf("%s: expected: , got: ", uploadID) } } @@ -297,7 +296,7 @@ func TestCheckAzureUploadID(t *testing.T) { } for _, uploadID := range validUploadIDs { - if err := checkAzureUploadID(context.Background(), uploadID); err != nil { + if err := checkAzureUploadID(minio.GlobalContext, uploadID); err != nil { t.Fatalf("%s: expected: , got: %s", uploadID, err) } } diff --git a/cmd/gateway/b2/gateway-b2.go b/cmd/gateway/b2/gateway-b2.go index f39f14bbc..c89d76557 100644 --- a/cmd/gateway/b2/gateway-b2.go +++ b/cmd/gateway/b2/gateway-b2.go @@ -105,7 +105,7 @@ func (g *B2) Name() string { // NewGatewayLayer returns b2 gateway layer, implements ObjectLayer interface to // talk to B2 remote backend. func (g *B2) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) { - ctx := context.Background() + ctx := minio.GlobalContext client, err := b2.AuthorizeAccount(ctx, creds.AccessKey, creds.SecretKey, b2.Transport(minio.NewGatewayHTTPTransport())) if err != nil { return nil, err diff --git a/cmd/gateway/gcs/gateway-gcs.go b/cmd/gateway/gcs/gateway-gcs.go index 3b840376e..bb6666dab 100644 --- a/cmd/gateway/gcs/gateway-gcs.go +++ b/cmd/gateway/gcs/gateway-gcs.go @@ -144,12 +144,12 @@ EXAMPLES: func gcsGatewayMain(ctx *cli.Context) { projectID := ctx.Args().First() if projectID == "" && os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" { - logger.LogIf(context.Background(), errGCSProjectIDNotFound, logger.Application) + logger.LogIf(minio.GlobalContext, errGCSProjectIDNotFound, logger.Application) cli.ShowCommandHelpAndExit(ctx, "gcs", 1) } if projectID != "" && !isValidGCSProjectIDFormat(projectID) { reqInfo := (&logger.ReqInfo{}).AppendTags("projectID", ctx.Args().First()) - contxt := logger.SetReqInfo(context.Background(), reqInfo) + contxt := logger.SetReqInfo(minio.GlobalContext, reqInfo) logger.LogIf(contxt, errGCSInvalidProjectID, logger.Application) cli.ShowCommandHelpAndExit(ctx, "gcs", 1) } @@ -169,7 +169,7 @@ func (g *GCS) Name() string { // NewGatewayLayer returns gcs ObjectLayer. func (g *GCS) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) { - ctx := context.Background() + ctx := minio.GlobalContext var err error if g.projectID == "" { @@ -373,7 +373,7 @@ func (l *gcsGateway) CleanupGCSMinioSysTmpBucket(ctx context.Context, bucket str if err != nil { if err != iterator.Done { reqInfo := &logger.ReqInfo{BucketName: bucket} - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(minio.GlobalContext, reqInfo) logger.LogIf(ctx, err) } return @@ -383,7 +383,7 @@ func (l *gcsGateway) CleanupGCSMinioSysTmpBucket(ctx context.Context, bucket str err := l.client.Bucket(bucket).Object(attrs.Name).Delete(ctx) if err != nil { reqInfo := &logger.ReqInfo{BucketName: bucket, ObjectName: attrs.Name} - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(minio.GlobalContext, reqInfo) logger.LogIf(ctx, err) return } diff --git a/cmd/gateway/hdfs/gateway-hdfs.go b/cmd/gateway/hdfs/gateway-hdfs.go index 9ed4be080..c505664ed 100644 --- a/cmd/gateway/hdfs/gateway-hdfs.go +++ b/cmd/gateway/hdfs/gateway-hdfs.go @@ -332,13 +332,13 @@ func (n *hdfsObjects) listDirFactory() minio.ListDirFunc { if os.IsNotExist(err) { err = nil } - logger.LogIf(context.Background(), err) + logger.LogIf(minio.GlobalContext, err) return } defer f.Close() fis, err := f.Readdir(0) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(minio.GlobalContext, err) return } if len(fis) == 0 { diff --git a/cmd/gateway/oss/gateway-oss_test.go b/cmd/gateway/oss/gateway-oss_test.go index 63085d82a..91dc3e69e 100644 --- a/cmd/gateway/oss/gateway-oss_test.go +++ b/cmd/gateway/oss/gateway-oss_test.go @@ -17,7 +17,6 @@ package oss import ( - "context" "fmt" "net/http" "reflect" @@ -115,7 +114,7 @@ func TestS3MetaToOSSOptions(t *testing.T) { headers := map[string]string{ "x-amz-meta-invalid_meta": "value", } - _, err = appendS3MetaToOSSOptions(context.Background(), nil, headers) + _, err = appendS3MetaToOSSOptions(minio.GlobalContext, nil, headers) if err != nil { if _, ok := err.(minio.UnsupportedMetadata); !ok { t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err) @@ -132,7 +131,7 @@ func TestS3MetaToOSSOptions(t *testing.T) { "X-Amz-Meta-X-Amz-Matdesc": "{}", "X-Amz-Meta-X-Amz-Iv": "eWmyryl8kq+EVnnsE7jpOg==", } - opts, err := appendS3MetaToOSSOptions(context.Background(), nil, headers) + opts, err := appendS3MetaToOSSOptions(minio.GlobalContext, nil, headers) if err != nil { t.Fatalf("Test failed, with %s", err) } diff --git a/cmd/gateway/s3/gateway-s3-metadata_test.go b/cmd/gateway/s3/gateway-s3-metadata_test.go index a76c4d0e0..ba1f23766 100644 --- a/cmd/gateway/s3/gateway-s3-metadata_test.go +++ b/cmd/gateway/s3/gateway-s3-metadata_test.go @@ -18,8 +18,9 @@ package s3 import ( "bytes" - "context" "testing" + + minio "github.com/minio/minio/cmd" ) // Tests for GW metadata format validity. @@ -62,7 +63,7 @@ func TestReadGWMetadata(t *testing.T) { for i, tt := range tests { buf := bytes.NewBufferString(tt.metaStr) - m, err := readGWMetadata(context.Background(), *buf) + m, err := readGWMetadata(minio.GlobalContext, *buf) if err != nil && tt.pass { t.Errorf("Test %d: Expected parse gw metadata to succeed, but failed, %s", i+1, err) } diff --git a/cmd/gateway/s3/gateway-s3.go b/cmd/gateway/s3/gateway-s3.go index 0d924147b..54d6ea386 100644 --- a/cmd/gateway/s3/gateway-s3.go +++ b/cmd/gateway/s3/gateway-s3.go @@ -241,7 +241,7 @@ func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) encS := s3EncObjects{s} // Start stale enc multipart uploads cleanup routine. - go encS.cleanupStaleEncMultipartUploads(context.Background(), + go encS.cleanupStaleEncMultipartUploads(minio.GlobalContext, minio.GlobalMultipartCleanupInterval, minio.GlobalMultipartExpiry, minio.GlobalServiceDoneCh) return &encS, nil diff --git a/cmd/generic-handlers.go b/cmd/generic-handlers.go index a8f7c208e..0ae75f998 100644 --- a/cmd/generic-handlers.go +++ b/cmd/generic-handlers.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "net/http" "strings" "time" @@ -723,7 +722,7 @@ func setBucketForwardingHandler(h http.Handler) http.Handler { PassHost: true, RoundTripper: NewGatewayHTTPTransport(), Logger: func(err error) { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) }, }) return bucketForwardingHandler{fwd, h} diff --git a/cmd/handler-utils.go b/cmd/handler-utils.go index 9e9179aff..e7d22f73f 100644 --- a/cmd/handler-utils.go +++ b/cmd/handler-utils.go @@ -51,7 +51,7 @@ func parseLocationConstraint(r *http.Request) (location string, s3Error APIError locationConstraint := createBucketLocationConfiguration{} err := xmlDecoder(r.Body, &locationConstraint, r.ContentLength) if err != nil && r.ContentLength != 0 { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) // Treat all other failures as XML parsing errors. return "", ErrMalformedXML } // else for both err as nil or io.EOF @@ -431,7 +431,7 @@ func getResource(path string, host string, domains []string) (string, error) { if host, _, err = net.SplitHostPort(host); err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("host", host) reqInfo.AppendTags("path", path) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) return "", err } diff --git a/cmd/jwt.go b/cmd/jwt.go index c18c5a0b4..4b4555cbb 100644 --- a/cmd/jwt.go +++ b/cmd/jwt.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "errors" "net/http" "time" @@ -164,6 +163,6 @@ func webRequestAuthenticate(req *http.Request) (*xjwt.MapClaims, bool, error) { func newAuthToken(audience string) string { cred := globalActiveCred token, err := authenticateNode(cred.AccessKey, cred.SecretKey, audience) - logger.CriticalIf(context.Background(), err) + logger.CriticalIf(GlobalContext, err) return token } diff --git a/cmd/lifecycle.go b/cmd/lifecycle.go index 03cb081bc..8e780c617 100644 --- a/cmd/lifecycle.go +++ b/cmd/lifecycle.go @@ -61,7 +61,7 @@ func (sys *LifecycleSys) Get(bucketName string) (lc lifecycle.Lifecycle, ok bool return } - l, err := objAPI.GetBucketLifecycle(context.Background(), bucketName) + l, err := objAPI.GetBucketLifecycle(GlobalContext, bucketName) if err != nil { return } @@ -89,7 +89,7 @@ func saveLifecycleConfig(ctx context.Context, objAPI ObjectLayer, bucketName str func getLifecycleConfig(objAPI ObjectLayer, bucketName string) (*lifecycle.Lifecycle, error) { // Construct path to lifecycle.xml for the given bucket. configFile := path.Join(bucketConfigPrefix, bucketName, bucketLifecycleConfig) - configData, err := readConfig(context.Background(), objAPI, configFile) + configData, err := readConfig(GlobalContext, objAPI, configFile) if err != nil { if err == errConfigNotFound { err = BucketLifecycleNotFound{Bucket: bucketName} @@ -139,7 +139,7 @@ func (sys *LifecycleSys) Init(buckets []BucketInfo, objAPI ObjectLayer) error { // Loads lifecycle policies for all buckets into LifecycleSys. func (sys *LifecycleSys) load(buckets []BucketInfo, objAPI ObjectLayer) error { for _, bucket := range buckets { - config, err := objAPI.GetBucketLifecycle(context.Background(), bucket.Name) + config, err := objAPI.GetBucketLifecycle(GlobalContext, bucket.Name) if err != nil { if _, ok := err.(BucketLifecycleNotFound); ok { sys.Remove(bucket.Name) diff --git a/cmd/lock-rest-client.go b/cmd/lock-rest-client.go index 3c9d72876..644375ab9 100644 --- a/cmd/lock-rest-client.go +++ b/cmd/lock-rest-client.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "crypto/tls" "errors" "io" @@ -174,7 +173,7 @@ func newlockRESTClient(endpoint Endpoint) *lockRESTClient { trFn := newCustomHTTPTransport(tlsConfig, rest.DefaultRESTTimeout, rest.DefaultRESTTimeout) restClient, err := rest.NewClient(serverURL, trFn, newAuthToken) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return &lockRESTClient{endpoint: endpoint, restClient: restClient, connected: 0} } diff --git a/cmd/metrics.go b/cmd/metrics.go index 01bd1e639..a36690757 100644 --- a/cmd/metrics.go +++ b/cmd/metrics.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "net/http" "strings" "time" @@ -163,7 +162,7 @@ func gatewayMetricsPrometheus(ch chan<- prometheus.Metric) { return } - m, err := objLayer.GetMetrics(context.Background()) + m, err := objLayer.GetMetrics(GlobalContext) if err != nil { return } @@ -354,7 +353,7 @@ func storageMetricsPrometheus(ch chan<- prometheus.Metric) { } // Fetch disk space info - storageInfo := objLayer.StorageInfo(context.Background(), true) + storageInfo := objLayer.StorageInfo(GlobalContext, true) offlineDisks := storageInfo.Backend.OfflineDisks onlineDisks := storageInfo.Backend.OnlineDisks @@ -424,13 +423,13 @@ func metricsHandler() http.Handler { registry := prometheus.NewRegistry() err := registry.Register(minioVersionInfo) - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) err = registry.Register(httpRequestsDuration) - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) err = registry.Register(newMinioCollector()) - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) gatherers := prometheus.Gatherers{ prometheus.DefaultGatherer, diff --git a/cmd/namespace-lock.go b/cmd/namespace-lock.go index d85123eef..6b4544033 100644 --- a/cmd/namespace-lock.go +++ b/cmd/namespace-lock.go @@ -128,7 +128,7 @@ func (n *nsLockMap) unlock(volume string, path string, readLock bool) { } n.lockMapMutex.Lock() if nsLk.ref == 0 { - logger.LogIf(context.Background(), errors.New("Namespace reference count cannot be 0")) + logger.LogIf(GlobalContext, errors.New("Namespace reference count cannot be 0")) } else { nsLk.ref-- if nsLk.ref == 0 { diff --git a/cmd/notification.go b/cmd/notification.go index 0cf458068..6d426dd20 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -143,7 +143,7 @@ func (sys *NotificationSys) ReloadFormat(dryRun bool) []NotificationPeerErr { continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.ReloadFormat(dryRun) }, idx, *client.host) } @@ -158,7 +158,7 @@ func (sys *NotificationSys) DeletePolicy(policyName string) []NotificationPeerEr continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.DeletePolicy(policyName) }, idx, *client.host) } @@ -173,7 +173,7 @@ func (sys *NotificationSys) LoadPolicy(policyName string) []NotificationPeerErr continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.LoadPolicy(policyName) }, idx, *client.host) } @@ -188,7 +188,7 @@ func (sys *NotificationSys) LoadPolicyMapping(userOrGroup string, isGroup bool) continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.LoadPolicyMapping(userOrGroup, isGroup) }, idx, *client.host) } @@ -203,7 +203,7 @@ func (sys *NotificationSys) DeleteUser(accessKey string) []NotificationPeerErr { continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.DeleteUser(accessKey) }, idx, *client.host) } @@ -218,7 +218,7 @@ func (sys *NotificationSys) LoadUser(accessKey string, temp bool) []Notification continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.LoadUser(accessKey, temp) }, idx, *client.host) } @@ -233,7 +233,7 @@ func (sys *NotificationSys) LoadGroup(group string) []NotificationPeerErr { continue } client := client - ng.Go(context.Background(), func() error { return client.LoadGroup(group) }, idx, *client.host) + ng.Go(GlobalContext, func() error { return client.LoadGroup(group) }, idx, *client.host) } return ng.Wait() } @@ -247,7 +247,7 @@ func (sys *NotificationSys) BackgroundHealStatus() []madmin.BgHealState { } st, err := client.BackgroundHealStatus() if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) } else { states[idx] = st } @@ -264,7 +264,7 @@ func (sys *NotificationSys) StartProfiling(profiler string) []NotificationPeerEr continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.StartProfiling(profiler) }, idx, *client.host) } @@ -378,7 +378,7 @@ func (sys *NotificationSys) ServerUpdate(updateURL, sha256Hex string, latestRele continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.ServerUpdate(updateURL, sha256Hex, latestReleaseTime) }, idx, *client.host) } @@ -393,7 +393,7 @@ func (sys *NotificationSys) SignalService(sig serviceSignal) []NotificationPeerE continue } client := client - ng.Go(context.Background(), func() error { + ng.Go(GlobalContext, func() error { return client.SignalService(sig) }, idx, *client.host) } @@ -643,7 +643,7 @@ func (sys *NotificationSys) RemoteTargetExist(bucketName string, targetID event. // Loads notification policies for all buckets into NotificationSys. func (sys *NotificationSys) load(buckets []BucketInfo, objAPI ObjectLayer) error { for _, bucket := range buckets { - ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{BucketName: bucket.Name}) + ctx := logger.SetReqInfo(GlobalContext, &logger.ReqInfo{BucketName: bucket.Name}) config, err := readNotificationConfig(ctx, objAPI, bucket.Name) if err != nil && err != errNoSuchNotifications { if _, ok := err.(*event.ErrARNNotFound); ok { @@ -769,7 +769,7 @@ func (sys *NotificationSys) RemoveAllRemoteTargets() { func (sys *NotificationSys) RemoveRemoteTarget(bucketName string, targetID event.TargetID) { for terr := range sys.targetList.Remove(targetID) { reqInfo := (&logger.ReqInfo{}).AppendTags("targetID", terr.ID.Name) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, terr.Err) } @@ -843,7 +843,7 @@ func (sys *NotificationSys) NetReadPerfInfo(size int64) []ServerNetReadPerfInfo info, err := client.NetReadPerfInfo(size) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", client.host.String()) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) info.Addr = client.host.String() @@ -869,7 +869,7 @@ func (sys *NotificationSys) CollectNetPerfInfo(size int64) map[string][]ServerNe info, err := client.CollectNetPerfInfo(size) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", client.host.String()) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) } @@ -948,7 +948,7 @@ func (sys *NotificationSys) NetOBDInfo(ctx context.Context) madmin.ServerNetOBDI addr := client.host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) netOBDs[index].Addr = addr if err != nil { @@ -1029,7 +1029,7 @@ func (sys *NotificationSys) DriveOBDInfo(ctx context.Context) []madmin.ServerDri if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1059,7 +1059,7 @@ func (sys *NotificationSys) CPUOBDInfo(ctx context.Context) []madmin.ServerCPUOB if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1089,7 +1089,7 @@ func (sys *NotificationSys) DiskHwOBDInfo(ctx context.Context) []madmin.ServerDi if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1119,7 +1119,7 @@ func (sys *NotificationSys) OsOBDInfo(ctx context.Context) []madmin.ServerOsOBDI if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1149,7 +1149,7 @@ func (sys *NotificationSys) MemOBDInfo(ctx context.Context) []madmin.ServerMemOB if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1179,7 +1179,7 @@ func (sys *NotificationSys) ProcOBDInfo(ctx context.Context) []madmin.ServerProc if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1209,7 +1209,7 @@ func (sys *NotificationSys) DrivePerfInfo(size int64) []madmin.ServerDrivesPerfI if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1239,7 +1239,7 @@ func (sys *NotificationSys) MemUsageInfo() []ServerMemUsageInfo { if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1269,7 +1269,7 @@ func (sys *NotificationSys) CPULoadInfo() []ServerCPULoadInfo { if err != nil { addr := sys.peerClients[index].host.String() reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) reply[index].Addr = addr reply[index].Error = err.Error() @@ -1467,7 +1467,7 @@ func sendEvent(args eventArgs) { reqInfo := &logger.ReqInfo{BucketName: args.BucketName, ObjectName: args.Object.Name} reqInfo.AppendTags("EventName", args.EventName.String()) reqInfo.AppendTags("targetID", err.ID.Name) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogOnceIf(ctx, err.Err, err.ID) } }() diff --git a/cmd/object-api-utils.go b/cmd/object-api-utils.go index 3d360a702..95d988fb0 100644 --- a/cmd/object-api-utils.go +++ b/cmd/object-api-utils.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "encoding/hex" "fmt" "io" @@ -219,7 +218,7 @@ func pathJoin(elem ...string) string { func mustGetUUID() string { uuid, err := uuid.New() if err != nil { - logger.CriticalIf(context.Background(), err) + logger.CriticalIf(GlobalContext, err) } return uuid.String() diff --git a/cmd/object-lock.go b/cmd/object-lock.go index d3fd2bbb9..917d8bef0 100644 --- a/cmd/object-lock.go +++ b/cmd/object-lock.go @@ -375,7 +375,7 @@ func checkPutObjectLockAllowed(ctx context.Context, r *http.Request, bucket, obj func initBucketObjectLockConfig(buckets []BucketInfo, objAPI ObjectLayer) error { for _, bucket := range buckets { - ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{BucketName: bucket.Name}) + ctx := logger.SetReqInfo(GlobalContext, &logger.ReqInfo{BucketName: bucket.Name}) configFile := path.Join(bucketConfigPrefix, bucket.Name, bucketObjectLockEnabledConfigFile) bucketObjLockData, err := readConfig(ctx, objAPI, configFile) if err != nil { diff --git a/cmd/peer-rest-client.go b/cmd/peer-rest-client.go index 4d1350920..c1fcabdc0 100644 --- a/cmd/peer-rest-client.go +++ b/cmd/peer-rest-client.go @@ -66,7 +66,7 @@ func (client *peerRESTClient) reConnect() { // permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints() // after verifying format.json func (client *peerRESTClient) call(method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) { - return client.callWithContext(context.Background(), method, values, body, length) + return client.callWithContext(GlobalContext, method, values, body, length) } // Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected @@ -633,7 +633,7 @@ func (client *peerRESTClient) sendEvent(bucket string, targetID, remoteTargetID reqInfo := &logger.ReqInfo{BucketName: bucket} reqInfo.AppendTags("targetID", targetID.Name) reqInfo.AppendTags("event", eventData.EventName.String()) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) globalNotificationSys.RemoveRemoteTarget(bucket, targetID) } @@ -934,7 +934,7 @@ func (client *peerRESTClient) doTrace(traceCh chan interface{}, doneCh chan stru values.Set(peerRESTTraceErr, strconv.FormatBool(trcErr)) // To cancel the REST request in case doneCh gets closed. - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(GlobalContext) cancelCh := make(chan struct{}) defer close(cancelCh) @@ -972,7 +972,7 @@ func (client *peerRESTClient) doTrace(traceCh chan interface{}, doneCh chan stru func (client *peerRESTClient) doListen(listenCh chan interface{}, doneCh chan struct{}, v url.Values) { // To cancel the REST request in case doneCh gets closed. - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(GlobalContext) cancelCh := make(chan struct{}) defer close(cancelCh) @@ -1045,7 +1045,7 @@ func (client *peerRESTClient) ConsoleLog(logCh chan interface{}, doneCh chan str go func() { for { // get cancellation context to properly unsubscribe peers - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(GlobalContext) respBody, err := client.callWithContext(ctx, peerRESTMethodLog, nil, nil, -1) if err != nil { // Retry the failed request. @@ -1087,7 +1087,7 @@ func getRemoteHosts(endpointZones EndpointZones) []*xnet.Host { for _, hostStr := range GetRemotePeers(endpointZones) { host, err := xnet.ParseHost(hostStr) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) continue } remoteHosts = append(remoteHosts, host) @@ -1102,7 +1102,7 @@ func getRestClients(endpoints EndpointZones) []*peerRESTClient { for i, host := range peerHosts { client, err := newPeerRESTClient(host) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) continue } restClients[i] = client diff --git a/cmd/peer-rest-server.go b/cmd/peer-rest-server.go index 6b55836ec..84845577f 100644 --- a/cmd/peer-rest-server.go +++ b/cmd/peer-rest-server.go @@ -729,7 +729,7 @@ func (s *peerRESTServer) ReloadFormatHandler(w http.ResponseWriter, r *http.Requ return } - err := objAPI.ReloadFormat(context.Background(), dryRun) + err := objAPI.ReloadFormat(GlobalContext, dryRun) if err != nil { s.writeErrorResponse(w, err) return @@ -947,7 +947,7 @@ func (s *peerRESTServer) SendEventHandler(w http.ResponseWriter, r *http.Request for i := range errs { reqInfo := (&logger.ReqInfo{}).AppendTags("Event", eventReq.Event.EventName.String()) reqInfo.AppendTags("targetName", eventReq.TargetID.Name) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, errs[i].Err) eventResp.Success = false diff --git a/cmd/policy.go b/cmd/policy.go index 6cf43471f..be626a564 100644 --- a/cmd/policy.go +++ b/cmd/policy.go @@ -74,7 +74,7 @@ func (sys *PolicySys) IsAllowed(args policy.Args) bool { // is used to validate bucket policies. objAPI := newObjectLayerFn() if objAPI != nil { - config, err := objAPI.GetBucketPolicy(context.Background(), args.BucketName) + config, err := objAPI.GetBucketPolicy(GlobalContext, args.BucketName) if err == nil { return config.IsAllowed(args) } @@ -97,7 +97,7 @@ func (sys *PolicySys) IsAllowed(args policy.Args) bool { // Loads policies for all buckets into PolicySys. func (sys *PolicySys) load(buckets []BucketInfo, objAPI ObjectLayer) error { for _, bucket := range buckets { - config, err := objAPI.GetBucketPolicy(context.Background(), bucket.Name) + config, err := objAPI.GetBucketPolicy(GlobalContext, bucket.Name) if err != nil { if _, ok := err.(BucketPolicyNotFound); ok { sys.Remove(bucket.Name) @@ -113,8 +113,8 @@ func (sys *PolicySys) load(buckets []BucketInfo, objAPI ObjectLayer) error { logger.Info("Found in-consistent bucket policies, Migrating them for Bucket: (%s)", bucket.Name) config.Version = policy.DefaultVersion - if err = savePolicyConfig(context.Background(), objAPI, bucket.Name, config); err != nil { - logger.LogIf(context.Background(), err) + if err = savePolicyConfig(GlobalContext, objAPI, bucket.Name, config); err != nil { + logger.LogIf(GlobalContext, err) return err } } @@ -231,7 +231,7 @@ func getPolicyConfig(objAPI ObjectLayer, bucketName string) (*policy.Policy, err // Construct path to policy.json for the given bucket. configFile := path.Join(bucketConfigPrefix, bucketName, bucketPolicyConfig) - configData, err := readConfig(context.Background(), objAPI, configFile) + configData, err := readConfig(GlobalContext, objAPI, configFile) if err != nil { if err == errConfigNotFound { err = BucketPolicyNotFound{Bucket: bucketName} diff --git a/cmd/posix-list-dir_other.go b/cmd/posix-list-dir_other.go index 97a1f7ad1..32b05a062 100644 --- a/cmd/posix-list-dir_other.go +++ b/cmd/posix-list-dir_other.go @@ -19,7 +19,6 @@ package cmd import ( - "context" "io" "os" "path" @@ -80,7 +79,7 @@ func readDirN(dirPath string, count int) (entries []string, err error) { st, err = os.Stat(path.Join(dirPath, fi.Name())) if err != nil { reqInfo := (&logger.ReqInfo{}).AppendTags("path", path.Join(dirPath, fi.Name())) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) continue } diff --git a/cmd/posix.go b/cmd/posix.go index 7ec9fe77e..e6a432ff4 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -179,7 +179,7 @@ func isDirEmpty(dirname string) bool { f, err := os.Open((dirname)) if err != nil { if !os.IsNotExist(err) { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) } return false @@ -189,7 +189,7 @@ func isDirEmpty(dirname string) bool { _, err = f.Readdirnames(1) if err != io.EOF { if !os.IsNotExist(err) { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) } return false @@ -746,7 +746,7 @@ func (s *posix) WalkSplunk(volume, dirPath, marker string, endWalkCh <-chan stru return false, filterMatchingPrefix(entries, dirEntry) } - walkResultCh := startTreeWalk(context.Background(), volume, dirPath, marker, true, listDir, endWalkCh) + walkResultCh := startTreeWalk(GlobalContext, volume, dirPath, marker, true, listDir, endWalkCh) for { walkResult, ok := <-walkResultCh if !ok { @@ -820,7 +820,7 @@ func (s *posix) Walk(volume, dirPath, marker string, recursive bool, leafFile st return false, filterMatchingPrefix(entries, dirEntry) } - walkResultCh := startTreeWalk(context.Background(), volume, dirPath, marker, recursive, listDir, endWalkCh) + walkResultCh := startTreeWalk(GlobalContext, volume, dirPath, marker, recursive, listDir, endWalkCh) for { walkResult, ok := <-walkResultCh if !ok { diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index 76a7401df..682820a5c 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "crypto/tls" "fmt" "net/http" @@ -39,7 +38,7 @@ var printEndpointError = func() func(Endpoint, error) { return func(endpoint Endpoint, err error) { reqInfo := (&logger.ReqInfo{}).AppendTags("endpoint", endpoint.String()) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) mutex.Lock() defer mutex.Unlock() m, ok := printOnce[endpoint] @@ -272,7 +271,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, zoneCount, setCount, drivesPerSet) // Initialize erasure code format on disks - format, err = initFormatXL(context.Background(), storageDisks, setCount, drivesPerSet, deploymentID) + format, err = initFormatXL(GlobalContext, storageDisks, setCount, drivesPerSet, deploymentID) if err != nil { return nil, nil, err } diff --git a/cmd/server-main.go b/cmd/server-main.go index 8fda557ab..c04acaca4 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -166,7 +166,7 @@ func initSafeMode(buckets []BucketInfo) (err error) { // at a given time, this big transaction lock ensures this // appropriately. This is also true for rotation of encrypted // content. - objLock := newObject.NewNSLock(context.Background(), minioMetaBucket, transactionConfigPrefix) + objLock := newObject.NewNSLock(GlobalContext, minioMetaBucket, transactionConfigPrefix) if err = objLock.GetLock(globalOperationTimeout); err != nil { return err } @@ -316,7 +316,7 @@ func serverMain(ctx *cli.Context) { setDefaultProfilerRates() // Initialize globalConsoleSys system - globalConsoleSys = NewConsoleLogger(context.Background()) + globalConsoleSys = NewConsoleLogger(GlobalContext) signal.Notify(globalOSSignalCh, os.Interrupt, syscall.SIGTERM) diff --git a/cmd/server-startup-msg.go b/cmd/server-startup-msg.go index bc11176fd..fc8ed80e8 100644 --- a/cmd/server-startup-msg.go +++ b/cmd/server-startup-msg.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "crypto/x509" "fmt" "net" @@ -55,7 +54,7 @@ func printStartupSafeModeMessage(apiEndpoints []string, err error) { // Object layer is initialized then print StorageInfo in safe mode. objAPI := newObjectLayerWithoutSafeModeFn() if objAPI != nil { - if msg := getStorageInfoMsgSafeMode(objAPI.StorageInfo(context.Background(), false)); msg != "" { + if msg := getStorageInfoMsgSafeMode(objAPI.StorageInfo(GlobalContext, false)); msg != "" { logStartupMessage(msg) } } @@ -111,13 +110,13 @@ func printStartupMessage(apiEndpoints []string) { // If cache layer is enabled, print cache capacity. cachedObjAPI := newCachedObjectLayerFn() if cachedObjAPI != nil { - printCacheStorageInfo(cachedObjAPI.StorageInfo(context.Background())) + printCacheStorageInfo(cachedObjAPI.StorageInfo(GlobalContext)) } // Object layer is initialized then print StorageInfo. objAPI := newObjectLayerFn() if objAPI != nil { - printStorageInfo(objAPI.StorageInfo(context.Background(), false)) + printStorageInfo(objAPI.StorageInfo(GlobalContext, false)) } // Prints credential, region and browser access. diff --git a/cmd/signature-v4-utils.go b/cmd/signature-v4-utils.go index 86e776fd5..6f09d6881 100644 --- a/cmd/signature-v4-utils.go +++ b/cmd/signature-v4-utils.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "crypto/hmac" "encoding/hex" "io" @@ -64,7 +63,7 @@ func getContentSha256Cksum(r *http.Request, stype serviceType) string { if stype == serviceSTS { payload, err := ioutil.ReadAll(io.LimitReader(r.Body, stsRequestBodyLimit)) if err != nil { - logger.CriticalIf(context.Background(), err) + logger.CriticalIf(GlobalContext, err) } sum256 := sha256.New() sum256.Write(payload) diff --git a/cmd/storage-rest-client.go b/cmd/storage-rest-client.go index 12e9eae68..fd3c071c2 100644 --- a/cmd/storage-rest-client.go +++ b/cmd/storage-rest-client.go @@ -575,7 +575,7 @@ func newStorageRESTClient(endpoint Endpoint) *storageRESTClient { trFn := newCustomHTTPTransport(tlsConfig, rest.DefaultRESTTimeout, rest.DefaultRESTTimeout) restClient, err := rest.NewClient(serverURL, trFn, newAuthToken) if err != nil { - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return &storageRESTClient{endpoint: endpoint, restClient: restClient, connected: 0} } return &storageRESTClient{endpoint: endpoint, restClient: restClient, connected: 1} diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index 33ce9c5ad..6e90503ee 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -18,7 +18,6 @@ package cmd import ( "bufio" - "context" "encoding/gob" "encoding/hex" "errors" @@ -414,7 +413,7 @@ func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http type readMetadataFunc func(buf []byte, volume, entry string) FileInfo func readMetadata(buf []byte, volume, entry string) FileInfo { - m, err := xlMetaV1UnmarshalJSON(context.Background(), buf) + m, err := xlMetaV1UnmarshalJSON(GlobalContext, buf) if err != nil { return FileInfo{} } diff --git a/cmd/update.go b/cmd/update.go index af01f63b3..7b4edb0f9 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -137,7 +137,7 @@ func IsDocker() bool { } // Log error, as we will not propagate it to caller - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return err == nil } @@ -180,7 +180,7 @@ func IsBOSH() bool { } // Log error, as we will not propagate it to caller - logger.LogIf(context.Background(), err) + logger.LogIf(GlobalContext, err) return err == nil } @@ -196,7 +196,7 @@ func getHelmVersion(helmInfoFilePath string) string { // without Helm charts as well. if !os.IsNotExist(err) { reqInfo := (&logger.ReqInfo{}).AppendTags("helmInfoFilePath", helmInfoFilePath) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) } return "" diff --git a/cmd/utils.go b/cmd/utils.go index 785836ea9..da8aaf9fe 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -71,7 +71,7 @@ func IsErr(err error, errs ...error) bool { func request2BucketObjectName(r *http.Request) (bucketName, objectName string) { path, err := getResource(r.URL.Path, r.Host, globalDomainNames) if err != nil { - logger.CriticalIf(context.Background(), err) + logger.CriticalIf(GlobalContext, err) } return path2BucketObject(path) diff --git a/cmd/web-handler-context.go b/cmd/web-handler-context.go index e66ab9d6e..be18b241c 100644 --- a/cmd/web-handler-context.go +++ b/cmd/web-handler-context.go @@ -247,5 +247,5 @@ func newWebContext(r *http.Request, args ToKeyValuer, api string) context.Contex BucketName: bucket, ObjectName: object, } - return logger.SetReqInfo(context.Background(), reqInfo) + return logger.SetReqInfo(GlobalContext, reqInfo) } diff --git a/cmd/web-handlers.go b/cmd/web-handlers.go index 1574cb76f..f8428d8ab 100644 --- a/cmd/web-handlers.go +++ b/cmd/web-handlers.go @@ -1183,7 +1183,7 @@ func (web *webAPIHandlers) Upload(w http.ResponseWriter, r *http.Request) { } } - objInfo, err := putObject(context.Background(), bucket, object, pReader, opts) + objInfo, err := putObject(GlobalContext, bucket, object, pReader, opts) if err != nil { writeWebErrorResponse(w, err) return @@ -2272,7 +2272,7 @@ func writeWebErrorResponse(w http.ResponseWriter, err error) { reqInfo := &logger.ReqInfo{ DeploymentID: globalDeploymentID, } - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) apiErr := toWebAPIError(ctx, err) w.WriteHeader(apiErr.HTTPStatusCode) w.Write([]byte(apiErr.Description)) diff --git a/cmd/xl-sets.go b/cmd/xl-sets.go index 583d16a82..180b382fb 100644 --- a/cmd/xl-sets.go +++ b/cmd/xl-sets.go @@ -363,7 +363,7 @@ func newXLSets(endpoints Endpoints, storageDisks []StorageAPI, format *formatXLV mrfUploadCh: make(chan partialUpload, 10000), } - go s.sets[i].cleanupStaleMultipartUploads(context.Background(), + go s.sets[i].cleanupStaleMultipartUploads(GlobalContext, GlobalMultipartCleanupInterval, GlobalMultipartExpiry, GlobalServiceDoneCh) } @@ -536,7 +536,7 @@ func undoMakeBucketSets(bucket string, sets []*xlObjects, errs []error) { index := index g.Go(func() error { if errs[index] == nil { - return sets[index].DeleteBucket(context.Background(), bucket, false) + return sets[index].DeleteBucket(GlobalContext, bucket, false) } return nil }, index) @@ -712,7 +712,7 @@ func undoDeleteBucketSets(bucket string, sets []*xlObjects, errs []error) { index := index g.Go(func() error { if errs[index] == nil { - return sets[index].MakeBucketWithLocation(context.Background(), bucket, "") + return sets[index].MakeBucketWithLocation(GlobalContext, bucket, "") } return nil }, index) @@ -1026,7 +1026,7 @@ func (s *xlSets) listObjectsNonSlash(ctx context.Context, bucket, prefix, marker defer close(endWalkCh) const ndisks = 3 - entryChs := s.startMergeWalksN(context.Background(), bucket, prefix, "", true, endWalkCh, ndisks) + entryChs := s.startMergeWalksN(GlobalContext, bucket, prefix, "", true, endWalkCh, ndisks) var objInfos []ObjectInfo var eof bool @@ -1175,7 +1175,7 @@ func (s *xlSets) listObjects(ctx context.Context, bucket, prefix, marker, delimi if entryChs == nil { endWalkCh = make(chan struct{}) // start file tree walk across at most randomly 3 disks in a set. - entryChs = s.startMergeWalksN(context.Background(), bucket, prefix, marker, recursive, endWalkCh, ndisks) + entryChs = s.startMergeWalksN(GlobalContext, bucket, prefix, marker, recursive, endWalkCh, ndisks) } entries := mergeEntriesCh(entryChs, maxKeys, ndisks) diff --git a/cmd/xl-v1-common.go b/cmd/xl-v1-common.go index 2bef89737..be826dee0 100644 --- a/cmd/xl-v1-common.go +++ b/cmd/xl-v1-common.go @@ -83,5 +83,5 @@ func (xl xlObjects) isObject(bucket, prefix string) (ok bool) { // ignored if necessary. readQuorum := getReadQuorum(len(storageDisks)) - return reduceReadQuorumErrs(context.Background(), g.Wait(), objectOpIgnoredErrs, readQuorum) == nil + return reduceReadQuorumErrs(GlobalContext, g.Wait(), objectOpIgnoredErrs, readQuorum) == nil } diff --git a/cmd/xl-v1-common_test.go b/cmd/xl-v1-common_test.go index 057cf1a1d..9966b19d0 100644 --- a/cmd/xl-v1-common_test.go +++ b/cmd/xl-v1-common_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "os" "testing" ) @@ -38,11 +37,11 @@ func TestXLParentDirIsObject(t *testing.T) { bucketName := "testbucket" objectName := "object" - if err = obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err = obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal(err) } objectContent := "12345" - objInfo, err := obj.PutObject(context.Background(), bucketName, objectName, + objInfo, err := obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{}) if err != nil { t.Fatal(err) @@ -87,7 +86,7 @@ func TestXLParentDirIsObject(t *testing.T) { } for i, testCase := range testCases { - gotValue := xl.parentDirIsObject(context.Background(), bucketName, testCase.objectName) + gotValue := xl.parentDirIsObject(GlobalContext, bucketName, testCase.objectName) if testCase.parentIsObject != gotValue { t.Errorf("Test %d: Unexpected value returned got %t, expected %t", i+1, gotValue, testCase.parentIsObject) } diff --git a/cmd/xl-v1-healing-common_test.go b/cmd/xl-v1-healing-common_test.go index 5c452401e..2e3abcb9f 100644 --- a/cmd/xl-v1-healing-common_test.go +++ b/cmd/xl-v1-healing-common_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "fmt" "os" "path/filepath" @@ -175,15 +174,15 @@ func TestListOnlineDisks(t *testing.T) { // Prepare bucket/object backend for the tests below. // Cleanup from previous test. - obj.DeleteObject(context.Background(), bucket, object) - obj.DeleteBucket(context.Background(), bucket, false) + obj.DeleteObject(GlobalContext, bucket, object) + obj.DeleteBucket(GlobalContext, bucket, false) - err = obj.MakeBucketWithLocation(context.Background(), "bucket", "") + err = obj.MakeBucketWithLocation(GlobalContext, "bucket", "") if err != nil { t.Fatalf("Failed to make a bucket %v", err) } - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{}) if err != nil { t.Fatalf("Failed to putObject %v", err) } @@ -229,7 +228,7 @@ func TestListOnlineDisks(t *testing.T) { } - partsMetadata, errs := readAllXLMetadata(context.Background(), xlDisks, bucket, object) + partsMetadata, errs := readAllXLMetadata(GlobalContext, xlDisks, bucket, object) for i := range partsMetadata { if errs[i] != nil { t.Fatalf("Test %d: expected error to be nil: %s", i+1, errs[i].Error()) @@ -243,7 +242,7 @@ func TestListOnlineDisks(t *testing.T) { i+1, test.expectedTime, modTime) } - availableDisks, newErrs := disksWithAllParts(context.Background(), onlineDisks, partsMetadata, test.errs, bucket, object, madmin.HealDeepScan) + availableDisks, newErrs := disksWithAllParts(GlobalContext, onlineDisks, partsMetadata, test.errs, bucket, object, madmin.HealDeepScan) test.errs = newErrs if test._tamperBackend != noTamper { @@ -257,7 +256,7 @@ func TestListOnlineDisks(t *testing.T) { } func TestDisksWithAllParts(t *testing.T) { - ctx := context.Background() + ctx := GlobalContext obj, disks, err := prepareXL16() if err != nil { t.Fatalf("Prepare XL backend failed - %v", err) diff --git a/cmd/xl-v1-healing.go b/cmd/xl-v1-healing.go index 24866a208..5041af4c1 100644 --- a/cmd/xl-v1-healing.go +++ b/cmd/xl-v1-healing.go @@ -712,7 +712,7 @@ func (xl xlObjects) HealObject(ctx context.Context, bucket, object string, opts } else { newReqInfo = logger.NewReqInfo("", "", globalDeploymentID, "", "Heal", bucket, object) } - healCtx := logger.SetReqInfo(context.Background(), newReqInfo) + healCtx := logger.SetReqInfo(GlobalContext, newReqInfo) // Healing directories handle it separately. if HasSuffix(object, SlashSeparator) { diff --git a/cmd/xl-v1-healing_test.go b/cmd/xl-v1-healing_test.go index 747b8a9cd..be0b0bb63 100644 --- a/cmd/xl-v1-healing_test.go +++ b/cmd/xl-v1-healing_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "path/filepath" "testing" @@ -41,7 +40,7 @@ func TestUndoMakeBucket(t *testing.T) { } bucketName := getRandomBucketName() - if err = obj.MakeBucketWithLocation(context.Background(), bucketName, ""); err != nil { + if err = obj.MakeBucketWithLocation(GlobalContext, bucketName, ""); err != nil { t.Fatal(err) } z := obj.(*xlZones) @@ -49,7 +48,7 @@ func TestUndoMakeBucket(t *testing.T) { undoMakeBucket(xl.getDisks(), bucketName) // Validate if bucket was deleted properly. - _, err = obj.GetBucketInfo(context.Background(), bucketName) + _, err = obj.GetBucketInfo(GlobalContext, bucketName) if err != nil { switch err.(type) { case BucketNotFound: @@ -83,21 +82,21 @@ func TestHealObjectCorrupted(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = objLayer.MakeBucketWithLocation(context.Background(), bucket, "") + err = objLayer.MakeBucketWithLocation(GlobalContext, bucket, "") if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } // Create an object with multiple parts uploaded in decreasing // part number. - uploadID, err := objLayer.NewMultipartUpload(context.Background(), bucket, object, opts) + uploadID, err := objLayer.NewMultipartUpload(GlobalContext, bucket, object, opts) if err != nil { t.Fatalf("Failed to create a multipart upload - %v", err) } var uploadedParts []CompletePart for _, partID := range []int{2, 1} { - pInfo, err1 := objLayer.PutObjectPart(context.Background(), bucket, object, uploadID, partID, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts) + pInfo, err1 := objLayer.PutObjectPart(GlobalContext, bucket, object, uploadID, partID, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts) if err1 != nil { t.Fatalf("Failed to upload a part - %v", err1) } @@ -107,7 +106,7 @@ func TestHealObjectCorrupted(t *testing.T) { }) } - _, err = objLayer.CompleteMultipartUpload(context.Background(), bucket, object, uploadID, uploadedParts, ObjectOptions{}) + _, err = objLayer.CompleteMultipartUpload(GlobalContext, bucket, object, uploadID, uploadedParts, ObjectOptions{}) if err != nil { t.Fatalf("Failed to complete multipart upload - %v", err) } @@ -121,7 +120,7 @@ func TestHealObjectCorrupted(t *testing.T) { t.Fatalf("Failed to delete a file - %v", err) } - _, err = objLayer.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) + _, err = objLayer.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) if err != nil { t.Fatalf("Failed to heal object - %v", err) } @@ -144,7 +143,7 @@ func TestHealObjectCorrupted(t *testing.T) { if err != nil { t.Errorf("Failure during creating part.1 - %v", err) } - _, err = objLayer.HealObject(context.Background(), bucket, object, madmin.HealOpts{DryRun: false, Remove: true, ScanMode: madmin.HealDeepScan}) + _, err = objLayer.HealObject(GlobalContext, bucket, object, madmin.HealOpts{DryRun: false, Remove: true, ScanMode: madmin.HealDeepScan}) if err != nil { t.Errorf("Expected nil but received %v", err) } @@ -170,7 +169,7 @@ func TestHealObjectCorrupted(t *testing.T) { if err != nil { t.Errorf("Failure during creating part.1 - %v", err) } - _, err = objLayer.HealObject(context.Background(), bucket, object, madmin.HealOpts{DryRun: false, Remove: true, ScanMode: madmin.HealDeepScan}) + _, err = objLayer.HealObject(GlobalContext, bucket, object, madmin.HealOpts{DryRun: false, Remove: true, ScanMode: madmin.HealDeepScan}) if err != nil { t.Errorf("Expected nil but received %v", err) } @@ -190,7 +189,7 @@ func TestHealObjectCorrupted(t *testing.T) { } // Try healing now, expect to receive errFileNotFound. - _, err = objLayer.HealObject(context.Background(), bucket, object, madmin.HealOpts{DryRun: false, Remove: true, ScanMode: madmin.HealDeepScan}) + _, err = objLayer.HealObject(GlobalContext, bucket, object, madmin.HealOpts{DryRun: false, Remove: true, ScanMode: madmin.HealDeepScan}) if err != nil { if _, ok := err.(ObjectNotFound); !ok { t.Errorf("Expect %v but received %v", ObjectNotFound{Bucket: bucket, Object: object}, err) @@ -198,7 +197,7 @@ func TestHealObjectCorrupted(t *testing.T) { } // since majority of xl.jsons are not available, object should be successfully deleted. - _, err = objLayer.GetObjectInfo(context.Background(), bucket, object, ObjectOptions{}) + _, err = objLayer.GetObjectInfo(GlobalContext, bucket, object, ObjectOptions{}) if _, ok := err.(ObjectNotFound); !ok { t.Errorf("Expect %v but received %v", ObjectNotFound{Bucket: bucket, Object: object}, err) } @@ -225,21 +224,21 @@ func TestHealObjectXL(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = obj.MakeBucketWithLocation(context.Background(), bucket, "") + err = obj.MakeBucketWithLocation(GlobalContext, bucket, "") if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } // Create an object with multiple parts uploaded in decreasing // part number. - uploadID, err := obj.NewMultipartUpload(context.Background(), bucket, object, opts) + uploadID, err := obj.NewMultipartUpload(GlobalContext, bucket, object, opts) if err != nil { t.Fatalf("Failed to create a multipart upload - %v", err) } var uploadedParts []CompletePart for _, partID := range []int{2, 1} { - pInfo, err1 := obj.PutObjectPart(context.Background(), bucket, object, uploadID, partID, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts) + pInfo, err1 := obj.PutObjectPart(GlobalContext, bucket, object, uploadID, partID, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts) if err1 != nil { t.Fatalf("Failed to upload a part - %v", err1) } @@ -249,7 +248,7 @@ func TestHealObjectXL(t *testing.T) { }) } - _, err = obj.CompleteMultipartUpload(context.Background(), bucket, object, uploadID, uploadedParts, ObjectOptions{}) + _, err = obj.CompleteMultipartUpload(GlobalContext, bucket, object, uploadID, uploadedParts, ObjectOptions{}) if err != nil { t.Fatalf("Failed to complete multipart upload - %v", err) } @@ -263,7 +262,7 @@ func TestHealObjectXL(t *testing.T) { t.Fatalf("Failed to delete a file - %v", err) } - _, err = obj.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) + _, err = obj.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) if err != nil { t.Fatalf("Failed to heal object - %v", err) } @@ -285,7 +284,7 @@ func TestHealObjectXL(t *testing.T) { z.zones[0].xlDisksMu.Unlock() // Try healing now, expect to receive errDiskNotFound. - _, err = obj.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealDeepScan}) + _, err = obj.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealDeepScan}) // since majority of xl.jsons are not available, object quorum can't be read properly and error will be errXLReadQuorum if _, ok := err.(InsufficientReadQuorum); !ok { t.Errorf("Expected %v but received %v", InsufficientReadQuorum{}, err) @@ -311,13 +310,13 @@ func TestHealEmptyDirectoryXL(t *testing.T) { object := "empty-dir/" var opts ObjectOptions - err = obj.MakeBucketWithLocation(context.Background(), bucket, "") + err = obj.MakeBucketWithLocation(GlobalContext, bucket, "") if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } // Upload an empty directory - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte{}), 0, "", ""), opts) if err != nil { t.Fatal(err) @@ -333,7 +332,7 @@ func TestHealEmptyDirectoryXL(t *testing.T) { } // Heal the object - hr, err := obj.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) + hr, err := obj.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) if err != nil { t.Fatalf("Failed to heal object - %v", err) } @@ -357,7 +356,7 @@ func TestHealEmptyDirectoryXL(t *testing.T) { } // Heal the same object again - hr, err = obj.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) + hr, err = obj.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) if err != nil { t.Fatalf("Failed to heal object - %v", err) } diff --git a/cmd/xl-v1-metadata.go b/cmd/xl-v1-metadata.go index 040519d82..32c03a110 100644 --- a/cmd/xl-v1-metadata.go +++ b/cmd/xl-v1-metadata.go @@ -93,7 +93,7 @@ func (c *ChecksumInfo) UnmarshalJSON(data []byte) error { } if !c.Algorithm.Available() { - logger.LogIf(context.Background(), errBitrotHashAlgoInvalid) + logger.LogIf(GlobalContext, errBitrotHashAlgoInvalid) return errBitrotHashAlgoInvalid } return nil diff --git a/cmd/xl-v1-metadata_test.go b/cmd/xl-v1-metadata_test.go index 5cdc850c1..fad2cd3cb 100644 --- a/cmd/xl-v1-metadata_test.go +++ b/cmd/xl-v1-metadata_test.go @@ -17,7 +17,6 @@ package cmd import ( - "context" "testing" "time" @@ -136,7 +135,7 @@ func TestObjectToPartOffset(t *testing.T) { // Test them. for _, testCase := range testCases { - index, offset, err := xlMeta.ObjectToPartOffset(context.Background(), testCase.offset) + index, offset, err := xlMeta.ObjectToPartOffset(GlobalContext, testCase.offset) if err != testCase.expectedErr { t.Fatalf("%+v: expected = %s, got: %s", testCase, testCase.expectedErr, err) } @@ -192,7 +191,7 @@ func TestPickValidXLMeta(t *testing.T) { }, } for i, test := range testCases { - xlMeta, err := pickValidXLMeta(context.Background(), test.metaArr, test.modTime, len(test.metaArr)/2) + xlMeta, err := pickValidXLMeta(GlobalContext, test.metaArr, test.modTime, len(test.metaArr)/2) if test.expectedErr != nil { if err.Error() != test.expectedErr.Error() { t.Errorf("Test %d: Expected to fail with %v but received %v", diff --git a/cmd/xl-v1-multipart_test.go b/cmd/xl-v1-multipart_test.go index 402d626a3..c6a4aba3a 100644 --- a/cmd/xl-v1-multipart_test.go +++ b/cmd/xl-v1-multipart_test.go @@ -40,20 +40,20 @@ func TestXLCleanupStaleMultipartUploads(t *testing.T) { objectName := "object" var opts ObjectOptions - obj.MakeBucketWithLocation(context.Background(), bucketName, "") - uploadID, err := obj.NewMultipartUpload(context.Background(), bucketName, objectName, opts) + obj.MakeBucketWithLocation(GlobalContext, bucketName, "") + uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, opts) if err != nil { t.Fatal("Unexpected err: ", err) } // Create a context we can cancel. - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(GlobalContext) var cleanupWg sync.WaitGroup cleanupWg.Add(1) go func() { defer cleanupWg.Done() - xl.cleanupStaleMultipartUploads(context.Background(), time.Millisecond, 0, ctx.Done()) + xl.cleanupStaleMultipartUploads(GlobalContext, time.Millisecond, 0, ctx.Done()) }() // Wait for 100ms such that - we have given enough time for cleanup routine to kick in. @@ -65,7 +65,7 @@ func TestXLCleanupStaleMultipartUploads(t *testing.T) { cleanupWg.Wait() // Check if upload id was already purged. - if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil { + if err = obj.AbortMultipartUpload(GlobalContext, bucketName, objectName, uploadID); err != nil { if _, ok := err.(InvalidUploadID); !ok { t.Fatal("Unexpected err: ", err) } diff --git a/cmd/xl-v1-object_test.go b/cmd/xl-v1-object_test.go index 6a4120620..fc61d4520 100644 --- a/cmd/xl-v1-object_test.go +++ b/cmd/xl-v1-object_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "io/ioutil" "math/rand" "os" @@ -46,23 +45,23 @@ func TestRepeatPutObjectPart(t *testing.T) { // cleaning up of temporary test directories defer removeRoots(disks) - err = objLayer.MakeBucketWithLocation(context.Background(), "bucket1", "") + err = objLayer.MakeBucketWithLocation(GlobalContext, "bucket1", "") if err != nil { t.Fatal(err) } - uploadID, err := objLayer.NewMultipartUpload(context.Background(), "bucket1", "mpartObj1", opts) + uploadID, err := objLayer.NewMultipartUpload(GlobalContext, "bucket1", "mpartObj1", opts) if err != nil { t.Fatal(err) } fiveMBBytes := bytes.Repeat([]byte("a"), 5*humanize.MiByte) md5Hex := getMD5Hash(fiveMBBytes) - _, err = objLayer.PutObjectPart(context.Background(), "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts) + _, err = objLayer.PutObjectPart(GlobalContext, "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts) if err != nil { t.Fatal(err) } // PutObjectPart should succeed even if part already exists. ref: https://github.com/minio/minio/issues/1930 - _, err = objLayer.PutObjectPart(context.Background(), "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts) + _, err = objLayer.PutObjectPart(GlobalContext, "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts) if err != nil { t.Fatal(err) } @@ -90,18 +89,18 @@ func TestXLDeleteObjectBasic(t *testing.T) { t.Fatal(err) } - err = xl.MakeBucketWithLocation(context.Background(), "bucket", "") + err = xl.MakeBucketWithLocation(GlobalContext, "bucket", "") if err != nil { t.Fatal(err) } // Create object "dir/obj" under bucket "bucket" for Test 7 to pass - _, err = xl.PutObject(context.Background(), "bucket", "dir/obj", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) + _, err = xl.PutObject(GlobalContext, "bucket", "dir/obj", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) if err != nil { t.Fatalf("XL Object upload failed: %s", err) } for i, test := range testCases { - actualErr := xl.DeleteObject(context.Background(), test.bucket, test.object) + actualErr := xl.DeleteObject(GlobalContext, test.bucket, test.object) if test.expectedErr != nil && actualErr != test.expectedErr { t.Errorf("Test %d: Expected to fail with %s, but failed with %s", i+1, test.expectedErr, actualErr) } @@ -145,13 +144,13 @@ func TestXLDeleteObjectsXLSet(t *testing.T) { {bucketName, "obj_4"}, } - err := xlSets.MakeBucketWithLocation(context.Background(), bucketName, "") + err := xlSets.MakeBucketWithLocation(GlobalContext, bucketName, "") if err != nil { t.Fatal(err) } for _, testCase := range testCases { - _, err = xlSets.PutObject(context.Background(), testCase.bucket, testCase.object, + _, err = xlSets.PutObject(GlobalContext, testCase.bucket, testCase.object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{}) if err != nil { t.Fatalf("XL Object upload failed: %s", err) @@ -167,7 +166,7 @@ func TestXLDeleteObjectsXLSet(t *testing.T) { } objectNames := toObjectNames(testCases) - delErrs, err := xlSets.DeleteObjects(context.Background(), bucketName, objectNames) + delErrs, err := xlSets.DeleteObjects(GlobalContext, bucketName, objectNames) if err != nil { t.Errorf("Failed to call DeleteObjects with the error: `%v`", err) } @@ -179,7 +178,7 @@ func TestXLDeleteObjectsXLSet(t *testing.T) { } for _, test := range testCases { - _, statErr := xlSets.GetObjectInfo(context.Background(), test.bucket, test.object, ObjectOptions{}) + _, statErr := xlSets.GetObjectInfo(GlobalContext, test.bucket, test.object, ObjectOptions{}) switch statErr.(type) { case ObjectNotFound: default: @@ -201,7 +200,7 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) { xl := z.zones[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(context.Background(), "bucket", "") + err = obj.MakeBucketWithLocation(GlobalContext, "bucket", "") if err != nil { t.Fatal(err) } @@ -210,7 +209,7 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) { object := "object" opts := ObjectOptions{} // Create object "obj" under bucket "bucket". - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) if err != nil { t.Fatal(err) } @@ -225,13 +224,13 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) { return xlDisks } z.zones[0].xlDisksMu.Unlock() - err = obj.DeleteObject(context.Background(), bucket, object) + err = obj.DeleteObject(GlobalContext, bucket, object) if err != nil { t.Fatal(err) } // Create "obj" under "bucket". - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) if err != nil { t.Fatal(err) } @@ -245,7 +244,7 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) { return xlDisks } z.zones[0].xlDisksMu.Unlock() - err = obj.DeleteObject(context.Background(), bucket, object) + err = obj.DeleteObject(GlobalContext, bucket, object) // since majority of disks are not available, metaquorum is not achieved and hence errXLReadQuorum error if err != toObjectErr(errXLReadQuorum, bucket, object) { t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errXLReadQuorum, bucket, object), err) @@ -265,7 +264,7 @@ func TestGetObjectNoQuorum(t *testing.T) { xl := z.zones[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(context.Background(), "bucket", "") + err = obj.MakeBucketWithLocation(GlobalContext, "bucket", "") if err != nil { t.Fatal(err) } @@ -274,7 +273,7 @@ func TestGetObjectNoQuorum(t *testing.T) { object := "object" opts := ObjectOptions{} // Create "object" under "bucket". - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) if err != nil { t.Fatal(err) } @@ -303,7 +302,7 @@ func TestGetObjectNoQuorum(t *testing.T) { } z.zones[0].xlDisksMu.Unlock() // Fetch object from store. - err = xl.GetObject(context.Background(), bucket, object, 0, int64(len("abcd")), ioutil.Discard, "", opts) + err = xl.GetObject(GlobalContext, bucket, object, 0, int64(len("abcd")), ioutil.Discard, "", opts) if err != toObjectErr(errXLReadQuorum, bucket, object) { t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err) } @@ -324,7 +323,7 @@ func TestPutObjectNoQuorum(t *testing.T) { xl := z.zones[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(context.Background(), "bucket", "") + err = obj.MakeBucketWithLocation(GlobalContext, "bucket", "") if err != nil { t.Fatal(err) } @@ -333,7 +332,7 @@ func TestPutObjectNoQuorum(t *testing.T) { object := "object" opts := ObjectOptions{} // Create "object" under "bucket". - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) if err != nil { t.Fatal(err) } @@ -362,7 +361,7 @@ func TestPutObjectNoQuorum(t *testing.T) { } z.zones[0].xlDisksMu.Unlock() // Upload new content to same object "object" - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts) if err != toObjectErr(errXLWriteQuorum, bucket, object) { t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err) } @@ -381,7 +380,7 @@ func TestHealing(t *testing.T) { xl := z.zones[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(context.Background(), "bucket", "") + err = obj.MakeBucketWithLocation(GlobalContext, "bucket", "") if err != nil { t.Fatal(err) } @@ -396,13 +395,13 @@ func TestHealing(t *testing.T) { t.Fatal(err) } - _, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader(data), length, "", ""), ObjectOptions{}) + _, err = obj.PutObject(GlobalContext, bucket, object, mustGetPutObjReader(t, bytes.NewReader(data), length, "", ""), ObjectOptions{}) if err != nil { t.Fatal(err) } disk := xl.getDisks()[0] - xlMetaPreHeal, err := readXLMeta(context.Background(), disk, bucket, object) + xlMetaPreHeal, err := readXLMeta(GlobalContext, disk, bucket, object) if err != nil { t.Fatal(err) } @@ -414,12 +413,12 @@ func TestHealing(t *testing.T) { t.Fatal(err) } - _, err = xl.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) + _, err = xl.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan}) if err != nil { t.Fatal(err) } - xlMetaPostHeal, err := readXLMeta(context.Background(), disk, bucket, object) + xlMetaPostHeal, err := readXLMeta(GlobalContext, disk, bucket, object) if err != nil { t.Fatal(err) } @@ -438,17 +437,17 @@ func TestHealing(t *testing.T) { // gone down when an object was replaced by a new object. xlMetaOutDated := xlMetaPreHeal xlMetaOutDated.Stat.ModTime = time.Now() - err = writeXLMetadata(context.Background(), disk, bucket, object, xlMetaOutDated) + err = writeXLMetadata(GlobalContext, disk, bucket, object, xlMetaOutDated) if err != nil { t.Fatal(err) } - _, err = xl.HealObject(context.Background(), bucket, object, madmin.HealOpts{ScanMode: madmin.HealDeepScan}) + _, err = xl.HealObject(GlobalContext, bucket, object, madmin.HealOpts{ScanMode: madmin.HealDeepScan}) if err != nil { t.Fatal(err) } - xlMetaPostHeal, err = readXLMeta(context.Background(), disk, bucket, object) + xlMetaPostHeal, err = readXLMeta(GlobalContext, disk, bucket, object) if err != nil { t.Fatal(err) } @@ -465,7 +464,7 @@ func TestHealing(t *testing.T) { t.Fatal(err) } // This would create the bucket. - _, err = xl.HealBucket(context.Background(), bucket, false, false) + _, err = xl.HealBucket(GlobalContext, bucket, false, false) if err != nil { t.Fatal(err) } @@ -492,41 +491,41 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin xl := z.zones[0].sets[0] xlDisks := xl.getDisks() - err := obj.MakeBucketWithLocation(context.Background(), bucket, globalMinioDefaultRegion) + err := obj.MakeBucketWithLocation(GlobalContext, bucket, globalMinioDefaultRegion) if err != nil { t.Fatalf("Failed to make a bucket %v", err) } // Object for test case 1 - No StorageClass defined, no MetaData in PutObject object1 := "object1" - _, err = obj.PutObject(context.Background(), bucket, object1, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts) + _, err = obj.PutObject(GlobalContext, bucket, object1, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts1, errs1 := readAllXLMetadata(context.Background(), xlDisks, bucket, object1) + parts1, errs1 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object1) // Object for test case 2 - No StorageClass defined, MetaData in PutObject requesting RRS Class object2 := "object2" metadata2 := make(map[string]string) metadata2["x-amz-storage-class"] = storageclass.RRS - _, err = obj.PutObject(context.Background(), bucket, object2, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata2}) + _, err = obj.PutObject(GlobalContext, bucket, object2, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata2}) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts2, errs2 := readAllXLMetadata(context.Background(), xlDisks, bucket, object2) + parts2, errs2 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object2) // Object for test case 3 - No StorageClass defined, MetaData in PutObject requesting Standard Storage Class object3 := "object3" metadata3 := make(map[string]string) metadata3["x-amz-storage-class"] = storageclass.STANDARD - _, err = obj.PutObject(context.Background(), bucket, object3, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata3}) + _, err = obj.PutObject(GlobalContext, bucket, object3, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata3}) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts3, errs3 := readAllXLMetadata(context.Background(), xlDisks, bucket, object3) + parts3, errs3 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object3) // Object for test case 4 - Standard StorageClass defined as Parity 6, MetaData in PutObject requesting Standard Storage Class object4 := "object4" @@ -538,12 +537,12 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin }, } - _, err = obj.PutObject(context.Background(), bucket, object4, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata4}) + _, err = obj.PutObject(GlobalContext, bucket, object4, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata4}) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts4, errs4 := readAllXLMetadata(context.Background(), xlDisks, bucket, object4) + parts4, errs4 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object4) // Object for test case 5 - RRS StorageClass defined as Parity 2, MetaData in PutObject requesting RRS Class // Reset global storage class flags @@ -556,12 +555,12 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin }, } - _, err = obj.PutObject(context.Background(), bucket, object5, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata5}) + _, err = obj.PutObject(GlobalContext, bucket, object5, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata5}) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts5, errs5 := readAllXLMetadata(context.Background(), xlDisks, bucket, object5) + parts5, errs5 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object5) // Object for test case 6 - RRS StorageClass defined as Parity 2, MetaData in PutObject requesting Standard Storage Class object6 := "object6" @@ -573,12 +572,12 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin }, } - _, err = obj.PutObject(context.Background(), bucket, object6, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata6}) + _, err = obj.PutObject(GlobalContext, bucket, object6, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata6}) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts6, errs6 := readAllXLMetadata(context.Background(), xlDisks, bucket, object6) + parts6, errs6 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object6) // Object for test case 7 - Standard StorageClass defined as Parity 5, MetaData in PutObject requesting RRS Class // Reset global storage class flags @@ -591,12 +590,12 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin }, } - _, err = obj.PutObject(context.Background(), bucket, object7, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata7}) + _, err = obj.PutObject(GlobalContext, bucket, object7, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata7}) if err != nil { t.Fatalf("Failed to putObject %v", err) } - parts7, errs7 := readAllXLMetadata(context.Background(), xlDisks, bucket, object7) + parts7, errs7 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object7) tests := []struct { parts []xlMetaV1 @@ -614,7 +613,7 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin {parts7, errs7, 14, 15, nil}, } for i, tt := range tests { - actualReadQuorum, actualWriteQuorum, err := objectQuorumFromMeta(context.Background(), *xl, tt.parts, tt.errs) + actualReadQuorum, actualWriteQuorum, err := objectQuorumFromMeta(GlobalContext, *xl, tt.parts, tt.errs) if tt.expectedError != nil && err == nil { t.Errorf("Test %d, Expected %s, got %s", i+1, tt.expectedError, err) return diff --git a/cmd/xl-v1-utils.go b/cmd/xl-v1-utils.go index b62f24b1d..c77b2ed4e 100644 --- a/cmd/xl-v1-utils.go +++ b/cmd/xl-v1-utils.go @@ -195,7 +195,7 @@ func shuffleDisks(disks []StorageAPI, distribution []int) (shuffledDisks []Stora // the corresponding error in errs slice is not nil func evalDisks(disks []StorageAPI, errs []error) []StorageAPI { if len(errs) != len(disks) { - logger.LogIf(context.Background(), errors.New("unexpected disks/errors slice length")) + logger.LogIf(GlobalContext, errors.New("unexpected disks/errors slice length")) return nil } newDisks := make([]StorageAPI, len(disks)) diff --git a/cmd/xl-v1-utils_test.go b/cmd/xl-v1-utils_test.go index cb27a26b5..3b9e5209c 100644 --- a/cmd/xl-v1-utils_test.go +++ b/cmd/xl-v1-utils_test.go @@ -18,7 +18,6 @@ package cmd import ( "bytes" - "context" "encoding/hex" "encoding/json" "reflect" @@ -90,11 +89,11 @@ func TestReduceErrs(t *testing.T) { } // Validates list of all the testcases for returning valid errors. for i, testCase := range testCases { - gotErr := reduceReadQuorumErrs(context.Background(), testCase.errs, testCase.ignoredErrs, 5) + gotErr := reduceReadQuorumErrs(GlobalContext, testCase.errs, testCase.ignoredErrs, 5) if gotErr != testCase.err { t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr) } - gotNewErr := reduceWriteQuorumErrs(context.Background(), testCase.errs, testCase.ignoredErrs, 6) + gotNewErr := reduceWriteQuorumErrs(GlobalContext, testCase.errs, testCase.ignoredErrs, 6) if gotNewErr != errXLWriteQuorum { t.Errorf("Test %d : expected %s, got %s", i+1, errXLWriteQuorum, gotErr) } @@ -302,7 +301,7 @@ func TestGetXLMetaV1Jsoniter1(t *testing.T) { t.Errorf("Unmarshalling failed: %v", err) } - jsoniterXLMeta, err := xlMetaV1UnmarshalJSON(context.Background(), xlMetaJSON) + jsoniterXLMeta, err := xlMetaV1UnmarshalJSON(GlobalContext, xlMetaJSON) if err != nil { t.Errorf("jsoniter parsing of XLMeta failed: %v", err) } @@ -319,7 +318,7 @@ func TestGetXLMetaV1Jsoniter10(t *testing.T) { if err := json.Unmarshal(xlMetaJSON, &unMarshalXLMeta); err != nil { t.Errorf("Unmarshalling failed: %v", err) } - jsoniterXLMeta, err := xlMetaV1UnmarshalJSON(context.Background(), xlMetaJSON) + jsoniterXLMeta, err := xlMetaV1UnmarshalJSON(GlobalContext, xlMetaJSON) if err != nil { t.Errorf("jsoniter parsing of XLMeta failed: %v", err) } @@ -349,7 +348,7 @@ func TestGetPartSizeFromIdx(t *testing.T) { } for i, testCase := range testCases { - s, err := calculatePartSizeFromIdx(context.Background(), testCase.totalSize, testCase.partSize, testCase.partIndex) + s, err := calculatePartSizeFromIdx(GlobalContext, testCase.totalSize, testCase.partSize, testCase.partIndex) if err != nil { t.Errorf("Test %d: Expected to pass but failed. %s", i+1, err) } @@ -373,7 +372,7 @@ func TestGetPartSizeFromIdx(t *testing.T) { } for i, testCaseFailure := range testCasesFailure { - _, err := calculatePartSizeFromIdx(context.Background(), testCaseFailure.totalSize, testCaseFailure.partSize, testCaseFailure.partIndex) + _, err := calculatePartSizeFromIdx(GlobalContext, testCaseFailure.totalSize, testCaseFailure.partSize, testCaseFailure.partIndex) if err == nil { t.Errorf("Test %d: Expected to failed but passed. %s", i+1, err) } diff --git a/cmd/xl-v1.go b/cmd/xl-v1.go index 36718abcb..6bba669f0 100644 --- a/cmd/xl-v1.go +++ b/cmd/xl-v1.go @@ -108,7 +108,7 @@ func getDisksInfo(disks []StorageAPI, endpoints Endpoints) (disksInfo []DiskInfo return err } reqInfo := (&logger.ReqInfo{}).AppendTags("disk", disks[index].String()) - ctx := logger.SetReqInfo(context.Background(), reqInfo) + ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) } disksInfo[index] = info diff --git a/cmd/xl-zones.go b/cmd/xl-zones.go index 4e60c230a..ecde2a010 100644 --- a/cmd/xl-zones.go +++ b/cmd/xl-zones.go @@ -80,7 +80,7 @@ func newXLZones(endpointZones EndpointZones) (ObjectLayer, error) { } } if !z.SingleZone() { - z.quickHealBuckets(context.Background()) + z.quickHealBuckets(GlobalContext) } return z, nil } @@ -326,7 +326,7 @@ func undoMakeBucketZones(bucket string, zones []*xlSets, errs []error) { index := index g.Go(func() error { if errs[index] == nil { - return zones[index].DeleteBucket(context.Background(), bucket, false) + return zones[index].DeleteBucket(GlobalContext, bucket, false) } return nil }, index) @@ -1286,7 +1286,7 @@ func undoDeleteBucketZones(bucket string, zones []*xlSets, errs []error) { index := index g.Go(func() error { if errs[index] == nil { - return zones[index].MakeBucketWithLocation(context.Background(), bucket, "") + return zones[index].MakeBucketWithLocation(GlobalContext, bucket, "") } return nil }, index)