[master 1/3] Add generic classes for cache and cache stats

vpodzime installerbot-noreply at redhat.com
Thu Jun 18 20:06:59 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

Inheriting classes will implement specific functionality for LVM cache and Bcache.
---
 blivet/devices/cache.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 blivet/devices/cache.py

diff --git a/blivet/devices/cache.py b/blivet/devices/cache.py
new file mode 100644
index 0000000..f036466
--- /dev/null
+++ b/blivet/devices/cache.py
@@ -0,0 +1,116 @@
+# devices/cache.py
+#
+# Copyright (C) 2015  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU 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.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Vratislav Podzimek <vpodzime at redhat.com>
+#
+
+"""Module providing common helper classes, functions and other things related to
+cached devices (like bcache, LVM cache and whatever appears in the future).
+
+"""
+
+from six import add_metaclass
+import abc
+
+ at add_metaclass(abc.ABCMeta)
+class Cache(object):
+    """Abstract base class for cache objects providing the cache-related
+    functionality on cached devices. Instances of this class are not expected to
+    be devices (both in what they represent as well as not instances of the
+    :class:`~.devices.Device` class) since they just provide the cache-related
+    functionality of cached devices and are not devices on their own.
+
+    """
+
+    @abc.abstractproperty
+    def size(self):
+        """Size of the cache"""
+        pass
+
+    @abc.abstractproperty
+    def exists(self):
+        """Whether the cache (device) exists or not"""
+        pass
+
+    @abc.abstractproperty
+    def stats(self):
+        """Statistics for the cache
+        :rtype: :class:`CacheStats`
+        """
+        pass
+
+    @abc.abstractproperty
+    def mode(self):
+        """Mode of the cache (writeback/writethrough...)
+        :rtype: str
+        """
+        pass
+
+    @abc.abstractproperty
+    def backing_device_name(self):
+        """Name of the backing (big/slow) device of the cache (if any)"""
+
+        pass
+
+    @abc.abstractproperty
+    def cache_device_name(self):
+        """Name of the cache (small/fast) device of the cache (if any)"""
+
+        pass
+
+    @abc.abstractmethod
+    def detach(self):
+        """Detach the cache
+        :returns: identifier of the detached cache that can be later used for attaching it back
+
+        """
+        pass
+
+
+ at add_metaclass(abc.ABCMeta)
+class CacheStats(object):
+    """Abstract base class for common statistics of caches (cached
+    devices). Inheriting classes are expected to add (cache-)type-specific
+    attributes on top of the common set.
+
+    """
+
+    @abc.abstractproperty
+    def block_size(self):
+        """block size of the cache"""
+        pass
+
+    @abc.abstractproperty
+    def size(self):
+        """size of the cache"""
+        pass
+
+    @abc.abstractproperty
+    def used(self):
+        """how much of the cache is used"""
+        pass
+
+    @abc.abstractproperty
+    def hits(self):
+        """number of hits"""
+        pass
+
+    @abc.abstractproperty
+    def misses(self):
+        """number of misses"""
+        pass


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/3cae442e78a2ca6c4c03c78bd31139d04488f734


More information about the anaconda-patches mailing list