jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.64k stars 180 forks source link

Add WithLoopDevices to report loop devices #310

Closed Itxaka closed 2 years ago

Itxaka commented 2 years ago

Currently we skipp over all loop devices in the system and with no possibility of reporting those.

This patch introduces a new option to Block that allows us to report loop devices as disk and their partitions like if they were normal disks.

This patch does not modify any existing functionality or alters anything with the default values.

With WithLoopDevices enabled this reports the same info for loop devices as with other disks, including size, fs, mountpoints and so on.

Signed-off-by: Itxaka igarcia@suse.com

Itxaka commented 2 years ago

@fromanirh any comments on this? thanks!

ffromani commented 2 years ago

thanks @Itxaka for your contribution! I'll review today/tomorrow

jaypipes commented 2 years ago

@Itxaka what is the use case for a go-hardware library tracking loopback devices? :)

Itxaka commented 2 years ago

well, we could make the same question about returning mount points and filesystems no? Those are not hardware related at all, more like system status, so thinking in terms of ghw providing info about the current system in which its running, I want to see all the mountpoints, including those from loop devices which are mounted. I.E. I want to scan all mountpoints in the system to do something with them, report of scan or whatever, loop devices mounted are part of that system.

Thats the best I can do to sell this feature LOL :P

If you want a specific use case, we use loop devices in our installer[0] to test real installs, not really to a real filesystem, but to a loop device so we dont break any real disks, so we do some partition discovery and mounting. We currently use lsblk directly, but it would be much nicer to use a pure golang lib instead of depending on lsblk. Having loop mounts discovery in ghw helps us :)

[0] https://github.com/rancher-sandbox/elemental

jaypipes commented 2 years ago

well, we could make the same question about returning mount points and filesystems no? Those are not hardware related at all, more like system status, so thinking in terms of ghw providing info about the current system in which its running, I want to see all the mountpoints, including those from loop devices which are mounted. I.E. I want to scan all mountpoints in the system to do something with them, report of scan or whatever, loop devices mounted are part of that system.

Thats the best I can do to sell this feature LOL :P

If you want a specific use case, we use loop devices in our installer[0] to test real installs, not really to a real filesystem, but to a loop device so we dont break any real disks, so we do some partition discovery and mounting. We currently use lsblk directly, but it would be much nicer to use a pure golang lib instead of depending on lsblk. Having loop mounts discovery in ghw helps us :)

[0] https://github.com/rancher-sandbox/elemental

Fair enough. You've sold me on your use case.

I'll do a full review of the PR shortly.

Itxaka commented 2 years ago

any update on this @jaypipes ?

Itxaka commented 2 years ago

umm, failing on ubuntu but I cant reproduce it locally. As that its picking up the underlaying os devices Im sure there is something wrong in the code..Will try to debug

Itxaka commented 2 years ago

Found it, missing a value :D