From 1a1942a342be81beca17a733151b8ad4095be6e8 Mon Sep 17 00:00:00 2001 From: Pawan Date: Mon, 1 Feb 2021 12:03:54 +0530 Subject: [PATCH] feat(resize): adding resize support for raw block volumes Signed-off-by: Pawan --- changelogs/unreleased/281-pawanpraka1 | 1 + pkg/driver/agent.go | 19 ++++++++++++++++++- pkg/zfs/zfs_util.go | 8 ++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/281-pawanpraka1 diff --git a/changelogs/unreleased/281-pawanpraka1 b/changelogs/unreleased/281-pawanpraka1 new file mode 100644 index 000000000..18b0c3cc3 --- /dev/null +++ b/changelogs/unreleased/281-pawanpraka1 @@ -0,0 +1 @@ +adding resize support for raw block volumes diff --git a/pkg/driver/agent.go b/pkg/driver/agent.go index 385561466..493f5e2ed 100644 --- a/pkg/driver/agent.go +++ b/pkg/driver/agent.go @@ -17,6 +17,7 @@ limitations under the License. package driver import ( + "os" "strings" "sync" @@ -330,7 +331,23 @@ func (ns *node) NodeExpandVolume( err.Error(), ) } - if err = zfs.ResizeZFSVolume(vol, req.GetVolumePath()); err != nil { + + // find if it is block device so that we don't attempt filesystem resize + st, err := os.Stat(req.GetVolumePath()) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to stat mountpath %s", err.Error()) + } + + resizefs := false + + // doing this dirty check as volume capabilities are not passed for NodeExpandVolume + // CSI 1.2 spec will probably solve this + if st.IsDir() { + // it is not a block device, resize the filesystem + resizefs = true + } + + if err = zfs.ResizeZFSVolume(vol, req.GetVolumePath(), resizefs); err != nil { return nil, status.Errorf( codes.Internal, "failed to handle NodeExpandVolume Request for %s, {%s}", diff --git a/pkg/zfs/zfs_util.go b/pkg/zfs/zfs_util.go index d3c9abbc8..625d10697 100644 --- a/pkg/zfs/zfs_util.go +++ b/pkg/zfs/zfs_util.go @@ -703,7 +703,7 @@ func GetVolumeDevPath(vol *apis.ZFSVolume) (string, error) { } // ResizeZFSVolume resize volume -func ResizeZFSVolume(vol *apis.ZFSVolume, mountpath string) error { +func ResizeZFSVolume(vol *apis.ZFSVolume, mountpath string, resizefs bool) error { volume := vol.Spec.PoolName + "/" + vol.Name args := buildVolumeResizeArgs(vol) @@ -717,7 +717,11 @@ func ResizeZFSVolume(vol *apis.ZFSVolume, mountpath string) error { return err } - err = handleVolResize(vol, mountpath) + if resizefs == true { + // resize the filesystem so that applications can use the expanded space + err = handleVolResize(vol, mountpath) + } + return err }