From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============5730208622307217836==" MIME-Version: 1.0 From: Jiang, Dave Subject: [Accel-config] Re: [PATCH v1 06/11] accel-config: Add mdev create and remove commands Date: Sat, 05 Dec 2020 00:02:31 +0000 Message-ID: In-Reply-To: 20201202193057.299615-7-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============5730208622307217836== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: ramesh.thomas(a)intel.com > Sent: Wednesday, December 2, 2020 12:31 PM > To: accel-config(a)lists.01.org > Cc: Thomas, Ramesh ; Luck, Tony > ; Jiang, Dave > Subject: [PATCH v1 06/11] accel-config: Add mdev create and remove > commands > = > From: Ramesh Thomas Reviewed-by: Dave Jiang > = > Implements following commands - > accel-config create-mdev [|] > accel-config remove-mdev [|] > = > Signed-off-by: Ramesh Thomas > --- > accfg/mdev.c | 123 > ++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 1 deletion(-) > = > diff --git a/accfg/mdev.c b/accfg/mdev.c > index 56c5c68..652b734 100644 > --- a/accfg/mdev.c > +++ b/accfg/mdev.c > @@ -21,12 +21,133 @@ > #include > #include > = > +static int opt_called; > +static struct accfg_device *device; > + > +static int opt_cb_create_mdev(const struct option *opt, const char *arg,= int > unset) > +{ > + char **m; > + > + if (opt->short_name !=3D 'l') > + return -1; > + > + printf("Available mdev types:\n"); > + for (m =3D accfg_mdev_basenames; *m; m++) > + printf("\t%s\n", *m); > + > + opt_called =3D true; > + > + return 0; > +} > + > +static int opt_cb_remove_mdev(const struct option *opt, const char *arg, > int unset) > +{ > + uuid_t uuid; > + char uuid_str[UUID_STR_LEN]; > + struct accfg_device_mdev *mdev; > + enum accfg_mdev_type type; > + > + if (opt->short_name !=3D 'l') > + return -1; > + > + printf("Available mdevs:\n"); > + accfg_device_mdev_foreach(device, mdev) { > + accfg_mdev_get_uuid(mdev, uuid); > + type =3D accfg_mdev_get_type(mdev); > + uuid_unparse(uuid, uuid_str); > + printf("\tuuid:%s, type:%s\n", uuid_str, > + accfg_mdev_basenames[type]); > + } > + opt_called =3D true; > + > + return 0; > +} > + > int cmd_create_mdev(int argc, const char **argv, void *ctx) > { > + char **m; > + int rc, t; > + uuid_t uuid; > + char uuid_str[UUID_STR_LEN]; > + > + const struct option options[] =3D { > + OPT_CALLBACK_NOOPT('l', "list-mdev-types", NULL, NULL, > + "will list available mdev types", > opt_cb_create_mdev), > + OPT_END(), > + }; > + > + const char *const u[] =3D { > + "accfg create-mdev [ type>|]", > + NULL > + }; > + > + if (argc < 3) > + usage_with_options(u, options); > + > + device =3D accfg_ctx_device_get_by_name(ctx, argv[1]); > + if (!device) { > + fprintf(stderr, "Enter a valid device to create mdev\n"); > + usage_with_options(u, options); > + } > + > + argc =3D parse_options(argc, argv, options, u, 0); > + if (opt_called) > + return 0; > + > + for (m =3D accfg_mdev_basenames, t =3D 0; *m; m++, t++) > + if (!strcmp(argv[1], *m)) > + break; > + if (!*m) { > + fprintf(stderr, "Invalid mdev type\n"); > + usage_with_options(u, options); > + } > + > + rc =3D accfg_create_mdev(device, t, uuid); > + if (rc < 0) > + return rc; > + > + uuid_unparse(uuid, uuid_str); > + printf("Created mdev wth uuid: %s\n", uuid_str); > + > return 0; > } > = > int cmd_remove_mdev(int argc, const char **argv, void *ctx) > { > - return 0; > + int rc; > + uuid_t uuid; > + > + const struct option options[] =3D { > + OPT_CALLBACK_NOOPT('l', "list-mdevs", NULL, NULL, > + "will list available mdevs", > opt_cb_remove_mdev), > + OPT_END(), > + }; > + > + const char *const u[] =3D { > + "accfg remove-mdev [|]", > + "Pass null uuid to remove all mdevs", > + NULL > + }; > + > + if (argc < 3) > + usage_with_options(u, options); > + > + device =3D accfg_ctx_device_get_by_name(ctx, argv[1]); > + if (!device) { > + fprintf(stderr, "Enter a valid device to remove mdev\n"); > + usage_with_options(u, options); > + } > + > + argc =3D parse_options(argc, argv, options, u, 0); > + if (opt_called) > + return 0; > + > + if (uuid_parse(argv[1], uuid) < 0) { > + fprintf(stderr, "Invalid uuid\n"); > + usage_with_options(u, options); > + } > + > + rc =3D accfg_remove_mdev(device, uuid); > + > + return rc; > } > -- > 2.26.2 --===============5730208622307217836==--