From 884b77211c3eb618cd377ea59d9ef6acbda09679 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 11 Apr 2023 20:01:40 +0300 Subject: [PATCH] uringstor: fixes Signed-off-by: Evgenii Stratonikov --- .../blobstor/uringstor/control.go | 41 +++++++++++++------ .../blobstor/uringstor/put.go | 25 ++++------- .../blobstor/uringstor/slab/backend.go | 9 +++- .../blobstor/uringstor/uring.go | 14 +++++++ .../blobstor/uringstor/util.go | 23 +++++++++++ 5 files changed, 82 insertions(+), 30 deletions(-) diff --git a/pkg/local_object_storage/blobstor/uringstor/control.go b/pkg/local_object_storage/blobstor/uringstor/control.go index d6903b5bf..c8a4d7ef4 100644 --- a/pkg/local_object_storage/blobstor/uringstor/control.go +++ b/pkg/local_object_storage/blobstor/uringstor/control.go @@ -1,6 +1,7 @@ package uringstor import ( + "math/bits" "os" "path/filepath" "strconv" @@ -20,11 +21,13 @@ type nameIDPair struct { func (s *Storage) Open(readOnly bool) error { s.readOnly = readOnly - lp, err := loop.New(s.loopSize, s.loopParams) - if err != nil { - return err + if s.loopSize != 0 { + lp, err := loop.New(s.loopSize, &s.loopParams) + if err != nil { + return err + } + s.loop = lp } - s.loop = lp if !readOnly { if err := util.MkdirAllX(s.path, os.ModePerm); err != nil { @@ -54,17 +57,14 @@ func (s *Storage) Open(readOnly bool) error { maxID := -1 for i := range ids { - b := slab.NewUringBackend(filepath.Join(s.path, ids[i].name), s.loop) - sl, err := slab.New(slab.Params{ - Backend: b, - ReadOnly: s.readOnly, - }) + slabPath := filepath.Join(s.path, ids[i].name) + sl, err := s.openSlab(slabPath, 0, 0) if err != nil { return err } slabID := ids[i].id - index := sl.ChunkSize() / uint32(s.minObjectSize) + index := bits.TrailingZeros32(sl.ChunkSize()) - bits.TrailingZeros32(uint32(s.minObjectSize)) s.slabIDs[index] = append(s.slabIDs[index], slabID) s.slabMap[slabID] = sl @@ -76,6 +76,21 @@ func (s *Storage) Open(readOnly bool) error { if maxID > 0 { s.nextID = uint16(maxID + 1) } + for i := range s.slabIDs { + if len(s.slabIDs[i]) != 0 { + continue + } + + slabPath := filepath.Join(s.path, strconv.FormatUint(uint64(s.nextID), idToStringBase)) + ss, err := s.openSlab(slabPath, uint32(s.minObjectSize<