Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ func VgExists(log *slog.Logger, vgname string) bool {
return vgname == strings.TrimSpace(string(out))
}

// VgIsActive reports whether the given volume group has all of its LVs activated.
// A VG with no LVs is reported as active (nothing to activate).
func VgIsActive(log *slog.Logger, vgname string) bool {
cmd := exec.Command("lvs", vgname, "--noheadings", "-o", "lv_attr")
out, err := cmd.CombinedOutput()
if err != nil {
log.Debug("unable to list logical volumes", "vgName", vgname, "error", err, "output", string(out))
return false
}
for line := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") {
attr := strings.TrimSpace(line)
if attr == "" {
continue
}
if len(attr) < 5 || attr[4] != 'a' {
return false
}
}
return true
}

// VgActivate execute vgchange -ay to activate all volumes of the volume group
func VgActivate(log *slog.Logger) {
// TODO: this function is kind of best effort and does not return any errors and it's not clear if it worked or not
Expand Down
9 changes: 8 additions & 1 deletion pkg/server/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ func NewDriver(log *slog.Logger, driverName, nodeId, endpoint string, hostWriteP
log.Info("ensuring vg setup")

vgexists := lvm.VgExists(log, vgName)
if !vgexists {
if vgexists {
if lvm.VgIsActive(log, vgName) {
log.Info("vg already exists and is active", "vgName", vgName)
} else {
log.Info("vg already exists but is inactive, activating...", "vgName", vgName)
lvm.VgActivate(log)
}
} else {
log.Info("vg not found", "vgName", vgName)
lvm.VgActivate(log)
// now check again for existing vg again
Expand Down
Loading