[Libguestfs] [PATCH v6 2/7] daemon: Changing the way that we detect if a device contains partitions.

Richard W.M. Jones rjones at redhat.com
Wed May 2 09:44:52 UTC 2018


On Tue, May 01, 2018 at 03:53:59AM +0300, Mykola Ivanets wrote:
> Instead of using part_to_dev to find such devices we open the device's
> directory under /sys/block/<device> and look for entries starting with
> <device>, eg. /sys/block/sda/sda1.

> +(* Look to see if device can directly contain filesystem (RHBZ#590167).
> + * Partitioned devices cannot contain fileystem, so we will exclude such devices.
> + *)

Let's keep lines to < 80 characters.

> +and is_not_partitioned_device device =
> +  assert (String.is_prefix device "/dev/");
> +  let device = String.sub device 5 (String.length device - 5) in
> +  let dir = "/sys/block/" ^ device in
> +
> +  try
> +    (* Open the device's directory under /sys/block/<device> and
> +     * look for entries starting with <device>, eg. /sys/block/sda/sda1
> +     *)
> +    let parts = Array.to_list (Sys.readdir dir) in
> +    let has_partition = List.exists (fun part -> String.is_prefix part device) parts in

Also this line is >= 80 characters, but could easily be changed
so it's shorter.

> +    not has_partition
> +  with Sys_error (_) -> true

This is the real problem.  What Sys_error is expected here?  As far as
I can tell if anything throws Sys_error (or any other exception) here
then it's a real bug, so we shouldn't hide the error message.  If
you're not expecting a particular Sys_error, then don't try to catch
anything.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html




More information about the Libguestfs mailing list