diff options
Diffstat (limited to 'lib/btrfs')
-rw-r--r-- | lib/btrfs/btrfsvol/lvm.go | 20 | ||||
-rw-r--r-- | lib/btrfs/io1_pv.go | 24 | ||||
-rw-r--r-- | lib/btrfs/io2_lv.go | 13 |
3 files changed, 21 insertions, 36 deletions
diff --git a/lib/btrfs/btrfsvol/lvm.go b/lib/btrfs/btrfsvol/lvm.go index 4d40ccd..149c8cd 100644 --- a/lib/btrfs/btrfsvol/lvm.go +++ b/lib/btrfs/btrfsvol/lvm.go @@ -10,6 +10,8 @@ import ( "os" "reflect" + "github.com/datawire/dlib/derror" + "git.lukeshu.com/btrfs-progs-ng/lib/containers" "git.lukeshu.com/btrfs-progs-ng/lib/diskio" ) @@ -58,15 +60,27 @@ func (lv *LogicalVolume[PhysicalVolume]) Name() string { return lv.name } -func (lv *LogicalVolume[PhysicalVolume]) Size() (LogicalAddr, error) { +func (lv *LogicalVolume[PhysicalVolume]) Size() LogicalAddr { lv.init() lastChunk := lv.logical2physical.Max() if lastChunk == nil { - return 0, nil + return 0 } - return lastChunk.Value.LAddr.Add(lastChunk.Value.Size), nil + return lastChunk.Value.LAddr.Add(lastChunk.Value.Size) } +func (lv *LogicalVolume[PhysicalVolume]) Close() error { + var errs derror.MultiError + for _, dev := range lv.id2pv { + if err := dev.Close(); err != nil && err == nil { + errs = append(errs, err) + } + } + if errs != nil { + return errs + } + return nil +} func (lv *LogicalVolume[PhysicalVolume]) AddPhysicalVolume(id DeviceID, dev PhysicalVolume) error { lv.init() if other, exists := lv.id2pv[id]; exists { diff --git a/lib/btrfs/io1_pv.go b/lib/btrfs/io1_pv.go index 10b6e32..df31671 100644 --- a/lib/btrfs/io1_pv.go +++ b/lib/btrfs/io1_pv.go @@ -6,7 +6,6 @@ package btrfs import ( "fmt" - "os" "git.lukeshu.com/btrfs-progs-ng/lib/binstruct" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" @@ -14,7 +13,7 @@ import ( ) type Device struct { - *os.File + diskio.File[btrfsvol.PhysicalAddr] cacheSuperblocks []*diskio.Ref[btrfsvol.PhysicalAddr, Superblock] cacheSuperblock *Superblock @@ -22,22 +21,6 @@ type Device struct { var _ diskio.File[btrfsvol.PhysicalAddr] = (*Device)(nil) -func (dev Device) Size() (btrfsvol.PhysicalAddr, error) { - fi, err := dev.Stat() - if err != nil { - return 0, err - } - return btrfsvol.PhysicalAddr(fi.Size()), nil -} - -func (dev *Device) ReadAt(dat []byte, paddr btrfsvol.PhysicalAddr) (int, error) { - return dev.File.ReadAt(dat, int64(paddr)) -} - -func (dev *Device) WriteAt(dat []byte, paddr btrfsvol.PhysicalAddr) (int, error) { - return dev.File.WriteAt(dat, int64(paddr)) -} - var SuperblockAddrs = []btrfsvol.PhysicalAddr{ 0x00_0001_0000, // 64KiB 0x00_0400_0000, // 64MiB @@ -50,10 +33,7 @@ func (dev *Device) Superblocks() ([]*diskio.Ref[btrfsvol.PhysicalAddr, Superbloc } superblockSize := btrfsvol.PhysicalAddr(binstruct.StaticSize(Superblock{})) - sz, err := dev.Size() - if err != nil { - return nil, err - } + sz := dev.Size() var ret []*diskio.Ref[btrfsvol.PhysicalAddr, Superblock] for i, addr := range SuperblockAddrs { diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go index 47ab474..9316e27 100644 --- a/lib/btrfs/io2_lv.go +++ b/lib/btrfs/io2_lv.go @@ -57,7 +57,7 @@ func (fs *FS) Name() string { return name } -func (fs *FS) Size() (btrfsvol.LogicalAddr, error) { +func (fs *FS) Size() btrfsvol.LogicalAddr { return fs.LV.Size() } @@ -185,16 +185,7 @@ func (fs *FS) initDev(ctx context.Context, sb Superblock) error { } func (fs *FS) Close() error { - var errs derror.MultiError - for _, dev := range fs.LV.PhysicalVolumes() { - if err := dev.Close(); err != nil && err == nil { - errs = append(errs, err) - } - } - if errs != nil { - return errs - } - return nil + return fs.LV.Close() } var _ io.Closer = (*FS)(nil) |