From 47bb1633115bc0368d1fcdcccbe4db7337b24560 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 13 Sep 2023 22:15:39 +0300 Subject: [PATCH] node: don't mkdir random paths from configuration Unbreak peapods: 2023/09/13 18:50:36 open shard S4wpuCnzpWW7SbwhER3U1v: could not open *blobstor.BlobStor: open substorage peapod: open BoltDB instance: open /storage/peapod0.db: is a directory Call `stat()` gently instead walking up. FS mount point has to exist there in any event and we should have some access to it. The real problem is that #2462 (introducing Peapod) was correct on its own. And #2495 (introducing capacity) was also correct on its own. But they don't work together. Refs 7c543077055000805b023971e3cf80fa3b392cdd. Refs c060b16fca8c29728f99747b27b91ec1e75989d1. util.MkdirAllX will be removed from code in most of the cases. Signed-off-by: Roman Khimov --- CHANGELOG.md | 1 + cmd/neofs-node/config.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a95bbdd478..4b6f9d1825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog for NeoFS Node ## [Unreleased] ### Fixed +- Inability to start node with peapods configured (#2576) ### Removed diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 219398cdb2..d45a0a0c91 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -4,9 +4,11 @@ import ( "context" "errors" "fmt" + "io/fs" "net" "os" "os/signal" + "path/filepath" "sync" atomicstd "sync/atomic" "syscall" @@ -932,12 +934,19 @@ func writeSystemAttributes(c *cfg) error { for _, sh := range c.applicationConfiguration.EngineCfg.shards { for _, subStorage := range sh.SubStorages { path := subStorage.Path - paths = append(paths, path) - err := util.MkdirAllX(path, subStorage.Perm) - if err != nil { - return fmt.Errorf("can not create (ensure it exists) dir by '%s' path: %w", path, err) + for len(path) > 1 { // Dir returns / or . if nothing else left. + fi, err := os.Stat(path) + if err == nil && fi.IsDir() { + break + } + if err != nil && !errors.Is(err, fs.ErrNotExist) { + return fmt.Errorf("accessing %q: %w", path, err) + } + path = filepath.Dir(path) } + + paths = append(paths, path) } }