Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80DDFC433EF for ; Tue, 28 Sep 2021 09:06:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 439A860FC2 for ; Tue, 28 Sep 2021 09:06:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 439A860FC2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ra7jSq9NlNMPH6vmYRnt/873UqpWAuxhWFh7Fe0+oek=; b=X8xUJ9J30WQl/Z L+qvEFFsKF3LuBjOaOVSwp/q215AnlhOcx/e3HKpDwmsRpCtXiI7uG7drnJ6htXHE30xvTOdLisha QmG3b9bpjfU1aYsfuo0n9zmpTALnrdhC4glHv6/fYfcDe/3esqgsUVbVv0K2kz0tJIytIKGB7FERy OMnBIT0cmIQoYf0Khw4Z7qTXa/Ka58hOtzptnRZoUNXK7sb9bWMJqc5IpQutG0AUG0Od8woiM9Uzy T0y9RjsBgI8WDhNpeRYYqz7rSqixDgqlMtxjvT+CEBJKptacVp0VzV+7/8f4yritbFOqmkYB0hQcM NrxYJvlWJcT762F2En4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mV94B-006SXT-3j; Tue, 28 Sep 2021 09:06:23 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mV8pD-006LWt-A5 for linux-nvme@lists.infradead.org; Tue, 28 Sep 2021 08:50:57 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HJY5R6Qb2zbmsJ; Tue, 28 Sep 2021 16:46:35 +0800 (CST) Received: from dggpeml500006.china.huawei.com (7.185.36.76) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 28 Sep 2021 16:50:51 +0800 Received: from huawei.com (10.169.63.14) by dggpeml500006.china.huawei.com (7.185.36.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 28 Sep 2021 16:50:51 +0800 From: chengjike To: , , , CC: , Subject: [PATCH V3 nvme-cli 1/2] initialize disk "access" variable Date: Tue, 28 Sep 2021 16:50:49 +0800 Message-ID: <20210928085050.4141-2-chengjike.cheng@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20210928085050.4141-1-chengjike.cheng@huawei.com> References: <20210928085050.4141-1-chengjike.cheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.169.63.14] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500006.china.huawei.com (7.185.36.76) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210928_015055_746631_8A0FB676 X-CRM114-Status: GOOD ( 16.35 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org (This is a prep patch, which provides functions for the next "patch 2/2") When it is failed to get nvme_id_ns data from NVMe Subsystem. Then the "access" of disk is set to "faulty"(otherwise, set the value to "live"). Some displaying content of fault device can be obtained from the disk attribute files. In addition, external function "nvme_ns_get_access" is added, which will be used in the next patch. Signed-off-by: chengjike --- src/nvme/private.h | 1 + src/nvme/tree.c | 54 +++++++++++++++++++++++++++++++++++++++++----- src/nvme/tree.h | 11 ++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/nvme/private.h b/src/nvme/private.h index 2a151bf..255c1b1 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -37,6 +37,7 @@ struct nvme_ns { __u32 nsid; char *name; char *sysfs_dir; + char *access; int lba_shift; int lba_size; diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 293b0c0..04d92c9 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -229,9 +229,11 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n) static void __nvme_free_ns(struct nvme_ns *n) { list_del_init(&n->entry); - close(n->fd); + if (n->fd > 0) + close(n->fd); free(n->name); free(n->sysfs_dir); + free(n->access); free(n); } @@ -1023,9 +1025,6 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path, closedir(d); c->fd = nvme_open(name); - if (c->fd < 0) - return c->fd; - c->name = strdup(name); c->sysfs_dir = (char *)path; c->firmware = nvme_get_ctrl_attr(c, "firmware_rev"); @@ -1277,6 +1276,11 @@ const char *nvme_ns_get_name(nvme_ns_t n) return n->name; } +const char *nvme_ns_get_access(nvme_ns_t n) +{ + return n->access; +} + const char *nvme_ns_get_model(nvme_ns_t n) { return n->c ? n->c->model : n->s->model; @@ -1515,6 +1519,34 @@ free_ns: return NULL; } +static nvme_ns_t nvme_ns_get_local_data(const char *name, const char *path) +{ + struct nvme_ns *n; + char *ns_id; + + n = calloc(1, sizeof(*n)); + if (!n) { + errno = ENOMEM; + return NULL; + } + + n->name = strdup(name); + n->fd = -1; + ns_id = nvme_get_attr(path, "nsid"); + if (!ns_id) { + free(n->name); + free(n); + return NULL; + } + n->nsid = atoi(ns_id); + free(ns_id); + + list_head_init(&n->paths); + list_node_init(&n->entry); + + return n; +} + static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char *name) { struct nvme_ns *n; @@ -1528,9 +1560,21 @@ static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char * } n = nvme_ns_open(name); - if (!n) + if (!n) { + n = nvme_ns_get_local_data(name, path); + if (!n) + goto free_path; + ret = asprintf(&n->access, "%s", "faulty"); + if (ret < 0) + goto free_path; + goto get_attr; + } + + ret = asprintf(&n->access, "%s", "live"); + if (ret < 0) goto free_path; +get_attr: n->sysfs_dir = path; return n; diff --git a/src/nvme/tree.h b/src/nvme/tree.h index 68f5cbf..82895bd 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -452,6 +452,17 @@ const char *nvme_ns_get_sysfs_dir(nvme_ns_t n); */ const char *nvme_ns_get_name(nvme_ns_t n); +/** + * nvme_ns_get_access() - + * @n: Address of the nvme namespace structure + * + * Get the access status of the nvme namespace + * + * Return: The 'access' field from 'nvme_ns'(for normal namespace, + * 'live' is returned; for inaccessible namespace, 'faulty' is returned). + */ +const char *nvme_ns_get_access(nvme_ns_t n); + /** * nvme_ns_get_firmware() - * @n: -- 2.21.0.windows.1 _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme