WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] make blktap find it's major through sysfs

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] make blktap find it's major through sysfs
From: Steven Rostedt <srostedt@xxxxxxxxxx>
Date: Thu, 28 Sep 2006 21:56:40 -0400
Cc: andrew.warfield@xxxxxxxxxxxx
Delivery-date: Thu, 28 Sep 2006 18:56:39 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 1.5.0.4 (X11/20060614)
This patch makes blktap find it's major number by searching sysfs instead of reading /proc/devices.

-- Steve

Signed-off-by: Steven Rostedt <srostedt@xxxxxxxxxx>
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[])
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] make blktap find it's major through sysfs, Steven Rostedt <=