[sheepdog] [PATCH v4 2/2] sheepdog: support user-defined redundancy option

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Nov 1 15:20:04 CET 2013


At Thu, 31 Oct 2013 13:49:28 +0800,
Liu Yuan wrote:
> 
> +/*
> + * Sheepdog support two kinds of redundancy, full replication and erasure
> + * coding.
> + *
> + * # create a fully replicated vdi with x copies
> + * -o redundancy=x (1 <= x <= SD_MAX_COPIES)
> + *
> + * # create a erasure coded vdi with x data strips and y parity strips
> + * -o redundancy=x:y (x must be one of {2,4,8,16} and 1 <= y < SD_EC_MAX_STRIP)
> + */
> +static int parse_redundancy(BDRVSheepdogState *s, const char *opt)
> +{
> +    struct SheepdogInode *inode = &s->inode;
> +    const char *n1, *n2;
> +    uint8_t copy, parity;
> +    char p[10];
> +
> +    strncpy(p, opt, sizeof(p));

strncpy() is not safe here.  Please use pstrcpy() instead.

> +    n1 = strtok(p, ":");
> +    n2 = strtok(NULL, ":");
> +
> +    if ((n1 && !is_numeric(n1)) || (n2 && !is_numeric(n2))) {
> +        return -EINVAL;
> +    }

This cannot detect an error when 'opt' is empty.  Actually, the
following command causes a segfault.

 $ qemu-img create -o redundancy= sheepdog:test 4G

Thanks,

Kazutaka



More information about the sheepdog mailing list