[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 05/11] snapshot: add paired functions for intern
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH 05/11] snapshot: add paired functions for internal snapshot id and name |
Date: |
Tue, 11 Jun 2013 11:14:05 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Sat, Jun 08, 2013 at 02:58:01PM +0800, Wenchao Xia wrote:
> +/*
> + * Every internal snapshot have an ID used by qemu block layer, this function
> + * check whether name used by user mess up with ID. An empty string is also
> + * invalid.
> + */
> +bool snapshot_name_wellformed(const char *name)
> +{
> + char *p;
> + /* variable v is used to remove gcc warning of "ignoring return value"
> and
> + "set but not used" */
> + unsigned long v;
> +
> + if (*name == '\0') {
> + return false;
> + }
> +
> + v = strtoul(name, &p, 10);
> + v++;
> +
> + if (*p == '\0') {
> + /* Numeric string */
> + return false;
> + }
> + return true;
> +}
Shorter function with the same behavior and a rewritten doc comment:
/*
* Return true if the given internal snapshot name is valid, false
* otherwise.
*
* To prevent clashes with internal snapshot IDs, names consisting only
* of digits are rejected. Empty strings are also rejected.
*/
bool snapshot_name_wellformed(const char *name)
{
return strspn(name, "0123456789") != strlen(name);
}
> +
> +/* Following function generate id string, used by block driver, such as
> qcow2.
> + Since no better place to go, place the funtion here for now. */
> +void snapshot_id_string_generate(int id, char *id_str, int id_str_size)
> +{
> + snprintf(id_str, id_str_size, "%d", id);
> +}
Since the caller has to manage id, this function doesn't really abstract
anything. I would keep the snprintf() inline, there's only one caller.
Re: [Qemu-devel] [PATCH 04/11] snapshot: new function bdrv_snapshot_find_by_id_and_name(), Stefan Hajnoczi, 2013/06/11
[Qemu-devel] [PATCH 06/11] snapshot: distinguish id and name in snapshot delete, Wenchao Xia, 2013/06/08