mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
Merge pull request #38 from gman0/cephfs-conf-scheme
cephfs config scheme
This commit is contained in:
commit
3c2c7551df
@ -51,7 +51,7 @@ const cephSecret = `{{.Key}}`
|
||||
|
||||
const (
|
||||
cephConfigRoot = "/etc/ceph"
|
||||
cephConfigFileName = "ceph.conf"
|
||||
cephConfigFileNameFmt = "ceph.share.%s.conf"
|
||||
cephKeyringFileNameFmt = "ceph.client.%s.keyring"
|
||||
cephSecretFileNameFmt = "ceph.client.%s.secret"
|
||||
)
|
||||
@ -85,7 +85,8 @@ type cephConfigWriter interface {
|
||||
}
|
||||
|
||||
type cephConfigData struct {
|
||||
Monitors string
|
||||
Monitors string
|
||||
VolumeUuid string
|
||||
}
|
||||
|
||||
func writeCephTemplate(fileName string, m os.FileMode, t *template.Template, data interface{}) error {
|
||||
@ -107,7 +108,7 @@ func writeCephTemplate(fileName string, m os.FileMode, t *template.Template, dat
|
||||
}
|
||||
|
||||
func (d *cephConfigData) writeToFile() error {
|
||||
return writeCephTemplate(cephConfigFileName, 0640, cephConfigTempl, d)
|
||||
return writeCephTemplate(fmt.Sprintf(cephConfigFileNameFmt, d.VolumeUuid), 0640, cephConfigTempl, d)
|
||||
}
|
||||
|
||||
type cephKeyringData struct {
|
||||
@ -144,6 +145,6 @@ func getCephKeyringPath(userId string) string {
|
||||
return path.Join(cephConfigRoot, fmt.Sprintf(cephKeyringFileNameFmt, userId))
|
||||
}
|
||||
|
||||
func getCephConfPath() string {
|
||||
return path.Join(cephConfigRoot, cephConfigFileName)
|
||||
func getCephConfPath(volUuid string) string {
|
||||
return path.Join(cephConfigRoot, fmt.Sprintf(cephConfigFileNameFmt, volUuid))
|
||||
}
|
||||
|
@ -77,12 +77,6 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
||||
|
||||
volId := newVolumeIdentifier(volOptions, req)
|
||||
|
||||
conf := cephConfigData{Monitors: volOptions.Monitors}
|
||||
if err = conf.writeToFile(); err != nil {
|
||||
glog.Errorf("couldn't generate ceph.conf: %v", err)
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
// Create a volume in case the user didn't provide one
|
||||
|
||||
if volOptions.ProvisionVolume {
|
||||
|
@ -119,6 +119,12 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
conf := cephConfigData{Monitors: volOptions.Monitors, VolumeUuid: volUuid}
|
||||
if err = conf.writeToFile(); err != nil {
|
||||
glog.Errorf("failed to write ceph config file to %s: %v", getCephConfPath(volUuid), err)
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
// Check if the volume is already mounted
|
||||
|
||||
isMnt, err := isMountPoint(targetPath)
|
||||
|
@ -33,10 +33,12 @@ type volumeMounter interface {
|
||||
|
||||
type fuseMounter struct{}
|
||||
|
||||
func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions) error {
|
||||
func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions, volUuid string) error {
|
||||
args := [...]string{
|
||||
mountPoint,
|
||||
"-c", getCephConfPath(volUuid),
|
||||
"-n", cephEntityClientPrefix + cr.id,
|
||||
"--keyring", getCephKeyringPath(cr.id),
|
||||
"-r", volOptions.RootPath,
|
||||
}
|
||||
|
||||
@ -45,7 +47,7 @@ func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions) er
|
||||
return fmt.Errorf("cephfs: ceph-fuse failed with following error: %s\ncephfs: ceph-fuse output: %s", err, out)
|
||||
}
|
||||
|
||||
if !bytes.Contains(out, []byte("starting fuse"[:])) {
|
||||
if !bytes.Contains(out, []byte("starting fuse")) {
|
||||
return fmt.Errorf("cephfs: ceph-fuse failed:\ncephfs: ceph-fuse output: %s", out)
|
||||
}
|
||||
|
||||
@ -63,7 +65,7 @@ func (m *fuseMounter) mount(mountPoint string, cr *credentials, volOptions *volu
|
||||
return err
|
||||
}
|
||||
|
||||
if err := mountFuse(localVolRoot, cr, volOptions); err != nil {
|
||||
if err := mountFuse(localVolRoot, cr, volOptions, volUuid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user