src/client_resource.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/main.c | 35 +----------------------------------
src/sanlock_resource.h | 6 ++++++
3 files changed, 50 insertions(+), 34 deletions(-)
New commits:
commit b7dfd532299dff2c03c0596f4ed5a50fb02c6484
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 12 11:47:17 2011 -0500
sanlock: add str_to_lockspace to lib
to convert string format to struct sanlk_lockspace
diff --git a/src/client_resource.c b/src/client_resource.c
index 90416d0..5a807e1 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -554,3 +554,46 @@ int sanlock_state_to_args(char *res_state,
return rv;
}
+/*
+ * convert to struct sanlk_lockspace from string with format:
+ * <lockspace_name>:<host_id>:<path>:<offset>
+ */
+
+int sanlock_str_to_lockspace(char *str, struct sanlk_lockspace *ls)
+{
+ char *host_id = NULL;
+ char *path = NULL;
+ char *offset = NULL;
+
+ if (str)
+ host_id = strstr(str, ":");
+ if (host_id)
+ path = strstr(host_id+1, ":");
+ if (host_id && path)
+ offset = strstr(path+1, ":");
+
+ if (host_id) {
+ *host_id = '\0';
+ host_id++;
+ }
+ if (path) {
+ *path = '\0';
+ path++;
+ }
+ if (offset) {
+ *offset= '\0';
+ offset++;
+ }
+
+ if (str)
+ strncpy(ls->name, str, NAME_ID_SIZE);
+ if (host_id)
+ ls->host_id = atoll(host_id);
+ if (path)
+ strncpy(ls->host_id_disk.path, path, SANLK_PATH_LEN-1);
+ if (offset)
+ ls->host_id_disk.offset = atoll(offset);
+
+ return 0;
+}
+
diff --git a/src/main.c b/src/main.c
index 7dbc573..3063dc6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2049,42 +2049,9 @@ static int do_daemon(void)
return rv;
}
-/* arg = <lockspace_name>:<host_id>:<path>:<offset> */
-
static int parse_arg_lockspace(char *arg)
{
- char *host_id = NULL;
- char *path = NULL;
- char *offset = NULL;
-
- if (arg)
- host_id = strstr(arg, ":");
- if (host_id)
- path = strstr(host_id+1, ":");
- if (host_id && path)
- offset = strstr(path+1, ":");
-
- if (host_id) {
- *host_id = '\0';
- host_id++;
- }
- if (path) {
- *path = '\0';
- path++;
- }
- if (offset) {
- *offset= '\0';
- offset++;
- }
-
- if (arg)
- strncpy(com.lockspace.name, arg, NAME_ID_SIZE);
- if (host_id)
- com.lockspace.host_id = atoll(host_id);
- if (path)
- strncpy(com.lockspace.host_id_disk.path, path, SANLK_PATH_LEN-1);
- if (offset)
- com.lockspace.host_id_disk.offset = atoll(offset);
+ sanlock_str_to_lockspace(arg, &com.lockspace);
log_debug("lockspace %s host_id %llu path %s offset %llu",
com.lockspace.name,
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index fe822fc..f41f3e3 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -74,5 +74,11 @@ int sanlock_state_to_args(char *res_state,
int *res_count,
struct sanlk_resource ***res_args);
+/*
+ * convert to struct sanlk_lockspace from string with format:
+ * <lockspace_name>:<host_id>:<path>:<offset>
+ */
+
+int sanlock_str_to_lockspace(char *str, struct sanlk_lockspace *ls);
#endif
Show replies by date