Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: Don't use nvme CLI to retrieve subsystems #13647

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
32 changes: 15 additions & 17 deletions lxd/storage/drivers/driver_powerflex_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,31 +1077,29 @@ func (d *powerflex) unmapVolume(vol Volume) error {
// connectNVMeSubsys connects this host to the NVMe subsystem configured in the storage pool.
// The connection can only be established after the first volume is mapped to this host.
func (d *powerflex) connectNVMeSubsys() error {
stdout, err := shared.RunCommand("nvme", "list-subsys", "-o", "json")
pool, err := d.resolvePool()
if err != nil {
return fmt.Errorf("Failed getting list of NVMe/TCP subsystems: %w", err)
return err
}

var allSubSystems struct {
SubSystems []struct {
NQN string `json:"NQN"`
Paths []any `json:"Paths"`
} `json:"Subsystems"`
}
basePath := "/sys/devices/virtual/nvme-subsystem"

decoder := json.NewDecoder(strings.NewReader(stdout))
err = decoder.Decode(&allSubSystems)
// Retrieve list of existing NVMe subsystems on this host.
directories, err := os.ReadDir(basePath)
if err != nil {
return fmt.Errorf("Failed to parse list of NVMe/TCP subsystems: %w", err)
return fmt.Errorf("Failed getting a list of NVMe subsystems: %w", err)
}

pool, err := d.resolvePool()
if err != nil {
return err
}
for _, directory := range directories {
subsystemName := directory.Name()

// Get the subsystem's NQN.
nqnBytes, err := os.ReadFile(filepath.Join(basePath, subsystemName, "subsysnqn"))
if err != nil {
return fmt.Errorf("Failed getting the NQN of subystem %q: %w", subsystemName, err)
}

for _, subSystem := range allSubSystems.SubSystems {
if strings.Contains(subSystem.NQN, pool.ProtectionDomainID) {
if strings.Contains(string(nqnBytes), pool.ProtectionDomainID) {
// Already connected to the NVMe subsystem for the storage pools protection ID.
return nil
}
Expand Down
Loading