From patchwork Sun Feb 3 01:20:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 2085651 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3A7E13FD2B for ; Sun, 3 Feb 2013 01:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753772Ab3BCBWR (ORCPT ); Sat, 2 Feb 2013 20:22:17 -0500 Received: from mail-pb0-f44.google.com ([209.85.160.44]:63978 "EHLO mail-pb0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753633Ab3BCBWL (ORCPT ); Sat, 2 Feb 2013 20:22:11 -0500 Received: by mail-pb0-f44.google.com with SMTP id wz12so2666068pbc.31 for ; Sat, 02 Feb 2013 17:22:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=i2qu1x+VCRda+epzIxcks5FJ5TU+DmHRiCt+n3zXtCg=; b=Pgu4y/Zr4aMaNRqL0FVOeg4DD+dWxzX1gr2+m9DP5KxXADFk4/tvYK/s2s3Q8eEf6L Z8sfiTJdkeX/J25MCA+/XOQlSUJZ+VK/M5Xc9UC5oNk770sDXXRQy7QUacb2CEJ6SzP9 fJZSIxVFrnk6UmTZhwsdp9C37IRy9KQxn1vzpBhBBiH4Zuic464v/faqzLIbgia9zFo3 xwPqeNO7uvjHknl8PJFp5QbSvlhKZYkIBaPihMAv2YcKBwbEPHOU5LNQyfvNDqUQZn72 ZqW4NUQZqKffxpuA6qkeGydIJOLn6q0T7+W22t3ifPneYt5WuUF8UvKqK8nVC+ppEr+Q PSnA== X-Received: by 10.66.75.66 with SMTP id a2mr41149096paw.65.1359854531403; Sat, 02 Feb 2013 17:22:11 -0800 (PST) Received: from htj.dyndns.org (c-69-181-251-227.hsd1.ca.comcast.net. [69.181.251.227]) by mx.google.com with ESMTPS id hs2sm13149467pbc.22.2013.02.02.17.22.09 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 02 Feb 2013 17:22:10 -0800 (PST) From: Tejun Heo To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, rusty@rustcorp.com.au, bfields@fieldses.org, skinsbursky@parallels.com, ebiederm@xmission.com, jmorris@namei.org, axboe@kernel.dk, Tejun Heo , Jack Morgenstein , Or Gerlitz , Roland Dreier , linux-rdma@vger.kernel.org Subject: [PATCH 28/62] infiniband/mlx4: convert to idr_alloc() Date: Sat, 2 Feb 2013 17:20:29 -0800 Message-Id: <1359854463-2538-29-git-send-email-tj@kernel.org> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1359854463-2538-1-git-send-email-tj@kernel.org> References: <1359854463-2538-1-git-send-email-tj@kernel.org> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Convert to the much saner new idr interface. Only compile tested. Signed-off-by: Tejun Heo Cc: Jack Morgenstein Cc: Or Gerlitz Cc: Roland Dreier Cc: linux-rdma@vger.kernel.org --- This patch depends on an earlier idr changes and I think it would be best to route these together through -mm. Please holler if there's any objection. Thanks. drivers/infiniband/hw/mlx4/cm.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/cm.c b/drivers/infiniband/hw/mlx4/cm.c index dbc99d4..80e59ed 100644 --- a/drivers/infiniband/hw/mlx4/cm.c +++ b/drivers/infiniband/hw/mlx4/cm.c @@ -203,7 +203,7 @@ static void sl_id_map_add(struct ib_device *ibdev, struct id_map_entry *new) static struct id_map_entry * id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id) { - int ret, id; + int ret; static int next_id; struct id_map_entry *ent; struct mlx4_ib_sriov *sriov = &to_mdev(ibdev)->sriov; @@ -220,25 +220,23 @@ id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id) ent->dev = to_mdev(ibdev); INIT_DELAYED_WORK(&ent->timeout, id_map_ent_timeout); - do { - spin_lock(&to_mdev(ibdev)->sriov.id_map_lock); - ret = idr_get_new_above(&sriov->pv_id_table, ent, - next_id, &id); - if (!ret) { - next_id = ((unsigned) id + 1) & MAX_IDR_MASK; - ent->pv_cm_id = (u32)id; - sl_id_map_add(ibdev, ent); - } + idr_preload(GFP_KERNEL); + spin_lock(&to_mdev(ibdev)->sriov.id_map_lock); - spin_unlock(&sriov->id_map_lock); - } while (ret == -EAGAIN && idr_pre_get(&sriov->pv_id_table, GFP_KERNEL)); - /*the function idr_get_new_above can return -ENOSPC, so don't insert in that case.*/ - if (!ret) { - spin_lock(&sriov->id_map_lock); + ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT); + if (ret >= 0) { + next_id = ((unsigned)ret + 1) & MAX_IDR_MASK; + ent->pv_cm_id = (u32)ret; + sl_id_map_add(ibdev, ent); list_add_tail(&ent->list, &sriov->cm_list); - spin_unlock(&sriov->id_map_lock); - return ent; } + + spin_unlock(&sriov->id_map_lock); + idr_preload_end(); + + if (ret >= 0) + return ent; + /*error flow*/ kfree(ent); mlx4_ib_warn(ibdev, "No more space in the idr (err:0x%x)\n", ret);