udisksctl: Add drive-set-standby command#1448
udisksctl: Add drive-set-standby command#1448xarinatan wants to merge 3 commits intostoraged-project:masterfrom
Conversation
tbzatek
left a comment
There was a problem hiding this comment.
Thanks for your contribution and sorry it took it so long to reply.
LLM WARNING
I used Cursor (so LLMs were involved, Gemini 3 Pro and Anthropic Opus 4.5 specifically)
We've just published new contributing guidelines proposal in #1458, please make sure to read it (and feel free to comment!). In general, please just add the commit message annotation about the specific LLM used.
unless I run something like hdparm -S XX /dev/sdX, which of course is not persistent.
Many distributions provide an init script or system service to modify drive settings at startup, see e.g. https://wiki.gentoo.org/wiki/Hdparm. Of course, this conflicts with the UDisks approach and vice versa.
If this gets implemented it would also make it easier to integrate it into KDE tooling for example.
Desktop environments should never call udisksctl which is just a wrapper around D-Bus calls anyway, but rather reach out through D-Bus directly, e.g. through generated bindings.
Anyway, very nice, a useful addition! We don't often provide all functionality in udisksctl by default and features are typically added on demand, like this one.
|
Jenkins, ok to test. |
|
ping @xarinatan - still interested to finish this? |
|
Oh! my bad, I think I filtered away Github notifications in my inbox a little too thoroughly, so I completely missed this. Thank you for considering the PR, I will take a look at the needed changes and let you know asap. And thanks for explaining; I know about setting up startup scripts, but personally using dbus to actually update a config seemed much cleaner. I figured that dbus is the normal way, since that's what Gnome appears to do, but if you have some other desktop and you want to be able to send these Dbus commands, having udiskctl send that dbus message for you is neat. |
|
I'm seeing some things in the failures that I'm not sure are on me, the tests, or the environment, hence my push to see if this clears up the CI pipeline. I saw that #1505 added one of the failing tests to the skip list and #1500 had a bunch of test cleanups, so now that we're back on latest it should be cleaner, but let's see how it goes. .. as I was writing this I see that fedora44 is not passing, but I'm unsure if this is my fault because it's testing The error there is: By the way, regarding the Contributors guide compliance, I assume I should just amend the git commit with the correct attribution, right? If not let me know. edit: the f_43 test also seems to have a failure I don't think is related to my code, edit 2: I only just saw your actual comments in the code itself, I'll also make sure I'll address those before moving forward. First some sleep though. |
Add a new 'drive-set-standby' command to udisksctl that allows users to set the persistent standby timeout for ATA drives via the command line. This exposes the existing SetConfiguration D-Bus method which was previously only accessible programmatically. The configuration is stored in /etc/udisks2/<DRIVE_ID>.conf and applied automatically on drive connection (startup, hotplug, resume). The command accepts: --object-path/-p: Specify drive by D-Bus object path --block-device/-b: Specify drive by device file (e.g., /dev/sda) --timeout/-t: Standby timeout value 0-255 (required) --no-user-interaction: Skip polkit authentication prompts This provides a user-friendly alternative to hdparm -S that persists across reboots without requiring custom scripts or systemd services. Co-Authored-By: Gemini 3.0 Pro <[email protected]> Co-Authored-By: Claude Opus 4.5 <[email protected]>
…-drive-set-standby
…erface Address review feedback on PR storaged-project#1448: gate both the tab-completion candidates and the runtime execution path of drive-set-standby on the presence of the org.freedesktop.UDisks2.Drive.Ata interface, since the command's only effect is on ATA drives. Previously the command would silently no-op on non-ATA drives and tab-complete drives where it had no effect. The new behavior mirrors the existing pattern used by the drive-smart-* commands. Co-Authored-By: Claude Opus 4.7 <[email protected]>
01025ac to
23a9279
Compare
|
Implemented the two requested changes! Also added a small if() clause to error out with I also amended the first commit (hence the force push), the alternative would be to add a separate commit and squash on merge, but if I got your original "add the commit message annotation" message right you intended to have the commit amended. The review changes have been added in a separate commit (attributed/co-authored-by to claude opus 4.7) |
tbzatek
left a comment
There was a problem hiding this comment.
One more minor leak found. Can you also squash the commits with no merge record please?
I'm seeing some things in the failures that I'm not sure are on me
Oh don't worry about that, it's unrelated. Our test are never 100% stable.
By the way, regarding the Contributors guide compliance, I assume I should just amend the git commit with the correct attribution, right? If not let me know.
Correct, it's about the annotation. Looks good in its current state!
| g_printerr ("Error looking up object for device %s\n", opt_set_standby_device); | ||
| goto out; | ||
| } | ||
| drive = udisks_client_get_drive_for_block (client, udisks_object_peek_block (block_object)); |
There was a problem hiding this comment.
Memory leak - drive needs to be unref'ed in the out section.
Hello there!
Note: This started as an issue I was going to file, but then I realized I might as well try to actually make a patch for it, which I did, so I went ahead and turned the issue into a PR instead.
TL;DR: Can we implement a
drive-set-standby(or alike) subcommand in udiskctl?Long version:
I ran into the issue of wanting to set the standby timeout for my newly purchased harddisk, and like many before me, ran into the issue that the disk keeps running, unless I run something like
hdparm -S XX /dev/sdX, which of course is not persistent. Then, as many before me probably also did, I realized I only have a few options there; Write a udev rule myself, or use some tool like Gnome Disks (which seems weird since I run KDE).It got me thinking: why doesn't udiskctl support this? The udisks dbus backend seems to have the support already (this is what Gnome Disks uses), so it just has to be plumbed through to the udiskctl utility, which would help many people and other projects to write simple automation for it that doesn't directly mess with udev rules. If this gets implemented it would also make it easier to integrate it into KDE tooling for example.
LLM WARNING
I used Cursor (so LLMs were involved, Gemini 3 Pro and Anthropic Opus 4.5 specifically) to quickly understand the codebase and whip up a patch for this. I did not write, but did thoroughly read the code (it seems to catch errors properly and handle all cases) and locally verified it to work on my WD Red 18TB drive. Feel free to only take it as loose inspiration and create your own version from scratch; I merely want to help.
See below for the description of the patch itself:
Add a new 'drive-set-standby' command to udisksctl that allows users to set the persistent standby timeout for ATA drives via the command line.
This exposes the existing SetConfiguration D-Bus method which was previously only accessible programmatically. The configuration is stored in /etc/udisks2/<DRIVE_ID>.conf and applied automatically on drive connection (startup, hotplug, resume).
The command accepts:
--object-path/-p: Specify drive by D-Bus object path
--block-device/-b: Specify drive by device file (e.g., /dev/sda)
--timeout/-t: Standby timeout value 0-255 (required)
--no-user-interaction: Skip polkit authentication prompts