Skip to content

Commit

Permalink
CA-309979 Fix Storage Manager initialisation
Browse files Browse the repository at this point in the history
Now that we have xapi-init-complete.target, both mpathcount.service and
usb-scan.service can wait until this point as there is no point to
either of them until xapi can be notified of their results.

In addition, ExecStartPost can be used in both cases to kick them once
as soon as they come up, which makes the mpathroot init script obsolete.

The sm-multipath init script is likewise incorrect and its reliance on
systemd-sysv-generator coupled with its LSB header cause it to come up
*after* network-online.target which is too late. Since it that there are
non-init uses of this script, leave it alone for now but do not enable
it (and disable it on upgrade). Replace its service function with the
new oneshot sm-mpath-root.service which calls a simplified version.

We should find and replace the non-init uses of
/etc/rc.d/init.d/sm-multipath so that we can stop providing it entirely
and eventually remove all use of INITDIR from Storage Manager

Signed-off-by: Tim Smith <tim.smith@citrix.com>
  • Loading branch information
TimSmithCtx authored and MarkSymsCtx committed May 2, 2019
1 parent b7e346c commit d84c81a
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 133 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ SM_PY_FILES = $(foreach LIB, $(SM_LIBS), drivers/$(LIB).py) $(foreach DRIVER, $(
.PHONY: build
build:
make -C dcopy
make -C mpathroot

.PHONY: precommit
precommit: build
Expand Down Expand Up @@ -151,8 +150,10 @@ install: precheck
$(SM_STAGING)$(SM_DEST)/plugins/
install -m 644 multipath/$(MPATH_CONF) \
$(SM_STAGING)/$(MPATH_CONF_DIR)
install -m 755 multipath/$(MPATH_DAEMON) \
install -m 755 multipath/sm-multipath \
$(SM_STAGING)/$(INIT_DIR)
install -m 755 multipath/multipath-root-setup \
$(SM_STAGING)/$(SM_DEST)
install -m 644 etc/logrotate.d/$(SMLOG_CONF) \
$(SM_STAGING)/$(LOGROTATE_DIR)
install -m 644 etc/make-dummy-sr.service \
Expand All @@ -161,6 +162,8 @@ install: precheck
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
install -m 644 systemd/xs-sm.service \
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
install -m 644 systemd/sm-mpath-root.service \
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
install -m 644 systemd/usb-scan.* \
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
install -m 644 systemd/mpathcount.* \
Expand Down Expand Up @@ -205,7 +208,6 @@ install: precheck
install -m 755 scripts/kickpipe $(SM_STAGING)$(LIBEXEC)
$(MAKE) -C dcopy install DESTDIR=$(SM_STAGING)
$(MAKE) -C snapwatchd install DESTDIR=$(SM_STAGING)
$(MAKE) -C mpathroot install DESTDIR=$(SM_STAGING)
ln -sf $(SM_DEST)blktap2.py $(SM_STAGING)$(BIN_DEST)/blktap2
ln -sf $(SM_DEST)lcache.py $(SM_STAGING)$(BIN_DEST)tapdisk-cache-stats
ln -sf /dev/null $(SM_STAGING)$(UDEV_RULES_DIR)/69-dm-lvm-metad.rules
Expand Down
25 changes: 12 additions & 13 deletions mk/sm.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ DESTDIR=$RPM_BUILD_ROOT make install
%clean
rm -rf $RPM_BUILD_ROOT

%pre
# Remove sm-multipath on install or upgrade, to ensure it goes
[ ! -x /sbin/chkconfig ] || chkconfig --del sm-multipath || :

%post
[ ! -x /sbin/chkconfig ] || chkconfig --add mpathroot
[ ! -x /sbin/chkconfig ] || chkconfig --add sm-multipath
service sm-multipath start
%systemd_post make-dummy-sr.service
%systemd_post mpcount.service
%systemd_post snapwatchd.service
%systemd_post sm-mpath-root.service
%systemd_post xs-sm.service
%systemd_post usb-scan.socket
%systemd_post mpathcount.socket
/bin/systemctl enable xs-sm.service >/dev/null 2>&1 || :
/bin/systemctl enable usb-scan.socket >/dev/null 2>&1 || :
/bin/systemctl enable mpathcount.socket >/dev/null 2>&1 || :

[ -f /etc/lvm/lvm.conf.orig ] || cp /etc/lvm/lvm.conf /etc/lvm/lvm.conf.orig || exit $?
[ -d /etc/lvm/master ] || mkdir /etc/lvm/master || exit $?
Expand All @@ -72,12 +71,14 @@ update-alternatives --install /etc/multipath.conf multipath.conf /etc/multipath.
%systemd_preun make-dummy-sr.service
%systemd_preun mpcount.service
%systemd_preun snapwatchd.service
%systemd_preun sm-mpath-root.service
%systemd_preun xs-sm.service
%systemd_preun usb-scan.socket
%systemd_preun mpathcount.socket
#only remove in case of erase (but not at upgrade)
# Remove sm-multipath on upgrade or uninstall, to ensure it goes
[ ! -x /sbin/chkconfig ] || chkconfig --del sm-multipath || :
# only remove in case of erase (but not at upgrade)
if [ $1 -eq 0 ] ; then
[ ! -x /sbin/chkconfig ] || chkconfig --del sm-multipath
update-alternatives --remove multipath.conf /etc/multipath.xenserver/multipath.conf
fi
exit 0
Expand All @@ -86,6 +87,7 @@ exit 0
%systemd_postun make-dummy-sr.service
%systemd_postun mpcount.service
%systemd_postun_with_restart snapwatchd.service
%systemd_postun sm-mpath-root.service
%systemd_postun xs-sm.service
if [ $1 -eq 0 ]; then
[ ! -d /etc/lvm/master ] || rm -Rf /etc/lvm/master || exit $?
Expand All @@ -94,16 +96,11 @@ elif [ $1 -eq 1 ]; then
true;
fi

%posttrans
[ ! -x /sbin/chkconfig ] || chkconfig --add sm-multipath


%check
tests/run_python_unittests.sh

%files
%defattr(-,root,root,-)
/etc/rc.d/init.d/mpathroot
/etc/udev/scripts/xs-mpath-scsidev.sh
/etc/xapi.d/plugins/coalesce-leaf
/etc/xapi.d/plugins/lvhd-thin
Expand Down Expand Up @@ -329,11 +326,13 @@ tests/run_python_unittests.sh
/opt/xensource/sm/cbtutil.py
/opt/xensource/sm/cbtutil.pyc
/opt/xensource/sm/cbtutil.pyo
/opt/xensource/sm/multipath-root-setup
/sbin/mpathutil
/etc/rc.d/init.d/sm-multipath
%{_unitdir}/make-dummy-sr.service
%{_unitdir}/snapwatchd.service
%{_unitdir}/xs-sm.service
%{_unitdir}/sm-mpath-root.service
%{_unitdir}/usb-scan.service
%{_unitdir}/usb-scan.socket
%{_unitdir}/mpathcount.service
Expand Down
14 changes: 0 additions & 14 deletions mpathroot/Makefile

This file was deleted.

102 changes: 0 additions & 102 deletions mpathroot/mpathroot.init

This file was deleted.

79 changes: 79 additions & 0 deletions multipath/multipath-root-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
#
# Copyright (C) Citrix Systems Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; version 2.1 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Ensures the correct symlinks are present in /dev if rood device
# is multipathed
set -e
MP_UTIL=/usr/sbin/mpathconf

#
# This block of functions is taken from dracut
#
find_block_device() {
local rootdev blkdev fs type opts misc
while read blkdev fs type opts misc; do
[[ $blkdev = rootfs ]] && continue # skip rootfs entry
[[ $fs = $1 ]] && { rootdev=$blkdev; break; } # we have a winner!
done < /proc/mounts
[[ -b $rootdev ]] || return 1 # oops, not a block device.
# get major/minor for the device
ls -nLl "$rootdev" | \
(read x x x x maj min x; maj=${maj//,/}; echo $maj:$min)
}

find_root_block_device() { find_block_device /; }

find_root_wwid() {
local rootdev blkdev fs type opts misc
while read blkdev fs type opts misc; do
[[ $blkdev = rootfs ]] && continue # skip rootfs entry
[[ $fs = '/' ]] && { rootdev=$blkdev; break; } # we have a winner!
done < /proc/mounts
[[ -b $rootdev ]] || return 1 # oops, not a block device.
/usr/lib/udev/scsi_id -g $rootdev
}

is_mpath() {
[ -e /sys/dev/block/$1/dm/uuid ] || return 1
# we modified the matching pattern: ^mpath did not work
[[ $(cat /sys/dev/block/$1/dm/uuid) =~ mpath- ]] && return 0
return 1
}

#
# End of block

# We want to be sure multipathd is running with modules
$MP_UTIL --enable --with_module y

# Create an mpInuse symlink for the root device if that is multipath.
ROOT_PART=$(find_root_block_device)
if is_mpath $ROOT_PART; then
ROOT_PART_MINOR=${ROOT_PART#[[:digit:]]*:}
ROOT_PART_SLAVE=$(/bin/ls /sys/block/dm-$ROOT_PART_MINOR/slaves)
ROOT_DISK_MINOR=${ROOT_PART_SLAVE#dm-}
MPATH_NODES="$(dmsetup ls --target multipath --exec ls)"
for n in $MPATH_NODES ; do
# stat %T returns value in hex, convert to decimal before comparing
NODE_MINOR="$((0x$(stat -L --format=%T $n)))"
if [ "$ROOT_DISK_MINOR" = "$NODE_MINOR" ] ; then
mkdir -p /dev/disk/mpInuse
ln -sf $n /dev/disk/mpInuse
fi
done
fi
exit 0
1 change: 0 additions & 1 deletion snapwatchd/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
XS_INCLUDE ?= /usr/include

PREFIX ?= /opt/xensource/sm/snapwatchd
INITDIR ?= /etc/rc.d/init.d
SYSTEMD_SERVICE_DIR ?= /usr/lib/systemd/system
DESTDIR ?=

Expand Down
3 changes: 3 additions & 0 deletions systemd/mpathcount.service
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[Unit]
Description=Multipath scanner
Wants=xapi-init-complete.target
After=xapi-init-complete.target

[Service]
StandardInput=socket
StandardOutput=null
StandardError=journal
ExecStart=/usr/bin/sh -c '. /etc/xensource-inventory; while dd of=/dev/null bs=4096 count=1 status=none conv=noerror; do /opt/xensource/sm/mpathcount.py; done'
ExecStartPost=/opt/xensource/libexec/kickpipe mpathcount
Restart=always
13 changes: 13 additions & 0 deletions systemd/sm-mpath-root.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Ensure symlinks for multipathed rootdev
Wants=basic.target multipathd.service
After=basic.target
Before=multipathd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/opt/xensource/sm/multipath-root-setup

[Install]
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions systemd/usb-scan.service
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[Unit]
Description=USB device scanner
Wants=xapi-init-complete.target
After=xapi-init-complete.target

[Service]
StandardInput=socket
StandardOutput=null
StandardError=journal
ExecStart=/usr/bin/sh -c '. /etc/xensource-inventory; while dd of=/dev/null bs=4096 count=1 status=none conv=noerror; do /opt/xensource/bin/xe pusb-scan host-uuid=$${INSTALLATION_UUID}; done'
ExecStartPost=/opt/xensource/libexec/kickpipe usb-scan
Restart=always

0 comments on commit d84c81a

Please sign in to comment.