diff --git a/Makefile b/Makefile index a32d669..afd91d8 100644 --- a/Makefile +++ b/Makefile @@ -27,16 +27,16 @@ endif endif archives: - @utils/pckgen $(PWD) tar zip + @tools/pckgen $(PWD) tar zip rpm: - @utils/pckgen $(PWD) rpm --debug + @tools/pckgen $(PWD) rpm --debug srpm: - @utils/pckgen $(PWD) srpm --debug + @tools/pckgen $(PWD) srpm --debug deb: - @utils/pckgen $(PWD) deb + @tools/pckgen $(PWD) deb dsc: - @utils/pckgen $(PWD) dsc + @tools/pckgen $(PWD) dsc diff --git a/casadm/Makefile b/casadm/Makefile index eac2cc1..558aab7 100644 --- a/casadm/Makefile +++ b/casadm/Makefile @@ -3,9 +3,10 @@ # SPDX-License-Identifier: BSD-3-Clause-Clear # +include ../tools/helpers.mk + PWD:=$(shell pwd) MODULESDIR:=$(PWD)/../modules -UTILS_DIR:=$(PWD)/../utils METADATA_DIR:=$(PWD)/../.metadata BINARY_PATH = /sbin @@ -135,28 +136,12 @@ install_files: @mkdir -p $(DESTDIR)$(BINARY_PATH) @install -m 755 $(TARGET) $(DESTDIR)$(BINARY_PATH)/$(TARGET) @mkdir -p $(DESTDIR)/usr/share/man/man8 - @install -m 644 $(UTILS_DIR)/$(TARGET).8 $(DESTDIR)/usr/share/man/man8/$(TARGET).8 - - @install -m 755 -d $(DESTDIR)/etc/opencas - @install -m 644 $(UTILS_DIR)/opencas.conf $(DESTDIR)/etc/opencas/opencas.conf - @install -m 444 $(UTILS_DIR)/ioclass-config.csv $(DESTDIR)/etc/opencas/ioclass-config.csv - @install -m 755 -d $(DESTDIR)/var/lib/opencas - @install -m 644 $(METADATA_DIR)/cas_version $(DESTDIR)/var/lib/opencas/cas_version - + @install -m 644 $(TARGET).8 $(DESTDIR)/usr/share/man/man8/$(TARGET).8 @mkdir -p $(DESTDIR)/usr/share/man/man5 - @install -m 644 $(UTILS_DIR)/opencas.conf.5 $(DESTDIR)/usr/share/man/man5/opencas.conf.5 uninstall: @echo "Uninstalling casadm" - @rm $(DESTDIR)$(BINARY_PATH)/$(TARGET) - @rm $(DESTDIR)/usr/share/man/man8/$(TARGET).8 - - @rm $(DESTDIR)/etc/opencas/opencas.conf - @rm $(DESTDIR)/etc/opencas/ioclass-config.csv - @rm -rf $(DESTDIR)/etc/opencas - @rm $(DESTDIR)/var/lib/opencas/cas_version - @rm -rf $(DESTDIR)/var/lib/opencas - - @rm $(DESTDIR)/usr/share/man/man5/opencas.conf.5 + $(call remove-file,$(DESTDIR)$(BINARY_PATH)/$(TARGET)) + $(call remove-file,$(DESTDIR)/usr/share/man/man8/$(TARGET).8) .PHONY: clean distclean all sync build install uninstall diff --git a/utils/casadm.8 b/casadm/casadm.8 similarity index 100% rename from utils/casadm.8 rename to casadm/casadm.8 diff --git a/configure b/configure index 375c588..0643a82 100755 --- a/configure +++ b/configure @@ -79,7 +79,7 @@ fi # Run version generator with 'build' flag to # indicate that we are in the build process -(cd utils && ./cas_version_gen build) +(cd tools && ./cas_version_gen build) if [ $? -ne 0 ]; then echo "Error: failed to obtain CAS version" >&2 exit 1 diff --git a/modules/Makefile b/modules/Makefile index 1d5859e..039259a 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -15,6 +15,13 @@ obj-y += cas_disk/ # line; invoke the kernel build system. else +include ../tools/helpers.mk + +define remove-module + @if (lsmod | grep -q ${1}); then rmmod ${1}; \ + else echo "WARNING: Module ${1} is not loaded"; fi +endef + OCFDIR=$(PWD)/../ocf PWD=$(shell pwd) KERNEL_VERSION ?= "$(shell uname -r)" @@ -57,11 +64,11 @@ install_files: uninstall: @echo "Uninstalling Open-CAS modules" - @$(RMMOD) $(CACHE_MODULE) - @$(RMMOD) $(DISK_MODULE) + $(call remove-module,$(CACHE_MODULE)) + $(call remove-module,$(DISK_MODULE)) - @rm $(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko - @rm $(DESTDIR)$(MODULES_DIR)/$(DISK_MODULE).ko + $(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko) + $(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(DISK_MODULE).ko) @$(DEPMOD) diff --git a/utils/cas_version_gen b/tools/cas_version_gen similarity index 100% rename from utils/cas_version_gen rename to tools/cas_version_gen diff --git a/tools/helpers.mk b/tools/helpers.mk new file mode 100644 index 0000000..3912726 --- /dev/null +++ b/tools/helpers.mk @@ -0,0 +1,15 @@ +# +# Copyright(c) 2021 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +define remove-file + @if [ -f ${1} ] || [ -L ${1} ]; then rm -rf ${1}; \ + else echo "WARNING: Cannot find file ${1}"; fi +endef + +define remove-directory + @if [ -d ${1} ]; then rm -rf ${1}; \ + else echo "WARNING: Cannot find directory ${1}"; fi +endef + diff --git a/utils/pckgen b/tools/pckgen similarity index 99% rename from utils/pckgen rename to tools/pckgen index 3ded45d..7d67c2b 100755 --- a/utils/pckgen +++ b/tools/pckgen @@ -515,7 +515,7 @@ DEB_BUILD_DIR="$TEMP_DIR/debuild" # Version file location: VERSION_FILE="$SOURCES_DIR/.metadata/cas_version" # CAS version generator location: -CAS_VERSION_GEN="$SOURCES_DIR/utils/cas_version_gen" +CAS_VERSION_GEN="$SOURCES_DIR/tools/cas_version_gen" check_version diff --git a/utils/pckgen.d/deb/debian/CAS_NAME-modules.dkms b/tools/pckgen.d/deb/debian/CAS_NAME-modules.dkms similarity index 100% rename from utils/pckgen.d/deb/debian/CAS_NAME-modules.dkms rename to tools/pckgen.d/deb/debian/CAS_NAME-modules.dkms diff --git a/utils/pckgen.d/deb/debian/CAS_NAME-modules.install b/tools/pckgen.d/deb/debian/CAS_NAME-modules.install similarity index 100% rename from utils/pckgen.d/deb/debian/CAS_NAME-modules.install rename to tools/pckgen.d/deb/debian/CAS_NAME-modules.install diff --git a/utils/pckgen.d/deb/debian/CAS_NAME.docs b/tools/pckgen.d/deb/debian/CAS_NAME.docs similarity index 100% rename from utils/pckgen.d/deb/debian/CAS_NAME.docs rename to tools/pckgen.d/deb/debian/CAS_NAME.docs diff --git a/utils/pckgen.d/deb/debian/CAS_NAME.install b/tools/pckgen.d/deb/debian/CAS_NAME.install similarity index 100% rename from utils/pckgen.d/deb/debian/CAS_NAME.install rename to tools/pckgen.d/deb/debian/CAS_NAME.install diff --git a/utils/pckgen.d/deb/debian/CAS_NAME.manpages b/tools/pckgen.d/deb/debian/CAS_NAME.manpages similarity index 100% rename from utils/pckgen.d/deb/debian/CAS_NAME.manpages rename to tools/pckgen.d/deb/debian/CAS_NAME.manpages diff --git a/utils/pckgen.d/deb/debian/changelog b/tools/pckgen.d/deb/debian/changelog similarity index 100% rename from utils/pckgen.d/deb/debian/changelog rename to tools/pckgen.d/deb/debian/changelog diff --git a/utils/pckgen.d/deb/debian/compat b/tools/pckgen.d/deb/debian/compat similarity index 100% rename from utils/pckgen.d/deb/debian/compat rename to tools/pckgen.d/deb/debian/compat diff --git a/utils/pckgen.d/deb/debian/control b/tools/pckgen.d/deb/debian/control similarity index 100% rename from utils/pckgen.d/deb/debian/control rename to tools/pckgen.d/deb/debian/control diff --git a/utils/pckgen.d/deb/debian/copyright b/tools/pckgen.d/deb/debian/copyright similarity index 100% rename from utils/pckgen.d/deb/debian/copyright rename to tools/pckgen.d/deb/debian/copyright diff --git a/utils/pckgen.d/deb/debian/rules b/tools/pckgen.d/deb/debian/rules similarity index 100% rename from utils/pckgen.d/deb/debian/rules rename to tools/pckgen.d/deb/debian/rules diff --git a/utils/pckgen.d/deb/debian/source/format b/tools/pckgen.d/deb/debian/source/format similarity index 100% rename from utils/pckgen.d/deb/debian/source/format rename to tools/pckgen.d/deb/debian/source/format diff --git a/utils/pckgen.d/rpm/CAS_NAME.spec b/tools/pckgen.d/rpm/CAS_NAME.spec similarity index 100% rename from utils/pckgen.d/rpm/CAS_NAME.spec rename to tools/pckgen.d/rpm/CAS_NAME.spec diff --git a/utils/Makefile b/utils/Makefile index 315ac73..08d0bf8 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -3,8 +3,12 @@ # SPDX-License-Identifier: BSD-3-Clause-Clear # +include ../tools/helpers.mk + CASCTL_DIR = /lib/opencas UDEVRULES_DIR = /lib/udev/rules.d +METADATA_DIR:=$(PWD)/../.metadata +UTILS_DIR:=$(PWD)/../utils UDEV:=$(shell which udevadm) SYSTEMCTL := $(shell which systemctl) PYTHON3 := $(shell which python3) @@ -30,6 +34,14 @@ else install_files: @echo "Installing Open-CAS utils" + @install -m 755 -d $(DESTDIR)/etc/opencas + @install -m 644 $(UTILS_DIR)/opencas.conf $(DESTDIR)/etc/opencas/opencas.conf + @install -m 444 $(UTILS_DIR)/ioclass-config.csv $(DESTDIR)/etc/opencas/ioclass-config.csv + @install -m 755 -d $(DESTDIR)/var/lib/opencas + @install -m 644 $(METADATA_DIR)/cas_version $(DESTDIR)/var/lib/opencas/cas_version + @mkdir -p $(DESTDIR)/usr/share/man/man5 + @install -m 644 $(UTILS_DIR)/opencas.conf.5 $(DESTDIR)/usr/share/man/man5/opencas.conf.5 + @install -m 755 -d $(DESTDIR)$(CASCTL_DIR) @install -m 644 opencas.py $(DESTDIR)$(CASCTL_DIR)/opencas.py @install -m 755 casctl $(DESTDIR)$(CASCTL_DIR)/casctl @@ -58,28 +70,36 @@ install_files: endif uninstall: - @rm $(DESTDIR)$(CASCTL_DIR)/opencas.py - @rm $(DESTDIR)$(CASCTL_DIR)/casctl - @rm $(DESTDIR)$(CASCTL_DIR)/open-cas-loader - @rm -rf $(DESTDIR)$(CASCTL_DIR) + @echo "Uninstalling Open-CAS utils" - @rm $(DESTDIR)/etc/dracut.conf.d/opencas.conf + $(call remove-file,$(DESTDIR)/etc/opencas/opencas.conf) + $(call remove-file,$(DESTDIR)/etc/opencas/ioclass-config.csv) + $(call remove-directory,$(DESTDIR)/etc/opencas) + $(call remove-file,$(DESTDIR)/var/lib/opencas/cas_version) + $(call remove-directory,$(DESTDIR)/var/lib/opencas) + $(call remove-file,$(DESTDIR)/usr/share/man/man5/opencas.conf.5) - @rm $(DESTDIR)/sbin/casctl + $(call remove-file,$(DESTDIR)$(CASCTL_DIR)/opencas.py) + $(call remove-file,$(DESTDIR)$(CASCTL_DIR)/casctl) + $(call remove-file,$(DESTDIR)$(CASCTL_DIR)/open-cas-loader) + $(call remove-directory,$(DESTDIR)$(CASCTL_DIR)) - @rm $(DESTDIR)/usr/share/man/man8/casctl.8 + $(call remove-file,$(DESTDIR)/etc/dracut.conf.d/opencas.conf) - @rm $(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas-load.rules - @rm $(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas.rules + $(call remove-file,$(DESTDIR)/sbin/casctl) + + $(call remove-file,$(DESTDIR)/usr/share/man/man8/casctl.8) + + $(call remove-file,$(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas-load.rules) + $(call remove-file,$(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas.rules) @$(UDEV) control --reload-rules @$(SYSTEMCTL) -q disable open-cas-shutdown @$(SYSTEMCTL) -q disable open-cas @$(SYSTEMCTL) daemon-reload - @rm $(DESTDIR)$(SYSTEMD_DIR)/open-cas-shutdown.service - @rm $(DESTDIR)$(SYSTEMD_DIR)/open-cas.service - @rm $(DESTDIR)$(SYSTEMD_DIR)/../system-shutdown/open-cas.shutdown - + $(call remove-file,$(DESTDIR)$(SYSTEMD_DIR)/open-cas-shutdown.service) + $(call remove-file,$(DESTDIR)$(SYSTEMD_DIR)/open-cas.service) + $(call remove-file,$(DESTDIR)$(SYSTEMD_DIR)/../system-shutdown/open-cas.shutdown) .PHONY: install uninstall clean distclean