From: Steven Rostedt <srostedt@redhat.com>
To: xen-devel@lists.xensource.com
Cc: andrew.warfield@cl.cam.ac.uk
Subject: [PATCH] make blktap find it's major through sysfs
Date: Thu, 28 Sep 2006 21:56:40 -0400 [thread overview]
Message-ID: <451C7D58.2010407@redhat.com> (raw)
[-- 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
reply other threads:[~2006-09-29 1:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=451C7D58.2010407@redhat.com \
--to=srostedt@redhat.com \
--cc=andrew.warfield@cl.cam.ac.uk \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.