github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/cmd/ndm_daemonset/probe/blkidprobe.go (about)

     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/v2"
    24  )
    25  
    26  const (
    27  	blkidProbePriority = 4
    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 := &registerProbe{
    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  	if len(bd.FSInfo.FileSystem) == 0 {
    63  		bd.FSInfo.FileSystem = di.GetOnDiskFileSystem()
    64  	}
    65  
    66  	// if the host is CentOS 7, the `libblkid` version on host is `2.23`,
    67  	// but the `PTUUID` tag was start to provide from `2.24`. This will cause
    68  	// the udev cache fetched from host udevd will not contain env `ID_PART_TABLE_UUID`.
    69  	// Fortunately, the `libblkid` version in our base container (ubuntu 16.04)
    70  	// is `2.27.1`, will provide `PTUUID` tag, so we should fetch `PTUUID` from `blkid`.
    71  	if len(bd.PartitionInfo.PartitionTableUUID) == 0 {
    72  		bd.PartitionInfo.PartitionTableUUID = di.GetPartitionTableUUID()
    73  	}
    74  
    75  	// PARTUUID also is fetched using blkid, if udev is unable to get the data
    76  	if len(bd.PartitionInfo.PartitionEntryUUID) == 0 {
    77  		bd.PartitionInfo.PartitionEntryUUID = di.GetPartitionEntryUUID()
    78  	}
    79  }