Skip to content

Commit 5232bd5

Browse files
committed
Fix existing VG not being activated
If the VG exists but has inactive LVs - we activate it explicitly.
1 parent 9799671 commit 5232bd5

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

pkg/lvm/lvm.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,27 @@ func VgExists(log *slog.Logger, vgname string) bool {
156156
return vgname == strings.TrimSpace(string(out))
157157
}
158158

159+
// VgIsActive reports whether the given volume group has all of its LVs activated.
160+
// A VG with no LVs is reported as active (nothing to activate).
161+
func VgIsActive(log *slog.Logger, vgname string) bool {
162+
cmd := exec.Command("lvs", vgname, "--noheadings", "-o", "lv_attr")
163+
out, err := cmd.CombinedOutput()
164+
if err != nil {
165+
log.Debug("unable to list logical volumes", "vgName", vgname, "error", err, "output", string(out))
166+
return false
167+
}
168+
for line := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") {
169+
attr := strings.TrimSpace(line)
170+
if attr == "" {
171+
continue
172+
}
173+
if len(attr) < 5 || attr[4] != 'a' {
174+
return false
175+
}
176+
}
177+
return true
178+
}
179+
159180
// VgActivate execute vgchange -ay to activate all volumes of the volume group
160181
func VgActivate(log *slog.Logger) {
161182
// TODO: this function is kind of best effort and does not return any errors and it's not clear if it worked or not

pkg/server/driver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ func NewDriver(log *slog.Logger, driverName, nodeId, endpoint string, hostWriteP
5555
log.Info("ensuring vg setup")
5656

5757
vgexists := lvm.VgExists(log, vgName)
58-
if !vgexists {
58+
if vgexists {
59+
if lvm.VgIsActive(log, vgName) {
60+
log.Info("vg already exists and is active", "vgName", vgName)
61+
} else {
62+
log.Info("vg already exists but is inactive, activating...", "vgName", vgName)
63+
lvm.VgActivate(log)
64+
}
65+
} else {
5966
log.Info("vg not found", "vgName", vgName)
6067
lvm.VgActivate(log)
6168
// now check again for existing vg again

0 commit comments

Comments
 (0)