From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.25 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794170894; b=nyqzknzrgpW5yA2dpMayYvB03F79EcMEJDZiEV2Q5HXY91HdGSC7VqPB5fLsLx23LsyP fguIbiRblfIKJTDOLiEen3PeNkUhsxytieIj8hxfcXLoaExwYtQvdbj16AHpRnMMm4yeT uhkcmMZgP8F8pH/fn+Ti63hCuK0z2tRP3KuaG6ocJcvcYIisa4x5W4Z2kbjAnDA041nIf taYVwRti0j8XMnsR3o+zpoLQR9TGbRBCcFDOy8PCuyFEWSRsjvl+LgAPuNEQ71U0qWsIO jyNP6Ry6hBDHW2LmxiyodOzxWwA2yinQ93eZ1Jk9KZ0Ii9R9EhBteZ7rk974Y4m/s3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794170894; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=3brYAxqIKs7hzrh5Z8CcY1cxO1lYTUq1vxhAu2CJUaQ=; b=C26lF5HKYfS1+sy2LaU+OKrmLCJR5roHwRHh+2PU+VLQKn+3SkR9UwcOchhq7hIoI7zw cDLximIwbfLRg3vp6j2+AJm4mNWu/DppH46ggiZb2Rui9U9brBHD5PHdJQPA49DIlINXP 6VducOgfpfbW9YQvduC8k4H+GZ/vWYaNmJEbqYjmV1uJtKDS6Vx52mgwFjpTRHr7X2uWZ JDNLGp4XQMWbLt1DjfHPRP5k33iP71xKs4GoGupvHlNw24AaZQfKEoSPLmUErek0KqwBi TM10+DFQPtK+W8wdwioJeB5jZdkbKnRJTyuiaie6LqYBn3iouUnwT1BDi+fIYkMnb9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=bdtTPFtm; arc=none smtp.remote-ip=91.218.175.25 Received: from mta0.migadu.com (out-25.mta0.migadu.com [91.218.175.25]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AA46606A33A for ; Sun, 8 Nov 2026 20:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3AA46606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=bdtTPFtm X-Envelope-To: linux-scsi@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=+gVCO9skWtYMC8Y5tChRIvZEelk+iMaAj3nXdgDCfX0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794170892; v=1; x=1794775692; b=bdtTPFtmaQBoQc1uVTZP3uF4O1iJWkqOMSHqib07z0doZwSzLtHQD/fD8ikYAAmQjJt4w8io isuNHqUxyxsT8IVadOmZTNDidMTSC0+s9fbIlr5v6AulbgvVzNXQGbxHpLguIqLeGDE4SJRhIRG xrh/nT7UWSZ/3++8RJ/sba7s= X-Envelope-To: linux-scsi@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id fa92a12345c98661; Sun, 08 Nov 2026 20:48:12 +0000 X-Mizu-Trace-ID: fa92a12345c98661 X-Migadu-Flow: FLOW_OUT From: John Garry To: james.bottomley@hansenpartnership.com, mkp@kernel.org Cc: hare@suse.com, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, snitzer@kernel.org, jmeneghi@redhat.com, bmarzins@redhat.com, dm-devel@lists.linux.dev, hch@lst.de, michael.christie@oracle.com, John Garry , Hannes Reinecke Subject: [PATCH v9 14/29] scsi-multipath: provide sysfs link from to scsi_device Date: Sun, 8 Nov 2026 20:47:18 +0000 Message-ID: <20261108204733.557995-15-john.garry@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261108204733.557995-1-john.garry@linux.dev> References: <20261108204733.557995-1-john.garry@linux.dev> X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Provide a link in sysfs from a scsi_mpath_device to member scsi_device's. An example is as follows: # ls -l /sys/class/scsi_mpath_device/scsi_mpath_device0/multipath/ total 0 lrwxrwxrwx 1 root root 0 Feb 24 12:01 8:0:0:0 -> ../../../../platform/host8/session1/target8:0:0/8:0:0:0 lrwxrwxrwx 1 root root 0 Feb 24 12:01 9:0:0:0 -> ../../../../platform/host9/session2/target9:0:0/9:0:0:0 Reviewed-by: Hannes Reinecke Signed-off-by: John Garry --- drivers/scsi/scsi_multipath.c | 43 +++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_sysfs.c | 5 ++++ include/scsi/scsi_multipath.h | 8 +++++++ 3 files changed, 56 insertions(+) diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c index 625a72cb73c3..092975e0aca1 100644 --- a/drivers/scsi/scsi_multipath.c +++ b/drivers/scsi/scsi_multipath.c @@ -116,11 +116,54 @@ static bool scsi_multipath_sysfs_group_visible(struct kobject *kobj) } DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(scsi_multipath_sysfs) +static struct attribute dummy_attr = { + .name = "dummy", +}; + +static struct attribute *scsi_mpath_attrs[] = { + &dummy_attr, + NULL +}; + +static const struct attribute_group scsi_mpath_attr_group = { + .name = "multipath", + .attrs = scsi_mpath_attrs, + .is_visible = SYSFS_GROUP_VISIBLE(scsi_multipath_sysfs), +}; + static const struct attribute_group *scsi_mpath_device_groups[] = { &scsi_mpath_device_attrs_group, + &scsi_mpath_attr_group, NULL }; +void scsi_mpath_add_sysfs_link(struct scsi_device *sdev) +{ + struct device *target = &sdev->sdev_gendev; + struct scsi_mpath_head *scsi_mpath_head = + sdev->scsi_mpath_dev->scsi_mpath_head; + struct device *source = &scsi_mpath_head->dev; + int error; + + error = sysfs_add_link_to_group(&source->kobj, "multipath", + &target->kobj, dev_name(target)); + if (error) { + sdev_printk(KERN_INFO, sdev, "Failed to create mpath sysfs link, error=%d\n", + error); + } +} + +void scsi_mpath_remove_sysfs_link(struct scsi_device *sdev) +{ + struct device *target = &sdev->sdev_gendev; + struct scsi_mpath_head *scsi_mpath_head = + sdev->scsi_mpath_dev->scsi_mpath_head; + struct device *source = &scsi_mpath_head->dev; + + sysfs_remove_link_from_group(&source->kobj, "multipath", + dev_name(target)); +} + static const struct class scsi_mpath_device_class = { .name = "scsi_mpath_device", .dev_groups = scsi_mpath_device_groups, diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 5b5de5806385..b5d12b694396 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1444,6 +1444,9 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) transport_add_device(&sdev->sdev_gendev); sdev->is_visible = 1; + if (sdev->scsi_mpath_dev) + scsi_mpath_add_sysfs_link(sdev); + if (IS_ENABLED(CONFIG_BLK_DEV_BSG)) { sdev->bsg_dev = scsi_bsg_register_queue(sdev); if (IS_ERR(sdev->bsg_dev)) { @@ -1496,6 +1499,8 @@ void __scsi_remove_device(struct scsi_device *sdev) if (IS_ENABLED(CONFIG_BLK_DEV_BSG) && sdev->bsg_dev) bsg_unregister_queue(sdev->bsg_dev); + if (sdev->scsi_mpath_dev) + scsi_mpath_remove_sysfs_link(sdev); device_unregister(&sdev->sdev_dev); transport_remove_device(dev); device_del(dev); diff --git a/include/scsi/scsi_multipath.h b/include/scsi/scsi_multipath.h index 50d422798d83..d224a15ce9c2 100644 --- a/include/scsi/scsi_multipath.h +++ b/include/scsi/scsi_multipath.h @@ -49,6 +49,8 @@ void scsi_mpath_remove_device(struct scsi_mpath_device *scsi_mpath_dev); void scsi_mpath_get_head(struct scsi_mpath_head *scsi_mpath_head); int scsi_mpath_try_get_head(struct scsi_mpath_head *scsi_mpath_head); void scsi_mpath_put_head(struct scsi_mpath_head *scsi_mpath_head); +void scsi_mpath_add_sysfs_link(struct scsi_device *sdev); +void scsi_mpath_remove_sysfs_link(struct scsi_device *sdev); #else /* CONFIG_SCSI_MULTIPATH */ struct scsi_mpath_head { @@ -87,5 +89,11 @@ static inline void scsi_mpath_put_head(struct scsi_mpath_head *scsi_mpath_head) { } +static inline void scsi_mpath_add_sysfs_link(struct scsi_device *sdev) +{ +} +static inline void scsi_mpath_remove_sysfs_link(struct scsi_device *sdev) +{ +} #endif /* CONFIG_SCSI_MULTIPATH */ #endif /* _SCSI_SCSI_MULTIPATH_H */ -- 2.43.0