[lustre-devel] [PATCH 19/21] lustre: obdclass: avoid races in class_register_type()

NeilBrown neilb at suse.com
Sun Feb 10 16:58:55 PST 2019


On Fri, Feb 08 2019, Andreas Dilger wrote:

> On Feb 6, 2019, at 17:03, NeilBrown <neilb at suse.com> wrote:
>> 
>> If there are two parallel attempts to register the
>> same class name, it could get registered twice.
>> So re-check after allocation to make sure the name is
>> still unique.
>
> The patch itself seems reasonable, but I don't see how this
> scenario could ever happen?  class_register_type() is only
> called once per device type from the module init code, and
> I don't think it is possible to insert the same module twice?

I agree. I don't think it can happen.
By the same logic, the test

	if (class_search_type(name)) {
		CDEBUG(D_IOCTL, "Type %s already registered\n", name);
		return -EEXIST;
	}

at the start of class_register_type() is pointless, as it is not
possible for the same name to be registered twice.

But I think it is still good to have this test, and to fail-safe.
To me the test as it is "looks" prone to races, so I wanted to fix it.
When I'm analysining obscure bugs, it helps a lot to have code that is
"obviously correct" without having the understand (and double check)
various assumptions about usage which are necessary for it to be
correct.

So this patch isn't needed for correctness. It is needed (I think) to
make the code understandable and maintainable.

Thanks,
NeilBrown


>
> Cheers, Andreas
> ---
> Andreas Dilger
> Principal Lustre Architect
> Whamcloud
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20190211/28704704/attachment.sig>


More information about the lustre-devel mailing list