diff options
author | Sage Weil <sage@newdream.net> | 2009-12-07 18:55:05 -0500 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2009-12-07 18:55:05 -0500 |
commit | c2e552e76e2c6907ca50cd9a4b747a2e2e8c615e (patch) | |
tree | 4251e189caeb4de3f4a8763ae70600fc9d3acb51 /fs/ceph | |
parent | 415e49a9c4faf1a1480b1497da2037608e5aa2c5 (diff) |
ceph: use kref for ceph_msg
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph')
-rw-r--r-- | fs/ceph/messenger.c | 47 | ||||
-rw-r--r-- | fs/ceph/messenger.h | 13 | ||||
-rw-r--r-- | fs/ceph/msgpool.c | 2 |
3 files changed, 27 insertions, 35 deletions
diff --git a/fs/ceph/messenger.c b/fs/ceph/messenger.c index bf762107b3d5..b0571b01b19f 100644 --- a/fs/ceph/messenger.c +++ b/fs/ceph/messenger.c | |||
@@ -1958,7 +1958,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, | |||
1958 | m = kmalloc(sizeof(*m), GFP_NOFS); | 1958 | m = kmalloc(sizeof(*m), GFP_NOFS); |
1959 | if (m == NULL) | 1959 | if (m == NULL) |
1960 | goto out; | 1960 | goto out; |
1961 | atomic_set(&m->nref, 1); | 1961 | kref_init(&m->kref); |
1962 | INIT_LIST_HEAD(&m->list_head); | 1962 | INIT_LIST_HEAD(&m->list_head); |
1963 | 1963 | ||
1964 | m->hdr.type = cpu_to_le16(type); | 1964 | m->hdr.type = cpu_to_le16(type); |
@@ -2070,34 +2070,23 @@ void ceph_msg_kfree(struct ceph_msg *m) | |||
2070 | /* | 2070 | /* |
2071 | * Drop a msg ref. Destroy as needed. | 2071 | * Drop a msg ref. Destroy as needed. |
2072 | */ | 2072 | */ |
2073 | void ceph_msg_put(struct ceph_msg *m) | 2073 | void ceph_msg_last_put(struct kref *kref) |
2074 | { | 2074 | { |
2075 | dout("ceph_msg_put %p %d -> %d\n", m, atomic_read(&m->nref), | 2075 | struct ceph_msg *m = container_of(kref, struct ceph_msg, kref); |
2076 | atomic_read(&m->nref)-1); | ||
2077 | if (atomic_read(&m->nref) <= 0) { | ||
2078 | pr_err("bad ceph_msg_put on %p %llu %d=%s %d+%d\n", | ||
2079 | m, le64_to_cpu(m->hdr.seq), | ||
2080 | le16_to_cpu(m->hdr.type), | ||
2081 | ceph_msg_type_name(le16_to_cpu(m->hdr.type)), | ||
2082 | le32_to_cpu(m->hdr.front_len), | ||
2083 | le32_to_cpu(m->hdr.data_len)); | ||
2084 | WARN_ON(1); | ||
2085 | } | ||
2086 | if (atomic_dec_and_test(&m->nref)) { | ||
2087 | dout("ceph_msg_put last one on %p\n", m); | ||
2088 | WARN_ON(!list_empty(&m->list_head)); | ||
2089 | |||
2090 | /* drop middle, data, if any */ | ||
2091 | if (m->middle) { | ||
2092 | ceph_buffer_put(m->middle); | ||
2093 | m->middle = NULL; | ||
2094 | } | ||
2095 | m->nr_pages = 0; | ||
2096 | m->pages = NULL; | ||
2097 | 2076 | ||
2098 | if (m->pool) | 2077 | dout("ceph_msg_put last one on %p\n", m); |
2099 | ceph_msgpool_put(m->pool, m); | 2078 | WARN_ON(!list_empty(&m->list_head)); |
2100 | else | 2079 | |
2101 | ceph_msg_kfree(m); | 2080 | /* drop middle, data, if any */ |
2081 | if (m->middle) { | ||
2082 | ceph_buffer_put(m->middle); | ||
2083 | m->middle = NULL; | ||
2102 | } | 2084 | } |
2085 | m->nr_pages = 0; | ||
2086 | m->pages = NULL; | ||
2087 | |||
2088 | if (m->pool) | ||
2089 | ceph_msgpool_put(m->pool, m); | ||
2090 | else | ||
2091 | ceph_msg_kfree(m); | ||
2103 | } | 2092 | } |
diff --git a/fs/ceph/messenger.h b/fs/ceph/messenger.h index f9c9f6487302..981b7c08ad82 100644 --- a/fs/ceph/messenger.h +++ b/fs/ceph/messenger.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __FS_CEPH_MESSENGER_H | 1 | #ifndef __FS_CEPH_MESSENGER_H |
2 | #define __FS_CEPH_MESSENGER_H | 2 | #define __FS_CEPH_MESSENGER_H |
3 | 3 | ||
4 | #include <linux/kref.h> | ||
4 | #include <linux/mutex.h> | 5 | #include <linux/mutex.h> |
5 | #include <linux/net.h> | 6 | #include <linux/net.h> |
6 | #include <linux/radix-tree.h> | 7 | #include <linux/radix-tree.h> |
@@ -85,7 +86,7 @@ struct ceph_msg { | |||
85 | struct page **pages; /* data payload. NOT OWNER. */ | 86 | struct page **pages; /* data payload. NOT OWNER. */ |
86 | unsigned nr_pages; /* size of page array */ | 87 | unsigned nr_pages; /* size of page array */ |
87 | struct list_head list_head; | 88 | struct list_head list_head; |
88 | atomic_t nref; | 89 | struct kref kref; |
89 | bool front_is_vmalloc; | 90 | bool front_is_vmalloc; |
90 | bool more_to_follow; | 91 | bool more_to_follow; |
91 | int front_max; | 92 | int front_max; |
@@ -243,11 +244,13 @@ extern int ceph_alloc_middle(struct ceph_connection *con, struct ceph_msg *msg); | |||
243 | 244 | ||
244 | static inline struct ceph_msg *ceph_msg_get(struct ceph_msg *msg) | 245 | static inline struct ceph_msg *ceph_msg_get(struct ceph_msg *msg) |
245 | { | 246 | { |
246 | dout("ceph_msg_get %p %d -> %d\n", msg, atomic_read(&msg->nref), | 247 | kref_get(&msg->kref); |
247 | atomic_read(&msg->nref)+1); | ||
248 | atomic_inc(&msg->nref); | ||
249 | return msg; | 248 | return msg; |
250 | } | 249 | } |
251 | extern void ceph_msg_put(struct ceph_msg *msg); | 250 | extern void ceph_msg_last_put(struct kref *kref); |
251 | static inline void ceph_msg_put(struct ceph_msg *msg) | ||
252 | { | ||
253 | kref_put(&msg->kref, ceph_msg_last_put); | ||
254 | } | ||
252 | 255 | ||
253 | #endif | 256 | #endif |
diff --git a/fs/ceph/msgpool.c b/fs/ceph/msgpool.c index 7599b3382076..ad5482c0267b 100644 --- a/fs/ceph/msgpool.c +++ b/fs/ceph/msgpool.c | |||
@@ -165,7 +165,7 @@ void ceph_msgpool_put(struct ceph_msgpool *pool, struct ceph_msg *msg) | |||
165 | { | 165 | { |
166 | spin_lock(&pool->lock); | 166 | spin_lock(&pool->lock); |
167 | if (pool->num < pool->min) { | 167 | if (pool->num < pool->min) { |
168 | ceph_msg_get(msg); /* retake a single ref */ | 168 | kref_set(&msg->kref, 1); /* retake a single ref */ |
169 | list_add(&msg->list_head, &pool->msgs); | 169 | list_add(&msg->list_head, &pool->msgs); |
170 | pool->num++; | 170 | pool->num++; |
171 | dout("msgpool_put %p reclaim %p, now %d/%d\n", pool, msg, | 171 | dout("msgpool_put %p reclaim %p, now %d/%d\n", pool, msg, |