[PATCH 1/2] nvmet: make 'readonly' setting configurable
Hannes Reinecke
hare at suse.de
Thu Apr 3 08:51:55 PDT 2025
On 4/3/25 17:44, Keith Busch wrote:
> 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.
>
Sure, can do that.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
More information about the Linux-nvme
mailing list