[buildd-tools-devel] [PATCH 4/8] Add filesystem union support to directory chroots

Jan-Marek Glogowski glogow at fbihome.de
Wed May 20 17:55:54 UTC 2009


Change directory chroots to inheritate from chroot_fs_union
instead of chroot and adapt setup scripts, documentation and
tests.
---
 etc/setup.d/00check               |    8 +++++
 etc/setup.d/10mount               |    2 +
 man/schroot.conf.5.in             |    6 ++-
 sbuild/sbuild-chroot-directory.cc |   58 +++++++++++++++++++++++++++++++++++-
 sbuild/sbuild-chroot-directory.h  |   21 ++++++++++++-
 sbuild/sbuild-chroot.cc           |    2 -
 test/sbuild-chroot-directory.cc   |   48 +++++++++++++++++++++---------
 7 files changed, 122 insertions(+), 23 deletions(-)

diff --git a/etc/setup.d/00check b/etc/setup.d/00check
index 11481e2..ff91bd9 100755
--- a/etc/setup.d/00check
+++ b/etc/setup.d/00check
@@ -82,6 +82,14 @@ if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then
 		echo "Directory '$CHROOT_DIRECTORY' does not exist"
 		exit 1
 	    fi
+	    if [ "$CHROOT_FS_UNION_TYPE" != "none" ]; then
+		if [ ! -d "$CHROOT_FS_UNION_OVERLAY_DIRECTORY" ] \
+		    && [ $1 = "setup-recover" ];
+		then
+		    echo "Directory '$CHROOT_FS_UNION_OVERLAY_DIRECTORY' does not exist"
+		    exit 1
+		fi
+	    fi
 	    ;;
 	file | loopback)
 	    if [ ! -f "$CHROOT_FILE" ]; then
diff --git a/etc/setup.d/10mount b/etc/setup.d/10mount
index 6052ebf..1bcda29 100755
--- a/etc/setup.d/10mount
+++ b/etc/setup.d/10mount
@@ -141,9 +141,11 @@ if [ "$CHROOT_TYPE" = "plain" ] || [ "$CHROOT_TYPE" = "directory" ] || [ "$CHROO
     if [ "$CHROOT_TYPE" = "plain" ]; then
 	CHROOT_MOUNT_OPTIONS="--rbind"
 	CHROOT_MOUNT_DEVICE="$CHROOT_DIRECTORY"
+	CHROOT_FS_UNION_RO_BRANCH="$CHROOT_DIRECTORY"
     elif [ "$CHROOT_TYPE" = "directory" ]; then
 	CHROOT_MOUNT_OPTIONS="--bind"
 	CHROOT_MOUNT_DEVICE="$CHROOT_DIRECTORY"
+	CHROOT_FS_UNION_RO_BRANCH="$CHROOT_DIRECTORY"
     elif [ "$CHROOT_TYPE" = "file" ]; then
 	UNPACK_LOCATION="${UNPACK_DIR}/${SESSION_ID}"
 	CHROOT_MOUNT_OPTIONS="--bind"
diff --git a/man/schroot.conf.5.in b/man/schroot.conf.5.in
index 1833e42..fad5890 100644
--- a/man/schroot.conf.5.in
+++ b/man/schroot.conf.5.in
@@ -144,8 +144,10 @@ using the following regular expression:
 Plain and directory chroots
 .PP
 Chroots of type \[oq]plain\[cq] or \[oq]directory\[cq] are directories
-accessible in the filesystem.  The two types are equivalent except for the fact
-that if \f[CI]run\-setup\-scripts\fP is set to \[oq]true\[cq] for
+accessible in the filesystem.  They implement the \fBfilesystem union 
+chroot\fP options (see \[lq]\fIFilesystem Union chroot options\fP\[rq], 
+below).  The two types are equivalent except for the fact that if 
+\f[CI]run\-setup\-scripts\fP is set to \[oq]true\[cq] for
 \[oq]plain\[cq] chroots, filesystem mounting is disabled.
 .PP
 These chroot types have an additional (mandatory) configuration option:
diff --git a/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc
index 96780c8..210bd09 100644
--- a/sbuild/sbuild-chroot-directory.cc
+++ b/sbuild/sbuild-chroot-directory.cc
@@ -32,6 +32,7 @@
 using namespace sbuild;
 
 chroot_directory::chroot_directory ():
+  chroot_fs_union(),
   chroot_plain()
 {
   set_run_setup_scripts(true);
@@ -47,10 +48,37 @@ chroot_directory::clone () const
   return ptr(new chroot_directory(*this));
 }
 
+sbuild::chroot::ptr
+chroot_directory::clone_source () const
+{
+  ptr clone;
+
+  if (get_fs_union_configured()) {
+    clone = ptr(new chroot_directory(*this));
+    chroot_source::clone_source_setup(clone);
+  }
+
+  return ptr(clone);
+}
+
 std::string
 chroot_directory::get_path () const
 {
-  return get_mount_location();
+  // When running setup scripts, we are session-capable, so the path
+  // is the bind-mounted location, rather than the original location.
+  if (get_fs_union_configured())
+    return chroot_fs_union::get_path();
+  if (get_run_setup_scripts() == true)
+    return get_mount_location();
+  else
+    return get_directory();
+}
+
+void
+chroot_directory::setup_env (environment& env)
+{
+  chroot_fs_union::setup_env(env);
+  chroot_plain::setup_env(env);
 }
 
 std::string const&
@@ -78,5 +106,31 @@ chroot_directory::setup_lock (chroot::setup_type type,
 sbuild::chroot::session_flags
 chroot_directory::get_session_flags () const
 {
-  return SESSION_CREATE;
+  if (get_fs_union_configured())
+    return chroot_fs_union::get_session_flags();
+  if (get_run_setup_scripts() == true)
+    return SESSION_CREATE;
+  return SESSION_NOFLAGS;
+}
+
+void
+chroot_directory::get_details (format_detail& detail) const
+{
+  chroot_fs_union::get_details(detail);
+  chroot_plain::get_details(detail);
+}
+
+void
+chroot_directory::get_keyfile (keyfile& keyfile) const
+{
+  chroot_fs_union::get_keyfile(keyfile);
+  chroot_plain::get_keyfile(keyfile);
+}
+
+void
+chroot_directory::set_keyfile (keyfile const& keyfile,
+			      string_list&   used_keys)
+{
+  chroot_fs_union::set_keyfile(keyfile, used_keys);
+  chroot_plain::set_keyfile(keyfile, used_keys);
 }
diff --git a/sbuild/sbuild-chroot-directory.h b/sbuild/sbuild-chroot-directory.h
index c0eb9c4..574aaf1 100644
--- a/sbuild/sbuild-chroot-directory.h
+++ b/sbuild/sbuild-chroot-directory.h
@@ -19,7 +19,8 @@
 #ifndef SBUILD_CHROOT_DIRECTORY_H
 #define SBUILD_CHROOT_DIRECTORY_H
 
-#include <sbuild/sbuild-chroot.h>
+#include <sbuild/sbuild-chroot-fs-union.h>
+#include <sbuild/sbuild-chroot-plain.h>
 
 namespace sbuild
 {
@@ -27,7 +28,7 @@ namespace sbuild
   /**
    * A chroot located in the filesystem.
    */
-  class chroot_directory : virtual public chroot_plain
+  class chroot_directory : public chroot_fs_union, public chroot_plain
   {
   protected:
     /// The constructor.
@@ -42,9 +43,15 @@ namespace sbuild
     virtual chroot::ptr
     clone () const;
 
+    virtual chroot::ptr
+    clone_source () const;
+
     virtual std::string
     get_path () const;
 
+    virtual void
+    setup_env (environment& env);
+
     virtual std::string const&
     get_chroot_type () const;
 
@@ -56,6 +63,16 @@ namespace sbuild
     setup_lock (chroot::setup_type type,
 		bool               lock,
 		int                status);
+
+    virtual void
+    get_details (format_detail& detail) const;
+
+    virtual void
+    get_keyfile (keyfile& keyfile) const;
+
+    virtual void
+    set_keyfile (keyfile const& keyfile,
+                 string_list&   used_keys);
   };
 
 }
diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc
index 6d1b943..d3a52be 100644
--- a/sbuild/sbuild-chroot.cc
+++ b/sbuild/sbuild-chroot.cc
@@ -480,8 +480,6 @@ sbuild::chroot::print_details (std::ostream& stream) const
 void
 sbuild::chroot::get_keyfile (keyfile& keyfile) const
 {
-  keyfile.remove_group(get_name());
-
   keyfile::set_object_value(*this, &chroot::get_chroot_type,
 			    keyfile, get_name(), "type");
 
diff --git a/test/sbuild-chroot-directory.cc b/test/sbuild-chroot-directory.cc
index 5d3d8fa..dc2f925 100644
--- a/test/sbuild-chroot-directory.cc
+++ b/test/sbuild-chroot-directory.cc
@@ -47,7 +47,8 @@ class test_chroot_directory : public test_chroot_base<chroot_directory>
   CPPUNIT_TEST(test_directory);
   CPPUNIT_TEST(test_chroot_type);
   CPPUNIT_TEST(test_setup_env);
-  CPPUNIT_TEST(test_setup_env2);
+  CPPUNIT_TEST(test_setup_env_noscripts);
+  CPPUNIT_TEST(test_setup_env_fsunion);
   CPPUNIT_TEST(test_session_flags);
   CPPUNIT_TEST(test_print_details);
   CPPUNIT_TEST(test_print_config);
@@ -85,11 +86,8 @@ public:
     CPPUNIT_ASSERT(chroot->get_chroot_type() == "directory");
   }
 
-  void test_setup_env()
+  void test_setup_env_initial(sbuild::environment& expected)
   {
-    chroot->set_run_setup_scripts(false);
-
-    sbuild::environment expected;
     expected.add("CHROOT_TYPE",           "directory");
     expected.add("CHROOT_NAME",           "test-name");
     expected.add("CHROOT_DESCRIPTION",    "test-description");
@@ -97,26 +95,46 @@ public:
     expected.add("CHROOT_DIRECTORY",      "/srv/chroot/example-chroot");
     expected.add("CHROOT_PATH",           "/srv/chroot/example-chroot");
     expected.add("CHROOT_SCRIPT_CONFIG",  sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
+    expected.add("CHROOT_SESSION_CREATE", "true");
     expected.add("CHROOT_SESSION_CLONE",  "false");
-    expected.add("CHROOT_SESSION_CREATE", "false");
     expected.add("CHROOT_SESSION_PURGE",  "false");
+    expected.add("CHROOT_FS_UNION_TYPE",  "none");
+    expected.add("CHROOT_PATH",           "/mnt/mount-location");
+  }
 
+  void test_setup_env()
+  {
+    sbuild::environment expected;
+    test_setup_env_initial(expected);
     test_chroot_base<chroot_directory>::test_setup_env(expected);
   }
 
-  void test_setup_env2()
+  void test_setup_env_noscripts()
   {
+    chroot->set_run_setup_scripts(false);
+
     sbuild::environment expected;
-    expected.add("CHROOT_TYPE",           "directory");
-    expected.add("CHROOT_NAME",           "test-name");
-    expected.add("CHROOT_DESCRIPTION",    "test-description");
-    expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
-    expected.add("CHROOT_DIRECTORY",       "/srv/chroot/example-chroot");
+    test_setup_env_initial(expected);
+
+    expected.add("CHROOT_PATH",           "/srv/chroot/example-chroot");
+    expected.add("CHROOT_SESSION_CREATE", "false");
+
+    test_chroot_base<chroot_directory>::test_setup_env(expected);
+  }
+
+  void test_setup_env_fsunion()
+  {
+    sbuild::chroot_directory *c = dynamic_cast<sbuild::chroot_directory *>(chroot.get());
+
+    c->set_fs_union_type("aufs");
+
+    sbuild::environment expected;
+    test_setup_env_initial(expected);
+
     expected.add("CHROOT_PATH",           "/mnt/mount-location");
     expected.add("CHROOT_SCRIPT_CONFIG",  sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
-    expected.add("CHROOT_SESSION_CLONE",  "false");
-    expected.add("CHROOT_SESSION_CREATE", "true");
-    expected.add("CHROOT_SESSION_PURGE",  "false");
+    expected.add("CHROOT_SESSION_CLONE",  "true");
+    expected.add("CHROOT_FS_UNION_TYPE",  "aufs");
 
     test_chroot_base<chroot_directory>::test_setup_env(expected);
   }
-- 
1.6.3.1




More information about the Buildd-tools-devel mailing list