zfs: Allow space in dataset name
Signed-off-by: Mustafa Khafateh <m@khafateh.com>pull/3186/head
parent
49d177bf95
commit
f4b1f023d7
|
@ -0,0 +1,3 @@
|
|||
12 3 0x00 1 80 79205351707403 395818011156865
|
||||
nread nwritten reads writes wtime wlentime wupdate rtime rlentime rupdate wcnt rcnt
|
||||
1884160 3206144 22 132 7155162 104112268 79210489694949 24168078 104112268 79210489849220 0 0
|
|
@ -0,0 +1,9 @@
|
|||
23 1 0x01 7 2160 221578688875 6665999035587
|
||||
name type data
|
||||
dataset_name 7 pool1
|
||||
writes 4 0
|
||||
nwritten 4 0
|
||||
reads 4 0
|
||||
nread 4 0
|
||||
nunlinks 4 0
|
||||
nunlinked 4 0
|
|
@ -0,0 +1,9 @@
|
|||
24 1 0x01 7 2160 221611904716 7145015038451
|
||||
name type data
|
||||
dataset_name 7 pool1/dataset with space
|
||||
writes 4 4
|
||||
nwritten 4 12302
|
||||
reads 4 2
|
||||
nread 4 28
|
||||
nunlinks 4 3
|
||||
nunlinked 4 3
|
|
@ -0,0 +1 @@
|
|||
ONLINE
|
|
@ -301,7 +301,8 @@ func (c *zfsCollector) parsePoolObjsetFile(reader io.Reader, zpoolPath string, h
|
|||
parseLine := false
|
||||
var zpoolName, datasetName string
|
||||
for scanner.Scan() {
|
||||
parts := strings.Fields(scanner.Text())
|
||||
line := scanner.Text()
|
||||
parts := strings.Fields(line)
|
||||
|
||||
if !parseLine && len(parts) == 3 && parts[0] == "name" && parts[1] == "type" && parts[2] == "data" {
|
||||
parseLine = true
|
||||
|
@ -315,7 +316,7 @@ func (c *zfsCollector) parsePoolObjsetFile(reader io.Reader, zpoolPath string, h
|
|||
zpoolPathElements := strings.Split(zpoolPath, "/")
|
||||
pathLen := len(zpoolPathElements)
|
||||
zpoolName = zpoolPathElements[pathLen-2]
|
||||
datasetName = parts[2]
|
||||
datasetName = line[strings.Index(line, parts[2]):]
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -315,6 +315,55 @@ func TestZpoolParsing(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestZpoolObjsetParsingWithSpace(t *testing.T) {
|
||||
tests := []struct {
|
||||
path string
|
||||
expectedDataset string
|
||||
}{
|
||||
{
|
||||
path: "fixtures/proc/spl/kstat/zfs/pool1/objset-1",
|
||||
expectedDataset: "pool1",
|
||||
},
|
||||
{
|
||||
path: "fixtures/proc/spl/kstat/zfs/pool1/objset-2",
|
||||
expectedDataset: "pool1/dataset1",
|
||||
},
|
||||
{
|
||||
path: "fixtures/proc/spl/kstat/zfs/pool3/objset-1",
|
||||
expectedDataset: "pool1",
|
||||
},
|
||||
{
|
||||
path: "fixtures/proc/spl/kstat/zfs/pool3/objset-2",
|
||||
expectedDataset: "pool1/dataset with space",
|
||||
},
|
||||
}
|
||||
|
||||
c := zfsCollector{}
|
||||
|
||||
var handlerCalled bool
|
||||
for _, test := range tests {
|
||||
file, err := os.Open(test.path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
handlerCalled = false
|
||||
err = c.parsePoolObjsetFile(file, test.path, func(poolName string, datasetName string, s zfsSysctl, v uint64) {
|
||||
handlerCalled = true
|
||||
if test.expectedDataset != datasetName {
|
||||
t.Fatalf("Incorrectly parsed dataset name: expected: '%s', got: '%s'", test.expectedDataset, datasetName)
|
||||
}
|
||||
})
|
||||
file.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !handlerCalled {
|
||||
t.Fatalf("Zpool parsing handler was not called for '%s'", test.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestZpoolObjsetParsing(t *testing.T) {
|
||||
zpoolPaths, err := filepath.Glob("fixtures/proc/spl/kstat/zfs/*/objset-*")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue