[sheepdog] [PATCH v4 3/4] sheep: use refcnt_t in various data structures
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Thu Jul 11 03:48:12 CEST 2013
This patch lets various data structures employ refcnt_t for its
reference counting of cache entries. Changed structs are: vnode_info,
client_info, request, and object_cache_entry.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v3:
- remove redundant assert()s
include/sheep.h | 3 ++-
sheep/group.c | 10 +++-------
sheep/object_cache.c | 8 ++++----
sheep/request.c | 16 ++++++++--------
sheep/sheep_priv.h | 4 ++--
sheep/vdi.c | 2 +-
6 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/include/sheep.h b/include/sheep.h
index cd23b75..44e23f2 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -17,6 +17,7 @@
#include "list.h"
#include "net.h"
#include "logger.h"
+#include "work.h"
struct sd_vnode {
struct node_id nid;
@@ -33,7 +34,7 @@ struct vnode_info {
int nr_nodes;
int nr_zones;
- int refcnt;
+ refcnt_t refcnt;
};
#define TRACE_GRAPH_ENTRY 0x01
diff --git a/sheep/group.c b/sheep/group.c
index 370c625..c8e919d 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -107,9 +107,7 @@ static int get_node_idx(struct vnode_info *vnode_info, struct sd_node *ent)
*/
struct vnode_info *grab_vnode_info(struct vnode_info *vnode_info)
{
- assert(uatomic_read(&vnode_info->refcnt) > 0);
-
- uatomic_inc(&vnode_info->refcnt);
+ refcount_inc(&vnode_info->refcnt);
return vnode_info;
}
@@ -132,9 +130,7 @@ struct vnode_info *get_vnode_info(void)
void put_vnode_info(struct vnode_info *vnode_info)
{
if (vnode_info) {
- assert(uatomic_read(&vnode_info->refcnt) > 0);
-
- if (uatomic_sub_return(&vnode_info->refcnt, 1) == 0)
+ if (refcount_dec(&vnode_info->refcnt) == 0)
free(vnode_info);
}
}
@@ -155,7 +151,7 @@ struct vnode_info *alloc_vnode_info(const struct sd_node *nodes,
vnode_info->nr_vnodes = nodes_to_vnodes(vnode_info->nodes, nr_nodes,
vnode_info->vnodes);
vnode_info->nr_zones = get_zones_nr_from(nodes, nr_nodes);
- uatomic_set(&vnode_info->refcnt, 1);
+ refcount_set(&vnode_info->refcnt, 1);
return vnode_info;
}
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 0aaf882..06054c3 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -42,7 +42,7 @@ struct global_cache {
struct object_cache_entry {
uint32_t idx; /* Index of this entry */
- int refcnt; /* Reference count of this entry */
+ refcnt_t refcnt; /* Reference count of this entry */
uint64_t bmap; /* Each bit represents one dirty block in object */
struct object_cache *oc; /* Object cache this entry belongs to */
struct rb_node node; /* For lru tree of object cache */
@@ -133,17 +133,17 @@ static uint64_t calc_object_bmap(size_t len, off_t offset)
static inline void get_cache_entry(struct object_cache_entry *entry)
{
- uatomic_inc(&entry->refcnt);
+ refcount_inc(&entry->refcnt);
}
static inline void put_cache_entry(struct object_cache_entry *entry)
{
- uatomic_dec(&entry->refcnt);
+ refcount_dec(&entry->refcnt);
}
static inline bool entry_in_use(struct object_cache_entry *entry)
{
- return uatomic_read(&entry->refcnt) > 0;
+ return refcount_read(&entry->refcnt) > 0;
}
/*
diff --git a/sheep/request.c b/sheep/request.c
index c0ed943..fc1fccf 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -487,7 +487,7 @@ static struct request *alloc_request(struct client_info *ci, int data_length)
return NULL;
req->ci = ci;
- ci->refcnt++;
+ refcount_inc(&ci->refcnt);
if (data_length) {
req->data_length = data_length;
req->data = valloc(data_length);
@@ -498,7 +498,7 @@ static struct request *alloc_request(struct client_info *ci, int data_length)
}
INIT_LIST_HEAD(&req->request_list);
- uatomic_set(&req->refcnt, 1);
+ refcount_set(&req->refcnt, 1);
uatomic_inc(&sys->nr_outstanding_reqs);
@@ -509,7 +509,7 @@ static void free_request(struct request *req)
{
uatomic_dec(&sys->nr_outstanding_reqs);
- req->ci->refcnt--;
+ refcount_dec(&req->ci->refcnt);
put_vnode_info(req->vinfo);
free(req->data);
free(req);
@@ -520,7 +520,7 @@ void put_request(struct request *req)
struct client_info *ci = req->ci;
eventfd_t value = 1;
- if (uatomic_sub_return(&req->refcnt, 1) > 0)
+ if (refcount_dec(&req->refcnt) > 0)
return;
if (req->local)
@@ -748,10 +748,10 @@ static void clear_client_info(struct client_info *ci)
unregister_event(ci->conn.fd);
- sd_dprintf("refcnt:%d, fd:%d, %s:%d", ci->refcnt, ci->conn.fd,
- ci->conn.ipstr, ci->conn.port);
+ sd_dprintf("refcnt:%d, fd:%d, %s:%d", refcount_read(&ci->refcnt),
+ ci->conn.fd, ci->conn.ipstr, ci->conn.port);
- if (ci->refcnt)
+ if (refcount_read(&ci->refcnt))
return;
destroy_client(ci);
@@ -785,7 +785,7 @@ static struct client_info *create_client(int fd, struct cluster_info *cluster)
ci->conn.fd = fd;
ci->conn.events = EPOLLIN;
- ci->refcnt = 0;
+ refcount_set(&ci->refcnt, 0);
INIT_LIST_HEAD(&ci->done_reqs);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 1f002bf..eb885a7 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -52,7 +52,7 @@ struct client_info {
struct list_head done_reqs;
- int refcnt;
+ refcnt_t refcnt;
};
enum REQUST_STATUS {
@@ -75,7 +75,7 @@ struct request {
struct list_head request_list;
struct list_head pending_list;
- int refcnt;
+ refcnt_t refcnt;
bool local;
int local_req_efd;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 0e38ba3..6839bba 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -856,7 +856,7 @@ static int start_deletion(struct request *req, uint32_t vid)
if (dw->count == 0)
goto out;
- uatomic_inc(&req->refcnt);
+ refcount_inc(&req->refcnt);
if (list_empty(&deletion_work_list)) {
list_add_tail(&dw->list, &deletion_work_list);
--
1.7.10.4
More information about the sheepdog
mailing list