From patchwork Fri May 6 07:26:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 761082 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p467Qvap007478 for ; Fri, 6 May 2011 07:26:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753809Ab1EFH0x (ORCPT ); Fri, 6 May 2011 03:26:53 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:37547 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753057Ab1EFH0w (ORCPT ); Fri, 6 May 2011 03:26:52 -0400 Received: by mail-wy0-f174.google.com with SMTP id 21so2188193wya.19 for ; Fri, 06 May 2011 00:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=bh/Bq0RreumLzmdeRlgQsPqg+hcHerYbCZuIFAQEk/I=; b=Lwl5VYRvdkhAB2APKZ5qic4yzBcqpCwv3XNjNchp9jxzHeMcQUDRtE3LLBHgPqBudR fYZT7f5UBhV6ejSwJqi4iqLoxZqV59ZHKslxaWjMieAM49IHuJSz/xq4t0l8nfyjOdxw zIiTZEHh9XgmCp5IkbqHe+tpJkNpLZoxiXbcY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=s5doWf/L9qFUWojU/gTthDcqZJDGaxKCuVugbv4XQd/1GMEfl1erikt4HFBXGE8X3Q NMyllu5+bEuBNEOT4Z7RQ+gW30Yy8ZaL1GsOg36VCBCnmZ9Filw0Pm0DwTNTtrhFfuP+ FM0lubDYN7P1+lDOZ6sdsIuJkFejByOg3ZllU= Received: by 10.216.179.137 with SMTP id h9mr137688wem.4.1304666812110; Fri, 06 May 2011 00:26:52 -0700 (PDT) Received: from localhost.localdomain ([109.65.211.213]) by mx.google.com with ESMTPS id d54sm1453950wej.34.2011.05.06.00.26.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 May 2011 00:26:51 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 2/2] kvm tools: Simplify search for root device Date: Fri, 6 May 2011 10:26:35 +0300 Message-Id: <1304666795-15251-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1304666795-15251-1-git-send-email-levinsasha928@gmail.com> References: <1304666795-15251-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 06 May 2011 07:26:57 +0000 (UTC) Use /dev/block to find the block device used for root instead of searching through mounts. Signed-off-by: Sasha Levin --- 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;