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

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