Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ssvm: delete temp directory while deleting entity download url#12562

Draft
shwstppr wants to merge 1 commit intoapache:4.20from
shwstppr:fix-ssvm-delentitydownloadurl
Draft

ssvm: delete temp directory while deleting entity download url#12562
shwstppr wants to merge 1 commit intoapache:4.20from
shwstppr:fix-ssvm-delentitydownloadurl

Conversation

@shwstppr
Copy link
Contributor

@shwstppr shwstppr commented Jan 31, 2026

Description

When expired entity URLs are cleaned up, orphan directories are left behind. This change tries to delete the base temporary directory while cleanup.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Download link for a volume expires and server calls DeleteEntityDownloadURLCommand

Before

2026-01-31T07:36:09,043 DEBUG [cloud.agent.Agent] (AgentRequest-Handler-5:[]) Request:Seq 4-7227995926952935435:  { Cmd , MgmtId: 90520731363323, via: 4, Ver: v1, Flags: 100111, [{"com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand":{"path":"volumes/2/4/97b241b4-4d31-469f-b4a4-a2fcab2606ff.qcow2","extractUrl":"http://172.120.1.2/userdata/88a99588-c0e0-4691-96c7-c7e6534d9fbe/t-dd.qcow2","type":"VOLUME","parentPath":"c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065","accountId":"0","wait":"0","bypassHostMaintenance":"false"}}] }
2026-01-31T07:36:09,044 DEBUG [cloud.agent.Agent] (AgentRequest-Handler-5:[]) Processing command: com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand
2026-01-31T07:36:09,044 DEBUG [storage.resource.NfsSecondaryStorageResource] (AgentRequest-Handler-5:[]) Executing command "DeleteEntityDownloadURLCommand" [{"path":"volumes/2/4/97b241b4-4d31-469f-b4a4-a2fcab2606ff.qcow2","extractUrl":"http://172.120.1.2/userdata/88a99588-c0e0-4691-96c7-c7e6534d9fbe/t-dd.qcow2","type":"VOLUME","parentPath":"c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065","accountId":0,"contextMap":{},"wait":0,"bypassHostMaintenance":false}].
2026-01-31T07:36:09,044 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) handleDeleteEntityDownloadURLCommand Path:volumes/2/4/97b241b4-4d31-469f-b4a4-a2fcab2606ff.qcow2 Type:VOLUME
2026-01-31T07:36:09,045 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Executing command [/bin/bash -c unlink /var/www/html/userdata/88a99588-c0e0-4691-96c7-c7e6534d9fbe/t-dd.qcow2 ].
2026-01-31T07:36:09,054 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Successfully executed process [5938] for command [/bin/bash -c unlink /var/www/html/userdata/88a99588-c0e0-4691-96c7-c7e6534d9fbe/t-dd.qcow2 ].
2026-01-31T07:36:09,054 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Deleted volume /mnt/SecStorage/c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065/volumes/2/4/97b241b4-4d31-469f-b4a4-a2fcab2606ff.qcow2
2026-01-31T07:36:09,055 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Executing command [/bin/bash -c rm -rf /mnt/SecStorage/c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065/volumes/2/4/97b241b4-4d31-469f-b4a4-a2fcab2606ff.qcow2 ].
2026-01-31T07:36:09,063 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Successfully executed process [5939] for command [/bin/bash -c rm -rf /mnt/SecStorage/c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065/volumes/2/4/97b241b4-4d31-469f-b4a4-a2fcab2606ff.qcow2 ].
2026-01-31T07:36:09,063 DEBUG [cloud.agent.Agent] (AgentRequest-Handler-5:[]) Seq 4-7227995926952935435:  { Ans: , MgmtId: 90520731363323, via: 4, Ver: v1, Flags: 110, [{"com.cloud.agent.api.Answer":{"result":"true","details":"","wait":"0","bypassHostMaintenance":"false"}}]


root@s-2-VM:/var/www/html/userdata# ls -lrt
total 20
drwxr-xr-x 2 www-data www-data 4096 Jan 31 06:08 9142b6e3-f6c6-48de-86b6-6003eb147d2c
drwxr-xr-x 2 www-data www-data 4096 Jan 31 06:10 85378760-8b68-4c60-81fc-11ddbe59fd85
drwxr-xr-x 2 www-data www-data 4096 Jan 31 06:28 a3276a6b-03aa-44d0-aeef-183da3b214c4
drwxr-xr-x 2 www-data www-data 4096 Jan 31 06:35 0cfcf0a0-58f8-471b-8864-9b8a2b754da3
drwxr-xr-x 2 www-data www-data 4096 Jan 31 07:36 88a99588-c0e0-4691-96c7-c7e6534d9fbe
root@s-2-VM:/var/www/html/userdata# ls -lrt 88a99588-c0e0-4691-96c7-c7e6534d9fbe
total 0

After

2026-01-31T19:38:40,034 DEBUG [cloud.agent.Agent] (AgentRequest-Handler-4:[]) Request:Seq 4-3413728517546836680:  { Cmd , MgmtId: 90520731363323, via: 4, Ver: v1, Flags: 100111, [{"com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand":{"path":"volumes/2/4/b5c47a87-6193-4d78-ab1f-1ade1422c296.qcow2","extractUrl":"http://172.120.1.2/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5/t-dd.qcow2","type":"VOLUME","parentPath":"c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065","accountId":"0","wait":"0","bypassHostMaintenance":"false"}}] }
2026-01-31T19:38:40,035 DEBUG [cloud.agent.Agent] (AgentRequest-Handler-4:[]) Processing command: com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand
2026-01-31T19:38:40,035 DEBUG [storage.resource.NfsSecondaryStorageResource] (AgentRequest-Handler-4:[]) Executing command "DeleteEntityDownloadURLCommand" [{"path":"volumes/2/4/b5c47a87-6193-4d78-ab1f-1ade1422c296.qcow2","extractUrl":"http://172.120.1.2/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5/t-dd.qcow2","type":"VOLUME","parentPath":"c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065","accountId":0,"contextMap":{},"wait":0,"bypassHostMaintenance":false}].
2026-01-31T19:38:40,035 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) handleDeleteEntityDownloadURLCommand Path:volumes/2/4/b5c47a87-6193-4d78-ab1f-1ade1422c296.qcow2 Type:VOLUME
2026-01-31T19:38:40,036 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) Executing command [/bin/bash -c unlink /var/www/html/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5/t-dd.qcow2 ].
2026-01-31T19:38:40,039 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) Successfully executed process [8782] for command [/bin/bash -c unlink /var/www/html/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5/t-dd.qcow2 ].
2026-01-31T19:38:40,039 INFO  [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) Deleting symlink root directory: d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5 for http://172.120.1.2/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5/t-dd.qcow2
2026-01-31T19:38:40,039 DEBUG [cloud.utils.FileUtil] (AgentRequest-Handler-4:[]) Deleting path: /var/www/html/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5
2026-01-31T19:38:40,040 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) Deleted volume /mnt/SecStorage/c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065/volumes/2/4/b5c47a87-6193-4d78-ab1f-1ade1422c296.qcow2
2026-01-31T19:38:40,040 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) Executing command [/bin/bash -c rm -rf /mnt/SecStorage/c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065/volumes/2/4/b5c47a87-6193-4d78-ab1f-1ade1422c296.qcow2 ].
2026-01-31T19:38:40,048 DEBUG [storage.template.UploadManagerImpl] (AgentRequest-Handler-4:[]) Successfully executed process [8783] for command [/bin/bash -c rm -rf /mnt/SecStorage/c794fe3b-bedb-3e8e-a5c6-c5a2b28a2065/volumes/2/4/b5c47a87-6193-4d78-ab1f-1ade1422c296.qcow2 ].
2026-01-31T19:38:40,049 DEBUG [cloud.agent.Agent] (AgentRequest-Handler-4:[]) Seq 4-3413728517546836680:  { Ans: , MgmtId: 90520731363323, via: 4, Ver: v1, Flags: 110, [{"com.cloud.agent.api.Answer":{"result":"true","details":"","wait":"0","bypassHostMaintenance":"false"}}]


root@s-2-VM:~# ls -lrt /var/www/html/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5
ls: cannot access '/var/www/html/userdata/d3a9b2ea-b212-4480-bca4-0dc1d9d3e6a5': No such file or directory

How did you try to break this feature and the system with this change?

url

When expired entity URLs are cleaned up, orphan directories are left
behind. This change tries to delete the base temporary directory while
cleanup.

Signed-off-by: Abhishek Kumar <[email protected]>
@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

❌ Patch coverage is 31.42857% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.26%. Comparing base (6bed3d4) to head (eef3e49).
⚠️ Report is 2 commits behind head on 4.20.

Files with missing lines Patch % Lines
...cloudstack/storage/template/UploadManagerImpl.java 47.82% 8 Missing and 4 partials ⚠️
utils/src/main/java/com/cloud/utils/FileUtil.java 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #12562   +/-   ##
=========================================
  Coverage     16.26%   16.26%           
- Complexity    13426    13432    +6     
=========================================
  Files          5660     5660           
  Lines        499949   499982   +33     
  Branches      60704    60712    +8     
=========================================
+ Hits          81296    81332   +36     
+ Misses       409581   409572    -9     
- Partials       9072     9078    +6     
Flag Coverage Δ
uitests 4.16% <ø> (ø)
unittests 17.11% <31.42%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shwstppr
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16663

@shwstppr
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

@shwstppr a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@shwstppr shwstppr marked this pull request as ready for review January 31, 2026 19:10
@blueorangutan
Copy link

[SF] Trillian test result (tid-15346)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 49207 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12562-t15346-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@abh1sar abh1sar added this to the 4.20.3 milestone Feb 1, 2026
Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

Copy link
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@shwstppr shwstppr changed the title secondary-storage: delete temp directory while deleting entity download url ssvm: delete temp directory while deleting entity download url Feb 2, 2026
@RosiKyu RosiKyu self-assigned this Feb 3, 2026
Copy link
Collaborator

@RosiKyu RosiKyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have identified an issue in the PR:

Test Steps

  1. Configure short expiration intervals:
    • extract.url.expiration.interval = 120 seconds
    • extract.url.cleanup.interval = 60 seconds
  2. Restart management server for config changes to take effect
  3. Create and attach a DATA volume to a VM
  4. Stop the VM
  5. Extract the volume to generate a download URL
  6. Verify UUID directory is created in /var/www/html/userdata/
  7. Wait for URL expiration and cleanup (~3 minutes)
  8. Check if symlink and UUID directory are deleted

Expected Result:

  • The symlink /var/www/html/userdata/<UUID>/test-vol.qcow2 should be deleted
  • The UUID directory /var/www/html/userdata/<UUID>/ should be deleted
  • SSVM logs should show: "Deleting symlink root directory: for "

Actual Result:

  • FAIL - The unlink command failed due to incorrect path construction
  • The unlink tried /var/www/html/userdata/test-vol.qcow2 instead of /var/www/html/userdata/7357f278-a8be-4c93-a43a-4679f6f220ab/test-vol.qcow2
  • Since unlink failed, the deleteEntitySymlinkRootPathIfNeeded method never executed
  • Both the symlink AND UUID directory remain orphaned

Root Cause:
There seems to be an issue in the path extraction logic:

String linkPath = extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1);

This extracts only the filename (test-vol.qcow2) instead of the full relative path (7357f278-a8be-4c93-a43a-4679f6f220ab/test-vol.qcow2).

Test Evidence:

  • Configuration changes:
(localcloud) 🐱 > update configuration name=extract.url.expiration.interval value=120
{
  "configuration": {
    "category": "Advanced",
    "component": "management-server",
    "defaultvalue": "14400",
    "description": "The life of an extract URL after which it is deleted ",
    "displaytext": "Extract url expiration interval",
    "group": "Management Server",
    "isdynamic": false,
    "name": "extract.url.expiration.interval",
    "subgroup": "Limits",
    "type": "Number",
    "value": "120"
  }
}
(localcloud) 🐱 > update configuration name=extract.url.cleanup.interval value=60
{
  "configuration": {
    "category": "Advanced",
    "component": "management-server",
    "defaultvalue": "7200",
    "description": "The interval (in seconds) to wait before cleaning up the extract URL's ",
    "displaytext": "Extract url cleanup interval",
    "group": "Management Server",
    "isdynamic": false,
    "name": "extract.url.cleanup.interval",
    "subgroup": "Limits",
    "type": "Number",
    "value": "60"
  }
}
  • Volume creation and attachment:
(localcloud) 🐱 > attach volume id=baff5910-2d21-4542-b2ee-6ee34cc6be73 virtualmachineid=90e7a447-1df2-4e75-8afc-ba807548ca42
{
  "volume": {
    "account": "admin",
    "attached": "2026-02-04T11:45:14+0000",
    "clusterid": "6f535ef8-be7f-4a5a-b87c-c589d427341b",
    "clustername": "p1-c1",
    "created": "2026-02-04T11:44:36+0000",
    "deleteprotection": false,
    "destroyed": false,
    "deviceid": 1,
    "diskioread": 0,
    "diskiowrite": 0,
    "diskkbsread": 0,
    "diskkbswrite": 0,
    "diskofferingdisplaytext": "Small Disk, 5 GB",
    "diskofferingid": "4391aa82-7d9b-4e3c-9f16-9a4506f58c68",
    "diskofferingname": "Small",
    "displayvolume": true,
    "domain": "ROOT",
    "domainid": "ae560d02-01b6-11f1-9894-1e003100046f",
    "domainpath": "/",
    "hasannotations": false,
    "hypervisor": "KVM",
    "id": "baff5910-2d21-4542-b2ee-6ee34cc6be73",
    "isextractable": true,
    "jobid": "1c3936a5-d499-45de-a2d7-0495df953d8e",
    "jobstatus": 0,
    "name": "test-vol",
    "path": "baff5910-2d21-4542-b2ee-6ee34cc6be73",
    "podid": "09b0e9f6-5957-4f76-95ed-00764e23ed02",
    "podname": "Pod1",
    "provisioningtype": "thin",
    "quiescevm": false,
    "size": 5368709120,
    "state": "Ready",
    "storage": "ref-trl-10829-k-Mol9-rositsa-kyuchukova-kvm-pri2",
    "storageid": "234e7aff-ac28-3150-8891-497563810b52",
    "storagetype": "shared",
    "supportsstoragesnapshot": false,
    "tags": [],
    "type": "DATADISK",
    "virtualmachineid": "90e7a447-1df2-4e75-8afc-ba807548ca42",
    "vmdisplayname": "VM-90e7a447-1df2-4e75-8afc-ba807548ca42",
    "vmname": "VM-90e7a447-1df2-4e75-8afc-ba807548ca42",
    "vmstate": "Running",
    "vmtype": "User",
    "zoneid": "7bc0e169-5133-42ba-8e5f-ea6f5db39ee8",
    "zonename": "ref-trl-10829-k-Mol9-rositsa-kyuchukova"
  }
}
  • Volume extraction:
(localcloud) 🐱 > extract volume id=baff5910-2d21-4542-b2ee-6ee34cc6be73 mode=HTTP_DOWNLOAD zoneid=7bc0e169-5133-42ba-8e5f-ea6f5db39ee8
{
  "volume": {
    "accountid": "ec2bc4c5-01b6-11f1-9894-1e003100046f",
    "extractMode": "HTTP_DOWNLOAD",
    "id": "baff5910-2d21-4542-b2ee-6ee34cc6be73",
    "name": "test-vol",
    "state": "DOWNLOAD_URL_CREATED",
    "url": "http://10.0.55.122/userdata/7357f278-a8be-4c93-a43a-4679f6f220ab/test-vol.qcow2",
    "zoneid": "7bc0e169-5133-42ba-8e5f-ea6f5db39ee8",
    "zonename": "ref-trl-10829-k-Mol9-rositsa-kyuchukova"
  }
}
  • UUID directory and symlink created:
root@s-3-VM:~# ls -la /var/www/html/userdata/
total 16
drwxr-xr-x 3 www-data www-data 4096 Feb  4 11:52 .
drwxr-xr-x 5 www-data www-data 4096 Feb  4 11:05 ..
drwxr-xr-x 2 www-data www-data 4096 Feb  4 11:52 7357f278-a8be-4c93-a43a-4679f6f220ab
-rwxr-xr-x 1 www-data www-data   17 Jan 31 10:47 .htaccess

root@s-3-VM:~# ls -la /var/www/html/userdata/7357f278-a8be-4c93-a43a-4679f6f220ab/
total 12
drwxr-xr-x 2 www-data www-data 4096 Feb  4 11:52 .
drwxr-xr-x 3 www-data www-data 4096 Feb  4 11:52 ..
lrwxrwxrwx 1 root     root      107 Feb  4 11:52 test-vol.qcow2 -> /mnt/SecStorage/af60251b-b7ae-3132-a37a-9ba1f92e3118/volumes/2/5/3fb4a0d4-4d0d-489d-bb5f-77a85aa62fcc.qcow2
  • Management Server log showing correct extractUrl sent:
[root@ref-trl-10829-k-Mol9-rositsa-kyuchukova-mgmt1 ~]# grep -i "DeleteEntityDownloadURL" /var/log/cloudstack/management/management-server.log | tail -20
2026-02-04 11:55:06,720 DEBUG [c.c.h.o.r.Ovm3HypervisorGuru] (StorageManager-Scavenger-1:[]) (logid:) getCommandHostDelegation: class com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand
2026-02-04 11:55:06,721 DEBUG [c.c.a.m.ClusteredAgentManagerImpl] (StorageManager-Scavenger-1:[]) (logid:) Wait time setting on com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand is 1800 seconds
2026-02-04 11:55:06,722 DEBUG [c.c.a.t.Request] (StorageManager-Scavenger-1:[]) (logid:) Seq 4-4037477065937649683: Sending  { Cmd , MgmtId: 32986170917999, via: 4(s-3-VM), Ver: v1, Flags: 100111, [{"com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand":{"path":"volumes/2/5/3fb4a0d4-4d0d-489d-bb5f-77a85aa62fcc.qcow2","extractUrl":"http://10.0.55.122/userdata/7357f278-a8be-4c93-a43a-4679f6f220ab/test-vol.qcow2","type":"VOLUME","parentPath":"af60251b-b7ae-3132-a37a-9ba1f92e3118","accountId":"0","wait":"0","bypassHostMaintenance":"false"}}] }
  • SSVM log showing unlink failure due to incorrect path:
root@s-3-VM:~# grep -A5 -B5 "handleDeleteEntityDownloadURLCommand" /var/log/cloud.log
2026-02-04T11:55:06,734 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) handleDeleteEntityDownloadURLCommand Path:volumes/2/5/3fb4a0d4-4d0d-489d-bb5f-77a85aa62fcc.qcow2 Type:VOLUME
2026-02-04T11:55:06,756 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Execution of process [4146] for command [/bin/bash -c unlink /var/www/html/userdata/test-vol.qcow2 ] failed.
2026-02-04T11:55:06,757 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Process [4146] for command [/bin/bash -c unlink /var/www/html/userdata/test-vol.qcow2 ] encountered the error: [unlink: cannot unlink '/var/www/html/userdata/test-vol.qcow2': No such file or directory].
2026-02-04T11:55:06,757 WARN  [storage.template.UploadManagerImpl] (AgentRequest-Handler-5:[]) Error in deleting symlink :unlink: cannot unlink '/var/www/html/userdata/test-vol.qcow2': No such file or directory
  • After cleanup interval - UUID directory still exists (orphaned):
root@s-3-VM:~# ls -la /var/www/html/userdata/
total 16
drwxr-xr-x 3 www-data www-data 4096 Feb  4 11:52 .
drwxr-xr-x 5 www-data www-data 4096 Feb  4 11:05 ..
drwxr-xr-x 2 www-data www-data 4096 Feb  4 11:52 7357f278-a8be-4c93-a43a-4679f6f220ab
-rwxr-xr-x 1 www-data www-data   17 Jan 31 10:47 .htaccess
  • Verified PR code is deployed (method exists in JAR):
root@s-3-VM:/usr/local/cloud/systemvm# unzip -p cloud-secondary-storage-4.20.3.0-SNAPSHOT.jar | grep -a "deleteEntitySymlinkRootPathIfNeeded"
extractUrlkl#deleteEntitySymlinkRootPathIfNeededQ(Lcom/cloud/agent/api/storage/DeleteEntityDownloadURLCommand;Ljava/lang/String;)V...

root@s-3-VM:/usr/local/cloud/systemvm# unzip -p cloud-secondary-storage-4.20.3.0-SNAPSHOT.jar | grep -a "Deleting symlink root directory"
...Deleting symlink root directory: {} for {}...

The path extraction logic needs to be fixed. The code should extract everything after /userdata/ from the extractUrl, not just the filename after the last /.

@shwstppr shwstppr marked this pull request as draft February 5, 2026 05:38
@shwstppr
Copy link
Contributor Author

shwstppr commented Feb 5, 2026

Thanks @RosiKyu . I was maybe working with main branch env for testing and didn't face the problem.
I'll look into it and add a fix

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request aims to fix a bug where orphan temporary directories are left behind when expired entity download URLs are cleaned up in the SSVM (Secondary Storage VM). The fix adds logic to delete the UUID-named root directory that contained the symlink after the symlink itself is removed.

Changes:

  • Added a new deleteRecursively method to FileUtil.java for recursive directory deletion using the modern NIO.2 Path API
  • Modified UploadManagerImpl.java to call a new cleanup method after symlink deletion
  • Added unit tests to verify the UUID directory cleanup logic works correctly

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
utils/src/main/java/com/cloud/utils/FileUtil.java Adds new deleteRecursively method to support recursive deletion of directories and their contents
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadManagerImpl.java Introduces BASE_EXTRACT_DIR constant and deleteEntitySymlinkRootPathIfNeeded method to clean up orphan UUID directories after symlink deletion
services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/template/UploadManagerImplTest.java Adds unit tests for the new cleanup logic covering empty paths, invalid UUIDs, and valid UUID scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +338 to +346
String linkPath = extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1);
command.add("unlink " + BASE_EXTRACT_DIR + linkPath);
result = command.execute();
if (result != null) {
// FIXME - Ideally should bail out if you can't delete symlink. Not doing it right now.
// This is because the ssvm might already be destroyed and the symlinks do not exist.
logger.warn("Error in deleting symlink :" + result);
} else {
deleteEntitySymlinkRootPathIfNeeded(cmd, linkPath);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linkPath extraction logic is incorrect. Given extractUrl format http://host/userdata/UUID/filename, using lastIndexOf(File.separator) will find the last "/" before the filename, resulting in linkPath being just "filename" instead of "UUID/filename". This breaks the deleteEntitySymlinkRootPathIfNeeded method which expects linkPath to contain the UUID directory name as the first path component. The code should extract everything after "/userdata/" using extractUrl.substring(extractUrl.indexOf("/userdata/") + "/userdata/".length()) instead, with proper validation that "/userdata/" exists in the URL.

Suggested change
String linkPath = extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1);
command.add("unlink " + BASE_EXTRACT_DIR + linkPath);
result = command.execute();
if (result != null) {
// FIXME - Ideally should bail out if you can't delete symlink. Not doing it right now.
// This is because the ssvm might already be destroyed and the symlinks do not exist.
logger.warn("Error in deleting symlink :" + result);
} else {
deleteEntitySymlinkRootPathIfNeeded(cmd, linkPath);
final String userDataSegment = "/userdata/";
int userDataIndex = extractUrl.indexOf(userDataSegment);
if (userDataIndex == -1) {
logger.warn("Extract URL does not contain expected segment '/userdata/': " + extractUrl);
} else {
String linkPath = extractUrl.substring(userDataIndex + userDataSegment.length());
if (StringUtils.isBlank(linkPath)) {
logger.warn("Extract URL does not contain a valid link path after '/userdata/': " + extractUrl);
} else {
command.add("unlink " + BASE_EXTRACT_DIR + linkPath);
result = command.execute();
if (result != null) {
// FIXME - Ideally should bail out if you can't delete symlink. Not doing it right now.
// This is because the ssvm might already be destroyed and the symlinks do not exist.
logger.warn("Error in deleting symlink :" + result);
} else {
deleteEntitySymlinkRootPathIfNeeded(cmd, linkPath);
}
}

Copilot uses AI. Check for mistakes.

public static boolean deleteRecursively(Path path) throws IOException {
LOGGER.debug("Deleting path: {}", path);
if (Files.isDirectory(path)) {
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteRecursively method may behave unexpectedly when encountering symbolic links to directories. Files.isDirectory(path) follows symlinks by default, which means if a symlink points to a directory, this method will recursively delete the contents of the target directory instead of just removing the symlink. Consider using Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS) to treat symlinks as files and delete them directly without following them.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +77
@Test
public void deletesSymlinkRootDirectoryWhenValidUuid() {
String validLinkPath = "123e4567-e89b-12d3-a456-426614174000/file";
uploadManager.deleteEntitySymlinkRootPathIfNeeded(mock(DeleteEntityDownloadURLCommand.class), validLinkPath);
fileUtilMock.verify(() -> FileUtil.deleteRecursively(any(Path.class)), times(1));
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case for linkPath that contains only a UUID without a filename (e.g., "123e4567-e89b-12d3-a456-426614174000"). While this may not occur in normal operation given the URL format, it's a valid edge case that should be handled correctly.

Copilot uses AI. Check for mistakes.
return;
}
logger.info("Deleting symlink root directory: {} for {}", rootDir, cmd.getExtractUrl());
Path rootDirPath = Path.of(BASE_EXTRACT_DIR + rootDir);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using Path.of(BASE_EXTRACT_DIR, rootDir) instead of string concatenation for path construction. This is more robust and handles path separators correctly across different operating systems, even if BASE_EXTRACT_DIR is modified in the future to not include a trailing separator.

Suggested change
Path rootDirPath = Path.of(BASE_EXTRACT_DIR + rootDir);
Path rootDirPath = Path.of(BASE_EXTRACT_DIR, rootDir);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants