From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TB8MN-0003Wz-Sv for qemu-devel@nongnu.org; Mon, 10 Sep 2012 14:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TB8ME-0001Jk-Ot for qemu-devel@nongnu.org; Mon, 10 Sep 2012 14:05:23 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:34729) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TB8ME-00019H-5x for qemu-devel@nongnu.org; Mon, 10 Sep 2012 14:05:14 -0400 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 10 Sep 2012 20:05:43 +0200 Message-Id: <1347300346-14482-2-git-send-email-hpoussin@reactos.org> In-Reply-To: <1347300346-14482-1-git-send-email-hpoussin@reactos.org> References: <1347300346-14482-1-git-send-email-hpoussin@reactos.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 1/3] slirp: improve TFTP performance List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jan Kiszka , =?UTF-8?q?Herv=C3=A9=20Poussineau?= When transfering a file, keep it open during the whole transfer, instead of opening/closing it for each block. 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(-) 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_ses= sion *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 t= ftp_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 t= ftp_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 tf= tp_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 1.7.10.4