Skip to content

Commit

Permalink
udiskslinuxdriveata: Port to libblockdev SMART plugin
Browse files Browse the repository at this point in the history
Also, make the dependency on libblockdev-smart optional,
the D-Bus API is ready for that. If unavailable, the
org.freedesktop.UDisks2.Drive.Ata.SmartUpdated property
will just stay zero forever.
  • Loading branch information
tbzatek committed Jan 31, 2024
1 parent 5f92cc9 commit beb434a
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 406 deletions.
27 changes: 23 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ if test "x$enable_daemon" = "xyes"; then
AC_SUBST(BLOCKDEV_CFLAGS)
AC_SUBST(BLOCKDEV_LIBS)

PKG_CHECK_MODULES(LIBATASMART, [libatasmart >= 0.17])
AC_SUBST(LIBATASMART_CFLAGS)
AC_SUBST(LIBATASMART_LIBS)

PKG_CHECK_MODULES(LIBBLKID, [blkid])
AC_SUBST(LIBBLKID_CFLAGS)
AC_SUBST(LIBBLKID_LIBS)
Expand Down Expand Up @@ -544,6 +540,28 @@ if test "x$enable_daemon" = "xyes"; then
if test "x$have_nvme" = "xno"; then
AC_MSG_ERROR([BLOCKDEV NVMe support requested but header or library not found])
fi

# libblockdev smart
have_smart=no
AC_ARG_ENABLE(smart, AS_HELP_STRING([--disable-smart], [disable ATA SMART support]))
if test "x$enable_smart" != "xno"; then
SAVE_CFLAGS=$CFLAGS
SAVE_LDFLAGS=$LDFLAGS

CFLAGS="$GLIB_CFLAGS"
LDFLAGS="$GLIB_LIBS"
AC_MSG_CHECKING([libblockdev-smart presence])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <blockdev/smart.h>]], [[]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_SMART, 1, [Define, if libblockdev-smart is available])
have_smart=yes],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([libblockdev-smart requested but not found.])
have_smart=no])
CFLAGS=$SAVE_CFLAGS
LDFLAGS=$SAVE_LDFLAGS
fi
AM_CONDITIONAL(HAVE_SMART, [test "$have_smart" = "yes"])
fi


Expand Down Expand Up @@ -674,6 +692,7 @@ echo "
Enable daemon: ${enable_daemon}
Enable modules: ${enable_modules_info}

ATA SMART support: ${have_smart}
BTRFS module: ${have_btrfs}
iSCSI module: ${have_iscsi}${have_libiscsi_session_info_msg}
LVM2 module: ${have_lvm2}
Expand Down
14 changes: 9 additions & 5 deletions data/org.freedesktop.UDisks2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,13 @@
<literal>org.freedesktop.UDisks2.Error.WouldWakeup</literal> is
returned.
The option @atasmart_blob can be used to inject libatasmart
compatible blobs for testing how clients react to different
kinds of SMART data. This option may be removed in the future
without it being considered an ABI break.
The option @atasmart_blob (of type 's' representing a path to
the blob file) can be used to inject libatasmart-compatible
blobs for testing how clients react to different kinds of SMART
data. Only valid when backed with the
<literal>libblockdev_libatasmat</literal> plugin. This option
may be removed in the future without it being considered an ABI
break. Deprecated since 2.11.0.
-->
<method name="SmartUpdate">
<arg name="options" direction="in" type="a{sv}"/>
Expand Down Expand Up @@ -946,7 +949,8 @@
Starts a SMART selftest. The @type parameter is for the type
of test to start - valid values are <literal>short</literal>,
<literal>extended</literal> and <literal>conveyance</literal>.
<literal>extended</literal>, <literal>conveyance</literal> and
<literal>offline</literal> (since 2.11.0).
Note that the method returns immediately after the test has
been started successfully.
Expand Down
7 changes: 3 additions & 4 deletions packaging/udisks2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
%global gobject_introspection_version 1.30.0
%global polkit_version 0.102
%global systemd_version 208
%global libatasmart_version 0.17
%global dbus_version 1.4.0
%global with_gtk_doc 1
%global libblockdev_version 3.0
Expand Down Expand Up @@ -36,7 +35,6 @@ Source0: https://github.com/storaged-project/udisks/releases/download/udisks-%{v
BuildRequires: glib2-devel >= %{glib2_version}
BuildRequires: gobject-introspection-devel >= %{gobject_introspection_version}
BuildRequires: libgudev1-devel >= %{systemd_version}
BuildRequires: libatasmart-devel >= %{libatasmart_version}
BuildRequires: polkit-devel >= %{polkit_version}
BuildRequires: systemd >= %{systemd_version}
BuildRequires: systemd-devel >= %{systemd_version}
Expand All @@ -54,6 +52,7 @@ BuildRequires: libblockdev-mdraid-devel >= %{libblockdev_version}
BuildRequires: libblockdev-fs-devel >= %{libblockdev_version}
BuildRequires: libblockdev-crypto-devel >= %{libblockdev_version}
BuildRequires: libblockdev-nvme-devel >= %{libblockdev_version}
BuildRequires: libblockdev-smart-devel >= %{libblockdev_version}
BuildRequires: libmount-devel
BuildRequires: libuuid-devel

Expand All @@ -65,15 +64,14 @@ Requires: libblockdev-mdraid >= %{libblockdev_version}
Requires: libblockdev-fs >= %{libblockdev_version}
Requires: libblockdev-crypto >= %{libblockdev_version}
Requires: libblockdev-nvme >= %{libblockdev_version}
Requires: libblockdev-smart >= %{libblockdev_version}

Requires: lib%{name}%{?_isa} = %{version}-%{release}

# Needed to pull in the system bus daemon
Requires: dbus >= %{dbus_version}
# Needed to pull in the udev daemon
Requires: udev >= %{systemd_version}
# We need at least this version for bugfixes/features etc.
Requires: libatasmart >= %{libatasmart_version}
# For mount, umount, mkswap
Requires: util-linux
# For ejecting removable disks
Expand Down Expand Up @@ -201,6 +199,7 @@ autoreconf -ivf
%else
--disable-gtk-doc \
%endif
--enable-smart \
%if 0%{?with_btrfs}
--enable-btrfs \
%endif
Expand Down
2 changes: 0 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ libudisks_daemon_la_CFLAGS = \
$(GIO_CFLAGS) \
$(GMODULE_CFLAGS) \
$(GUDEV_CFLAGS) \
$(LIBATASMART_CFLAGS) \
$(LIBBLKID_CFLAGS) \
$(LIBMOUNT_CFLAGS) \
$(LIBUUID_CFLAGS) \
Expand All @@ -138,7 +137,6 @@ libudisks_daemon_la_LIBADD = \
$(GUDEV_LIBS) \
$(BLOCKDEV_LIBS) \
-lbd_utils \
$(LIBATASMART_LIBS) \
$(LIBBLKID_LIBS) \
$(LIBMOUNT_LIBS) \
$(LIBUUID_LIBS) \
Expand Down
10 changes: 8 additions & 2 deletions src/udisksdaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,18 @@ udisks_daemon_constructed (GObject *object)
BDPluginSpec fs_plugin = {BD_PLUGIN_FS, NULL};
BDPluginSpec crypto_plugin = {BD_PLUGIN_CRYPTO, NULL};
BDPluginSpec nvme_plugin = {BD_PLUGIN_NVME, NULL};

#ifdef HAVE_SMART
BDPluginSpec smart_plugin = {BD_PLUGIN_SMART, NULL};
#endif
/* The core daemon needs the part, swap, loop, mdraid, fs and crypto plugins.
Additional plugins are required by various modules, but they make sure
plugins are loaded themselves. */
BDPluginSpec *plugins[] = {&part_plugin, &swap_plugin, &loop_plugin, &mdraid_plugin,
&fs_plugin, &crypto_plugin, &nvme_plugin, NULL};
&fs_plugin, &crypto_plugin, &nvme_plugin,
#ifdef HAVE_SMART
&smart_plugin,
#endif
NULL};
BDPluginSpec **plugin_p = NULL;
error = NULL;

Expand Down
Loading

0 comments on commit beb434a

Please sign in to comment.