qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: "Hervé Poussineau" <hpoussin@reactos.org>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2 1/3] slirp: improve TFTP performance
Date: Mon, 10 Sep 2012 20:57:37 +0200	[thread overview]
Message-ID: <504E3821.5020207@siemens.com> (raw)
In-Reply-To: <1347300346-14482-2-git-send-email-hpoussin@reactos.org>

On 2012-09-10 20:05, Hervé Poussineau wrote:
> 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>
> Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
>  slirp/tftp.c |   32 ++++++++++++++++++--------------
>  slirp/tftp.h |    1 +
>  2 files changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/slirp/tftp.c b/slirp/tftp.c
> index b78765f..520dbd6 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;
> +    }
>      g_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) {
> -        g_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,24 +100,23 @@ static int tftp_session_find(Slirp *slirp, struct tftp_t *tp)
>  static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr,
>                            uint8_t *buf, int len)
>  {
> -  int fd;
> -  int bytes_read = 0;
> -
> -  fd = open(spt->filename, O_RDONLY | O_BINARY);
> +    int bytes_read = 0;
>  
> -  if (fd < 0) {
> -    return -1;
> -  }
> +    if (spt->fd < 0) {
> +        spt->fd = open(spt->filename, O_RDONLY | O_BINARY);
> +    }
>  
> -  if (len) {
> -    lseek(fd, block_nr * 512, SEEK_SET);
> +    if (spt->fd < 0) {
> +        return -1;
> +    }
>  
> -    bytes_read = read(fd, buf, len);
> -  }
> +    if (len) {
> +        lseek(spt->fd, block_nr * 512, SEEK_SET);
>  
> -  close(fd);
> +        bytes_read = read(spt->fd, buf, len);
> +    }
>  
> -  return bytes_read;
> +    return bytes_read;
>  }
>  
>  static int tftp_send_oack(struct tftp_session *spt,
> diff --git a/slirp/tftp.h b/slirp/tftp.h
> index 72e5e91..9c364ea 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;
> 

Thanks, added to slirp queue.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

  reply	other threads:[~2012-09-10 18:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-10 18:05 [Qemu-devel] [PATCH v2 0/3] slirp: tftp server improvements Hervé Poussineau
2012-09-10 18:05 ` [Qemu-devel] [PATCH v2 1/3] slirp: improve TFTP performance Hervé Poussineau
2012-09-10 18:57   ` Jan Kiszka [this message]
2012-09-10 18:05 ` [Qemu-devel] [PATCH v2 2/3] slirp: Handle more than 65535 blocks in TFTP transfers Hervé Poussineau
2012-09-10 18:41   ` Jan Kiszka
2012-09-10 18:05 ` [Qemu-devel] [PATCH v2 3/3] slirp: Implement TFTP Blocksize option Hervé Poussineau
2012-09-10 18:49   ` Jan Kiszka

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=504E3821.5020207@siemens.com \
    --to=jan.kiszka@siemens.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).