-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add check of correct lv state of thin-pool when vg is already cr…
…eated
- Loading branch information
1 parent
172fdfe
commit d270241
Showing
7 changed files
with
632 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package vgmanager | ||
|
||
import "fmt" | ||
|
||
// LvAttr has mapped lv_attr information, see https://linux.die.net/man/8/lvs | ||
// It is a complete parsing of the entire attribute byte flags that is attached to each LV. | ||
// This is useful when attaching logic to the state of an LV as the state of an LV can be determined | ||
// from the Attributes, e.g. for determining wether an LV is considered a Thin-Pool or not. | ||
type LvAttr struct { | ||
VolumeType | ||
Permissions | ||
AllocationPolicy | ||
Minor | ||
State | ||
Open | ||
OpenTarget | ||
Zero | ||
Partial | ||
} | ||
|
||
func ParsedLvAttr(raw string) (LvAttr, error) { | ||
if len(raw) != 10 { | ||
return LvAttr{}, fmt.Errorf("%s is an invalid length lv_attr", raw) | ||
} | ||
return LvAttr{ | ||
VolumeType(raw[0]), | ||
Permissions(raw[1]), | ||
AllocationPolicy(raw[2]), | ||
Minor(raw[3]), | ||
State(raw[4]), | ||
Open(raw[5]), | ||
OpenTarget(raw[6]), | ||
Zero(raw[7]), | ||
Partial(raw[8]), | ||
}, nil | ||
} | ||
|
||
func (l LvAttr) String() string { | ||
return fmt.Sprintf( | ||
"%c%c%c%c%c%c%c%c%c", | ||
l.VolumeType, | ||
l.Permissions, | ||
l.AllocationPolicy, | ||
l.Minor, | ||
l.State, | ||
l.Open, | ||
l.OpenTarget, | ||
l.Zero, | ||
l.Partial, | ||
) | ||
} | ||
|
||
type VolumeType rune | ||
|
||
const ( | ||
VolumeTypeMirrored VolumeType = 'm' | ||
VolumeTypeMirroredNoInitialSync VolumeType = 'M' | ||
VolumeTypeOrigin VolumeType = 'o' | ||
VolumeTypeOriginWithMergingSnapshot VolumeType = 'O' | ||
VolumeTypeRAID VolumeType = 'r' | ||
VolumeTypeRAIDNoInitialSync VolumeType = 'R' | ||
VolumeTypeSnapshot VolumeType = 's' | ||
VolumeTypeMergingSnapshot VolumeType = 'S' | ||
VolumeTypePVMove VolumeType = 'p' | ||
VolumeTypeVirtual VolumeType = 'v' | ||
VolumeTypeMirrorOrRAIDImage VolumeType = 'i' | ||
VolumeTypeMirrorOrRAIDImageOutOfSync VolumeType = 'I' | ||
VolumeTypeMirrorLogDevice VolumeType = 'l' | ||
VolumeTypeUnderConversion VolumeType = 'c' | ||
VolumeTypeThinVolume VolumeType = 'V' | ||
VolumeTypeThinPool VolumeType = 't' | ||
VolumeTypeThinPoolData VolumeType = 'T' | ||
VolumeTypeThinPoolMetadata VolumeType = 'e' | ||
VolumeTypeNone VolumeType = '-' | ||
) | ||
|
||
type Permissions rune | ||
|
||
const ( | ||
PermissionsWriteable Permissions = 'w' | ||
PermissionsReadOnly Permissions = 'r' | ||
PermissionsReadOnlyActivationOfNonReadOnlyVolume Permissions = 'R' | ||
PermissionsNone Permissions = '-' | ||
) | ||
|
||
type AllocationPolicy rune | ||
|
||
const ( | ||
AllocationPolicyAnywhere AllocationPolicy = 'a' | ||
AllocationPolicyAnywhereLocked AllocationPolicy = 'A' | ||
AllocationPolicyContiguous AllocationPolicy = 'c' | ||
AllocationPolicyContiguousLocked AllocationPolicy = 'C' | ||
AllocationPolicyInherited AllocationPolicy = 'i' | ||
AllocationPolicyInheritedLocked AllocationPolicy = 'I' | ||
AllocationPolicyCling AllocationPolicy = 'l' | ||
AllocationPolicyClingLocked AllocationPolicy = 'L' | ||
AllocationPolicyNormal AllocationPolicy = 'n' | ||
AllocationPolicyNormalLocked AllocationPolicy = 'N' | ||
AllocationPolicyNone = '-' | ||
) | ||
|
||
type Minor rune | ||
|
||
const ( | ||
MinorTrue Minor = 'm' | ||
MinorFalse Minor = '-' | ||
) | ||
|
||
type State rune | ||
|
||
const ( | ||
StateActive State = 'a' | ||
StateSuspended = 's' | ||
StateInvalidSnapshot = 'I' | ||
StateSuspendedSnapshot = 'S' | ||
StateSnapshotMergeFailed = 'm' | ||
StateSuspendedSnapshotMergeFailed = 'M' | ||
StateMappedDevicePresentWithoutTables = 'd' | ||
StateMappedDevicePresentWithInactiveTables = 'i' | ||
StateNone = '-' | ||
) | ||
|
||
type Open rune | ||
|
||
const ( | ||
OpenTrue Open = 'o' | ||
OpenFalse Open = '-' | ||
) | ||
|
||
type OpenTarget rune | ||
|
||
const ( | ||
OpenTargetMirror = 'm' | ||
OpenTargetRaid = 'r' | ||
OpenTargetSnapshot = 's' | ||
OpenTargetThin = 't' | ||
OpenTargetUnknown = 'u' | ||
OpenTargetVirtual = 'v' | ||
) | ||
|
||
type Zero rune | ||
|
||
const ( | ||
ZeroTrue Zero = 'z' | ||
ZeroFalse Zero = '-' | ||
) | ||
|
||
type Partial rune | ||
|
||
const ( | ||
PartialTrue = 'p' | ||
PartialFalse = '-' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package vgmanager | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParsedLvAttr(t *testing.T) { | ||
type args struct { | ||
raw string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want LvAttr | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
"RAID Config without Initial Sync", | ||
args{raw: "Rwi-a-r---"}, | ||
LvAttr{ | ||
VolumeType: VolumeTypeRAIDNoInitialSync, | ||
Permissions: PermissionsWriteable, | ||
AllocationPolicy: AllocationPolicyInherited, | ||
Minor: MinorFalse, | ||
State: StateActive, | ||
Open: OpenFalse, | ||
OpenTarget: OpenTargetRaid, | ||
Zero: ZeroFalse, | ||
Partial: PartialFalse, | ||
}, | ||
assert.NoError, | ||
}, | ||
{ | ||
"ThinPool with Zeroing", | ||
args{raw: "twi-a-tz--"}, | ||
LvAttr{ | ||
VolumeType: VolumeTypeThinPool, | ||
Permissions: PermissionsWriteable, | ||
AllocationPolicy: AllocationPolicyInherited, | ||
Minor: MinorFalse, | ||
State: StateActive, | ||
Open: OpenFalse, | ||
OpenTarget: OpenTargetThin, | ||
Zero: ZeroTrue, | ||
Partial: PartialFalse, | ||
}, | ||
assert.NoError, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParsedLvAttr(tt.args.raw) | ||
if !tt.wantErr(t, err, fmt.Sprintf("ParsedLvAttr(%v)", tt.args.raw)) { | ||
return | ||
} | ||
assert.Equalf(t, tt.want, got, "ParsedLvAttr(%v)", tt.args.raw) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.