changeset 565:a7132fb142ae

objstore: add a state to struct vdev Currently, it doesn't do much. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 02 Dec 2018 10:40:03 -0500
parents ea6421cabc8c
children 6cc439510275
files src/objstore/include/nomad/objstore.h src/objstore/vdev.c
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/objstore/include/nomad/objstore.h	Sun Dec 02 10:39:04 2018 -0500
+++ b/src/objstore/include/nomad/objstore.h	Sun Dec 02 10:40:03 2018 -0500
@@ -41,11 +41,19 @@
 struct objstore_vdev {
 	struct rb_node node;
 
+	struct lock lock;
+
+	/* the following can be read without locking the vdev */
 	refcnt_t refcnt;
 	const struct objstore_vdev_def *def;
 	const char *path;
 	struct xuuid uuid;
 
+	/* the following are protected by the vdev lock */
+	enum vdev_state {
+		VDEV_LOADING,
+		VDEV_ONLINE,
+	} state;
 	void *private;
 };
 
--- a/src/objstore/vdev.c	Sun Dec 02 10:39:04 2018 -0500
+++ b/src/objstore/vdev.c	Sun Dec 02 10:40:03 2018 -0500
@@ -27,6 +27,7 @@
 static struct mem_cache *vdev_cache;
 
 static LOCK_CLASS(vdevs_lc);
+static LOCK_CLASS(vdev_lc);
 
 static struct {
 	struct lock lock;
@@ -88,8 +89,11 @@
 	vdev->def = backend->def;
 	vdev->path = path;
 	xuuid_clear(&vdev->uuid);
+	vdev->state = VDEV_LOADING;
 	vdev->private = NULL;
 
+	MXINIT(&vdev->lock, &vdev_lc);
+
 	return vdev;
 
 err:
@@ -103,6 +107,8 @@
 	if (!vdev)
 		return;
 
+	MXDESTROY(&vdev->lock);
+
 	free((char *) vdev->path);
 	mem_cache_free(vdev_cache, vdev);
 }
@@ -143,6 +149,10 @@
 
 	/* TODO: load all vols */
 
+	MXLOCK(&vdev->lock);
+	vdev->state = VDEV_ONLINE;
+	MXUNLOCK(&vdev->lock);
+
 	return vdev;
 
 err: