Files
my-rook-config/pkg/daemon/ceph/mds/filesystem.go
T

130 lines
4.0 KiB
Go
Raw Normal View History

2016-11-21 14:24:07 -08:00
/*
Copyright 2016 The Rook Authors. All rights reserved.
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 mds
import (
"fmt"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/daemon/ceph/client"
ceph "github.com/rook/rook/pkg/daemon/ceph/client"
2017-10-05 10:00:19 -07:00
"github.com/rook/rook/pkg/model"
2016-11-21 14:24:07 -08:00
)
const (
2017-10-05 10:00:19 -07:00
defaultFilesystemName = "rookfs"
2016-11-21 14:24:07 -08:00
defaultPoolName = "fspool"
poolKeyName = "pool"
idKeyName = "id"
2017-10-05 10:00:19 -07:00
dataPoolSuffix = "data"
metadataPoolSuffix = "metadata"
2016-11-21 14:24:07 -08:00
mdsKeyName = "mds"
2017-10-05 10:00:19 -07:00
FilesystemKey = "fs"
appName = "cephfs"
2016-11-21 14:24:07 -08:00
)
// A file system (an instance of CephFS)
2017-10-05 10:00:19 -07:00
type Filesystem struct {
Name string
metadataPool *model.Pool
dataPools []*model.Pool
activeMDSCount int32
2016-11-21 14:24:07 -08:00
}
// Create a new file service struct
2017-10-05 10:00:19 -07:00
func NewFS(name string, metadataPool *model.Pool, dataPools []*model.Pool, activeMDSCount int32) *Filesystem {
metadataPool.Name = fmt.Sprintf("%s-%s", name, metadataPoolSuffix)
for i, pool := range dataPools {
pool.Name = fmt.Sprintf("%s-%s%d", name, dataPoolSuffix, i)
}
2017-10-05 10:00:19 -07:00
return &Filesystem{
Name: name,
metadataPool: metadataPool,
dataPools: dataPools,
activeMDSCount: activeMDSCount,
2016-11-21 14:24:07 -08:00
}
}
2017-10-05 10:00:19 -07:00
func (f *Filesystem) CreateFilesystem(context *clusterd.Context, clusterName string) error {
logger.Infof("Creating file system %s", f.Name)
_, err := client.GetFilesystem(context, clusterName, f.Name)
if err == nil {
2017-10-05 10:00:19 -07:00
logger.Infof("file system %s already exists", f.Name)
return nil
}
2017-10-05 10:00:19 -07:00
if len(f.dataPools) == 0 {
return fmt.Errorf("at least one data pool must be specified")
2016-11-21 14:24:07 -08:00
}
2017-10-05 10:00:19 -07:00
err = ceph.CreatePoolWithProfile(context, clusterName, *f.metadataPool, appName)
2016-11-21 14:24:07 -08:00
if err != nil {
2017-10-05 10:00:19 -07:00
return fmt.Errorf("failed to create metadata pool '%s': %+v", f.metadataPool.Name, err)
}
var dataPoolNames []string
for _, pool := range f.dataPools {
dataPoolNames = append(dataPoolNames, pool.Name)
err = ceph.CreatePoolWithProfile(context, clusterName, *pool, appName)
if err != nil {
return fmt.Errorf("failed to create data pool %s. %+v", pool.Name, err)
}
if pool.Type == model.ErasureCoded {
// An erasure coded data pool used for a file system must allow overwrites
if err := client.SetPoolProperty(context, clusterName, pool.Name, "allow_ec_overwrites", "true"); err != nil {
logger.Warningf("failed to set ec pool property. %+v", err)
}
}
2016-11-21 14:24:07 -08:00
}
2016-11-28 17:38:06 -08:00
// create the file system
2017-10-05 10:00:19 -07:00
if err := client.CreateFilesystem(context, clusterName, f.Name, f.metadataPool.Name, dataPoolNames, f.activeMDSCount); err != nil {
2016-11-28 17:38:06 -08:00
return err
2016-11-21 14:24:07 -08:00
}
2017-10-05 10:00:19 -07:00
logger.Infof("created file system %s on %d data pool(s) and metadata pool %s", f.Name, len(f.dataPools), f.metadataPool.Name)
2016-11-21 14:24:07 -08:00
return nil
}
// Remove the file system in ceph
2017-10-05 10:00:19 -07:00
func DeleteFilesystem(context *clusterd.Context, clusterName, filesystemName string) error {
logger.Infof("Removing file system %s", filesystemName)
2016-11-21 14:24:07 -08:00
2016-11-28 17:38:06 -08:00
// mark the cephFS instance as cluster_down before removing
2017-10-05 10:00:19 -07:00
if err := client.MarkFilesystemAsDown(context, clusterName, filesystemName); err != nil {
2016-11-28 17:38:06 -08:00
return err
2016-11-21 14:24:07 -08:00
}
2016-11-28 17:38:06 -08:00
// mark each MDS associated with the file system to "failed"
2017-10-05 10:00:19 -07:00
fsDetails, err := client.GetFilesystem(context, clusterName, filesystemName)
2016-11-21 14:24:07 -08:00
if err != nil {
2016-11-28 17:38:06 -08:00
return err
}
for _, mdsInfo := range fsDetails.MDSMap.Info {
2017-10-05 10:00:19 -07:00
if err := client.FailMDS(context, clusterName, mdsInfo.GID); err != nil {
2016-11-28 17:38:06 -08:00
return err
}
}
// Permanently remove the file system
2017-10-05 10:00:19 -07:00
if err := client.RemoveFilesystem(context, clusterName, filesystemName); err != nil {
2016-11-28 17:38:06 -08:00
return err
2016-11-21 14:24:07 -08:00
}
2017-10-05 10:00:19 -07:00
logger.Infof("Removed file system %s", filesystemName)
2016-11-21 14:24:07 -08:00
return nil
}