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

Add support for BRTFS RAID #883

Open
MauriceNino opened this issue Jan 18, 2024 · 1 comment
Open

Add support for BRTFS RAID #883

MauriceNino opened this issue Jan 18, 2024 · 1 comment

Comments

@MauriceNino
Copy link

Is your feature request related to a problem? Please describe.
A user (@zwimer) of my project requested BRTFS support, so it can work like the other RAIDs. Link to the ticket: MauriceNino/dashdot/issues/980

Describe the solution you'd like
I would like to have similar output to what's given for RAIDs in blockDevices(). This includes:

  1. Setting the group for drives that are included in the RAID
  2. Adding an entry similar to the name: 'md...', type: 'raid.' to the output with information about the pool size

What would help to gather the output, would probably be the brtfs cli tool.

e.g.

> sudo btrfs filesystem df [path]

	Data, RAID0: total=4.00GB, used=2.37GB
	System, RAID1: total=8.00MB, used=4.00KB
	System: total=4.00MB, used=0.00
	Metadata, RAID1: total=768.00MB, used=181.83MB

Additional context
I have added the current storage output of the user on his system.

Output:
const disks =  [
  {
    device: '/dev/sda',
    type: 'HD',
    name: 'WDC WD181KFGX-68',
    vendor: 'Western Digital',
    size: 18000207937536,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '0A83',
    serialNum: '',
    interfaceType: 'SATA',
    smartStatus: 'unknown',
    temperature: null
  },
  {
    device: '/dev/sdb',
    type: 'HD',
    name: 'WDC WD181KFGX-68',
    vendor: 'Western Digital',
    size: 18000207937536,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '0A83',
    serialNum: '',
    interfaceType: 'SATA',
    smartStatus: 'unknown',
    temperature: null
  },
  {
    device: '/dev/sdc',
    type: 'HD',
    name: 'WDC WD181KFGX-68',
    vendor: 'Western Digital',
    size: 18000207937536,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '0A83',
    serialNum: '',
    interfaceType: 'SATA',
    smartStatus: 'unknown',
    temperature: null
  },
  {
    device: '/dev/sdd',
    type: 'HD',
    name: 'WDC WD181KFGX-68',
    vendor: 'Western Digital',
    size: 18000207937536,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '0A83',
    serialNum: '',
    interfaceType: 'SATA',
    smartStatus: 'unknown',
    temperature: null
  },
  {
    device: '/dev/nvme0n1',
    type: 'NVMe',
    name: 'Samsung SSD 980 PRO 2TB                 ',
    vendor: 'Samsung',
    size: 2000398934016,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '',
    serialNum: 'S6B0NL0T615860L',
    interfaceType: 'PCIe',
    smartStatus: 'unknown',
    temperature: null
  }
]
const sizes =  [
  {
    fs: '/dev/nvme0n1p3',
    type: 'btrfs',
    size: 1998694907904,
    used: 236039712768,
    available: 1760865275904,
    use: 11.82,
    mount: '/',
    rw: true
  },
  {
    fs: 'efivarfs',
    type: 'efivarfs',
    size: 262144,
    used: 54272,
    available: 202752,
    use: 21.12,
    mount: '/mnt/host/sys/firmware/efi/efivars',
    rw: false
  },
  {
    fs: '/dev/nvme0n1p2',
    type: 'ext4',
    size: 1020702720,
    used: 388988928,
    available: 561250304,
    use: 40.94,
    mount: '/mnt/host/boot',
    rw: true
  },
  {
    fs: '/dev/nvme0n1p1',
    type: 'vfat',
    size: 627900416,
    used: 18206720,
    available: 609693696,
    use: 2.9,
    mount: '/mnt/host/boot/efi',
    rw: true
  },
  {
    fs: '/dev/sdc1',
    type: 'btrfs',
    size: 72000827555840,
    used: 51600711196672,
    available: 2409158074368,
    use: 95.54,
    mount: '/mnt/host/mnt/cryo',
    rw: true
  }
]
const blocks =  [
  {
    name: 'nvme0n1',
    type: 'disk',
    fsType: '',
    mount: '',
    size: 2000398934016,
    physical: 'SSD',
    uuid: '',
    label: '',
    model: 'Samsung SSD 980 PRO 2TB',
    serial: 'S6B0NL0T615860L     ',
    removable: false,
    protocol: 'nvme',
    group: '',
    device: '/dev/nvme0n1'
  },
  {
    name: 'sda',
    type: 'disk',
    fsType: 'btrfs',
    mount: '',
    size: 18000207937536,
    physical: 'HDD',
    uuid: 'a5850a6f-adba-4e34-8fe4-6f191813d5cd',
    label: '',
    model: 'WDC WD181KFGX-68',
    serial: '',
    removable: false,
    protocol: 'sata',
    group: '',
    device: '/dev/sda'
  },
  {
    name: 'sdb',
    type: 'disk',
    fsType: 'btrfs',
    mount: '',
    size: 18000207937536,
    physical: 'HDD',
    uuid: 'a5850a6f-adba-4e34-8fe4-6f191813d5cd',
    label: '',
    model: 'WDC WD181KFGX-68',
    serial: '',
    removable: false,
    protocol: 'sata',
    group: '',
    device: '/dev/sdb'
  },
  {
    name: 'sdc',
    type: 'disk',
    fsType: '',
    mount: '',
    size: 18000207937536,
    physical: 'HDD',
    uuid: '',
    label: '',
    model: 'WDC WD181KFGX-68',
    serial: '',
    removable: false,
    protocol: 'sata',
    group: '',
    device: '/dev/sdc'
  },
  {
    name: 'sdd',
    type: 'disk',
    fsType: '',
    mount: '',
    size: 18000207937536,
    physical: 'HDD',
    uuid: '',
    label: '',
    model: 'WDC WD181KFGX-68',
    serial: '',
    removable: false,
    protocol: 'sata',
    group: '',
    device: '/dev/sdd'
  },
  {
    name: 'zram0',
    type: 'disk',
    fsType: 'swap',
    mount: '[SWAP]',
    size: 8589934592,
    physical: 'SSD',
    uuid: '7bcab061-21a3-4241-b6e3-bfe482fa018d',
    label: 'zram0',
    model: '',
    serial: '',
    removable: false,
    protocol: '',
    group: '',
    device: '/dev/zram0'
  },
  {
    name: 'nvme0n1p1',
    type: 'part',
    fsType: 'vfat',
    mount: '/mnt/host/boot/efi',
    size: 629145600,
    physical: '',
    uuid: '3671-6189',
    label: '',
    model: '',
    serial: '',
    removable: false,
    protocol: 'nvme',
    group: '',
    device: '/dev/nvme0n1'
  },
  {
    name: 'nvme0n1p2',
    type: 'part',
    fsType: 'ext4',
    mount: '/mnt/host/boot',
    size: 1073741824,
    physical: '',
    uuid: '7b45994d-fe45-406d-b7f8-1ec605f6dcd7',
    label: '',
    model: '',
    serial: '',
    removable: false,
    protocol: 'nvme',
    group: '',
    device: '/dev/nvme0n1'
  },
  {
    name: 'nvme0n1p3',
    type: 'part',
    fsType: 'btrfs',
    mount: '/etc/hosts',
    size: 1998694907904,
    physical: '',
    uuid: 'b795618d-1f46-4658-b196-69c7d4348e40',
    label: 'fedora_localhost-live',
    model: '',
    serial: '',
    removable: false,
    protocol: 'nvme',
    group: '',
    device: '/dev/nvme0n1'
  },
  {
    name: 'sdc1',
    type: 'part',
    fsType: 'btrfs',
    mount: '/mnt/host/mnt/cryo',
    size: 18000205840384,
    physical: '',
    uuid: 'a5850a6f-adba-4e34-8fe4-6f191813d5cd',
    label: '',
    model: '',
    serial: '',
    removable: false,
    protocol: '',
    group: '',
    device: '/dev/sdc'
  },
  {
    name: 'sdd1',
    type: 'part',
    fsType: 'btrfs',
    mount: '',
    size: 18000205840384,
    physical: '',
    uuid: 'a5850a6f-adba-4e34-8fe4-6f191813d5cd',
    label: '',
    model: '',
    serial: '',
    removable: false,
    protocol: '',
    group: '',
    device: '/dev/sdd'
  }
]
@zwimer
Copy link

zwimer commented Jan 19, 2024

Hi, here are some useful outputs from btrfs filesystem commands (how you get info about your fs with btrfs):

Size:

$ btrfs fi df -b /mnt/cryo
Data, RAID5: total=53856703610880, used=51651465285632
System, RAID1: total=33554432, used=4571136
Metadata, RAID1: total=95563022336, used=77258293248
GlobalReserve, single: total=536870912, used=0

I don't have any labels on this FS. But if you want to grab them, this is how

$ btrfs fi label /mnt/cryo

To get info about the disks involved:

$ sudo btrfs filesystem show /mnt/cryo  # sudo is required
Label: none  uuid: a5850a6f-adba-4e34-8fe4-6f191813d5cd
        Total devices 4 FS bytes used 47.05TiB
        devid    1 size 16.37TiB used 16.37TiB path /dev/sdc1
        devid    2 size 16.37TiB used 16.37TiB path /dev/sdd1
        devid    3 size 16.37TiB used 16.37TiB path /dev/sda
        devid    4 size 16.37TiB used 16.37TiB path /dev/sdb

For detailed usage info (per disk as well):

$ sudo btrfs filesystem usage -b /mnt/cryo  # sudo gives more info
Overall:
    Device size:                    72000827555840
    Device allocated:               72000823361536
    Device unallocated:                    4194304
    Device missing:                              0
    Device slack:                                0
    Used:                           69023826019944
    Free (estimated):                2205225963522      (min: 2205225963522)
    Free (statfs, df):               2205225963520
    Data ratio:                               1.33
    Metadata ratio:                           2.00
    Global reserve:                      536870912      (used: 0)
    Multiple profiles:                          no

Data,RAID5: Size:53856703610880, Used:51651477647360 (95.91%)
   /dev/sdc1    17952926597120
   /dev/sdd1    17952926597120
   /dev/sda     17951888506880
   /dev/sdb     17951888506880

Metadata,RAID1: Size:95563022336, Used:77258145792 (80.85%)
   /dev/sdc1    47244640256
   /dev/sdd1    47244640256
   /dev/sda     48318382080
   /dev/sdb     48318382080

System,RAID1: Size:33554432, Used:4571136 (13.62%)
   /dev/sdc1      33554432
   /dev/sdd1      33554432

Unallocated:
   /dev/sdc1       1048576
   /dev/sdd1       1048576
   /dev/sda        1048576
   /dev/sdb        1048576

Same command as above but without sudo; it will have less information and some values might be odd (like slack and free and unallocated; compare with the sudo version for more info):

$ btrfs filesystem usage -b /mnt/cryo  # non-sudo version
WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
Overall:
    Device size:                    72000827555840
    Device allocated:                 191193153536
    Device unallocated:             71809634402304
    Device missing:                              0
    Device slack:               18446672213508612096
    Used:                             154525597696
    Free (estimated):                            0      (min: 9223407941671976960)
    Free (statfs, df):               2205223903232
    Data ratio:                               0.00
    Metadata ratio:                           2.00
    Global reserve:                      536870912      (used: 0)
    Multiple profiles:                          no

Data,RAID5: Size:53856703610880, Used:51651479707648 (95.91%)

Metadata,RAID1: Size:95563022336, Used:77258227712 (80.85%)

System,RAID1: Size:33554432, Used:4571136 (13.62%)

There are also options to show this in a more compact table (might be more parsable)

This is what df -Thl gives by the way:

/dev/sdc1      btrfs      66T   48T  2.1T  96% /mnt/cryo

As you can see ,the percentage is correct (matches with previous info) but the capacity is only the sum of the disks, it doesn't take into account the loss of data due to parity overhead like the commands above do.

If you want to poke around more and have a btrfs mount yourself, btrfs fi help will give you info about the main tool I used above to get all that info.

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

No branches or pull requests

3 participants