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 Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_RPC
26 # include <linux/module.h>
27 # include <linux/init.h>
28 # include <linux/list.h>
30 # include <liblustre.h>
32 #include <linux/obd.h>
33 #include <linux/obd_support.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_lib.h>
36 #include <linux/lustre_ha.h>
37 #include <linux/lustre_net.h>
38 #include <linux/lprocfs_status.h>
40 struct uuid_nid_data {
41 struct list_head head;
48 /* FIXME: This should probably become more elegant than a global linked list */
49 static struct list_head g_uuid_list;
50 static spinlock_t g_uuid_lock;
52 void class_init_uuidlist(void)
54 INIT_LIST_HEAD(&g_uuid_list);
55 spin_lock_init(&g_uuid_lock);
58 void class_exit_uuidlist(void)
64 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer)
66 struct list_head *tmp;
68 spin_lock (&g_uuid_lock);
70 list_for_each(tmp, &g_uuid_list) {
71 struct uuid_nid_data *data =
72 list_entry(tmp, struct uuid_nid_data, head);
74 if (strcmp(data->uuid, uuid) == 0) {
75 peer->peer_nid = data->nid;
76 peer->peer_ni = data->ni;
78 spin_unlock (&g_uuid_lock);
83 spin_unlock (&g_uuid_lock);
87 int class_add_uuid(char *uuid, __u64 nid, __u32 nal)
89 const ptl_handle_ni_t *nip;
90 struct uuid_nid_data *data;
92 int nob = strnlen (uuid, PAGE_SIZE) + 1;
97 nip = kportal_get_ni (nal);
99 CERROR("get_ni failed: is the NAL module loaded?\n");
104 OBD_ALLOC(data, sizeof(*data));
108 OBD_ALLOC(data->uuid, nob);
112 CDEBUG(D_INFO, "add uuid %s "LPX64" %u\n", uuid, nid, nal);
113 memcpy(data->uuid, uuid, nob);
118 spin_lock (&g_uuid_lock);
120 list_add(&data->head, &g_uuid_list);
122 spin_unlock (&g_uuid_lock);
127 OBD_FREE (data, sizeof (*data));
129 kportal_put_ni (nal);
133 /* delete only one entry if uuid is specified, otherwise delete all */
134 int class_del_uuid (char *uuid)
136 struct list_head deathrow;
137 struct list_head *tmp;
139 struct uuid_nid_data *data;
141 INIT_LIST_HEAD (&deathrow);
143 spin_lock (&g_uuid_lock);
145 list_for_each_safe(tmp, n, &g_uuid_list) {
146 data = list_entry(tmp, struct uuid_nid_data, head);
148 if (uuid == NULL || strcmp(data->uuid, uuid) == 0) {
149 list_del (&data->head);
150 list_add (&data->head, &deathrow);
156 spin_unlock (&g_uuid_lock);
158 if (list_empty (&deathrow))
162 data = list_entry(deathrow.next, struct uuid_nid_data, head);
164 list_del (&data->head);
166 kportal_put_ni (data->nal);
167 OBD_FREE(data->uuid, strlen(data->uuid) + 1);
168 OBD_FREE(data, sizeof(*data));
169 } while (!list_empty (&deathrow));