changeset 144:b3d800982276

objstore: clean up & reorganize getattr Split the existing function into two: one that given a vg forwards the operation to the volume code based on the vg type, and one that operates on a single volume. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 18 Oct 2015 13:21:04 -0400
parents 8cdc4c122e03
children 4c6f76989836
files src/objstore/CMakeLists.txt src/objstore/include/nomad/objstore.h src/objstore/include/nomad/objstore_impl.h src/objstore/obj.c src/objstore/objstore.c src/objstore/vg.c
diffstat 6 files changed, 67 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/objstore/CMakeLists.txt	Sun Oct 18 13:18:54 2015 -0400
+++ b/src/objstore/CMakeLists.txt	Sun Oct 18 13:21:04 2015 -0400
@@ -21,6 +21,7 @@
 #
 
 add_library(nomad_objstore SHARED
+	obj.c
 	objstore.c
 	vg.c
 	vol.c
--- a/src/objstore/include/nomad/objstore.h	Sun Oct 18 13:18:54 2015 -0400
+++ b/src/objstore/include/nomad/objstore.h	Sun Oct 18 13:21:04 2015 -0400
@@ -81,8 +81,7 @@
 extern int objstore_getroot(struct objstore *vg, struct nobjhndl *hndl);
 
 /* object operations */
-extern int objstore_obj_getattr(struct objstore_vol *store,
-				const struct nobjhndl *hndl,
-				struct nattr *attr);
+extern int objstore_getattr(struct objstore *vg, const struct nobjhndl *hndl,
+			    struct nattr *attr);
 
 #endif
--- a/src/objstore/include/nomad/objstore_impl.h	Sun Oct 18 13:18:54 2015 -0400
+++ b/src/objstore/include/nomad/objstore_impl.h	Sun Oct 18 13:21:04 2015 -0400
@@ -67,4 +67,8 @@
 /* wrappers for volume ops */
 extern int objstore_vol_getroot(struct objstore_vol *vol, struct nobjhndl *hndl);
 
+/* wrappers for object ops */
+extern int objstore_vol_getattr(struct objstore_vol *vol,
+				const struct nobjhndl *hndl, struct nattr *attr);
+
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/objstore/obj.c	Sun Oct 18 13:21:04 2015 -0400
@@ -0,0 +1,37 @@
+/*
+ * 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 <nomad/error.h>
+#include <nomad/objstore.h>
+#include <nomad/objstore_impl.h>
+
+int objstore_vol_getattr(struct objstore_vol *vol, const struct nobjhndl *hndl,
+			 struct nattr *attr)
+{
+	if (!vol || !hndl || !hndl->clock || !attr)
+		return EINVAL;
+
+	if (!vol->def->obj_ops || !vol->def->obj_ops->getattr)
+		return ENOTSUP;
+
+	return vol->def->obj_ops->getattr(vol, hndl, attr);
+}
--- a/src/objstore/objstore.c	Sun Oct 18 13:18:54 2015 -0400
+++ b/src/objstore/objstore.c	Sun Oct 18 13:21:04 2015 -0400
@@ -120,15 +120,3 @@
 {
 	return ERR_PTR(ENOTSUP);
 }
-
-int objstore_obj_getattr(struct objstore_vol *store, const struct nobjhndl *hndl,
-			 struct nattr *attr)
-{
-	if (!hndl || !hndl->clock)
-		return EINVAL;
-
-	if (!store || !store->def->obj_ops || !store->def->obj_ops->getattr)
-		return EINVAL;
-
-	return store->def->obj_ops->getattr(store, hndl, attr);
-}
--- a/src/objstore/vg.c	Sun Oct 18 13:18:54 2015 -0400
+++ b/src/objstore/vg.c	Sun Oct 18 13:21:04 2015 -0400
@@ -117,3 +117,26 @@
 
 	return ret;
 }
+
+int objstore_getattr(struct objstore *vg, const struct nobjhndl *hndl,
+		     struct nattr *attr)
+{
+	struct objstore_vol *vol;
+	int ret;
+
+	if (!vg || !hndl || !attr)
+		return EINVAL;
+
+	/*
+	 * TODO: we're assuming OS_VG_SIMPLE
+	 */
+	mxlock(&vg->lock);
+	vol = list_head(&vg->vols);
+	if (vol)
+		ret = objstore_vol_getattr(vol, hndl, attr);
+	else
+		ret = ENXIO;
+	mxunlock(&vg->lock);
+
+	return ret;
+}