From 2fcc252f5c4bf90b5285741474560e3398462c21 Mon Sep 17 00:00:00 2001 From: gman Date: Tue, 12 Jun 2018 17:05:42 +0200 Subject: [PATCH] cephfs: pass volume UUIDs where needed --- pkg/cephfs/util.go | 20 +++++++++++--------- pkg/cephfs/volume.go | 4 ++-- pkg/cephfs/volumemounter.go | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pkg/cephfs/util.go b/pkg/cephfs/util.go index b2e75b01c..54f354a78 100644 --- a/pkg/cephfs/util.go +++ b/pkg/cephfs/util.go @@ -79,9 +79,10 @@ func tryLock(id string, mtx keymutex.KeyMutex, name string) error { func storeCephUserCredentials(volUuid string, cr *credentials, volOptions *volumeOptions) error { keyringData := cephKeyringData{ - UserId: cr.id, - Key: cr.key, - RootPath: volOptions.RootPath, + UserId: cr.id, + Key: cr.key, + RootPath: volOptions.RootPath, + VolumeUuid: volUuid, } if volOptions.ProvisionVolume { @@ -89,21 +90,22 @@ func storeCephUserCredentials(volUuid string, cr *credentials, volOptions *volum keyringData.Namespace = getVolumeNamespace(volUuid) } - return storeCephCredentials(cr, &keyringData) + return storeCephCredentials(volUuid, cr, &keyringData) } -func storeCephAdminCredentials(cr *credentials) error { - return storeCephCredentials(cr, &cephFullCapsKeyringData{UserId: cr.id, Key: cr.key}) +func storeCephAdminCredentials(volUuid string, cr *credentials) error { + return storeCephCredentials(volUuid, cr, &cephFullCapsKeyringData{UserId: cr.id, Key: cr.key, VolumeUuid: volUuid}) } -func storeCephCredentials(cr *credentials, keyringData cephConfigWriter) error { +func storeCephCredentials(volUuid string, cr *credentials, keyringData cephConfigWriter) error { if err := keyringData.writeToFile(); err != nil { return err } secret := cephSecretData{ - UserId: cr.id, - Key: cr.key, + UserId: cr.id, + Key: cr.key, + VolumeUuid: volUuid, } if err := secret.writeToFile(); err != nil { diff --git a/pkg/cephfs/volume.go b/pkg/cephfs/volume.go index 851476ddc..0ef12c543 100644 --- a/pkg/cephfs/volume.go +++ b/pkg/cephfs/volume.go @@ -88,7 +88,7 @@ func createVolume(volOptions *volumeOptions, adminCr *credentials, volUuid strin // Access to cephfs's / is required volOptions.RootPath = "/" - if err := mountKernel(cephRoot, adminCr, volOptions); err != nil { + if err := mountKernel(cephRoot, adminCr, volOptions, volUuid); err != nil { return fmt.Errorf("error mounting ceph root: %v", err) } @@ -144,7 +144,7 @@ func purgeVolume(volId string, cr *credentials, volOptions *volumeOptions) error return err } - if err := mountKernel(volRoot, cr, volOptions); err != nil { + if err := mountKernel(volRoot, cr, volOptions, volUuid); err != nil { return err } diff --git a/pkg/cephfs/volumemounter.go b/pkg/cephfs/volumemounter.go index 7756b5c22..666a0ce21 100644 --- a/pkg/cephfs/volumemounter.go +++ b/pkg/cephfs/volumemounter.go @@ -38,7 +38,7 @@ func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions, vo mountPoint, "-c", getCephConfPath(volUuid), "-n", cephEntityClientPrefix + cr.id, - "--keyring", getCephKeyringPath(cr.id), + "--keyring", getCephKeyringPath(volUuid, cr.id), "-r", volOptions.RootPath, } @@ -74,7 +74,7 @@ func (m *fuseMounter) mount(mountPoint string, cr *credentials, volOptions *volu type kernelMounter struct{} -func mountKernel(mountPoint string, cr *credentials, volOptions *volumeOptions) error { +func mountKernel(mountPoint string, cr *credentials, volOptions *volumeOptions, volUuid string) error { if err := execCommandAndValidate("modprobe", "ceph"); err != nil { return err } @@ -84,7 +84,7 @@ func mountKernel(mountPoint string, cr *credentials, volOptions *volumeOptions) fmt.Sprintf("%s:%s", volOptions.Monitors, volOptions.RootPath), mountPoint, "-o", - fmt.Sprintf("name=%s,secretfile=%s", cr.id, getCephSecretPath(cr.id)), + fmt.Sprintf("name=%s,secretfile=%s", cr.id, getCephSecretPath(volUuid, cr.id)), ) } @@ -99,7 +99,7 @@ func (m *kernelMounter) mount(mountPoint string, cr *credentials, volOptions *vo return err } - if err := mountKernel(localVolRoot, cr, volOptions); err != nil { + if err := mountKernel(localVolRoot, cr, volOptions, volUuid); err != nil { return err }