4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_RPC
39 #include "../include/obd.h"
40 #include "../include/obd_support.h"
41 #include "../include/obd_class.h"
42 #include "../include/lustre_lib.h"
43 #include "../include/lustre_ha.h"
44 #include "../include/lustre_net.h"
45 #include "../include/lprocfs_status.h"
49 struct uuid_nid_data {
50 struct list_head un_list;
51 struct obd_uuid un_uuid;
53 lnet_nid_t un_nids[NIDS_MAX];
56 /* FIXME: This should probably become more elegant than a global linked list */
57 static struct list_head g_uuid_list;
58 static spinlock_t g_uuid_lock;
60 void class_init_uuidlist(void)
62 INIT_LIST_HEAD(&g_uuid_list);
63 spin_lock_init(&g_uuid_lock);
66 void class_exit_uuidlist(void)
72 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index)
74 struct uuid_nid_data *data;
78 obd_str2uuid(&tmp, uuid);
79 spin_lock(&g_uuid_lock);
80 list_for_each_entry(data, &g_uuid_list, un_list) {
81 if (obd_uuid_equals(&data->un_uuid, &tmp)) {
82 if (index >= data->un_nid_count)
86 *peer_nid = data->un_nids[index];
90 spin_unlock(&g_uuid_lock);
93 EXPORT_SYMBOL(lustre_uuid_to_peer);
95 /* Add a nid to a niduuid. Multiple nids can be added to a single uuid;
96 * LNET will choose the best one.
98 int class_add_uuid(const char *uuid, __u64 nid)
100 struct uuid_nid_data *data, *entry;
103 LASSERT(nid != 0); /* valid newconfig NID is never zero */
105 if (strlen(uuid) > UUID_MAX - 1)
108 data = kzalloc(sizeof(*data), GFP_NOFS);
112 obd_str2uuid(&data->un_uuid, uuid);
113 data->un_nids[0] = nid;
114 data->un_nid_count = 1;
116 spin_lock(&g_uuid_lock);
117 list_for_each_entry(entry, &g_uuid_list, un_list) {
118 if (obd_uuid_equals(&entry->un_uuid, &data->un_uuid)) {
122 for (i = 0; i < entry->un_nid_count; i++)
123 if (nid == entry->un_nids[i])
126 if (i == entry->un_nid_count) {
127 LASSERT(entry->un_nid_count < NIDS_MAX);
128 entry->un_nids[entry->un_nid_count++] = nid;
134 list_add(&data->un_list, &g_uuid_list);
135 spin_unlock(&g_uuid_lock);
138 CDEBUG(D_INFO, "found uuid %s %s cnt=%d\n", uuid,
139 libcfs_nid2str(nid), entry->un_nid_count);
142 CDEBUG(D_INFO, "add uuid %s %s\n", uuid, libcfs_nid2str(nid));
146 EXPORT_SYMBOL(class_add_uuid);
148 /* Delete the nids for one uuid if specified, otherwise delete all */
149 int class_del_uuid(const char *uuid)
152 struct uuid_nid_data *data;
153 struct uuid_nid_data *temp;
155 spin_lock(&g_uuid_lock);
159 obd_str2uuid(&tmp, uuid);
160 list_for_each_entry(data, &g_uuid_list, un_list) {
161 if (obd_uuid_equals(&data->un_uuid, &tmp)) {
162 list_move(&data->un_list, &deathrow);
167 list_splice_init(&g_uuid_list, &deathrow);
169 spin_unlock(&g_uuid_lock);
171 if (uuid && list_empty(&deathrow)) {
172 CDEBUG(D_INFO, "Try to delete a non-existent uuid %s\n", uuid);
176 list_for_each_entry_safe(data, temp, &deathrow, un_list) {
177 list_del(&data->un_list);
179 CDEBUG(D_INFO, "del uuid %s %s/%d\n",
180 obd_uuid2str(&data->un_uuid),
181 libcfs_nid2str(data->un_nids[0]),
190 /* check if @nid exists in nid list of @uuid */
191 int class_check_uuid(struct obd_uuid *uuid, __u64 nid)
193 struct uuid_nid_data *entry;
196 CDEBUG(D_INFO, "check if uuid %s has %s.\n",
197 obd_uuid2str(uuid), libcfs_nid2str(nid));
199 spin_lock(&g_uuid_lock);
200 list_for_each_entry(entry, &g_uuid_list, un_list) {
203 if (!obd_uuid_equals(&entry->un_uuid, uuid))
206 /* found the uuid, check if it has @nid */
207 for (i = 0; i < entry->un_nid_count; i++) {
208 if (entry->un_nids[i] == nid) {
215 spin_unlock(&g_uuid_lock);
218 EXPORT_SYMBOL(class_check_uuid);