QEMU update with VENOM (CVE-2015-3456) patch
[packages/centos6/qemu.git] / 0177-slirp-improve-TFTP-performance.patch
1 From c1b408d0c9d836e0a95d1e0695c0c6c605ceb368 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= <hpoussin@reactos.org>
3 Date: Mon, 10 Sep 2012 20:52:25 +0200
4 Subject: [PATCH] slirp: improve TFTP performance
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 When transferring a file, keep it open during the whole transfer,
10 instead of opening/closing it for each block.
11
12 Signed-off-by: HervĂ© Poussineau <hpoussin@reactos.org>
13 Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
14 Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
15 (cherry picked from commit 78be056628c76ff73eedeade86fde44b97343c79)
16
17 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
18 ---
19  slirp/tftp.c | 32 ++++++++++++++++++--------------
20  slirp/tftp.h |  1 +
21  2 files changed, 19 insertions(+), 14 deletions(-)
22
23 diff --git a/slirp/tftp.c b/slirp/tftp.c
24 index b78765f..520dbd6 100644
25 --- a/slirp/tftp.c
26 +++ b/slirp/tftp.c
27 @@ -37,6 +37,10 @@ static inline void tftp_session_update(struct tftp_session *spt)
28  
29  static void tftp_session_terminate(struct tftp_session *spt)
30  {
31 +    if (spt->fd >= 0) {
32 +        close(spt->fd);
33 +        spt->fd = -1;
34 +    }
35      g_free(spt->filename);
36      spt->slirp = NULL;
37  }
38 @@ -54,7 +58,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
39  
40      /* sessions time out after 5 inactive seconds */
41      if ((int)(curtime - spt->timestamp) > 5000) {
42 -        g_free(spt->filename);
43 +        tftp_session_terminate(spt);
44          goto found;
45      }
46    }
47 @@ -64,6 +68,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
48   found:
49    memset(spt, 0, sizeof(*spt));
50    memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip));
51 +  spt->fd = -1;
52    spt->client_port = tp->udp.uh_sport;
53    spt->slirp = slirp;
54  
55 @@ -95,24 +100,23 @@ static int tftp_session_find(Slirp *slirp, struct tftp_t *tp)
56  static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr,
57                            uint8_t *buf, int len)
58  {
59 -  int fd;
60 -  int bytes_read = 0;
61 -
62 -  fd = open(spt->filename, O_RDONLY | O_BINARY);
63 +    int bytes_read = 0;
64  
65 -  if (fd < 0) {
66 -    return -1;
67 -  }
68 +    if (spt->fd < 0) {
69 +        spt->fd = open(spt->filename, O_RDONLY | O_BINARY);
70 +    }
71  
72 -  if (len) {
73 -    lseek(fd, block_nr * 512, SEEK_SET);
74 +    if (spt->fd < 0) {
75 +        return -1;
76 +    }
77  
78 -    bytes_read = read(fd, buf, len);
79 -  }
80 +    if (len) {
81 +        lseek(spt->fd, block_nr * 512, SEEK_SET);
82  
83 -  close(fd);
84 +        bytes_read = read(spt->fd, buf, len);
85 +    }
86  
87 -  return bytes_read;
88 +    return bytes_read;
89  }
90  
91  static int tftp_send_oack(struct tftp_session *spt,
92 diff --git a/slirp/tftp.h b/slirp/tftp.h
93 index 72e5e91..9c364ea 100644
94 --- a/slirp/tftp.h
95 +++ b/slirp/tftp.h
96 @@ -33,6 +33,7 @@ struct tftp_t {
97  struct tftp_session {
98      Slirp *slirp;
99      char *filename;
100 +    int fd;
101  
102      struct in_addr client_ip;
103      uint16_t client_port;
104 -- 
105 1.7.12.1
106