mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
cephfs/volume: added the ability to use either FUSE or ceph kernel client
This commit is contained in:
parent
e45f87632e
commit
defc676b3d
@ -37,15 +37,19 @@ caps mon = "allow r"
|
|||||||
caps osd = "allow {{perms .ReadOnly}}"
|
caps osd = "allow {{perms .ReadOnly}}"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const cephSecret = `{{.Key}}`
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cephConfigRoot = "/etc/ceph"
|
cephConfigRoot = "/etc/ceph"
|
||||||
cephConfigFileName = "ceph.conf"
|
cephConfigFileName = "ceph.conf"
|
||||||
cephKeyringFileNameFmt = "ceph.client.%s.keyring"
|
cephKeyringFileNameFmt = "ceph.client.%s.keyring"
|
||||||
|
cephSecretFileNameFmt = "ceph.client.%s.secret"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cephConfigTempl *template.Template
|
cephConfigTempl *template.Template
|
||||||
cephKeyringTempl *template.Template
|
cephKeyringTempl *template.Template
|
||||||
|
cephSecretTempl *template.Template
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -61,6 +65,7 @@ func init() {
|
|||||||
|
|
||||||
cephConfigTempl = template.Must(template.New("config").Parse(cephConfig))
|
cephConfigTempl = template.Must(template.New("config").Parse(cephConfig))
|
||||||
cephKeyringTempl = template.Must(template.New("keyring").Funcs(fm).Parse(cephKeyring))
|
cephKeyringTempl = template.Must(template.New("keyring").Funcs(fm).Parse(cephKeyring))
|
||||||
|
cephSecretTempl = template.Must(template.New("secret").Parse(cephSecret))
|
||||||
}
|
}
|
||||||
|
|
||||||
type cephConfigWriter interface {
|
type cephConfigWriter interface {
|
||||||
@ -102,3 +107,15 @@ type cephKeyringData struct {
|
|||||||
func (d *cephKeyringData) writeToFile() error {
|
func (d *cephKeyringData) writeToFile() error {
|
||||||
return writeCephTemplate(fmt.Sprintf(cephKeyringFileNameFmt, d.User), 0600, cephKeyringTempl, d)
|
return writeCephTemplate(fmt.Sprintf(cephKeyringFileNameFmt, d.User), 0600, cephKeyringTempl, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type cephSecretData struct {
|
||||||
|
User, Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *cephSecretData) writeToFile() error {
|
||||||
|
return writeCephTemplate(fmt.Sprintf(cephSecretFileNameFmt, d.User), 0600, cephSecretTempl, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCephSecretPath(user string) string {
|
||||||
|
return path.Join(cephConfigRoot, fmt.Sprintf(cephSecretFileNameFmt, user))
|
||||||
|
}
|
||||||
|
@ -21,13 +21,19 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type volume struct {
|
const (
|
||||||
RootPath string
|
volumeMounter_fuse = "fuse"
|
||||||
User string
|
volumeMounter_kernel = "kernel"
|
||||||
|
)
|
||||||
|
|
||||||
|
type volumeMounter interface {
|
||||||
|
mount(mountPoint string, volOptions *volumeOptions) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vol *volume) mount(mountPoint string) error {
|
type fuseMounter struct{}
|
||||||
out, err := execCommand("ceph-fuse", mountPoint, "-n", "client."+vol.User, "-r", vol.RootPath)
|
|
||||||
|
func (m *fuseMounter) mount(mountPoint string, volOptions *volumeOptions) error {
|
||||||
|
out, err := execCommand("ceph-fuse", mountPoint, "-n", "client."+volOptions.User, "-r", volOptions.RootPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cephfs: ceph-fuse failed with following error: %s\ncephfs: cephf-fuse output: %s", err, out)
|
return fmt.Errorf("cephfs: ceph-fuse failed with following error: %s\ncephfs: cephf-fuse output: %s", err, out)
|
||||||
}
|
}
|
||||||
@ -35,19 +41,34 @@ func (vol *volume) mount(mountPoint string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vol *volume) unmount() error {
|
type kernelMounter struct{}
|
||||||
out, err := execCommand("fusermount", "-u", vol.RootPath)
|
|
||||||
|
func (m *kernelMounter) mount(mountPoint string, volOptions *volumeOptions) error {
|
||||||
|
out, err := execCommand("modprobe", "ceph")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cephfs: fusermount failed with following error: %v\ncephfs: fusermount output: %s", err, out)
|
return fmt.Errorf("cephfs: modprobe failed with following error, %s\ncephfs: modprobe output: %s", err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
args := [...]string{
|
||||||
|
"-t", "ceph",
|
||||||
|
fmt.Sprintf("%s:%s", volOptions.Monitors, volOptions.RootPath),
|
||||||
|
mountPoint,
|
||||||
|
"-o",
|
||||||
|
fmt.Sprintf("name=%s,secretfile=%s", volOptions.User, getCephSecretPath(volOptions.User)),
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err = execCommand("mount", args[:]...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cephfs: mount.ceph failed with following error: %s\ncephfs: mount.ceph output: %s", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmountVolume(root string) error {
|
func unmountVolume(mountPoint string) error {
|
||||||
out, err := execCommand("fusermount", "-u", root)
|
out, err := execCommand("umount", mountPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cephfs: fusermount failed with following error: %v\ncephfs: fusermount output: %s", err, out)
|
return fmt.Errorf("cephfs: umount failed with following error: %v\ncephfs: umount output: %s", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user