render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0177-slirp-improve-TFTP-performance.patch

5544c1
From c1b408d0c9d836e0a95d1e0695c0c6c605ceb368 Mon Sep 17 00:00:00 2001
5544c1
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= <hpoussin@reactos.org>
5544c1
Date: Mon, 10 Sep 2012 20:52:25 +0200
5544c1
Subject: [PATCH] slirp: improve TFTP performance
5544c1
MIME-Version: 1.0
5544c1
Content-Type: text/plain; charset=UTF-8
5544c1
Content-Transfer-Encoding: 8bit
5544c1
5544c1
When transferring a file, keep it open during the whole transfer,
5544c1
instead of opening/closing it for each block.
5544c1
5544c1
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
5544c1
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
5544c1
(cherry picked from commit 78be056628c76ff73eedeade86fde44b97343c79)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 slirp/tftp.c | 32 ++++++++++++++++++--------------
5544c1
 slirp/tftp.h |  1 +
5544c1
 2 files changed, 19 insertions(+), 14 deletions(-)
5544c1
5544c1
diff --git a/slirp/tftp.c b/slirp/tftp.c
5544c1
index b78765f..520dbd6 100644
5544c1
--- a/slirp/tftp.c
5544c1
+++ b/slirp/tftp.c
5544c1
@@ -37,6 +37,10 @@ static inline void tftp_session_update(struct tftp_session *spt)
5544c1
 
5544c1
 static void tftp_session_terminate(struct tftp_session *spt)
5544c1
 {
5544c1
+    if (spt->fd >= 0) {
5544c1
+        close(spt->fd);
5544c1
+        spt->fd = -1;
5544c1
+    }
5544c1
     g_free(spt->filename);
5544c1
     spt->slirp = NULL;
5544c1
 }
5544c1
@@ -54,7 +58,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
5544c1
 
5544c1
     /* sessions time out after 5 inactive seconds */
5544c1
     if ((int)(curtime - spt->timestamp) > 5000) {
5544c1
-        g_free(spt->filename);
5544c1
+        tftp_session_terminate(spt);
5544c1
         goto found;
5544c1
     }
5544c1
   }
5544c1
@@ -64,6 +68,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
5544c1
  found:
5544c1
   memset(spt, 0, sizeof(*spt));
5544c1
   memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip));
5544c1
+  spt->fd = -1;
5544c1
   spt->client_port = tp->udp.uh_sport;
5544c1
   spt->slirp = slirp;
5544c1
 
5544c1
@@ -95,24 +100,23 @@ static int tftp_session_find(Slirp *slirp, struct tftp_t *tp)
5544c1
 static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr,
5544c1
                           uint8_t *buf, int len)
5544c1
 {
5544c1
-  int fd;
5544c1
-  int bytes_read = 0;
5544c1
-
5544c1
-  fd = open(spt->filename, O_RDONLY | O_BINARY);
5544c1
+    int bytes_read = 0;
5544c1
 
5544c1
-  if (fd < 0) {
5544c1
-    return -1;
5544c1
-  }
5544c1
+    if (spt->fd < 0) {
5544c1
+        spt->fd = open(spt->filename, O_RDONLY | O_BINARY);
5544c1
+    }
5544c1
 
5544c1
-  if (len) {
5544c1
-    lseek(fd, block_nr * 512, SEEK_SET);
5544c1
+    if (spt->fd < 0) {
5544c1
+        return -1;
5544c1
+    }
5544c1
 
5544c1
-    bytes_read = read(fd, buf, len);
5544c1
-  }
5544c1
+    if (len) {
5544c1
+        lseek(spt->fd, block_nr * 512, SEEK_SET);
5544c1
 
5544c1
-  close(fd);
5544c1
+        bytes_read = read(spt->fd, buf, len);
5544c1
+    }
5544c1
 
5544c1
-  return bytes_read;
5544c1
+    return bytes_read;
5544c1
 }
5544c1
 
5544c1
 static int tftp_send_oack(struct tftp_session *spt,
5544c1
diff --git a/slirp/tftp.h b/slirp/tftp.h
5544c1
index 72e5e91..9c364ea 100644
5544c1
--- a/slirp/tftp.h
5544c1
+++ b/slirp/tftp.h
5544c1
@@ -33,6 +33,7 @@ struct tftp_t {
5544c1
 struct tftp_session {
5544c1
     Slirp *slirp;
5544c1
     char *filename;
5544c1
+    int fd;
5544c1
 
5544c1
     struct in_addr client_ip;
5544c1
     uint16_t client_port;
5544c1
-- 
5544c1
1.7.12.1
5544c1