src/direct.c | 6 +++---
src/host_id.c | 17 ++++++++++-------
tests/sanlk_load.c | 2 +-
3 files changed, 14 insertions(+), 11 deletions(-)
New commits:
commit 8e17fd668efe9bffd04df8b4f9c26a52f0f371d2
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 22 15:21:57 2011 -0500
sanlock: generate a uuid for host id
instead of doing approx the same thing with a timestamp
plus random number. Still include the uname nodename
after the uuid as a debugging hint about the actual host.
diff --git a/src/direct.c b/src/direct.c
index 50d5cbf..5c57574 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -467,7 +467,7 @@ int direct_dump(struct task *task, char *dump_path)
goto out_close;
}
- printf("%8s %36s %36s %10s %4s %4s %s\n",
+ printf("%8s %36s %48s %10s %4s %4s %s\n",
"offset",
"lockspace",
"resource",
@@ -502,7 +502,7 @@ int direct_dump(struct task *task, char *dump_path)
strncpy(sname, lr->space_name, NAME_ID_SIZE);
strncpy(rname, lr->resource_name, NAME_ID_SIZE);
- printf("%08llu %36s %36s %010llu %04llu %04llu\n",
+ printf("%08llu %36s %48s %010llu %04llu %04llu\n",
(unsigned long long)((sector_nr + i) * sd.sector_size),
sname, rname,
(unsigned long long)lr->timestamp,
@@ -513,7 +513,7 @@ int direct_dump(struct task *task, char *dump_path)
strncpy(sname, lr->space_name, NAME_ID_SIZE);
strncpy(rname, lr->resource_name, NAME_ID_SIZE);
- printf("%08llu %36s %36s %010llu %04llu %04llu %llu\n",
+ printf("%08llu %36s %48s %010llu %04llu %04llu %llu\n",
(unsigned long long)(sector_nr * sd.sector_size),
sname, rname,
(unsigned long long)lr->timestamp,
diff --git a/src/host_id.c b/src/host_id.c
index 8f2bfa8..9cb8617 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/utsname.h>
+#include <uuid/uuid.h>
#include "sanlock_internal.h"
#include "diskio.h"
@@ -576,7 +577,8 @@ int get_rand(int a, int b)
void setup_spaces(void)
{
struct utsname name;
- struct timeval tv;
+ char uuid[37];
+ uuid_t uu;
INIT_LIST_HEAD(&spaces);
INIT_LIST_HEAD(&spaces_add);
@@ -597,13 +599,14 @@ void setup_spaces(void)
/* make up something that's likely to be different among hosts */
memset(&our_host_name_global, 0, sizeof(our_host_name_global));
+ memset(&name, 0, sizeof(name));
+ memset(&uuid, 0, sizeof(uuid));
+
uname(&name);
- gettimeofday(&tv, NULL);
+ uuid_generate(uu);
+ uuid_unparse_lower(uu, uuid);
- snprintf(our_host_name_global, NAME_ID_SIZE, "%llu.%llu.%d.%s",
- (unsigned long long)tv.tv_sec,
- (unsigned long long)tv.tv_usec,
- get_rand(1, RAND_MAX-1),
- name.nodename);
+ snprintf(our_host_name_global, NAME_ID_SIZE, "%s.%s",
+ uuid, name.nodename);
}
diff --git a/tests/sanlk_load.c b/tests/sanlk_load.c
index 6c55ffb..d874fa2 100644
--- a/tests/sanlk_load.c
+++ b/tests/sanlk_load.c
@@ -657,7 +657,7 @@ int main(int argc, char *argv[])
out:
printf("sanlk_load init <lock_disk_base> [<ls_count>
<res_count>]\n");
printf("\n");
- printf("sanlk_load rand\n");
+ printf("sanlk_load rand <lock_disk_base> -i <host_id> [-D -s
<ls_count> -r <res_count> -p <pid_count>]\n");
printf("\n");
return -1;
}