You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KVM: Fix storage pool refcount leak on creation failure - #14694
This PR fixes a storage pool reference-count leak in createStoragePoolLocked().
When the reference count is incremented for a secondary storage pool, subsequent failures in checkNetfsStoragePoolMounted() or getStoragePool() can leave the reference count incremented because the existing exception handling only catches LibvirtException.
Solution
Track whether the storage pool reference count was successfully incremented.
Track whether the operation completed successfully.
Use a finally block to decrement the reference count if the operation fails after the increment.
Preserve existing LibvirtException handling.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Bug Severity
Minor
How Has This Been Tested?
Added testCreateStoragePoolDecrementsRefCountWhenGetStoragePoolFails() to verify that the reference count is decremented when getStoragePool() throws a CloudRuntimeException.
Thanks for picking this up. The fix itself looks right to me: decrementing in a finally covers the CloudRuntimeException from getStoragePool(), and gating it on refCountIncremented also stops the old catch from decrementing a primary pool that was never counted.
One problem: this depends on #14189 but targets 4.22 without it. createStoragePoolLocked only exists in #14189, and incStoragePoolRefCount/decStoragePoolRefCount are private on 4.22 (#14189 makes them protected). Applied to 4.22 alone, LibvirtStorageAdaptorTest doesn't compile:
LibvirtStorageAdaptorTest.java:[197,19] error: cannot find symbol
symbol: method createStoragePoolLocked(String,String,int,String,<null>,StoragePoolType,<null>,boolean)
LibvirtStorageAdaptorTest.java:[210,35] error: incStoragePoolRefCount(String) has private access in LibvirtStorageAdaptor
LibvirtStorageAdaptorTest.java:[211,35] error: decStoragePoolRefCount(String) has private access in LibvirtStorageAdaptor
On top of #14189, the main change applies cleanly but the test file conflicts with the tests #14189 adds there.
Two ways to go: rebase this onto 4.22 once #14189 merges, which is the simplest; or make it standalone now by testing through the public createStoragePool(...) and checking the ref count through storagePoolRefCounts rather than spying on the private methods. Either works for me.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a storage pool reference-count leak in
createStoragePoolLocked().When the reference count is incremented for a secondary storage pool, subsequent failures in
checkNetfsStoragePoolMounted()orgetStoragePool()can leave the reference count incremented because the existing exception handling only catchesLibvirtException.Solution
finallyblock to decrement the reference count if the operation fails after the increment.LibvirtExceptionhandling.Types of changes
Bug Severity
How Has This Been Tested?
Added
testCreateStoragePoolDecrementsRefCountWhenGetStoragePoolFails()to verify that the reference count is decremented whengetStoragePool()throws aCloudRuntimeException.git diff --check: Passed.Related: #14189