nvmet: revalidate-ns & generate AEN from configfs
authorChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Tue, 19 May 2020 08:06:29 +0000 (01:06 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 27 May 2020 05:12:38 +0000 (07:12 +0200)
Add a new attribute "revalidate_size" for the namespace which allows
user to revalidate and generate the AEN if needed. This attribute is
needed so that we can install userspace rules with systemd service based
on inotify/fsnotify/uevent. The registered callback for such a service
will end up writing to this attribute to generate AEN if needed.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Sagi Grimberg <sagi@grimbeg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/configfs.c

index 24eb4cf..17c5292 100644 (file)
@@ -540,6 +540,31 @@ static ssize_t nvmet_ns_buffered_io_store(struct config_item *item,
 
 CONFIGFS_ATTR(nvmet_ns_, buffered_io);
 
+static ssize_t nvmet_ns_revalidate_size_store(struct config_item *item,
+               const char *page, size_t count)
+{
+       struct nvmet_ns *ns = to_nvmet_ns(item);
+       bool val;
+
+       if (strtobool(page, &val))
+               return -EINVAL;
+
+       if (!val)
+               return -EINVAL;
+
+       mutex_lock(&ns->subsys->lock);
+       if (!ns->enabled) {
+               pr_err("enable ns before revalidate.\n");
+               mutex_unlock(&ns->subsys->lock);
+               return -EINVAL;
+       }
+       nvmet_ns_revalidate(ns);
+       mutex_unlock(&ns->subsys->lock);
+       return count;
+}
+
+CONFIGFS_ATTR_WO(nvmet_ns_, revalidate_size);
+
 static struct configfs_attribute *nvmet_ns_attrs[] = {
        &nvmet_ns_attr_device_path,
        &nvmet_ns_attr_device_nguid,
@@ -547,6 +572,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = {
        &nvmet_ns_attr_ana_grpid,
        &nvmet_ns_attr_enable,
        &nvmet_ns_attr_buffered_io,
+       &nvmet_ns_attr_revalidate_size,
 #ifdef CONFIG_PCI_P2PDMA
        &nvmet_ns_attr_p2pmem,
 #endif