Add ISU package 51/305351/2 accepted/tizen/8.0/unified/20240201.164552
authorAdam Michalski <a.michalski2@partner.samsung.com>
Tue, 14 Nov 2023 16:22:41 +0000 (17:22 +0100)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 31 Jan 2024 16:19:02 +0000 (17:19 +0100)
resourced is a special case. As the service binary performs mounts that must be
visible by the rest of the system, it cannot use any form of sandboxing. That's
why the binary has to be run directly from the ISU package. In addition, different
images may provide different set of configuration files (/etc/resourced/*) and some
configurations may need plugins in the form of shared libraries. As if that was not
enough, the aforementioned plugins may reside in different directories, depending on
the target architecture (as with all shared libraries on Linux systems). Putting all
this together and preparing a correct and roboust ISU configuration is challenging.

The solution is to prepare an ISU package that will work in all these cases:
- any collection of configuration files (/etc/resourced/*)
- any collection of plugins (possibly with no plugins at all)
- support a whole raft of different combinations of the above two.

The solution is based on direct binary file exchange, bind mounting the whole
/etc/resourced directory and bind mounting the whole plugins directory. The latter
is optional (so possibly resourced can run without plugins at all on some
configurations). Bind mounting entire subdirectories allows for the flexibility of
the whole ISU configuration. Please find the implementation details below.

The following changes have been made for ISU:
* isu/isu.cfg - ISU configuration file.
    [isu] section:
        `name` and `version` have been filled by using the #NAME# and #VERSION#
        that will be replaced into the name and version of the RPM package.
        `system_service` is the systemd service name and must be the same as the
        original one. It has also been extended to add two dependent mount units:
            `##PLUGIN_MOUNT##` will be substituted into
            `usr-lib{64}-resourced-plugins.mount` (depending on the architecture)
            which bind mounts resourced plugins subdirectory allowing it to be
            replaced with the ones provided by the ISU package
            `etc-resourced.mount` which is responsible for replacing /etc/resourced
            with the one provided by ISU
    [files] section:
        contains a list of files/directories that should be added to the ISU package.
        We provide 3 mandatory entries here:
            /usr/bin/resourced - resourced binary
            /etc/resourced - directory containing resourced configuration
            libresourced-private-api.so.* - library that is mandatory for resourced
            resourced/plugins - directory with resourced plugins (optional)
        We use the `##LIBDIR##` snippet to obtain the proper library path (explained
        later).
* isu/resourced.service- modified ISU service file.
    Comparing to the original service file, dependency on plugin mount unit has been
    introduced. Plugin mount unit in turns is dependent on the `etc-resourced` mount
    unit. Also, the ExecStart has been modified so that it loads the service binary
    from the ISU package path rather than the original one (/usr/bin/resourced).
* isu/etc-resourced.mount - mount unit responsible for replacing the original
    /etc/resourced directory with the one provided by the ISU package
* isu/usr-lib-resourced-plugins.mount - mount unit responsible for replacing plugins
    subdirectory with the one provided by the ISU package.
    ##PLUGIN_LIB_DIR## is substituted by the appropriate string generated in the
    resourced.spec file, which depends on the architecture: on 32-bit systems it will
    be /usr/lib, and on 64-bit ones /usr/lib64. This mount unit may be renamed later
    to `usr-lib64-resourced-plugins.mount` as the name of the mount unit must reflect
    the path to which it applies a bind mount. This is done in the isu/CMakeLists.txt.
* packaging/resourced.spec - main resourced RPM spec file.
    The following changes has been made:
    - added isu package, its description, and isu configuration files section
    - added ISU_ARCH_BIT constant to be passed to the cmake invocation, so that it
      knows for which architecture the build was invoked
    - added `##LIBDIR##`, `##PLUGIN_LIB_DIR## ` and `##PLUGIN_MOUNT##` symbols
      expansion to substitute the placeholders in isu configuration, service file and
      mount unit files depending on the architecture:
      ##LIBDIR## exapnds to /usr/lib{64}
      ##PLUGIN_MOUNT## expands to usr-lib{64}-resourced-plugins.mount
      ##PLUGIN_LIB_DIR## expands to /usr/lib{64}/resourced/plugins
    - added packaing plugins directory to the `bin` rpm package. This is needed to
      prevent plugins mount unit from failing when the plugins are not present (they
      are optional).
* isu/CMakeLists.txt - CMake config file for the ISU rpm package
    Added installing ISU config file, isu service file and mount units to the
    appropriate locations (/etc/isu/*). Also added renaming plugins mount unit file
    to the appropriate one (depending on the architecture).
* src/CMakeLists.txt - main CMake config file
    Added creating resourced plugins directory unconditionally. Necessary for the
    spec file to be able to package plugins directory (possibly empty) into the `bin`
    rpm package.

Change-Id: Ic3eb567450a166874263e7c5bded326dc663d221

CMakeLists.txt
isu/CMakeLists.txt [new file with mode: 0644]
isu/etc-resourced.mount [new file with mode: 0644]
isu/isu.cfg [new file with mode: 0644]
isu/resourced.service [new file with mode: 0644]
isu/usr-lib-resourced-plugins.mount [new file with mode: 0644]
packaging/resourced.spec
src/CMakeLists.txt

index 7eb6d8d..448a83f 100644 (file)
@@ -99,3 +99,5 @@ IF(DEFINED RD_TESTS_PATH)
   ENABLE_TESTING()
   ADD_SUBDIRECTORY(tests)
 ENDIF(DEFINED RD_TESTS_PATH)
+
+ADD_SUBDIRECTORY(isu)
diff --git a/isu/CMakeLists.txt b/isu/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b45dee7
--- /dev/null
@@ -0,0 +1,18 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(ISU C)
+
+IF("${ISU_ARCH_BIT}" STREQUAL "32")
+       OPTION(USE_32BIT "Use 32bit architecture" ON)
+ELSEIF("${ISU_ARCH_BIT}" STREQUAL "64")
+       OPTION(USE_64BIT "Use 64bit architecture" ON)
+ENDIF()
+
+INSTALL(FILES isu.cfg DESTINATION /etc/isu/resourced/ PERMISSIONS OWNER_WRITE OWNER_READ)
+INSTALL(FILES resourced.service DESTINATION /etc/isu/resourced/system-services/ PERMISSIONS OWNER_WRITE OWNER_READ WORLD_READ)
+INSTALL(FILES etc-resourced.mount DESTINATION /etc/isu/resourced/system-services/ PERMISSIONS OWNER_WRITE OWNER_READ WORLD_READ)
+
+IF(USE_32BIT)
+       INSTALL(FILES usr-lib-resourced-plugins.mount DESTINATION /etc/isu/resourced/system-services/ PERMISSIONS OWNER_WRITE OWNER_READ WORLD_READ)
+ELSEIF(USE_64BIT)
+       INSTALL(FILES usr-lib-resourced-plugins.mount DESTINATION /etc/isu/resourced/system-services/ RENAME usr-lib64-resourced-plugins.mount PERMISSIONS OWNER_WRITE OWNER_READ WORLD_READ)
+ENDIF()
diff --git a/isu/etc-resourced.mount b/isu/etc-resourced.mount
new file mode 100644 (file)
index 0000000..1595bf6
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Before=local-fs.target
+ConditionPathIsMountPoint=!/etc/resourced
+DefaultDependencies=no
+
+[Mount]
+What=#ISU_RUN_PATH#/resourced/rootfs/etc/resourced
+Where=/etc/resourced
+Options=defaults,relatime,bind,ro
diff --git a/isu/isu.cfg b/isu/isu.cfg
new file mode 100644 (file)
index 0000000..d487584
--- /dev/null
@@ -0,0 +1,10 @@
+[isu]
+name=#NAME#
+version=#VERSION#
+system_service=resourced.service ##PLUGIN_MOUNT## etc-resourced.mount
+
+[files]
+/usr/bin/resourced
+/etc/resourced
+-##LIBDIR##/resourced/plugins
+##LIBDIR##/libresourced-private-api.so.*
diff --git a/isu/resourced.service b/isu/resourced.service
new file mode 100644 (file)
index 0000000..730f339
--- /dev/null
@@ -0,0 +1,23 @@
+[Unit]
+Description=Resource management daemon
+# resourced monitors AUL (lauchpad) d-bus signals to learn about existence
+# and the state of applications.  Consequently, it has to start before
+# launchpad to have knowledge of all applications.  The Before= line below
+# refers to user-sessions, because tlm, and consequently user@.service
+# starts after user-sessions are allowed.
+After=##PLUGIN_MOUNT##
+Before=systemd-user-sessions.service
+BindsTo=##PLUGIN_MOUNT##
+DefaultDependencies=no
+Requires=resourced.socket
+
+[Service]
+Type=simple
+SmackProcessLabel=System
+ExecStart=#ISU_RUN_PATH#/resourced/rootfs/usr/bin/resourced
+MemoryLimit=50M
+Restart=on-failure
+RestartSec=0
+
+[Install]
+WantedBy=multi-user.target
diff --git a/isu/usr-lib-resourced-plugins.mount b/isu/usr-lib-resourced-plugins.mount
new file mode 100644 (file)
index 0000000..58352e9
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Before=local-fs.target
+After=etc-resourced.mount
+BindsTo=etc-resourced.mount
+ConditionPathIsMountPoint=!##PLUGIN_LIB_DIR##
+DefaultDependencies=no
+
+[Mount]
+What=#ISU_RUN_PATH#/resourced/rootfs##PLUGIN_LIB_DIR##
+Where=##PLUGIN_LIB_DIR##
+Options=defaults,relatime,bind,ro
index bc25e47..a93250e 100644 (file)
@@ -101,14 +101,28 @@ Summary:  watchdog module for resourced
 %description   watchdog-handler
 %endif
 
+%package isu
+Summary: ISU package for resourced
+Group:   Application Framework/Service
+
+%description isu
+Configuration files to generate the ISU (Individual Service Upgrade) package
+
 %prep
 %setup -q
 
+%ifarch %{arm} %ix86
+%define ISU_ARCH_BIT 32
+%else
+%define ISU_ARCH_BIT 64
+%endif
+
 %build
 mkdir -p build
 pushd build
 %cmake .. -DFULLVER=%{version}                        \
         -DCMAKE_BUILD_TYPE=Release                       \
+        -DISU_ARCH_BIT=%{ISU_ARCH_BIT}                   \
         -DCPU_THROTTLING_MODULE=%{cpu_throttling_module} \
         -DCPU_BOOSTING_MODULE=%{cpu_boosting_module}     \
         -DMEMORY_MODULE=%{memory_module}                 \
@@ -125,6 +139,15 @@ pushd build
 make %{?jobs:-j%jobs}
 popd
 
+LIB_DIR=%{_libdir}
+sed -ie s,"##LIBDIR##,$LIB_DIR,g" isu/isu.cfg
+RD_PLUGIN_PATH=%{plugindir}
+RD_PLUGIN_MOUNT_NAME=$(systemd-escape $RD_PLUGIN_PATH).mount
+RD_PLUGIN_MOUNT_NAME=$(cut -c2- <<< $RD_PLUGIN_MOUNT_NAME) > /dev/null
+sed -ie s,"##PLUGIN_MOUNT##,$RD_PLUGIN_MOUNT_NAME,g" isu/isu.cfg
+sed -ie s,"##PLUGIN_MOUNT##,$RD_PLUGIN_MOUNT_NAME,g" isu/resourced.service
+sed -ie s,"##PLUGIN_LIB_DIR##,$RD_PLUGIN_PATH,g" isu/usr-lib-resourced-plugins.mount
+
 %install
 rm -rf %{buildroot}
 pushd build
@@ -153,6 +176,7 @@ mv %{confdir}/optimizer-profile-tv.conf %{confdir}/optimizer.conf
 %manifest resourced.manifest
 %{_libdir}/libresourced-private-api.so.*
 %{_bindir}/resourced
+%dir %{plugindir}
 %attr(-,root, root) %{_bindir}/resourced
 %attr(700, root, root) %{TZ_SYS_ETC}/dump.d/module.d/dump_heart_data.sh
 
@@ -196,3 +220,6 @@ mv %{confdir}/optimizer-profile-tv.conf %{confdir}/optimizer.conf
 %defattr(-,root,root)
 %{_libdir}/resourced-tests/run_tests.sh
 %{_libdir}/resourced-tests/watchdog-test
+
+%files isu
+/etc/isu/resourced/*
index 9613cf1..907deb7 100644 (file)
@@ -142,6 +142,8 @@ INSTALL(FILES ${RESOURCED_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/resou
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/resourced-private-api.pc.in ${CMAKE_SOURCE_DIR}/resourced-private-api.pc @ONLY)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/resourced-private-api.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
 
+INSTALL(DIRECTORY DESTINATION ${MAKE_INSTALL_PREFIX}${RD_PLUGIN_PATH})
+
 ADD_LIBRARY(plugin-resourced-process-block MODULE
        ${BLOCK_SOURCE_DIR}/block.c
        ${BLOCK_SOURCE_DIR}/block-monitor.c)