[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 2/2] libgfs2: Move get_list out of libgfs2



This function was only used in gfs2_tool so it can be moved out of
libgfs2 and merged into gfs2_tool's print_list function. This also
removes four more uses of 'die' from libgfs2.

Signed-off-by: Andrew Price <andy andrewprice me uk>
---
 gfs2/libgfs2/libgfs2.h |    1 -
 gfs2/libgfs2/misc.c    |   64 ------------------------------------------------
 gfs2/tool/misc.c       |   54 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 53 insertions(+), 66 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index a89c25c..a25cf7b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -630,7 +630,6 @@ extern int dir_exists(const char *dir);
 extern int check_for_gfs2(struct gfs2_sbd *sdp);
 extern void mount_gfs2_meta(struct gfs2_sbd *sdp);
 extern void cleanup_metafs(struct gfs2_sbd *sdp);
-extern char *get_list(void);
 extern char *find_debugfs_mount(void);
 extern char *mp2fsname(char *mp);
 extern char *get_sysfs(char *fsname, char *filename);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index d5ce490..21329f3 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -267,70 +267,6 @@ int set_sysfs(char *fsname, char *filename, char *val)
 	return 0;
 }
 
-/**
- * get_list - Get the list of GFS2 filesystems
- *
- * Returns: a NULL terminated string
- */
-
-#define LIST_SIZE 1048576
-
-char *get_list(void)
-{
-	char path[PATH_MAX];
-	char s_id[PATH_MAX];
-	char *list, *p;
-	int rv, fd, x = 0, total = 0;
-	DIR *d;
-	struct dirent *de;
-
-	list = malloc(LIST_SIZE);
-	if (!list)
-		die("out of memory\n");
-
-	memset(path, 0, PATH_MAX);
-	snprintf(path, PATH_MAX, "%s", SYS_BASE);
-
-	d = opendir(path);
-	if (!d)
-		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
-
-	while ((de = readdir(d))) {
-		if (de->d_name[0] == '.')
-			continue;
-
-		memset(path, 0, PATH_MAX);
-		snprintf(path, PATH_MAX, "%s/%s/id", SYS_BASE, de->d_name);
-
-		fd = open(path, O_RDONLY);
-		if (fd < 0)
-			die("can't open %s: %s\n", path, strerror(errno));
-
-		memset(s_id, 0, PATH_MAX);
-
-		rv = read(fd, s_id, sizeof(s_id));
-		if (rv < 0)
-			die("can't read %s: %s\n", path, strerror(errno));
-
-		close(fd);
-
-		p = strstr(s_id, "\n");
-		if (p)
-			*p = '\0';
-
-		total += strlen(s_id) + strlen(de->d_name) + 2;
-		if (total > LIST_SIZE)
-			break;
-
-		x += sprintf(list + x, "%s %s\n", s_id, de->d_name);
-
-	}
-
-	closedir(d);
-
-	return list;
-}
-
 char *find_debugfs_mount(void)
 {
 	FILE *file;
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 2e57cd1..f23ec82 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -362,11 +362,63 @@ print_journals(int argc, char **argv)
  *
  */
 
+#define LIST_SIZE 1048576
+
 void
 print_list(void)
 {
-	char *list = get_list();
+	char path[PATH_MAX];
+	char s_id[PATH_MAX];
+	char *list, *p;
+	int rv, fd, x = 0, total = 0;
+	DIR *d;
+	struct dirent *de;
+
+	list = malloc(LIST_SIZE);
+	if (!list)
+		die("out of memory\n");
+
+	memset(path, 0, PATH_MAX);
+	snprintf(path, PATH_MAX, "%s", SYS_BASE);
+
+	d = opendir(path);
+	if (!d)
+		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+
+	while ((de = readdir(d))) {
+		if (de->d_name[0] == '.')
+			continue;
+
+		memset(path, 0, PATH_MAX);
+		snprintf(path, PATH_MAX, "%s/%s/id", SYS_BASE, de->d_name);
+
+		fd = open(path, O_RDONLY);
+		if (fd < 0)
+			die("can't open %s: %s\n", path, strerror(errno));
+
+		memset(s_id, 0, PATH_MAX);
+
+		rv = read(fd, s_id, sizeof(s_id));
+		if (rv < 0)
+			die("can't read %s: %s\n", path, strerror(errno));
+
+		close(fd);
+
+		p = strstr(s_id, "\n");
+		if (p)
+			*p = '\0';
+
+		total += strlen(s_id) + strlen(de->d_name) + 2;
+		if (total > LIST_SIZE)
+			break;
+
+		x += sprintf(list + x, "%s %s\n", s_id, de->d_name);
+
+	}
+
+	closedir(d);
 	printf("%s", list);
+	free(list);
 }
 
 /**
-- 
1.5.6.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]