osbuild2: deduplicate mkfsStages() function
Use a single GenMkfsStages() function from osbuild2 instead of implementing it multiple times in distros. Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
parent
3110ae4629
commit
86118960b9
5 changed files with 71 additions and 239 deletions
|
|
@ -5,7 +5,6 @@ import (
|
|||
"math/rand"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
|
@ -973,7 +972,7 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string) *o
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: filename})
|
||||
p.AddStage(osbuild.NewTruncateStage(&osbuild.TruncateStageOptions{Filename: filename, Size: fmt.Sprintf("%d", pt.Size)}))
|
||||
|
||||
for _, stage := range mkfsStages(&pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(&pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -1228,7 +1227,7 @@ func liveImagePipeline(inputPipelineName string, outputFilename string, pt *disk
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: outputFilename})
|
||||
p.AddStage(osbuild.NewSfdiskStage(sfOptions, loopback))
|
||||
|
||||
for _, stage := range mkfsStages(pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -1253,63 +1252,6 @@ func xzArchivePipeline(inputPipelineName, inputFilename, outputFilename string)
|
|||
return p
|
||||
}
|
||||
|
||||
// mkfsStages generates a list of org.osbuild.mkfs.* stages based on a
|
||||
// partition table description for a single device node
|
||||
func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild2.Stage {
|
||||
stages := make([]*osbuild2.Stage, 0, len(pt.Partitions))
|
||||
|
||||
// assume loopback device for simplicity since it's the only one currently supported
|
||||
// panic if the conversion fails
|
||||
devOptions, ok := device.Options.(*osbuild.LoopbackDeviceOptions)
|
||||
if !ok {
|
||||
panic("mkfsStages: failed to convert device options to loopback options")
|
||||
}
|
||||
|
||||
for _, p := range pt.Partitions {
|
||||
if p.Payload == nil {
|
||||
// no filesystem for partition (e.g., BIOS boot)
|
||||
continue
|
||||
}
|
||||
var stage *osbuild.Stage
|
||||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Payload.Type {
|
||||
case "xfs":
|
||||
options := &osbuild.MkfsXfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsXfsStage(options, stageDevice)
|
||||
case "vfat":
|
||||
options := &osbuild.MkfsFATStageOptions{
|
||||
VolID: strings.Replace(p.Payload.UUID, "-", "", -1),
|
||||
}
|
||||
stage = osbuild.NewMkfsFATStage(options, stageDevice)
|
||||
case "btrfs":
|
||||
options := &osbuild.MkfsBtrfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsBtrfsStage(options, stageDevice)
|
||||
case "ext4":
|
||||
options := &osbuild.MkfsExt4StageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsExt4Stage(options, stageDevice)
|
||||
default:
|
||||
panic("unknown fs type " + p.Type)
|
||||
}
|
||||
stages = append(stages, stage)
|
||||
}
|
||||
return stages
|
||||
}
|
||||
|
||||
func qemuPipeline(inputPipelineName, inputFilename, outputFilename, format, qcow2Compat string) *osbuild.Pipeline {
|
||||
p := new(osbuild.Pipeline)
|
||||
p.Name = format
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"math/rand"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
|
@ -711,7 +710,7 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string) *o
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: filename})
|
||||
p.AddStage(osbuild.NewTruncateStage(&osbuild.TruncateStageOptions{Filename: filename, Size: fmt.Sprintf("%d", pt.Size)}))
|
||||
|
||||
for _, stage := range mkfsStages(&pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(&pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -952,7 +951,7 @@ func liveImagePipeline(inputPipelineName string, outputFilename string, pt *disk
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: outputFilename})
|
||||
p.AddStage(osbuild.NewSfdiskStage(sfOptions, loopback))
|
||||
|
||||
for _, stage := range mkfsStages(pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -977,63 +976,6 @@ func xzArchivePipeline(inputPipelineName, inputFilename, outputFilename string)
|
|||
return p
|
||||
}
|
||||
|
||||
// mkfsStages generates a list of org.osbuild.mkfs.* stages based on a
|
||||
// partition table description for a single device node
|
||||
func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild.Stage {
|
||||
stages := make([]*osbuild.Stage, 0, len(pt.Partitions))
|
||||
|
||||
// assume loopback device for simplicity since it's the only one currently supported
|
||||
// panic if the conversion fails
|
||||
devOptions, ok := device.Options.(*osbuild.LoopbackDeviceOptions)
|
||||
if !ok {
|
||||
panic("mkfsStages: failed to convert device options to loopback options")
|
||||
}
|
||||
|
||||
for _, p := range pt.Partitions {
|
||||
if p.Payload == nil {
|
||||
// no filesystem for partition (e.g., BIOS boot)
|
||||
continue
|
||||
}
|
||||
var stage *osbuild.Stage
|
||||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Payload.Type {
|
||||
case "xfs":
|
||||
options := &osbuild.MkfsXfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsXfsStage(options, stageDevice)
|
||||
case "vfat":
|
||||
options := &osbuild.MkfsFATStageOptions{
|
||||
VolID: strings.Replace(p.Payload.UUID, "-", "", -1),
|
||||
}
|
||||
stage = osbuild.NewMkfsFATStage(options, stageDevice)
|
||||
case "btrfs":
|
||||
options := &osbuild.MkfsBtrfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsBtrfsStage(options, stageDevice)
|
||||
case "ext4":
|
||||
options := &osbuild.MkfsExt4StageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsExt4Stage(options, stageDevice)
|
||||
default:
|
||||
panic("unknown fs type " + p.Type)
|
||||
}
|
||||
stages = append(stages, stage)
|
||||
}
|
||||
return stages
|
||||
}
|
||||
|
||||
func qemuPipeline(inputPipelineName, inputFilename, outputFilename, format, qcow2Compat string) *osbuild.Pipeline {
|
||||
p := new(osbuild.Pipeline)
|
||||
p.Name = format
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"math/rand"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
|
@ -707,7 +706,7 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string, rn
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: filename})
|
||||
p.AddStage(osbuild.NewTruncateStage(&osbuild.TruncateStageOptions{Filename: filename, Size: fmt.Sprintf("%d", pt.Size)}))
|
||||
|
||||
for _, stage := range mkfsStages(&pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(&pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -948,7 +947,7 @@ func liveImagePipeline(inputPipelineName string, outputFilename string, pt *disk
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: outputFilename})
|
||||
p.AddStage(osbuild.NewSfdiskStage(sfOptions, loopback))
|
||||
|
||||
for _, stage := range mkfsStages(pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -973,63 +972,6 @@ func xzArchivePipeline(inputPipelineName, inputFilename, outputFilename string)
|
|||
return p
|
||||
}
|
||||
|
||||
// mkfsStages generates a list of org.osbuild.mkfs.* stages based on a
|
||||
// partition table description for a single device node
|
||||
func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild.Stage {
|
||||
stages := make([]*osbuild.Stage, 0, len(pt.Partitions))
|
||||
|
||||
// assume loopback device for simplicity since it's the only one currently supported
|
||||
// panic if the conversion fails
|
||||
devOptions, ok := device.Options.(*osbuild.LoopbackDeviceOptions)
|
||||
if !ok {
|
||||
panic("mkfsStages: failed to convert device options to loopback options")
|
||||
}
|
||||
|
||||
for _, p := range pt.Partitions {
|
||||
if p.Payload == nil {
|
||||
// no filesystem for partition (e.g., BIOS boot)
|
||||
continue
|
||||
}
|
||||
var stage *osbuild.Stage
|
||||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Payload.Type {
|
||||
case "xfs":
|
||||
options := &osbuild.MkfsXfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsXfsStage(options, stageDevice)
|
||||
case "vfat":
|
||||
options := &osbuild.MkfsFATStageOptions{
|
||||
VolID: strings.Replace(p.Payload.UUID, "-", "", -1),
|
||||
}
|
||||
stage = osbuild.NewMkfsFATStage(options, stageDevice)
|
||||
case "btrfs":
|
||||
options := &osbuild.MkfsBtrfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsBtrfsStage(options, stageDevice)
|
||||
case "ext4":
|
||||
options := &osbuild.MkfsExt4StageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsExt4Stage(options, stageDevice)
|
||||
default:
|
||||
panic("unknown fs type " + p.Type)
|
||||
}
|
||||
stages = append(stages, stage)
|
||||
}
|
||||
return stages
|
||||
}
|
||||
|
||||
func qemuPipeline(inputPipelineName, inputFilename, outputFilename, format, qcow2Compat string) *osbuild.Pipeline {
|
||||
p := new(osbuild.Pipeline)
|
||||
p.Name = format
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package rhel90beta
|
|||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
|
@ -1039,7 +1038,7 @@ func liveImagePipeline(inputPipelineName string, outputFilename string, pt *disk
|
|||
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: outputFilename})
|
||||
p.AddStage(osbuild.NewSfdiskStage(sfOptions, loopback))
|
||||
|
||||
for _, stage := range mkfsStages(pt, loopback) {
|
||||
for _, stage := range osbuild.GenMkfsStages(pt, loopback) {
|
||||
p.AddStage(stage)
|
||||
}
|
||||
|
||||
|
|
@ -1064,63 +1063,6 @@ func xzArchivePipeline(inputPipelineName, inputFilename, outputFilename string)
|
|||
return p
|
||||
}
|
||||
|
||||
// mkfsStages generates a list of org.osbuild.mkfs.* stages based on a
|
||||
// partition table description for a single device node
|
||||
func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild.Stage {
|
||||
stages := make([]*osbuild.Stage, 0, len(pt.Partitions))
|
||||
|
||||
// assume loopback device for simplicity since it's the only one currently supported
|
||||
// panic if the conversion fails
|
||||
devOptions, ok := device.Options.(*osbuild.LoopbackDeviceOptions)
|
||||
if !ok {
|
||||
panic("mkfsStages: failed to convert device options to loopback options")
|
||||
}
|
||||
|
||||
for _, p := range pt.Partitions {
|
||||
if p.Payload == nil {
|
||||
// no filesystem for partition (e.g., BIOS boot)
|
||||
continue
|
||||
}
|
||||
var stage *osbuild.Stage
|
||||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Payload.Type {
|
||||
case "xfs":
|
||||
options := &osbuild.MkfsXfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsXfsStage(options, stageDevice)
|
||||
case "vfat":
|
||||
options := &osbuild.MkfsFATStageOptions{
|
||||
VolID: strings.Replace(p.Payload.UUID, "-", "", -1),
|
||||
}
|
||||
stage = osbuild.NewMkfsFATStage(options, stageDevice)
|
||||
case "btrfs":
|
||||
options := &osbuild.MkfsBtrfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsBtrfsStage(options, stageDevice)
|
||||
case "ext4":
|
||||
options := &osbuild.MkfsExt4StageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = osbuild.NewMkfsExt4Stage(options, stageDevice)
|
||||
default:
|
||||
panic("unknown fs type " + p.Type)
|
||||
}
|
||||
stages = append(stages, stage)
|
||||
}
|
||||
return stages
|
||||
}
|
||||
|
||||
func qemuPipeline(inputPipelineName, inputFilename, outputFilename, format, qcow2Compat string) *osbuild.Pipeline {
|
||||
p := new(osbuild.Pipeline)
|
||||
p.Name = format
|
||||
|
|
|
|||
64
internal/osbuild2/mkfs_stage.go
Normal file
64
internal/osbuild2/mkfs_stage.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package osbuild2
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
)
|
||||
|
||||
// GenMkfsStages generates a list of org.mkfs.* stages based on a
|
||||
// partition table description for a single device node
|
||||
func GenMkfsStages(pt *disk.PartitionTable, device *Device) []*Stage {
|
||||
stages := make([]*Stage, 0, len(pt.Partitions))
|
||||
|
||||
// assume loopback device for simplicity since it's the only one currently supported
|
||||
// panic if the conversion fails
|
||||
devOptions, ok := device.Options.(*LoopbackDeviceOptions)
|
||||
if !ok {
|
||||
panic("GenMkfsStages: failed to convert device options to loopback options")
|
||||
}
|
||||
|
||||
for _, p := range pt.Partitions {
|
||||
if p.Payload == nil {
|
||||
// no filesystem for partition (e.g., BIOS boot)
|
||||
continue
|
||||
}
|
||||
var stage *Stage
|
||||
stageDevice := NewLoopbackDevice(
|
||||
&LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Payload.Type {
|
||||
case "xfs":
|
||||
options := &MkfsXfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = NewMkfsXfsStage(options, stageDevice)
|
||||
case "vfat":
|
||||
options := &MkfsFATStageOptions{
|
||||
VolID: strings.Replace(p.Payload.UUID, "-", "", -1),
|
||||
}
|
||||
stage = NewMkfsFATStage(options, stageDevice)
|
||||
case "btrfs":
|
||||
options := &MkfsBtrfsStageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = NewMkfsBtrfsStage(options, stageDevice)
|
||||
case "ext4":
|
||||
options := &MkfsExt4StageOptions{
|
||||
UUID: p.Payload.UUID,
|
||||
Label: p.Payload.Label,
|
||||
}
|
||||
stage = NewMkfsExt4Stage(options, stageDevice)
|
||||
default:
|
||||
panic("unknown fs type " + p.Type)
|
||||
}
|
||||
stages = append(stages, stage)
|
||||
}
|
||||
return stages
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue