2018-03-05 11:59:47 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cephfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2018-03-09 16:05:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type volume struct {
|
2018-03-20 14:57:03 +00:00
|
|
|
RootPath string
|
|
|
|
User string
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 16:05:19 +00:00
|
|
|
func (vol *volume) mount(mountPoint string) error {
|
2018-03-20 14:57:03 +00:00
|
|
|
out, err := execCommand("ceph-fuse", mountPoint, "-n", "client."+vol.User, "-r", vol.RootPath)
|
2018-03-09 16:05:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cephfs: ceph-fuse failed with following error: %s\ncephfs: cephf-fuse output: %s", err, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 16:05:19 +00:00
|
|
|
func (vol *volume) unmount() error {
|
2018-03-20 14:57:03 +00:00
|
|
|
out, err := execCommand("fusermount", "-u", vol.RootPath)
|
2018-03-05 11:59:47 +00:00
|
|
|
if err != nil {
|
2018-03-09 16:05:19 +00:00
|
|
|
return fmt.Errorf("cephfs: fusermount failed with following error: %v\ncephfs: fusermount output: %s", err, out)
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-09 16:05:19 +00:00
|
|
|
func unmountVolume(root string) error {
|
2018-03-05 11:59:47 +00:00
|
|
|
out, err := execCommand("fusermount", "-u", root)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cephfs: fusermount failed with following error: %v\ncephfs: fusermount output: %s", err, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-09 16:05:19 +00:00
|
|
|
func createMountPoint(root string) error {
|
|
|
|
return os.MkdirAll(root, 0750)
|
|
|
|
}
|