diff --git a/utils/open-cas.shutdown b/utils/open-cas.shutdown index e43a308..fd94042 100755 --- a/utils/open-cas.shutdown +++ b/utils/open-cas.shutdown @@ -7,4 +7,4 @@ # systemd-shutdown plugin to stop all remaining Open CAS devices /usr/bin/echo "Open CAS cleanup handler" > /dev/kmsg -/sbin/casctl stop +/sbin/casctl stop --flush diff --git a/utils/opencas.py b/utils/opencas.py index f3ae112..70c81a1 100644 --- a/utils/opencas.py +++ b/utils/opencas.py @@ -139,7 +139,16 @@ class casadm: cmd += ['--'+param.replace('_', '-'), str(value)] return cls.run_cmd(cmd) - + + @classmethod + def set_param_cleaning_policy(cls, policy, cache_id, **kwargs): + cmd = [cls.casadm_path, + '--set-param', '--name', 'cleaning-'+policy, + '--cache-id', str(cache_id)] + for param, value in kwargs.items(): + cmd += ['--'+param.replace('_', '-'), str(value)] + return cls.run_cmd(cmd) + @classmethod def get_params(cls, namespace, cache_id, **kwargs): cmd = [cls.casadm_path, @@ -269,6 +278,10 @@ class cas_config(object): self.check_lazy_startup_valid(param_value) elif param_name == "target_failover_state": self.check_failover_state_valid(param_value) + elif param_name == "wake-up": + self.check_wake_up_valid(param_value) + elif param_name == "flush-max-buffers": + self.check_flush_max_buffers_valid(param_value) else: raise ValueError(f'{param_name} is invalid parameter name') @@ -315,6 +328,29 @@ class cas_config(object): if cache_line_size not in ['4', '8', '16', '32', '64']: raise ValueError(f'{cache_line_size} is invalid cache line size') + def check_wake_up_valid(self, wake_up): + if self.params.get("cleaning_policy") == "acp": + if not wake_up.isdigit(): + raise ValueError(f"{wake_up} is invalid wake-up value for acp cleaning policy") + if int(wake_up) not in range(0, 10000): + raise ValueError(f"{wake_up} is invalid wake-up value for acp cleaning policy") + elif self.params.get("cleaning_policy") == "alru": + if not wake_up.isdigit(): + raise ValueError(f"{wake_up} is invalid wake-up value for alru cleaning policy") + if int(wake_up) not in range(0, 3600): + raise ValueError(f"{wake_up} is invalid wake-up value for alru cleaning policy") + + def check_flush_max_buffers_valid(self, flush_max_buffers): + if self.params.get("cleaning_policy") == "acp": + if not flush_max_buffers.isdigit(): + raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for acp cleaning policy") + if int(flush_max_buffers) not in range(1, 10000): + raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for acp cleaning policy") + elif self.params.get("cleaning_policy") == "alru": + if not flush_max_buffers.isdigit(): + raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for alru cleaning policy") + if int(flush_max_buffers) not in range(1, 10000): + raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for alru cleaning policy") def check_recursive(self): if not self.device.startswith('/dev/cas'): return @@ -590,9 +626,16 @@ def start_cache(cache, load, force=False): def configure_cache(cache): if "cleaning_policy" in cache.params: - casadm.set_param( - "cleaning", cache_id=cache.cache_id, policy=cache.params["cleaning_policy"] - ) + if cache.params["cleaning_policy"] == "acp" or cache.params["cleaning_policy"] == "alru": + casadm.set_param_cleaning_policy( + policy=cache.params["cleaning_policy"], cache_id=cache.cache_id, wake_up=cache.params["wake_up"], flush_max_buffers=cache.params["flush_max_buffers"] + ) + else: + casadm.set_param( + "cleaning", cache_id=cache.cache_id, policy=cache.params["cleaning_policy"] + ) + + if "promotion_policy" in cache.params: casadm.set_param( "promotion", cache_id=cache.cache_id, policy=cache.params["promotion_policy"]