From: Andrew Cooper Date: Mon, 12 Feb 2018 11:33:42 +0000 (+0000) Subject: Introduce and use xenstore_init() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a08df2278be1a8d5b677f0ba78e13ca20ae141f8;p=people%2Fandrewcoop%2Fxen-test-framework.git Introduce and use xenstore_init() This really should have been introduced along with xenstore_read(), but the problem only becomes apparent when booting an XTF test as the initial domain. The presence of xenstore must not be assumed. Signed-off-by: Andrew Cooper --- diff --git a/common/lib.c b/common/lib.c index 43142ce..acf4da1 100644 --- a/common/lib.c +++ b/common/lib.c @@ -45,6 +45,11 @@ int xtf_probe_sysctl_interface_version(void) int xtf_get_domid(void) { + int rc = xenstore_init(); + + if ( rc ) + return -1; + const char *str = xenstore_read("domid"); unsigned int domid = 0; diff --git a/common/xenbus.c b/common/xenbus.c index 2888ab0..59159f2 100644 --- a/common/xenbus.c +++ b/common/xenbus.c @@ -108,6 +108,12 @@ static void xenbus_read(void *data, size_t len) } } +int xenstore_init(void) +{ + /* Nothing to initialise. Report the presence of the xenbus ring. */ + return xb_port ? 0 : -ENODEV; +} + const char *xenstore_read(const char *path) { struct xenstore_msg_hdr hdr = { diff --git a/include/xtf/xenstore.h b/include/xtf/xenstore.h index 2c0778e..857d82e 100644 --- a/include/xtf/xenstore.h +++ b/include/xtf/xenstore.h @@ -6,6 +6,12 @@ #ifndef XTF_XENSTORE_H #define XTF_XENSTORE_H +/** + * Initialise XTF ready for xenstore communication. May fail if there is no + * xenbus ring found. + */ +int xenstore_init(void); + /** * Issue a #XS_READ operation for @p key, waiting synchronously for the reply. * diff --git a/tests/selftest/main.c b/tests/selftest/main.c index 1f57cb2..321b082 100644 --- a/tests/selftest/main.c +++ b/tests/selftest/main.c @@ -17,6 +17,7 @@ #include const char test_title[] = "XTF Selftests"; +bool has_xenstore = true; static void test_xenstore(void) { @@ -317,6 +318,11 @@ static void test_driver_init(void) xtf_failure("Fail: apic_init() returned %d\n", rc); } + rc = xenstore_init(); + has_xenstore = !rc; + if ( rc && rc != -ENODEV ) + xtf_failure("Fail: xenstore_init() returned %d\n", rc); + rc = xtf_init_grant_table(1); if ( rc ) xtf_failure("Fail: xtf_init_grant_table(1) returned %d\n", rc); @@ -345,7 +351,6 @@ void test_main(void) write_cr4(cr4); } - test_xenstore(); test_extable(); test_exlog(); test_exec_user(); @@ -356,6 +361,9 @@ void test_main(void) test_custom_idte(); test_driver_init(); + if ( has_xenstore ) + test_xenstore(); + xtf_success(NULL); }