Skip to content

Commit 4b09fda

Browse files
liuminjianliuminjian
andauthored
feat(crd): enhance the details stored on BD when the device has zpool (#643)
Signed-off-by: liuminjian <liuminjian@d-uni.com> Co-authored-by: liuminjian <liuminjian@chinatelecom.cn>
1 parent 2554170 commit 4b09fda

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

cmd/ndm_daemonset/controller/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const (
7373
NDMDeviceTypeKey = "ndm.io/blockdevice-type"
7474
// NDMManagedKey specifies blockdevice cr should be managed by ndm or not.
7575
NDMManagedKey = "ndm.io/managed"
76+
// NDMZpoolName specifies the zpool name
77+
NDMZpoolName = "ndm.io/zpool-name"
7678
)
7779

7880
const (

cmd/ndm_daemonset/probe/usedbyprobe.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ func (sp *usedbyProbe) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevi
129129

130130
// check for ZFS file system
131131
fstype := usedByProbe.BlkidIdentifier.GetOnDiskFileSystem()
132-
132+
zpool := usedByProbe.BlkidIdentifier.GetOnDiskLabel()
133133
if fstype == zfsFileSystemLabel {
134134
blockDevice.DevUse.InUse = true
135-
135+
blockDevice.FSInfo.FileSystem = zfsFileSystemLabel
136+
blockDevice.Labels[controller.NDMZpoolName] = zpool
136137
// the disk can either be in use by cstor or zfs local PV
137138
ok, err := isBlockDeviceInUseByKernel(blockDevice.DevPath)
138139

pkg/blkid/blkid.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
const (
3333
fsTypeIdentifier = "TYPE"
34+
labelIdentifier = "LABEL"
3435
)
3536

3637
type DeviceIdentifier struct {
@@ -40,17 +41,27 @@ type DeviceIdentifier struct {
4041
// GetOnDiskFileSystem returns the filesystem present on the disk by reading from the disk
4142
// using libblkid
4243
func (di *DeviceIdentifier) GetOnDiskFileSystem() string {
44+
return di.GetTagValue(fsTypeIdentifier)
45+
}
46+
47+
// GetOnDiskLabel returns the label present on the disk by reading from the disk
48+
// using libblkid
49+
func (di *DeviceIdentifier) GetOnDiskLabel() string {
50+
return di.GetTagValue(labelIdentifier)
51+
}
52+
53+
func (di *DeviceIdentifier) GetTagValue(tag string) string {
4354
var blkidType *C.char
44-
blkidType = C.CString(fsTypeIdentifier)
55+
blkidType = C.CString(tag)
4556
defer C.free(unsafe.Pointer(blkidType))
4657

4758
var device *C.char
4859
device = C.CString(di.DevPath)
4960
defer C.free(unsafe.Pointer(device))
5061

51-
var fstype *C.char
52-
fstype = C.blkid_get_tag_value(nil, blkidType, device)
53-
defer C.free(unsafe.Pointer(fstype))
62+
var tagValue *C.char
63+
tagValue = C.blkid_get_tag_value(nil, blkidType, device)
64+
defer C.free(unsafe.Pointer(tagValue))
5465

55-
return C.GoString(fstype)
66+
return C.GoString(tagValue)
5667
}

0 commit comments

Comments
 (0)