diff options
author | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2017-10-13 09:14:21 +0300 |
---|---|---|
committer | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2017-10-13 09:14:21 +0300 |
commit | adbafb9dc657eb01fdeb6e2bc290e6b64b4005b4 (patch) | |
tree | c28d6821b840916a8c6a03fc77c16e1a88220569 | |
parent | 2c031a69ab37a828b8a0270e8a4bd2bdc9e68f97 (diff) |
Added getopt on main()
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
-rw-r--r-- | include/common.h | 5 | ||||
-rwxr-xr-x | run.sh | 2 | ||||
-rw-r--r-- | src/userspace_io.c | 22 |
3 files changed, 21 insertions, 8 deletions
diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..a9cfca2 --- /dev/null +++ b/include/common.h @@ -0,0 +1,5 @@ +#ifndef _COMMON_H +#define _COMMON_H +#define OPT_DEV (1 << 0) +#define OPT_UUID (1 << 1) +#endif @@ -36,7 +36,7 @@ vf_create() { vf_destroy() { # FIXME only one mdev per ethernet supported for now - echo 1 > /sys/class/mdev_bus/$intf/*/remove > /dev/null + sudo sh -c "echo 1 > /sys/bus/mdev/devices/*/remove > /dev/null" } case "$1" in diff --git a/src/userspace_io.c b/src/userspace_io.c index 4c34708..ef3bdc6 100644 --- a/src/userspace_io.c +++ b/src/userspace_io.c @@ -19,14 +19,21 @@ #include <drivers/driver_ops.h> #include <vfio_api.h> #include <mm_api.h> +#include <common.h> #include <drivers/r8169.h> /* FIXME modularize driver load */ extern const struct driver_ops r8169_ops; +static char help_msg[] = { + "\n" + " -d: device uuid\n" + " -i: device id in /dev/vfio\n" +}; + static void usage(char *name) { - printf("usage: %s <group id>\n", name); + printf("usage: %s [OPTIONS] \n%s\n", name, help_msg); } int main(int argc, char *argv[]) @@ -46,19 +53,22 @@ int main(int argc, char *argv[]) int ret, c; struct driver_ops exec_ops = r8169_ops; char *rx_buff[256]; + uint32_t opts = 0; - while ((c = getopt(argc, argv, "d:i:f:")) != -1) { + while ((c = getopt(argc, argv, "d:i:")) != -1) { switch (c) { case 'd': + strncpy(group_uuid, optarg, sizeof(group_uuid)); + opts |= OPT_UUID; break; case 'i': - break; - case 'f': + group_id = atoi(optarg); + opts |= OPT_DEV; break; } } - if (argc != 3) { + if ((opts & (OPT_UUID | OPT_DEV)) != (OPT_UUID | OPT_DEV)) { usage(argv[0]); return -1; } @@ -73,12 +83,10 @@ int main(int argc, char *argv[]) if (container < 0) goto out; - group_id = atoi(argv[1]); group = get_group(group_id); if (group < 0) goto out; - strncpy(group_uuid, argv[2], sizeof(group_uuid)); device = vfio_init_dev(group, container, &group_status, &iommu_info, &device_info, ®ion_info, group_uuid); |