Skip to content

Commit

Permalink
Merge pull request #1316 from tbzatek/smart-3
Browse files Browse the repository at this point in the history
udiskslinuxdriveata: Respect ID_ATA_SMART_ACCESS=none
  • Loading branch information
tbzatek authored Sep 30, 2024
2 parents acb473b + c63dee2 commit 85d6fac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
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

0 comments on commit 85d6fac

Please sign in to comment.