From: Mark Wooding <mdw@distorted.org.uk>
To: git@vger.kernel.org
Subject: [PATCH 9/9] http-fetch: Paranoid sanity checking for the object queue.
Date: Wed, 01 Feb 2006 11:44:43 +0000 [thread overview]
Message-ID: <20060201114443.5042.65478.stgit@metalzone.distorted.org.uk> (raw)
In-Reply-To: <20060201112822.5042.41256.stgit@metalzone.distorted.org.uk>
From: Mark Wooding <mdw@distorted.org.uk>
Probably not wanted in the mainline, but useful for debugging.
Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
---
http-fetch.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/http-fetch.c b/http-fetch.c
index fa3eb4a..80eaa2f 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -3,6 +3,7 @@
#include "pack.h"
#include "fetch.h"
#include "http.h"
+#include <assert.h>
#define PREV_BUF_SIZE 4096
#define RANGE_HEADER_SIZE 30
@@ -28,6 +29,13 @@ enum object_request_state {
COMPLETE,
};
+typedef struct stash {
+ struct stash *next;
+ unsigned char sha1[20];
+ int activep;
+ int tickp;
+} stash;
+
struct object_request
{
unsigned char sha1[20];
@@ -47,6 +55,7 @@ struct object_request
int rename;
struct active_request_slot *slot;
struct object_request *next;
+ stash *tick;
};
struct alternates_request {
@@ -57,8 +66,60 @@ struct alternates_request {
int http_specific;
};
+static stash *seen = 0;
+
+static stash *findstash(unsigned char *sha1)
+{
+ stash *s;
+ for (s = seen; s; s = s->next) {
+ if (memcmp(sha1, s->sha1, 20) == 0)
+ return s;
+ }
+ return NULL;
+}
+
+static stash *enstash(unsigned char *sha1)
+{
+ stash *s;
+ if ((s = findstash(sha1)) != NULL)
+ assert(!s->activep);
+ else {
+ s = xmalloc(sizeof(*s));
+ memcpy(s->sha1, sha1, 20);
+ s->next = seen;
+ seen = s;
+ }
+ s->activep = 1;
+ return s;
+}
+
+static void unstash(unsigned char *sha1)
+{
+ stash *s = findstash(sha1);
+ assert(s && s->activep);
+ s->activep = 0;
+}
+
static struct object_request *object_queue_head = NULL;
+static void sanity_check_stash(void)
+{
+ stash *s;
+ struct object_request *obj_req;
+
+ for (s = seen; s; s = s->next)
+ s->tickp = 0;
+ for (obj_req = object_queue_head; obj_req; obj_req = obj_req->next) {
+ assert(obj_req->tick);
+ s = obj_req->tick;
+ assert(memcmp(s->sha1, obj_req->sha1, 20) == 0);
+ assert(s->activep);
+ s->tickp = 1;
+ }
+ for (s = seen; s; s = s->next)
+ assert(!s->tickp == !s->activep);
+}
+
static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
void *data)
{
@@ -287,6 +348,7 @@ static void release_object_request(struc
{
struct object_request *entry = object_queue_head;
+ sanity_check_stash();
if (obj_req->local != -1)
error("fd leakage in release: %d", obj_req->local);
if (obj_req == object_queue_head) {
@@ -298,6 +360,8 @@ static void release_object_request(struc
entry->next = entry->next->next;
}
+ unstash(obj_req->sha1);
+ sanity_check_stash();
free(obj_req->url);
free(obj_req);
}
@@ -309,6 +373,7 @@ void fill_active_slots(void)
struct active_request_slot *slot = active_queue_head;
int num_transfers;
+ sanity_check_stash();
while (active_requests < max_requests && obj_req != NULL) {
if (obj_req->state == WAITING) {
if (has_sha1_file(obj_req->sha1))
@@ -327,6 +392,7 @@ void fill_active_slots(void)
}
slot = slot->next;
}
+ sanity_check_stash();
}
#endif
@@ -347,6 +413,7 @@ void prefetch(unsigned char *sha1)
"%s.temp", filename);
newreq->next = NULL;
+ sanity_check_stash();
if (object_queue_head == NULL) {
object_queue_head = newreq;
} else {
@@ -356,6 +423,8 @@ void prefetch(unsigned char *sha1)
}
tail->next = newreq;
}
+ newreq->tick = enstash(sha1);
+ sanity_check_stash();
#ifdef USE_CURL_MULTI
fill_active_slots();
@@ -789,6 +858,7 @@ static int fetch_object(struct alt_base
int ret = 0;
struct object_request *obj_req = object_queue_head;
+ sanity_check_stash();
while (obj_req != NULL && memcmp(obj_req->sha1, sha1, 20))
obj_req = obj_req->next;
if (obj_req == NULL)
next prev parent reply other threads:[~2006-02-01 11:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-01 11:28 [PATCH 0/9] http-fetch fixes Mark Wooding
2006-02-01 11:44 ` [PATCH 1/9] http-fetch: Mark slots as `watched' to stop them being reused Mark Wooding
2006-02-01 11:44 ` [PATCH 2/9] http-fetch: Fix object list corruption in fill_active_slots() Mark Wooding
2006-02-01 11:44 ` [PATCH 3/9] http-fetch: Abort requests for objects which arrived in packs Mark Wooding
2006-02-01 17:12 ` Nick Hengeveld
2006-02-01 17:23 ` Mark Wooding
2006-02-06 23:11 ` Nick Hengeveld
2006-02-01 11:44 ` [PATCH 4/9] http-fetch: Actually watch the file descriptors of interest Mark Wooding
2006-02-01 15:03 ` Nick Hengeveld
2006-02-01 11:44 ` [PATCH 5/9] http-fetch: Fix message reporting rename of object file Mark Wooding
2006-02-01 11:44 ` [PATCH 6/9] http: Turn on verbose Curl messages if GIT_CURL_VERBOSE set in environment Mark Wooding
2006-02-01 11:44 ` [PATCH 7/9] http-fetch: Tidy control flow in process_alternate_response Mark Wooding
2006-02-01 11:44 ` [PATCH 8/9] http: Paranoid sanity checking for active slots Mark Wooding
2006-02-01 11:44 ` Mark Wooding [this message]
2006-02-01 15:30 ` [PATCH 0/9] http-fetch fixes Uwe Zeisberger
2006-02-01 15:47 ` Mark Wooding
2006-02-02 3:02 ` Junio C Hamano
2006-02-03 20:20 ` Mark Wooding
2006-02-03 20:42 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060201114443.5042.65478.stgit@metalzone.distorted.org.uk \
--to=mdw@distorted.org.uk \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).