[PATCH 1/2] nvmet: make 'readonly' setting configurable
Keith Busch
kbusch at kernel.org
Thu Apr 3 08:44:55 PDT 2025
On Thu, Apr 03, 2025 at 04:47:46PM +0200, Hannes Reinecke wrote:
> +static ssize_t nvmet_ns_readonly_store(struct config_item *item,
> + const char *page, size_t count)
> +{
> + struct nvmet_ns *ns = to_nvmet_ns(item);
> + bool val;
> +
> + if (kstrtobool(page, &val))
> + return -EINVAL;
> +
> + mutex_lock(&ns->subsys->lock);
> + if (ns->enabled) {
> + pr_err("the ns:%d is already enabled.\n", ns->nsid);
> + mutex_unlock(&ns->subsys->lock);
> + return -EINVAL;
> + }
> + ns->readonly = val;
> + mutex_unlock(&ns->subsys->lock);
Not sure how people feel about the "cleanup" constructs. If we're okay
using them in this driver, this is a simple use case for the guard to
manage the mutex:
guard(mutex)(&ns->subsys->lock);
And then you don't need to worry about unlocking.
> + return count;
> +}
More information about the Linux-nvme
mailing list