Create single discoverer per mount type for CSV

Instead of creating a set of discoverers per file, this change creates
a discoverer per type by first concatenating the mount specifications
from all files. This will allow all device nodes, for example, to
be treated as a single device.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-06-16 14:17:53 +02:00
parent 88d1143827
commit 55cb82c6c8

View File

@ -47,23 +47,21 @@ func NewFromCSVFiles(logger *logrus.Logger, files []string, root string) (Discov
csv.MountSpecSym: symlinkLocator, csv.MountSpecSym: symlinkLocator,
} }
var discoverers []Discover var mountSpecs []*csv.MountSpec
for _, filename := range files { for _, filename := range files {
d, err := NewFromCSVFile(logger, locators, filename) targets, err := loadCSVFile(logger, filename)
if err != nil { if err != nil {
logger.Warnf("Skipping CSV file %v: %v", filename, err) logger.Warnf("Skipping CSV file %v: %v", filename, err)
continue continue
} }
discoverers = append(discoverers, d) mountSpecs = append(mountSpecs, targets...)
} }
return &list{discoverers: discoverers}, nil return newFromMountSpecs(logger, locators, mountSpecs)
} }
// NewFromCSVFile creates a discoverer for the specified CSV file. A logger is also supplied. // loadCSVFile
// The constructed discoverer is comprised of a list, with each element in the list being associated with a particular func loadCSVFile(logger *logrus.Logger, filename string) ([]*csv.MountSpec, error) {
// MountSpecType.
func NewFromCSVFile(logger *logrus.Logger, locators map[csv.MountSpecType]lookup.Locator, filename string) (Discover, error) {
// Create a discoverer for each file-kind combination // Create a discoverer for each file-kind combination
targets, err := csv.NewCSVFileParser(logger, filename).Parse() targets, err := csv.NewCSVFileParser(logger, filename).Parse()
if err != nil { if err != nil {
@ -73,7 +71,7 @@ func NewFromCSVFile(logger *logrus.Logger, locators map[csv.MountSpecType]lookup
return nil, fmt.Errorf("CSV file is empty") return nil, fmt.Errorf("CSV file is empty")
} }
return newFromMountSpecs(logger, locators, targets) return targets, nil
} }
// newFromMountSpecs creates a discoverer for the CSV file. A logger is also supplied. // newFromMountSpecs creates a discoverer for the CSV file. A logger is also supplied.