From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com,
prasadjoshi124@gmail.com, kvm@vger.kernel.org,
Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 2/2] kvm tools: Simplify search for root device
Date: Fri, 6 May 2011 10:26:35 +0300 [thread overview]
Message-ID: <1304666795-15251-2-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1304666795-15251-1-git-send-email-levinsasha928@gmail.com>
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(-)
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;
--
1.7.5.rc3
next prev parent reply other threads:[~2011-05-06 7:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-06 7:26 [PATCH 1/2] kvm tools: Fix IRQ assignments Sasha Levin
2011-05-06 7:26 ` Sasha Levin [this message]
2011-05-07 8:41 ` [PATCH 2/2] kvm tools: Simplify search for root device Pekka Enberg
2011-05-07 8:46 ` Sasha Levin
2011-05-07 8:49 ` Prasad Joshi
2011-05-06 7:29 ` [PATCH 1/2] kvm tools: Fix IRQ assignments Pekka Enberg
2011-05-06 7:31 ` Cyrill Gorcunov
2011-05-06 7:36 ` Sasha Levin
2011-05-06 7:43 ` Pekka Enberg
2011-05-06 8:01 ` Sasha Levin
2011-05-06 8:04 ` Pekka Enberg
2011-05-06 8:08 ` Cyrill Gorcunov
2011-05-06 8:10 ` Pekka Enberg
2011-05-06 8:16 ` Cyrill Gorcunov
2011-05-06 7:47 ` Cyrill Gorcunov
2011-05-06 7:59 ` Pekka Enberg
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=1304666795-15251-2-git-send-email-levinsasha928@gmail.com \
--to=levinsasha928@gmail.com \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox