[Pdbg] [PATCH] Revert "htm: Use splice() to copy dump"

Michael Neuling mikey at neuling.org
Tue Dec 1 11:37:35 AEDT 2020


On Thu, 2020-11-26 at 13:38 +1100, Rashmica Gupta wrote:
> This reverts commit 436eb8c74fb4a762b61837ee27ddbd6b5fe21334.
> Unable to use splice on newer kernels due to 36e2c7421f02 ("fs: don't
> allow splice read/write without explicit ops"). So revert back to plain
> old read/write.

Is there a performance penalty with this and if so how much? 

Mikey

> 
> Signed-off-by: Rashmica Gupta <rashmica.g at gmail.com>
> ---
>  libpdbg/htm.c | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/libpdbg/htm.c b/libpdbg/htm.c
> index 0d755dd..43cef84 100644
> --- a/libpdbg/htm.c
> +++ b/libpdbg/htm.c
> @@ -966,39 +966,41 @@ static int do_htm_status(struct htm *htm)
>         return 1;
>  }
>  
> +#define COPY_BUF_SIZE getpagesize()
>  static int copy_file(int output, int input, uint64_t size)
>  {
> +       char *buf;
>         size_t r;
> -       int pipefd[2];
> -       int rc = -1;
>  
> -       if (pipe(pipefd)) {
> -               perror("pipe");
> -               exit(1);
> +       buf = malloc(COPY_BUF_SIZE);
> +       if (!buf) {
> +               PR_ERROR("Can't malloc buffer\n");
> +               return -1;
>         }
>  
>         while (size) {
> -               r = splice(input, 0, pipefd[1], 0, size, 0);
> +               r = read(input, buf, MIN(COPY_BUF_SIZE, size));
>                 if (r == -1) {
>                         PR_ERROR("Failed to read\n");
>                         goto out;
>                 }
>                 if (r == 0) {
> -                       PR_ERROR("Unexpect EOF\n");
> +                       PR_ERROR("EOF\n");
>                         goto out;
>                 }
>  
> -               if (splice(pipefd[0], 0, output, 0, r, 0) != r) {
> +               if (write(output, buf, r) != r) {
>                         PR_ERROR("Short write!\n");
>                         goto out;
>                 }
>                 size -= r;
>         }
> -       rc = 0;
> +
> +       return 0;
> +
>  out:
> -       close(pipefd[1]);
> -       close(pipefd[0]);
> -       return rc;
> +       free(buf);
> +       return -1;
>  
>  }
>  



More information about the Pdbg mailing list