@ -20,6 +20,7 @@ import (
"bytes"
"bytes"
"context"
"context"
"errors"
"errors"
"fmt"
"os"
"os"
"strings"
"strings"
"unicode/utf8"
"unicode/utf8"
@ -39,7 +40,6 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
// If its server mode or nas gateway, migrate the backend.
// If its server mode or nas gateway, migrate the backend.
doneCh := make ( chan struct { } )
doneCh := make ( chan struct { } )
defer close ( doneCh )
var encrypted bool
var encrypted bool
var err error
var err error
@ -48,17 +48,27 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
// the following reasons:
// the following reasons:
// - Read quorum is lost just after the initialization
// - Read quorum is lost just after the initialization
// of the object layer.
// of the object layer.
for range newRetryTimerSimple ( doneCh ) {
retryTimerCh := newRetryTimerSimple ( doneCh )
var stop bool
for ! stop {
select {
case <- retryTimerCh :
if encrypted , err = checkBackendEncrypted ( objAPI ) ; err != nil {
if encrypted , err = checkBackendEncrypted ( objAPI ) ; err != nil {
if err == errDiskNotFound ||
if err == errDiskNotFound ||
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) {
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) {
logger . Info ( "Waiting for config backend to be encrypted.." )
logger . Info ( "Waiting for config backend to be encrypted.." )
continue
continue
}
}
close ( doneCh )
return err
return err
}
}
break
stop = true
case <- globalOSSignalCh :
close ( doneCh )
return fmt . Errorf ( "Config encryption process stopped gracefully" )
}
}
}
close ( doneCh )
if encrypted {
if encrypted {
// backend is encrypted, but credentials are not specified
// backend is encrypted, but credentials are not specified
@ -83,11 +93,18 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
return err
return err
}
}
doneCh = make ( chan struct { } )
defer close ( doneCh )
retryTimerCh = newRetryTimerSimple ( doneCh )
// Migrating Config backend needs a retry mechanism for
// Migrating Config backend needs a retry mechanism for
// the following reasons:
// the following reasons:
// - Read quorum is lost just after the initialization
// - Read quorum is lost just after the initialization
// of the object layer.
// of the object layer.
for range newRetryTimerSimple ( doneCh ) {
for {
select {
case <- retryTimerCh :
// Migrate IAM configuration
// Migrate IAM configuration
if err = migrateConfigPrefixToEncrypted ( objAPI , activeCredOld , encrypted ) ; err != nil {
if err = migrateConfigPrefixToEncrypted ( objAPI , activeCredOld , encrypted ) ; err != nil {
if err == errDiskNotFound ||
if err == errDiskNotFound ||
@ -98,9 +115,11 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
}
}
return err
return err
}
}
break
}
return nil
return nil
case <- globalOSSignalCh :
return fmt . Errorf ( "Config encryption process stopped gracefully" )
}
}
}
}
const (
const (