Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2927870rdh; Mon, 27 Nov 2023 02:30:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzbaH7TrIPI4xY1yw3CYaP9nUQ/t5RMlY2uzCdO+ew4kn0F8RUhCpj1VaqGju1+Y3VIAHD X-Received: by 2002:a05:6808:e86:b0:3af:75e2:4c34 with SMTP id k6-20020a0568080e8600b003af75e24c34mr14348875oil.50.1701081040157; Mon, 27 Nov 2023 02:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701081040; cv=none; d=google.com; s=arc-20160816; b=ynCLYWZiKLYu29hOF/9AHMt7xHNOnhdg5EzNsunRbmXK4MCrTWYF/XKdt82Z58AMJA NcCv5Pr/9XJYx2QJWHtWIsPOAkZ4t7JqyQxHOsk8iEbTvIhoIsyDtgF3ndoLG95VEVNC xign+sH7yk1DcrPtQqh9aJ2ELMAKtnaiK2U8Kq+j3PjONuUPKZ7hZ88aS6ymjN/JR6Zd QbNMeMQ6OSgpPutzKIIn3BoM/ifNyFjz/opvWv4JgqnbknWuEBXwHHeWUgS+SK++MmxF YEXT3rZykSlxlqUAaJfunqbqgCWkPViwE7wwgee/IShoqeJ+j7girO0zHTfOrqV0ipfs /TBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=njBm3F4ghZp3I2T2lc9YUf5ew6i+9J0XGP00DaQkz1k=; fh=DJbT8ne4Efjik5M2lT8AzCh46QRFyMX3tPkPd3UGLh8=; b=W005oggdK0lCHvc/c6P8vi0B7Y40jGScXtLQs1st1OtApzcoCk8bkvjAWCWHJMhgsq 0GsrVNYb/XXhjMrjaaonWjxeLHntZDFDMolxbFVOdfxYRKV+07Gn8Hvn69jTxR6Sf0vH wRS9Dz2qmUBYvnFGOkj/Hf+apdargRu34KihLZAoTFdQo5cHINFAcBHKb1LM28f0RZTS AspINNU+5A1xe4ZdT19IwlUWYDsQvWxJyFku+zZ/lq+DqjLoqhlm4Ykjg+Otvsv98aMs LSwRUNWi8RIO2rSqmQUulvwTi2lUhyg+wdOymdJeIxAdzMYvoYu84uaZjHREbez9Rspq ODbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m21-20020a634c55000000b005bd6784a9fasi9171999pgl.676.2023.11.27.02.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 02:30:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 606B08079C93; Mon, 27 Nov 2023 02:30:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232932AbjK0KaA (ORCPT + 99 others); Mon, 27 Nov 2023 05:30:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232919AbjK0K36 (ORCPT ); Mon, 27 Nov 2023 05:29:58 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C54A3EA for ; Mon, 27 Nov 2023 02:30:04 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 20A1F202AC; Mon, 27 Nov 2023 10:30:03 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 0CB66132A6; Mon, 27 Nov 2023 10:30:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id N8CeAatvZGXgfwAAn2gu4w (envelope-from ); Mon, 27 Nov 2023 10:30:03 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [RFC v1] nvme: add cse, ds, ms, nsze and nuse to sysfs Date: Mon, 27 Nov 2023 11:32:08 +0100 Message-ID: <20231127103208.25748-1-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++++++ X-Spam-Score: 8.27 X-Rspamd-Server: rspamd1 X-Rspamd-Queue-Id: 20A1F202AC Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:98 is neither permitted nor denied by domain of dwagner@suse.de) smtp.mailfrom=dwagner@suse.de X-Spamd-Result: default: False [8.27 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.32)[-0.317]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 27 Nov 2023 02:30:19 -0800 (PST) libnvme is using the sysfs for enumarating the nvme resources. Though there are few missing attritbutes in the sysfs. For these libnvme issues commands during discovering. As the kernel already knows all these attributes and we would like to avoid libnvme to issue commands all the time, expose these missing attributes. Signed-off-by: Daniel Wagner --- As discussed during ALPPS, these here are the missing attribures which libnvme is still looking up via commands. I've tested this with a modified libnvme and didn't observe any ioctls anymore. I'm pretty sure the naming is a bit off for the variables. Not really sure if we want to stick to the spec naming sceme or have our own one, e.g. 'nsze' vs 'capacity'. Also getting a pointer to the nvme_ns data structure is a bit strange (dev_to_nvme_ns). This stip is necessary as many of the ns attributes are in nvme_ns. Shouldn't these per path values not all be the same and thus couldn't these be in nvme_ns_head? Anyway, just not sure who to deal with this. So any pointers highly welcomed! Cheers, Daniel drivers/nvme/host/core.c | 2 ++ drivers/nvme/host/nvme.h | 2 ++ drivers/nvme/host/sysfs.c | 72 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 80673ea63fea..f100ee241bd7 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2029,6 +2029,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, blk_mq_freeze_queue(ns->disk->queue); lbaf = nvme_lbaf_index(id->flbas); ns->lba_shift = id->lbaf[lbaf].ds; + ns->nsze = le64_to_cpu(id->nsze); + ns->nuse = le64_to_cpu(id->nuse); nvme_set_queue_limits(ns->ctrl, ns->queue); nvme_configure_metadata(ns, id); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index f35647c470af..97652bf2c787 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -487,6 +487,8 @@ struct nvme_ns { struct nvme_ns_head *head; int lba_shift; + u64 nsze; + u64 nuse; u16 ms; u16 pi_size; u16 sgs; diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c index 212e1b05d298..b46faee50361 100644 --- a/drivers/nvme/host/sysfs.c +++ b/drivers/nvme/host/sysfs.c @@ -114,12 +114,84 @@ static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(nsid); +static struct nvme_ns *dev_to_nvme_ns(struct device *dev) +{ + struct gendisk *disk = dev_to_disk(dev); + + if (disk->fops == &nvme_bdev_ops) + return nvme_get_ns_from_dev(dev); + else { + struct nvme_ns_head *head = disk->private_data; + struct nvme_subsystem *subsys = head->subsys; + struct nvme_ctrl *ctrl; + struct nvme_ns *ns, *ret = NULL; + + list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { + down_read(&ctrl->namespaces_rwsem); + list_for_each_entry(ns, &ctrl->namespaces, list) { + ret = ns; + break; + } + up_read(&ctrl->namespaces_rwsem); + } + return ret; + } +} + +static ssize_t csi_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ids.csi); +} +static DEVICE_ATTR_RO(csi); + +static ssize_t lba_ds_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvme_ns *ns = dev_to_nvme_ns(dev); + + return sysfs_emit(buf, "%d\n", ns->lba_shift); +} +static DEVICE_ATTR_RO(lba_ds); + +static ssize_t lba_ms_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvme_ns *ns = dev_to_nvme_ns(dev); + + return sysfs_emit(buf, "%d\n", ns->ms); +} +static DEVICE_ATTR_RO(lba_ms); + +static ssize_t nsze_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvme_ns *ns = dev_to_nvme_ns(dev); + + return sysfs_emit(buf, "%llu\n", ns->nsze); +} +static DEVICE_ATTR_RO(nsze); + +static ssize_t nuse_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvme_ns *ns = dev_to_nvme_ns(dev); + + return sysfs_emit(buf, "%llu\n", ns->nuse); +} +static DEVICE_ATTR_RO(nuse); + static struct attribute *nvme_ns_id_attrs[] = { &dev_attr_wwid.attr, &dev_attr_uuid.attr, &dev_attr_nguid.attr, &dev_attr_eui.attr, + &dev_attr_csi.attr, &dev_attr_nsid.attr, + &dev_attr_lba_ds.attr, + &dev_attr_lba_ms.attr, + &dev_attr_nsze.attr, + &dev_attr_nuse.attr, #ifdef CONFIG_NVME_MULTIPATH &dev_attr_ana_grpid.attr, &dev_attr_ana_state.attr, -- 2.43.0