Commit ca1cfd5
committed
kvm: fix storage pool refcount race and misreported umount result
Two bugs in the storage pool teardown path.
adjustStoragePoolRefCount() means to lock on the single String instance
held as the map key, so that all callers share a monitor. When the map
has no entry for the pool, orElse(uuid) returns the caller's own instance
instead and the synchronized block guards nothing.
Increments cannot race each other: they happen inside createStoragePool,
which is only reached through KVMStoragePoolManager.createStoragePool,
and that is synchronized. Decrements are not covered, because
KVMStoragePoolManager.deleteStoragePool is not. So an increment and a
decrement can run at the same time, and while the map has no entry for
the pool they take different monitors and the decrement's remove() can
erase the increment. The count then reaches zero while the pool is still
in use. Use ConcurrentHashMap.compute(), which is atomic for the key.
deleteStoragePool() decided whether the retried umount had worked from
the return of runSimpleBashScript(), which is null both when the command
fails, because runScript() discards the output on a non-zero exit, and
when it succeeds without printing anything. A failed umount was therefore
logged and returned as a success. Take the outcome from whether the path
is still a mount point, which also covers the pool having been unmounted
by something else in the meantime, and return false rather than throwing
when it is still mounted: deleteStoragePool() is called from finally
blocks, where a throw would discard the result of an operation that has
already succeeded.
Signed-off-by: Brad House <bhouse@nexthop.ai>1 parent 10037c8 commit ca1cfd5
2 files changed
Lines changed: 89 additions & 20 deletions
File tree
- plugins/hypervisors/kvm/src
- main/java/com/cloud/hypervisor/kvm/storage
- test/java/com/cloud/hypervisor/kvm/storage
Lines changed: 31 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
700 | 700 | | |
701 | 701 | | |
702 | 702 | | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
718 | 713 | | |
719 | 714 | | |
720 | 715 | | |
721 | 716 | | |
722 | 717 | | |
723 | | - | |
| 718 | + | |
724 | 719 | | |
725 | 720 | | |
726 | 721 | | |
727 | 722 | | |
728 | 723 | | |
729 | 724 | | |
730 | 725 | | |
731 | | - | |
| 726 | + | |
732 | 727 | | |
733 | 728 | | |
734 | 729 | | |
| |||
948 | 943 | | |
949 | 944 | | |
950 | 945 | | |
951 | | - | |
952 | | - | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
953 | 958 | | |
954 | 959 | | |
955 | 960 | | |
956 | 961 | | |
957 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
958 | 969 | | |
959 | 970 | | |
960 | 971 | | |
| |||
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| |||
176 | 185 | | |
177 | 186 | | |
178 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
179 | 237 | | |
0 commit comments