@ -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 )
if encrypted , err = checkBackendEncrypted ( objAPI ) ; err != nil {
var stop bool
if err == errDiskNotFound ||
for ! stop {
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) {
select {
logger . Info ( "Waiting for config backend to be encrypted.." )
case <- retryTimerCh :
continue
if encrypted , err = checkBackendEncrypted ( objAPI ) ; err != nil {
if err == errDiskNotFound ||
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) {
logger . Info ( "Waiting for config backend to be encrypted.." )
continue
}
close ( doneCh )
return err
}
}
return err
stop = true
case <- globalOSSignalCh :
close ( doneCh )
return fmt . Errorf ( "Config encryption process stopped gracefully" )
}
}
break
}
}
close ( doneCh )
if encrypted {
if encrypted {
// backend is encrypted, but credentials are not specified
// backend is encrypted, but credentials are not specified
@ -83,24 +93,33 @@ 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 {
// Migrate IAM configuration
select {
if err = migrateConfigPrefixToEncrypted ( objAPI , activeCredOld , encrypted ) ; err != nil {
case <- retryTimerCh :
if err == errDiskNotFound ||
// Migrate IAM configuration
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) ||
if err = migrateConfigPrefixToEncrypted ( objAPI , activeCredOld , encrypted ) ; err != nil {
strings . Contains ( err . Error ( ) , InsufficientWriteQuorum { } . Error ( ) ) {
if err == errDiskNotFound ||
logger . Info ( "Waiting for config backend to be encrypted.." )
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) ||
continue
strings . Contains ( err . Error ( ) , InsufficientWriteQuorum { } . Error ( ) ) {
logger . Info ( "Waiting for config backend to be encrypted.." )
continue
}
return err
}
}
return err
return nil
case <- globalOSSignalCh :
return fmt . Errorf ( "Config encryption process stopped gracefully" )
}
}
break
}
}
return nil
}
}
const (
const (