ceph: use kref for ceph_osd_request
authorSage Weil <sage@newdream.net>
Mon, 7 Dec 2009 21:37:03 +0000 (13:37 -0800)
committerSage Weil <sage@newdream.net>
Mon, 7 Dec 2009 21:37:03 +0000 (13:37 -0800)
Signed-off-by: Sage Weil <sage@newdream.net>
fs/ceph/osd_client.c
fs/ceph/osd_client.h

index d639c74e749f399d00d63f0fb440dabcba51bd55..67ef8ab06af4cf459385c30d7d412561787e765e 100644 (file)
@@ -77,25 +77,24 @@ static void calc_layout(struct ceph_osd_client *osdc,
 /*
  * requests
  */
-void ceph_osdc_put_request(struct ceph_osd_request *req)
+void ceph_osdc_release_request(struct kref *kref)
 {
-       dout("osdc put_request %p %d -> %d\n", req, atomic_read(&req->r_ref),
-            atomic_read(&req->r_ref)-1);
-       BUG_ON(atomic_read(&req->r_ref) <= 0);
-       if (atomic_dec_and_test(&req->r_ref)) {
-               if (req->r_request)
-                       ceph_msg_put(req->r_request);
-               if (req->r_reply)
-                       ceph_msg_put(req->r_reply);
-               if (req->r_own_pages)
-                       ceph_release_page_vector(req->r_pages,
-                                                req->r_num_pages);
-               ceph_put_snap_context(req->r_snapc);
-               if (req->r_mempool)
-                       mempool_free(req, req->r_osdc->req_mempool);
-               else
-                       kfree(req);
-       }
+       struct ceph_osd_request *req = container_of(kref,
+                                                   struct ceph_osd_request,
+                                                   r_kref);
+
+       if (req->r_request)
+               ceph_msg_put(req->r_request);
+       if (req->r_reply)
+               ceph_msg_put(req->r_reply);
+       if (req->r_own_pages)
+               ceph_release_page_vector(req->r_pages,
+                                        req->r_num_pages);
+       ceph_put_snap_context(req->r_snapc);
+       if (req->r_mempool)
+               mempool_free(req, req->r_osdc->req_mempool);
+       else
+               kfree(req);
 }
 
 /*
@@ -149,7 +148,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
 
        req->r_osdc = osdc;
        req->r_mempool = use_mempool;
-       atomic_set(&req->r_ref, 1);
+       kref_init(&req->r_kref);
        init_completion(&req->r_completion);
        init_completion(&req->r_safe_completion);
        INIT_LIST_HEAD(&req->r_unsafe_item);
index 3d4ae6595aaaa10764d021dd6f831d4daea24858..20ee61847416e830288759d3e22098726eaab881 100644 (file)
@@ -2,6 +2,7 @@
 #define _FS_CEPH_OSD_CLIENT_H
 
 #include <linux/completion.h>
+#include <linux/kref.h>
 #include <linux/mempool.h>
 #include <linux/rbtree.h>
 
@@ -49,7 +50,7 @@ struct ceph_osd_request {
        int r_prepared_pages, r_got_reply;
 
        struct ceph_osd_client *r_osdc;
-       atomic_t          r_ref;
+       struct kref       r_kref;
        bool              r_mempool;
        struct completion r_completion, r_safe_completion;
        ceph_osdc_callback_t r_callback, r_safe_callback;
@@ -118,9 +119,13 @@ extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
 
 static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
 {
-       atomic_inc(&req->r_ref);
+       kref_get(&req->r_kref);
+}
+extern void ceph_osdc_release_request(struct kref *kref);
+static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
+{
+       kref_put(&req->r_kref, ceph_osdc_release_request);
 }
-extern void ceph_osdc_put_request(struct ceph_osd_request *req);
 
 extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
                                   struct ceph_osd_request *req,
This page took 0.029754 seconds and 5 git commands to generate.