[buildd-tools-devel] [PATCH 8/8] Filesystem union support for block-device chroots
Jan-Marek Glogowski
glogow at fbihome.de
Wed May 20 17:55:58 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".
---
etc/setup.d/10mount | 11 ++++++++++
sbuild/sbuild-chroot-block-device.cc | 37 +++++++++++++++++++++++----------
sbuild/sbuild-chroot-block-device.h | 7 ++++-
sbuild/sbuild-chroot-fs-union.cc | 1 -
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 +
8 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/etc/setup.d/10mount b/etc/setup.d/10mount
index c659bfa..bedbed0 100755
--- a/etc/setup.d/10mount
+++ b/etc/setup.d/10mount
@@ -228,6 +228,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 3316dd9..c61e363 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(),
device()
{
@@ -48,6 +48,19 @@ chroot_block_device::clone () const
return ptr(new chroot_block_device(*this));
}
+sbuild::chroot::ptr
+chroot_block_device::clone_source () const
+{
+ ptr clone;
+
+ if (get_fs_union_configured()) {
+ clone = ptr(new chroot_block_device(*this));
+ chroot_source::clone_source_setup(clone);
+ }
+
+ return ptr(clone);
+}
+
std::string const&
chroot_block_device::get_device () const
{
@@ -58,7 +71,7 @@ void
chroot_block_device::set_device (std::string const& device)
{
if (!is_absname(device))
- throw error(device, DEVICE_ABS);
+ throw chroot::error(device, DEVICE_ABS);
set_mount_uuid_autodetection();
this->device = device;
@@ -88,7 +101,7 @@ chroot_block_device::get_chroot_type () const
void
chroot_block_device::setup_env (environment& env)
{
- chroot::setup_env(env);
+ chroot_fs_union::setup_env(env);
chroot_mountable::setup_env(env);
env.add("CHROOT_DEVICE", get_device());
@@ -112,7 +125,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
{
if (!stat(this->device).is_block())
{
- throw error(get_device(), DEVICE_NOTBLOCK);
+ throw chroot::error(this->device, DEVICE_NOTBLOCK);
}
else
{
@@ -125,7 +138,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_LOCK, e);
+ throw chroot::error(this->device, DEVICE_LOCK, e);
}
}
else
@@ -136,7 +149,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_UNLOCK, e);
+ throw chroot::error(this->device, DEVICE_UNLOCK, e);
}
}
}
@@ -155,14 +168,16 @@ 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::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);
if (!this->device.empty())
detail.add(_("Device"), get_device());
@@ -171,7 +186,7 @@ chroot_block_device::get_details (format_detail& detail) const
void
chroot_block_device::get_keyfile (keyfile& keyfile) const
{
- chroot::get_keyfile(keyfile);
+ chroot_fs_union::get_keyfile(keyfile);
chroot_mountable::get_keyfile(keyfile);
keyfile::set_object_value(*this, &chroot_block_device::get_device,
@@ -182,7 +197,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);
keyfile::get_object_value(*this, &chroot_block_device::set_device,
diff --git a/sbuild/sbuild-chroot-block-device.h b/sbuild/sbuild-chroot-block-device.h
index 4966943..f83cad3 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,9 @@ namespace sbuild
virtual chroot::ptr
clone () const;
+ virtual chroot::ptr
+ clone_source () const;
+
/**
* Get the block device of the chroot.
*
diff --git a/sbuild/sbuild-chroot-fs-union.cc b/sbuild/sbuild-chroot-fs-union.cc
index b7bdb5a..0d4b824 100644
--- a/sbuild/sbuild-chroot-fs-union.cc
+++ b/sbuild/sbuild-chroot-fs-union.cc
@@ -96,7 +96,6 @@ chroot_fs_union::set_fs_union_type (std::string const& fs_union_type)
if ((fs_union_type == "aufs") || (fs_union_type == "unionfs"))
{
set_run_setup_scripts(true);
- set_run_exec_scripts(true);
this->fs_union_type = fs_union_type;
}
else
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.cc b/sbuild/sbuild-chroot-lvm-snapshot.cc
index 55ec4a9..9d46caf 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()
{
@@ -69,7 +68,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;
chroot_mountable::set_mount_device(snapshot_device);
@@ -123,14 +122,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(get_device(), DEVICE_NOTBLOCK);
+ throw chroot::error(get_device(), DEVICE_NOTBLOCK);
}
else
{
@@ -148,7 +147,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_LOCK, e);
+ throw chroot::error(get_device(), DEVICE_LOCK, e);
}
}
else
@@ -159,7 +158,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_UNLOCK, e);
+ throw chroot::error(get_device(), DEVICE_UNLOCK, e);
}
}
}
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.h b/sbuild/sbuild-chroot-lvm-snapshot.h
index 1e9984a..433a12d 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 3bbd3ca..1baa5fc 100644
--- a/test/sbuild-chroot-block-device.cc
+++ b/test/sbuild-chroot-block-device.cc
@@ -108,6 +108,7 @@ public:
expected.add("CHROOT_SESSION_CLONE", "false");
expected.add("CHROOT_SESSION_CREATE", "true");
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 afb6e5b..9d0c72c 100644
--- a/test/sbuild-chroot-lvm-snapshot.cc
+++ b/test/sbuild-chroot-lvm-snapshot.cc
@@ -115,6 +115,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.3.1
More information about the Buildd-tools-devel
mailing list