pool: Fix race conditions in HSM management commands

Addresses race conditions in HSM management commands. These
race conditions could lead to corrupted HSM definitions and
infinite loops during flush and stage.

It is unlikely that one would hit any of these races in the
real world. For this reason I am not requesting a merge to
stable branches.

Target: trunk
Require-notes: yes
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: http://rb.dcache.org/r/5486/