qdict: Introduce qdict_rename_keys()

A few block drivers will need to rename .bdrv_create options for their
QAPIfication, so let's have a helper function for that.

Backports commit bcebf102ccc3c6db327f341adc379fdf0673ca6b from qemu
This commit is contained in:
Kevin Wolf 2018-03-12 09:38:35 -04:00 committed by Lioncash
parent 418f96df9b
commit 025e354370
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
16 changed files with 54 additions and 0 deletions

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_aarch64
#define qdict_put_obj qdict_put_obj_aarch64
#define qdict_put_str qdict_put_str_aarch64
#define qdict_rename_keys qdict_rename_keys_aarch64
#define qdict_size qdict_size_aarch64
#define qdict_type qdict_type_aarch64
#define qemu_clock_get_us qemu_clock_get_us_aarch64

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_aarch64eb
#define qdict_put_obj qdict_put_obj_aarch64eb
#define qdict_put_str qdict_put_str_aarch64eb
#define qdict_rename_keys qdict_rename_keys_aarch64eb
#define qdict_size qdict_size_aarch64eb
#define qdict_type qdict_type_aarch64eb
#define qemu_clock_get_us qemu_clock_get_us_aarch64eb

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_arm
#define qdict_put_obj qdict_put_obj_arm
#define qdict_put_str qdict_put_str_arm
#define qdict_rename_keys qdict_rename_keys_arm
#define qdict_size qdict_size_arm
#define qdict_type qdict_type_arm
#define qemu_clock_get_us qemu_clock_get_us_arm

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_armeb
#define qdict_put_obj qdict_put_obj_armeb
#define qdict_put_str qdict_put_str_armeb
#define qdict_rename_keys qdict_rename_keys_armeb
#define qdict_size qdict_size_armeb
#define qdict_type qdict_type_armeb
#define qemu_clock_get_us qemu_clock_get_us_armeb

View file

@ -2135,6 +2135,7 @@ symbols = (
'qdict_put_null',
'qdict_put_obj',
'qdict_put_str',
'qdict_rename_keys',
'qdict_size',
'qdict_type',
'qemu_clock_get_us',

View file

@ -79,4 +79,10 @@ QObject *qdict_crumple(const QDict *src, Error **errp);
void qdict_join(QDict *dest, QDict *src, bool overwrite);
typedef struct QDictRenames {
const char *from;
const char *to;
} QDictRenames;
bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp);
#endif /* QDICT_H */

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_m68k
#define qdict_put_obj qdict_put_obj_m68k
#define qdict_put_str qdict_put_str_m68k
#define qdict_rename_keys qdict_rename_keys_m68k
#define qdict_size qdict_size_m68k
#define qdict_type qdict_type_m68k
#define qemu_clock_get_us qemu_clock_get_us_m68k

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_mips
#define qdict_put_obj qdict_put_obj_mips
#define qdict_put_str qdict_put_str_mips
#define qdict_rename_keys qdict_rename_keys_mips
#define qdict_size qdict_size_mips
#define qdict_type qdict_type_mips
#define qemu_clock_get_us qemu_clock_get_us_mips

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_mips64
#define qdict_put_obj qdict_put_obj_mips64
#define qdict_put_str qdict_put_str_mips64
#define qdict_rename_keys qdict_rename_keys_mips64
#define qdict_size qdict_size_mips64
#define qdict_type qdict_type_mips64
#define qemu_clock_get_us qemu_clock_get_us_mips64

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_mips64el
#define qdict_put_obj qdict_put_obj_mips64el
#define qdict_put_str qdict_put_str_mips64el
#define qdict_rename_keys qdict_rename_keys_mips64el
#define qdict_size qdict_size_mips64el
#define qdict_type qdict_type_mips64el
#define qemu_clock_get_us qemu_clock_get_us_mips64el

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_mipsel
#define qdict_put_obj qdict_put_obj_mipsel
#define qdict_put_str qdict_put_str_mipsel
#define qdict_rename_keys qdict_rename_keys_mipsel
#define qdict_size qdict_size_mipsel
#define qdict_type qdict_type_mipsel
#define qemu_clock_get_us qemu_clock_get_us_mipsel

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_powerpc
#define qdict_put_obj qdict_put_obj_powerpc
#define qdict_put_str qdict_put_str_powerpc
#define qdict_rename_keys qdict_rename_keys_powerpc
#define qdict_size qdict_size_powerpc
#define qdict_type qdict_type_powerpc
#define qemu_clock_get_us qemu_clock_get_us_powerpc

View file

@ -563,6 +563,40 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
}
}
/**
* qdict_rename_keys(): Rename keys in qdict according to the replacements
* specified in the array renames. The array must be terminated by an entry
* with from = NULL.
*
* The renames are performed individually in the order of the array, so entries
* may be renamed multiple times and may or may not conflict depending on the
* order of the renames array.
*
* Returns true for success, false in error cases.
*/
bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp)
{
QObject *qobj;
while (renames->from) {
if (qdict_haskey(qdict, renames->from)) {
if (qdict_haskey(qdict, renames->to)) {
error_setg(errp, "'%s' and its alias '%s' can't be used at the "
"same time", renames->to, renames->from);
return false;
}
qobj = qdict_get(qdict, renames->from);
qobject_incref(qobj);
qdict_put_obj(qdict, renames->to, qobj);
qdict_del(qdict, renames->from);
}
renames++;
}
return true;
}
/**
* qdict_flatten(): For each nested QDict with key x, all fields with key y
* are moved to this QDict and their key is renamed to "x.y". For each nested

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_sparc
#define qdict_put_obj qdict_put_obj_sparc
#define qdict_put_str qdict_put_str_sparc
#define qdict_rename_keys qdict_rename_keys_sparc
#define qdict_size qdict_size_sparc
#define qdict_type qdict_type_sparc
#define qemu_clock_get_us qemu_clock_get_us_sparc

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_sparc64
#define qdict_put_obj qdict_put_obj_sparc64
#define qdict_put_str qdict_put_str_sparc64
#define qdict_rename_keys qdict_rename_keys_sparc64
#define qdict_size qdict_size_sparc64
#define qdict_type qdict_type_sparc64
#define qemu_clock_get_us qemu_clock_get_us_sparc64

View file

@ -2129,6 +2129,7 @@
#define qdict_put_null qdict_put_null_x86_64
#define qdict_put_obj qdict_put_obj_x86_64
#define qdict_put_str qdict_put_str_x86_64
#define qdict_rename_keys qdict_rename_keys_x86_64
#define qdict_size qdict_size_x86_64
#define qdict_type qdict_type_x86_64
#define qemu_clock_get_us qemu_clock_get_us_x86_64