From b1e56562204b9bbc3be7b68516debec6b9c06c95 Mon Sep 17 00:00:00 2001 From: Surya Gupta Date: Thu, 16 Nov 2023 05:30:12 -0500 Subject: [PATCH 1/3] updated query mdm logic --- drv_cfg.go | 70 ++++++++++++------------------------------------------ 1 file changed, 15 insertions(+), 55 deletions(-) diff --git a/drv_cfg.go b/drv_cfg.go index 67e6015..7d96beb 100644 --- a/drv_cfg.go +++ b/drv_cfg.go @@ -15,6 +15,8 @@ package goscaleio import ( "fmt" "os" + "os/exec" + "regexp" "strconv" "strings" "syscall" @@ -34,6 +36,7 @@ const ( IOCTLDevice = "/dev/scini" mockGUID = "9E56672F-2F4B-4A42-BFF4-88B6846FBFDA" mockSystem = "14dbbf5617523654" + drvCfg = "/opt/emc/scaleio/sdc/bin/drv_cfg" ) var ( @@ -124,25 +127,6 @@ func DrvCfgQueryRescan() (string, error) { return rcCode, err } -// internal, opaque to us, struct of IP addresses -type netAddress struct { - opaque [24]byte -} - -type ioctlMdmInfo struct { - filler [4]byte - mdmIDL uint32 - mdmIDH uint32 - sdcIDL uint32 - sdcIDH uint32 - installIDL uint32 - installIDH uint32 - /*Total amount of socket addresses*/ - numSockAddrs uint64 - /*The MDM socket addresses*/ - addresses [16]netAddress -} - // ConfiguredCluster contains configuration information for one connected system type ConfiguredCluster struct { // SystemID is the MDM cluster system ID @@ -151,15 +135,6 @@ type ConfiguredCluster struct { SdcID string } -type ioctlQueryMDMs struct { - rc [8]byte - numMdms uint16 - - filler [4]byte //uint32 - /*Variable array of MDM. Its size is determined by numMdms*/ - mdms [20]ioctlMdmInfo -} - // DrvCfgQuerySystems will return the configured MDM endpoints for the locally installed SDC func DrvCfgQuerySystems() (*[]ConfiguredCluster, error) { clusters := make([]ConfiguredCluster, 0) @@ -175,38 +150,23 @@ func DrvCfgQuerySystems() (*[]ConfiguredCluster, error) { return &clusters, nil } - f, err := os.Open(SDCDevice) + cmd := exec.Command(drvCfg, "--query_mdm") + output, err := cmd.CombinedOutput() if err != nil { - return nil, err + return nil, fmt.Errorf("DrvCfgQuerySystems: Request to query MDM failed : %v", err) } - defer func() { - _ = f.Close() - }() - - opCode := _IO(_IOCTLBase, _IOCTLQueryMDM) - - buf := ioctlQueryMDMs{} - - buf.numMdms = uint16(len(buf.mdms)) - - // #nosec CWE-242, validated buffer is large enough to hold data - err = ioctl(f.Fd(), opCode, uintptr(unsafe.Pointer(&buf))) - - if err != nil { - return nil, fmt.Errorf("queryMDM error: %v", err) - } - - rc, err := strconv.ParseInt(hex.EncodeToString(buf.rc[0:1]), 16, 64) - if rc != 65 { - return nil, fmt.Errorf("Request to query MDM failed, RC=%d", rc) + // Parse the output to extract MDM information + re := regexp.MustCompile(`MDM-ID ([a-f0-9]+) SDC ID ([a-f0-9]+)`) + matches := re.FindAllStringSubmatch(string(output), -1) + if len(matches) == 0 { + return nil, fmt.Errorf("no MDM information found in drv_cfg output") } - for i := uint16(0); i < buf.numMdms; i++ { - systemID := fmt.Sprintf("%8.8x%8.8x", - buf.mdms[i].mdmIDH, buf.mdms[i].mdmIDL) - sdcID := fmt.Sprintf("%8.8x%8.8x", - buf.mdms[i].sdcIDH, buf.mdms[i].sdcIDL) + // Fetch the systemID and sdcID for each system + for _, match := range matches { + systemID := match[1] + sdcID := match[2] aCluster := ConfiguredCluster{ SystemID: systemID, SdcID: sdcID, From b024d38133ee517a7402a6d71d08a23ec8956abe Mon Sep 17 00:00:00 2001 From: Surya Gupta Date: Thu, 16 Nov 2023 07:06:17 -0500 Subject: [PATCH 2/3] run query_mdm cmd with chroot --- drv_cfg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drv_cfg.go b/drv_cfg.go index 7d96beb..ef779e9 100644 --- a/drv_cfg.go +++ b/drv_cfg.go @@ -150,7 +150,7 @@ func DrvCfgQuerySystems() (*[]ConfiguredCluster, error) { return &clusters, nil } - cmd := exec.Command(drvCfg, "--query_mdm") + cmd := exec.Command("chroot", "/noderoot", drvCfg, "--query_mdm") output, err := cmd.CombinedOutput() if err != nil { return nil, fmt.Errorf("DrvCfgQuerySystems: Request to query MDM failed : %v", err) From 3eb5d71ea4693454e61f6182c20e7090d55a5916 Mon Sep 17 00:00:00 2001 From: Surya Gupta Date: Fri, 17 Nov 2023 05:26:40 -0500 Subject: [PATCH 3/3] adding symlink --- inttests/drv_cfg_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inttests/drv_cfg_test.go b/inttests/drv_cfg_test.go index 2cf117a..b7956a6 100644 --- a/inttests/drv_cfg_test.go +++ b/inttests/drv_cfg_test.go @@ -55,6 +55,9 @@ func TestGetDrvCfgGUIDSDCNotInstalled(t *testing.T) { // TestGetSrvCfgSystems will return the PowerFlex systems connected to tyhe local SDC func TestGetDrvCfgSystems(t *testing.T) { goscaleio.SDCDevice = goscaleio.IOCTLDevice + // Adding symlink in order to run query_mdm cmd on the host and fetch the systems + os.Symlink("/", "/noderoot") + defer os.Remove("/noderoot") systems, err := goscaleio.DrvCfgQuerySystems() // The response depends on the installation state of the SDC