[Ocfs2-tools-devel] [PATCH 3/5] debugfs: Make do_dlm_locks() use stringlist
Sunil Mushran
sunil.mushran at oracle.com
Wed Oct 8 16:05:45 PDT 2008
Patch makes do_dlm_locks() make use of the utility functions
added to manage a list of strings.
Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
debugfs.ocfs2/commands.c | 21 ++++-----------------
debugfs.ocfs2/dump_dlm_locks.c | 20 +-------------------
debugfs.ocfs2/include/dump_dlm_locks.h | 7 +------
3 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index ea20080..4717e4f 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -1484,14 +1484,12 @@ static void do_dlm_locks(char **args)
FILE *out;
int dump_lvbs = 0;
int i;
- struct locknames *lock;
struct list_head locklist;
- struct list_head *iter, *iter2;
if (check_device_open())
return;
- INIT_LIST_HEAD(&locklist);
+ init_stringlist(&locklist);
i = 1;
if (args[i] && strlen(args[i])) {
@@ -1500,27 +1498,16 @@ static void do_dlm_locks(char **args)
i++;
}
- for ( ; args[i] && strlen(args[i]); ++i) {
- lock = calloc(1, sizeof(struct locknames));
- if (!lock)
+ for ( ; args[i] && strlen(args[i]); ++i)
+ if (add_to_stringlist(args[i], &locklist))
break;
- INIT_LIST_HEAD(&lock->list);
- strncpy(lock->name, args[i], sizeof(lock->name));
- list_add_tail(&lock->list, &locklist);
- }
}
out = open_pager(gbls.interactive);
dump_dlm_locks(gbls.fs->uuid_str, out, dump_lvbs, &locklist);
close_pager(out);
- if (!list_empty(&locklist)) {
- list_for_each_safe(iter, iter2, &locklist) {
- lock = list_entry(iter, struct locknames, list);
- list_del(iter);
- free(lock);
- }
- }
+ free_stringlist(&locklist);
}
/*
diff --git a/debugfs.ocfs2/dump_dlm_locks.c b/debugfs.ocfs2/dump_dlm_locks.c
index 05c5d9b..b946821 100644
--- a/debugfs.ocfs2/dump_dlm_locks.c
+++ b/debugfs.ocfs2/dump_dlm_locks.c
@@ -397,24 +397,6 @@ static void read_lockres(FILE *file, struct lockres *res, int lvb)
}
}
-static int lockname_in_list(char *name, struct list_head *locklist)
-{
- struct locknames *l;
- struct list_head *iter, *iter2;
-
- if (!list_empty(locklist)) {
- list_for_each_safe(iter, iter2, locklist) {
- l = list_entry(iter, struct locknames, list);
- if (!strncmp(name, l->name, sizeof(l->name))) {
- list_del(iter);
- return 1;
- }
- }
- }
-
- return 0;
-}
-
static int get_next_dlm_lockname(FILE *file, char *name, int len)
{
char line[512];
@@ -459,7 +441,7 @@ void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
init_lockres(&res);
while (get_next_dlm_lockname(file, name, sizeof(name))) {
- if (show_all_locks || lockname_in_list(name, locklist)) {
+ if (show_all_locks || del_from_stringlist(name, locklist)) {
read_lockres(file, &res, dump_lvbs);
dump_lockres(name, &res, out);
diff --git a/debugfs.ocfs2/include/dump_dlm_locks.h b/debugfs.ocfs2/include/dump_dlm_locks.h
index ce1a226..2cbb72a 100644
--- a/debugfs.ocfs2/include/dump_dlm_locks.h
+++ b/debugfs.ocfs2/include/dump_dlm_locks.h
@@ -74,12 +74,7 @@ struct lock {
struct list_head list;
};
-struct locknames {
- char name[OCFS2_LOCK_ID_MAX_LEN];
- struct list_head list;
-};
-
void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
- struct list_head *all_locks);
+ struct list_head *locklist);
#endif /* _DUMP_DLM_LOCKS_H_ */
--
1.5.4.3
More information about the Ocfs2-tools-devel
mailing list