[Libguestfs] [PATCH 1/2] New API: list_md_devices
Richard W.M. Jones
rjones at redhat.com
Thu Nov 10 14:53:48 UTC 2011
On Thu, Nov 10, 2011 at 02:19:11PM +0000, Matthew Booth wrote:
> + /* Look for directories under /sys/block matching md[0-9]*
> + * As an additional check, we also make sure they have a md subdirectory */
> + int err = glob(PREFIX "[0-9]*" SUFFIX, GLOB_ERR, NULL, &mds);
> + if (err == GLOB_NOSPACE) {
> + reply_with_error("OOM searching for md devices");
> + goto error;
> + } else if (err == GLOB_ABORTED) {
> + reply_with_error("Read error searching for md devices");
> + goto error;
Since glob is supposed to set errno on error, I'd prefer:
reply_with_perror ("glob");
for both of the branches above (combine them into a single branch
if you like).
> + } else if (err == GLOB_NOMATCH) {
> + /* This is fine */
> + }
I think this branch should just be dropped.
> + for (size_t i = 0; i < mds.gl_pathc; i++) {
> + size_t len = strlen(mds.gl_pathv[i]) - strlen(PREFIX) - strlen(SUFFIX);
> +
> +#define DEV "/dev/md"
> + char *dev = malloc(strlen(DEV) + len + 1);
Need to check the return value from malloc and reply_with_perror /
goto error on failure.
> +# Create a raid1 based on the 2 disks
> +debug sh "/usr/bin/yes | mdadm -C /dev/md/test --level=1 --raid-devices=2 /dev/vda /dev/vdb >/dev/null 2>&1"
I guessed we'd be running the debug backdoor here to create devices.
Is it not worth binding this call too?
> +# Ensure list-md-devices now returns the newly create md device
"created"
Generally looking good.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
More information about the Libguestfs
mailing list