[PATCH 1/2] nvmet: make 'readonly' setting configurable

Christoph Hellwig hch at lst.de
Thu Apr 3 23:21:26 PDT 2025


On Thu, Apr 03, 2025 at 09:44:55AM -0600, Keith Busch wrote:
> > +	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.

I really hate it with passion as the syntax is so butt ugly and has
no explicit unlock point.  Why couldn't folks at least do the simple
python thing:

	with (mutex(&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;
	}

> 
> > +	return count;
> > +}
---end quoted text---



More information about the Linux-nvme mailing list