Mercurial > nomad
changeset 852:8ccfc441cff6
objstore: add alloc_only argument to obj_by_oid
This bool will allow obj_by_oid to be used to look up both existing objects
(e.g., during open) and not-yet-created objects (e.g., during create).
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 17 Dec 2022 14:03:31 -0500 |
parents | 77da9822fa93 |
children | dc84208232c6 |
files | src/objstore/obj.c src/objstore/obj_ops.c src/objstore/objstore_impl.h |
diffstat | 3 files changed, 15 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/obj.c Sat Dec 17 20:43:56 2022 -0500 +++ b/src/objstore/obj.c Sat Dec 17 14:03:31 2022 -0500 @@ -224,7 +224,8 @@ * * Return with the object locked and referenced. */ -struct obj *obj_by_oid(struct objstore_clone *clone, const struct noid *oid) +struct obj *obj_by_oid(struct objstore_clone *clone, const struct noid *oid, + bool alloc_only) { struct objstore *vol = clone->vol; struct obj *obj; @@ -243,13 +244,19 @@ goto err_obj_new; } - ret = clone->ops->initobj(obj, false); + ret = clone->ops->initobj(obj, alloc_only); if (ret) goto err_obj_new; - /* must have at least one version & head */ - ASSERT3U(obj->nversions, >=, 1); - ASSERT3U(rb_numnodes(&obj->heads), >=, 1); + if (alloc_only) { + /* must have no versions or heads */ + ASSERT3U(obj->nversions, ==, 0); + ASSERT3U(rb_numnodes(&obj->heads), ==, 0); + } else { + /* must have at least one version & head */ + ASSERT3U(obj->nversions, >=, 1); + ASSERT3U(rb_numnodes(&obj->heads), >=, 1); + } obj->state = OBJ_STATE_LIVE; break; @@ -313,7 +320,7 @@ /* * First, find the object based on the oid. */ - obj = obj_by_oid(clone, oid); + obj = obj_by_oid(clone, oid, false); if (IS_ERR(obj)) return ERR_CAST(obj);
--- a/src/objstore/obj_ops.c Sat Dec 17 20:43:56 2022 -0500 +++ b/src/objstore/obj_ops.c Sat Dec 17 14:03:31 2022 -0500 @@ -31,7 +31,7 @@ if (!vol || !oid || !infos || !ninfos) return -EINVAL; - obj = obj_by_oid(vol->clone, oid); + obj = obj_by_oid(vol->clone, oid, false); if (IS_ERR(obj)) return PTR_ERR(obj);
--- a/src/objstore/objstore_impl.h Sat Dec 17 20:43:56 2022 -0500 +++ b/src/objstore/objstore_impl.h Sat Dec 17 14:03:31 2022 -0500 @@ -77,7 +77,7 @@ extern void objver_free(struct objver *ver); extern struct obj *obj_by_oid(struct objstore_clone *clone, - const struct noid *oid); + const struct noid *oid, bool alloc_only); extern struct objver *objver_by_clock(struct objstore_clone *clone, const struct noid *oid, const struct nvclock *clock);