Skip to content

Commit fb82dec

Browse files
committed
BUG/MEDIUM: haterm: Properly initialize the splicing support for haterm
First, we must not emit any warning if splicing is not configured and the global maxpipes value is 0. Then we must not remove GTUNE_USE_SPLICE flag when we fail to allocate the haterm master pipe. Instead, we test it when we negociate with the opposite side, to properly exclude the splicing if it is not usable. No backport needed.
1 parent 3131216 commit fb82dec

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/haterm.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <haproxy/buf.h>
55
#include <haproxy/cfgparse.h>
66
#include <haproxy/chunk.h>
7+
#include <haproxy/compat.h>
78
#include <haproxy/global.h>
89
#include <haproxy/hstream-t.h>
910
#include <haproxy/http_htx.h>
@@ -332,6 +333,7 @@ static int hstream_ff_snd(struct connection *conn, struct hstream *hs)
332333
nego_flags |= NEGO_FF_FL_EXACT_SIZE;
333334
#if defined(USE_LINUX_SPLICE)
334335
if ((global.tune.options & GTUNE_USE_SPLICE) &&
336+
master_pipe &&
335337
!(sd->iobuf.flags & IOBUF_FL_NO_SPLICING) &&
336338
!(hs->flags & HS_ST_OPT_NO_SPLICING))
337339
nego_flags |= NEGO_FF_FL_MAY_SPLICE;
@@ -348,6 +350,7 @@ static int hstream_ff_snd(struct connection *conn, struct hstream *hs)
348350

349351
#if defined(USE_LINUX_SPLICE)
350352
if (sd->iobuf.pipe) {
353+
BUG_ON(master_pipesize == 0 || master_pipe == NULL);
351354
if (len > master_pipesize)
352355
len = master_pipesize;
353356
ret = tee(master_pipe->cons, sd->iobuf.pipe->prod, len, SPLICE_F_NONBLOCK);
@@ -1207,42 +1210,45 @@ static int hstream_build_responses(void)
12071210
#if defined(USE_LINUX_SPLICE)
12081211
static void hstream_init_splicing(void)
12091212
{
1210-
if (!(global.tune.options & GTUNE_USE_SPLICE))
1213+
unsigned int pipesize = 65536 * 5 / 4;
1214+
1215+
if (!(global.tune.options & GTUNE_USE_SPLICE) || !global.maxpipes)
12111216
return;
12121217

1213-
if (!global.tune.pipesize)
1214-
global.tune.pipesize = 65536 * 5 / 4;
1218+
if (global.tune.pipesize)
1219+
pipesize = global.tune.pipesize;
12151220

12161221
master_pipe = get_pipe();
12171222
if (master_pipe) {
12181223
struct iovec v = { .iov_base = common_response,
12191224
.iov_len = sizeof(common_response) };
12201225
int total, ret;
12211226

1227+
#ifdef F_SETPIPE_SZ
1228+
fcntl(master_pipe->cons, F_SETPIPE_SZ, pipesize);
1229+
#endif
12221230
total = ret = 0;
12231231
do {
12241232
ret = vmsplice(master_pipe->prod, &v, 1, SPLICE_F_NONBLOCK);
12251233
if (ret > 0)
12261234
total += ret;
1227-
} while (ret > 0 && total < global.tune.pipesize);
1235+
} while (ret > 0 && total < pipesize);
12281236
master_pipesize = total;
12291237

1230-
if (master_pipesize < global.tune.pipesize) {
1238+
if (master_pipesize < pipesize) {
12311239
if (master_pipesize < 60*1024) {
12321240
/* Older kernels were limited to around 60-61 kB */
1233-
ha_warning("Failed to vmsplice response buffer after %lu bytes, splicing disabled\n", master_pipesize);
1234-
global.tune.options &= ~GTUNE_USE_SPLICE;
1241+
ha_warning("Failed to vmsplice haterm mastre pipe after %lu bytes, splicing disabled for haterm\n", master_pipesize);
12351242
put_pipe(master_pipe);
12361243
master_pipe = NULL;
1244+
master_pipesize = 0;
12371245
}
12381246
else
1239-
ha_warning("Splicing is limited to %lu bytes (too old kernel)\n", master_pipesize);
1247+
ha_warning("Splicing in haterm is limited to %lu bytes (too old kernel)\n", master_pipesize);
12401248
}
12411249
}
1242-
else {
1243-
ha_warning("Unable to allocate master pipe for splicing, splicing disabled\n");
1244-
global.tune.options &= ~GTUNE_USE_SPLICE;
1245-
}
1250+
else
1251+
ha_warning("Unable to allocate haterm master pipe for splicing, splicing disabled for haterm\n");
12461252
}
12471253

12481254
static void hstream_deinit(void)

0 commit comments

Comments
 (0)