|
| 1 | +/* |
| 2 | +Copyright 2020 The OpenEBS Authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package probe |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/openebs/node-disk-manager/blockdevice" |
| 21 | + "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller" |
| 22 | + "github.com/openebs/node-disk-manager/pkg/blkid" |
| 23 | + "k8s.io/klog" |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + blkidProbePriority = 2 |
| 28 | +) |
| 29 | + |
| 30 | +var ( |
| 31 | + blkidProbeState = defaultEnabled |
| 32 | +) |
| 33 | + |
| 34 | +type blkidProbe struct { |
| 35 | +} |
| 36 | + |
| 37 | +var blkidProbeRegister = func() { |
| 38 | + // Get a controller object |
| 39 | + ctrl := <-controller.ControllerBroadcastChannel |
| 40 | + if ctrl == nil { |
| 41 | + klog.Error("unable to configure custom tag probe") |
| 42 | + return |
| 43 | + } |
| 44 | + probe := &blkidProbe{} |
| 45 | + |
| 46 | + newRegisterProbe := ®isterProbe{ |
| 47 | + priority: blkidProbePriority, |
| 48 | + name: "blkid probe", |
| 49 | + state: blkidProbeState, |
| 50 | + pi: probe, |
| 51 | + controller: ctrl, |
| 52 | + } |
| 53 | + |
| 54 | + newRegisterProbe.register() |
| 55 | +} |
| 56 | + |
| 57 | +func (bp *blkidProbe) Start() {} |
| 58 | + |
| 59 | +func (bp *blkidProbe) FillBlockDeviceDetails(bd *blockdevice.BlockDevice) { |
| 60 | + di := &blkid.DeviceIdentifier{DevPath: bd.DevPath} |
| 61 | + |
| 62 | + bd.FSInfo.FileSystem = di.GetOnDiskFileSystem() |
| 63 | + |
| 64 | + // if the host is CentOS 7, the `libblkid` version on host is `2.23`, |
| 65 | + // but the `PTUUID` tag was start to provide from `2.24`. This will cause |
| 66 | + // the udev cache fetched from host udevd will not contain env `ID_PART_TABLE_UUID`. |
| 67 | + // Fortunately, the `libblkid` version in our base container (ubuntu 16.04) |
| 68 | + // is `2.27.1`, will provide `PTUUID` tag, so we should fetch `PTUUID` from `blkid`. |
| 69 | + bd.PartitionInfo.PartitionTableUUID = di.GetPartitionUUID() |
| 70 | +} |
0 commit comments