linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / infiniband / core / uverbs_main.c
index 4e16314..903f85a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2005 Topspin Communications.  All rights reserved.
- * Copyright (c) 2005, 2006 Cisco Systems.  All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2005 PathScale, Inc. All rights reserved.
@@ -66,7 +66,7 @@ enum {
 
 static struct class *uverbs_class;
 
-DEFINE_SPINLOCK(ib_uverbs_idr_lock);
+DEFINE_MUTEX(ib_uverbs_idr_mutex);
 DEFINE_IDR(ib_uverbs_pd_idr);
 DEFINE_IDR(ib_uverbs_mr_idr);
 DEFINE_IDR(ib_uverbs_mw_idr);
@@ -91,12 +91,10 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
        [IB_USER_VERBS_CMD_DEREG_MR]            = ib_uverbs_dereg_mr,
        [IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL] = ib_uverbs_create_comp_channel,
        [IB_USER_VERBS_CMD_CREATE_CQ]           = ib_uverbs_create_cq,
-       [IB_USER_VERBS_CMD_RESIZE_CQ]           = ib_uverbs_resize_cq,
        [IB_USER_VERBS_CMD_POLL_CQ]             = ib_uverbs_poll_cq,
        [IB_USER_VERBS_CMD_REQ_NOTIFY_CQ]       = ib_uverbs_req_notify_cq,
        [IB_USER_VERBS_CMD_DESTROY_CQ]          = ib_uverbs_destroy_cq,
        [IB_USER_VERBS_CMD_CREATE_QP]           = ib_uverbs_create_qp,
-       [IB_USER_VERBS_CMD_QUERY_QP]            = ib_uverbs_query_qp,
        [IB_USER_VERBS_CMD_MODIFY_QP]           = ib_uverbs_modify_qp,
        [IB_USER_VERBS_CMD_DESTROY_QP]          = ib_uverbs_destroy_qp,
        [IB_USER_VERBS_CMD_POST_SEND]           = ib_uverbs_post_send,
@@ -108,7 +106,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
        [IB_USER_VERBS_CMD_DETACH_MCAST]        = ib_uverbs_detach_mcast,
        [IB_USER_VERBS_CMD_CREATE_SRQ]          = ib_uverbs_create_srq,
        [IB_USER_VERBS_CMD_MODIFY_SRQ]          = ib_uverbs_modify_srq,
-       [IB_USER_VERBS_CMD_QUERY_SRQ]           = ib_uverbs_query_srq,
        [IB_USER_VERBS_CMD_DESTROY_SRQ]         = ib_uverbs_destroy_srq,
 };
 
@@ -122,7 +119,7 @@ static void ib_uverbs_release_dev(struct kref *ref)
        struct ib_uverbs_device *dev =
                container_of(ref, struct ib_uverbs_device, ref);
 
-       complete(&dev->comp);
+       kfree(dev);
 }
 
 void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
@@ -183,45 +180,47 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
        if (!context)
                return 0;
 
-       list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
-               struct ib_ah *ah = uobj->object;
+       mutex_lock(&ib_uverbs_idr_mutex);
 
-               idr_remove_uobj(&ib_uverbs_ah_idr, uobj);
+       list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
+               struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id);
+               idr_remove(&ib_uverbs_ah_idr, uobj->id);
                ib_destroy_ah(ah);
+               list_del(&uobj->list);
                kfree(uobj);
        }
 
        list_for_each_entry_safe(uobj, tmp, &context->qp_list, list) {
-               struct ib_qp *qp = uobj->object;
+               struct ib_qp *qp = idr_find(&ib_uverbs_qp_idr, uobj->id);
                struct ib_uqp_object *uqp =
                        container_of(uobj, struct ib_uqp_object, uevent.uobject);
-
-               idr_remove_uobj(&ib_uverbs_qp_idr, uobj);
+               idr_remove(&ib_uverbs_qp_idr, uobj->id);
                ib_uverbs_detach_umcast(qp, uqp);
                ib_destroy_qp(qp);
+               list_del(&uobj->list);
                ib_uverbs_release_uevent(file, &uqp->uevent);
                kfree(uqp);
        }
 
        list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) {
-               struct ib_cq *cq = uobj->object;
+               struct ib_cq *cq = idr_find(&ib_uverbs_cq_idr, uobj->id);
                struct ib_uverbs_event_file *ev_file = cq->cq_context;
                struct ib_ucq_object *ucq =
                        container_of(uobj, struct ib_ucq_object, uobject);
-
-               idr_remove_uobj(&ib_uverbs_cq_idr, uobj);
+               idr_remove(&ib_uverbs_cq_idr, uobj->id);
                ib_destroy_cq(cq);
+               list_del(&uobj->list);
                ib_uverbs_release_ucq(file, ev_file, ucq);
                kfree(ucq);
        }
 
        list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) {
-               struct ib_srq *srq = uobj->object;
+               struct ib_srq *srq = idr_find(&ib_uverbs_srq_idr, uobj->id);
                struct ib_uevent_object *uevent =
                        container_of(uobj, struct ib_uevent_object, uobject);
-
-               idr_remove_uobj(&ib_uverbs_srq_idr, uobj);
+               idr_remove(&ib_uverbs_srq_idr, uobj->id);
                ib_destroy_srq(srq);
+               list_del(&uobj->list);
                ib_uverbs_release_uevent(file, uevent);
                kfree(uevent);
        }
@@ -229,27 +228,30 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
        /* XXX Free MWs */
 
        list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {
-               struct ib_mr *mr = uobj->object;
+               struct ib_mr *mr = idr_find(&ib_uverbs_mr_idr, uobj->id);
                struct ib_device *mrdev = mr->device;
                struct ib_umem_object *memobj;
 
-               idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
+               idr_remove(&ib_uverbs_mr_idr, uobj->id);
                ib_dereg_mr(mr);
 
                memobj = container_of(uobj, struct ib_umem_object, uobject);
                ib_umem_release_on_close(mrdev, &memobj->umem);
 
+               list_del(&uobj->list);
                kfree(memobj);
        }
 
        list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) {
-               struct ib_pd *pd = uobj->object;
-
-               idr_remove_uobj(&ib_uverbs_pd_idr, uobj);
+               struct ib_pd *pd = idr_find(&ib_uverbs_pd_idr, uobj->id);
+               idr_remove(&ib_uverbs_pd_idr, uobj->id);
                ib_dealloc_pd(pd);
+               list_del(&uobj->list);
                kfree(uobj);
        }
 
+       mutex_unlock(&ib_uverbs_idr_mutex);
+
        return context->device->dealloc_ucontext(context);
 }
 
@@ -459,6 +461,7 @@ void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr)
        ib_uverbs_async_handler(uobj->uverbs_file, uobj->uobject.user_handle,
                                event->event, &uobj->async_list,
                                &uobj->async_events_reported);
+                               
 }
 
 void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr)
@@ -740,7 +743,6 @@ static void ib_uverbs_add_one(struct ib_device *device)
                return;
 
        kref_init(&uverbs_dev->ref);
-       init_completion(&uverbs_dev->comp);
 
        spin_lock(&map_lock);
        uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
@@ -794,8 +796,6 @@ err_cdev:
 
 err:
        kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
-       wait_for_completion(&uverbs_dev->comp);
-       kfree(uverbs_dev);
        return;
 }
 
@@ -815,18 +815,14 @@ static void ib_uverbs_remove_one(struct ib_device *device)
        spin_unlock(&map_lock);
 
        clear_bit(uverbs_dev->devnum, dev_map);
-
        kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
-       wait_for_completion(&uverbs_dev->comp);
-       kfree(uverbs_dev);
 }
 
-static int uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
-                              const char *dev_name, void *data,
-                              struct vfsmount *mnt)
+static struct super_block *uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
+                                              const char *dev_name, void *data)
 {
        return get_sb_pseudo(fs_type, "infinibandevent:", NULL,
-                            INFINIBANDEVENTFS_MAGIC, mnt);
+                            INFINIBANDEVENTFS_MAGIC);
 }
 
 static struct file_system_type uverbs_event_fs = {