mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-27 00:30:18 +00:00
cephfs: implement createVolume() with go-ceph
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
fe62348cfb
commit
8cba08189d
@ -23,6 +23,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
|
|
||||||
|
fsAdmin "github.com/ceph/go-ceph/cephfs/admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -135,20 +137,16 @@ func createVolume(ctx context.Context, volOptions *volumeOptions, cr *util.Crede
|
|||||||
clusterAdditionalInfo[volOptions.ClusterID] = &localClusterState{}
|
clusterAdditionalInfo[volOptions.ClusterID] = &localClusterState{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ca, err := volOptions.conn.GetFSAdmin()
|
||||||
|
if err != nil {
|
||||||
|
util.ErrorLog(ctx, "could not get FSAdmin, can not create subvolume %s: %s", string(volID), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// create subvolumegroup if not already created for the cluster.
|
// create subvolumegroup if not already created for the cluster.
|
||||||
if !clusterAdditionalInfo[volOptions.ClusterID].subVolumeGroupCreated {
|
if !clusterAdditionalInfo[volOptions.ClusterID].subVolumeGroupCreated {
|
||||||
err := execCommandErr(
|
opts := fsAdmin.SubVolumeGroupOptions{}
|
||||||
ctx,
|
err = ca.CreateSubVolumeGroup(volOptions.FsName, volOptions.SubvolumeGroup, &opts)
|
||||||
"ceph",
|
|
||||||
"fs",
|
|
||||||
"subvolumegroup",
|
|
||||||
"create",
|
|
||||||
volOptions.FsName,
|
|
||||||
volOptions.SubvolumeGroup,
|
|
||||||
"-m", volOptions.Monitors,
|
|
||||||
"-c", util.CephConfigPath,
|
|
||||||
"-n", cephEntityClientPrefix+cr.ID,
|
|
||||||
"--keyfile="+cr.KeyFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to create subvolume group %s, for the vol %s: %s", volOptions.SubvolumeGroup, string(volID), err)
|
util.ErrorLog(ctx, "failed to create subvolume group %s, for the vol %s: %s", volOptions.SubvolumeGroup, string(volID), err)
|
||||||
return err
|
return err
|
||||||
@ -157,30 +155,16 @@ func createVolume(ctx context.Context, volOptions *volumeOptions, cr *util.Crede
|
|||||||
clusterAdditionalInfo[volOptions.ClusterID].subVolumeGroupCreated = true
|
clusterAdditionalInfo[volOptions.ClusterID].subVolumeGroupCreated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
opts := fsAdmin.SubVolumeOptions{
|
||||||
"fs",
|
Size: fsAdmin.ByteCount(bytesQuota),
|
||||||
"subvolume",
|
Mode: 0777,
|
||||||
"create",
|
|
||||||
volOptions.FsName,
|
|
||||||
string(volID),
|
|
||||||
strconv.FormatInt(bytesQuota, 10),
|
|
||||||
"--group_name",
|
|
||||||
volOptions.SubvolumeGroup,
|
|
||||||
"--mode", "777",
|
|
||||||
"-m", volOptions.Monitors,
|
|
||||||
"-c", util.CephConfigPath,
|
|
||||||
"-n", cephEntityClientPrefix + cr.ID,
|
|
||||||
"--keyfile=" + cr.KeyFile,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if volOptions.Pool != "" {
|
if volOptions.Pool != "" {
|
||||||
args = append(args, "--pool_layout", volOptions.Pool)
|
opts.PoolLayout = volOptions.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
err := execCommandErr(
|
// FIXME: check if the right credentials are used ("-n", cephEntityClientPrefix + cr.ID)
|
||||||
ctx,
|
err = ca.CreateSubVolume(volOptions.FsName, volOptions.SubvolumeGroup, string(volID), &opts)
|
||||||
"ceph",
|
|
||||||
args[:]...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to create subvolume %s in fs %s: %s", string(volID), volOptions.FsName, err)
|
util.ErrorLog(ctx, "failed to create subvolume %s in fs %s: %s", string(volID), volOptions.FsName, err)
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user