Ensure LSM handles aren't closed while the LSM manager is looking at them

Take the dhandle lock, but minimize the amount of time we are holding it for.

This is similar to #1409 but holds the dhandle lock for a shorter period. There could be a lot of trees open, and the manager can allocate memory inside the loop, so I think it's best to avoid holding the handle lock for the entire operation.