view src/objstore/posix/vol.c @ 851:77da9822fa93

objstore/posix: don't walk object versions during create-type initobj Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 17 Dec 2022 20:43:56 -0500
parents 40d18d06086a
children 8d3171c87786
line wrap: on
line source

/*
 * Copyright (c) 2018-2020,2022 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 "posix.h"

static int posix_getroot(struct objstore_clone *clone, struct noid *root)
{
	struct posix_vol *pvol = clone->private;

	noid_set(root, &clone->uuid, pvol->root_host, pvol->root_uniq);

	return 0;
}

static int __initobj_alloc_version(struct posix_obj *pobj, void *private,
				   struct dirent *dirent)
{
	struct obj *obj = pobj->obj;
	struct nvclock clock;
	struct objver *ver;
	int ret;

	ret = nvclock_from_str(&clock, dirent->d_name);
	if (ret)
		return ret;

	ver = obj_add_version(obj, &clock);

	return IS_ERR(ver) ? PTR_ERR(ver) : 0;
}

static int posix_initobj(struct obj *obj, bool create)
{
	struct posix_obj *pobj;
	int ret;

	pobj = malloc(sizeof(struct posix_obj));
	if (!pobj)
		return -ENOMEM;

	snprintf(pobj->objname, sizeof(pobj->objname), "%016"PRIx64"-%016"PRIx64,
		 noid_get_allocator(&obj->oid), noid_get_uniq(&obj->oid));

	/* set all these before calling the walker code */
	obj->nversions = 0;
	obj->ops = &posix_obj_ops;
	obj->private = pobj;

	pobj->obj = obj;

	/* load all the versions */
	if (create) {
		ret = 0; /* nothing to do */
	} else {
		ret = walk_object_versions(pobj, -1, __initobj_alloc_version,
					   NULL);
		if (ret)
			goto err;
	}

	obj->nversions = rb_numnodes(&obj->versions);

	return ret;

err:
	/* reset just to make sure */
	obj->nversions = 0;
	obj->ops = NULL;
	obj->private = NULL;

	free(pobj);

	return ret;
}

static int posix_allocoid(struct objstore_clone *clone, struct noid *new)
{
	struct posix_vol *pvol = clone->private;

	FIXME("we need to prevent concurent RMW for next_uniq");
	noid_set(new, &clone->uuid, nomad_local_node_id(), pvol->next_uniq++);

	return 0;
}

static int posix_createobj(struct objstore_clone *clone,
			   const struct noid *oid, const struct nvclock *clock,
			   const struct nattr *attrs, const struct noid *parent)
{
	struct posix_vol *pvol = clone->private;

	return create_obj(pvol->rootfd,
			  noid_get_allocator(oid), noid_get_uniq(oid),
			  noid_get_allocator(parent), noid_get_uniq(parent),
			  clock, attrs);
}

const struct clone_ops posix_clone_ops = {
	.getroot  = posix_getroot,
	.initobj  = posix_initobj,
	.allocoid = posix_allocoid,
	.createobj = posix_createobj,

	.txn_begin  = posix_txn_begin,
	.txn_log_entry = posix_txn_log_entry,
	.txn_commit = posix_txn_commit,
	.txn_complete = posix_txn_complete,
	.txn_abort  = posix_txn_abort,
};