<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 22, 2021, 13:39 Richard W.M. Jones <<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The patch doesn't compile for me:<br>
<br>
pipe-ops.c:121:17: error: initialization of ‘_Bool (*)(struct rw *, uint64_t,  uint64_t,  _Bool)’ {aka ‘_Bool (*)(struct rw *, long unsigned int,  long unsigned int,  _Bool)’} from incompatible pointer type ‘_Bool (*)(struct rw *, uint64_t,  uint64_t)’ {aka ‘_Bool (*)(struct rw *, long unsigned int,  long unsigned int)’} [-Werror=incompatible-pointer-types]<br>
  121 |   .synch_zero = pipe_synch_trim_zero,<br>
      |                 ^~~~~~~~~~~~~~~~~~~~<br>
pipe-ops.c:121:17: note: (near initialization for ‘pipe_ops.synch_zero’)<br>
pipe-ops.c:133:18: error: initialization of ‘_Bool (*)(struct rw *, struct command *, nbd_completion_callback,  _Bool)’ from incompatible pointer type ‘_Bool (*)(struct rw *, struct command *, nbd_completion_callback)’ [-Werror=incompatible-pointer-types]<br>
  133 |   .asynch_zero = pipe_asynch_trim_zero,<br>
      |                  ^~~~~~~~~~~~~~~~~~~~~<br>
pipe-ops.c:133:18: note: (near initialization for ‘pipe_ops.asynch_zero’)<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">It compiled here on top of master, will check again.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
More comments below.<br>
<br>
On Sun, Feb 21, 2021 at 03:09:05AM +0200, Nir Soffer wrote:<br>
> diff --git a/copy/file-ops.c b/copy/file-ops.c<br>
> index 2a239d0..d0b9447 100644<br>
> --- a/copy/file-ops.c<br>
> +++ b/copy/file-ops.c<br>
> @@ -100,10 +100,9 @@ file_synch_write (struct rw *rw,<br>
>  }<br>
>  <br>
>  static bool<br>
> -file_synch_trim (struct rw *rw, uint64_t offset, uint64_t count)<br>
> +file_punch_hole(int fd, uint64_t offset, uint64_t count)<br>
<br>
(Style) missing space before '(' ...<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Sorry, will fix in next version.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
>  {<br>
>  #ifdef FALLOC_FL_PUNCH_HOLE<br>
> -  int fd = rw->u.local.fd;<br>
>    int r;<br>
>  <br>
>    r = fallocate (fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,<br>
> @@ -113,17 +112,14 @@ file_synch_trim (struct rw *rw, uint64_t offset, uint64_t count)<br>
>      exit (EXIT_FAILURE);<br>
>    }<br>
>    return true;<br>
> -#else /* !FALLOC_FL_PUNCH_HOLE */<br>
> -  return false;<br>
>  #endif<br>
> +  return false;<br>
>  }<br>
>  <br>
>  static bool<br>
> -file_synch_zero (struct rw *rw, uint64_t offset, uint64_t count)<br>
> +file_zero_range(int fd, uint64_t offset, uint64_t count)<br>
<br>
... and here<br>
<br>
>  {<br>
> -  if (S_ISREG (rw->u.local.stat.st_mode)) {<br>
>  #ifdef FALLOC_FL_ZERO_RANGE<br>
> -    int fd = rw->u.local.fd;<br>
>      int r;<br>
>  <br>
>      r = fallocate (fd, FALLOC_FL_ZERO_RANGE, offset, count);<br>
> @@ -133,11 +129,13 @@ file_synch_zero (struct rw *rw, uint64_t offset, uint64_t count)<br>
>      }<br>
>      return true;<br>
>  #endif<br>
> -  }<br>
> -  else if (S_ISBLK (rw->u.local.stat.st_mode) &&<br>
> -           IS_ALIGNED (offset | count, rw->u.local.sector_size)) {<br>
> +  return false;<br>
> +}<br>
> +<br>
> +static bool<br>
> +file_zeroout(int fd, uint64_t offset, uint64_t count)<br>
<br>
... and here<br>
<br>
> +{<br>
>  #ifdef BLKZEROOUT<br>
> -    int fd = rw->u.local.fd;<br>
>      int r;<br>
>      uint64_t range[2] = {offset, count};<br>
>  <br>
> @@ -148,6 +146,31 @@ file_synch_zero (struct rw *rw, uint64_t offset, uint64_t count)<br>
>      }<br>
>      return true;<br>
>  #endif<br>
> +    return false;<br>
> +}<br>
> +<br>
> +static bool<br>
> +file_synch_trim (struct rw *rw, uint64_t offset, uint64_t count)<br>
> +{<br>
> +  return file_punch_hole(rw->u.local.fd, offset, count);<br>
> +}<br>
> +<br>
> +static bool<br>
> +file_synch_zero (struct rw *rw, uint64_t offset, uint64_t count, bool allocate)<br>
<br>
... and overlong line.<br>
<br>
> +{<br>
> +  int fd = rw->u.local.fd;<br>
> +<br>
> +  if (S_ISREG (rw->u.local.stat.st_mode)) {<br>
> +    if (allocate) {<br>
> +        return file_zero_range (fd, offset, count);<br>
> +    } else {<br>
> +        return file_punch_hole (fd, offset, count);<br>
> +    }<br>
> +  }<br>
> +  else if (S_ISBLK (rw->u.local.stat.st_mode) &&<br>
> +           IS_ALIGNED (offset | count, rw->u.local.sector_size)) {<br>
> +    /* Always allocate, discard and gurantee zeroing. */<br>
> +    return file_zeroout (fd, offset, count);<br>
>    }<br>
>    return false;<br>
<br>
In the S_ISBLK && not aligned case, is giving up OK?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Not sure what do you mean by this, but it returns false love ke the previous version, right?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> diff --git a/copy/nbdcopy.h b/copy/nbdcopy.h<br>
> index 69fac2a..21d09bf 100644<br>
> --- a/copy/nbdcopy.h<br>
> +++ b/copy/nbdcopy.h<br>
> @@ -134,7 +134,8 @@ struct rw_ops {<br>
>    bool (*synch_trim) (struct rw *rw, uint64_t offset, uint64_t count);<br>
>  <br>
>    /* Synchronously zero.  If not possible, returns false. */<br>
> -  bool (*synch_zero) (struct rw *rw, uint64_t offset, uint64_t count);<br>
> +  bool (*synch_zero) (struct rw *rw, uint64_t offset, uint64_t count,<br>
> +                      bool allocate);<br>
<br>
After this change ops->synch_trim and ops->asynch_trim are no longer<br>
used, so I guess they should be removed completely from the code?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yes, unless we have a reason to keep the trim option.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Rich.<br>
<br>
-- <br>
Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones" rel="noreferrer noreferrer" target="_blank">http://people.redhat.com/~rjones</a><br>
Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
virt-builder quickly builds VMs from scratch<br>
<a href="http://libguestfs.org/virt-builder.1.html" rel="noreferrer noreferrer" target="_blank">http://libguestfs.org/virt-builder.1.html</a><br>
<br>
</blockquote></div></div></div>