changeset 104:40b4277fb1e1

objstore: allow allocating & keeping track of volume groups Volume groups are currently rather empty. They just contain their name. 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:31 -0400
parents b397469f53d2
children cd8f74fb7a65
files src/client/main.c src/objstore/CMakeLists.txt src/objstore/include/nomad/objstore.h src/objstore/include/nomad/objstore_impl.h src/objstore/objstore.c src/objstore/vg.c
diffstat 6 files changed, 110 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/client/main.c	Sat Oct 17 15:27:29 2015 -0400
+++ b/src/client/main.c	Sat Oct 17 15:27:31 2015 -0400
@@ -40,6 +40,7 @@
 
 int main(int argc, char **argv)
 {
+	struct objstore *vg;
 	struct objstore_vol *vol;
 	int ret;
 
@@ -62,22 +63,34 @@
 		goto err;
 	}
 
+	vg = objstore_vg_create("myfiles");
+	fprintf(stderr, "vg = %p\n", vg);
+
+	if (IS_ERR(vg)) {
+		ret = PTR_ERR(vg);
+		fprintf(stderr, "error: %s\n", strerror(ret));
+		goto err_init;
+	}
+
 	vol = objstore_vol_create("abc", OS_MODE_STORE);
 	fprintf(stderr, "vol = %p\n", vol);
 
 	if (IS_ERR(vol)) {
 		ret = PTR_ERR(vol);
 		fprintf(stderr, "error: %s\n", strerror(ret));
-		goto err_vol;
+		goto err_vg;
 	}
 
-	ret = connsvc(NULL, CLIENT_DAEMON_PORT, process_connection, vol);
+	ret = connsvc(NULL, CLIENT_DAEMON_PORT, process_connection, vg);
 
 	fprintf(stderr, "connsvc() = %d (%s)\n", ret, strerror(ret));
 
 	/* XXX: undo objstore_vol_create() */
 
-err_vol:
+err_vg:
+	/* XXX: undo objstore_vg_create() */
+
+err_init:
 	/* XXX: undo objstore_init() */
 
 err:
--- a/src/objstore/CMakeLists.txt	Sat Oct 17 15:27:29 2015 -0400
+++ b/src/objstore/CMakeLists.txt	Sat Oct 17 15:27:31 2015 -0400
@@ -22,10 +22,12 @@
 
 add_library(nomad_objstore SHARED
 	objstore.c
+	vg.c
 )
 
 target_link_libraries(nomad_objstore
 	${BASE_LIBS}
+	${LIST_LIBRARY}
 	dl
 )
 
--- a/src/objstore/include/nomad/objstore.h	Sat Oct 17 15:27:29 2015 -0400
+++ b/src/objstore/include/nomad/objstore.h	Sat Oct 17 15:27:31 2015 -0400
@@ -23,6 +23,8 @@
 #ifndef __NOMAD_OBJSTORE_H
 #define __NOMAD_OBJSTORE_H
 
+#include <sys/list.h>
+
 #include <nomad/types.h>
 
 enum objstore_mode {
@@ -30,9 +32,19 @@
 	OS_MODE_STORE,
 };
 
+struct objstore {
+	list_node_t node;
+
+	const char *name;
+	list_t vols;		/* list of volumes */
+};
+
 struct objstore_vol_def;
 
 struct objstore_vol {
+	list_node_t vg_list;
+	struct objstore *vg;
+
 	const struct objstore_vol_def *def;
 
 	struct nuuid uuid;
@@ -44,6 +56,9 @@
 
 extern int objstore_init(void);
 
+/* volume group management */
+extern struct objstore *objstore_vg_create(const char *name);
+
 /* volume management */
 extern struct objstore_vol *objstore_vol_create(const char *path,
 						enum objstore_mode mode);
--- a/src/objstore/include/nomad/objstore_impl.h	Sat Oct 17 15:27:29 2015 -0400
+++ b/src/objstore/include/nomad/objstore_impl.h	Sat Oct 17 15:27:31 2015 -0400
@@ -60,4 +60,6 @@
 	const struct obj_ops *obj_ops;
 };
 
+extern int objstore_vg_init(void);
+
 #endif
--- a/src/objstore/objstore.c	Sat Oct 17 15:27:29 2015 -0400
+++ b/src/objstore/objstore.c	Sat Oct 17 15:27:31 2015 -0400
@@ -64,6 +64,10 @@
 {
 	int ret;
 
+	ret = objstore_vg_init();
+	if (ret)
+		return ret;
+
 	ret = load_backend(&mem_backend, "mem");
 	if (ret)
 		return ret;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/objstore/vg.c	Sat Oct 17 15:27:31 2015 -0400
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stddef.h>
+
+#include <nomad/error.h>
+#include <nomad/mutex.h>
+#include <nomad/objstore.h>
+#include <nomad/objstore_impl.h>
+
+static pthread_mutex_t vgs_lock;
+static list_t vgs;
+
+int objstore_vg_init(void)
+{
+	struct objstore *filecache;
+
+	mxinit(&vgs_lock);
+
+	list_create(&vgs, sizeof(struct objstore),
+		    offsetof(struct objstore, node));
+
+	filecache = objstore_vg_create("file$");
+	if (IS_ERR(filecache))
+		return PTR_ERR(filecache);
+
+	return 0;
+}
+
+struct objstore *objstore_vg_create(const char *name)
+{
+	struct objstore *vg;
+
+	vg = malloc(sizeof(struct objstore));
+	if (!vg)
+		return ERR_PTR(ENOMEM);
+
+	vg->name = strdup(name);
+	if (!vg->name) {
+		free(vg);
+		return ERR_PTR(ENOMEM);
+	}
+
+	list_create(&vg->vols, sizeof(struct objstore_vol),
+		    offsetof(struct objstore_vol, vg_list));
+
+	mxlock(&vgs_lock);
+	list_insert_tail(&vgs, vg);
+	mxunlock(&vgs_lock);
+
+	return vg;
+}