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

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