[PATCH 1/2] nvme: keep transport module referenced while head node is open
Nilay Shroff
nilay at linux.ibm.com
Tue Sep 1 21:55:48 PDT 2026
On 9/1/26 10:09 PM, Keith Busch wrote:
> On Mon, Aug 31, 2026 at 08:49:54PM +0530, Nilay Shroff wrote:
>> +static inline int nvme_module_get(struct nvme_ns *ns, unsigned int count)
>> +{
>> + unsigned int i;
>> +
>> + for (i = 0; i < count; i++) {
>> + if (!try_module_get(ns->ctrl->ops->module))
>> + goto out_unwind;
>> + }
>> +
>> + return 0;
>> +out_unwind:
>> + while (i--)
>> + module_put(ns->ctrl->ops->module);
>> + return -ENXIO;
>> +}
>> +
>> +static inline void nvme_module_put(struct nvme_ns *ns, unsigned int count)
>> +{
>> + while (count--)
>> + module_put(ns->ctrl->ops->module);
>> +}
>
> Thanks, looks correct to me.
>
> I don't like the looping though. This could be done in a single
> atomic_sub instead of multiple atomic_dec calls if the module api
> provided something to get/put many references.
Yeah I though of the same however unfortunately module APIs don't
provide something using which we could atomically get/put more than
one references.
Thanks,
--Nilay
More information about the Linux-nvme
mailing list