2 * Public include file for the UUID library
4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
5 * Copyright (C) 2002 Cluster File System
6 * - changed for use in lustre
9 * This file may be redistributed under the terms of the GNU
10 * Library General Public License.
13 #define DEBUG_SUBSYSTEM S_CLASS
16 # include <linux/ctype.h>
17 # include <linux/kernel.h>
18 # include <linux/sched.h>
19 # include <linux/smp_lock.h>
21 # include <liblustre.h>
24 #include <linux/obd_support.h>
25 #include <linux/obd_class.h>
26 #include <linux/obd_ost.h>
31 __u16 time_hi_and_version;
36 static void uuid_unpack(class_uuid_t in, struct uuid *uu)
42 tmp = (tmp << 8) | *ptr++;
43 tmp = (tmp << 8) | *ptr++;
44 tmp = (tmp << 8) | *ptr++;
48 tmp = (tmp << 8) | *ptr++;
52 tmp = (tmp << 8) | *ptr++;
53 uu->time_hi_and_version = tmp;
56 tmp = (tmp << 8) | *ptr++;
59 memcpy(uu->node, ptr, 6);
63 static void uuid_pack(struct uuid *uu, class_uuid_t ptr)
66 unsigned char *out = ptr;
69 out[3] = (unsigned char) tmp;
71 out[2] = (unsigned char) tmp;
73 out[1] = (unsigned char) tmp;
75 out[0] = (unsigned char) tmp;
78 out[5] = (unsigned char) tmp;
80 out[4] = (unsigned char) tmp;
82 tmp = uu->time_hi_and_version;
83 out[7] = (unsigned char) tmp;
85 out[6] = (unsigned char) tmp;
88 out[9] = (unsigned char) tmp;
90 out[8] = (unsigned char) tmp;
92 memcpy(out+10, uu->node, 6);
95 int class_uuid_parse(struct obd_uuid in, class_uuid_t uu)
101 if (strlen(in) != 36)
103 for (i=0, cp = in; i <= 36; i++,cp++) {
104 if ((i == 8) || (i == 13) || (i == 18) ||
114 uuid.time_low = simple_strtoul(in, NULL, 16);
115 uuid.time_mid = simple_strtoul(in+9, NULL, 16);
116 uuid.time_hi_and_version = simple_strtoul(in+14, NULL, 16);
117 uuid.clock_seq = simple_strtoul(in+19, NULL, 16);
120 for (i=0; i < 6; i++) {
123 uuid.node[i] = simple_strtoul(buf, NULL, 16);
126 uuid_pack(&uuid, uu);
131 void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
135 uuid_unpack(uu, &uuid);
137 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
138 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
139 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
140 uuid.node[0], uuid.node[1], uuid.node[2],
141 uuid.node[3], uuid.node[4], uuid.node[5]);
144 struct obd_device *client_tgtuuid2obd(struct obd_uuid *tgtuuid)
148 for (i = 0; i < MAX_OBD_DEVICES; i++) {
149 struct obd_device *obd = &obd_dev[i];
150 if (obd->obd_type == NULL)
152 if ((strncmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME,
153 sizeof LUSTRE_OSC_NAME) == 0) ||
154 (strncmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME,
155 sizeof LUSTRE_MDC_NAME) == 0)) {
156 struct client_obd *cli = &obd->u.cli;
157 struct obd_import *imp = cli->cl_import;
158 if (strncmp(tgtuuid->uuid, imp->imp_target_uuid.uuid,
159 sizeof(imp->imp_target_uuid)) == 0)