Skip to content

Commit

Permalink
fix(zfspv): rounding off the volume size to Gi and Mi
Browse files Browse the repository at this point in the history
ZFS does not create the zvol if volume size is not multiple of
the volblocksize. There are use cases where customer will create
a PVC with size as 5G, which will be 5 * 1000 * 1000 * 1000 bytes
and this is not the multiple of default volblocksize 8k.

In ZFS, volblocksize and recordsize must be power of 2 from 512B to 1M,
so keeping the size in the form of Gi or Mi should be
sufficient to make volsize multiple of volblocksize/recordsize.

Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Aug 6, 2020
1 parent cd4a0de commit d7c1cf5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions 191-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rounding off the volume size to the Gi and Mi
30 changes: 26 additions & 4 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import (
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
)

const (
Mi = 1024 * 1024
Gi = 1024 * 1024 * 1024
)

// controller is the server implementation
// for CSI Controller
type controller struct {
Expand Down Expand Up @@ -75,10 +80,26 @@ func sendEventOrIgnore(pvcName, pvName, capacity, stgType, method string) {
}
}

// getRoundedCapacity rounds the capacity on 1024 base
func getRoundedCapacity(size int64) int64 {

/*
* volblocksize and recordsize must be power of 2 from 512B to 1M
* so keeping the size in the form of Gi or Mi should be
* sufficient to make volsize multiple of volblocksize/recordsize.
*/
if size > Gi {
return ((size + Gi - 1) / Gi) * Gi
}

// Keeping minimum allocatable size as 1Mi (1024 * 1024)
return ((size + Mi - 1) / Mi) * Mi
}

// CreateZFSVolume create new zfs volume from csi volume request
func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
volName := req.GetName()
size := req.GetCapacityRange().RequiredBytes
size := getRoundedCapacity(req.GetCapacityRange().RequiredBytes)

// parameter keys may be mistyped from the CRD specification when declaring
// the storageclass, which kubectl validation will not catch. Because ZFS
Expand Down Expand Up @@ -148,7 +169,7 @@ func CreateZFSClone(req *csi.CreateVolumeRequest, snapshot string) (string, erro
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
size := getRoundedCapacity(req.GetCapacityRange().RequiredBytes)
volsize := strconv.FormatInt(int64(size), 10)

snapshotID := strings.Split(snapshot, "@")
Expand Down Expand Up @@ -208,7 +229,7 @@ func (cs *controller) CreateVolume(
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
size := getRoundedCapacity(req.GetCapacityRange().RequiredBytes)
contentSource := req.GetVolumeContentSource()
pvcName := helpers.GetInsensitiveParameter(&parameters, "csi.storage.k8s.io/pvc/name")

Expand Down Expand Up @@ -325,7 +346,8 @@ func (cs *controller) ControllerExpandVolume(
req *csi.ControllerExpandVolumeRequest,
) (*csi.ControllerExpandVolumeResponse, error) {

updatedSize := req.GetCapacityRange().GetRequiredBytes()
/* round off the new size */
updatedSize := getRoundedCapacity(req.GetCapacityRange().GetRequiredBytes())

vol, err := zfs.GetZFSVolume(req.VolumeId)
if err != nil {
Expand Down

0 comments on commit d7c1cf5

Please sign in to comment.