changeset 725:d32f426dfa36

objstore: replace volume vdev pointer with a clone pointer Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 29 Jun 2019 10:34:48 -0400
parents 5d393695de9f
children 169419861ba8
files src/objstore/include/nomad/objstore.h src/objstore/mem/main.c src/objstore/mem/obj.c src/objstore/posix/main.c src/objstore/vol.c
diffstat 5 files changed, 28 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/objstore/include/nomad/objstore.h	Sat Jun 29 09:54:06 2019 -0400
+++ b/src/objstore/include/nomad/objstore.h	Sat Jun 29 10:34:48 2019 -0400
@@ -56,6 +56,8 @@
 	void *private;
 };
 
+struct objstore_clone;
+
 struct objstore {
 	struct rb_node node;
 
@@ -64,7 +66,7 @@
 	/* the following can be read without locking the volume */
 	refcnt_t refcnt;
 	const struct vol_ops *ops;
-	struct objstore_vdev *vdev;
+	struct objstore_clone *clone; /* FIXME: should be a list */
 	struct xuuid uuid;
 
 	/* the following are protected by the volume lock */
--- a/src/objstore/mem/main.c	Sat Jun 29 09:54:06 2019 -0400
+++ b/src/objstore/mem/main.c	Sat Jun 29 10:34:48 2019 -0400
@@ -35,7 +35,7 @@
 
 static int mem_vdev_getroot(struct objstore *vol, struct noid *root)
 {
-	struct memstore *ms = vol->vdev->private;
+	struct memstore *ms = vol->clone->vdev->private;
 
 	MXLOCK(&ms->lock);
 	*root = ms->root->oid;
@@ -46,7 +46,7 @@
 
 static int mem_initobj(struct obj *obj)
 {
-	struct memstore *ms = obj->vol->vdev->private;
+	struct memstore *ms = obj->vol->clone->vdev->private;
 	struct memobj key = {
 		.oid = obj->oid,
 	};
--- a/src/objstore/mem/obj.c	Sat Jun 29 09:54:06 2019 -0400
+++ b/src/objstore/mem/obj.c	Sat Jun 29 10:34:48 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  * Copyright (c) 2015 Holly Sipek
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -278,7 +278,7 @@
 
 static int mem_obj_checkversion(struct obj *obj, const struct nvclock *clock)
 {
-	struct memstore *ms = obj->vol->vdev->private;
+	struct memstore *ms = obj->vol->clone->vdev->private;
 	struct memver *mver;
 
 	mver = findver_by_hndl(ms, &obj->oid, clock);
@@ -492,7 +492,7 @@
 	const struct memdentry key = {
 		.name = name,
 	};
-	struct memstore *ms = dirver->obj->vol->vdev->private;
+	struct memstore *ms = dirver->obj->vol->clone->vdev->private;
 	struct memver *dirmver = dirver->private;
 	struct memobj *childobj;
 
--- a/src/objstore/posix/main.c	Sat Jun 29 09:54:06 2019 -0400
+++ b/src/objstore/posix/main.c	Sat Jun 29 10:34:48 2019 -0400
@@ -212,7 +212,7 @@
 
 static int __create_vol(struct posix_vol *pvol, const char *volid)
 {
-	struct posix_vdev *pvdev = pvol->vol->vdev->private;
+	struct posix_vdev *pvdev = pvol->vol->clone->vdev->private;
 	struct posix_vol_header hdr;
 	int ret;
 
--- a/src/objstore/vol.c	Sat Jun 29 09:54:06 2019 -0400
+++ b/src/objstore/vol.c	Sat Jun 29 10:34:48 2019 -0400
@@ -84,7 +84,8 @@
 	return noid_cmp(&a->oid, &b->oid);
 }
 
-static struct objstore *vol_alloc(struct objstore_vdev *vdev)
+static struct objstore *vol_alloc(struct objstore_clone *clone,
+				  struct objstore_vdev *vdev)
 {
 	struct objstore *vol;
 	void *priv;
@@ -106,10 +107,15 @@
 		goto err_priv;
 	}
 
+	vdev_getref(vdev);
+
 	refcnt_init(&vol->refcnt, 1);
 	vol->ops = NULL;
-	vol->vdev = vdev_getref(vdev);
-	xuuid_generate(&vol->uuid);
+	vol->clone = clone;
+	if (clone)
+		vol->uuid = clone->uuid;
+	else
+		xuuid_generate(&vol->uuid);
 	vol->private = priv;
 
 	MXINIT(&vol->lock, &vol_lc);
@@ -127,16 +133,18 @@
 
 static void vol_free(struct objstore *vol)
 {
-	if (vol->vdev->def->vol_private_size)
+	if (vol->clone->vdev->def->vol_private_size)
 		free(vol->private);
 
-	vdev_putref(vol->vdev);
+	vdev_putref(vol->clone->vdev);
 
 	mem_cache_free(vol_cache, vol);
 }
 
 static void check_vol_ops(struct objstore *vol)
 {
+	struct objstore_vdev *vdev = vol->clone->vdev;
+
 	/*
 	 * We warn here (instead of when we try to use the ops) to avoid
 	 * spamming the log with these messages.  We also don't do anything
@@ -144,10 +152,10 @@
 	 */
 	if (!vol->ops)
 		cmn_err(CE_INFO, "Volume ops are required (backend: %s)",
-			vol->vdev->def->name);
+			vdev->def->name);
 	else if (!vol->ops->initobj)
 		cmn_err(CE_INFO, "Object init function is required (backend: %s)",
-			vol->vdev->def->name);
+			vdev->def->name);
 }
 
 struct objstore *objstore_vol_create(struct objstore_vdev *vdev)
@@ -158,7 +166,7 @@
 	if (!vdev->def->create_vol)
 		return ERR_PTR(-ENOTSUP);
 
-	vol = vol_alloc(vdev);
+	vol = vol_alloc(NULL, vdev);
 	if (IS_ERR(vol))
 		return vol;
 
@@ -188,12 +196,10 @@
 	if (!clone->vdev->def->import_vol)
 		return -ENOTSUP;
 
-	vol = vol_alloc(clone->vdev);
+	vol = vol_alloc(clone, clone->vdev);
 	if (IS_ERR(vol))
 		return PTR_ERR(vol);
 
-	vol->uuid = clone->uuid;
-
 	ret = clone->vdev->def->import_vol(vol);
 	if (ret)
 		goto err;
@@ -253,7 +259,7 @@
 	rb_for_each(&loaded_vols.tree, cur) {
 		struct vol_info *info = &(*vols)[i++];
 
-		info->vdevid = cur->vdev->uuid;
+		info->vdevid = cur->clone->vdev->uuid;
 		info->volid  = cur->uuid;
 	}
 
@@ -273,7 +279,7 @@
 	ASSERT0(rb_numnodes(&vol->objs));
 	rb_destroy(&vol->objs);
 
-	vdev_putref(vol->vdev);
+	vdev_putref(vol->clone->vdev);
 
 	mem_cache_free(vol_cache, vol);
 }