All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] make blktap find it's major through sysfs
@ 2006-09-29  1:56 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2006-09-29  1:56 UTC (permalink / raw)
  To: xen-devel; +Cc: andrew.warfield

[-- Attachment #1: Type: text/plain, Size: 164 bytes --]

This patch makes blktap find it's major number by searching sysfs 
instead of reading /proc/devices.

-- Steve

Signed-off-by: Steven Rostedt <srostedt@redhat.com>

[-- Attachment #2: xen-linux-blktap-sysfs-search.patch --]
[-- Type: text/x-patch, Size: 1757 bytes --]

diff -r f4ec8ed65c15 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c	Thu Sep 28 21:41:44 2006 -0400
+++ b/tools/blktap/drivers/blktapctrl.c	Thu Sep 28 21:54:10 2006 -0400
@@ -636,28 +636,56 @@ static void print_drivers(void)
 		DPRINTF("Found driver: [%s]\n",dtypes[i]->name);
 } 
 
+#define MTAB "/proc/mounts"
+#define BLKTAP_SYSFS_PATH "/class/xen/blktap0/dev"
+
+#define MAX_PATH 255
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+static char sysfsdir[MAX_PATH + 1];
+
+static int find_sysfsdir(void)
+{
+    FILE *fp;
+    char type[MAX_PATH + 1];
+
+    if ((fp = fopen(MTAB, "r")) == NULL)
+        return -1;
+
+    while (fscanf(fp, "%*s %"
+                  STR(MAX_PATH)
+                  "s %"
+                  STR(MAX_PATH)
+                  "s %*s %*d %*d\n",
+                  sysfsdir, type) == 2) {
+        if (strncmp(type, "sysfs", 5) == 0)
+            break;
+    }
+    fclose(fp);
+
+    return strncmp(type, "sysfs", 5) == 0 ? 0 : -1;
+}
+
 static int find_blktap_major(void)
 {
-	FILE *fp;
-	int major;
-	char device[256];
-
-	if ((fp = fopen("/proc/devices", "r")) == NULL)
-		return -1;
-
-	/* Skip title */
-	fscanf(fp,"%*s %*s\n");
-	while (fscanf(fp, "%d %255s\n", &major, device) == 2) {
-		if (strncmp("blktap", device, 6) == 0)
-			break;
-	}
-
-	fclose(fp);
-
-	if (strncmp("blktap", device, 6) == 0)
-		return major;
-
-	return -1;
+    FILE *fp;
+    int major;
+    int minor;
+
+    if (find_sysfsdir() < 0)
+	    return -1;
+    
+    strncat(sysfsdir, BLKTAP_SYSFS_PATH, MAX_PATH);
+    
+    if ((fp = fopen(sysfsdir, "r")) == NULL)
+	    return -1;
+    
+    fscanf(fp,"%d:%d",&major, &minor);
+    
+    fclose(fp);
+    
+    return major;
 }
 
 int main(int argc, char *argv[])

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-09-29  1:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-29  1:56 [PATCH] make blktap find it's major through sysfs Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.