From 3b64974c255fca9089596b658b92d1ec4ca38e69 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Fri, 28 Mar 2025 11:23:37 -0700 Subject: [PATCH 1/3] storage_write.c: store connection number in cookie Also, move "select which connection to use" earlier. This does not change any program behaviour, but will be useful in the following commit. --- tar/storage/storage_write.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tar/storage/storage_write.c b/tar/storage/storage_write.c index c6295db0..1b70ccdb 100644 --- a/tar/storage/storage_write.c +++ b/tar/storage/storage_write.c @@ -66,6 +66,9 @@ struct write_file_internal { uint64_t machinenum; int done; + /* Connection we're using. */ + size_t conn; + /* Parameters used in write_file. */ uint8_t class; uint8_t name[32]; @@ -334,6 +337,9 @@ storage_write_file(STORAGE_W * S, uint8_t * buf, size_t len, if (crypto_file_enc(buf, len, C->filebuf)) goto err2; + /* Select connection to use. */ + C->conn = S->lastcnum = (S->lastcnum + 1) % S->numconns; + /* We're issuing a write operation. */ S->nbytespending += C->flen; @@ -347,8 +353,7 @@ storage_write_file(STORAGE_W * S, uint8_t * buf, size_t len, } /* Ask the netpacket layer to send a request and get a response. */ - S->lastcnum = (S->lastcnum + 1) % S->numconns; - if (netpacket_op(S->NPC[S->lastcnum], callback_write_file_send, C)) + if (netpacket_op(S->NPC[C->conn], callback_write_file_send, C)) goto err0; /* Send ourself SIGQUIT or SIGUSR2 if necessary. */ From 9f4fac7eb90a1bf64b757299df5091fb4e40c323 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Fri, 28 Mar 2025 11:23:38 -0700 Subject: [PATCH 2/3] storage_write.c: track nbytespending per connection If --aggressive-network is used, this effectively multiplies MAXPENDING_WRITEBYTES by almost 8. --- tar/storage/storage_write.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tar/storage/storage_write.c b/tar/storage/storage_write.c index 1b70ccdb..271bde04 100644 --- a/tar/storage/storage_write.c +++ b/tar/storage/storage_write.c @@ -40,7 +40,7 @@ struct storage_write_internal { size_t lastcnum; /* Number of bytes of pending writes. */ - size_t nbytespending; + size_t nbytespending[AGGRESSIVE_CNUM]; /* Last time we wrote a checkpoint. */ uint64_t lastcheckpoint; @@ -147,7 +147,8 @@ storage_write_start(uint64_t machinenum, const uint8_t lastseq[32], S->lastcnum = 0; /* No pending writes so far. */ - S->nbytespending = 0; + for (i = 0; i < S->numconns; i++) + S->nbytespending[i] = 0; /* No checkpoint yet. */ S->lastcheckpoint = 0; @@ -341,13 +342,13 @@ storage_write_file(STORAGE_W * S, uint8_t * buf, size_t len, C->conn = S->lastcnum = (S->lastcnum + 1) % S->numconns; /* We're issuing a write operation. */ - S->nbytespending += C->flen; + S->nbytespending[C->conn] += C->flen; /* * Make sure the pending operation queue isn't too large before we * add yet another operation to it. */ - while (S->nbytespending > MAXPENDING_WRITEBYTES) { + while (S->nbytespending[C->conn] > MAXPENDING_WRITEBYTES) { if (network_select(1)) goto err2; } @@ -419,7 +420,7 @@ callback_write_file_response(void * cookie, switch (packetbuf[0]) { case 0: /* This write operation is no longer pending. */ - C->S->nbytespending -= C->flen; + C->S->nbytespending[C->conn] -= C->flen; break; case 1: warn0("Cannot store file: File already exists"); @@ -467,15 +468,18 @@ callback_write_file_response(void * cookie, int storage_write_flush(STORAGE_W * S) { + size_t i; /* No-op on NULL. */ if (S == NULL) return (0); /* Wait until all pending writes have been completed. */ - while (S->nbytespending > 0) { - if (network_select(1)) - goto err0; + for (i = 0; i < S->numconns; i++) { + while (S->nbytespending[i] > 0) { + if (network_select(1)) + goto err0; + } } /* Success! */ From c4ac3bea3f20efa1e980c7e7affc21ca8950d27d Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Fri, 28 Mar 2025 13:47:14 -0700 Subject: [PATCH 3/3] REBASE? sanity check? --- tar/storage/storage_write.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tar/storage/storage_write.c b/tar/storage/storage_write.c index 271bde04..b82778fc 100644 --- a/tar/storage/storage_write.c +++ b/tar/storage/storage_write.c @@ -420,6 +420,10 @@ callback_write_file_response(void * cookie, switch (packetbuf[0]) { case 0: /* This write operation is no longer pending. */ + if (C->S->nbytespending[C->conn] < C->flen) { + warn0("Invalid connection number and/or length"); + goto err1; + } C->S->nbytespending[C->conn] -= C->flen; break; case 1: