Skip to content

Commit

Permalink
force make filesystem on a device (#935)
Browse files Browse the repository at this point in the history
* force make filesystem on a device
  • Loading branch information
DylanVerstraete authored Sep 14, 2020
1 parent 294a0b6 commit 2264806
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/storage/filesystem/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func NewBtrfs(manager DeviceManager) Filesystem {
}

func (b *btrfs) Create(ctx context.Context, name string, policy pkg.RaidProfile, devices ...*Device) (Pool, error) {
return b.create(ctx, name, policy, false, devices)
}

func (b *btrfs) CreateForce(ctx context.Context, name string, policy pkg.RaidProfile, devices ...*Device) (Pool, error) {
return b.create(ctx, name, policy, true, devices)
}

func (b *btrfs) create(ctx context.Context, name string, policy pkg.RaidProfile, force bool, devices []*Device) (Pool, error) {
name = strings.TrimSpace(name)
if len(name) == 0 {
return nil, fmt.Errorf("invalid name")
Expand Down Expand Up @@ -83,6 +91,10 @@ func (b *btrfs) Create(ctx context.Context, name string, policy pkg.RaidProfile,
"-m", string(policy),
}

if force {
args = append(args, "-f")
}

args = append(args, paths...)
if _, err := b.utils.run(ctx, "mkfs.btrfs", args...); err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type Filesystem interface {
// devices: list of devices to use in the filesystem
// profile: Raid profile of the filesystem
Create(ctx context.Context, name string, profile pkg.RaidProfile, devices ...*Device) (Pool, error)

// CreateForce creates a new filesystem with force
// It will delete existing data and partition tables
CreateForce(ctx context.Context, name string, profile pkg.RaidProfile, devices ...*Device) (Pool, error)
// List all existing filesystems on the node
List(ctx context.Context, filter Filter) ([]Pool, error)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (s *storageModule) initialize(policy pkg.StoragePolicy) error {
poolDevices = append(poolDevices, &fdisks[idx][i*int(policy.Disks)+j])
}

pool, err := fs.Create(ctx, uuid.New().String(), policy.Raid, poolDevices...)
pool, err := fs.CreateForce(ctx, uuid.New().String(), policy.Raid, poolDevices...)
if err != nil {
log.Info().Err(err).Msg("create filesystem")

Expand Down

0 comments on commit 2264806

Please sign in to comment.