From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TB9B6-0001O2-BG for qemu-devel@nongnu.org; Mon, 10 Sep 2012 14:57:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TB9Ay-000139-Ew for qemu-devel@nongnu.org; Mon, 10 Sep 2012 14:57:48 -0400 Received: from goliath.siemens.de ([192.35.17.28]:34118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TB9Ay-00012a-5Y for qemu-devel@nongnu.org; Mon, 10 Sep 2012 14:57:40 -0400 Message-ID: <504E3821.5020207@siemens.com> Date: Mon, 10 Sep 2012 20:57:37 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1347300346-14482-1-git-send-email-hpoussin@reactos.org> <1347300346-14482-2-git-send-email-hpoussin@reactos.org> In-Reply-To: <1347300346-14482-2-git-send-email-hpoussin@reactos.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 1/3] slirp: improve TFTP performance List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?SGVydsOpIFBvdXNzaW5lYXU=?= Cc: "qemu-devel@nongnu.org" On 2012-09-10 20:05, Herv=C3=A9 Poussineau wrote: > When transfering a file, keep it open during the whole transfer, > instead of opening/closing it for each block. >=20 > Signed-off-by: Herv=C3=A9 Poussineau > Reviewed-by: Aurelien Jarno > --- > slirp/tftp.c | 32 ++++++++++++++++++-------------- > slirp/tftp.h | 1 + > 2 files changed, 19 insertions(+), 14 deletions(-) >=20 > 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_s= ession *spt) > =20 > static void tftp_session_terminate(struct tftp_session *spt) > { > + if (spt->fd >=3D 0) { > + close(spt->fd); > + spt->fd =3D -1; > + } > g_free(spt->filename); > spt->slirp =3D NULL; > } > @@ -54,7 +58,7 @@ static int tftp_session_allocate(Slirp *slirp, struct= tftp_t *tp) > =20 > /* 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 =3D -1; > spt->client_port =3D tp->udp.uh_sport; > spt->slirp =3D slirp; > =20 > @@ -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 =3D 0; > - > - fd =3D open(spt->filename, O_RDONLY | O_BINARY); > + int bytes_read =3D 0; > =20 > - if (fd < 0) { > - return -1; > - } > + if (spt->fd < 0) { > + spt->fd =3D open(spt->filename, O_RDONLY | O_BINARY); > + } > =20 > - if (len) { > - lseek(fd, block_nr * 512, SEEK_SET); > + if (spt->fd < 0) { > + return -1; > + } > =20 > - bytes_read =3D read(fd, buf, len); > - } > + if (len) { > + lseek(spt->fd, block_nr * 512, SEEK_SET); > =20 > - close(fd); > + bytes_read =3D read(spt->fd, buf, len); > + } > =20 > - return bytes_read; > + return bytes_read; > } > =20 > 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; > =20 > struct in_addr client_ip; > uint16_t client_port; >=20 Thanks, added to slirp queue. Jan --=20 Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux