From patchwork Thu Jan 23 22:21:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Smart X-Patchwork-Id: 11349253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8376317EF for ; Thu, 23 Jan 2020 22:21:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F24521D7E for ; Thu, 23 Jan 2020 22:21:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FWfeuxsi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728904AbgAWWVM (ORCPT ); Thu, 23 Jan 2020 17:21:12 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40481 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgAWWVL (ORCPT ); Thu, 23 Jan 2020 17:21:11 -0500 Received: by mail-pg1-f196.google.com with SMTP id k25so2087999pgt.7 for ; Thu, 23 Jan 2020 14:21:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0k821ioYLcih8vf/gJjSO7Ax9tQbTTCQOZMsHt0dh0c=; b=FWfeuxsiNPtHOY0B0ji/JlI1wYZKjigKigdSgGqLrMGWUfdAaOx9r+MzpQ+hmKN7zb l0EqC3Dv1u7iuFUfxRNsNLtUJu5WYQ77O7Wj+aqPFvnxIzq7dMnXoqtqsbKIXdDs7CMI RCjqWsBNRsiNKygTy3uM4a+7VusLMpRVjzDDq8jNzgUOJuQNBVaHJHq3SF2PoxH1/2ue KTt6n8dXalt3sD8JywPVXcYnQOJstDNLiDkZC0snvHVY+rwy+LLjkn6gI0vxHiLpHELm BPQ+hHy4cICC9HDRuL4OeE0s6g7BWPjaKTsrjxUlaCbdlA9Me9JQgYmRm66tygo/n8Fb Worg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0k821ioYLcih8vf/gJjSO7Ax9tQbTTCQOZMsHt0dh0c=; b=TczlEgI6thaZzmPldpVoxIW+VRUGtSxyLQ9vj0k4uhNO0i9OHG6miSkgpn7O2eN9XN 5/K8tdJ8UcLygM/32LA3URP9TMusww9to/t/ZExFFsbciR4JgPP3cw/IKdal6Qo1d4fe yJj9IsVVFolRD1JMKO2JAhs6EW23aQ0M0VGul9HU9FdhFMX2mvU3UZcuN8c2LksuUm78 /tfYST2OwBR6ElQnnxO+ojXG3WlBHLA/nNRPsITpeRP1OPgoqBmS9pX39SWhbyEdFHPu qIgXcFm0qhXyL27sRPr7/mozRio3QC8O/JIdl/kv5aAQZyIpzg90e22WquH/iY9LD2D0 vwig== X-Gm-Message-State: APjAAAX5PoU+y9Ap+YFE+q7IKsGEHVKOvRSeEvNZCP6Lr78Trr+gfoCp oVt0HhpyaEFZUxznOyRd1SCE0hm3 X-Google-Smtp-Source: APXvYqyvvCz1Qt08iWFMUxVLRszvHBlwPKjOXccYlnDGEHWiRmmlQrj7BkyirJajvfux3fNAhtss6Q== X-Received: by 2002:a63:d66:: with SMTP id 38mr559643pgn.233.1579818070785; Thu, 23 Jan 2020 14:21:10 -0800 (PST) Received: from os42.localdomain ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id g8sm3616660pfh.43.2020.01.23.14.21.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Jan 2020 14:21:10 -0800 (PST) From: James Smart To: linux-scsi@vger.kernel.org Cc: James Smart Subject: [PATCH v2 1/3] scsi: refactor sdev lun queue depth setting via sysfs Date: Thu, 23 Jan 2020 14:21:00 -0800 Message-Id: <20200123222102.23383-2-jsmart2021@gmail.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200123222102.23383-1-jsmart2021@gmail.com> References: <20200123222102.23383-1-jsmart2021@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In preparation for allowing other attributes and routines to change the current and max lun queue depth on an sdev, refactor the sysfs sdev attribute change routine. The refactoring creates a new scsi-internal routine, scsi_change_max_queue_depth(), which changes a devices current and max queue value. The new routine is placed next to the routine, scsi_change_queue_depth(), which is used by most lldds to implement a queue depth change. Signed-off-by: James Smart Reviewed-by: Bart Van Assche --- drivers/scsi/scsi.c | 22 ++++++++++++++++++++++ drivers/scsi/scsi_priv.h | 1 + drivers/scsi/scsi_sysfs.c | 9 +++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 930e4803d888..195c0b11260a 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -249,6 +249,28 @@ int scsi_change_queue_depth(struct scsi_device *sdev, int depth) } EXPORT_SYMBOL(scsi_change_queue_depth); +/* + * scsi_change_max_queue_depth - change the max queue depth for a device. + * @sdev: SCSI Device in question + * @depth: number of commands allowed to be queued to the driver + * + * Calls the device's transport to validate and change the queue depth, + * then stores the new maximum on the device. + */ +int +scsi_change_max_queue_depth(struct scsi_device *sdev, int depth) +{ + int retval; + + retval = sdev->host->hostt->change_queue_depth(sdev, depth); + if (retval < 0) + return retval; + + sdev->max_queue_depth = sdev->queue_depth; + + return 0; +} + /** * scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth * @sdev: SCSI Device in question diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 3bff9f7aa684..5c288cf3ae64 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -41,6 +41,7 @@ static inline void scsi_log_send(struct scsi_cmnd *cmd) static inline void scsi_log_completion(struct scsi_cmnd *cmd, int disposition) { }; #endif +int scsi_change_max_queue_depth(struct scsi_device *sdev, int depth); /* scsi_devinfo.c */ diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 677b5c5403d2..954f68b002cb 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -982,22 +982,19 @@ sdev_store_queue_depth(struct device *dev, struct device_attribute *attr, { int depth, retval; struct scsi_device *sdev = to_scsi_device(dev); - struct scsi_host_template *sht = sdev->host->hostt; - if (!sht->change_queue_depth) - return -EINVAL; + if (!sdev->host->hostt->change_queue_depth) + return -ENOTSUPP; depth = simple_strtoul(buf, NULL, 0); if (depth < 1 || depth > sdev->host->can_queue) return -EINVAL; - retval = sht->change_queue_depth(sdev, depth); + retval = scsi_change_max_queue_depth(sdev, depth); if (retval < 0) return retval; - sdev->max_queue_depth = sdev->queue_depth; - return count; } sdev_show_function(queue_depth, "%d\n"); From patchwork Thu Jan 23 22:21:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Smart X-Patchwork-Id: 11349255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04E11159A for ; Thu, 23 Jan 2020 22:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D405F21734 for ; Thu, 23 Jan 2020 22:21:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MiRqD2qO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729203AbgAWWVN (ORCPT ); Thu, 23 Jan 2020 17:21:13 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:33802 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728988AbgAWWVN (ORCPT ); Thu, 23 Jan 2020 17:21:13 -0500 Received: by mail-pj1-f65.google.com with SMTP id f2so23428pjq.1 for ; Thu, 23 Jan 2020 14:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aOcxg7DsFkYHqwW8hr47b+HAI2mUE5xc6hC+CMJmCGU=; b=MiRqD2qOxLy+bwx8i1OetxGjPc+Nci3fZjYhurcW8hf+8jxVDpfnh7r+pnHT2mHhYv EVBklXOvuHXpQ7/oyjSZwgHKOJ/sEtUYlFiOcbF64vDyIaoh+H9oqGsbjzuOP7ykaX8+ 1/stTcA2sbFO4pkKmfsiCtEmkje76hQXtradF96msmiSLjCIjPdCMlYR96AIBmf3hfSU pS6qW26NnSkkSfpGBeH8biaF4edjVCs9YqQdQtfZFd2OVuAjOMb8jDVcXe5Z9T7gtRNh Zyky5GthiCjCLCiav5pJ6uj/NzR5U6Gbf3YfvDW4DII2yK/vM5OpiG8W6CqGURHY6kfZ ZsjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aOcxg7DsFkYHqwW8hr47b+HAI2mUE5xc6hC+CMJmCGU=; b=eY4cGoer7ijM2Za2fc5Oxo+lQzKhgoAOEPcs+Wscscyx4dUfvEOFHsTWtOFzKZawbj qcGPw4mgLnK5j3oMQeKKTzfVZTYXiu+jpmIPKmTbXFvJWuWY0KiwcMDEL3ZvyDCx8L9q wO3Cw6Vir0f3uBtifBP7Efv20T2kzRVqyUjg+HR/t/0ja7cZC9YnyZQhh7YrZAXz5oX7 YzhKJteZw8DYU61xrP0mTqjSW4wt9KKKulPW4+Gv4vs1z9oyOg06Y7+l6P9sPtgX6iNN psAD9Aahjl4Es6QKGctP5/RIK0IVnrll/OIdsz2zpmG92syPcmzzR1yZsXVYNDbwLYbE 1j5w== X-Gm-Message-State: APjAAAXv6PzIEtm9qoq4f1XpSzl2/KhQy3VAhICwcaXRGvpGs9V67Qh1 GchItuq2hqsOTdJ5896oZxbDu6ZZ X-Google-Smtp-Source: APXvYqzLacguDwPJsX5uPUU4Hr+BgSi2BP1Db4MO5FBqaj03gAIFBzPcSBN57nF2o3AvtS3SJXjuDA== X-Received: by 2002:a17:90a:2e88:: with SMTP id r8mr9730pjd.85.1579818071642; Thu, 23 Jan 2020 14:21:11 -0800 (PST) Received: from os42.localdomain ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id g8sm3616660pfh.43.2020.01.23.14.21.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Jan 2020 14:21:11 -0800 (PST) From: James Smart To: linux-scsi@vger.kernel.org Cc: James Smart Subject: [PATCH v2 2/3] scsi: add shost helper to set max queue depth on all of its devices Date: Thu, 23 Jan 2020 14:21:01 -0800 Message-Id: <20200123222102.23383-3-jsmart2021@gmail.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200123222102.23383-1-jsmart2021@gmail.com> References: <20200123222102.23383-1-jsmart2021@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Create a helper routine to loop through all devices on an shost and change their current and maximum queue depth. The helper is created such that is lldd callable. Signed-off-by: James Smart --- drivers/scsi/scsi.c | 32 ++++++++++++++++++++++++++++++++ include/scsi/scsi_device.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 195c0b11260a..f5bb8ce4661f 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -272,6 +272,38 @@ scsi_change_max_queue_depth(struct scsi_device *sdev, int depth) } /** + * shost_change_max_queue_depths - helper to walk all devices on a + * shost and change their max queue depth. + * @shost: shost whose devices we want to iterate over. + * @depth: number of commands allowed to be queued to the driver + * + * Validates the shost allows a change of queue depth, the value is valid, + * then traverses over all devices and sets their maximum queue depth. + */ +int shost_change_max_queue_depths(struct Scsi_Host *shost, int depth) +{ + struct scsi_device *sdev; + int retval; + + if (!shost->hostt->change_queue_depth) + return -ENOTSUPP; + + if (depth < 1 || depth > shost->can_queue) + return -EINVAL; + + shost_for_each_device(sdev, shost) { + retval = scsi_change_max_queue_depth(sdev, depth); + if (retval != 0) + sdev_printk(KERN_INFO, sdev, + "failed to set queue depth to %d (err %d)", + depth, retval); + } + + return 0; +} +EXPORT_SYMBOL(shost_change_max_queue_depths); + +/** * scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth * @sdev: SCSI Device in question * @depth: Current number of outstanding SCSI commands on this device, diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index f8312a3e5b42..38c4b97fc1b8 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -392,6 +392,7 @@ extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *, extern int scsi_change_queue_depth(struct scsi_device *, int); extern int scsi_track_queue_full(struct scsi_device *, int); +extern int shost_change_max_queue_depths(struct Scsi_Host *shost, int depth); extern int scsi_set_medium_removal(struct scsi_device *, char); From patchwork Thu Jan 23 22:21:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Smart X-Patchwork-Id: 11349257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FBFC1398 for ; Thu, 23 Jan 2020 22:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B3DB21D7E for ; Thu, 23 Jan 2020 22:21:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zd4zXd9e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729205AbgAWWVN (ORCPT ); Thu, 23 Jan 2020 17:21:13 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42351 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgAWWVN (ORCPT ); Thu, 23 Jan 2020 17:21:13 -0500 Received: by mail-pg1-f195.google.com with SMTP id s64so2078043pgb.9 for ; Thu, 23 Jan 2020 14:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ngc2l8NkuAdUGD5zjUuA+OfrA2FJEejnzIlFf0MlouA=; b=Zd4zXd9ekITMK+WnJhhDdjeCMM5kB2BjAz1AlpjUm8ZmLna1uqDzW7MZR/HfCZ8DW/ lXS6nKaiKBmIOP+o5YSWFNSJitI08XaYC6uHaMooZIVwXrX7OJyRP7zUL6ptosON+eqv 5+JUkJNmcUv3iubcr0kCKooqadlL2Ene+YYbGjKtpUIpBAiBi32vxF3qZgMQ7cxTSZki HgzdoIHKlJKz92qdPO2+q+QiHGm/6a1Ldv5iiWwl8qPqZzIEwNodVEu/8xQXjSsefx76 40JX+dtrdDijP02jRsZnft3d4dV95daN2TaabuVV0QKf183ReG+qeAhetBCu/dSyxqGg hwIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ngc2l8NkuAdUGD5zjUuA+OfrA2FJEejnzIlFf0MlouA=; b=IiB1keb7wrGvOcSAzNMdMXihC5O7yUo/pqKPBVs3/dbCY14QGQzymtIbq+wfF3yKUK gnRDdStlI+z5EuQbI5/hW3rffT54fCBeE80EzGOmgRoZI6JnUHD11/nlSAq7XWN/tYDJ kBY/MzwH6FO3XOy+mlJxYyUJ7J3j/DUieRHlgnReUKFLgK47Ppx7y0UipJjLwOw94a77 0mMizlpJWUTiJPcbwQ+Kb31+GycnhblRxdLt7tElvOjVyjecq39AUwXTT8dww/WGgm1p QyHiVC3m6Jrc+QIY8oLSeelj7ahofpCrpBHaHZkmh18cli440HRxGXPWs1Shi23UqpJN iLfQ== X-Gm-Message-State: APjAAAXoY69/Wr0Mqfqei51Ce4ih0VvrD8QyL7krGosqRqBqBHjIOH4k StI5n5fxjOgZABc8v1dgkxAAwigU X-Google-Smtp-Source: APXvYqzB9EFHdcFWhAo9KZ+00A6wypvcWhCrUSNNYcNVfKDIk3v2Kz6v1bxaN7ngh3IcjOHjriWNgA== X-Received: by 2002:a65:6794:: with SMTP id e20mr621141pgr.152.1579818072497; Thu, 23 Jan 2020 14:21:12 -0800 (PST) Received: from os42.localdomain ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id g8sm3616660pfh.43.2020.01.23.14.21.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Jan 2020 14:21:12 -0800 (PST) From: James Smart To: linux-scsi@vger.kernel.org Cc: James Smart Subject: [PATCH v2 3/3] scsi: add shost attribute to set max queue depth on all devices on the shost Date: Thu, 23 Jan 2020 14:21:02 -0800 Message-Id: <20200123222102.23383-4-jsmart2021@gmail.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200123222102.23383-1-jsmart2021@gmail.com> References: <20200123222102.23383-1-jsmart2021@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch adds an shost attribute, max_device_queue_depth, that will cycle through all devices on the shost and change their current and max queue depth to the new value. Signed-off-by: James Smart --- drivers/scsi/scsi_sysfs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 954f68b002cb..85dab4867eed 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -368,6 +368,23 @@ store_shost_eh_deadline(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR(eh_deadline, S_IRUGO | S_IWUSR, show_shost_eh_deadline, store_shost_eh_deadline); +static ssize_t +store_host_max_device_queue_depth(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct Scsi_Host *shost = class_to_shost(dev); + int depth, retval; + + depth = simple_strtoul(buf, NULL, 0); + + retval = shost_change_max_queue_depths(shost, depth); + + return (retval < 0) ? retval : count; +} + +static DEVICE_ATTR(max_device_queue_depth, S_IWUSR, NULL, + store_host_max_device_queue_depth); + shost_rd_attr(unique_id, "%u\n"); shost_rd_attr(cmd_per_lun, "%hd\n"); shost_rd_attr(can_queue, "%hd\n"); @@ -411,6 +428,7 @@ static struct attribute *scsi_sysfs_shost_attrs[] = { &dev_attr_prot_guard_type.attr, &dev_attr_host_reset.attr, &dev_attr_eh_deadline.attr, + &dev_attr_max_device_queue_depth.attr, NULL };