Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Systemd init support for loading cache volumes #221

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README
Expand Up @@ -27,5 +27,12 @@ This builds both the flashcache.ko and 3 utilities.
flascache-sa-guide.txt has details on how to create and load
flashcache volumes.

Loading flashcache volumes on Systemd :
-------------------------------------
On folder "systemd" you will find the necessary components and a
README file that describes how to set up those files to load
flashcache volumes when using this init system.

Mohan Srinivasan
Paul Saab
Manuel Bernal-Llinares
21 changes: 21 additions & 0 deletions systemd/README
@@ -0,0 +1,21 @@
Systemd bootup for Flashcache
Author: Manuel Bernal Llinares
------------------------------

This folder contains three files for loading flashcache volumes when booting
the system:
- flashcache.service, contains the service definition, usually placed at /etc/systemd/system/flashcache.service,
with permissions 664.
- flashcache_loader, this script is called by the service "start" action, it parses the flashcachetab file, and
calls flashcache_load to activate the cache volumes specified on the file.
- flashcachetab, this file contains a flashcache volume per line, with optional volume name, to be activated by
flashcache_loader script.
- flashcache_vol.conf, sysctl style file with configuration parameters for the cache volumes

All these files should be installed at:
/etc/systemd/system/flashcache.service
/etc/init.d/flashcache_loader
/etc/flashcache/flashcachetab
/etc/flashcache/flashcache_vol.conf (optional)

This files have been tested on a Debian 8.4, using flashcache compiled from its source code at github.com/facebookarchive/flashcache
15 changes: 15 additions & 0 deletions systemd/flashcache.service
@@ -0,0 +1,15 @@
[Unit]
Description=Flashcache volumes loading service
DefaultDependencies=no
Requires=lvm2-monitor.service -.mount boot.mount lvm2-activation-early.service lvm2-activation.service systemd-fsck-root.service systemd-remount-fs.service
After=lvm2-monintor.service -.mount boot.mount lvm2-activation-early.service lvm2-activation.service systemd-fsck-root.service systemd-remount-fs.service
Wants=lvm2-monitor.service lvm2-activation-early.service lvm2-activation.service
Before=checkfs.service mountall.service

[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/etc/init.d/flashcache_loader

[Install]
WantedBy=default.target
28 changes: 28 additions & 0 deletions systemd/flashcache_loader
@@ -0,0 +1,28 @@
#!/bin/bash

# PATH
#PATH=/sbin:/bin:/usr/bin
EGREP=$(which egrep)
SYSCTL=$(which sysctl)

# File with cache volumes listing
ETC_FLASHCACHE=/etc/flashcache
FLASHCACHETAB=$ETC_FLASHCACHE/flashcachetab
VOLUMES_SYSCTL_PARAMS=$ETC_FLASHCACHE/flashcache_vol.conf

cat "$FLASHCACHETAB" | $EGREP -v "^#" | while read line ;
do
items=($line)
echo "Loading ${items[0]} (${items[1]})"
if flashcache_load ${items[0]} ${items[1]} 2> /dev/null; then
echo "Flashcache volume ${items[1]} loaded from ${items[0]}"
else
(>&2 echo "ERROR loading Flashcache volume ${items[1]} loaded from ${items[0]}")
fi
done
if [ -f "$VOLUMES_SYSCTL_PARAMS" ] ; then
echo "Loading cache volumes configuration from $VOLUMES_SYSCTL_PARAMS"
$SYSCTL -p "$VOLUMES_SYSCTL_PARAMS"
else
echo "No cache volumes configuration file has been found!"
fi
6 changes: 6 additions & 0 deletions systemd/flashcache_vol.conf
@@ -0,0 +1,6 @@
# Configuration parameters for the flashcache cache volumes
#
# The easiest way to customize your cache volumes parameters is, once the volumes
# have been created, run
# sysctl -a | grep flashcache >> /etc/flashcache/flashcache_vol.conf
# Then, edit the file to tweak the parameters for each volume
2 changes: 2 additions & 0 deletions systemd/flashcachetab
@@ -0,0 +1,2 @@
# This file contains a list of devices from which to load flashcache volumes
# <cache_device> <optional_cache_volume_name>