rbd: Fix the name comparison bug.
Checked the definition of strncmp. If substring s1 is found in strnmp(s1, s2, len), then it will return 0. For the len value, it is better to use strcmp. Otherwise, if s1=cluster1, s2=cluster & len=strlen(s2), strncmp will return 0. But they are two different strings. For cluster names, they are different. Signed-off-by: Ziye Yang <ziye.yang@intel.com> Change-Id: I15a06184d834cd1567b329d0322cd6bdea6fee4b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7991 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: <dongx.yi@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Community-CI: Mellanox Build Bot
This commit is contained in:
parent
1180c390c1
commit
d33f44866d
@ -256,7 +256,7 @@ bdev_rbd_get_cluster(const char *cluster_name, rados_t **cluster)
|
||||
|
||||
pthread_mutex_lock(&g_map_bdev_rbd_cluster_mutex);
|
||||
STAILQ_FOREACH(entry, &g_map_bdev_rbd_cluster, link) {
|
||||
if (strncmp(cluster_name, entry->name, strlen(entry->name)) == 0) {
|
||||
if (strcmp(cluster_name, entry->name) == 0) {
|
||||
entry->ref++;
|
||||
*cluster = &entry->cluster;
|
||||
pthread_mutex_unlock(&g_map_bdev_rbd_cluster_mutex);
|
||||
@ -692,7 +692,7 @@ bdev_rbd_cluster_dump_entry(const char *cluster_name, struct spdk_json_write_ctx
|
||||
|
||||
pthread_mutex_lock(&g_map_bdev_rbd_cluster_mutex);
|
||||
STAILQ_FOREACH(entry, &g_map_bdev_rbd_cluster, link) {
|
||||
if (strncmp(cluster_name, entry->name, strlen(entry->name))) {
|
||||
if (strcmp(cluster_name, entry->name)) {
|
||||
continue;
|
||||
}
|
||||
if (entry->user_id) {
|
||||
@ -808,7 +808,7 @@ rbd_register_cluster(const char *name, const char *user_id, const char *const *c
|
||||
|
||||
pthread_mutex_lock(&g_map_bdev_rbd_cluster_mutex);
|
||||
STAILQ_FOREACH(entry, &g_map_bdev_rbd_cluster, link) {
|
||||
if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
|
||||
if (strcmp(name, entry->name) == 0) {
|
||||
SPDK_ERRLOG("Cluster name=%s already exists\n", name);
|
||||
pthread_mutex_unlock(&g_map_bdev_rbd_cluster_mutex);
|
||||
return -1;
|
||||
@ -907,7 +907,7 @@ bdev_rbd_unregister_cluster(const char *name)
|
||||
|
||||
pthread_mutex_lock(&g_map_bdev_rbd_cluster_mutex);
|
||||
STAILQ_FOREACH(entry, &g_map_bdev_rbd_cluster, link) {
|
||||
if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
|
||||
if (strcmp(name, entry->name) == 0) {
|
||||
if (entry->ref == 0) {
|
||||
STAILQ_REMOVE(&g_map_bdev_rbd_cluster, entry, bdev_rbd_cluster, link);
|
||||
rados_shutdown(entry->cluster);
|
||||
|
Loading…
Reference in New Issue
Block a user