[sheepdog] [PATCH v3 1/6] sheep/http: add nolock version for onode_lookup()

Robin Dong robin.k.dong at gmail.com
Tue Feb 25 08:59:26 CET 2014


From: Robin Dong <sanbai at taobao.com>

Remove lock from onode_create() and add nolock version
for onode_lookup()

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 sheep/http/kv.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index ac9decb..4d40c5b 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -787,7 +787,6 @@ static int onode_create(struct kv_onode *onode, uint32_t bucket_vid)
 	int ret;
 	bool create = true;
 
-	sys->cdrv->lock(bucket_vid);
 	ret = sd_read_object(vid_to_vdi_oid(bucket_vid), (char *)inode,
 			       sizeof(*inode), 0);
 	if (ret != SD_RES_SUCCESS) {
@@ -822,7 +821,6 @@ create:
 	ret = onode_do_create(onode, inode, idx, create);
 out:
 	free(inode);
-	sys->cdrv->unlock(bucket_vid);
 	return ret;
 }
 
@@ -901,14 +899,14 @@ out:
  *
  * [ sheep, dog, wolve, '\0', fish, {unallocated}, tiger, ]
  */
-static int onode_lookup(struct kv_onode *onode, uint32_t ovid, const char *name)
+static int onode_lookup_nolock(struct kv_onode *onode, uint32_t ovid,
+			       const char *name)
 {
 	struct sd_inode *inode = xmalloc(sizeof(struct sd_inode));
 	uint32_t tmp_vid, idx;
 	uint64_t hval, i;
 	int ret;
 
-	sys->cdrv->lock(ovid);
 	ret = sd_read_object(vid_to_vdi_oid(ovid), (char *)inode,
 			     sizeof(*inode), 0);
 	if (ret != SD_RES_SUCCESS) {
@@ -941,7 +939,17 @@ static int onode_lookup(struct kv_onode *onode, uint32_t ovid, const char *name)
 	}
 out:
 	free(inode);
+	return ret;
+}
+
+static int onode_lookup(struct kv_onode *onode, uint32_t ovid, const char *name)
+{
+	int ret;
+
+	sys->cdrv->lock(ovid);
+	ret = onode_lookup_nolock(onode, ovid, name);
 	sys->cdrv->unlock(ovid);
+
 	return ret;
 }
 
-- 
1.7.12.4




More information about the sheepdog mailing list