diff mbox

[2/2] kvm tools: Simplify search for root device

Message ID 1304666795-15251-2-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin May 6, 2011, 7:26 a.m. UTC
Use /dev/block to find the block device used for root
instead of searching through mounts.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/kvm-run.c |   48 +++---------------------------------------------
 1 files changed, 3 insertions(+), 45 deletions(-)

Comments

Pekka Enberg May 7, 2011, 8:41 a.m. UTC | #1
On Fri, 6 May 2011, Sasha Levin wrote:
> Use /dev/block to find the block device used for root
> instead of searching through mounts.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>

Weren't there distro differences in this area? Prasad, Asias, does this 
work for you?
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sasha Levin May 7, 2011, 8:46 a.m. UTC | #2
On Sat, 2011-05-07 at 11:41 +0300, Pekka Enberg wrote:
> On Fri, 6 May 2011, Sasha Levin wrote:
> > Use /dev/block to find the block device used for root
> > instead of searching through mounts.
> >
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> 
> Weren't there distro differences in this area? Prasad, Asias, does this 
> work for you?

The distro differences were when we tried using /dev/ROOT and found it's
optional and doesn't always exist.
Prasad Joshi May 7, 2011, 8:49 a.m. UTC | #3
On Sat, May 7, 2011 at 9:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
> On Fri, 6 May 2011, Sasha Levin wrote:
>>
>> Use /dev/block to find the block device used for root
>> instead of searching through mounts.
>>
>> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
>
> Weren't there distro differences in this area? Prasad, Asias, does this work
> for you?

Ya it works on my machine.

Thanks and Regards,
Prasad
>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index d5a952f..6fee8ae 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -249,56 +249,14 @@  static const char *find_kernel(void)
 
 static int root_device(char *dev, long *part)
 {
-	FILE   *fp;
-	char   *line;
-	int    tmp;
-	size_t nr_read;
-	char   device[PATH_MAX];
-	char   mnt_pt[PATH_MAX];
-	char   resolved_path[PATH_MAX];
-	char   *p;
 	struct stat st;
 
-	fp = fopen("/proc/mounts", "r");
-	if (!fp)
+	if (stat("/", &st) < 0)
 		return -1;
 
-	line = NULL;
-	tmp  = 0;
-	while (!feof(fp)) {
-		if (getline(&line, &nr_read, fp) < 0)
-			break;
-		sscanf(line, "%s %s", device, mnt_pt);
-		if (!strncmp(device, "/dev", 4) && !strcmp(mnt_pt, "/")) {
-			tmp = 1;
-			break;
-		}
-	}
-	fclose(fp);
-	free(line);
-
-	if (!tmp)
-		return -1;
-
-	/* get the absolute path */
-	if (!realpath(device, resolved_path))
-		return -1;
-
-	/* find the partition number */
-	p = resolved_path;
-	while (*p) {
-		if (isdigit(*p)) {
-			strncpy(dev, resolved_path, p - resolved_path);
-			*part = atol(p);
-			break;
-		}
-		p++;
-	}
-
-	/* verify the device path */
-	if (stat(dev, &st) < 0)
-		return -1;
+	*part = minor(st.st_dev);
 
+	sprintf(dev, "/dev/block/%u:0", major(st.st_dev));
 	if (access(dev, R_OK) < 0)
 		return -1;