From 4428ceae16f10254b0126ce4a635c6ba7a5cef87 Mon Sep 17 00:00:00 2001 From: Yibo Zhuang Date: Fri, 20 May 2022 18:42:47 -0700 Subject: [PATCH] runtime: direct-volume stats use correct name Today the shim does a translation when doing direct-volume stats where it takes the source and returns the mount path within the guest. The source for a direct-assigned volume is actually the device path on the host and not the publish volume path. This change will perform a lookup of the mount info during direct-volume stats to ensure that the device path is provided to the shim for querying the volume stats. Fixes: #4297 Signed-off-by: Yibo Zhuang --- src/runtime/cmd/kata-runtime/kata-volume.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/runtime/cmd/kata-runtime/kata-volume.go b/src/runtime/cmd/kata-runtime/kata-volume.go index e08e9482fa81..bfc026fd4420 100644 --- a/src/runtime/cmd/kata-runtime/kata-volume.go +++ b/src/runtime/cmd/kata-runtime/kata-volume.go @@ -7,10 +7,11 @@ package main import ( "encoding/json" + "fmt" "net/url" containerdshim "github.com/kata-containers/kata-containers/src/runtime/pkg/containerd-shim-v2" - "github.com/kata-containers/kata-containers/src/runtime/pkg/direct-volume" + volume "github.com/kata-containers/kata-containers/src/runtime/pkg/direct-volume" "github.com/kata-containers/kata-containers/src/runtime/pkg/utils/shimclient" "github.com/urfave/cli" @@ -127,8 +128,14 @@ func Stats(volumePath string) ([]byte, error) { if err != nil { return nil, err } - urlSafeDevicePath := url.PathEscape(volumePath) - body, err := shimclient.DoGet(sandboxId, defaultTimeout, containerdshim.DirectVolumeStatUrl+"/"+urlSafeDevicePath) + volumeMountInfo, err := volume.VolumeMountInfo(volumePath) + if err != nil { + return nil, err + } + + urlSafeDevicePath := url.PathEscape(volumeMountInfo.Device) + body, err := shimclient.DoGet(sandboxId, defaultTimeout, + fmt.Sprintf("%s?%s=%s", containerdshim.DirectVolumeStatUrl, containerdshim.DirectVolumePathKey, urlSafeDevicePath)) if err != nil { return nil, err } @@ -141,8 +148,13 @@ func Resize(volumePath string, size uint64) error { if err != nil { return err } + volumeMountInfo, err := volume.VolumeMountInfo(volumePath) + if err != nil { + return err + } + resizeReq := containerdshim.ResizeRequest{ - VolumePath: volumePath, + VolumePath: volumeMountInfo.Device, Size: size, } encoded, err := json.Marshal(resizeReq)