[sheepdog] [PATCH 3/6] object cache: fix object_cache_lookup()
Liu Yuan
namei.unix at gmail.com
Wed Aug 1 12:03:47 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
one of object_cache_lookup() callers, object_is_cached() can be called in main
thread, then we shouldn't try to sleep at main thread, otherwise we'll meet a
deadlock between threads doing push and main thread.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/object_cache.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index e986bed..5e709c2 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -648,18 +648,23 @@ static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
int fd, ret = SD_RES_SUCCESS, flags = def_open_flags;
unsigned data_length;
- if (!create) {
- pthread_rwlock_wrlock(&oc->lock);
- if (!object_tree_search(&oc->object_tree, idx))
- ret = SD_RES_NO_CACHE;
- pthread_rwlock_unlock(&oc->lock);
- return ret;
- }
-
strbuf_init(&buf, PATH_MAX);
strbuf_addstr(&buf, cache_dir);
strbuf_addf(&buf, "/%06"PRIx32"/%08"PRIx32, oc->vid, idx);
+ if (!create) {
+ if (access(buf.buf, R_OK | W_OK) < 0) {
+ if (errno != ENOENT) {
+ dprintf("%m\n");
+ ret = SD_RES_EIO;
+ } else {
+ ret = SD_RES_NO_CACHE;
+ }
+ return ret;
+ }
+ return ret;
+ }
+
flags |= O_CREAT | O_TRUNC;
fd = open(buf.buf, flags, def_fmode);
--
1.7.10.2
More information about the sheepdog
mailing list