@@ -16,43 +16,74 @@ import (
16
16
17
17
// VolumeWipeTarget is a target for wiping a volume.
18
18
type VolumeWipeTarget struct {
19
- VolumeStatus * blockres.VolumeStatus
19
+ label string
20
+
21
+ parentDevName , devName string
20
22
}
21
23
22
- // GetLabel implements runtime.PartitionTarget.
23
- func (v * VolumeWipeTarget ) GetLabel () string {
24
- return v .VolumeStatus .Metadata ().ID ()
24
+ // VolumeWipeTargetFromVolumeStatus creates a new VolumeWipeTarget from a VolumeStatus.
25
+ func VolumeWipeTargetFromVolumeStatus (vs * blockres.VolumeStatus ) * VolumeWipeTarget {
26
+ parentDevName := vs .TypedSpec ().ParentLocation
27
+
28
+ if parentDevName == "" {
29
+ parentDevName = vs .TypedSpec ().Location
30
+ }
31
+
32
+ return & VolumeWipeTarget {
33
+ label : vs .Metadata ().ID (),
34
+ parentDevName : parentDevName ,
35
+ devName : vs .TypedSpec ().Location ,
36
+ }
25
37
}
26
38
27
- // Wipe implements runtime.PartitionTarget .
28
- func ( v * VolumeWipeTarget ) Wipe ( ctx context. Context , log func ( string , ... any )) error {
29
- parentDevName := v . VolumeStatus . TypedSpec ().ParentLocation
39
+ // VolumeWipeTargetFromDiscoveredVolume creates a new VolumeWipeTarget from a DiscoveredVolume .
40
+ func VolumeWipeTargetFromDiscoveredVolume ( dv * blockres. DiscoveredVolume ) * VolumeWipeTarget {
41
+ parentDevName := dv . TypedSpec ().ParentDevPath
30
42
31
43
if parentDevName == "" {
32
- parentDevName = v . VolumeStatus . TypedSpec ().Location
44
+ parentDevName = dv . TypedSpec ().DevPath
33
45
}
34
46
35
- parentBd , err := block .NewFromPath (parentDevName )
47
+ return & VolumeWipeTarget {
48
+ label : dv .TypedSpec ().PartitionLabel ,
49
+ parentDevName : parentDevName ,
50
+ devName : dv .TypedSpec ().DevPath ,
51
+ }
52
+ }
53
+
54
+ // GetLabel implements runtime.PartitionTarget.
55
+ func (v * VolumeWipeTarget ) GetLabel () string {
56
+ return v .label
57
+ }
58
+
59
+ // String implements runtime.PartitionTarget.
60
+ func (v * VolumeWipeTarget ) String () string {
61
+ return fmt .Sprintf ("%s:%s" , v .label , v .devName )
62
+ }
63
+
64
+ // Wipe implements runtime.PartitionTarget.
65
+ func (v * VolumeWipeTarget ) Wipe (ctx context.Context , log func (string , ... any )) error {
66
+ parentBd , err := block .NewFromPath (v .parentDevName )
36
67
if err != nil {
37
- return fmt .Errorf ("error opening block device %q: %w" , parentDevName , err )
68
+ return fmt .Errorf ("error opening block device %q: %w" , v . parentDevName , err )
38
69
}
39
70
40
71
defer parentBd .Close () //nolint:errcheck
41
72
42
73
if err = parentBd .RetryLockWithTimeout (ctx , true , time .Minute ); err != nil {
43
- return fmt .Errorf ("error locking block device %q: %w" , parentDevName , err )
74
+ return fmt .Errorf ("error locking block device %q: %w" , v . parentDevName , err )
44
75
}
45
76
46
77
defer parentBd .Unlock () //nolint:errcheck
47
78
48
- bd , err := block .NewFromPath (v .VolumeStatus . TypedSpec (). Location , block .OpenForWrite ())
79
+ bd , err := block .NewFromPath (v .devName , block .OpenForWrite ())
49
80
if err != nil {
50
- return fmt .Errorf ("error opening block device %q: %w" , v .VolumeStatus . TypedSpec (). Location , err )
81
+ return fmt .Errorf ("error opening block device %q: %w" , v .devName , err )
51
82
}
52
83
53
84
defer bd .Close () //nolint:errcheck
54
85
55
- log ("wiping the volume %q (%s)" , v .GetLabel (), v .VolumeStatus . TypedSpec (). Location )
86
+ log ("wiping the volume %q (%s)" , v .GetLabel (), v .devName )
56
87
57
88
return bd .FastWipe ()
58
89
}
0 commit comments