From: Liu Yuan <[email protected]> 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 <[email protected]> --- 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 -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
