1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
26 #define DEBUG_SUBSYSTEM S_RPC
29 # include <liblustre.h>
32 #include <obd_support.h>
33 #include <obd_class.h>
34 #include <lustre_lib.h>
35 #include <lustre_ha.h>
36 #include <lustre_net.h>
37 #include <lprocfs_status.h>
39 struct uuid_nid_data {
40 struct list_head un_list;
43 int un_count; /* nid/uuid pair refcount */
46 /* FIXME: This should probably become more elegant than a global linked list */
47 static struct list_head g_uuid_list;
48 static spinlock_t g_uuid_lock;
50 void class_init_uuidlist(void)
52 CFS_INIT_LIST_HEAD(&g_uuid_list);
53 spin_lock_init(&g_uuid_lock);
56 void class_exit_uuidlist(void)
62 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index)
64 struct list_head *tmp;
66 spin_lock (&g_uuid_lock);
68 list_for_each(tmp, &g_uuid_list) {
69 struct uuid_nid_data *data =
70 list_entry(tmp, struct uuid_nid_data, un_list);
72 if (!strcmp(data->un_uuid, uuid) &&
74 *peer_nid = data->un_nid;
76 spin_unlock (&g_uuid_lock);
81 spin_unlock (&g_uuid_lock);
85 /* Add a nid to a niduuid. Multiple nids can be added to a single uuid;
86 LNET will choose the best one. */
87 int class_add_uuid(char *uuid, __u64 nid)
89 struct uuid_nid_data *data, *entry;
90 int nob = strnlen (uuid, CFS_PAGE_SIZE) + 1;
93 LASSERT(nid != 0); /* valid newconfig NID is never zero */
95 if (nob > CFS_PAGE_SIZE)
98 OBD_ALLOC(data, sizeof(*data));
102 OBD_ALLOC(data->un_uuid, nob);
104 OBD_FREE(data, sizeof(*data));
108 memcpy(data->un_uuid, uuid, nob);
112 spin_lock (&g_uuid_lock);
113 list_for_each_entry(entry, &g_uuid_list, un_list) {
114 if (entry->un_nid == nid &&
115 (strcmp(entry->un_uuid, uuid) == 0)) {
122 list_add(&data->un_list, &g_uuid_list);
123 spin_unlock (&g_uuid_lock);
126 CDEBUG(D_INFO, "found uuid %s %s cnt=%d\n", uuid,
127 libcfs_nid2str(nid), entry->un_count);
128 OBD_FREE(data->un_uuid, nob);
129 OBD_FREE(data, sizeof(*data));
131 CDEBUG(D_INFO, "add uuid %s %s\n", uuid, libcfs_nid2str(nid));
136 /* Delete the nids for one uuid if specified, otherwise delete all */
137 int class_del_uuid (char *uuid)
139 struct list_head deathrow;
140 struct uuid_nid_data *data, *n;
142 CFS_INIT_LIST_HEAD (&deathrow);
144 spin_lock (&g_uuid_lock);
145 list_for_each_entry_safe(data, n, &g_uuid_list, un_list) {
147 list_del (&data->un_list);
148 list_add (&data->un_list, &deathrow);
149 } else if (strcmp(data->un_uuid, uuid) == 0) {
151 if (data->un_count <= 0) {
152 list_del (&data->un_list);
153 list_add (&data->un_list, &deathrow);
158 spin_unlock (&g_uuid_lock);
160 if (list_empty (&deathrow)) {
162 CERROR("delete non-existent uuid %s\n", uuid);
167 data = list_entry(deathrow.next, struct uuid_nid_data, un_list);
169 list_del (&data->un_list);
170 CDEBUG(D_INFO, "del uuid %s %s\n", data->un_uuid,
171 libcfs_nid2str(data->un_nid));
173 OBD_FREE(data->un_uuid, strlen(data->un_uuid) + 1);
174 OBD_FREE(data, sizeof(*data));
175 } while (!list_empty (&deathrow));