diff options
author | John Levon <john.levon@nutanix.com> | 2021-05-21 10:57:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-21 10:57:02 +0100 |
commit | 300f87e1b02e979da8cec444249f09ea0ef167a0 (patch) | |
tree | 2b9693716a620f50f3b046480c5a7e9f48812bd9 | |
parent | cfe9901919943f14961e1da1c4a823336ff79555 (diff) | |
download | libvfio-user-300f87e1b02e979da8cec444249f09ea0ef167a0.zip libvfio-user-300f87e1b02e979da8cec444249f09ea0ef167a0.tar.gz libvfio-user-300f87e1b02e979da8cec444249f09ea0ef167a0.tar.bz2 |
gpio-pci-idio-16: default to keep running (#470)
Default the gpio device server sample such that it stays running, so that we can
do basic sanity testing of client re-connect.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
-rw-r--r-- | samples/gpio-pci-idio-16.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 138a861..f9caa04 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -141,6 +141,7 @@ main(int argc, char *argv[]) { int ret; bool verbose = false; + bool restart = true; int opt; struct sigaction act = { .sa_handler = _sa_handler }; vfu_ctx_t *vfu_ctx; @@ -157,13 +158,16 @@ main(int argc, char *argv[]) .write_data = &migration_write_data }; - while ((opt = getopt(argc, argv, "v")) != -1) { + while ((opt = getopt(argc, argv, "Rv")) != -1) { switch (opt) { + case 'R': + restart = false; + break; case 'v': verbose = true; break; default: /* '?' */ - fprintf(stderr, "Usage: %s [-v] <socketpath>\n", argv[0]); + fprintf(stderr, "Usage: %s [-Rv] <socketpath>\n", argv[0]); exit(EXIT_FAILURE); } } @@ -237,12 +241,19 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to attach device"); } - ret = vfu_run_ctx(vfu_ctx); - if (ret != 0) { - if (errno != ENOTCONN && errno != EINTR) { - err(EXIT_FAILURE, "failed to realize device emulation"); + do { + ret = vfu_run_ctx(vfu_ctx); + if (ret != 0) { + if (errno == ENOTCONN) { + ret = vfu_attach_ctx(vfu_ctx); + if (ret < 0) { + err(EXIT_FAILURE, "failed to re-attach device"); + } + } else if (errno != EINTR) { + err(EXIT_FAILURE, "vfu_run_ctx() failed"); + } } - } + } while (restart); vfu_destroy_ctx(vfu_ctx); return EXIT_SUCCESS; |