Skip to content

Commit

Permalink
runtime: direct-volume stats use correct name
Browse files Browse the repository at this point in the history
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 <yibzhuang@gmail.com>
  • Loading branch information
yibozhuang committed May 21, 2022
1 parent ffdc065 commit 4428cea
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/runtime/cmd/kata-runtime/kata-volume.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 4428cea

Please sign in to comment.