]> err.no Git - varnish/commitdiff
Unify backend error handling
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 18 Sep 2006 06:41:57 +0000 (06:41 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 18 Sep 2006 06:41:57 +0000 (06:41 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1057 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_backend.c
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_pass.c
varnish-cache/bin/varnishd/cache_pipe.c
varnish-cache/bin/varnishd/cache_response.c

index f8cd81acfab516b1dcd0821de58b006b2b8df961..e791f0b18dce08b041947084afef09e234a2329a 100644 (file)
@@ -297,7 +297,7 @@ void VCA_Init(void);
 
 /* cache_backend.c */
 void VBE_Init(void);
-struct vbe_conn *VBE_GetFd(struct backend *bp, unsigned xid);
+struct vbe_conn *VBE_GetFd(struct sess *sp);
 void VBE_ClosedFd(struct vbe_conn *vc, int already);
 void VBE_RecycleFd(struct vbe_conn *vc);
 
@@ -367,7 +367,7 @@ int PassSession(struct sess *sp);
 void PassBody(struct sess *sp);
 
 /* cache_pipe.c */
-void PipeSession(struct sess *sp);
+int PipeSession(struct sess *sp);
 
 /* cache_pool.c */
 void WRK_Init(void);
index 6033b54bc8d00e08514254f0968758d87cffa18c..4a584c5a21ded0938e5c1a72337cd826f7bfc26f 100644 (file)
@@ -175,12 +175,15 @@ vbe_connect(struct backend *bp)
  * new connection.
  */
 
-struct vbe_conn *
-VBE_GetFd(struct backend *bp, unsigned xid)
+static struct vbe_conn *
+vbe_nextfd(struct sess *sp)
 {
        struct vbe_conn *vc, *vc2;
        struct pollfd pfd;
+       struct backend *bp;
 
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+       bp = sp->backend;
        CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
        while (1) {
                /*
@@ -245,12 +248,29 @@ VBE_GetFd(struct backend *bp, unsigned xid)
        if (vc != NULL ) {
                assert(vc->fd >= 0);
                VSL_stats->backend_conn++;
-               VSL(SLT_BackendXID, vc->fd, "%u", xid);
+               WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid);
                AN(vc->backend);
        }
        return (vc);
 }
 
+/*--------------------------------------------------------------------*/
+
+struct vbe_conn *
+VBE_GetFd(struct sess *sp)
+{
+       struct vbe_conn *vc;
+
+       vc = vbe_nextfd(sp);
+       if (vc != NULL) {
+               WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd,
+                   sp->backend->vcl_name);
+               return (vc);
+       }
+       RES_Error(sp, 503, "Backend did not respond.");
+       return (NULL);
+}
+
 /* Close a connection ------------------------------------------------*/
 
 void
index b2bbfedb40c50a11d19affa7627ae75ae7ebaa8e..4c4116599b8d5b7f016106b4a3600351f57e73df 100644 (file)
@@ -530,7 +530,14 @@ cnt_miss(struct sess *sp)
                INCOMPL();
        if (sp->handling == VCL_RET_FETCH) {
                AZ(sp->vbc);
-               FetchHeaders(sp);
+               if (FetchHeaders(sp)) {
+                       sp->obj->cacheable = 0;
+                       HSH_Unbusy(sp->obj);
+                       HSH_Deref(sp->obj);
+                       sp->obj = NULL;
+                       sp->step = STP_DONE;
+                       return (0);
+               }
                sp->step = STP_FETCH;
                AN(sp->vbc);
                return (0);
@@ -613,7 +620,7 @@ cnt_pipe(struct sess *sp)
 {
 
        sp->wrk->acct.pipe++;
-       PipeSession(sp);
+       (void)PipeSession(sp);
        sp->step = STP_DONE;
        return (0);
 }
index 1ad353f1534a54afc2093784496bfe14153fe6dd..ed417f7a19d79a546f1b40b8fdc5f8e4a29d92ff 100644 (file)
@@ -290,11 +290,9 @@ FetchHeaders(struct sess *sp)
 
        sp->obj->xid = sp->xid;
 
-       vc = VBE_GetFd(sp->backend, sp->xid);
+       vc = VBE_GetFd(sp);
        if (vc == NULL)
-               vc = VBE_GetFd(sp->backend, sp->xid);
-       XXXAN(vc);
-       WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
+               return (1);
 
        http_ClrHeader(vc->http);
        vc->http->logtag = HTTP_Tx;
index dca4425ff49e1196b7a5928dea839a74f2c62c67..589c1980a01e6af98f7b6d89fa329b78bf08ef23 100644 (file)
@@ -202,12 +202,9 @@ PassSession(struct sess *sp)
        CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
        w = sp->wrk;
 
-       vc = VBE_GetFd(sp->backend, sp->xid);
-       if (vc == NULL) {
-               RES_Error(sp, 503, "Backend did not respond.");
+       vc = VBE_GetFd(sp);
+       if (vc == NULL)
                return (1);
-       }
-       WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
 
        http_CopyReq(w, vc->fd, vc->http, sp->http);
        http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_PASS);
index 78c58986b60082615b554003fb21b33c045db60d..e1747a1d8a2c180ff2063dfade4614cff84267ec 100644 (file)
@@ -40,7 +40,7 @@ rdf(struct pollfd *fds, int idx)
        }
 }
 
-void
+int
 PipeSession(struct sess *sp)
 {
        struct vbe_conn *vc;
@@ -53,12 +53,9 @@ PipeSession(struct sess *sp)
        CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
        w = sp->wrk;
 
-       vc = VBE_GetFd(sp->backend, sp->xid);
-       if (vc == NULL) {
-               RES_Error(sp, 503, "Backend did not respond.");
-               return;
-       }
-       VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
+       vc = VBE_GetFd(sp);
+       if (vc == NULL)
+               return (1);
        vc->http->logtag = HTTP_Tx;
 
        http_CopyReq(w, vc->fd, vc->http, sp->http);
index bb7e846714e14d9265200e4e3cf1bcaa70967434..c9244731bb8103b4ca6efda2eac32584777d4c7a 100644 (file)
@@ -103,7 +103,7 @@ RES_Error(struct sess *sp, int code, const char *expl)
        vsb_cat(sb,
                "Server: Varnish\r\n"
                "Connection: close\r\n"
-               "content-Type: text/html; charset=iso-8859-1\r\n"
+               "Content-Type: text/html; charset=iso-8859-1\r\n"
                "\r\n"
                "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
                "<HTML>\r\n"