[Buildd-tools-devel] [PATCH 22/22] Filesystem union support for block-device chroots

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


Probably one should disable filesystem union support for LVM.
This can be easily done by defining an set_fs_union_type
function which fails on fs_union_type != "none".
---
 bin/schroot/setup/10mount            |   13 +++++++-
 sbuild/sbuild-chroot-block-device.cc |   49 ++++++++++++++++++++++------------
 sbuild/sbuild-chroot-block-device.h  |    6 +++-
 sbuild/sbuild-chroot-lvm-snapshot.cc |   11 +++----
 sbuild/sbuild-chroot-lvm-snapshot.h  |    4 +--
 test/sbuild-chroot-block-device.cc   |    1 +
 test/sbuild-chroot-lvm-snapshot.cc   |    1 +
 7 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/bin/schroot/setup/10mount b/bin/schroot/setup/10mount
index d952db8..29ab074 100755
--- a/bin/schroot/setup/10mount
+++ b/bin/schroot/setup/10mount
@@ -184,8 +184,6 @@ if [ "$CHROOT_TYPE" = "plain" ] || [ "$CHROOT_TYPE" = "directory" ] || [ "$CHROO
 	CHROOT_MOUNT_DEVICE="$UNPACK_LOCATION"
     elif [ "$CHROOT_TYPE" = "lvm-snapshot" ]; then
 	CHROOT_MOUNT_DEVICE="$CHROOT_LVM_SNAPSHOT_DEVICE"
-    elif [ "$CHROOT_TYPE" = "block-device" ]; then
-	CHROOT_MOUNT_DEVICE="$CHROOT_DEVICE"
     fi
 
     if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then
@@ -232,6 +230,17 @@ if [ "$CHROOT_TYPE" = "plain" ] || [ "$CHROOT_TYPE" = "directory" ] || [ "$CHROO
 		    CHROOT_MOUNT_OPTIONS="${CHROOT_MOUNT_OPTIONS} -o loop"
 		fi
 	    fi
+
+	elif [ "$CHROOT_TYPE" = "block-device" ]; then
+	    if [ "xyes" = "x${CREATE_FS_UNION}" ]; then
+		if ! do_mount_block_device "$CHROOT_MOUNT_OPTIONS" "$CHROOT_MOUNT_DEVICE"
+		then
+		    exit 1
+		fi
+		CHROOT_FS_UNION_RO_BRANCH="${MOUNT_DIR}/${CHROOT_MOUNT_UUID}"
+	    else
+		CHROOT_MOUNT_DEVICE="$CHROOT_DEVICE"
+	    fi
 	fi
 
         # If recovering, we want to remount all filesystems to ensure
diff --git a/sbuild/sbuild-chroot-block-device.cc b/sbuild/sbuild-chroot-block-device.cc
index e704a09..5fb6315 100644
--- a/sbuild/sbuild-chroot-block-device.cc
+++ b/sbuild/sbuild-chroot-block-device.cc
@@ -32,7 +32,7 @@ using boost::format;
 using namespace sbuild;
 
 chroot_block_device::chroot_block_device ():
-  chroot(),
+  chroot_fs_union(),
   chroot_mountable()
 {
 }
@@ -47,20 +47,26 @@ chroot_block_device::clone () const
   return ptr(new chroot_block_device(*this));
 }
 
-void
-chroot_block_device::set_container (std::string const& device)
+sbuild::chroot::ptr
+chroot_block_device::clone_source () const
 {
-  if (!is_absname(device))
-    throw error(device, DEVICE_ABS);
+  ptr clone;
 
-  chroot::set_container(device);
+  if (get_fs_union_configured()) {
+    clone = ptr(new chroot_block_device(*this));
+    chroot_source::clone_source_setup(clone);
+  }
+
+  return ptr(clone);
 }
 
 void
-chroot_block_device::setup_env (environment& env)
+chroot_block_device::set_container (std::string const& device)
 {
-  chroot::setup_env(env);
-  chroot_mountable::setup_env(env);
+  if (!is_absname(device))
+    throw chroot::error(device, DEVICE_ABS);
+
+  chroot::set_container(device);
 }
 
 void
@@ -83,7 +89,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
     {
       if (!stat(device).is_block())
 	{
-	  throw error(device, DEVICE_NOTBLOCK);
+	  throw chroot::error(device, DEVICE_NOTBLOCK);
 	}
       else
 	{
@@ -96,7 +102,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
 		}
 	      catch (sbuild::lock::error const& e)
 		{
-		  throw error(device, DEVICE_LOCK, e);
+		  throw chroot::error(device, DEVICE_LOCK, e);
 		}
 	    }
 	  else
@@ -107,7 +113,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
 		}
 	      catch (sbuild::lock::error const& e)
 		{
-		  throw error(device, DEVICE_UNLOCK, e);
+		  throw chroot::error(device, DEVICE_UNLOCK, e);
 		}
 	    }
 	}
@@ -126,20 +132,29 @@ chroot_block_device::setup_lock (chroot::setup_type type,
 sbuild::chroot::session_flags
 chroot_block_device::get_session_flags () const
 {
-  return SESSION_NOFLAGS | chroot_mountable::get_session_flags();
+  return SESSION_NOFLAGS 
+	| chroot_fs_union::get_session_flags()
+	| chroot_mountable::get_session_flags();
 }
 
+ void
+ chroot_block_device::setup_env (environment& env)
+ {
+  chroot_fs_union::setup_env(env);
+  chroot_mountable::setup_env(env);
+ }
+ 
 void
 chroot_block_device::get_details (format_detail& detail) const
 {
-  this->chroot::get_details(detail);
-  this->chroot_mountable::get_details(detail);
+  chroot_fs_union::get_details(detail);
+  chroot_mountable::get_details(detail);
 }
 
 void
 chroot_block_device::get_keyfile (keyfile& keyfile) const
 {
-  chroot::get_keyfile(keyfile);
+  chroot_fs_union::get_keyfile(keyfile);
   chroot_mountable::get_keyfile(keyfile);
 }
 
@@ -147,7 +162,7 @@ void
 chroot_block_device::set_keyfile (keyfile const& keyfile,
 				  string_list&   used_keys)
 {
-  chroot::set_keyfile(keyfile, used_keys);
+  chroot_fs_union::set_keyfile(keyfile, used_keys);
   chroot_mountable::set_keyfile(keyfile, used_keys);
 }
 
diff --git a/sbuild/sbuild-chroot-block-device.h b/sbuild/sbuild-chroot-block-device.h
index 9b53ec9..420dc2d 100644
--- a/sbuild/sbuild-chroot-block-device.h
+++ b/sbuild/sbuild-chroot-block-device.h
@@ -19,7 +19,7 @@
 #ifndef SBUILD_CHROOT_BLOCK_DEVICE_H
 #define SBUILD_CHROOT_BLOCK_DEVICE_H
 
-#include <sbuild/sbuild-chroot.h>
+#include <sbuild/sbuild-chroot-fs-union.h>
 #include <sbuild/sbuild-chroot-mountable.h>
 
 namespace sbuild
@@ -30,7 +30,7 @@ namespace sbuild
    *
    * The device will be mounted on demand.
    */
-  class chroot_block_device : virtual public chroot,
+  class chroot_block_device : public chroot_fs_union,
 			      public chroot_mountable
   {
   protected:
@@ -46,6 +46,8 @@ namespace sbuild
     virtual chroot::ptr
     clone () const;
 
+    virtual chroot::ptr
+    clone_source () const;
 
     /**
      * Set the block device of the chroot.  This is the "source" device.
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.cc b/sbuild/sbuild-chroot-lvm-snapshot.cc
index 4423b62..2855738 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.cc
+++ b/sbuild/sbuild-chroot-lvm-snapshot.cc
@@ -33,7 +33,6 @@ using namespace sbuild;
 
 chroot_lvm_snapshot::chroot_lvm_snapshot ():
   chroot_block_device(),
-  chroot_source(),
   snapshot_device(),
   snapshot_options()
 {
@@ -71,7 +70,7 @@ void
 chroot_lvm_snapshot::set_snapshot_device (std::string const& snapshot_device)
 {
   if (!is_absname(snapshot_device))
-    throw error(snapshot_device, DEVICE_ABS);
+    throw chroot::error(snapshot_device, DEVICE_ABS);
 
   this->snapshot_device = snapshot_device;
 }
@@ -116,14 +115,14 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
 	device = get_snapshot_device();
 
       if (device.empty())
-	throw error(CHROOT_DEVICE);
+	throw chroot::error(CHROOT_DEVICE);
 
       try
 	{
 	  stat file_status(device);
 	  if (!file_status.is_block())
 	    {
-	      throw error(device, DEVICE_NOTBLOCK);
+	      throw chroot::error(device, DEVICE_NOTBLOCK);
 	    }
 	  else
 	    {
@@ -141,7 +140,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
 		    }
 		  catch (sbuild::lock::error const& e)
 		    {
-		      throw error(device, DEVICE_LOCK, e);
+		      throw chroot::error(device, DEVICE_LOCK, e);
 		    }
 		}
 	      else
@@ -152,7 +151,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
 		    }
 		  catch (sbuild::lock::error const& e)
 		    {
-		      throw error(device, DEVICE_UNLOCK, e);
+		      throw chroot::error(device, DEVICE_UNLOCK, e);
 		    }
 		}
 	    }
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.h b/sbuild/sbuild-chroot-lvm-snapshot.h
index fe6048a..6a8ee05 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.h
+++ b/sbuild/sbuild-chroot-lvm-snapshot.h
@@ -20,7 +20,6 @@
 #define SBUILD_CHROOT_LVM_SNAPSHOT_H
 
 #include <sbuild/sbuild-chroot-block-device.h>
-#include <sbuild/sbuild-chroot-source.h>
 
 namespace sbuild
 {
@@ -30,8 +29,7 @@ namespace sbuild
    *
    * A snapshot LV will be created and mounted on demand.
    */
-  class chroot_lvm_snapshot : public chroot_block_device,
-			      public chroot_source
+  class chroot_lvm_snapshot : public chroot_block_device
   {
   protected:
     /// The constructor.
diff --git a/test/sbuild-chroot-block-device.cc b/test/sbuild-chroot-block-device.cc
index 88ed25f..2e73a91 100644
--- a/test/sbuild-chroot-block-device.cc
+++ b/test/sbuild-chroot-block-device.cc
@@ -111,6 +111,7 @@ public:
     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");
 
     test_chroot_base<chroot_block_device>::test_setup_env(expected);
   }
diff --git a/test/sbuild-chroot-lvm-snapshot.cc b/test/sbuild-chroot-lvm-snapshot.cc
index d269abe..454fbd6 100644
--- a/test/sbuild-chroot-lvm-snapshot.cc
+++ b/test/sbuild-chroot-lvm-snapshot.cc
@@ -118,6 +118,7 @@ public:
     expected.add("CHROOT_SESSION_CLONE",  "true");
     expected.add("CHROOT_SESSION_CREATE", "true");
     expected.add("CHROOT_SESSION_PURGE",  "false");
+    expected.add("CHROOT_FS_UNION_TYPE",  "none");
 
     test_chroot_base<chroot_lvm_snapshot>::test_setup_env(expected);
   }
-- 
1.6.2.1




More information about the Buildd-tools-devel mailing list