Skip to content
Snippets Groups Projects
Commit bb90c167 authored by Jinshan Xiong's avatar Jinshan Xiong
Browse files

b=13149
r=nathan,adilger

Fix the logic in class_del_uuid(). It will return the wrong result when an entry
 has been referenced over once.
parent 13db90f3
No related branches found
No related tags found
No related merge requests found
...@@ -138,43 +138,45 @@ int class_add_uuid(const char *uuid, __u64 nid) ...@@ -138,43 +138,45 @@ int class_add_uuid(const char *uuid, __u64 nid)
int class_del_uuid(const char *uuid) int class_del_uuid(const char *uuid)
{ {
struct list_head deathrow; struct list_head deathrow;
struct uuid_nid_data *data, *n; struct uuid_nid_data *data;
int found = 0;
CFS_INIT_LIST_HEAD (&deathrow); CFS_INIT_LIST_HEAD (&deathrow);
spin_lock (&g_uuid_lock); spin_lock (&g_uuid_lock);
if (uuid == NULL) {
list_for_each_entry_safe(data, n, &g_uuid_list, un_list) { list_splice_init(&g_uuid_list, &deathrow);
if (uuid == NULL) { found = 1;
list_del (&data->un_list); } else {
list_add (&data->un_list, &deathrow); list_for_each_entry(data, &g_uuid_list, un_list) {
} else if (strcmp(data->un_uuid, uuid) == 0) { if (strcmp(data->un_uuid, uuid))
continue;
--data->un_count; --data->un_count;
if (data->un_count <= 0) { LASSERT(data->un_count >= 0);
list_del (&data->un_list); if (data->un_count == 0)
list_add (&data->un_list, &deathrow); list_move(&data->un_list, &deathrow);
} found = 1;
break; break;
} }
} }
spin_unlock (&g_uuid_lock); spin_unlock (&g_uuid_lock);
if (list_empty (&deathrow)) { if (!found) {
if (uuid) if (uuid)
CERROR("delete non-existent uuid %s\n", uuid); CERROR("Try to delete a non-existent uuid %s\n", uuid);
return -EINVAL; return -EINVAL;
} }
do { while (!list_empty(&deathrow)) {
data = list_entry(deathrow.next, struct uuid_nid_data, un_list); data = list_entry(deathrow.next, struct uuid_nid_data, un_list);
list_del(&data->un_list);
list_del (&data->un_list);
CDEBUG(D_INFO, "del uuid %s %s\n", data->un_uuid, CDEBUG(D_INFO, "del uuid %s %s\n", data->un_uuid,
libcfs_nid2str(data->un_nid)); libcfs_nid2str(data->un_nid));
OBD_FREE(data->un_uuid, strlen(data->un_uuid) + 1); OBD_FREE(data->un_uuid, strlen(data->un_uuid) + 1);
OBD_FREE(data, sizeof(*data)); OBD_FREE(data, sizeof(*data));
} while (!list_empty (&deathrow)); }
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment