changeset 105:cd8f74fb7a65

objstore: associate each created volume with a volume group Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Signed-off-by: Steve Dougherty <steve@asksteved.com>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 17 Oct 2015 15:27:39 -0400
parents 40b4277fb1e1
children d1b40f1a89a6
files src/client/main.c src/objstore/include/nomad/objstore.h src/objstore/include/nomad/objstore_impl.h src/objstore/objstore.c src/objstore/vg.c
diffstat 5 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/client/main.c	Sat Oct 17 15:27:31 2015 -0400
+++ b/src/client/main.c	Sat Oct 17 15:27:39 2015 -0400
@@ -72,7 +72,7 @@
 		goto err_init;
 	}
 
-	vol = objstore_vol_create("abc", OS_MODE_STORE);
+	vol = objstore_vol_create(vg, "fauxpath", OS_MODE_STORE);
 	fprintf(stderr, "vol = %p\n", vol);
 
 	if (IS_ERR(vol)) {
--- a/src/objstore/include/nomad/objstore.h	Sat Oct 17 15:27:31 2015 -0400
+++ b/src/objstore/include/nomad/objstore.h	Sat Oct 17 15:27:39 2015 -0400
@@ -26,6 +26,7 @@
 #include <sys/list.h>
 
 #include <nomad/types.h>
+#include <nomad/mutex.h>
 
 enum objstore_mode {
 	OS_MODE_CACHE,
@@ -35,6 +36,7 @@
 struct objstore {
 	list_node_t node;
 
+	pthread_mutex_t lock;
 	const char *name;
 	list_t vols;		/* list of volumes */
 };
@@ -60,9 +62,11 @@
 extern struct objstore *objstore_vg_create(const char *name);
 
 /* volume management */
-extern struct objstore_vol *objstore_vol_create(const char *path,
+extern struct objstore_vol *objstore_vol_create(struct objstore *vg,
+						const char *path,
 						enum objstore_mode mode);
-extern struct objstore_vol *objstore_vol_load(struct nuuid *uuid,
+extern struct objstore_vol *objstore_vol_load(struct objstore *vg,
+					      struct nuuid *uuid,
 					      const char *path);
 
 /* volume operations */
--- a/src/objstore/include/nomad/objstore_impl.h	Sat Oct 17 15:27:31 2015 -0400
+++ b/src/objstore/include/nomad/objstore_impl.h	Sat Oct 17 15:27:39 2015 -0400
@@ -60,6 +60,8 @@
 	const struct obj_ops *obj_ops;
 };
 
+/* internal volume group management helpers */
 extern int objstore_vg_init(void);
+extern void objstore_vg_add_vol(struct objstore *vg, struct objstore_vol *vol);
 
 #endif
--- a/src/objstore/objstore.c	Sat Oct 17 15:27:31 2015 -0400
+++ b/src/objstore/objstore.c	Sat Oct 17 15:27:39 2015 -0400
@@ -77,7 +77,8 @@
 	return 0;
 }
 
-struct objstore_vol *objstore_vol_create(const char *path, enum objstore_mode mode)
+struct objstore_vol *objstore_vol_create(struct objstore *vg, const char *path,
+					 enum objstore_mode mode)
 {
 	struct objstore_vol *s;
 	int ret;
@@ -101,6 +102,8 @@
 	if (ret)
 		goto err_path;
 
+	objstore_vg_add_vol(vg, s);
+
 	return s;
 
 err_path:
@@ -112,7 +115,8 @@
 	return ERR_PTR(ret);
 }
 
-struct objstore_vol *objstore_vol_load(struct nuuid *uuid, const char *path)
+struct objstore_vol *objstore_vol_load(struct objstore *vg, struct nuuid *uuid,
+				       const char *path)
 {
 	return ERR_PTR(ENOTSUP);
 }
--- a/src/objstore/vg.c	Sat Oct 17 15:27:31 2015 -0400
+++ b/src/objstore/vg.c	Sat Oct 17 15:27:39 2015 -0400
@@ -23,7 +23,6 @@
 #include <stddef.h>
 
 #include <nomad/error.h>
-#include <nomad/mutex.h>
 #include <nomad/objstore.h>
 #include <nomad/objstore_impl.h>
 
@@ -63,9 +62,18 @@
 	list_create(&vg->vols, sizeof(struct objstore_vol),
 		    offsetof(struct objstore_vol, vg_list));
 
+	mxinit(&vg->lock);
+
 	mxlock(&vgs_lock);
 	list_insert_tail(&vgs, vg);
 	mxunlock(&vgs_lock);
 
 	return vg;
 }
+
+void objstore_vg_add_vol(struct objstore *vg, struct objstore_vol *vol)
+{
+	mxlock(&vg->lock);
+	list_insert_tail(&vg->vols, vol);
+	mxunlock(&vg->lock);
+}