All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiang, Dave <dave.jiang at intel.com>
To: accel-config@lists.01.org
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	[thread overview]
Message-ID: <f3eb399bc0904d02bf41e9ffc7869c8b@intel.com> (raw)
In-Reply-To: 20201202193057.299615-7-ramesh.thomas@intel.com

[-- Attachment #1: Type: text/plain, Size: 4383 bytes --]



> -----Original Message-----
> From: ramesh.thomas(a)intel.com <ramesh.thomas(a)intel.com>
> Sent: Wednesday, December 2, 2020 12:31 PM
> To: accel-config(a)lists.01.org
> Cc: Thomas, Ramesh <ramesh.thomas(a)intel.com>; Luck, Tony
> <tony.luck(a)intel.com>; Jiang, Dave <dave.jiang(a)intel.com>
> Subject: [PATCH v1 06/11] accel-config: Add mdev create and remove
> commands
> 
> From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Reviewed-by: Dave Jiang <dave.jiang(a)intel.com>

> 
> Implements following commands -
> accel-config create-mdev <device-name> [<mdev-type>|<options>]
> accel-config remove-mdev <device-name> [<uuid>|<options>]
> 
> Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
> ---
>  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 <sys/stat.h>
>  #include <accfg.h>
> 
> +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 != 'l')
> +		return -1;
> +
> +	printf("Available mdev types:\n");
> +	for (m = accfg_mdev_basenames; *m; m++)
> +		printf("\t%s\n", *m);
> +
> +	opt_called = 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 != 'l')
> +		return -1;
> +
> +	printf("Available mdevs:\n");
> +	accfg_device_mdev_foreach(device, mdev) {
> +		accfg_mdev_get_uuid(mdev, uuid);
> +		type = accfg_mdev_get_type(mdev);
> +		uuid_unparse(uuid, uuid_str);
> +		printf("\tuuid:%s, type:%s\n", uuid_str,
> +				accfg_mdev_basenames[type]);
> +	}
> +	opt_called = 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[] = {
> +		OPT_CALLBACK_NOOPT('l', "list-mdev-types", NULL, NULL,
> +				"will list available mdev types",
> opt_cb_create_mdev),
> +		OPT_END(),
> +	};
> +
> +	const char *const u[] = {
> +		"accfg create-mdev <device name> [<mdev
> type>|<options>]",
> +		NULL
> +	};
> +
> +	if (argc < 3)
> +		usage_with_options(u, options);
> +
> +	device = 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 = parse_options(argc, argv, options, u, 0);
> +	if (opt_called)
> +		return 0;
> +
> +	for (m = accfg_mdev_basenames, t = 0; *m; m++, t++)
> +		if (!strcmp(argv[1], *m))
> +			break;
> +	if (!*m) {
> +		fprintf(stderr, "Invalid mdev type\n");
> +		usage_with_options(u, options);
> +	}
> +
> +	rc = 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[] = {
> +		OPT_CALLBACK_NOOPT('l', "list-mdevs", NULL, NULL,
> +				"will list available mdevs",
> opt_cb_remove_mdev),
> +		OPT_END(),
> +	};
> +
> +	const char *const u[] = {
> +		"accfg remove-mdev <device name> [<uuid>|<options>]",
> +		"Pass null uuid to remove all mdevs",
> +		NULL
> +	};
> +
> +	if (argc < 3)
> +		usage_with_options(u, options);
> +
> +	device = 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 = 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 = accfg_remove_mdev(device, uuid);
> +
> +	return rc;
>  }
> --
> 2.26.2

                 reply	other threads:[~2020-12-05  0:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f3eb399bc0904d02bf41e9ffc7869c8b@intel.com \
    --to=accel-config@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.