From patchwork Thu Sep 20 11:22:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 10607473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60D72112B for ; Thu, 20 Sep 2018 11:22:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5118F2D0ED for ; Thu, 20 Sep 2018 11:22:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 456552D1A3; Thu, 20 Sep 2018 11:22:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8EEF2D0ED for ; Thu, 20 Sep 2018 11:22:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730984AbeITRFR (ORCPT ); Thu, 20 Sep 2018 13:05:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:58642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732502AbeITRFR (ORCPT ); Thu, 20 Sep 2018 13:05:17 -0400 Received: from localhost (unknown [193.47.165.251]) (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 82A2F21532; Thu, 20 Sep 2018 11:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1537442537; bh=uWZW+YFWOwFQ2MMduhcNN60ox+U3xhFGXEaReiEPWTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQHsVbwGguxw13aONjS87crOzeaH9WWClzrkciRPi8OyVr7jPKrP8o5T/7Ab6gw3g OvfsUhah5Oixq8Kw/xDv6Li228gTH42wCt9EK1mvKrVQXmD879CTf2ajGcApFysVcp gJ3wAtlnf7/BWaABzgciCMdUhH0rXi/QNEzMAHGw= From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: Leon Romanovsky , RDMA mailing list , linux-s390@vger.kernel.org, Ursula Braun , "David S. Miller" , netdev@vger.kernel.org, Selvin Xavier , Steve Wise , Lijun Ou , Shiraz Saleem , Ariel Elior , Christian Benvenuti , Adit Ranadive , Dennis Dalessandro Subject: [PATCH rdma-next 4/5] RDMA/core: Implement IB device rename function Date: Thu, 20 Sep 2018 14:22:01 +0300 Message-Id: <20180920112202.9181-5-leon@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920112202.9181-1-leon@kernel.org> References: <20180920112202.9181-1-leon@kernel.org> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Leon Romanovsky Generic implementation of IB device rename function. Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/core_priv.h | 1 + drivers/infiniband/core/device.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) -- 2.14.4 diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index d7399d5b1cb6..c5881756b799 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -87,6 +87,7 @@ int ib_device_register_sysfs(struct ib_device *device, int (*port_callback)(struct ib_device *, u8, struct kobject *)); void ib_device_unregister_sysfs(struct ib_device *device); +int ib_device_rename(struct ib_device *ibdev, const char *name); typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port, struct net_device *idev, void *cookie); diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index a9bc2a3f490c..36b79cd6b620 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -178,6 +178,29 @@ void ib_device_get_name(struct ib_device *ibdev, char *name) } EXPORT_SYMBOL(ib_device_get_name); +int ib_device_rename(struct ib_device *ibdev, const char *name) +{ + struct ib_device *device; + int ret = 0; + + if (!strcmp(name, ibdev->name)) + return ret; + + mutex_lock(&device_mutex); + list_for_each_entry(device, &device_list, core_list) { + if (!strcmp(name, device->name)) { + ret = -EEXIST; + goto out; + } + } + + strlcpy(ibdev->name, name, IB_DEVICE_NAME_MAX); + ret = device_rename(&ibdev->dev, name); +out: + mutex_unlock(&device_mutex); + return ret; +} + static int alloc_name(char *name) { unsigned long *inuse;