From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D207373C02 for ; Tue, 3 Mar 2026 07:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772522013; cv=none; b=NYrjEgXLOlBeJJMdIkBwuFWIdkCj5pY8l3DbBbBWGtUDbJ4D/wLo4k4N48+dVEAyzjvxcvcJWaHxuCQJk4wh0KUArOPzaVXMpTgrI9pbMVTlStvNCJTV7Easez7fuVf6ozzSY1MhhDp8FcZlFvl+PlXEgu6vb1Vpa4j9BEG7k5o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772522013; c=relaxed/simple; bh=vXeb1YMngigtTKDZStvPTDAGb3cr/q40OIJPzfwTusI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FM7HCcO4gIevz4oRMZRFOgflEZ2yjGc52SxtsxsDWjayns8jtRRF+WtuDCLn7l4rbgArp4Q993x8OpNrAQgGLS81ebGGzia/nCxNjGc2n1ztNOEhaLPIQ+3msppQBx8X1KGVWamHgcizE8uUpS+sNfzJXBkvEya8oWTusrIQ63U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=WCvfR5B1; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="WCvfR5B1" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48374014a77so63236225e9.3 for ; Mon, 02 Mar 2026 23:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1772522009; x=1773126809; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+diqLHAbCu0YIrK7BmkSHmFnH/39tPbeAFxeHFPEiPU=; b=WCvfR5B1g/sqPVC9A5U4cw8GK5IiLeOUh3KQBm1X+bA0D+SsU63OtHnl77KXZz8Ft9 ry2/8r+5ABwzgT28sqHTp3iY9olKeTnVO74libat5Ml/uLcj+GXaSbqWQLoSGqy/JgBl a+Q8MIO7vdoFKczSeP1amMGeub8nLrTTSlcsKv866bs+fyGFOeDA9l+AYlF9lvySZX1k sl4ak9ejtvNqagXr79Jz7h4dR/nVkZ7nwKZbT1f0LaqIYk5uurZy6qn8+J+lFVpQDi9r tliLsdCyZ3oJYYVfguipVTheYqpbYKTpWnWJjKBR025Ossy2q8/a/LMoe+GFE5rRLsTA TblQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772522009; x=1773126809; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+diqLHAbCu0YIrK7BmkSHmFnH/39tPbeAFxeHFPEiPU=; b=IfHVDdSXxkKWc1+Cjw8c6L+eeZdbNHWEx3sf7ovuizbJ5/GQu1phHzf6EnswJ+9911 9dEskjjVUXNKXA9EVmYxcrMjaep98e9Kekn+X2SgTMneHoPx8Z+pgsgSbwYQrySNTZzL t9Z32vapxc4YmdqyzPxyKn+7P0M2gfj8WQHYXgzHucGcHaxmFQdjF29zf60wM4jKMNUd x6GtpZan6E0Wi2yDQmwDasrsvIhKLkCEe0L/5Py8a02jjHsRyH/C261bTVX0a4Jk1Ui5 0y+n90NECq5pbuDZ45qxeArUyBxsaWAmhgtdhh1FJpSHUcv+ictbI1PG8whkwkEgoW9f Q3/w== X-Forwarded-Encrypted: i=1; AJvYcCUYYPzIAogVxcNxpjPirrJFDCCvtNMXUozZk9rsgWSzHpQUfW3gU7SjKjTmRVNWFBm6zdv1lqfnUFmFAs0=@vger.kernel.org X-Gm-Message-State: AOJu0YyBKlLsloGc8l1bsKMDXnjoq51sWPa9Bz0Hv70wgB7sxXmB833g aPdK2Qq8YR6PwwF3ZYK/57Ccktj9iYABt9CYxDIhSjwadvO5kwp7dAbUZiGXXKluNcs= X-Gm-Gg: ATEYQzwPPGYdzw/unF+K2N0MFbvu2itCtaRfkjoYfIbdLFycfmpAdnnEV+dMRNiTQnw vkfxHe7ZDh4VrLE3YEMna54LWywzmOQ+I1i5QQr/A38+ZHX0HFkuNXQz7SRMNdt6/FMlkEznSzT /uBA2WouN9O//i6wfzLjXyzVONmfA/CzxwOH49QuwIq4lalt5DCp+g9U4IIGtld5Yfh1zWst2Lw cQ1+hC48/OrVektpgO2RtgP49hx0eA/bdoSS9GQHAsBIaXV8S2H5MWtiuMvPGh2z29P4VU82imd cuaN/6GESSAvxcSVm5urRr1YgO/q4yEbPhzyfJouaAPk7pLUqnmtuhfXRbHt+X+W4s8y41fmP9R vezFjDqeZYRduimwa/oR61cL9wTvUVuf/D/Q5xV9NpXuRhOCikP/Zf5qnV8A6MVC9aaLRt3WQDE 0kkR7fxLInO4fbzhJ+azP5M+y8An0B+Pi9OAMyhRLpTHsos8+rUgsdGeo86q732VIS9g== X-Received: by 2002:a05:600c:4592:b0:480:6999:27ec with SMTP id 5b1f17b1804b1-483c9bc03b1mr291390865e9.13.1772522009331; Mon, 02 Mar 2026 23:13:29 -0800 (PST) Received: from [192.168.178.47] (aftr-82-135-83-117.dynamic.mnet-online.de. [82.135.83.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48512628e2asm22510605e9.1.2026.03.02.23.13.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Mar 2026 23:13:28 -0800 (PST) Message-ID: <0809867c-796a-4bf1-a868-7ec64504723d@suse.com> Date: Tue, 3 Mar 2026 08:13:27 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 03/24] scsi-multipath: introduce scsi_device head structure To: John Garry , hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@fb.com, martin.petersen@oracle.com, james.bottomley@hansenpartnership.com Cc: jmeneghi@redhat.com, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, michael.christie@oracle.com, snitzer@kernel.org, bmarzins@redhat.com, dm-devel@lists.linux.dev, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260225153627.1032500-1-john.g.garry@oracle.com> <20260225153627.1032500-4-john.g.garry@oracle.com> Content-Language: en-US From: Hannes Reinecke In-Reply-To: <20260225153627.1032500-4-john.g.garry@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/25/26 16:36, John Garry wrote: > Introduce a scsi_device head structure - scsi_mpath_head - to manage > multipathing for a scsi_device. This is similar to nvme_ns_head structure. > > There is no reference in scsi_mpath_head to any disk, as this would be > mananged by the scsi_disk driver. > > A list of scsi_mpath_head structures is managed to lookup for matching > multipathed scsi_device's. Matching is done through the scsi_device > unique id. > > Signed-off-by: John Garry > --- > drivers/scsi/scsi_multipath.c | 147 ++++++++++++++++++++++++++++++++++ > drivers/scsi/scsi_sysfs.c | 3 + > include/scsi/scsi_multipath.h | 29 +++++++ > 3 files changed, 179 insertions(+) > > diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c > index 04e0bad3d9204..49316269fad8e 100644 > --- a/drivers/scsi/scsi_multipath.c > +++ b/drivers/scsi/scsi_multipath.c > @@ -16,6 +16,10 @@ > bool scsi_multipath; > static bool scsi_multipath_always; > > +static LIST_HEAD(scsi_mpath_heads_list); > +static DEFINE_MUTEX(scsi_mpath_heads_lock); > +static DEFINE_IDA(scsi_multipath_dev_ida); > + > static int multipath_param_set(const char *val, const struct kernel_param *kp) > { > int ret; > @@ -99,6 +103,73 @@ static int scsi_multipath_sdev_init(struct scsi_device *sdev) > return 0; > } > > +struct mpath_head_template smpdt_pr = { > +}; > + > +static struct scsi_mpath_head *scsi_mpath_alloc_head(void) > +{ > + struct scsi_mpath_head *scsi_mpath_head; > + int ret; > + > + scsi_mpath_head = kzalloc(sizeof(*scsi_mpath_head), GFP_KERNEL); > + if (!scsi_mpath_head) > + return NULL; > + > + ida_init(&scsi_mpath_head->ida); > + mutex_init(&scsi_mpath_head->lock); > + > + scsi_mpath_head->mpath_head = mpath_alloc_head(); > + if (IS_ERR(scsi_mpath_head->mpath_head)) > + goto out_free; > + scsi_mpath_head->mpath_head->mpdt = &smpdt_pr; mpdt? What's that supposed to mean? Seems to be like a persistent reservation thing, so why don't you introduce it together with PR suppoer? > + scsi_mpath_head->mpath_head->drvdata = scsi_mpath_head; > + > + scsi_mpath_head->index = ida_alloc(&scsi_multipath_dev_ida, GFP_KERNEL); > + if (scsi_mpath_head->index < 0) > + goto out_put_head; > + > + device_initialize(&scsi_mpath_head->dev); > + ret = dev_set_name(&scsi_mpath_head->dev, "%d", scsi_mpath_head->index); Huh? The name is just the number? So we will have a device /sys/devices/virtual/1 ? The sysfs registration looks decidedly odd. I guess we should add a scsi multipath class to sort the devices under. > + if (ret) { > + put_device(&scsi_mpath_head->dev); > + goto out_free_ida; > + } > + > + return scsi_mpath_head; > + > +out_free_ida: > + ida_free(&scsi_multipath_dev_ida, scsi_mpath_head->index); > +out_put_head: > + mpath_put_head(scsi_mpath_head->mpath_head); > +out_free: > + kfree(scsi_mpath_head); > + return NULL; > +} > + > +static struct scsi_mpath_head *scsi_mpath_find_head( > + struct scsi_mpath_device *scsi_mpath_dev) > +{ > + struct scsi_mpath_head *scsi_mpath_head; > + int ret; > + > + mutex_lock(&scsi_mpath_heads_lock); > + list_for_each_entry(scsi_mpath_head, &scsi_mpath_heads_list, entry) { > + ret = scsi_mpath_get_head(scsi_mpath_head); > + if (ret) > + continue; > + if (strncmp(scsi_mpath_head->wwid, > + scsi_mpath_dev->device_id_str, > + SCSI_MPATH_DEVICE_ID_LEN) == 0) { > + > + mutex_unlock(&scsi_mpath_heads_lock); > + return scsi_mpath_head; > + } > + scsi_mpath_put_head(scsi_mpath_head); > + } > + > + return NULL; > +} > + > static void scsi_multipath_sdev_uninit(struct scsi_device *sdev) > { > kfree(sdev->scsi_mpath_dev); > @@ -107,6 +178,7 @@ static void scsi_multipath_sdev_uninit(struct scsi_device *sdev) > > int scsi_mpath_dev_alloc(struct scsi_device *sdev) > { > + struct scsi_mpath_head *scsi_mpath_head; > int ret; > > if (!scsi_multipath) > @@ -127,13 +199,75 @@ int scsi_mpath_dev_alloc(struct scsi_device *sdev) > goto out_uninit; > } > > + scsi_mpath_head = scsi_mpath_find_head(sdev->scsi_mpath_dev); > + if (scsi_mpath_head) > + goto found; > + /* scsi_mpath_disks_list lock held */ > + scsi_mpath_head = scsi_mpath_alloc_head(); > + if (!scsi_mpath_head) > + goto out_uninit; > + > + strcpy(scsi_mpath_head->wwid, sdev->scsi_mpath_dev->device_id_str); > + Do we have a sysfs attribute for this? > + ret = device_add(&scsi_mpath_head->dev); > + if (ret) > + goto out_put_head; > + > + list_add_tail(&scsi_mpath_head->entry, &scsi_mpath_heads_list); > + > + mutex_unlock(&scsi_mpath_heads_lock); > + sdev->scsi_mpath_dev->scsi_mpath_head = scsi_mpath_head; > + > +found: > + sdev->scsi_mpath_dev->index = ida_alloc(&scsi_mpath_head->ida, GFP_KERNEL); > + if (sdev->scsi_mpath_dev->index < 0) { > + ret = sdev->scsi_mpath_dev->index; > + goto out_put_head; > + } > + > + mutex_lock(&scsi_mpath_head->lock); > + scsi_mpath_head->dev_count++; > + mutex_unlock(&scsi_mpath_head->lock); > + > + sdev->scsi_mpath_dev->scsi_mpath_head = scsi_mpath_head; > return 0; > > +out_put_head: > + scsi_mpath_put_head(scsi_mpath_head); > out_uninit: > + mutex_unlock(&scsi_mpath_heads_lock); > scsi_multipath_sdev_uninit(sdev); > return ret; > } > > +static void scsi_mpath_remove_head(struct scsi_mpath_device *scsi_mpath_dev) > +{ > + struct scsi_mpath_head *scsi_mpath_head = > + scsi_mpath_dev->scsi_mpath_head; > + bool last_path = false; > + > + mutex_lock(&scsi_mpath_head->lock); > + scsi_mpath_head->dev_count--; > + if (scsi_mpath_head->dev_count == 0) > + last_path = true; > + mutex_unlock(&scsi_mpath_head->lock); > + > + if (last_path) > + device_del(&scsi_mpath_head->dev); > + > + scsi_mpath_dev->scsi_mpath_head = NULL; > + scsi_mpath_put_head(scsi_mpath_head); > +} > + > +void scsi_mpath_remove_device(struct scsi_mpath_device *scsi_mpath_dev) > +{ > + struct scsi_mpath_head *scsi_mpath_head = scsi_mpath_dev->scsi_mpath_head; > + > + ida_free(&scsi_mpath_head->ida, scsi_mpath_dev->index); > + > + scsi_mpath_remove_head(scsi_mpath_dev); > +} > + > void scsi_mpath_dev_release(struct scsi_device *sdev) > { > struct scsi_mpath_device *scsi_mpath_dev = sdev->scsi_mpath_dev; > @@ -142,8 +276,21 @@ void scsi_mpath_dev_release(struct scsi_device *sdev) > return; > > scsi_multipath_sdev_uninit(sdev); > +} > + > +int scsi_mpath_get_head(struct scsi_mpath_head *scsi_mpath_head) > +{ > + if (!get_device(&scsi_mpath_head->dev)) > + return -ENXIO; > + return 0; > +} > +EXPORT_SYMBOL_GPL(scsi_mpath_get_head); > > +void scsi_mpath_put_head(struct scsi_mpath_head *scsi_mpath_head) > +{ > + put_device(&scsi_mpath_head->dev); > } > +EXPORT_SYMBOL_GPL(scsi_mpath_put_head); > > int __init scsi_multipath_init(void) > { > diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c > index 0d69e27600a7a..287a683e89ae5 100644 > --- a/drivers/scsi/scsi_sysfs.c > +++ b/drivers/scsi/scsi_sysfs.c > @@ -1447,6 +1447,9 @@ void __scsi_remove_device(struct scsi_device *sdev) > } else > put_device(&sdev->sdev_dev); > > + if (sdev->scsi_mpath_dev) > + scsi_mpath_remove_device(sdev->scsi_mpath_dev); > + > /* > * Stop accepting new requests and wait until all queuecommand() and > * scsi_run_queue() invocations have finished before tearing down the > diff --git a/include/scsi/scsi_multipath.h b/include/scsi/scsi_multipath.h > index ca00ea10cd5db..38953b05a44dc 100644 > --- a/include/scsi/scsi_multipath.h > +++ b/include/scsi/scsi_multipath.h > @@ -19,9 +19,22 @@ > #ifdef CONFIG_SCSI_MULTIPATH > #define SCSI_MPATH_DEVICE_ID_LEN 40 > > +struct scsi_mpath_head { > + char wwid[SCSI_MPATH_DEVICE_ID_LEN]; Don't name it WWID. That's an ATA thing. Make it vpd_id. > + struct list_head entry; > + int dev_count; > + struct ida ida; > + struct mutex lock; > + struct mpath_head *mpath_head; > + struct device dev; > + int index; > +}; > + > struct scsi_mpath_device { > struct mpath_device mpath_device; > struct scsi_device *sdev; > + int index; > + struct scsi_mpath_head *scsi_mpath_head; > > char device_id_str[SCSI_MPATH_DEVICE_ID_LEN]; > }; > @@ -32,8 +45,13 @@ int scsi_mpath_dev_alloc(struct scsi_device *sdev); > void scsi_mpath_dev_release(struct scsi_device *sdev); > int scsi_multipath_init(void); > void scsi_multipath_exit(void); > +void scsi_mpath_remove_device(struct scsi_mpath_device *scsi_mpath_dev); > +int scsi_mpath_get_head(struct scsi_mpath_head *); > +void scsi_mpath_put_head(struct scsi_mpath_head *); > #else /* CONFIG_SCSI_MULTIPATH */ > > +struct scsi_mpath_head { > +}; > struct scsi_mpath_device { > }; > > @@ -51,5 +69,16 @@ static inline int scsi_multipath_init(void) > static inline void scsi_multipath_exit(void) > { > } > +static inline void scsi_mpath_remove_device(struct scsi_mpath_device > + *scsi_mpath_dev) > +{ > +} > +static inline int scsi_mpath_get_head(struct scsi_mpath_head *) > +{ > + return 0; > +} > +static inline void scsi_mpath_put_head(struct scsi_mpath_head *) > +{ > +} > #endif /* CONFIG_SCSI_MULTIPATH */ > #endif /* _SCSI_SCSI_MULTIPATH_H */ Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.com +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich