2016-11-05 17:09:05 -07: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.
|
|
|
|
|
*/
|
2018-08-31 13:39:02 -06:00
|
|
|
|
2016-11-10 10:59:26 -08:00
|
|
|
package osd
|
2016-08-14 14:54:18 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2023-03-23 07:04:03 +00:00
|
|
|
"os"
|
2021-07-14 16:07:36 -06:00
|
|
|
|
2023-03-23 07:04:03 +00:00
|
|
|
oposd "github.com/rook/rook/pkg/operator/ceph/cluster/osd"
|
2021-07-14 16:07:36 -06:00
|
|
|
"github.com/rook/rook/pkg/util/sys"
|
2016-08-14 14:54:18 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
bootstrapOSDKeyringTemplate = `
|
|
|
|
|
[client.bootstrap-osd]
|
|
|
|
|
key = %s
|
|
|
|
|
caps mon = "allow profile bootstrap-osd"
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
|
2020-01-13 16:58:51 +01:00
|
|
|
// Device is a device
|
2016-09-27 14:32:52 -07:00
|
|
|
type Device struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
NodeID string `json:"nodeId"`
|
2016-10-14 14:41:15 -07:00
|
|
|
Dir bool `json:"bool"`
|
2016-09-27 14:32:52 -07:00
|
|
|
}
|
|
|
|
|
|
2018-12-04 14:57:22 -07:00
|
|
|
// DesiredDevice keeps track of the desired settings for a device
|
|
|
|
|
type DesiredDevice struct {
|
2019-11-05 11:01:04 +09:00
|
|
|
Name string
|
|
|
|
|
OSDsPerDevice int
|
|
|
|
|
MetadataDevice string
|
|
|
|
|
DatabaseSizeMB int
|
|
|
|
|
DeviceClass string
|
2021-03-30 11:11:41 +03:00
|
|
|
InitialWeight string
|
2019-11-05 11:01:04 +09:00
|
|
|
IsFilter bool
|
|
|
|
|
IsDevicePathFilter bool
|
2018-12-04 14:57:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-01-13 16:58:51 +01:00
|
|
|
// DeviceOsdMapping represents the mapping of an OSD on disk
|
2017-01-11 20:19:47 -08:00
|
|
|
type DeviceOsdMapping struct {
|
|
|
|
|
Entries map[string]*DeviceOsdIDEntry // device name to OSD ID mapping entry
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 16:58:51 +01:00
|
|
|
// DeviceOsdIDEntry represents the details of an OSD
|
2017-01-11 20:19:47 -08:00
|
|
|
type DeviceOsdIDEntry struct {
|
2018-12-04 14:57:22 -07:00
|
|
|
Data int // OSD ID that has data stored here
|
|
|
|
|
Metadata []int // OSD IDs (multiple) that have metadata stored here
|
|
|
|
|
Config DesiredDevice // Device specific config options
|
2019-11-01 15:44:26 +09:00
|
|
|
PersistentDevicePaths []string
|
2021-07-14 16:07:36 -06:00
|
|
|
DeviceInfo *sys.LocalDisk // low-level info about the device
|
2023-06-22 09:59:34 +05:30
|
|
|
RestoreOSD bool // Restore OSD by reparing it with with OSD ID
|
2017-01-11 20:19:47 -08:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 22:08:50 -08:00
|
|
|
func (m *DeviceOsdMapping) String() string {
|
|
|
|
|
b, _ := json.Marshal(m)
|
|
|
|
|
return string(b)
|
|
|
|
|
}
|
2023-03-23 07:04:03 +00:00
|
|
|
|
|
|
|
|
func (d *DesiredDevice) UpdateDeviceClass(agent *OsdAgent, device *sys.LocalDisk) {
|
|
|
|
|
// Rook sets the storage class of a device with the following priority.
|
|
|
|
|
//
|
|
|
|
|
// 1. the device-level configuration
|
|
|
|
|
// 2. the global or node-local configuration
|
|
|
|
|
// 3. the default value estimated from sysfs.
|
|
|
|
|
if d.DeviceClass != "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if agent.pvcBacked {
|
|
|
|
|
crushDeviceClass := os.Getenv(oposd.CrushDeviceClassVarName)
|
|
|
|
|
if crushDeviceClass != "" {
|
|
|
|
|
d.DeviceClass = crushDeviceClass
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if agent.storeConfig.DeviceClass != "" {
|
|
|
|
|
d.DeviceClass = agent.storeConfig.DeviceClass
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.DeviceClass = sys.GetDiskDeviceClass(device)
|
|
|
|
|
}
|