Skip to content

Commit

Permalink
lxd/storage/drivers/powerflex: Don't use nvme CLI to retrieve subsystems
Browse files Browse the repository at this point in the history
The output format of 'nvme list-subsys -o json' has changed between jammy and noble.
By using sysfs directly we are independent from future output changes

Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
  • Loading branch information
roosterfish committed Jun 21, 2024
1 parent 65de71d commit 65125ad
Showing 1 changed file with 15 additions and 17 deletions.
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

0 comments on commit 65125ad

Please sign in to comment.