[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



David Allan wrote:
> diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
...

Hi Dave,

> +static int
> +storageVolumeZeroSparseFile(virStorageVolDefPtr vol,
> +                            struct stat *st,
> +                            int fd)

Since the only use of "st" is for st->st_size,
please consider using a simpler "size_t size" parameter.
If you opt to keep the "struct stat *" pointer parameter,
it should be "const".

> +{
> +    int ret = -1;
> +    char errbuf[64];
> +
> +    ret = ftruncate(fd, 0);
> +    if (ret == -1) {
> +        virReportSystemError(ret,
> +                             _("Failed to truncate volume with "
> +                               "path '%s' to 0 bytes: '%s'"),
> +                             vol->target.path,
> +                             virStrerror(errno, errbuf, sizeof(errbuf)));
> +        goto out;
> +    }
> +
> +    ret = ftruncate(fd, st->st_size);
...
> +static int
> +storageZeroExtent(virStorageVolDefPtr vol,
> +                  struct stat *st,
> +                  int fd,
> +                  size_t extent_start,
> +                  size_t extent_length,
> +                  char *writebuf,
> +                  size_t *bytes_zeroed)
> +{

Since the only use of "st" is for st->st_blksize,
please consider using a simpler "size_t blksize" parameter.

> +    int ret = -1, written;
> +    size_t remaining, write_size;
> +    char errbuf[64];
> +
> +    VIR_DEBUG("extent logical start: %zu len: %zu ",
> +              extent_start, extent_length);
> +
> +    if ((ret = lseek(fd, extent_start, SEEK_SET)) < 0) {
> +        virReportSystemError(ret, "Failed to seek to position %zu in volume "
> +                             "with path '%s': '%s'",
> +                             extent_start, vol->target.path,
> +                             virStrerror(errno, errbuf, sizeof(errbuf)));
> +        goto out;
> +    }
> +
> +    remaining = extent_length;
> +    while (remaining > 0) {
> +
> +        write_size = (st->st_blksize < remaining) ? st->st_blksize : remaining;
...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]