[libvirt] [PATCH 8/9] Simplified version of volume zeroing based on feedback from the list.

Eric Blake eblake at redhat.com
Tue Mar 2 23:44:06 UTC 2010


According to David Allan on 3/2/2010 3:13 PM:
> +    ret = ftruncate(fd, st->st_size);
> +    if (ret == -1) {
> +        virReportSystemError(ret,
> +                             _("Failed to truncate volume with "
> +                               "path '%s' to %llu bytes: '%s'\n"),
> +                             vol->target.path, st->st_size,

off_t is not guaranteed to be the same as long long.  You need a cast.

> +                             virStrerror(errno, errbuf, sizeof(errbuf)));
> +    }
> +
> +out:
> +    return ret;
> +}
> +
> +
> +static int
> +storageZeroExtent(virStorageVolDefPtr vol,
> +                  struct stat *st,
> +                  int fd,
> +                  size_t extent_start,
> +                  size_t extent_length,
> +                  char *writebuf,
> +                  size_t *bytes_zeroed)

Is size_t the right type for the extent, or do we want off_t?

> +    size_t remaining, write_size;
...
> +        if (written < 0) {
> +            virReportSystemError(written,
> +                                 _("Failed to write to storage volume with "
> +                                   "path '%s': '%s' "
> +                                   "(attempted to write %d bytes)"),
> +                                 vol->target.path,
> +                                 virStrerror(errno, errbuf, sizeof(errbuf)),
> +                                 write_size);

%d and write_size are not compatible.

> +    memset(&st, 0, sizeof(st));
> +
> +    if (fstat(fd, &st) == -1) {

The memset is wasted work.  stat() is sufficient for initializing st.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 320 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100302/08ad9369/attachment-0001.sig>


More information about the libvir-list mailing list