Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2078596ybb; Thu, 2 Apr 2020 12:39:58 -0700 (PDT) X-Google-Smtp-Source: APiQypIp99losAwXkXY5HmBv6C11yoUue8tHgQBwOhvCxIOxCTRdSP6ioS+YLtWNB4wkTz7IplEP X-Received: by 2002:a05:6830:19ee:: with SMTP id t14mr3904588ott.287.1585856398307; Thu, 02 Apr 2020 12:39:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585856398; cv=none; d=google.com; s=arc-20160816; b=jj8mi8SREgxvZLs2SquibCF7Z6ei+litqWwyucTlOyW3ng2VTbl5amRcukRj2xI9fi 1iq090aAk+S3ZCr4V/QFIBk7eD47M/JJxdrInzaRd2p8BiAbct9jwCDKQjEgblkulXsE Db6Of/9fZtqUQKXcKrJ6nrUrlCEEaIBYJLAUQNM3QjpU0NVxrg8LJ+UrCaVrcJNsvJmU h8du2tADT1liXs2dndqIGl1TA9gCYrmojN58nLq212d6BR5Rsx1z8TZZpGegYEBENMxZ VKF2d7NDpMeym9hIuB8n6IO8PtTG643pKzchRbde1Xse1XLrr/MGvkSDCE6tdbB4ECOg 4zcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qoaA5NbGxmTMnNGkYzMKE+9t8shJ4Z++3QQAiHksp9g=; b=Xem848rNmiROtQWAFrdmT+0ajkz2Ks+FCEttGwla/lBiCOc03Jwx9Svyo6CTn5ONff ggxedmNC4ITATjn12EI8Rgk5vdo9b5ZVkX6Om3Mkrlmktx+h0TgcxB2AOiQFgskyfz1E uQ17APsXID7cCK/xDRS5vseV9nTDxJgmrW6CK7LljKSo0sgHswtZD6B/yM9vZO6S9Ghr hz7otQfROgGbcSaETKM7A71CP+lf14uTz56BaXgE4IRYWTDMxs5cqlAuVb0mMi7W9O1k De3QJl+EdlHEuGbIdTuG7NJku89k4Q3iEHYFe+Ugze9mUl8o//WMNYZmTrLKrKgkpoKm ++qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13si2732225oom.86.2020.04.02.12.39.45; Thu, 02 Apr 2020 12:39:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389545AbgDBTbP (ORCPT + 99 others); Thu, 2 Apr 2020 15:31:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:36936 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389108AbgDBTbP (ORCPT ); Thu, 2 Apr 2020 15:31:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A8C07AEC2; Thu, 2 Apr 2020 19:31:13 +0000 (UTC) From: Anthony Iliopoulos To: Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvmet: add revalidation support to bdev and file backed namespaces Date: Thu, 2 Apr 2020 21:30:52 +0200 Message-Id: <20200402193052.19935-1-ailiop@suse.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for detecting capacity changes on nvmet blockdev and file backed namespaces. This allows for emulating and testing online resizing of nvme devices and filesystems on top. Signed-off-by: Anthony Iliopoulos --- drivers/nvme/target/admin-cmd.c | 5 +++++ drivers/nvme/target/io-cmd-bdev.c | 10 ++++++++++ drivers/nvme/target/io-cmd-file.c | 14 ++++++++++++++ drivers/nvme/target/nvmet.h | 2 ++ 4 files changed, 31 insertions(+) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 9d6f75cfa77c..4c79aa804887 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -486,6 +486,11 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req) if (!ns) goto done; + if (ns->bdev) + nvmet_bdev_ns_revalidate(ns); + else + nvmet_file_ns_revalidate(ns); + /* * nuse = ncap = nsze isn't always true, but we have no way to find * that out from the underlying device. diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index ea0e596be15d..1f8c00d68aa9 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -75,6 +75,16 @@ void nvmet_bdev_ns_disable(struct nvmet_ns *ns) } } +void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns) +{ + loff_t size; + + size = i_size_read(ns->bdev->bd_inode); + + if (ns->size != size) + ns->size = size; +} + static u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts) { u16 status = NVME_SC_SUCCESS; diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index cd5670b83118..c102437db72a 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -80,6 +80,20 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) return ret; } +void nvmet_file_ns_revalidate(struct nvmet_ns *ns) +{ + struct kstat stat; + + if (!ns->file) + return; + + if (vfs_getattr(&ns->file->f_path, + &stat, STATX_SIZE, AT_STATX_FORCE_SYNC)) + return; + + ns->size = stat.size; +} + static void nvmet_file_init_bvec(struct bio_vec *bv, struct scatterlist *sg) { bv->bv_page = sg_page(sg); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 421dff3ea143..8b479d932a7b 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -498,6 +498,8 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns); u16 nvmet_bdev_flush(struct nvmet_req *req); u16 nvmet_file_flush(struct nvmet_req *req); void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid); +void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns); +void nvmet_file_ns_revalidate(struct nvmet_ns *ns); static inline u32 nvmet_rw_len(struct nvmet_req *req) { -- 2.26.0