diff --git a/csi/node.go b/csi/node.go index cd8c4a1b7..6deece075 100644 --- a/csi/node.go +++ b/csi/node.go @@ -364,8 +364,9 @@ func (s *OsdCsiServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetV } var attachPathMatch bool + sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id) for _, attachPath := range vol.AttachPath { - if attachPath == path { + if attachPath == path || attachPath == sharedPath { attachPathMatch = true } } diff --git a/csi/node_test.go b/csi/node_test.go index 52202f9d4..b3807a052 100644 --- a/csi/node_test.go +++ b/csi/node_test.go @@ -1067,8 +1067,9 @@ func TestNodeGetVolumeStats(t *testing.T) { used := int64(1 * 1024 * 1024) available := size - used id := "myvol123" + sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id) // "/var/lib/osd/pxns/myvol123" vol := &api.Volume{ - AttachPath: []string{"/test"}, + AttachPath: []string{"/test", sharedPath}, Id: id, Locator: &api.VolumeLocator{ Name: id, @@ -1104,6 +1105,18 @@ func TestNodeGetVolumeStats(t *testing.T) { assert.Equal(t, false, resp.VolumeCondition.Abnormal) assert.Equal(t, "Volume status is up", resp.VolumeCondition.Message) + // Get VolumeStats - shared volume + resp, err = c.NodeGetVolumeStats( + context.Background(), + &csi.NodeGetVolumeStatsRequest{VolumeId: id, VolumePath: sharedPath}) + assert.NoError(t, err) + assert.Equal(t, 1, len(resp.Usage)) + assert.Equal(t, size, resp.Usage[0].Total) + assert.Equal(t, used, resp.Usage[0].Used) + assert.Equal(t, available, resp.Usage[0].Available) + assert.Equal(t, false, resp.VolumeCondition.Abnormal) + assert.Equal(t, "Volume status is up", resp.VolumeCondition.Message) + // Get VolumeStats - down vol.Status = api.VolumeStatus_VOLUME_STATUS_DOWN resp, err = c.NodeGetVolumeStats(