All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Herve Poussineau <hpoussin@reactos.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] slirp: improve TFTP performance
Date: Mon, 18 Apr 2011 16:04:05 +0200	[thread overview]
Message-ID: <20110418140405.GD16178@volta.aurel32.net> (raw)
In-Reply-To: <1302549054-2248-4-git-send-email-hpoussin@reactos.org>

On Mon, Apr 11, 2011 at 07:10:54PM +0000, Herve Poussineau wrote:
> From: Herv? Poussineau <hpoussin@reactos.org>
> 
> When transfering a file, keep it open during the whole transfer,
> instead of opening/closing it for each block.
> 
> Signed-off-by: Herv? Poussineau <hpoussin@reactos.org>
> ---
>  slirp/tftp.c |   20 ++++++++++++--------
>  slirp/tftp.h |    1 +
>  2 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/slirp/tftp.c b/slirp/tftp.c
> index 7e63269..48748f1 100644
> --- a/slirp/tftp.c
> +++ b/slirp/tftp.c
> @@ -37,6 +37,10 @@ static inline void tftp_session_update(struct tftp_session *spt)
>  
>  static void tftp_session_terminate(struct tftp_session *spt)
>  {
> +    if (spt->fd >= 0) {
> +        close(spt->fd);
> +        spt->fd = -1;
> +    }
>      qemu_free(spt->filename);
>      spt->slirp = NULL;
>  }
> @@ -54,7 +58,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
>  
>      /* sessions time out after 5 inactive seconds */
>      if ((int)(curtime - spt->timestamp) > 5000) {
> -        qemu_free(spt->filename);
> +        tftp_session_terminate(spt);
>          goto found;
>      }
>    }
> @@ -64,6 +68,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
>   found:
>    memset(spt, 0, sizeof(*spt));
>    memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip));
> +  spt->fd = -1;
>    spt->client_port = tp->udp.uh_sport;
>    spt->slirp = slirp;
>  
> @@ -95,23 +100,22 @@ static int tftp_session_find(Slirp *slirp, struct tftp_t *tp)
>  static int tftp_read_data(struct tftp_session *spt, uint32_t block_nr,
>                            uint8_t *buf, int len)
>  {
> -  int fd;
>    int bytes_read = 0;
>  
> -  fd = open(spt->filename, O_RDONLY | O_BINARY);
> +  if (spt->fd < 0) {
> +    spt->fd = open(spt->filename, O_RDONLY | O_BINARY);
> +  }
>  
> -  if (fd < 0) {
> +  if (spt->fd < 0) {
>      return -1;
>    }
>  
>    if (len) {
> -    lseek(fd, block_nr * 512, SEEK_SET);
> +    lseek(spt->fd, block_nr * 512, SEEK_SET);
>  
> -    bytes_read = read(fd, buf, len);
> +    bytes_read = read(spt->fd, buf, len);
>    }
>  
> -  close(fd);
> -
>    return bytes_read;
>  }

Given you are rewriting this most of this function, it's probably the
good moment to also fix the indentation to 4 spaces.

> diff --git a/slirp/tftp.h b/slirp/tftp.h
> index 471f22e..51704e4 100644
> --- a/slirp/tftp.h
> +++ b/slirp/tftp.h
> @@ -33,6 +33,7 @@ struct tftp_t {
>  struct tftp_session {
>      Slirp *slirp;
>      char *filename;
> +    int fd;
>  
>      struct in_addr client_ip;
>      uint16_t client_port;
> -- 
> 1.6.0.2.GIT
> 

Except the minor nit above:

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

  reply	other threads:[~2011-04-18 14:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 19:10 [Qemu-devel] [PATCH 0/3] slirp: misc fixes Herve Poussineau
2011-04-11 19:10 ` [Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option Herve Poussineau
2011-04-11 19:10   ` [Qemu-devel] [PATCH 2/3] slirp: Handle more than 65535 blocks in TFTP transfers Herve Poussineau
2011-04-11 19:10     ` [Qemu-devel] [PATCH 3/3] slirp: improve TFTP performance Herve Poussineau
2011-04-18 14:04       ` Aurelien Jarno [this message]
2011-04-18 14:02     ` [Qemu-devel] [PATCH 2/3] slirp: Handle more than 65535 blocks in TFTP transfers Aurelien Jarno
2011-04-16  9:15   ` [Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option Stefan Hajnoczi
2011-04-17 18:16     ` Hervé Poussineau
2011-04-17 19:53       ` Stefan Hajnoczi
2011-04-17 12:39   ` Avi Kivity
2011-04-18 14:02   ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110418140405.GD16178@volta.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=hpoussin@reactos.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.