[Buildd-tools-devel] [PATCH 16/22] Add filesystem union support to directory chroots

Jan-Marek Glogowski glogow at fbihome.de
Thu Mar 26 21:13:54 UTC 2009


Change directory and plain chroots to inheritate from
chroot_fs_union instead of chroot and adapt setup scripts,
documentation and tests.
---
 bin/schroot/schroot.conf.5.in     |    6 +++-
 bin/schroot/setup/00check         |    8 ++++++
 bin/schroot/setup/10mount         |    2 +
 sbuild/sbuild-chroot-directory.cc |   49 ++++++++++++++++++++++++-------------
 sbuild/sbuild-chroot-directory.h  |   13 ++++++----
 sbuild/sbuild-chroot-plain.cc     |   13 ++++++++++
 sbuild/sbuild-chroot-plain.h      |    3 ++
 test/sbuild-chroot-directory.cc   |   35 +++++++++++++++++++++-----
 test/sbuild-chroot-plain.cc       |    5 ++-
 9 files changed, 101 insertions(+), 33 deletions(-)

diff --git a/bin/schroot/schroot.conf.5.in b/bin/schroot/schroot.conf.5.in
index 90b55ab..b197bce 100644
--- a/bin/schroot/schroot.conf.5.in
+++ b/bin/schroot/schroot.conf.5.in
@@ -147,8 +147,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/bin/schroot/setup/00check b/bin/schroot/setup/00check
index e795d8f..5ece5c8 100755
--- a/bin/schroot/setup/00check
+++ b/bin/schroot/setup/00check
@@ -83,6 +83,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/bin/schroot/setup/10mount b/bin/schroot/setup/10mount
index 7c174d9..0a5dc65 100755
--- a/bin/schroot/setup/10mount
+++ b/bin/schroot/setup/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/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc
index 2ffd5b0..7afc603 100644
--- a/sbuild/sbuild-chroot-directory.cc
+++ b/sbuild/sbuild-chroot-directory.cc
@@ -32,7 +32,7 @@
 using namespace sbuild;
 
 chroot_directory::chroot_directory ():
-  chroot()
+  chroot_fs_union()
 {
 }
 
@@ -46,15 +46,29 @@ 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
 {
   // 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_container();
+  return get_container();
 }
 
 void
@@ -75,20 +89,11 @@ chroot_directory::setup_lock (chroot::setup_type type,
     }
 }
 
-sbuild::chroot::session_flags
-chroot_directory::get_session_flags () const
-{
-  if (get_run_setup_scripts() == true)
-    return SESSION_CREATE;
-  else
-    return SESSION_NOFLAGS;
-}
-
 void
 chroot_directory::set_container (std::string const& directory)
 {
   if (!directory.empty() && !is_absname(directory))
-    throw error(directory, LOCATION_ABS);
+    throw chroot::error(directory, LOCATION_ABS);
 
   chroot::set_container(directory);
 }
@@ -96,21 +101,31 @@ chroot_directory::set_container (std::string const& directory)
 void
 chroot_directory::setup_env (environment& env)
 {
-  chroot::setup_env(env);
+  chroot_fs_union::setup_env(env);
   env.add("CHROOT_DIRECTORY", get_container());
 }
 
+sbuild::chroot::session_flags
+chroot_directory::get_session_flags () const
+{
+  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::get_details(detail);
+  chroot_fs_union::get_details(detail);
   detail.add(_("Directory"), get_container());
 }
 
 void
 chroot_directory::get_keyfile (keyfile& keyfile) const
 {
-  chroot::get_keyfile(keyfile);
+  chroot_fs_union::get_keyfile(keyfile);
 
   keyfile::set_object_value(*(static_cast<const sbuild::chroot*>(this)), 
 			    &chroot::get_container,
@@ -121,7 +136,7 @@ void
 chroot_directory::set_keyfile (keyfile const& keyfile,
 			       string_list&   used_keys)
 {
-  chroot::set_keyfile(keyfile, used_keys);
+  chroot_fs_union::set_keyfile(keyfile, used_keys);
 
   // Transition from previous location key to directory key
   keyfile::priority prio_directory, prio_location;
diff --git a/sbuild/sbuild-chroot-directory.h b/sbuild/sbuild-chroot-directory.h
index 117e951..c9cf4b2 100644
--- a/sbuild/sbuild-chroot-directory.h
+++ b/sbuild/sbuild-chroot-directory.h
@@ -19,7 +19,7 @@
 #ifndef SBUILD_CHROOT_DIRECTORY_H
 #define SBUILD_CHROOT_DIRECTORY_H
 
-#include <sbuild/sbuild-chroot.h>
+#include <sbuild/sbuild-chroot-fs-union.h>
 
 namespace sbuild
 {
@@ -27,7 +27,7 @@ namespace sbuild
   /**
    * A chroot located in the filesystem.
    */
-  class chroot_directory : virtual public chroot
+  class chroot_directory : public chroot_fs_union
   {
   protected:
     /// The constructor.
@@ -42,6 +42,9 @@ namespace sbuild
     virtual chroot::ptr
     clone () const;
 
+    virtual chroot::ptr
+    clone_source () const;
+
     /**
      * Set the directory location of the chroot.
      *
@@ -58,15 +61,15 @@ namespace sbuild
 			std::string *key_name,
 			std::string *detail_name) const;
 
-    virtual session_flags
-    get_session_flags () const;
-
     virtual void
     setup_env (environment& env);
 
     virtual void
     get_details (format_detail& detail) const;
 
+    virtual session_flags
+    get_session_flags () const;
+
     virtual void
     get_keyfile (keyfile& keyfile) const;
 
diff --git a/sbuild/sbuild-chroot-plain.cc b/sbuild/sbuild-chroot-plain.cc
index 3852324..9f1df59 100644
--- a/sbuild/sbuild-chroot-plain.cc
+++ b/sbuild/sbuild-chroot-plain.cc
@@ -46,6 +46,19 @@ chroot_plain::clone () const
   return ptr(new chroot_plain(*this));
 }
 
+sbuild::chroot::ptr
+chroot_plain::clone_source () const
+{
+  ptr clone;
+
+  if (get_fs_union_configured()) {
+    clone = ptr(new chroot_plain(*this));
+    chroot_source::clone_source_setup(clone);
+  }
+
+  return ptr(clone);
+}
+ 
 void
 chroot_plain::get_chroot_strings (std::string *type,
 				  std::string *key_name,
diff --git a/sbuild/sbuild-chroot-plain.h b/sbuild/sbuild-chroot-plain.h
index 51115d8..32c0368 100644
--- a/sbuild/sbuild-chroot-plain.h
+++ b/sbuild/sbuild-chroot-plain.h
@@ -42,6 +42,9 @@ namespace sbuild
     virtual chroot::ptr
     clone () const;
 
+    chroot::ptr
+    clone_source () const;
+
     virtual void
     get_chroot_strings (std::string *type,
 			std::string *key_name,
diff --git a/test/sbuild-chroot-directory.cc b/test/sbuild-chroot-directory.cc
index 876f5d3..444b694 100644
--- a/test/sbuild-chroot-directory.cc
+++ b/test/sbuild-chroot-directory.cc
@@ -48,7 +48,8 @@ class test_chroot_directory : public test_chroot_base<chroot_directory>
   CPPUNIT_TEST(test_location);
   CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
-  CPPUNIT_TEST(test_setup_env2);
+  CPPUNIT_TEST(test_setup_env_scripts);
+  CPPUNIT_TEST(test_setup_env_fsunion);
   CPPUNIT_TEST(test_session_flags);
   CPPUNIT_TEST(test_print_details);
   CPPUNIT_TEST(test_print_config);
@@ -95,7 +96,7 @@ public:
     CPPUNIT_ASSERT(detail_name == "Directory");
   }
 
-  void test_setup_env_common(sbuild::environment& expected)
+  void test_setup_env_initial(sbuild::environment& expected)
   {
     expected.add("CHROOT_TYPE",           "directory");
     expected.add("CHROOT_NAME",           "test-name");
@@ -105,28 +106,48 @@ public:
     expected.add("CHROOT_LOCATION",       "");
     expected.add("CHROOT_DIRECTORY",      "/srv/chroot/example-chroot");
     expected.add("CHROOT_SCRIPT_CONFIG",  sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
+    expected.add("CHROOT_SESSION_CREATE", "false");
     expected.add("CHROOT_SESSION_CLONE",  "false");
     expected.add("CHROOT_SESSION_PURGE",  "false");
+    expected.add("CHROOT_FS_UNION_TYPE",  "none");
+    expected.add("CHROOT_PATH",           "/srv/chroot/example-chroot");
   }
 
   void test_setup_env()
   {
     sbuild::environment expected;
-    test_setup_env_common(expected);
-    expected.add("CHROOT_PATH",           "/srv/chroot/example-chroot");
-    expected.add("CHROOT_SESSION_CREATE", "false");
+    test_setup_env_initial(expected);
+    test_chroot_base<chroot_directory>::test_setup_env(expected);
+  }
+
+  void test_setup_env_scripts()
+  {
+    chroot->set_run_setup_scripts(true);
+
+    sbuild::environment expected;
+    test_setup_env_initial(expected);
+
+    expected.add("CHROOT_PATH",           "/mnt/mount-location");
+    expected.add("CHROOT_SESSION_CREATE", "true");
+    expected.add("CHROOT_FS_UNION_TYPE",  "none");
 
     test_chroot_base<chroot_directory>::test_setup_env(expected);
   }
 
-  void test_setup_env2()
+  void test_setup_env_fsunion()
   {
+    sbuild::chroot_directory *c = dynamic_cast<sbuild::chroot_directory *>(chroot.get());
+
     chroot->set_run_setup_scripts(true);
+    c->set_fs_union_type("aufs");
 
     sbuild::environment expected;
-    test_setup_env_common(expected);
+    test_setup_env_initial(expected);
+
     expected.add("CHROOT_PATH",           "/mnt/mount-location");
     expected.add("CHROOT_SESSION_CREATE", "true");
+    expected.add("CHROOT_SESSION_CLONE",  "true");
+    expected.add("CHROOT_FS_UNION_TYPE",  "aufs");
 
     test_chroot_base<chroot_directory>::test_setup_env(expected);
   }
diff --git a/test/sbuild-chroot-plain.cc b/test/sbuild-chroot-plain.cc
index a56e6ac..18fe54b 100644
--- a/test/sbuild-chroot-plain.cc
+++ b/test/sbuild-chroot-plain.cc
@@ -96,9 +96,10 @@ 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_CLONE", "false");
+    expected.add("CHROOT_SESSION_CLONE",  "false");
     expected.add("CHROOT_SESSION_CREATE", "false");
-    expected.add("CHROOT_SESSION_PURGE", "false");
+    expected.add("CHROOT_SESSION_PURGE",  "false");
+    expected.add("CHROOT_FS_UNION_TYPE",  "none");
 
     test_chroot_base<chroot_plain>::test_setup_env(expected);
   }
-- 
1.6.2.1




More information about the Buildd-tools-devel mailing list