Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Sergunov <anton.sergunov@flant.com>
  • Loading branch information
asergunov committed Feb 26, 2025
1 parent 49b948f commit 0515f0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
5 changes: 2 additions & 3 deletions images/agent/src/internal/controller/llv/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ func (r *Reconciler) deleteLVIfNeeded(ctx context.Context, vgName string, llv *v
r.log.Warning(fmt.Sprintf("[deleteLVIfNeeded] did not find LV %s in VG %s", llv.Spec.ActualLVNameOnTheNode, vgName))
return false, nil
}
var poolLv *cache.LVData
var usedRanges *utils.RangeCover
if lv.Data.PoolName != "" {
poolMapper, poolMetadataMapper, err := r.sdsCache.FindThinPoolMappers(lv)
Expand All @@ -612,9 +611,9 @@ func (r *Reconciler) deleteLVIfNeeded(ctx context.Context, vgName string, llv *v
return false, err
}

ranges, err := utils.ThinVolumeUsedRanges(ctx, r.log, superblock, utils.LVMThinDeviceId(lv.Data.ThinId))
ranges, err := utils.ThinVolumeUsedRanges(ctx, r.log, superblock, utils.LVMThinDeviceID(lv.Data.ThinID))
if err != nil {
err = fmt.Errorf("finding used ranges for deviceId %d in thin pool %s", lv.Data.ThinId, lv.Data.PoolName)
err = fmt.Errorf("finding used ranges for deviceId %d in thin pool %s", lv.Data.ThinID, lv.Data.PoolName)
return false, err
}
usedRanges = &ranges
Expand Down
2 changes: 1 addition & 1 deletion images/agent/src/internal/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type LVData struct {
CopyPercent string `json:"copy_percent"`
ConvertLv string `json:"convert_lv"`
LvTags string `json:"lv_tags"`
ThinId uint64 `json:"thin_id"`
ThinID uint64 `json:"thin_id"`
MetadataLv string `json:"metadata_lv"`
LVDmPath string `json:"lv_dm_path"`
}
Expand Down
29 changes: 15 additions & 14 deletions images/agent/src/internal/utils/range_cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,31 @@ type Range struct {

type RangeCover []Range

func (rc RangeCover) Merged() (RangeCover, error) {
rcLen := len(rc)
func (cover RangeCover) Merged() (RangeCover, error) {
rcLen := len(cover)
if rcLen <= 1 {
return rc, nil
return cover, nil
}

sort.Slice(rc, func(i, j int) bool {
return rc[i].Start < rc[j].Start
sort.Slice(cover, func(i, j int) bool {
return cover[i].Start < cover[j].Start
})

for i, d := range rc[0 : rcLen-1] {
if d.Start+d.Count > rc[i+1].Start {
for i, d := range cover[0 : rcLen-1] {
if d.Start+d.Count > cover[i+1].Start {
return nil, fmt.Errorf("self overlapped range")
}
}

last := Range{Start: 0, Count: 0}
reduced := make(RangeCover, 0, len(rc))
for _, d := range rc {
if last.Count == 0 {
reduced := make(RangeCover, 0, len(cover))
for _, d := range cover {
switch last.Count {
case 0:
last = d
} else if d.Start == last.Start+last.Count {
case d.Start - last.Start:
last.Count += d.Count
} else {
default:
reduced = append(reduced, last)
last = d
}
Expand All @@ -63,8 +64,8 @@ func (rc RangeCover) Merged() (RangeCover, error) {
return reduced, nil
}

func (value Range) Multiplied(multiplier int64) Range {
return Range{Start: value.Start * multiplier, Count: value.Count * multiplier}
func (cover Range) Multiplied(multiplier int64) Range {
return Range{Start: cover.Start * multiplier, Count: cover.Count * multiplier}
}

func (cover RangeCover) Multiplied(multiplier int64) RangeCover {
Expand Down
18 changes: 10 additions & 8 deletions images/agent/src/internal/utils/thin_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ limitations under the License.
package utils

import (
"agent/internal/logger"
"context"
"encoding/xml"
"errors"
"fmt"

"agent/internal/logger"
)

type (
LVMTime = int64
LVMTransaction = int64
LVMThinDeviceId = int64
LVMThinDeviceID = int64
)

type Superblock struct {
XMLName xml.Name `xml:"superblock"`
Uuid string `xml:"uuid,attr"`
UUID string `xml:"uuid,attr"`
Time LVMTime `xml:"time,attr"`
Transaction LVMTransaction `xml:"transaction,attr"`
Flags int64 `xml:"flags,attr"`
Expand All @@ -44,7 +45,7 @@ type Superblock struct {

type Device struct {
XMLName xml.Name `xml:"device"`
DevId LVMThinDeviceId `xml:"dev_id,attr"`
DevID LVMThinDeviceID `xml:"dev_id,attr"`
MappedBlocks int64 `xml:"mapped_blocks,attr"`
Transaction LVMTransaction `xml:"transaction,attr"`
CreationTime LVMTime `xml:"creation_time,attr"`
Expand Down Expand Up @@ -87,10 +88,10 @@ func ThinDump(ctx context.Context, log logger.Logger, tpool, tmeta string) (supe
return superblock, nil
}

func ThinVolumeUsedRanges(ctx context.Context, log logger.Logger, superblock Superblock, deviceId LVMThinDeviceId) (ranges RangeCover, err error) {
log.Trace(fmt.Sprintf("[ThinVolumeUsedRanges] calling for deviceId %d", deviceId))
func ThinVolumeUsedRanges(_ context.Context, log logger.Logger, superblock Superblock, deviceID LVMThinDeviceID) (ranges RangeCover, err error) {
log.Trace(fmt.Sprintf("[ThinVolumeUsedRanges] calling for deviceId %d", deviceID))
for _, device := range superblock.Devices {
if device.DevId != deviceId {
if device.DevID != deviceID {
continue
}

Expand All @@ -104,9 +105,10 @@ func ThinVolumeUsedRanges(ctx context.Context, log logger.Logger, superblock Sup
ranges = append(ranges, Range{Start: mapping.DataBlock, Count: 1})
}

ranges, err := ranges.Merged()
ranges, err = ranges.Merged()
if err != nil {
err = fmt.Errorf("finding used ranges: %w", err)
return
}

return ranges.Multiplied(superblock.DataBlockSize), nil
Expand Down

0 comments on commit 0515f0e

Please sign in to comment.