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 <linux/module.h>
30 # include <linux/init.h>
31 # include <linux/list.h>
33 # include <liblustre.h>
35 #include <linux/obd.h>
36 #include <linux/obd_support.h>
37 #include <linux/obd_class.h>
38 #include <linux/lustre_lib.h>
39 #include <linux/lustre_ha.h>
40 #include <linux/lustre_net.h>
41 #include <linux/lprocfs_status.h>
43 struct uuid_nid_data {
44 struct list_head un_list;
49 /* FIXME: This should probably become more elegant than a global linked list */
50 static struct list_head g_uuid_list;
51 static spinlock_t g_uuid_lock;
53 void class_init_uuidlist(void)
55 INIT_LIST_HEAD(&g_uuid_list);
56 spin_lock_init(&g_uuid_lock);
59 void class_exit_uuidlist(void)
65 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index)
67 struct list_head *tmp;
69 spin_lock (&g_uuid_lock);
71 list_for_each(tmp, &g_uuid_list) {
72 struct uuid_nid_data *data =
73 list_entry(tmp, struct uuid_nid_data, un_list);
75 if (!strcmp(data->un_uuid, uuid) &&
77 *peer_nid = data->un_nid;
79 spin_unlock (&g_uuid_lock);
84 spin_unlock (&g_uuid_lock);
88 int class_add_uuid(char *uuid, __u64 nid)
90 struct uuid_nid_data *data;
92 int nob = strnlen (uuid, PAGE_SIZE) + 1;
94 LASSERT(nid != 0); /* valid newconfig NID is never zero */
100 OBD_ALLOC(data, sizeof(*data));
104 OBD_ALLOC(data->un_uuid, nob);
106 OBD_FREE(data, sizeof(*data));
110 CDEBUG(D_INFO, "add uuid %s %s\n", uuid, libcfs_nid2str(nid));
111 memcpy(data->un_uuid, uuid, nob);
114 spin_lock (&g_uuid_lock);
116 list_add(&data->un_list, &g_uuid_list);
118 spin_unlock (&g_uuid_lock);
123 /* delete only one entry if uuid is specified, otherwise delete all */
124 int class_del_uuid (char *uuid)
126 struct list_head deathrow;
127 struct list_head *tmp;
129 struct uuid_nid_data *data;
131 INIT_LIST_HEAD (&deathrow);
133 spin_lock (&g_uuid_lock);
135 list_for_each_safe(tmp, n, &g_uuid_list) {
136 data = list_entry(tmp, struct uuid_nid_data, un_list);
138 if (uuid == NULL || strcmp(data->un_uuid, uuid) == 0) {
139 list_del (&data->un_list);
140 list_add (&data->un_list, &deathrow);
146 spin_unlock (&g_uuid_lock);
148 if (list_empty (&deathrow)) {
150 CERROR("delete non-existent uuid %s\n", uuid);
155 data = list_entry(deathrow.next, struct uuid_nid_data, un_list);
157 list_del (&data->un_list);
159 OBD_FREE(data->un_uuid, strlen(data->un_uuid) + 1);
160 OBD_FREE(data, sizeof(*data));
161 } while (!list_empty (&deathrow));