Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/host: disk_is_available function only validates mounted disks and not others #276

Open
rushikeshjadhav opened this issue Feb 20, 2025 · 2 comments

Comments

@rushikeshjadhav
Copy link
Contributor

In following case, disk_is_available('sdb') returns True which should not be the case.

def disk_is_available(self, disk):

[18:26 xcp-ng-xs1 ~]# lsblk 
NAME                                                                                     MAJ:MIN  RM   SIZE RO TYPE MOUNTPOINT
sdb                                                                                        8:16    0   500G  0 disk 
├─linstor_group-thin_device_tmeta                                                        253:1     0   128M  0 lvm  
│ └─linstor_group-thin_device-tpool                                                      253:3     0 499.8G  0 lvm  
│   ├─linstor_group-thin_device                                                          253:4     0 499.8G  0 lvm  
│   └─linstor_group-xcp--persistent--database_00000                                      253:5     0     1G  0 lvm  
│     └─drbd1000                                                                         147:1000  0     1G  0 disk 
└─linstor_group-thin_device_tdata                                                        253:2     0 499.8G  0 lvm  
  └─linstor_group-thin_device-tpool                                                      253:3     0 499.8G  0 lvm  
    ├─linstor_group-thin_device                                                          253:4     0 499.8G  0 lvm  
    └─linstor_group-xcp--persistent--database_00000                                      253:5     0     1G  0 lvm  
      └─drbd1000                                                                         147:1000  0     1G  0 disk 
sr0                                                                                       11:0     1  1024M  0 rom  
sdc                                                                                        8:32    0   500G  0 disk 
sda                                                                                        8:0     0    50G  0 disk 
├─sda4                                                                                     8:4     0   512M  0 part 
├─sda2                                                                                     8:2     0    18G  0 part 
├─sda5                                                                                     8:5     0     4G  0 part /var/log
├─sda3                                                                                     8:3     0   8.5G  0 part 
│ └─XSLocalEXT--8900cca8--706a--d7f2--447b--bff4129333a3-8900cca8--706a--d7f2--447b--bff4129333a3
                                                                                         253:0     0   8.5G  0 lvm  /run/sr-mount/8900cca8-706a-d7f2-447b-bff4129333a3
├─sda1                                                                                     8:1     0    18G  0 part /
└─sda6                                                                                     8:6     0     1G  0 part [SWAP]
@Wescoeur
Copy link
Member

In fact this function checks if a disk is mounted. If a filesystem is configured on it, we consider that we can use the disk, for DRBD it is perhaps a bit more restrictive. I suppose we could explicitly check if DRBDs are present. But in the case of a LVM VG we consider that the disk is free, which is not very symmetrical.

@rushikeshjadhav
Copy link
Contributor Author

rushikeshjadhav commented Feb 21, 2025

In fact this function checks if a disk is mounted. If a filesystem is configured on it, we consider that we can use the disk, for DRBD it is perhaps a bit more restrictive. I suppose we could explicitly check if DRBDs are present. But in the case of a LVM VG we consider that the disk is free, which is not very symmetrical.

I see that this function checks whether a disk is available for use (i.e., not mounted). The code further does not use the disks that have any mountpoint associated with them.

    def disk_is_available(self, disk):
        return len(self.ssh(['lsblk', '-n', '-o', 'MOUNTPOINT', '/dev/' + disk]).strip()) == 0

I was thinking to use blkid /dev/disk in here instead of lsblk. blkid returns 2 if there is nothing on the disk e.g. LVM, gpt, etc. hence marking disk_is_available.

e.g.

[22:35 xcp-ng-xs1 ~]# blkid /dev/sda
/dev/sda: PTTYPE="gpt" 
[22:35 xcp-ng-xs1 ~]# blkid /dev/sdb
/dev/sdb: UUID="OAcOvb-o0bE-etIW-m3Zk-Pf29-GCe3-92hVt4" TYPE="LVM2_member" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants