]> err.no Git - varnish/commitdiff
Put more meat on the stevedore (storage backend) interface:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 13 Jun 2006 07:57:32 +0000 (07:57 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 13 Jun 2006 07:57:32 +0000 (07:57 +0000)
Pull the struct definition into _stevedore.h and include this from
cache.h and mgt.h, they both need to be able to see it.

Add the stevedore pointer as an argument to the stevedore alloc function
so multiple stevedores is possible later on.

Add the stevedore pointer to the storage object, so freeing it again is
possible.

Add -s argument processing to select a given stevedore, call it's ->init
method and pass the stevedore in the heritage.

In the cache process pick stevedore out from heritage, call its open method.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@170 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/_stevedore.h [new file with mode: 0644]
varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt.h
varnish-cache/bin/varnishd/storage_malloc.c
varnish-cache/bin/varnishd/varnishd.c

diff --git a/varnish-cache/bin/varnishd/_stevedore.h b/varnish-cache/bin/varnishd/_stevedore.h
new file mode 100644 (file)
index 0000000..41ba35a
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * $Id: cache.h 164 2006-05-01 12:45:20Z phk $
+ */
+
+struct stevedore;
+
+typedef void storage_init_f(struct stevedore *, const char *spec);
+typedef void storage_open_f(struct stevedore *);
+typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
+typedef void storage_free_f(struct storage *);
+
+struct stevedore {
+       const char              *name;
+       storage_init_f          *init;  /* called by mgt process */
+       storage_open_f          *open;  /* called by cache process */
+       storage_alloc_f         *alloc;
+       storage_free_f          *free;
+
+       /* private fields */
+       void                    *priv;
+};
index 379caf45da45e85d91334b3f7ad64d51382ca110..2f5a8fd686e0d49f180cd9d41e223534c0677c57 100644 (file)
@@ -42,21 +42,16 @@ struct storage {
        unsigned char           *ptr;
        unsigned                len;
        void                    *priv;
+       struct stevedore        *stevedore;
 };
 
-typedef void storage_init_f(void);
-typedef struct storage *storage_alloc_f(unsigned size);
-typedef void storage_free_f(struct storage *);
-
-struct stevedore {
-       const char              *name;
-       storage_init_f          *init;
-       storage_alloc_f         *alloc;
-       storage_free_f          *free;
-};
-
-extern struct stevedore sma_stevedore;
+#include "_stevedore.h"
 
+/*
+ * XXX: in the longer term, we want to support multiple stevedores,
+ * XXX: selected by some kind of heuristics based on size, lifetime
+ * XXX: etc etc.  For now we support only one.
+ */
 extern struct stevedore *stevedore;
 
 /* Prototypes etc ----------------------------------------------------*/
index dbcd6c607b6d4c18ea84d67c8623eec0c6e104e1..75c02e4da20aba438e7ff5544d5ae4ed08047787 100644 (file)
@@ -33,7 +33,7 @@ fetch_straight(struct worker *w, struct sess *sp, int fd, struct http *hp, char
 
        cl = strtoumax(b, NULL, 0);
 
-       st = stevedore->alloc(cl);
+       st = stevedore->alloc(stevedore, cl);
        TAILQ_INSERT_TAIL(&sp->obj->store, st, list);
        st->len = cl;
        sp->obj->len = cl;
@@ -104,7 +104,7 @@ fetch_chunked(struct worker *w, struct sess *sp, int fd, struct http *hp)
                q++;
                if (u == 0)
                        break;
-               st = stevedore->alloc(u);
+               st = stevedore->alloc(stevedore, u);
                TAILQ_INSERT_TAIL(&sp->obj->store, st, list);
                st->len = u;
                sp->obj->len += u;
index 1c3c232f8cfb1e7c4bbe2c3e32da621aebea8953..50023b07582ba75fa8578b76632b012325537951 100644 (file)
@@ -125,9 +125,9 @@ child_main(void)
        if (hash->init != NULL)
                hash->init();
 
-       stevedore = &sma_stevedore;
-       if (stevedore->init != NULL)
-               stevedore->init();
+       stevedore = heritage.stevedore;
+       if (stevedore->open != NULL)
+               stevedore->open(stevedore);
 
        CVCL_Load(heritage.vcl_file, "boot");
        cli = cli_setup(eb, heritage.fds[2], heritage.fds[1], 0, cli_proto);
index 018cb0541a1e7702e9b2113d3e66910e776a5933..8aad4824505a48c0c36808c1c68989ffc627e039 100644 (file)
@@ -18,15 +18,18 @@ struct heritage {
         * interface IP number).
         */
 #define HERITAGE_NSOCKS                2       /* IPv4 + IPv6 */
-       int     sock_local[HERITAGE_NSOCKS];
-       int     sock_remote[HERITAGE_NSOCKS];
+       int                     sock_local[HERITAGE_NSOCKS];
+       int                     sock_remote[HERITAGE_NSOCKS];
 
        /* Share memory log fd and size (incl header) */
-       int             vsl_fd;
-       unsigned        vsl_size;
+       int                     vsl_fd;
+       unsigned                vsl_size;
 
        /* Initial VCL file */
-       char            *vcl_file;
+       char                    *vcl_file;
+
+       /* Storage method */
+       struct stevedore        *stevedore;
 };
 
 extern struct heritage heritage;
index c4b855eaa8549acbc2833facaf614e8305e10a6b..9cc269e6601130f2539488bf2b948c990f136dbf 100644 (file)
@@ -13,3 +13,7 @@ void mgt_child_request(mgt_ccb_f *, void *, char **argv, const char *fmt, ...);
 
 /* tcp.c */
 int open_tcp(const char *port);
+
+#include "_stevedore.h"
+
+extern struct stevedore sma_stevedore;
index d67ed50bbf86dfb11563aa10bdcb333dca732b61..01d732170895832087411b185ccf75a9841fe1f5 100644 (file)
@@ -17,7 +17,7 @@ struct sma {
 };
 
 static struct storage *
-sma_alloc(unsigned size)
+sma_alloc(struct stevedore *st __unused, unsigned size)
 {
        struct sma *sma;
 
@@ -41,8 +41,9 @@ sma_free(struct storage *s)
 }
 
 struct stevedore sma_stevedore = {
-       "Malloc",
+       "malloc",
        NULL,                   /* init */
+       NULL,                   /* open */
        sma_alloc,
        sma_free
 };
index aabc1492239ac807adb3b47efd6ecb5c255220cc..7324a6a9e49ef8b8c10cc9a82f06db13ef7eea5a 100644 (file)
@@ -277,10 +277,12 @@ static void
 usage(void)
 {
        fprintf(stderr, "usage: varnishd [options]\n");
-       fprintf(stderr, "    %-20s # %s\n", "-b", "backend_IP_number");
-       fprintf(stderr, "    %-20s # %s\n", "-d", "debug");
-       fprintf(stderr, "    %-20s # %s\n", "-f", "VCL_file");
-       fprintf(stderr, "    %-20s # %s\n", "-p number", "TCP listen port");
+       fprintf(stderr, "    %-28s # %s\n", "-b", "backend_IP_number");
+       fprintf(stderr, "    %-28s # %s\n", "-d", "debug");
+       fprintf(stderr, "    %-28s # %s\n", "-f", "VCL_file");
+       fprintf(stderr, "    %-28s # %s\n", "-p number", "TCP listen port");
+       fprintf(stderr, "    %-28s # %s\n",
+           "-s kind[,storageoptions]", "Backend storage specification");
 #if 0
        -c clusterid@cluster_controller
        -m memory_limit
@@ -294,6 +296,37 @@ usage(void)
 
 /*--------------------------------------------------------------------*/
 
+static int
+cmp_storage(struct stevedore *s, const char *p, const char *q)
+{
+       if (strlen(s->name) != q - p)
+               return (1);
+       if (strncmp(s->name, p, q - p))
+               return (1);
+       return (0);
+}
+
+static void
+setup_storage(const char *sflag)
+{
+       const char *p;
+
+       p = strchr(sflag, ',');
+       if (p == NULL)
+               p = strchr(sflag, '\0');
+       if (!cmp_storage(&sma_stevedore, sflag, p)) {
+               heritage.stevedore = &sma_stevedore;
+       } else {
+               fprintf(stderr, "Unknown storage method \"%*.*s\"\n",
+                       p - sflag, p - sflag, sflag);
+               exit (2);
+       }
+       if (heritage.stevedore->init != NULL)
+               heritage.stevedore->init(heritage.stevedore, p);
+}
+
+/*--------------------------------------------------------------------*/
+
 #include "shmlog.h"
 
 static void
@@ -324,6 +357,7 @@ init_vsl(const char *fn, unsigned size)
        AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
        heritage.vsl_size = slh.size + slh.start;
 }
+
 /*--------------------------------------------------------------------*/
 
 /* for development purposes */
@@ -338,6 +372,7 @@ main(int argc, char *argv[])
        unsigned dflag = 1;     /* XXX: debug=on for now */
        const char *bflag = NULL;
        const char *fflag = NULL;
+       const char *sflag = "malloc";
 
        register_printf_render_std((const unsigned char *)"HVQ");
  
@@ -357,6 +392,9 @@ main(int argc, char *argv[])
                case 'p':
                        portnumber = optarg;
                        break;
+               case 's':
+                       sflag = optarg;
+                       break;
                default:
                        usage();
                }
@@ -385,6 +423,8 @@ main(int argc, char *argv[])
        if (heritage.vcl_file == NULL)
                exit (1);
 
+       setup_storage(sflag);
+
        /*
         * XXX: Lacking the suspend/resume facility (due to the socket API
         * missing an unlisten(2) facility) we may want to push this into
@@ -398,6 +438,5 @@ main(int argc, char *argv[])
 
        testme();
 
-
        exit(0);
 }