Blame SOURCES/BZ-1213602-overlayfs-workaround-plugin.patch

5b4f08
commit 0c0b029122b476c269a4b560d9be558e69e054ae
5b4f08
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5b4f08
Date:   Thu Jun 25 12:09:52 2015 +0200
5b4f08
5b4f08
    Add plugin for overlayfs issue workaround. Patch by Pavel Odvody. BZ#1213602
5b4f08
5b4f08
diff --git a/plugins/ovl/ovl.conf b/plugins/ovl/ovl.conf
5b4f08
new file mode 100644
5b4f08
index 0000000..8e4d76c
5b4f08
--- /dev/null
5b4f08
+++ b/plugins/ovl/ovl.conf
5b4f08
@@ -0,0 +1,2 @@
5b4f08
+[main]
5b4f08
+enabled=1
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
new file mode 100644
5b4f08
index 0000000..de34081
5b4f08
--- /dev/null
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -0,0 +1,48 @@
5b4f08
+# Copyright (C) 2015  Red Hat, Inc.
5b4f08
+#
5b4f08
+# Authors: Pavel Odvody <podvody@redhat.com>
5b4f08
+#
5b4f08
+# This copyrighted material is made available to anyone wishing to use,
5b4f08
+# modify, copy, or redistribute it subject to the terms and conditions of
5b4f08
+# the GNU General Public License v.2, or (at your option) any later version.
5b4f08
+# This program is distributed in the hope that it will be useful, but WITHOUT
5b4f08
+# ANY WARRANTY expressed or implied, including the implied warranties of
5b4f08
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
5b4f08
+# Public License for more details.  You should have received a copy of the
5b4f08
+# GNU General Public License along with this program; if not, write to the
5b4f08
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
5b4f08
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
5b4f08
+# source code or documentation are not subject to the GNU General Public
5b4f08
+# License and may only be used or replicated with the express permission of
5b4f08
+# Red Hat, Inc.
5b4f08
+
5b4f08
+from yum.plugins import TYPE_CORE
5b4f08
+from os import utime, walk, path
5b4f08
+
5b4f08
+requires_api_version = '2.3'
5b4f08
+plugin_type = (TYPE_CORE,)
5b4f08
+base_dir = 'var/lib/rpm/'
5b4f08
+mtab = '/etc/mtab'
5b4f08
+
5b4f08
+def should_touch():
5b4f08
+        """ 
5b4f08
+        Touch the files only once we've verified that
5b4f08
+        we're on overlay mount
5b4f08
+        """
5b4f08
+        with open(mtab, 'r') as f:
5b4f08
+                line = f.readline()
5b4f08
+                return line and line.startswith('overlay /')
5b4f08
+        return False
5b4f08
+
5b4f08
+def init_hook(conduit):
5b4f08
+        if not should_touch():
5b4f08
+                return
5b4f08
+    ir = conduit.getConf().installroot
5b4f08
+        try:
5b4f08
+                for root, _, files in walk(path.join(ir, base_dir)):
5b4f08
+                        for f in files:
5b4f08
+                                p = path.join(root, f)
5b4f08
+                                with open(p, 'a'):
5b4f08
+                                        utime(p, None)
5b4f08
+        except Exception as e:
5b4f08
+                conduit.error(1, "Error while doing RPMdb copy-up:\n%s" % e)
5b4f08
commit 1555cfa6465e6e31515a86f097c8993d89c0085e
5b4f08
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5b4f08
Date:   Thu Jun 25 12:30:13 2015 +0200
5b4f08
5b4f08
    ovl plugin: fix indentation
5b4f08
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
index de34081..eda784e 100644
5b4f08
--- a/plugins/ovl/ovl.py
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -25,24 +25,24 @@ base_dir = 'var/lib/rpm/'
5b4f08
 mtab = '/etc/mtab'
5b4f08
 
5b4f08
 def should_touch():
5b4f08
-        """ 
5b4f08
-        Touch the files only once we've verified that
5b4f08
-        we're on overlay mount
5b4f08
-        """
5b4f08
-        with open(mtab, 'r') as f:
5b4f08
-                line = f.readline()
5b4f08
-                return line and line.startswith('overlay /')
5b4f08
-        return False
5b4f08
+    """ 
5b4f08
+    Touch the files only once we've verified that
5b4f08
+    we're on overlay mount
5b4f08
+    """
5b4f08
+    with open(mtab, 'r') as f:
5b4f08
+        line = f.readline()
5b4f08
+        return line and line.startswith('overlay /')
5b4f08
+    return False
5b4f08
 
5b4f08
 def init_hook(conduit):
5b4f08
-        if not should_touch():
5b4f08
-                return
5b4f08
+    if not should_touch():
5b4f08
+        return
5b4f08
     ir = conduit.getConf().installroot
5b4f08
-        try:
5b4f08
-                for root, _, files in walk(path.join(ir, base_dir)):
5b4f08
-                        for f in files:
5b4f08
-                                p = path.join(root, f)
5b4f08
-                                with open(p, 'a'):
5b4f08
-                                        utime(p, None)
5b4f08
-        except Exception as e:
5b4f08
-                conduit.error(1, "Error while doing RPMdb copy-up:\n%s" % e)
5b4f08
+    try:
5b4f08
+        for root, _, files in walk(path.join(ir, base_dir)):
5b4f08
+            for f in files:
5b4f08
+                p = path.join(root, f)
5b4f08
+                with open(p, 'a'):
5b4f08
+                    utime(p, None)
5b4f08
+    except Exception as e:
5b4f08
+        conduit.error(1, "Error while doing RPMdb copy-up:\n%s" % e)
5b4f08
commit 617d2d90a553f9e5bc4dfd9ab2f9c194b956fcab
5b4f08
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5b4f08
Date:   Thu Jun 25 12:53:39 2015 +0200
5b4f08
5b4f08
    ovl plugin: get rpmdbpath from conduit
5b4f08
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
index eda784e..f2fbdd4 100644
5b4f08
--- a/plugins/ovl/ovl.py
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -21,7 +21,6 @@ from os import utime, walk, path
5b4f08
 
5b4f08
 requires_api_version = '2.3'
5b4f08
 plugin_type = (TYPE_CORE,)
5b4f08
-base_dir = 'var/lib/rpm/'
5b4f08
 mtab = '/etc/mtab'
5b4f08
 
5b4f08
 def should_touch():
5b4f08
@@ -34,12 +33,12 @@ def should_touch():
5b4f08
         return line and line.startswith('overlay /')
5b4f08
     return False
5b4f08
 
5b4f08
-def init_hook(conduit):
5b4f08
+def prereposetup_hook(conduit):
5b4f08
     if not should_touch():
5b4f08
         return
5b4f08
-    ir = conduit.getConf().installroot
5b4f08
+    rpmdb_path = conduit.getRpmDB()._rpmdbpath
5b4f08
     try:
5b4f08
-        for root, _, files in walk(path.join(ir, base_dir)):
5b4f08
+        for root, _, files in walk(rpmdb_path):
5b4f08
             for f in files:
5b4f08
                 p = path.join(root, f)
5b4f08
                 with open(p, 'a'):
5b4f08
commit 5cd70d30bcdbd544e086a1aa3e7522c89bbd893a
5b4f08
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5b4f08
Date:   Tue Aug 4 12:00:37 2015 +0200
5b4f08
5b4f08
    ovl plugin: change copy-up strategy, execute when root fs is mounted OverlayFS, add logging. Patch by Pavel Odvody.
5b4f08
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
index f2fbdd4..8dd0a9e 100644
5b4f08
--- a/plugins/ovl/ovl.py
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -1,47 +1,93 @@
5b4f08
-# Copyright (C) 2015  Red Hat, Inc.
5b4f08
-#
5b4f08
-# Authors: Pavel Odvody <podvody@redhat.com>
5b4f08
-#
5b4f08
-# This copyrighted material is made available to anyone wishing to use,
5b4f08
-# modify, copy, or redistribute it subject to the terms and conditions of
5b4f08
-# the GNU General Public License v.2, or (at your option) any later version.
5b4f08
-# This program is distributed in the hope that it will be useful, but WITHOUT
5b4f08
-# ANY WARRANTY expressed or implied, including the implied warranties of
5b4f08
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
5b4f08
-# Public License for more details.  You should have received a copy of the
5b4f08
-# GNU General Public License along with this program; if not, write to the
5b4f08
-# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
5b4f08
-# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
5b4f08
-# source code or documentation are not subject to the GNU General Public
5b4f08
-# License and may only be used or replicated with the express permission of
5b4f08
-# Red Hat, Inc.
5b4f08
-
5b4f08
 from yum.plugins import TYPE_CORE
5b4f08
-from os import utime, walk, path
5b4f08
+from os import walk, path, fstat
5b4f08
 
5b4f08
 requires_api_version = '2.3'
5b4f08
 plugin_type = (TYPE_CORE,)
5b4f08
 mtab = '/etc/mtab'
5b4f08
 
5b4f08
+
5b4f08
+def _stat_ino_fp(fp):
5b4f08
+    """
5b4f08
+    Get the inode number from file descriptor
5b4f08
+    """
5b4f08
+    return fstat(fp.fileno()).st_ino
5b4f08
+
5b4f08
+
5b4f08
+def get_file_list(rpmpath):
5b4f08
+    """
5b4f08
+    Enumerate all files in a directory
5b4f08
+    """
5b4f08
+    for root, _, files in walk(rpmpath):
5b4f08
+        for f in files:
5b4f08
+            yield path.join(root, f)
5b4f08
+
5b4f08
+
5b4f08
+def for_each_file(files, cb, m='rb'):
5b4f08
+    """
5b4f08
+    Open each file with mode specified in `m`
5b4f08
+    and invoke `cb` on each of the file objects
5b4f08
+    """
5b4f08
+    if not files or not cb:
5b4f08
+        return []
5b4f08
+    ret = []
5b4f08
+    for f in files:
5b4f08
+        with open(f, m) as fp:
5b4f08
+            ret.append(cb(fp))
5b4f08
+    return ret
5b4f08
+
5b4f08
+
5b4f08
+def do_detect_copy_up(files):
5b4f08
+    """
5b4f08
+    Open the files first R/O, then R/W and count unique
5b4f08
+    inode numbers
5b4f08
+    """
5b4f08
+    num_files = len(files)
5b4f08
+    lower = for_each_file(files, _stat_ino_fp, 'rb')
5b4f08
+    upper = for_each_file(files, _stat_ino_fp, 'ab')
5b4f08
+    diff = set(lower + upper)
5b4f08
+    return len(diff) - num_files
5b4f08
+
5b4f08
+
5b4f08
+def raw_copy_up(files):
5b4f08
+    """
5b4f08
+    Induce a copy-up by opening R/W
5b4f08
+    """
5b4f08
+    return for_each_file(files, _stat_ino_fp, 'ab')
5b4f08
+
5b4f08
+
5b4f08
+def should_be_verbose(cmd):
5b4f08
+    """
5b4f08
+    If the debuglevel is > 2 then be verbose
5b4f08
+    """
5b4f08
+    if not hasattr(cmd, 'debuglevel'):
5b4f08
+        return False
5b4f08
+    return cmd.debuglevel > 2
5b4f08
+
5b4f08
+
5b4f08
 def should_touch():
5b4f08
     """ 
5b4f08
     Touch the files only once we've verified that
5b4f08
     we're on overlay mount
5b4f08
     """
5b4f08
+    if not path.exists(mtab):
5b4f08
+        return False
5b4f08
     with open(mtab, 'r') as f:
5b4f08
         line = f.readline()
5b4f08
-        return line and line.startswith('overlay /')
5b4f08
+        return line.startswith('overlay / overlay')
5b4f08
     return False
5b4f08
 
5b4f08
+
5b4f08
 def prereposetup_hook(conduit):
5b4f08
     if not should_touch():
5b4f08
         return
5b4f08
+
5b4f08
     rpmdb_path = conduit.getRpmDB()._rpmdbpath
5b4f08
+
5b4f08
     try:
5b4f08
-        for root, _, files in walk(rpmdb_path):
5b4f08
-            for f in files:
5b4f08
-                p = path.join(root, f)
5b4f08
-                with open(p, 'a'):
5b4f08
-                    utime(p, None)
5b4f08
+        files = list(get_file_list(rpmdb_path))
5b4f08
+        if should_be_verbose(conduit.getCmdLine()[0]):
5b4f08
+            conduit.info(1, "ovl: Copying up (%i) files from OverlayFS lower layer" % do_detect_copy_up(files))
5b4f08
+        else:
5b4f08
+            raw_copy_up(files)
5b4f08
     except Exception as e:
5b4f08
-        conduit.error(1, "Error while doing RPMdb copy-up:\n%s" % e)
5b4f08
+        conduit.error(1, "ovl: Error while doing RPMdb copy-up:\n%s" % e)
5b4f08
commit 11e4a7386e2e351e0ff5f8d89663eb66220a6100
5b4f08
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5b4f08
Date:   Tue Aug 4 12:18:49 2015 +0200
5b4f08
5b4f08
    ovl plugin: remove redundant debuglevel check
5b4f08
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
index 8dd0a9e..400d3c7 100644
5b4f08
--- a/plugins/ovl/ovl.py
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -4,6 +4,7 @@ from os import walk, path, fstat
5b4f08
 requires_api_version = '2.3'
5b4f08
 plugin_type = (TYPE_CORE,)
5b4f08
 mtab = '/etc/mtab'
5b4f08
+VERBOSE_DEBUGLEVEL = 3
5b4f08
 
5b4f08
 
5b4f08
 def _stat_ino_fp(fp):
5b4f08
@@ -48,22 +49,6 @@ def do_detect_copy_up(files):
5b4f08
     return len(diff) - num_files
5b4f08
 
5b4f08
 
5b4f08
-def raw_copy_up(files):
5b4f08
-    """
5b4f08
-    Induce a copy-up by opening R/W
5b4f08
-    """
5b4f08
-    return for_each_file(files, _stat_ino_fp, 'ab')
5b4f08
-
5b4f08
-
5b4f08
-def should_be_verbose(cmd):
5b4f08
-    """
5b4f08
-    If the debuglevel is > 2 then be verbose
5b4f08
-    """
5b4f08
-    if not hasattr(cmd, 'debuglevel'):
5b4f08
-        return False
5b4f08
-    return cmd.debuglevel > 2
5b4f08
-
5b4f08
-
5b4f08
 def should_touch():
5b4f08
     """ 
5b4f08
     Touch the files only once we've verified that
5b4f08
@@ -85,9 +70,7 @@ def prereposetup_hook(conduit):
5b4f08
 
5b4f08
     try:
5b4f08
         files = list(get_file_list(rpmdb_path))
5b4f08
-        if should_be_verbose(conduit.getCmdLine()[0]):
5b4f08
-            conduit.info(1, "ovl: Copying up (%i) files from OverlayFS lower layer" % do_detect_copy_up(files))
5b4f08
-        else:
5b4f08
-            raw_copy_up(files)
5b4f08
+        copied_num = do_detect_copy_up(files)
5b4f08
+        conduit.info(VERBOSE_DEBUGLEVEL, "ovl: Copying up (%i) files from OverlayFS lower layer" % copied_num)
5b4f08
     except Exception as e:
5b4f08
         conduit.error(1, "ovl: Error while doing RPMdb copy-up:\n%s" % e)
5b4f08
commit 6f43c2e1aff0ee0746685778544f7b05d2ef78a1
5b4f08
Author: Pavel Odvody <podvody@redhat.com>
5b4f08
Date:   Thu Sep 3 18:09:58 2015 +0200
5b4f08
5b4f08
    Add manpage, remove file-system check
5b4f08
5b4f08
diff --git a/docs/yum-ovl.1 b/docs/yum-ovl.1
5b4f08
new file mode 100644
5b4f08
index 0000000..ddfbfab
5b4f08
--- /dev/null
5b4f08
+++ b/docs/yum-ovl.1
5b4f08
@@ -0,0 +1,22 @@
5b4f08
+.TH "yum\-ovl" "1" "September 2015" "Red Hat" "User Manual"
5b4f08
+.
5b4f08
+.SH "NAME"
5b4f08
+yum\-ovl \- Performs an initial copy\-up of yum(8) package database\.
5b4f08
+.
5b4f08
+.SH "OPTIONS"
5b4f08
+\fB\-d\fR \fIdebug\-level\fR If debug level is \fI2\fR and more, print out the number of files copied up from the lower layer
5b4f08
+.
5b4f08
+.SH "FILES"
5b4f08
+\fI/usr/lib/yum\-plugins/ovl\.py\fR Plugin itself
5b4f08
+.
5b4f08
+.P
5b4f08
+\fI/etc/yum/pluginconf\.d/ovl\.conf\fR Configuration file allowing to enable/disable the plugin
5b4f08
+.
5b4f08
+.SH "AUTHOR"
5b4f08
+Pavel Odvody \fIpodvody@redhat\.com\fR
5b4f08
+.
5b4f08
+.SH "LICENSE"
5b4f08
+2015, Red Hat, Licensed under GPLv2+
5b4f08
+.
5b4f08
+.SH "SEE ALSO"
5b4f08
+yum(1) yum(8)
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
index 400d3c7..3d547ed 100644
5b4f08
--- a/plugins/ovl/ovl.py
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -3,7 +3,6 @@ from os import walk, path, fstat
5b4f08
 
5b4f08
 requires_api_version = '2.3'
5b4f08
 plugin_type = (TYPE_CORE,)
5b4f08
-mtab = '/etc/mtab'
5b4f08
 VERBOSE_DEBUGLEVEL = 3
5b4f08
 
5b4f08
 
5b4f08
@@ -49,23 +48,7 @@ def do_detect_copy_up(files):
5b4f08
     return len(diff) - num_files
5b4f08
 
5b4f08
 
5b4f08
-def should_touch():
5b4f08
-    """ 
5b4f08
-    Touch the files only once we've verified that
5b4f08
-    we're on overlay mount
5b4f08
-    """
5b4f08
-    if not path.exists(mtab):
5b4f08
-        return False
5b4f08
-    with open(mtab, 'r') as f:
5b4f08
-        line = f.readline()
5b4f08
-        return line.startswith('overlay / overlay')
5b4f08
-    return False
5b4f08
-
5b4f08
-
5b4f08
 def prereposetup_hook(conduit):
5b4f08
-    if not should_touch():
5b4f08
-        return
5b4f08
-
5b4f08
     rpmdb_path = conduit.getRpmDB()._rpmdbpath
5b4f08
 
5b4f08
     try:
5b4f08
commit 3980742eb6477c5bd5366222fb033cfc5c95d260
5b4f08
Author: Pavel Odvody <podvody@redhat.com>
5b4f08
Date:   Fri Sep 4 10:38:32 2015 +0200
5b4f08
5b4f08
    Added manpage description and reference to rpmdb
5b4f08
5b4f08
diff --git a/docs/yum-ovl.1 b/docs/yum-ovl.1
5b4f08
index ddfbfab..33e0dfb 100644
5b4f08
--- a/docs/yum-ovl.1
5b4f08
+++ b/docs/yum-ovl.1
5b4f08
@@ -6,6 +6,21 @@ yum\-ovl \- Performs an initial copy\-up of yum(8) package database\.
5b4f08
 .SH "OPTIONS"
5b4f08
 \fB\-d\fR \fIdebug\-level\fR If debug level is \fI2\fR and more, print out the number of files copied up from the lower layer
5b4f08
 .
5b4f08
+.SH "DESCRIPTION"
5b4f08
+Opening a file on OverlayFS in read\-only mode causes the file from
5b4f08
+.br
5b4f08
+lower layer to be opened, then later on, if the same file is opened 
5b4f08
+.br
5b4f08
+in write mode, a copy-up into the upper    layer    takes    place, 
5b4f08
+.br
5b4f08
+resulting into a \fBnew\fR file being opened\.
5b4f08
+.br
5b4f08
+Since yum(8) needs to open the \fBRPMdb\fR first read-only, and then
5b4f08
+.br
5b4f08
+also with write access, we need to copy-up the files beforehand to 
5b4f08
+.br
5b4f08
+make sure that the access is consistent.
5b4f08
+.
5b4f08
 .SH "FILES"
5b4f08
 \fI/usr/lib/yum\-plugins/ovl\.py\fR Plugin itself
5b4f08
 .
5b4f08
@@ -19,4 +34,4 @@ Pavel Odvody \fIpodvody@redhat\.com\fR
5b4f08
 2015, Red Hat, Licensed under GPLv2+
5b4f08
 .
5b4f08
 .SH "SEE ALSO"
5b4f08
-yum(1) yum(8)
5b4f08
+yum(1) yum(8) rpmdb(8)
5b4f08
diff -up yum-utils-1.1.31/docs/Makefile.old yum-utils-1.1.31/docs/Makefile
5b4f08
--- yum-utils-1.1.31/docs/Makefile.old	2015-09-04 17:10:03.460207371 +0200
5b4f08
+++ yum-utils-1.1.31/docs/Makefile	2015-09-04 17:10:19.167260413 +0200
5b4f08
@@ -3,7 +3,7 @@ DOCS = repoquery package-cleanup repo-rs
5b4f08
        yum-groups-manager debuginfo-install repodiff yum-fs-snapshot \
5b4f08
        show-installed show-changed-rco yum-debug-restore \
5b4f08
        find-repos-of-install needs-restarting repo-graph repoclosure \
5b4f08
-       repomanage repotrack verifytree yum-config-manager
5b4f08
+       repomanage repotrack verifytree yum-config-manager yum-ovl
5b4f08
 DOCS5 = yum-changelog.conf yum-versionlock.conf yum-fs-snapshot.conf
5b4f08
 DOCS8 = yum-complete-transaction yumdb
5b4f08
 
5b4f08
commit d03fce57c1fa3f9dff6fdd9867cbcaf66df9f841
5b4f08
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5b4f08
Date:   Fri Oct 9 15:16:33 2015 +0200
5b4f08
5b4f08
    ovl plugin: run at init_hook stage
5b4f08
5b4f08
diff --git a/plugins/ovl/ovl.py b/plugins/ovl/ovl.py
5b4f08
index 3d547ed..fe27022 100644
5b4f08
--- a/plugins/ovl/ovl.py
5b4f08
+++ b/plugins/ovl/ovl.py
5b4f08
@@ -47,9 +47,8 @@ def do_detect_copy_up(files):
5b4f08
     diff = set(lower + upper)
5b4f08
     return len(diff) - num_files
5b4f08
 
5b4f08
-
5b4f08
-def prereposetup_hook(conduit):
5b4f08
-    rpmdb_path = conduit.getRpmDB()._rpmdbpath
5b4f08
+def init_hook(conduit):
5b4f08
+    rpmdb_path = conduit._base.rpmdb._rpmdbpath
5b4f08
 
5b4f08
     try:
5b4f08
         files = list(get_file_list(rpmdb_path))