From patchwork Tue Feb 7 14:08:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maurizio Lombardi X-Patchwork-Id: 9560189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51FE36047A for ; Tue, 7 Feb 2017 14:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43CE92835B for ; Tue, 7 Feb 2017 14:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3901B283E7; Tue, 7 Feb 2017 14:08:54 +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=-6.9 required=2.0 tests=BAYES_00,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 A0E452835B for ; Tue, 7 Feb 2017 14:08:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754252AbdBGOIw (ORCPT ); Tue, 7 Feb 2017 09:08:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754199AbdBGOIu (ORCPT ); Tue, 7 Feb 2017 09:08:50 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A10786647; Tue, 7 Feb 2017 14:08:51 +0000 (UTC) Received: from manaslu.brq.redhat.com (dhcp-27-157.brq.redhat.com [10.34.27.157]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v17E8nua021690; Tue, 7 Feb 2017 09:08:50 -0500 From: Maurizio Lombardi To: jejb@linux.vnet.ibm.com Cc: linux-scsi@vger.kernel.org Subject: [PATCH RFC] enclosure: fix sysfs symlinks creation when using multipath Date: Tue, 7 Feb 2017 15:08:48 +0100 Message-Id: <1486476528-27580-2-git-send-email-mlombard@redhat.com> In-Reply-To: <1486476528-27580-1-git-send-email-mlombard@redhat.com> References: <1486476528-27580-1-git-send-email-mlombard@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 07 Feb 2017 14:08:51 +0000 (UTC) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With multipath, it may happen that the same device is passed to enclosure_add_device() multiple times and that the enclosure_add_links() function fails to create the symlinks because the device's sysfs directory entry is still NULL. In this case, the links will never be created because all the subsequent calls to enclosure_add_device() will immediately fail with EEXIST. This patch modifies the code so the driver will detect this condition and will retry to create the symlinks when enclosure_add_device() is called. Signed-off-by: Maurizio Lombardi Tested-by: Douglas Miller --- drivers/misc/enclosure.c | 16 ++++++++++++++-- include/linux/enclosure.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c index 65fed71..a856c98 100644 --- a/drivers/misc/enclosure.c +++ b/drivers/misc/enclosure.c @@ -375,21 +375,33 @@ int enclosure_add_device(struct enclosure_device *edev, int component, struct device *dev) { struct enclosure_component *cdev; + int error; if (!edev || component >= edev->components) return -EINVAL; cdev = &edev->component[component]; - if (cdev->dev == dev) + if (cdev->dev == dev) { + if (!cdev->links_created) { + error = enclosure_add_links(cdev); + if (!error) + cdev->links_created = 1; + } return -EEXIST; + } if (cdev->dev) enclosure_remove_links(cdev); put_device(cdev->dev); cdev->dev = get_device(dev); - return enclosure_add_links(cdev); + error = enclosure_add_links(cdev); + if (!error) + cdev->links_created = 1; + else + cdev->links_created = 0; + return error; } EXPORT_SYMBOL_GPL(enclosure_add_device); diff --git a/include/linux/enclosure.h b/include/linux/enclosure.h index a4cf57c..c3bdc4c 100644 --- a/include/linux/enclosure.h +++ b/include/linux/enclosure.h @@ -97,6 +97,7 @@ struct enclosure_component { struct device cdev; struct device *dev; enum enclosure_component_type type; + int links_created; int number; int fault; int active;