# HG changeset patch # User Josef 'Jeff' Sipek # Date 1671303811 18000 # Node ID 8ccfc441cff6ea18073eb43c91907dffb830b204 # Parent 77da9822fa932c26f5e553996cc396f30a394cdf 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 diff -r 77da9822fa93 -r 8ccfc441cff6 src/objstore/obj.c --- 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); diff -r 77da9822fa93 -r 8ccfc441cff6 src/objstore/obj_ops.c --- 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); diff -r 77da9822fa93 -r 8ccfc441cff6 src/objstore/objstore_impl.h --- 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);