[master] aee0b24 Methodify ObjGetSpace() and ObjExtend()

Poul-Henning Kamp phk at FreeBSD.org
Mon Sep 15 22:41:30 CEST 2014


commit aee0b243ebf134270a7d4e58c45632d62f9147e2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Sep 15 20:41:03 2014 +0000

    Methodify ObjGetSpace() and ObjExtend()

diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index af69ed3..60b38df 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -242,7 +242,13 @@ objallocwithnuke(struct stevedore *stv, struct vsl_log *vsl, struct dstat *ds,
 	return (st);
 }
 
-/*--------------------------------------------------------------------
+/*====================================================================
+ * ObjGetSpace()
+ *
+ * This function returns a pointer and length of free space.  If there
+ * is no free space, some will be added first.
+ *
+ * The "sz" argument is an input hint of how much space is desired.
  */
 
 int
@@ -251,6 +257,10 @@ ObjGetSpace(struct objcore *oc, struct vsl_log *vsl, struct dstat *ds,
 {
 	struct object *o;
 	struct storage *st;
+	const struct storeobj_methods *om = obj_getmethods(oc);
+
+	if (om->objgetspace != NULL)
+		return (om->objgetspace(oc, vsl, ds, sz, ptr));
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	AN(ds);
@@ -286,7 +296,11 @@ ObjGetSpace(struct objcore *oc, struct vsl_log *vsl, struct dstat *ds,
 	return (1);
 }
 
-/*--------------------------------------------------------------------
+/*====================================================================
+ * ObjExtend()
+ *
+ * This function extends the used part of the object a number of bytes
+ * into the last space returned by ObjGetSpace()
  */
 
 void
@@ -294,6 +308,12 @@ ObjExtend(struct objcore *oc, struct dstat *ds, ssize_t l)
 {
 	struct object *o;
 	struct storage *st;
+	const struct storeobj_methods *om = obj_getmethods(oc);
+
+	if (om->objextend != NULL) {
+		om->objextend(oc, ds, l);
+		return;
+	}
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	o = obj_getobj(oc, ds);
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 60faf9d..a5376a9 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -39,6 +39,7 @@ struct busyobj;
 struct objcore;
 struct worker;
 struct lru;
+struct vsl_log;
 
 /* Storage -----------------------------------------------------------*/
 
@@ -98,7 +99,10 @@ typedef void *objiterbegin_f(struct objcore *oc, struct worker *wrk);
 typedef enum objiter_status objiter_f(struct objcore *oc, void *oix,
     void **p, ssize_t *l);
 typedef void objiterend_f(struct objcore *oc, void **oix);
-/* objgetspace */
+typedef int objgetspace_f(struct objcore *oc, struct vsl_log *vsl,
+    struct dstat *ds, ssize_t *sz, uint8_t **ptr);
+typedef void objextend_f(struct objcore *oc, struct dstat *ds, ssize_t l);
+
 /* objtrimstore */
 /* objslim */
 /* objgetattr */
@@ -116,6 +120,8 @@ struct storeobj_methods {
 	objiterbegin_f	*objiterbegin;
 	objiter_f	*objiter;
 	objiterend_f	*objiterend;
+	objgetspace_f	*objgetspace;
+	objextend_f	*objextend;
 };
 
 /* Prototypes --------------------------------------------------------*/



More information about the varnish-commit mailing list