changeset 261:dcace0062e96

objstore: move volume creation & loading op into volume definition struct Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Fri, 22 Apr 2016 19:39:46 -0400
parents 28753e6672ab
children 61060d9fe18e
files src/objstore/include/nomad/objstore_backend.h src/objstore/mem/main.c src/objstore/vol.c
diffstat 3 files changed, 22 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/objstore/include/nomad/objstore_backend.h	Fri Apr 22 19:39:19 2016 -0400
+++ b/src/objstore/include/nomad/objstore_backend.h	Fri Apr 22 19:39:46 2016 -0400
@@ -59,13 +59,15 @@
 };
 
 struct vol_ops {
-	int (*create)(struct objstore_vol *store);
-	int (*load)(struct objstore_vol *store);
 	int (*getroot)(struct objstore_vol *store, struct noid *root);
 };
 
 struct objstore_vol_def {
 	const char *name;
+
+	int (*create)(struct objstore_vol *vol);
+	int (*load)(struct objstore_vol *vol);
+
 	const struct obj_ops *obj_ops;
 	const struct vol_ops *vol_ops;
 };
--- a/src/objstore/mem/main.c	Fri Apr 22 19:39:19 2016 -0400
+++ b/src/objstore/mem/main.c	Fri Apr 22 19:39:46 2016 -0400
@@ -39,7 +39,7 @@
 	return noid_cmp(&a->oid, &b->oid);
 }
 
-static int mem_vol_create(struct objstore_vol *store)
+static int mem_create(struct objstore_vol *vol)
 {
 	struct memstore *ms;
 	struct memobj *obj;
@@ -67,7 +67,7 @@
 	avl_add(&ms->objs, memobj_getref(obj));
 	ms->root = obj; /* hand off our reference */
 
-	store->private = ms;
+	vol->private = ms;
 
 	return 0;
 }
@@ -89,12 +89,14 @@
 }
 
 static const struct vol_ops vol_ops = {
-	.create = mem_vol_create,
 	.getroot = mem_vol_getroot,
 };
 
 const struct objstore_vol_def objvol = {
 	.name = "mem",
+
+	.create = mem_create,
+
 	.vol_ops = &vol_ops,
 	.obj_ops = &obj_ops,
 };
--- a/src/objstore/vol.c	Fri Apr 22 19:39:19 2016 -0400
+++ b/src/objstore/vol.c	Fri Apr 22 19:39:46 2016 -0400
@@ -39,40 +39,40 @@
 int objstore_vol_create(struct objstore *vg, const char *path,
 			enum objstore_mode mode)
 {
-	struct objstore_vol *s;
+	struct objstore_vol *vol;
 	int ret;
 
-	if (!backend->def->vol_ops->create)
+	if (!backend->def->create)
 		return -ENOTSUP;
 
-	s = umem_cache_alloc(vol_cache, 0);
-	if (!s)
+	vol = umem_cache_alloc(vol_cache, 0);
+	if (!vol)
 		return -ENOMEM;
 
-	refcnt_init(&s->refcnt, 1);
+	refcnt_init(&vol->refcnt, 1);
 
-	s->def = backend->def;
-	s->mode = mode;
-	s->path = strdup(path);
-	if (!s->path) {
+	vol->def = backend->def;
+	vol->mode = mode;
+	vol->path = strdup(path);
+	if (!vol->path) {
 		ret = -ENOMEM;
 		goto err;
 	}
 
-	ret = s->def->vol_ops->create(s);
+	ret = vol->def->create(vol);
 	if (ret)
 		goto err_path;
 
 	/* hand off our reference */
-	vg_add_vol(vg, s);
+	vg_add_vol(vg, vol);
 
 	return 0;
 
 err_path:
-	free((char *) s->path);
+	free((char *) vol->path);
 
 err:
-	umem_cache_free(vol_cache, s);
+	umem_cache_free(vol_cache, vol);
 
 	return ret;
 }