Skip to content

Commit

Permalink
feat(ZFSPV): adding support for applications to create "zfs" flesystem (
Browse files Browse the repository at this point in the history
#15)

Application can now create a storageclass to create zfs filesystem

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: openebs-zfspv5
allowVolumeExpansion: true
parameters:
  blocksize: "4k"
  fstype: "zfs"
  poolname: "zfspv-pool"
provisioner: zfs.csi.openebs.io

ZFSPV was supporting ext2/3/4 and xfs filesystem only which
adds one extra filesystem layer on top of ZFS filesystem. So now
we can driectly write to the ZFS filesystem and get the optimal performance
by directly creating ZFS filesystem for storage.

Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 authored and kmova committed Nov 21, 2019
1 parent 4ffd857 commit 68db6d2
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 175 deletions.
4 changes: 2 additions & 2 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
var err error
// ZFS Volume should be deleted. Check if deletion timestamp is set
if c.isDeletionCandidate(zv) {
err = zvol.DestroyZvol(zv)
err = zvol.DestroyVolume(zv)
if err == nil {
zvol.RemoveZvolFinalizer(zv)
}
Expand All @@ -91,7 +91,7 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
if zv.Finalizers != nil {
err = zvol.SetZvolProp(zv)
} else {
err = zvol.CreateZvol(zv)
err = zvol.CreateVolume(zv)
if err == nil {
err = zvol.UpdateZvolInfo(zv)
}
Expand Down
46 changes: 29 additions & 17 deletions deploy/sample/fio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ metadata:
name: openebs-zfspv
allowVolumeExpansion: true
parameters:
blocksize: "4k"
recordsize: "4k"
compression: "on"
dedup: "on"
thinprovision: "yes"
#encryption: "on"
#keyformat: "raw"
#keylocation: "file:///home/pawan/key"
fstype: "zfs"
poolname: "zfspv-pool"
provisioner: zfs.csi.openebs.io
allowedTopologies:
Expand All @@ -32,22 +33,33 @@ spec:
requests:
storage: 4Gi
---
apiVersion: v1
kind: Pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: fio
labels:
name: fio
spec:
restartPolicy: Never
containers:
- name: perfrunner
image: openebs/tests-fio
command: ["/bin/bash"]
args: ["-c", "while true ;do sleep 50; done"]
volumeMounts:
- mountPath: /datadir
name: fio-vol
tty: true
volumes:
- name: fio-vol
persistentVolumeClaim:
claimName: csi-zfspv
replicas: 1
selector:
matchLabels:
name: fio
template:
metadata:
labels:
name: fio
spec:
containers:
- resources:
name: perfrunner
image: openebs/tests-fio
imagePullPolicy: IfNotPresent
command: ["/bin/bash"]
args: ["-c", "while true ;do sleep 50; done"]
volumeMounts:
- mountPath: /datadir
name: fio-vol
volumes:
- name: fio-vol
persistentVolumeClaim:
claimName: csi-zfspv
4 changes: 2 additions & 2 deletions deploy/sample/mongo-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ kind: StorageClass
metadata:
name: mongo-pv-az
parameters:
blocksize: "4k"
volblocksize: "4k"
poolname: "zfspv-pool"
fsType: "xfs"
fstype: "xfs"
provisioner: zfs.csi.openebs.io
---
# Headless service for stable DNS entries of StatefulSet members.
Expand Down
2 changes: 1 addition & 1 deletion deploy/sample/percona.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: openebs-zfspv
allowVolumeExpansion: true
parameters:
blocksize: "4k"
volblocksize: "4k"
compression: "on"
dedup: "on"
thinprovision: "yes"
Expand Down
4 changes: 2 additions & 2 deletions deploy/sample/zfspvcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
name: pvc-37b07ad6-db68-11e9-bbb6-000c296e38d9
namespace: openebs
spec:
blocksize: 4k
capacity: "4294967296"
compression: "off"
dedup: "off"
Expand All @@ -13,5 +12,6 @@ spec:
keylocation: ""
ownerNodeID: zfspv-node1
poolName: zfspv-pool
recordsize: 8k
thinProvision: "off"

volumeType: DATASET
14 changes: 13 additions & 1 deletion deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
singular: zfsvolume
kind: ZFSVolume
shortNames:
- zvol
- zfsvol
- zv
additionalPrinterColumns:
- JSONPath: .spec.poolName
Expand All @@ -35,6 +35,18 @@ spec:
name: Size
description: Size of the volume
type: string
- JSONPath: .spec.volblocksize
name: volblocksize
description: volblocksize for the created zvol
type: string
- JSONPath: .spec.recordsize
name: recordsize
description: recordsize for the created zfs dataset
type: string
- JSONPath: .spec.fsType
name: Filesystem
description: filesystem created on the volume
type: string

---
##############################################
Expand Down
29 changes: 20 additions & 9 deletions pkg/apis/openebs.io/core/v1alpha1/zfsvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,42 @@ type VolumeInfo struct {
// Capacity of the volume
Capacity string `json:"capacity"`

// BlockSize specifies the blocksize
// which we should use to create the zvol
BlockSize string `json:"blocksize"`
// RecordSize specifies the record size
// for the zfs dataset
RecordSize string `json:"recordsize,omitempty"`

// VolBlockSize specifies the block size for the zvol
VolBlockSize string `json:"volblocksize,omitempty"`

// Compression specifies if the it should
// enabled on the zvol
Compression string `json:"compression"`
Compression string `json:"compression,omitempty"`

// Dedup specifies the deduplication
// should be enabled on the zvol
Dedup string `json:"dedup"`
Dedup string `json:"dedup,omitempty"`

// Encryption specifies the encryption
// should be enabled on the zvol
Encryption string `json:"encryption"`
Encryption string `json:"encryption,omitempty"`

// KeyLocation is the location of key
// for the encryption
KeyLocation string `json:"keylocation"`
KeyLocation string `json:"keylocation,omitempty"`

// KeyFormat specifies format of the
// encryption key
KeyFormat string `json:"keyformat"`
KeyFormat string `json:"keyformat,omitempty"`

// Thinprovision specifies if we should
// thin provisioned the volume or not
ThinProvision string `json:"thinProvision"`
ThinProvision string `json:"thinProvision,omitempty"`

// VolumeType specifies whether the volume is
// zvol or a dataset
VolumeType string `json:"volumeType"`

// FsType specifies filesystem type for the
// zfs volume/dataset
FsType string `json:"fsType,omitempty"`
}
28 changes: 21 additions & 7 deletions pkg/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,27 @@ func (b *Builder) WithOwnerNode(host string) *Builder {
return b
}

// WithBlockSize sets blocksize of ZFSVolume
func (b *Builder) WithBlockSize(blockSize string) *Builder {
bs := "4k"
if len(blockSize) > 0 {
bs = blockSize
}
b.volume.Object.Spec.BlockSize = bs
// WithRecordSize sets the recordsize of ZFSVolume
func (b *Builder) WithRecordSize(rs string) *Builder {
b.volume.Object.Spec.RecordSize = rs
return b
}

// WithVolBlockSize sets the volblocksize of ZFSVolume
func (b *Builder) WithVolBlockSize(bs string) *Builder {
b.volume.Object.Spec.VolBlockSize = bs
return b
}

// WithVolumeType sets if ZFSVolume needs to be thin provisioned
func (b *Builder) WithVolumeType(vtype string) *Builder {
b.volume.Object.Spec.VolumeType = vtype
return b
}

// WithFsType sets filesystem for the ZFSVolume
func (b *Builder) WithFsType(fstype string) *Builder {
b.volume.Object.Spec.FsType = fstype
return b
}

Expand Down
37 changes: 17 additions & 20 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
ctrl "github.com/openebs/zfs-localpv/cmd/controller"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
"github.com/openebs/zfs-localpv/pkg/builder"
zvol "github.com/openebs/zfs-localpv/pkg/zfs"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -65,7 +65,7 @@ func GetVolAndMountInfo(

getOptions := metav1.GetOptions{}
vol, err := builder.NewKubeclient().
WithNamespace(zvol.OpenEBSNamespace).
WithNamespace(zfs.OpenEBSNamespace).
Get(req.GetVolumeId(), getOptions)

if err != nil {
Expand Down Expand Up @@ -96,8 +96,8 @@ func (ns *node) NodePublishVolume(
if err != nil {
goto PublishVolumeResponse
}
// Create the zfs volume and attempt mount operation on the requested path
if err = zvol.CreateAndMountZvol(vol, mountInfo); err != nil {
// attempt mount operation on the requested path
if err = zfs.MountVolume(vol, mountInfo); err != nil {
goto PublishVolumeResponse
}

Expand All @@ -120,6 +120,7 @@ func (ns *node) NodeUnpublishVolume(
var (
err error
vol *apis.ZFSVolume
devpath string
currentMounts []string
)

Expand All @@ -130,22 +131,19 @@ func (ns *node) NodeUnpublishVolume(
targetPath := req.GetTargetPath()
volumeID := req.GetVolumeId()

getOptions := metav1.GetOptions{}
vol, err = builder.NewKubeclient().
WithNamespace(zvol.OpenEBSNamespace).
Get(volumeID, getOptions)

if err != nil {
if vol, err = zfs.GetZFSVolume(volumeID); err != nil {
return nil, err
}

zfsvolume := vol.Spec.PoolName + "/" + vol.Name
devpath := zvol.ZFS_DEVPATH + zfsvolume
currentMounts, err = zvol.GetMounts(devpath)
if devpath, err = zfs.GetVolumeDevPath(vol); err != nil {
goto NodeUnpublishResponse
}

currentMounts, err = zfs.GetMounts(devpath)
if err != nil {
return nil, err
} else if len(currentMounts) == 0 {
goto NodeUnpublishResponse
return nil, status.Error(codes.Internal, "umount request for not mounted volume")
} else if len(currentMounts) == 1 {
if currentMounts[0] != targetPath {
return nil, status.Error(codes.Internal, "device not mounted at right path")
Expand All @@ -158,15 +156,14 @@ func (ns *node) NodeUnpublishVolume(
return nil, status.Error(codes.Internal, "device not mounted at rightpath")
}

if vol, err = zvol.GetZFSVolume(volumeID); (err != nil) || (vol == nil) {
goto NodeUnpublishResponse
}

if err = zvol.UmountVolume(vol, req.GetTargetPath()); err != nil {
if err = zfs.UmountVolume(vol, req.GetTargetPath()); err != nil {
goto NodeUnpublishResponse
}

NodeUnpublishResponse:
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
logrus.Infof("hostpath: volume %s path: %s has been unmounted.",
volumeID, targetPath)

Expand All @@ -181,7 +178,7 @@ func (ns *node) NodeGetInfo(
req *csi.NodeGetInfoRequest,
) (*csi.NodeGetInfoResponse, error) {

topology := map[string]string{zvol.ZFSTopologyKey: ns.driver.config.NodeID}
topology := map[string]string{zfs.ZFSTopologyKey: ns.driver.config.NodeID}
return &csi.NodeGetInfoResponse{
NodeId: ns.driver.config.NodeID,
AccessibleTopology: &csi.Topology{
Expand Down

0 comments on commit 68db6d2

Please sign in to comment.