[sheepdog] [PATCH v4 2/3] cache: add oid_to_entry helper
Liu Yuan
namei.unix at gmail.com
Thu Jul 18 08:38:02 CEST 2013
This is a prepare patch
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
sheep/object_cache.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 721bff6..e3270df 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1007,6 +1007,23 @@ get_cache_entry_from(struct object_cache *cache, uint32_t idx)
return entry;
}
+/* This helper increases the refcount */
+static struct object_cache_entry *oid_to_entry(uint64_t oid)
+{
+ uint32_t vid = oid_to_vid(oid);
+ uint32_t idx = object_cache_oid_to_idx(oid);
+ struct object_cache *cache;
+ struct object_cache_entry *entry;
+
+ cache = find_object_cache(vid, false);
+ entry = get_cache_entry_from(cache, idx);
+ if (!entry) {
+ sd_dprintf("%" PRIx64 " doesn't exist", oid);
+ return NULL;
+ }
+ return entry;
+}
+
static int object_cache_flush_and_delete(struct object_cache *oc)
{
DIR *dir;
@@ -1155,15 +1172,10 @@ err:
int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
uint64_t offset, bool create)
{
- uint32_t vid = oid_to_vid(oid);
- uint32_t idx = object_cache_oid_to_idx(oid);
- struct object_cache *cache;
- struct object_cache_entry *entry;
+ struct object_cache_entry *entry = oid_to_entry(oid);
int ret;
sd_dprintf("%" PRIx64, oid);
- cache = find_object_cache(vid, false);
- entry = get_cache_entry_from(cache, idx);
if (!entry) {
sd_dprintf("%" PRIx64 " doesn't exist", oid);
return SD_RES_NO_CACHE;
@@ -1177,15 +1189,10 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
uint64_t offset)
{
- uint32_t vid = oid_to_vid(oid);
- uint32_t idx = object_cache_oid_to_idx(oid);
- struct object_cache *cache;
- struct object_cache_entry *entry;
+ struct object_cache_entry *entry = oid_to_entry(oid);
int ret;
sd_dprintf("%" PRIx64, oid);
- cache = find_object_cache(vid, false);
- entry = get_cache_entry_from(cache, idx);
if (!entry) {
sd_dprintf("%" PRIx64 " doesn't exist", oid);
return SD_RES_NO_CACHE;
--
1.7.9.5
More information about the sheepdog
mailing list