[Cluster-devel] cluster/cman/qdisk disk.h main.c mkqdisk.c proc.c
fabbione at sourceware.org
fabbione at sourceware.org
Thu Nov 15 04:14:16 UTC 2007
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: fabbione at sourceware.org 2007-11-15 04:14:15
Modified files:
cman/qdisk : disk.h main.c mkqdisk.c proc.c
Log message:
Fix bugzilla 362031
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/disk.h.diff?cvsroot=cluster&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/main.c.diff?cvsroot=cluster&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/mkqdisk.c.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/proc.c.diff?cvsroot=cluster&r1=1.3&r2=1.4
--- cluster/cman/qdisk/disk.h 2007/02/21 20:24:30 1.7
+++ cluster/cman/qdisk/disk.h 2007/11/15 04:14:15 1.8
@@ -277,7 +277,7 @@
void qd_destroy(qd_ctx *ctx);
/* proc.c */
-int find_partitions(const char *partfile, const char *label,
+int find_partitions(const char *devdir, const char *label,
char *devname, size_t devlen, int print);
int check_device(char *device, char *label, quorum_header_t *qh);
--- cluster/cman/qdisk/main.c 2007/11/01 00:25:28 1.11
+++ cluster/cman/qdisk/main.c 2007/11/15 04:14:15 1.12
@@ -1491,7 +1491,8 @@
}
if (ctx.qc_label) {
- if (find_partitions("/proc/partitions",
+ memset(device, 0, sizeof(device));
+ if (find_partitions("/dev",
ctx.qc_label, device,
sizeof(device), 0) != 0) {
clulog_and_print(LOG_CRIT, "Unable to match label"
--- cluster/cman/qdisk/mkqdisk.c 2006/11/21 14:50:49 1.4
+++ cluster/cman/qdisk/mkqdisk.c 2007/11/15 04:14:15 1.5
@@ -39,19 +39,19 @@
char *newdev = NULL, *newlabel = NULL;
int rv;
- printf("mkqdisk v0.5.1\n");
+ printf("mkqdisk v" RELEASE_VERSION "\n\n");
while ((rv = getopt(argc, argv, "Lf:c:l:h")) != EOF) {
switch (rv) {
case 'L':
/* List */
close(2);
- return find_partitions("/proc/partitions",
+ return find_partitions("/dev",
NULL, NULL, 0, 1);
break;
case 'f':
close(2);
- return find_partitions("/proc/partitions",
+ return find_partitions("/dev",
optarg, device,
sizeof(device), 1);
case 'c':
--- cluster/cman/qdisk/proc.c 2007/09/11 12:38:08 1.3
+++ cluster/cman/qdisk/proc.c 2007/11/15 04:14:15 1.4
@@ -26,10 +26,12 @@
#include <disk.h>
#include <errno.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <platform.h>
#include <stdlib.h>
#include <string.h>
-
+#include <unistd.h>
+#include <dirent.h>
int
check_device(char *device, char *label, quorum_header_t *qh)
@@ -68,62 +70,61 @@
int
-find_partitions(const char *partfile, const char *label,
+find_partitions(const char *devdir, const char *label,
char *devname, size_t devlen, int print)
{
- char line[4096];
- FILE *fp;
- int minor, major;
- unsigned long long blkcnt;
- char device[128];
- char realdev[256];
+ struct dirent **namelist;
+ struct stat sb;
+ char newpath[256];
+ int n;
quorum_header_t qh;
- fp = fopen(partfile, "r");
- if (!fp)
+ n = scandir(devdir, &namelist, 0, alphasort);
+ if (n <= 0)
return -1;
- while (fgets(line, sizeof(line), fp) != NULL) {
- if (strlen(line) > 128 + (22) /* 5 + 5 + 11 + 1 */) {
- /*printf("Line too long!\n");*/
- continue;
- }
-
- /* This line is taken from 2.6.15.4's proc line */
- sscanf(line, "%4d %4d %10llu %s", &major, &minor,
- &blkcnt, device);
-
- if (strlen(device)) {
- snprintf(realdev, sizeof(realdev),
- "/dev/%s", device);
- if (check_device(realdev, (char *)label, &qh) != 0)
- continue;
-
- if (print) {
- time_t timestamp = qh.qh_timestamp;
- printf("%s:\n", realdev);
- printf("\tMagic: %08x\n", qh.qh_magic);
- printf("\tLabel: %s\n", qh.qh_cluster);
- printf("\tCreated: %s",
- ctime((time_t *)×tamp));
- printf("\tHost: %s\n\n", qh.qh_updatehost);
- }
-
- if (devname && devlen) {
- /* Got it */
- strncpy(devname, realdev, devlen);
- fclose(fp);
- return 0;
+ while (n--) {
+ /* filter out:
+ * . and ..
+ * .static and .udev that are typical udev dirs that we don't want to scan
+ */
+ if (strcmp(namelist[n]->d_name, ".") &&
+ strcmp(namelist[n]->d_name, "..") &&
+ strcmp(namelist[n]->d_name, ".static") &&
+ strcmp(namelist[n]->d_name, ".udev")) {
+ snprintf(newpath, sizeof(newpath), "%s/%s", devdir, namelist[n]->d_name);
+ if (!lstat(newpath, &sb)) {
+ /* dive into directories */
+ if (S_ISDIR(sb.st_mode)) {
+ if (!find_partitions(newpath, label, devname, devlen, print)) {
+ if (devname && (strlen(devname) > 0))
+ return 0;
+ }
+ }
+ /* check if it's a block device */
+ if (S_ISBLK(sb.st_mode)) {
+ if (!check_device(newpath, (char *)label, &qh)) {
+ if (print) {
+ time_t timestamp = qh.qh_timestamp;
+ printf("%s:\n", newpath);
+ printf("\tMagic: %08x\n", qh.qh_magic);
+ printf("\tLabel: %s\n", qh.qh_cluster);
+ printf("\tCreated: %s",
+ ctime((time_t *)×tamp));
+ printf("\tHost: %s\n\n", qh.qh_updatehost);
+ }
+
+ if (devname && devlen) {
+ strncpy(devname, newpath, devlen);
+ return 0;
+ }
+ }
+ }
}
}
+ free(namelist[n]);
}
- fclose(fp);
-
- if (print)
- /* No errors if we're just printing stuff */
- return 0;
-
errno = ENOENT;
return -1;
}
More information about the Cluster-devel
mailing list