Hello,

Thank you for the patch. I reviewed the supplied diff statically and have a
few concerns about splitting a single write request into multiple RPCs. I
have not compiled or tested the changes.

   1.

   *Concurrent writes between chunks*

   Each chunk is submitted through a separate __io_write() call. Another
   writer may therefore run between chunks. With a shared file position, this
   can affect the placement of subsequent chunks; with append mode, another
   writer’s data may appear between them.

   Could we instead cap the request size and return the result of a single
   RPC as a short write? If multiple RPCs are necessary, the intended
   concurrency semantics should be explained and verified.
   2.

   *Offset advancement*

   offset += wrote is performed before checking for a short write or
   determining whether another iteration is needed. It therefore calculates a
   new offset even after the final transfer.

   If the loop is retained, please advance the offset only when another RPC
   is required, with a check that the resulting value is representable in
   loff_t.
   3.

   *Modification of *nbytes before success*

   The patch uses *nbytes as the current chunk size. Consequently, an error
   on the first RPC leaves it modified, whereas the previous implementation
   updated it only after a successful call.

   A local chunk variable would preserve the previous error-path behavior
   and separate the request length from the returned byte count.
   4.

   *Rationale for INT32_MAX*

   Please document which interface constraint establishes this limit. If it
   derives from the maximum encoded RPC message size, any applicable message
   overhead should also be considered.

The short-write termination condition correctly handles a zero-byte result
for a nonzero request. Returning the accumulated byte count when a later
RPC fails also preserves knowledge of the completed transfers.

For validation, I suggest covering the chunk-size boundary, short and
zero-byte results, errors after an earlier successful chunk, concurrent
writers, and explicit offsets near the representable limit.

Best regards,

Alperen Erkan

27 Kas 2026 Cum 20:33 tarihinde Ahmed Khider <[email protected]> şunu
yazdı:

> ---
>  hurd/fd-write.c | 44 ++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 36 insertions(+), 8 deletions(-)
>
> diff --git a/hurd/fd-write.c b/hurd/fd-write.c
> index 2dc2eedf..76ea1e43 100644
> --- a/hurd/fd-write.c
> +++ b/hurd/fd-write.c
> @@ -18,6 +18,7 @@
>
>  #include <errno.h>
>  #include <unistd.h>
> +#include <stdint.h>
>  #include <hurd.h>
>  #include <hurd/fd.h>
>
> @@ -27,20 +28,47 @@ _hurd_fd_write (struct hurd_fd *fd,
>  {
>    error_t err;
>    vm_size_t wrote;
> +  vm_size_t wbytes = *nbytes;
> +  vm_size_t tbytes = 0;
>
>    error_t writefd (io_t port)
> +  {
> +    return __io_write (port, buf, *nbytes, offset, &wrote);
> +  }
> +
> +  do
>      {
> -      return __io_write (port, buf, *nbytes, offset, &wrote);
> -    }
> +      *nbytes = wbytes > INT32_MAX ? INT32_MAX : wbytes;
> +
> +      err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty,
> writefd));
> +      if (err)
> +       {
> +         if (tbytes > 0)
> +           {
> +             *nbytes = tbytes;
> +             return 0;
> +
> +           }
> +         return err;
> +       }
> +
> +      if (__glibc_unlikely (wrote > *nbytes))  /* Sanity check for bogus
> server.  */
> +       return EGRATUITOUS;
>
> -  err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty,
> writefd));
> -  if (err)
> -    return err;
> +      wbytes -=wrote;
> +      tbytes += wrote;
>
> -  if (__glibc_unlikely (wrote > *nbytes))      /* Sanity check for bogus
> server.  */
> -    return EGRATUITOUS;
> +      buf = (const char*) buf + wrote;
>
> -  *nbytes = wrote;
> +      if(offset != -1)
> +       offset += wrote;
> +
> +      if(wrote < *nbytes)
> +       break;
> +
> +    }
> +  while(wbytes != 0);
>
> +  *nbytes = tbytes;
>    return 0;
>  }
> --
> 2.47.3
>
>
>

Reply via email to