Skip to content
Permalink
Browse files

1, use xenstore-chmod to grant read permissions of Xenstore for TinyVMI;

2, change back event-example, interrupt-event-example;
3, interrupt cannot be captured via console of MiniOS, use hardcoded time/count limits to exit event examples.
  • Loading branch information...
cnlelema committed Jun 9, 2018
1 parent 613240d commit a317bdf72e006cd31612088c676e838d9dcb963e
Showing with 116 additions and 50 deletions.
  1. +22 −0 domain_config
  2. +1 −1 include/domain_id.h
  3. +18 −4 main.c
  4. +45 −15 run.tiny.sh
  5. +16 −16 tests/examples/event-example.c
  6. +2 −2 tests/examples/examples.h
  7. +9 −9 tests/examples/interrupt-event-example.c
  8. +3 −3 tiny-vmi/driver/xen/xen.c
@@ -0,0 +1,22 @@
# -*- mode: python; -*-
#============================================================================
# Python configuration setup for 'xm create'.
# This script sets the parameters used when a domain is created using 'xm create'.
# You use a separate script for each domain you want to create, or
# you can set the parameters for the domain on the xm command line.
#============================================================================

#----------------------------------------------------------------------------
# Kernel image file.
kernel = "mini-os.gz"

# Initial memory allocation (in megabytes) for the new domain.
memory = 32

# A name for your domain. All domains must have different names.
name = "TinyVMI"

on_crash = 'destroy'

seclabel='system_u:system_r:domU_t'

@@ -3,7 +3,7 @@

//Lele: testing with constant values, all need replacement.
// default return value of xen_get_domainid_from_name
#define DOMAIN_ID 1
#define DOMAIN_ID 20000 // deprecated, 20000 as an invalid target VM ID.


/* The following values need to be set before run this:
22 main.c
@@ -7,10 +7,17 @@

#include "config/libvmi_conf_file.h"

#define PRINTTIMESTAMP \
{ struct timeval tv_begin; \
gettimeofday(&tv_begin,NULL); \
ttprint(VMI_TEST_MISC, "%s: TimeStamp: %lld s %lld us\n", __FUNCTION__, (long long)tv_begin.tv_sec,(long long)tv_begin.tv_usec); \
}

int main(void) {

// DOMAIN_NAME is defined in include/domain_id.h
char *name = DOMAIN_NAME;
// char inputStr[10]; //TODO: cannot get input from console of MiniOS.

addr_t vaddr =
// 0xc1c3a000;
@@ -25,20 +32,27 @@ int main(void) {

long long duration;
ttprint(VMI_TEST_MAIN, "Hello, world!\n");
//sleep(2);

PRINTTIMESTAMP;

sleep(2); //let TinyVMI paused here; allows outside 'xenstore-chmod' to grant permissions.

PRINTTIMESTAMP;

// scanf("%s", &inputStr);
// ttprint(VMI_TEST_MAIN, "got input str: %s", inputStr);

gettimeofday(&tv_begin,NULL);

result =
// test_module_list(name);
test_map_addr(name, vaddr);
// test_map_addr(name, vaddr);

/* examples in libvmi */
// map_addr(name,vaddr);
// map_symbol(name, "xen_entry"); // "startup_32"); //"xen_entry"
// module_list(name);
// event_example(name, 0);
event_example(name, 0);
// test_event_example(name, 0);
// interrupt_event_example(name);
// test_interrupt_event_example(name);
@@ -4,6 +4,9 @@ guestXLconfig="/home/smeller/extdisk/lab/vmi/vmidocker/xenGuests/aubu16.cfg"

tinyDir=$(dirname $0)

tinyVM="TinyVMI"
tinyID="0"

waitTime="1"
WAITBOOT="60"

@@ -77,6 +80,45 @@ function checkAndCreateGuest(){
}


# create TinyVMI VM and run it.
# this will also set xenstore permissions after knowing its domain ID.
# It achieve this by the following tricks:
# 1. create TinyVMI as a guest VM;
# 2. pause TinyVMI and get its ID by 'xl domid TinyVMI';
# 3. change xenstore permission by 'xenstore-chmod';
# 4. resume TinyVMI.
function createTinyVMI(){

echo "wait for $waitTime seconds before start tinyVMI"
sleep $waitTime
cd mini-os-x86_64-tinyvmi
xl create -c ../tinyvmi/domain_config &
echo "$tinyVM started"
sleep 1
xl pause $tinyVM

echo "$tinyVM paused"
xl list

tinyID=$(xl domid $tinyVM)
echo "get tinyID: $tinyID"

# now change the permission of xenstore directory.
# this will allow TinyVMI to convert a VM's string name into its
# domain ID.

xenstore-chmod -r '/local/domain' r$tinyID

echo "DONE: xenstore-chmod -r '/local/domain' r$tinyID"
xenstore-ls -p '/local/domain'
# unpause TinyVMI to resume normal run
xl unpause $tinyVM
echo "$tinyVM ($tinyID) unpaused"

cd -

}

checkAndCreateGuest
success="$?" # return 0 if failed, return 1 if success.

@@ -108,11 +150,7 @@ if [ -z $mode ];then
# exit $res
#fi

echo "wait for $waitTime seconds before start tinyVMI"
sleep $waitTime
cd mini-os-x86_64-tinyvmi
xl create -c ../../extras/mini-os/domain_config
cd -
createTinyVMI

elif [ "$mode" == "$justMake" ];then

@@ -138,11 +176,7 @@ elif [ "$mode" == "$makeRun" ];then
exit $res
fi

echo "wait for $waitTime seconds before start tinyVMI"
sleep $waitTime
cd mini-os-x86_64-tinyvmi
xl create -c ../../extras/mini-os/domain_config
cd -
createTinyVMI

else

@@ -164,10 +198,6 @@ else
exit $res
fi

echo "wait for $waitTime seconds before start tinyVMI"
sleep $waitTime
cd mini-os-x86_64-tinyvmi
xl create -c ../../extras/mini-os/domain_config
cd -
createTinyVMI

fi
@@ -415,7 +415,7 @@ status_t event_example (char *name, vmi_pid_t pid )
int inter_duration = 0;
int last_duration_start = 0;
int count = 0;
// while(!interrupted){
while(!interrupted){

ttprint(VMI_TEST_EVENTS, "Waiting for events...(500ms) %d\n", count);
count ++;
@@ -431,22 +431,22 @@ status_t event_example (char *name, vmi_pid_t pid )

inter_duration = duration - last_duration_start;

// if (duration > TEST_TIME_LIMIT){
// break;
// }else if (duration > 100 && inter_duration > 100){
// last_duration_start = duration;
// //gettimeofday(&tv_begin,NULL);
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
// ttprint(VMI_TEST_EVENTS, "\n another 100s passed ...\n");
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
// ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
if (duration > TEST_TIME_LIMIT){
break;
}else if (duration > 100 && inter_duration > 100){
last_duration_start = duration;
//gettimeofday(&tv_begin,NULL);
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
ttprint(VMI_TEST_EVENTS, "\n another 100s passed ...\n");
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");
ttprint(VMI_TEST_EVENTS, "\n ---------------\n");

// }
// }
}
}

ttprint(VMI_TEST_EVENTS, "Finished with test.\n");

@@ -6,9 +6,9 @@
#include "config/libvmi_conf_file.h"


#define TEST_TIME_LIMIT 0 // time in seconds
#define TEST_TIME_LIMIT 60 // time in seconds, used for ending while , such as in event_example.

#define MAX_COUNT_TEST 5 //
#define MAX_COUNT_TEST 100 // iterations when testing functions iteratively, such as in test_event_example.

/**
* accessories
@@ -121,9 +121,9 @@ status_t interrupt_event_example (char *vm_name) {
/* second way of clean exit */
gettimeofday(&tv_begin,NULL);

// while(!interrupted){
while(!interrupted){

// count ++;
count ++;

vmi_events_listen(vmi,500);

@@ -132,14 +132,14 @@ status_t interrupt_event_example (char *vm_name) {
interrupted = -1;
}

// gettimeofday(&tv_end,NULL);
// duration= (tv_end.tv_sec - tv_begin.tv_sec);
gettimeofday(&tv_end,NULL);
duration= (tv_end.tv_sec - tv_begin.tv_sec);

// if (duration > TEST_TIME_LIMIT){
// ttprint(VMI_TEST_EVENTS, "Waiting for events... timeout (%d seconds)\n", TEST_TIME_LIMIT);
// break;
// }
// }
if (duration > TEST_TIME_LIMIT){
ttprint(VMI_TEST_EVENTS, "Waiting for events... timeout (%d seconds)\n", TEST_TIME_LIMIT);
break;
}
}

ttprint(VMI_TEST_EVENTS, "Finished with test.\n");

@@ -281,9 +281,9 @@ uint64_t xen_get_domainid_from_name(
dbprint(VMI_DEBUG_XEN, "%s: get domainid: %d\n",__FUNCTION__, domainid);

if (domainid == VMI_INVALID_DOMID){
dbprint(VMI_DEBUG_XEN, "** failed to get domain id from name **\n");
dbprint(VMI_DEBUG_XEN, "** TODO: write flask policy for libxenstore event channel **\n");
dbprint(VMI_DEBUG_XEN, "** use default domain id: %d\n", DOMAIN_ID);
errprint("** failed to get domain id from name **\n");
errprint("** fix: can use xenstore-chmod to grant permission -- thanks to Tamas\n");
errprint("** use default domain id: %d\n", DOMAIN_ID);
domainid = DOMAIN_ID;
}

0 comments on commit a317bdf

Please sign in to comment.
You can’t perform that action at this time.