Commit 36cfccdf authored by Leigh Stoller's avatar Leigh Stoller

Add a common callback into mkvnode that allows it to customize

the root fs of the vnode before it is booted. Did not want to
duplicate this code in the libraries.
parent 4cc2a51b
......@@ -13,7 +13,7 @@ use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( $CP $EGREP $NFSMOUNT $UMOUNT $TMPASSWD $SFSSD $SFSCD $RPMCMD
$HOSTSFILE $LOOPBACKMOUNT
$HOSTSFILE $LOOPBACKMOUNT $TMGROUP $TMSHADOW $TMGSHADOW
os_account_cleanup os_ifconfig_line os_etchosts_line
os_setup os_groupadd os_useradd os_userdel os_usermod os_mkdir
os_ifconfig_veth os_viface_name os_modpasswd
......@@ -59,6 +59,9 @@ $NFSMOUNT = "/bin/mount -o vers=2,udp"; # Force NFS Version 2 over UDP
$LOOPBACKMOUNT = "/bin/mount -n -o bind ";
$UMOUNT = "/bin/umount";
$TMPASSWD = "$ETCDIR/passwd";
$TMGROUP = "$ETCDIR/group";
$TMSHADOW = "$ETCDIR/shadow";
$TMGSHADOW = "$ETCDIR/gshadow";
$SFSSD = "/usr/local/sbin/sfssd";
$SFSCD = "/usr/local/sbin/sfscd";
$RPMCMD = "/bin/rpm";
......
......@@ -42,6 +42,7 @@ BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
use libsetup;
use libtmcc;
use libtestbed;
use liblocsetup;
# Pull in libvnode
use libvnode;
......@@ -246,8 +247,24 @@ else {
}
}
#
# Call back to do things to the container before it boots.
#
sub callback($)
{
my ($path) = @_;
if (SHAREDHOST()) {
if (system("/bin/cp -f ".
"$TMGROUP $TMPASSWD $TMSHADOW $TMGSHADOW $path/etc") != 0) {
return -1;
}
}
return 0;
}
# OP: preconfig
if (safeLibOp($vnodeid,'vnodePreConfig',1,1,$vnodeid,$vmid)) {
if (safeLibOp($vnodeid,'vnodePreConfig',1,1,$vnodeid,$vmid,\&callback)) {
MyFatal("vnodePreConfig failed");
}
......
......@@ -9,7 +9,7 @@
package libvnode_openvz;
use Exporter;
@ISA = "Exporter";
@EXPORT = qw( vz_init vz_setDebug
@EXPORT = qw( vz_init vz_setDebug
vz_rootPreConfig vz_rootPreConfigNetwork vz_rootPostConfig
vz_vnodeCreate vz_vnodeDestroy vz_vnodeState
vz_vnodeBoot vz_vnodeHalt vz_vnodeReboot
......@@ -477,7 +477,7 @@ sub vz_vnodeReboot {
}
sub vz_vnodePreConfig {
my ($vnode_id,$vmid) = @_;
my ($vnode_id,$vmid,$callback) = @_;
#
# Look and see if this node already has imq devs mapped into it -- if
......@@ -526,8 +526,19 @@ sub vz_vnodePreConfig {
mysystem("$VZCTL set $vnode_id --netdev_del $dev --save");
}
}
return 0;
#
# Make sure container is mounted before calling the callback.
#
my $status = vmstatus($vmid);
my $didmount = 0;
if ($status ne 'running' && $status ne 'mounted') {
mysystem("$VZCTL mount $vnode_id");
}
my $ret = &$callback("$VZROOT/$vmid");
if ($didmount) {
mysystem("$VZCTL umount $vnode_id");
}
return $ret;
}
#
......
......@@ -110,8 +110,8 @@ sub disk_hacks($){
copy($filetobecopied, $newfile) or die $!;
}
sub createDisk($){
my ($name) = @_;
sub createDisk($$){
my ($name,$callback) = @_;
my $disk = $name;
my $disk_path = "/mnt/xen/disk";
my $root_path = "/mnt/xen/root";
......@@ -130,9 +130,11 @@ sub createDisk($){
# hacks to make things work!
disk_hacks($disk_path);
my $ret = &$callback($disk_path);
mysystem("umount $root_path");
mysystem("umount $disk_path");
return $ret;
}
sub diskName($){
......@@ -198,11 +200,10 @@ sub createConfig($$$){
close FILE;
}
sub vnodePreConfig($){
my ($id,) = @_;
sub vnodePreConfig($$$){
my ($id,$vmid,$callback) = @_;
return 0 if (-e diskName($id));
createDisk(diskName($id));
return 0;
return createDisk(diskName($id),$callback);
}
my @dhcp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment