Mercurial > nomad > experimental
changeset 272:23ccd4b1ff6a
objstore/mem: remove per backend object lock
The locking is taken care of by the generic code on the generic object
structure.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 25 Apr 2016 10:11:01 -0400 |
parents | 0d144c4bff6c |
children | 730dc1ba3c71 |
files | src/objstore/mem/main.c src/objstore/mem/mem.h src/objstore/mem/obj.c |
diffstat | 3 files changed, 35 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/mem/main.c Mon Apr 25 10:07:38 2016 -0400 +++ b/src/objstore/mem/main.c Mon Apr 25 10:11:01 2016 -0400 @@ -62,12 +62,10 @@ if (!mobj) return -ENOENT; - mxlock(&mobj->lock); obj->nversions = avl_numnodes(&mobj->versions); obj->nlink = mobj->nlink; obj->private = mobj; obj->ops = &obj_ops; - mxunlock(&mobj->lock); return 0; }
--- a/src/objstore/mem/mem.h Mon Apr 25 10:07:38 2016 -0400 +++ b/src/objstore/mem/mem.h Mon Apr 25 10:11:01 2016 -0400 @@ -94,7 +94,6 @@ /* misc */ avl_node_t node; refcnt_t refcnt; - pthread_mutex_t lock; }; /* <name> -> <specific version of an obj> */
--- a/src/objstore/mem/obj.c Mon Apr 25 10:07:38 2016 -0400 +++ b/src/objstore/mem/obj.c Mon Apr 25 10:11:01 2016 -0400 @@ -143,7 +143,6 @@ obj->nlink = 0; refcnt_init(&obj->refcnt, 1); - mxinit(&obj->lock); avl_create(&obj->versions, ver_cmp, sizeof(struct memver), offsetof(struct memver, node)); @@ -194,7 +193,6 @@ freeobjver(ver); avl_destroy(&obj->versions); - mxdestroy(&obj->lock); free(obj); } @@ -208,7 +206,7 @@ } /* - * returns a specific version of an object, with the object held & locked + * returns a specific version of an object, with the object held */ struct memver *findver_by_hndl(struct memstore *store, const struct noid *oid, @@ -224,7 +222,6 @@ if (!obj) return ERR_PTR(-ENOENT); - mxlock(&obj->lock); switch (avl_numnodes(&obj->versions)) { case 0: break; @@ -242,7 +239,6 @@ }; if (nvclock_is_null(clock)) { - mxunlock(&obj->lock); memobj_putref(obj); return ERR_PTR(-ENOTUNIQ); } @@ -255,8 +251,6 @@ } } - mxunlock(&obj->lock); - memobj_putref(obj); return ERR_PTR(-ENOENT); @@ -278,10 +272,10 @@ return ver; /* - * The object associated with 'ver' is locked and held. We unlock - * it, but keep the hold on it. Then we return the pointer to the - * memver to the caller. Then, later on when the caller calls the - * close function, we release the object's hold. + * The object associated with 'ver' is held. We keep the hold on + * it. Then we return the pointer to the memver to the caller. + * Then, later on when the caller calls the close function, we + * release the object's hold. * * While the object version is open, we maintain this reference hold * keeping the object and the version structures in memory. Even if @@ -290,8 +284,6 @@ * well. */ - mxunlock(&ver->obj->lock); - return ver; } @@ -325,13 +317,9 @@ if (!vol || !cookie || !attr) return -EINVAL; - mxlock(&ver->obj->lock); - *attr = ver->attrs; attr->nlink = ver->obj->nlink; - mxunlock(&ver->obj->lock); - return 0; } @@ -371,21 +359,15 @@ if (!vol || !cookie || !attr) return -EINVAL; - mxlock(&ver->obj->lock); - /* * first do some checks */ - if (!NATTR_ISREG(ver->attrs.mode)) { - ret = -EINVAL; - goto err_unlock; - } + if (!NATTR_ISREG(ver->attrs.mode)) + return -EINVAL; /* we can't change the type of the object */ - if ((attr->mode & NATTR_TMASK) != (ver->attrs.mode & NATTR_TMASK)) { - ret = -EINVAL; - goto err_unlock; - } + if ((attr->mode & NATTR_TMASK) != (ver->attrs.mode & NATTR_TMASK)) + return -EINVAL; /* * now do the updates @@ -394,7 +376,7 @@ if (valid & OBJ_ATTR_SIZE) { ret = __truncate(ver, attr->size, true); if (ret) - goto err_unlock; + return ret; } if (valid & OBJ_ATTR_MODE) @@ -403,12 +385,7 @@ /* TODO: do we need to tweak the versions AVL tree? */ nvclock_inc(ver->clock); - ret = 0; - -err_unlock: - mxunlock(&ver->obj->lock); - - return ret; + return 0; } static ssize_t mem_obj_read(struct objstore_vol *vol, void *cookie, @@ -424,12 +401,8 @@ if (!len) return 0; - mxlock(&ver->obj->lock); - - if (NATTR_ISDIR(ver->attrs.mode)) { - ret = -EISDIR; - goto err_unlock; - } + if (NATTR_ISDIR(ver->attrs.mode)) + return -EISDIR; /* TODO: do we need to check for other types? */ @@ -443,9 +416,6 @@ if (ret) memcpy(buf, ver->blob + offset, ret); -err_unlock: - mxunlock(&ver->obj->lock); - return ret; } @@ -462,12 +432,8 @@ if (!len) return 0; - mxlock(&ver->obj->lock); - - if (NATTR_ISDIR(ver->attrs.mode)) { - ret = -EISDIR; - goto err_unlock; - } + if (NATTR_ISDIR(ver->attrs.mode)) + return -EISDIR; /* TODO: do we need to check for other types? */ @@ -475,7 +441,7 @@ if ((offset + len) > ver->attrs.size) { ret = __truncate(ver, offset + len, false); if (ret) - goto err_unlock; + return ret; } memcpy(ver->blob + offset, buf, len); @@ -485,9 +451,6 @@ /* TODO: do we need to tweak the versions AVL tree? */ nvclock_inc(ver->clock); -err_unlock: - mxunlock(&ver->obj->lock); - return ret; } @@ -499,37 +462,23 @@ }; struct memver *dirver = dircookie; struct memdentry *dentry; - int ret; if (!vol || !dirver || !name || !child) return -EINVAL; - mxlock(&dirver->obj->lock); - - if (!NATTR_ISDIR(dirver->attrs.mode)) { - ret = -ENOTDIR; - goto err_unlock; - } + if (!NATTR_ISDIR(dirver->attrs.mode)) + return -ENOTDIR; dentry = avl_find(&dirver->dentries, &key, NULL); - if (!dentry) { - ret = -ENOENT; - goto err_unlock; - } + if (!dentry) + return -ENOENT; - mxlock(&dentry->obj->lock); *child = dentry->obj->oid; - mxunlock(&dentry->obj->lock); - ret = 0; - -err_unlock: - mxunlock(&dirver->obj->lock); - - return ret; + return 0; } -/* returns a locked & referenced child object */ +/* returns a referenced child object */ static struct memobj *__obj_create(struct memstore *store, struct memver *dir, const char *name, uint16_t mode) { @@ -548,9 +497,6 @@ return ERR_CAST(dentry); } - /* lock the object */ - mxlock(&obj->lock); - /* add the dentry to the parent */ avl_add(&dir->dentries, dentry); @@ -580,42 +526,28 @@ struct memstore *ms; struct memobj *childobj; struct memver *dirver = dircookie; - int ret; if (!vol || !dirver || !name || !child) return -EINVAL; ms = vol->private; - mxlock(&dirver->obj->lock); + if (!NATTR_ISDIR(dirver->attrs.mode)) + return -ENOTDIR; - if (!NATTR_ISDIR(dirver->attrs.mode)) { - ret = -ENOTDIR; - goto err_unlock; - } - - if (avl_find(&dirver->dentries, &key, NULL)) { - ret = -EEXIST; - goto err_unlock; - } + if (avl_find(&dirver->dentries, &key, NULL)) + return -EEXIST; childobj = __obj_create(ms, dirver, name, mode); - if (IS_ERR(childobj)) { - ret = PTR_ERR(childobj); - goto err_unlock; - } + if (IS_ERR(childobj)) + return PTR_ERR(childobj); /* set return oid */ *child = childobj->oid; - ret = 0; - mxunlock(&childobj->lock); memobj_putref(childobj); -err_unlock: - mxunlock(&dirver->obj->lock); - - return ret; + return 0; } static int __obj_unlink(struct memstore *store, struct memver *dir, @@ -626,8 +558,6 @@ /* get a reference for us */ child = memobj_getref(dentry->obj); - mxlock(&child->lock); - /* remove the dentry from the directory */ avl_remove(&dir->dentries, dentry); @@ -644,8 +574,7 @@ memobj_putref(child); } - /* unlock & put our ref */ - mxunlock(&child->lock); + /* put our ref */ memobj_putref(child); /* @@ -667,33 +596,21 @@ struct memdentry *dentry; struct memver *dirver = dircookie; struct memstore *ms; - int ret; if (!vol || !dirver || !name) return -EINVAL; ms = vol->private; - mxlock(&dirver->obj->lock); - - if (!NATTR_ISDIR(dirver->attrs.mode)) { - ret = -ENOTDIR; - goto err_unlock; - } + if (!NATTR_ISDIR(dirver->attrs.mode)) + return -ENOTDIR; dentry = avl_find(&dirver->dentries, &key, NULL); - if (!dentry) { - ret = -ENOENT; - goto err_unlock; - } + if (!dentry) + return -ENOENT; /* ok, we got the dentry - remove it */ - ret = __obj_unlink(ms, dirver, dentry); - -err_unlock: - mxunlock(&dirver->obj->lock); - - return ret; + return __obj_unlink(ms, dirver, dentry); } const struct obj_ops obj_ops = {