mirror of
https://github.com/minio/minio.git
synced 2025-04-20 10:37:31 -04:00
fix: log if there is readDir() failure with ListBuckets (#15461)
This is actionable and must be logged. Bonus: also honor umask by using 0o666 for all Open() syscalls.
This commit is contained in:
parent
2871cb5775
commit
3bd9615d0e
@ -110,7 +110,7 @@ func formatCacheGetVersion(r io.ReadSeeker) (string, error) {
|
|||||||
// Creates a new cache format.json if unformatted.
|
// Creates a new cache format.json if unformatted.
|
||||||
func createFormatCache(fsFormatPath string, format *formatCacheV1) error {
|
func createFormatCache(fsFormatPath string, format *formatCacheV1) error {
|
||||||
// open file using READ & WRITE permission
|
// open file using READ & WRITE permission
|
||||||
file, err := os.OpenFile(fsFormatPath, os.O_RDWR|os.O_CREATE, 0o600)
|
file, err := os.OpenFile(fsFormatPath, os.O_RDWR|os.O_CREATE, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ func loadFormatCache(ctx context.Context, drives []string) ([]*formatCacheV2, bo
|
|||||||
migrating := false
|
migrating := false
|
||||||
for i, drive := range drives {
|
for i, drive := range drives {
|
||||||
cacheFormatPath := pathJoin(drive, minioMetaBucket, formatConfigFile)
|
cacheFormatPath := pathJoin(drive, minioMetaBucket, formatConfigFile)
|
||||||
f, err := os.OpenFile(cacheFormatPath, os.O_RDWR, 0)
|
f, err := os.OpenFile(cacheFormatPath, os.O_RDWR, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if osIsNotExist(err) {
|
if osIsNotExist(err) {
|
||||||
continue
|
continue
|
||||||
@ -478,7 +478,7 @@ func migrateOldCache(ctx context.Context, c *diskCache) error {
|
|||||||
|
|
||||||
func migrateCacheFormatJSON(cacheFormatPath string) error {
|
func migrateCacheFormatJSON(cacheFormatPath string) error {
|
||||||
// now migrate format.json
|
// now migrate format.json
|
||||||
f, err := os.OpenFile(cacheFormatPath, os.O_RDWR, 0)
|
f, err := os.OpenFile(cacheFormatPath, os.O_RDWR, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func formatFSMigrate(ctx context.Context, wlk *lock.LockedFile, fsPath string) e
|
|||||||
func createFormatFS(fsFormatPath string) error {
|
func createFormatFS(fsFormatPath string) error {
|
||||||
// Attempt a write lock on formatConfigFile `format.json`
|
// Attempt a write lock on formatConfigFile `format.json`
|
||||||
// file stored in minioMetaBucket(.minio.sys) directory.
|
// file stored in minioMetaBucket(.minio.sys) directory.
|
||||||
lk, err := lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR|os.O_CREATE, 0o600)
|
lk, err := lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR|os.O_CREATE, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ func initFormatFS(ctx context.Context, fsPath string) (rlk *lock.RLockedFile, er
|
|||||||
// Hold write lock during migration so that we do not disturb any
|
// Hold write lock during migration so that we do not disturb any
|
||||||
// minio processes running in parallel.
|
// minio processes running in parallel.
|
||||||
var wlk *lock.LockedFile
|
var wlk *lock.LockedFile
|
||||||
wlk, err = lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0)
|
wlk, err = lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0o666)
|
||||||
if err == lock.ErrAlreadyLocked {
|
if err == lock.ErrAlreadyLocked {
|
||||||
// Lock already present, sleep and attempt again.
|
// Lock already present, sleep and attempt again.
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
@ -357,7 +357,7 @@ func formatFSFixDeploymentID(ctx context.Context, fsFormatPath string) error {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return fmt.Errorf("Initializing FS format stopped gracefully")
|
return fmt.Errorf("Initializing FS format stopped gracefully")
|
||||||
default:
|
default:
|
||||||
wlk, err = lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0)
|
wlk, err = lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0o666)
|
||||||
if err == lock.ErrAlreadyLocked {
|
if err == lock.ErrAlreadyLocked {
|
||||||
// Lock already present, sleep and attempt again
|
// Lock already present, sleep and attempt again
|
||||||
logger.Info("Another minio process(es) might be holding a lock to the file %s. Please kill that minio process(es) (elapsed %s)\n", fsFormatPath, getElapsedTime())
|
logger.Info("Another minio process(es) might be holding a lock to the file %s. Please kill that minio process(es) (elapsed %s)\n", fsFormatPath, getElapsedTime())
|
||||||
|
@ -517,7 +517,7 @@ func (fs *FSObjects) ListObjectParts(ctx context.Context, bucket, object, upload
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc, _, err := fsOpenFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile), 0)
|
rc, _, err := fsOpenFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile), 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == errFileNotFound || err == errFileAccessDenied {
|
if err == errFileNotFound || err == errFileAccessDenied {
|
||||||
return result, InvalidUploadID{Bucket: bucket, Object: object, UploadID: uploadID}
|
return result, InvalidUploadID{Bucket: bucket, Object: object, UploadID: uploadID}
|
||||||
|
@ -867,7 +867,7 @@ func (fs *FSObjects) getObjectInfoNoFSLock(ctx context.Context, bucket, object s
|
|||||||
// Read `fs.json` to perhaps contend with
|
// Read `fs.json` to perhaps contend with
|
||||||
// parallel Put() operations.
|
// parallel Put() operations.
|
||||||
|
|
||||||
rc, _, err := fsOpenFile(ctx, fsMetaPath, 0)
|
rc, _, err := fsOpenFile(ctx, fsMetaPath, 0o666)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fsMetaBuf, rerr := ioutil.ReadAll(rc)
|
fsMetaBuf, rerr := ioutil.ReadAll(rc)
|
||||||
rc.Close()
|
rc.Close()
|
||||||
|
@ -152,13 +152,25 @@ func parseDirEnt(buf []byte) (consumed int, name []byte, typ os.FileMode, err er
|
|||||||
// the directory itself, if the dirPath doesn't exist this function doesn't return
|
// the directory itself, if the dirPath doesn't exist this function doesn't return
|
||||||
// an error.
|
// an error.
|
||||||
func readDirFn(dirPath string, fn func(name string, typ os.FileMode) error) error {
|
func readDirFn(dirPath string, fn func(name string, typ os.FileMode) error) error {
|
||||||
f, err := Open(dirPath)
|
f, err := OpenFile(dirPath, readMode, 0o666)
|
||||||
|
if err != nil {
|
||||||
|
if osErrToFileErr(err) == errFileNotFound {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !osIsPermission(err) {
|
||||||
|
return osErrToFileErr(err)
|
||||||
|
}
|
||||||
|
// There may be permission error when dirPath
|
||||||
|
// is at the root of the disk mount that may
|
||||||
|
// not have the permissions to avoid 'noatime'
|
||||||
|
f, err = Open(dirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if osErrToFileErr(err) == errFileNotFound {
|
if osErrToFileErr(err) == errFileNotFound {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return osErrToFileErr(err)
|
return osErrToFileErr(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
bufp := direntPool.Get().(*[]byte)
|
bufp := direntPool.Get().(*[]byte)
|
||||||
@ -234,12 +246,14 @@ func readDirFn(dirPath string, fn func(name string, typ os.FileMode) error) erro
|
|||||||
func readDirWithOpts(dirPath string, opts readDirOpts) (entries []string, err error) {
|
func readDirWithOpts(dirPath string, opts readDirOpts) (entries []string, err error) {
|
||||||
f, err := OpenFile(dirPath, readMode, 0o666)
|
f, err := OpenFile(dirPath, readMode, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if osIsPermission(err) {
|
if !osIsPermission(err) {
|
||||||
f, err = Open(dirPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, osErrToFileErr(err)
|
return nil, osErrToFileErr(err)
|
||||||
}
|
}
|
||||||
} else {
|
// There may be permission error when dirPath
|
||||||
|
// is at the root of the disk mount that may
|
||||||
|
// not have the permissions to avoid 'noatime'
|
||||||
|
f, err = Open(dirPath)
|
||||||
|
if err != nil {
|
||||||
return nil, osErrToFileErr(err)
|
return nil, osErrToFileErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -751,19 +751,25 @@ func (s *xlStorage) MakeVol(ctx context.Context, volume string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListVols - list volumes.
|
// ListVols - list volumes.
|
||||||
func (s *xlStorage) ListVols(context.Context) (volsInfo []VolInfo, err error) {
|
func (s *xlStorage) ListVols(ctx context.Context) (volsInfo []VolInfo, err error) {
|
||||||
return listVols(s.diskPath)
|
return listVols(ctx, s.diskPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all the volumes from diskPath.
|
// List all the volumes from diskPath.
|
||||||
func listVols(dirPath string) ([]VolInfo, error) {
|
func listVols(ctx context.Context, dirPath string) ([]VolInfo, error) {
|
||||||
if err := checkPathLength(dirPath); err != nil {
|
if err := checkPathLength(dirPath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
entries, err := readDir(dirPath)
|
entries, err := readDir(dirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.LogIf(ctx, err)
|
||||||
|
if errors.Is(err, errFileAccessDenied) {
|
||||||
|
return nil, errDiskAccessDenied
|
||||||
|
} else if errors.Is(err, errFileNotFound) {
|
||||||
return nil, errDiskNotFound
|
return nil, errDiskNotFound
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
volsInfo := make([]VolInfo, 0, len(entries))
|
volsInfo := make([]VolInfo, 0, len(entries))
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if !HasSuffix(entry, SlashSeparator) || !isValidVolname(pathutil.Clean(entry)) {
|
if !HasSuffix(entry, SlashSeparator) || !isValidVolname(pathutil.Clean(entry)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user