So I spent a bit on this before I realized, as far as I can tell, the code is fine, and I can't reproduce this:
lctl net down works fine for me in this scenario, both on master and on b2_12.
I also can't reproduce the problem Doug described about the config thing. It's true that you cannot unconfigure LNet while ptlrpc is loaded, but that's because ptlrpc won't load without network interfaces available. ptlrpc doesn't support being loaded without nis configured, so you can't unconfigure them without unloading it.
But it's not just "a flag that's set" - that flag reflects whether LNet initialized its own config or if it was done by ptlrpc. If it was done by ptlrpc, then LNet can't just tear it down. All of the scenarios and orders I could think of for "config done by lnet, done by ptlrpc (this is the same as "done by a mount")" work fine, given that you accept that you can't unconfigure lnet while ptlrpc is loaded.
Maybe there's just something IML is doing that's making LNet busy...? Because this code seems to be fine.
Per our conversation this morning, it looks like with
LU-11986fixed (which is in progress, patch exists) IML is able to do what it needs to do.