diff options
author | Manikandan Selvaganesh <mselvaga@redhat.com> | 2017-02-14 17:50:27 +0100 |
---|---|---|
committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-03-31 09:07:00 -0400 |
commit | 4c3aa910e7913c34db24f864a33dfb6d1e0234a4 (patch) | |
tree | 14fa41784feddb97a572e1d7bf32401a34c43890 /libglusterfs/src | |
parent | e325479cf222d2f25dbc0a4c6b80bfe5a7f09f43 (diff) |
libglusterfs: add dict_rename_key()
The dict_rename_key() function will be used for converting the
"security.selinux" xattr to "trusted.gluster.selinux" in the upcoming
SELinux xlator.
BUG: 1318100
Change-Id: Ic5d0b9127e2c360d355f02e200a820597e83fa2c
Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
[ndevos: split from change Id8916bd8e064ccf74ba86225ead95f86dc5a1a25]
Reviewed-on: https://review.gluster.org/16616
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Tested-by: Niels de Vos <ndevos@redhat.com>
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/dict.c | 28 | ||||
-rw-r--r-- | libglusterfs/src/dict.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index a0de0947b1a..839b42685e8 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -22,6 +22,7 @@ #include "hashfn.h" #include "logging.h" #include "compat.h" +#include "compat-errno.h" #include "byte-order.h" #include "globals.h" #include "statedump.h" @@ -2387,6 +2388,33 @@ err: return ret; } +int +dict_rename_key (dict_t *this, char *key, char *replace_key) +{ + data_pair_t *pair = NULL; + int ret = -EINVAL; + + /* replacing a key by itself is a NO-OP */ + if (strcmp (key, replace_key) == 0) + return 0; + + LOCK (&this->lock); + { + /* no need to data_ref(pair->value), dict_set_lk() does it */ + pair = dict_lookup_common (this, key); + if (!pair) + ret = -ENODATA; + else + ret = dict_set_lk (this, replace_key, pair->value, 1); + } + UNLOCK (&this->lock); + + if (!ret) + /* only delete the key on success */ + dict_del (this, key); + + return ret; +} /** * Serialization format: diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index a7fb6c78425..bef58e102cc 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -239,6 +239,7 @@ GF_MUST_CHECK int dict_add_dynstr_with_alloc (dict_t *this, char *key, char *str GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str); GF_MUST_CHECK int dict_get_str_boolean (dict_t *this, char *key, int default_val); +GF_MUST_CHECK int dict_rename_key (dict_t *this, char *key, char *replace_key); GF_MUST_CHECK int dict_serialize_value_with_delim (dict_t *this, char *buf, int32_t *serz_len, char delimiter); void |