From patchwork Tue Jun 18 17:26:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 1118180 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="tPCjneSe"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45Sw446Nzbz9sDX for ; Wed, 19 Jun 2019 03:26:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729846AbfFRR0o (ORCPT ); Tue, 18 Jun 2019 13:26:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:53184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728572AbfFRR0n (ORCPT ); Tue, 18 Jun 2019 13:26:43 -0400 Received: from localhost (unknown [37.142.3.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E3495214AF; Tue, 18 Jun 2019 17:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560878802; bh=IPkvDpk3Zt1F7O3X+3vJA5Wr97gYSFVt8E1eoEhd1hE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tPCjneSeLoOxR/EYrzhwzGzYQRfHNnbh8MNPE90XROu/WslCRniJBY9xIQwU3/5r2 2hGeWmnQUQqPnQQixW6Avkg7gN/TZeZXkskFoJSyM5ohddr47umbNv/UbhmP+MZM0g naWlpfg3Sve/E/jfp1lh74/7vFAzYja8jdpZrZpE= From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: Leon Romanovsky , RDMA mailing list , Majd Dibbiny , Mark Zhang , Saeed Mahameed , linux-netdev Subject: [PATCH rdma-next v4 03/17] RDMA/restrack: Add an API to attach a task to a resource Date: Tue, 18 Jun 2019 20:26:11 +0300 Message-Id: <20190618172625.13432-4-leon@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190618172625.13432-1-leon@kernel.org> References: <20190618172625.13432-1-leon@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Mark Zhang Add rdma_restrack_attach_task() which is able to attach a task other then "current" to a resource. Signed-off-by: Mark Zhang Reviewed-by: Majd Dibbiny Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/restrack.c | 14 ++++++++++++++ drivers/infiniband/core/restrack.h | 2 ++ 2 files changed, 16 insertions(+) -- 2.20.1 diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c index 95573f292aae..3714634ae296 100644 --- a/drivers/infiniband/core/restrack.c +++ b/drivers/infiniband/core/restrack.c @@ -194,6 +194,20 @@ void rdma_restrack_set_task(struct rdma_restrack_entry *res, } EXPORT_SYMBOL(rdma_restrack_set_task); +/** + * rdma_restrack_attach_task() - attach the task onto this resource + * @res: resource entry + * @task: the task to attach, the current task will be used if it is NULL. + */ +void rdma_restrack_attach_task(struct rdma_restrack_entry *res, + struct task_struct *task) +{ + if (res->task) + put_task_struct(res->task); + get_task_struct(task); + res->task = task; +} + static void rdma_restrack_add(struct rdma_restrack_entry *res) { struct ib_device *dev = res_to_dev(res); diff --git a/drivers/infiniband/core/restrack.h b/drivers/infiniband/core/restrack.h index 09a1fbdf578e..d084e5f89849 100644 --- a/drivers/infiniband/core/restrack.h +++ b/drivers/infiniband/core/restrack.h @@ -25,4 +25,6 @@ struct rdma_restrack_root { int rdma_restrack_init(struct ib_device *dev); void rdma_restrack_clean(struct ib_device *dev); +void rdma_restrack_attach_task(struct rdma_restrack_entry *res, + struct task_struct *task); #endif /* _RDMA_CORE_RESTRACK_H_ */