All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 94de3f24 authored by Mike Hibler's avatar Mike Hibler

Merge branch 'disk-agent'

parents edb24215 875d650f
......@@ -12,6 +12,9 @@ SYSTEM := $(shell uname -s)
include $(OBJDIR)/Makeconf
SUBDIRS = program-agent link-agent tevc proxy linktest
ifeq ($(SYSTEM),Linux)
SUBDIRS += disk-agent
endif
ifneq ($(SYSTEM),CYGWIN_NT-5.1)
SUBDIRS += trafgen
endif
......
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = @top_builddir@
SUBDIR = $(subst $(TESTBED_SRCDIR)/,,$(SRCDIR))
SYSTEM := $(shell uname -s)
PROGRAMS = disk-agent
include $(OBJDIR)/Makeconf
all: $(PROGRAMS)
include $(TESTBED_SRCDIR)/GNUmakerules
CFLAGS += -DDEBUG
CFLAGS += -O -g -Wall
CFLAGS += -I. -I${OBJDIR}
CFLAGS += -I$(TESTBED_LIBSRCDIR)/event -I$(TESTBED_LIBSRCDIR)/libtb
CFLAGS += -I/usr/local/include
CFLAGS += -DHAVE_PUBSUB
CFLAGS += -DCLIENT_BINDIR='"$(CLIENT_BINDIR)"'
LDFLAGS += -g -L${TESTBED_LIBOBJDIR}/event -L${TESTBED_LIBOBJDIR}/libtb
LIBS += -levent -ltb -lcrypto -ldevmapper
LIBS += -L/usr/local/lib -lpubsub -ldevmapper
LDFLAGS += $(LDSTATIC)
# Deal with the presence/absence of kerberos in the linux ssl library
ifeq ($(SYSTEM),Linux)
ifneq ($(LDSTATIC),)
NOKERB := $(shell nm /usr/lib/libssl.a | grep -q krb; echo $$?)
else
NOKERB := 1
endif
ifeq ($(NOKERB),0)
CFLAGS += `/usr/kerberos/bin/krb5-config --cflags`
LIBS += `/usr/kerberos/bin/krb5-config --libs krb5`
ifneq ($(wildcard /usr/lib/libkrb5support.a),)
LIBS += -lkrb5support
endif
endif
LIBS += -ldl
endif
CXXFLAGS = $(CFLAGS)
disk-agent-debug: disk-agent.o
$(CXX) $(LDFLAGS) -o $@ disk-agent.o $(LIBS)
$(PROGRAMS): ${TESTBED_LIBOBJDIR}/event/libevent.a \
${TESTBED_LIBSRCDIR}/event/event.h
boss-install: $(INSTALL_DIR)/opsdir/sbin/disk-agent
control-install: $(INSTALL_SBINDIR)/disk-agent
post-install:
client: $(PROGRAMS)
client-install: client
$(INSTALL_PROGRAM) disk-agent$(EXE) $(DESTDIR)$(CLIENT_BINDIR)/disk-agent$(EXE)
chmod u+s-w $(DESTDIR)$(CLIENT_BINDIR)/disk-agent
clean:
/bin/rm -f *.o $(PROGRAMS)
$(INSTALL_DIR)/opsdir/sbin/%: %
@echo "Installing $<"
-mkdir -p $(INSTALL_DIR)/opsdir/sbin
$(INSTALL) $< $@
=== DISK AGENT ===
Currently, a couple of things needs to be taken care of before we can run
disk-agent. Those are,
1. Need to fix all the library paths in compile.sh to point to the correct location
2. For linking to devmapper library, we need to copy the libdevmapper.so.* to /lib/
3. Need to change the perl script run.pl to point to the right experiment name
#
# EMULAB-COPYRIGHT
# Copyright (c) 2010 University of Utah and the Flux Group.
# All rights reserved.
#
gcc -c /proj/utahstud/ydev/emulab-devel/clientside/lib/event/event.c -o event.o -I/proj/utahstud/ydev/emulab-devel/clientside/lib \
-I /proj/utahstud/ydev/emulab-devel/clientside/lib/libtb -I/proj/utahstud/ydev/ -L/proj/utahstud/ydev/pubsub
gcc -c /proj/utahstud/ydev/emulab-devel/clientside/lib/event/util.c -o util.o -I/proj/utahstud/ydev/emulab-devel/clientside/lib \
-I /proj/utahstud/ydev/emulab-devel/clientside/lib/libtb -I/proj/utahstud/ydev/ -L/proj/utahstud/ydev/pubsub
ar crv libevent.a event.o util.o
ranlib libevent.a
g++ -g -o disk-agent -Wall -I/proj/utahstud/ydev/emulab-devel/clientside/lib -I/proj/utahstud/ydev/emulab-devel/clientside/lib/libtb \
-I/proj/utahstud/ydev/emulab-devel/event/simple-agent -L/proj/utahstud/ydev/emulab-devel/event/simple-agent -L/proj/utahstud/ydev/pubsub disk-agent.cc libevent.a -ldevmapper -lpubsub -lssl
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _DM_LOGGING_H
#define _DM_LOGGING_H
#include "libdevmapper.h"
extern dm_log_fn dm_log;
extern dm_log_with_errno_fn dm_log_with_errno;
#define LOG_MESG(l, f, ln, e, x...) \
do { \
if (dm_log_is_non_default()) \
dm_log(l, f, ln, ## x); \
else \
dm_log_with_errno(l, f, ln, e, ## x); \
} while (0)
#define LOG_LINE(l, x...) LOG_MESG(l, __FILE__, __LINE__, 0, ## x)
#define LOG_LINE_WITH_ERRNO(l, e, x...) LOG_MESG(l, __FILE__, __LINE__, e, ## x)
#include "log.h"
#endif
This diff is collapsed.
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use Fcntl;
use IO::Handle;
use Socket;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
my $DOSTYPE = "$BINDIR/dostype";
sub mysystem($);
sub usage()
{
print("Usage: mkextrafs.pl [-f] [-lM] [-v <vglist>] <mountpoint>\n");
exit(-1);
}
my $optlist = "flv:M";
#
# Yep, hardwired for now. Should be options or queried via TMCC.
#
my $disk = "hda";
my $slice = "4";
my $partition = "";
my $forceit = 0;
my $lvm = 0;
my @vglist = ();
my $lmonster = 0;
my $flag = 0;
#
# Turn off line buffering on output
#
STDOUT->autoflush(1);
STDERR->autoflush(1);
#
# Untaint the environment.
#
$ENV{'PATH'} = "/tmp:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:".
"/usr/local/bin:/usr/site/bin:/usr/site/sbin:/usr/local/etc/emulab";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"f"})) {
$forceit = 1;
}
if (defined($options{"l"})) {
$lvm = 1;
}
if (defined($options{"v"})) {
@vglist = split(/,/,$options{"v"});
}
if (defined($options{"M"})) {
$lmonster = 1;
if (scalar(@vglist)) {
die("*** $0:\n".
" If you want a single giant LVM-based filesystem, you can" .
" only specify a single volume group name!\n");
}
}
if (scalar(@vglist) == 0) {
@vglist = ('emulab',);
}
my $mountpoint;
if (!$lvm || ($lvm && $lmonster)) {
if (@ARGV != 1) {
usage();
}
$mountpoint = $ARGV[0];
if (! -d $mountpoint) {
die("*** $0:\n".
" $mountpoint does not exist!\n");
}
}
#
# XXX determine the disk based on the root fs
#
my $rootdev = `df | egrep '/\$'`;
if ($rootdev =~ /^\/dev\/([a-z]+)\d+\s+/) {
$disk = $1;
}
my $diskdev = "/dev/${disk}";
my $fsdevice = "${diskdev}${slice}";
#
# An existing fstab entry indicates we have already done this
# XXX override with forceit? Would require unmounting and removing from fstab.
#
if (!system("egrep -q -s '^${fsdevice}' /etc/fstab")) {
$flag=1
# die("*** $0:\n".
# " There is already an entry in /etc/fstab for $fsdevice\n");
}
#
# Likewise, if already mounted somewhere, fail
#
my $mounted = `mount | egrep '^${fsdevice}'`;
if ($mounted =~ /^${fsdevice} on (\S*)/) {
die("*** $0:\n".
" $fsdevice is already mounted on $1\n");
}
my $stype = `sfdisk $diskdev -c $slice`;
if ($stype ne "") {
chomp($stype);
$stype = hex($stype);
}
else {
die("*** $0:\n".
" Could not parse slice $slice fdisk entry!\n");
}
#
# Fail if not forcing and the partition type is non-zero.
#
if (!$forceit) {
if ($stype != 0) {
die("*** $0:\n".
" non-zero partition type ($stype) for ${disk}${slice}, ".
"use -f to override\n");
}
} elsif ($stype && $stype != 131) {
warn("*** $0: WARNING: changing partition type from $stype to 131\n");
}
#
# Before we do anything, do lvm if necessary and do not make any filesystems
# inside the vgs unless they want a single monster fs.
#
if ($lvm) {
my $retval = 0;
my $blockdevs = "$fsdevice";
if ($retval = system("pvcreate $blockdevs")) {
die("*** $0:\n".
" 'pvcreate $blockdevs' failed!\n");
}
foreach my $vg (@vglist) {
if (system("vgcreate $vg $blockdevs")) {
die("*** $0:\n".
" 'vgcreate $vg $blockdevs' failed!\n");
}
}
if ($lmonster) {
if (system("lvcreate -n emulab -l 100\%VG $vglist[0]")) {
die("*** $0:\n".
" 'lvcreate -n emulab -l 100\%VG $vglist[0]' failed!\n");
}
$fsdevice = "/dev/$vglist[0]/emulab";
}
else {
exit(0);
}
}
#
# Set the partition type to Linux if not already set.
#
# XXX sfdisk appears to stomp on partition one's bootblock, at least if it
# is BSD. It zeros bytes in the block 0x200-0x400, I suspect it is attempting
# to invalidate any BSD disklabel. While we could just use a scripted fdisk
# sequence here instead, sfdisk is so much more to-the-point. So, we just
# save off the bootblock, run sfdisk and put the bootblock back.
#
# Would it seek out and destroy other BSD partitions? Don't know.
# I cannot find the source for sfdisk.
#
if (!$lvm && $stype != 131) {
die("*** $0:\n".
" No $DOSTYPE program, cannot set type of DOS partition\n")
if (! -e "$DOSTYPE");
mysystem("$DOSTYPE -f /dev/$disk $slice 131");
}
# eh, quick try for ext3 -- no way we can consistently check the kernel for
# support, off the top of my head
if ( -e "/sbin/mkfs.ext3") {
mysystem("sudo mke2fs -j $fsdevice");
if ( $flag == 0 ) {
mysystem("(echo \"$fsdevice $mountpoint ext3 defaults 0 0\" >> /etc/fstab) 2> /dev/null");
}
}
else {
mysystem("sudo mkfs $fsdevice");
if ( $flag == 0 ) {
mysystem("(echo \"$fsdevice $mountpoint ext2 defaults 0 0\" >> /etc/fstab) 2> /dev/null");
}
}
system("echo $fsdevice");
#mysystem("mount $mountpoint");
#mysystem("mkdir $mountpoint/local");
sub mysystem($)
{
my ($command) = @_;
if (0) {
# print "'$command'\n";
}
else {
# print "'$command'\n";
`$command`;
if ($?) {
die("*** $0:\n".
" Failed: '$command'\n");
}
}
return 0
}
#system("../../../pubsub/pubsubd -v -d -p 4001");
system("./disk-agent -E utahstud/stap3 -s event-server -u disk -p 16505");
#-k /var/emulab/boot/eventkey
......@@ -69,6 +69,7 @@ client: $(PROGRAMS)
client-install: client
$(INSTALL_PROGRAM) program-agent$(EXE) $(DESTDIR)$(CLIENT_BINDIR)/program-agent$(EXE)
chmod u+s-w $(DESTDIR)$(CLIENT_BINDIR)/program-agent
-mkdir -p $(DESTDIR)$(CLIENT_MANDIR)/man8
$(INSTALL) -m 644 $(SRCDIR)/program-agent.8 $(DESTDIR)$(CLIENT_MANDIR)/man8/program-agent.8
......
......@@ -24,7 +24,7 @@ SCRIPTS = $(addprefix $(SRCDIR)/, \
rc.keys rc.trafgen rc.tarfiles rc.rpms rc.progagent \
rc.startcmd rc.simulator rc.topomap rc.firewall \
rc.tiptunnels rc.trace rc.motelog rc.fakejail \
rc.tpmsetup rc.blobs)
rc.tpmsetup rc.blobs rc.diskagent)
SUBBOSS_SCRIPTS = $(addprefix $(SRCDIR)/, \
rc.config rc.misc rc.route \
......@@ -33,7 +33,7 @@ SUBBOSS_SCRIPTS = $(addprefix $(SRCDIR)/, \
rc.keys rc.trafgen rc.tarfiles rc.rpms rc.progagent \
rc.startcmd rc.simulator rc.firewall \
rc.tiptunnels rc.trace rc.motelog rc.fakejail \
rc.tpmsetup rc.mksubboss) # XXX: Add rc.blobs?
rc.tpmsetup rc.mksubboss rc.diskagent) # XXX: Add rc.blobs?
include $(OBJDIR)/Makeconf
......
......@@ -111,7 +111,7 @@ else {
"rc.hostnames", "rc.trace",
"rc.syncserver", "rc.trafgen",
"rc.tarfiles", "rc.rpms", "rc.progagent", "rc.linkagent",
"rc.tiptunnels", "rc.motelog", "rc.simulator"
"rc.tiptunnels", "rc.motelog", "rc.simulator", "rc.diskagent"
);
}
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use POSIX ":sys_wait_h";
use POSIX qw(setsid);
sub usage()
{
print "Usage: " .
scriptname() . " [-j vnodeid] boot|shutdown|reconfig|reset\n";
exit(1);
}
my $optlist = "j:";
my $action = "boot";
my $vnodeid;
# Turn off line buffering on output
$| = 1;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
# Only root.
if ($EUID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself.
#
use libsetup;
use libtmcc;
use librc;
use libtestbed qw(TBBackGround);
# Script specific goo.
my $LOGFILE = LOGDIR() . "/diskgent.debug";
my $WRAPLOG = LOGDIR() . "/diskwrap.debug";
my $PIDFILE = (FAKEJAILED() ? CONFDIR() : "/var/run") . "/diskagent.pid";
my $CONFIG = CONFDIR() . "/diskagents";
my $PAGENT = "$BINDIR/disk-agent";
my $TOKEN = "/var/tmp/diskagent-token";
#
# Not all clients support this.
#
exit(0)
if (MFS() || (REMOTE() && !(REMOTEDED() || PLAB() || FAKEJAILED()
|| JAILED())));
# Protos.
sub doboot();
sub doshutdown();
sub doreconfig();
sub docleanup();
# Parse command line.
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'j'})) {
my $vnodeid = $options{'j'};
libsetup_setvnodeid($vnodeid);
}
# Allow default above.
if (@ARGV) {
$action = $ARGV[0];
}
# Execute the action.
SWITCH: for ($action) {
/^boot$/i && do {
doboot();
last SWITCH;
};
/^shutdown$/i && do {
doshutdown();
last SWITCH;
};
/^reconfig$/i && do {
doreconfig();
last SWITCH;
};
/^cleanup$/i && do {
docleanup();
last SWITCH;
};
fatal("Invalid action: $action");
}
exit(0);
#
# Boot Action.
#
sub doboot()
{
my @agents = ();
#
# Need the pid/eid.
#
my ($pid, $eid, $vname) = check_nickname();
#
# Daemonize and let the boot continue. We have to disconnect and
# change our session id so that we do not killed off (nor the
# trafgen children) when boot script terminates. The downside is
# that we cannot report errors to the caller.
#
if (my $childpid = TBBackGround($WRAPLOG)) {
sleep(2);
# This catches most startup problems.
my $foo = waitpid($childpid, &WNOHANG);
if ($foo) {
my $status = $?;
unlink($PIDFILE);
system("cat $WRAPLOG")
if (-s $WRAPLOG);
fatal("Failed to program agent: $foo $status!");
}
exit(0);
}
# Fully disconnect from bootup.
setsid();
$TOKEN .= ".$$";
while (1) {
if (tmcc(TMCCCMD_DISKS, undef, \@agents) < 0) {
fatal("Could not get progagent config from server!");
}
unlink $CONFIG;
#
# We want to run disk-agent even if there are currently no
# registered agents. But to do that, we need a UID which we
# get from the TMCC creator command. Note that if we do not
# get a UID, we just exit normally without starting the agent.
# This is backward compatible and enables us to boot up unallocated
# nodes (though I am not sure they would ever reach this script).
#
if (@agents == 0) {
my @tmccresults;
if (tmcc(TMCCCMD_CREATOR, undef, \@tmccresults) < 0) {
fatal("Could not get UID for progagent from server!");
}
if ($tmccresults[0] =~ / SWAPPER=([-\w]*)/) {
push(@agents, "UID=$1\n");
} elsif ($tmccresults[0] =~ /^CREATOR=([-\w]*)/) {
push(@agents, "UID=$1\n");
} else {
warning("Cannot determine UID for program agent, not running");
exit(0);
}
}
#
# Write the data to the file. The rc script will interpret it.
# Note that one of the lines (the first) indicates what user to
# run the agent as.
#
if (!open(RUN, ">$CONFIG")) {
fatal("Could not open $CONFIG: $!");
}
foreach my $line (@agents) {
print RUN "$line";
}
close(RUN);
print "Starting Disk Agent ...\n";
my $server = "event-server"; #getlocalevserver();
my $port = "16505";
if (SHADOW()) {
my $boss = $ENV{'BOSSNAME'};
if (!defined($boss)) {
fatal("BOSSNAME is not set in the environment");
}
my ($domain) = ($boss =~ /^[^\.]+\.(.*)$/);
$server = "event-server.${domain}";
#
# See if we need to connect to the compatability gateway.
# Version 0, no elvin compat.
#
if (exists($ENV{'V0_COMPAT'})) {
$port = "-p " . $ENV{'V0_COMPAT'};
}
}
#
# PlanetLab nodes don't have a fixed elvind port, so we need to
# look that up and pass it in. Also for plab, we always restart
# a dead program-agent, regardless of the cause.
#
if (PLAB()) {
my $elvind_port;
if (tmcc(TMCCCMD_PLABCONFIG, undef, \@tmccresults) < 0) {
# this failure does happen...
warning("Could not get plabconfig from server, ".
"waiting awhile and trying again...");