Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udiskslinuxdriveata: Respect ID_ATA_SMART_ACCESS=none #1316

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/man/udisks.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>ID_ATA_SMART_ACCESS</option></term>
<listitem>
<para>
Override the access method for SMART data retrieval. Valid values include: <literal>sat16</literal>, <literal>sat12</literal>, <literal>linux-ide</literal>, <literal>sunplus</literal>, <literal>jmicron</literal>, <literal>none</literal> and <literal>auto</literal> (default).
Specify <literal>none</literal> to avoid any I/O, in such a case the <link linkend="gdbus-property-org-freedesktop-UDisks2-Drive-Ata.SmartUpdated">SmartUpdated</link> property will always equal to <quote>0</quote>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

Expand Down
16 changes: 12 additions & 4 deletions src/udiskslinuxdriveata.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive,
guchar count;
gboolean noio = FALSE;
gboolean awake;
const gchar *smart_access;

smart_access = g_udev_device_get_property (device->udev_device, "ID_ATA_SMART_ACCESS");
if (g_strcmp0 (smart_access, "none") == 0)
{
/* FIXME: find a better error code */
g_set_error_literal (error, UDISKS_ERROR, UDISKS_ERROR_CANCELLED,
"Refusing any I/O due to ID_ATA_SMART_ACCESS being set to 'none'");
goto out;
}

if (drive->standby_enabled)
noio = update_io_stats (drive, device);
Expand All @@ -530,10 +540,8 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive,
/* don't wake up disk unless specically asked to */
if (nowakeup && (!awake || noio))
{
g_set_error (error,
UDISKS_ERROR,
UDISKS_ERROR_WOULD_WAKEUP,
"Disk is in sleep mode and the nowakeup option was passed");
g_set_error_literal (error, UDISKS_ERROR, UDISKS_ERROR_WOULD_WAKEUP,
"Disk is in sleep mode and the nowakeup option was passed");
goto out_io;
}

Expand Down
14 changes: 10 additions & 4 deletions src/udiskslinuxdriveobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,23 +1134,29 @@ udisks_linux_drive_object_housekeeping (UDisksLinuxDriveObject *object,
cancellable,
&local_error))
{
if (nowakeup && (local_error->domain == UDISKS_ERROR &&
local_error->code == UDISKS_ERROR_WOULD_WAKEUP))
if (nowakeup && g_error_matches (local_error, UDISKS_ERROR, UDISKS_ERROR_WOULD_WAKEUP))
{
udisks_info ("Drive %s is in a sleep state",
g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
g_clear_error (&local_error);
}
else if (nowakeup && (local_error->domain == UDISKS_ERROR &&
local_error->code == UDISKS_ERROR_DEVICE_BUSY))
else if (nowakeup && g_error_matches (local_error, UDISKS_ERROR, UDISKS_ERROR_DEVICE_BUSY))
{
/* typically because a "secure erase" operation is pending */
udisks_info ("Drive %s is busy",
g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
g_clear_error (&local_error);
}
else if (g_error_matches (local_error, UDISKS_ERROR, UDISKS_ERROR_CANCELLED))
{
/* typically because the device indicates it refuses any I/O intentionally */
udisks_info ("Drive %s is refusing any I/O intentionally",
g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
g_clear_error (&local_error);
}
else
{
/* all other errors are reported within the BD_SMART_ERROR domain */
g_propagate_prefixed_error (error, local_error, "Error updating SMART data: ");
goto out;
}
Expand Down