[Libguestfs] [PATCH 14/27] daemon: Reimplement ‘lvs’ API in OCaml.
Pino Toscano
ptoscano at redhat.com
Wed Jul 19 13:21:19 UTC 2017
On Friday, 14 July 2017 15:39:22 CEST Richard W.M. Jones wrote:
> +let lvs_has_S_opt = lazy (
> + let out = command "lvm" ["lvs"; "--help"] in
> + String.find out "-S" >= 0
> +)
Could you please add the comment for this?
(* Check whether lvs has -S to filter its output.
* It is available only in lvm2 >= 2.02.107.
*)
> +and convert_lvm_output ?(prefix = "") out =
> + let lines = String.nsplit "\n" out in
> +
> + (* Skip leading and trailing ("pvs", I'm looking at you) whitespace. *)
> + let lines = List.map String.trim lines in
> +
> + (* Skip empty lines. *)
> + let lines = List.filter ((<>) "") lines in
> +
> + (* Ignore "unknown device" message (RHBZ#1054761). *)
> + let lines = List.filter ((<>) "unknown device") lines in
> +
> + (* Add a prefix? *)
> + let lines = List.map ((^) prefix) lines in
A small optimization here could be to avoid the map if the prefix is
empty:
let lines =
if prefix <> "" then List.map ((^) prefix) lines
else lines in
(or even not giving ?prefix a default value, and matching on None/Some)
--
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170719/7a25d9a8/attachment.sig>
More information about the Libguestfs
mailing list