Skip to content

Commit

Permalink
Add mount option for Cephfs
Browse files Browse the repository at this point in the history
The storage class already takes MountOptions(MountFlags), these are the
bind mount options. Some of these options may not be recognised by the
cephfs mount. Hence added a new parameter in Storage Class for cephfs
kernel mount options. Ceph kernel mount options are different from
ceph-fuse options, and there are not many ceph-fuse options. Thus the
parameter takes only the ceph kernel mount options and ceph kernel mount
is choosen only when kernel is >=4.17.

Signed-off-by: Poornima G <[email protected]>
  • Loading branch information
Poornima G committed Sep 5, 2019
1 parent 90c4d6a commit 10500c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/deploy-cephfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ is used to define in which namespace you want the configmaps to be stored
| `fsName` | yes | CephFS filesystem name into which the volume shall be created |
| `mounter` | no | Mount method to be used for this volume. Available options are `kernel` for Ceph kernel client and `fuse` for Ceph FUSE driver. Defaults to "default mounter", see command line arguments. |
| `pool` | no | Ceph pool into which volume data shall be stored |
| `mountOptions` | no | Comma seperated string of mount options accepted by cephfs kernel and/or fuse mount. by default no options are passed. Check man mount.ceph for options. |
| `csi.storage.k8s.io/provisioner-secret-name`, `csi.storage.k8s.io/node-stage-secret-name` | for Kubernetes | Name of the Kubernetes Secret object containing Ceph client credentials. Both parameters should have the same value |
| `csi.storage.k8s.io/provisioner-secret-namespace`, `csi.storage.k8s.io/node-stage-secret-namespace` | for Kubernetes | Namespaces of the above Secret objects |

Expand Down
4 changes: 4 additions & 0 deletions examples/cephfs/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ parameters:
# (optional) Ceph pool into which volume data shall be stored
# pool: cephfs_data

# (optional) Comma seperated string of Cephfs kernel mount options.
# Check man mount.ceph for mount options. For eg:
# mountOptions: readdir_max_bytes=1048576,norbytes

# The secrets have to contain user and/or Ceph admin credentials.
csi.storage.k8s.io/provisioner-secret-name: csi-cephfs-secret
csi.storage.k8s.io/provisioner-secret-namespace: default
Expand Down
6 changes: 6 additions & 0 deletions pkg/cephfs/volumemounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func loadAvailableMounters() error {
if err != nil {
return err
}

vers := strings.Split(string(kernelVersion), ".")
majorVers, err := strconv.Atoi(vers[0])
if err != nil {
Expand Down Expand Up @@ -197,8 +198,13 @@ func mountKernel(ctx context.Context, mountPoint string, cr *util.Credentials, v
if volOptions.FsName != "" {
optionsStr += fmt.Sprintf(",mds_namespace=%s", volOptions.FsName)
}
if volOptions.MountOptions != "" {
optionsStr += fmt.Sprintf(",%s", volOptions.MountOptions)
}
args = append(args, "-o", optionsStr)

klog.Infof("Kernel Mounted, command: %v", args)

return execCommandErr(ctx, "mount", args[:]...)
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/cephfs/volumeoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type volumeOptions struct {
RootPath string `json:"rootPath"`
Mounter string `json:"mounter"`
ProvisionVolume bool `json:"provisionVolume"`
MountOptions string `json:"mountOptions"`
}

func validateNonEmptyField(field, fieldName string) error {
Expand Down Expand Up @@ -147,6 +148,10 @@ func newVolumeOptions(ctx context.Context, requestName string, size int64, volOp
return nil, err
}

if err = extractOptionalOption(&opts.MountOptions, "mountOptions", volOptions); err != nil {
return nil, err
}

opts.RequestName = requestName
opts.Size = size

Expand Down Expand Up @@ -222,7 +227,9 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
if err = extractOptionalOption(&volOptions.Pool, "pool", volOpt); err != nil {
return nil, nil, err
}

if err = extractOptionalOption(&volOptions.MountOptions, "mountOptions", volOpt); err != nil {
return nil, nil, err
}
if err = extractMounter(&volOptions.Mounter, volOpt); err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 10500c1

Please sign in to comment.