Skip to content

Commit

Permalink
* fix lvm2 building
Browse files Browse the repository at this point in the history
* use 100%FREE vg space if get 0b for lv

Signed-off-by: walkerus <zfirewolfz@yandex.ru>
  • Loading branch information
walkerus committed Sep 13, 2023
1 parent 1d3d8cd commit f86d68f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
8 changes: 6 additions & 2 deletions actions/rootio/v1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ WORKDIR /dosfstools/
RUN ./autogen.sh; ./configure
RUN make LDFLAGS="--static"

# build lvm2 as static
FROM alpine as lvm
RUN apk update && apk add lvm2-static=2.03.21-r3

# Build final image
FROM alpine
RUN apk add lvm2
FROM scratch
COPY --from=mke2fs /e2fsprogs-1.45.6/misc/mke2fs.static /sbin/mke2fs
COPY --from=swap util-linux/swapon /sbin/swapon
COPY --from=swap util-linux/mkswap /sbin/mkswap
COPY --from=fattools dosfstools/src/mkfs.fat /sbin/mkfs.fat
COPY --from=lvm /usr/sbin/lvm.static /sbin/lvm
COPY --from=rootio /go/src/github.com/thebsdbox/rootio/rootio .
ENTRYPOINT ["/rootio"]
14 changes: 7 additions & 7 deletions actions/rootio/v1/cmd/rootio.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ var rootioPartition = &cobra.Command{
if err != nil {
log.Error(err)
}
}

if len(metadata.Instance.Storage.VolumeGroups) > 0 {
log.Infoln("Creating Volume Groups")
}
if len(metadata.Instance.Storage.VolumeGroups) > 0 {
log.Infoln("Creating Volume Groups")
}

for _, vg := range metadata.Instance.Storage.VolumeGroups {
if err := storage.CreateVolumeGroup(vg); err != nil {
log.Error(err)
}
for _, vg := range metadata.Instance.Storage.VolumeGroups {
if err := storage.CreateVolumeGroup(vg); err != nil {
log.Error(err)
}
}
},
Expand Down
26 changes: 16 additions & 10 deletions actions/rootio/v1/pkg/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type VolumeGroup struct {

// CreatePhysicalVolume creates a physical volume of the given device.
func CreatePhysicalVolume(dev string) error {
if err := run("pvcreate", dev); err != nil {
if err := run("lvm", "pvcreate", dev); err != nil {
return fmt.Errorf("lvm: CreatePhysicalVolume: %v", err)
}
return nil
Expand All @@ -30,22 +30,22 @@ func CreatePhysicalVolume(dev string) error {
// device at `dev` and adds it to the LVM metadata cache if `lvmetad`
// is running. If `dev` is an empty string, it scans all devices.
func PVScan(dev string) error {
args := []string{"--cache"}
args := []string{"pvscan", "--cache"}
if dev != "" {
args = append(args, dev)
}
return run("pvscan", args...)
return run("lvm", args...)
}

// VGScan runs the `vgscan --cache <name>` command. It scans for the
// volume group and adds it to the LVM metadata cache if `lvmetad`
// is running. If `name` is an empty string, it scans all volume groups.
func VGScan(name string) error {
args := []string{"--cache"}
args := []string{"vgscan", "--cache"}
if name != "" {
args = append(args, name)
}
return run("vgscan", args...)
return run("lvm", args...)
}

// ValidateVolumeGroupName validates a volume group name. A valid volume group
Expand Down Expand Up @@ -77,7 +77,7 @@ func ValidateTag(tag string) error {

// CreateVolumeGroup creates a new volume group.
func CreateVolumeGroup(name string, pvs []string, tags []string) (*VolumeGroup, error) {
var args []string
args := []string{"vgcreate"}

if err := ValidateVolumeGroupName(name); err != nil {
return nil, err
Expand All @@ -97,7 +97,7 @@ func CreateVolumeGroup(name string, pvs []string, tags []string) (*VolumeGroup,
args = append(args, pv)
}

if err := run("vgcreate", args...); err != nil {
if err := run("lvm", args...); err != nil {
return nil, err
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func (vg *VolumeGroup) CreateLogicalVolume(name string, sizeInBytes uint64, tags
}

// Validate the tag.
var args []string
args := []string{"lvcreate"}
for _, tag := range tags {
if tag != "" {
if err := ValidateTag(tag); err != nil {
Expand All @@ -146,12 +146,18 @@ func (vg *VolumeGroup) CreateLogicalVolume(name string, sizeInBytes uint64, tags
args = append(args, "--add-tag="+tag)
}
}
args = append(args, fmt.Sprintf("--size=%db", sizeInBytes))

if sizeInBytes == 0 {
args = append(args, "-l", "100%FREE")
} else {
args = append(args, fmt.Sprintf("--size=%db", sizeInBytes))
}

args = append(args, "--name="+name)
args = append(args, vg.name)
args = append(args, opts...)

if err := run("lvcreate", args...); err != nil {
if err := run("lvm", args...); err != nil {
if isInsufficientSpace(err) {
return fmt.Errorf("lvm: not enough free space")
}
Expand Down

0 comments on commit f86d68f

Please sign in to comment.