From patchwork Sun Jul 22 16:29:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1224721 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 1ECED3FDFB for ; Sun, 22 Jul 2012 16:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752133Ab2GVQad (ORCPT ); Sun, 22 Jul 2012 12:30:33 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:42019 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106Ab2GVQaP (ORCPT ); Sun, 22 Jul 2012 12:30:15 -0400 Received: by mail-wi0-f170.google.com with SMTP id hq12so1849948wib.1 for ; Sun, 22 Jul 2012 09:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=YAvTNQAJW+m+LrN7uoaDIrelf2Bf4T8i/tUaJaGdacg=; b=kSWg3TJieZbC9sLOCnfV3VoyoZBpSVFIk58D43prd8WsjvUEXzWZZjYX+3KBE17JGH zWzO4UIsQ0bSd9sVAr4HB/u9/h1xkDy6XR0pHjXdHRXd4pakwKVD87/WCk8VFPPZwGtg jjdSPzadK8VjwA+4/EwmFOeSJI9iR366ef0bUAbk71obAa3ImPLJgdar5SjCxOMGAvEA bBThAD+4GHSO2t0P0pRLu3WVinUkea7LeJpOIHWASAsGu2Xy3CZqC2G+XD35xkQ9TypG 9IYrzuDWXTyKWlKvgO6UsxRn4m7/ctfG407/sl61gWVuzlHDbyKudnYbjmeX0lclDUkD 0fSw== Received: by 10.180.105.163 with SMTP id gn3mr22211066wib.2.1342974614827; Sun, 22 Jul 2012 09:30:14 -0700 (PDT) Received: from localhost.localdomain ([217.203.160.170]) by mx.google.com with ESMTPS id ep14sm17495905wid.0.2012.07.22.09.29.58 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 Jul 2012 09:30:14 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org, mingo@elte.hu, gorcunov@gmail.com Cc: kvm@vger.kernel.org, Sasha Levin Subject: [PATCH] kvm tools: don't bother tracking is_dir Date: Sun, 22 Jul 2012 18:29:54 +0200 Message-Id: <1342974594-31317-5-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1342974594-31317-1-git-send-email-levinsasha928@gmail.com> References: <1342974594-31317-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is something we can calculate on the fly, and doesn't justify the overhead of tracking it all over fid transitions. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/virtio-9p.h | 1 - tools/kvm/virtio/9p.c | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/kvm/include/kvm/virtio-9p.h b/tools/kvm/include/kvm/virtio-9p.h index 186fe05..cb590d1 100644 --- a/tools/kvm/include/kvm/virtio-9p.h +++ b/tools/kvm/include/kvm/virtio-9p.h @@ -26,7 +26,6 @@ struct p9_msg { struct p9_fid { u32 fid; u32 uid; - u8 is_dir; char abs_path[PATH_MAX]; char *path; DIR *dir; diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index c663dab..2cf99a0 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -228,6 +228,15 @@ static int virtio_p9_openflags(int flags) return flags; } +static bool is_dir(struct p9_fid *fid) +{ + struct stat st; + + stat(fid->abs_path, &st); + + return S_ISDIR(st.st_mode); +} + static void virtio_p9_open(struct p9_dev *p9dev, struct p9_pdu *pdu, u32 *outlen) { @@ -245,7 +254,7 @@ static void virtio_p9_open(struct p9_dev *p9dev, stat2qid(&st, &qid); - if (new_fid->is_dir) { + if (is_dir(new_fid)) { new_fid->dir = opendir(new_fid->abs_path); if (!new_fid->dir) goto err_out; @@ -394,7 +403,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev, goto err_out; stat2qid(&st, &wqid); - new_fid->is_dir = S_ISDIR(st.st_mode); strcpy(new_fid->path, tmp); new_fid->uid = fid->uid; nwqid++; @@ -406,7 +414,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev, */ pdu->write_offset += sizeof(u16); old_fid = get_fid(p9dev, fid_val); - new_fid->is_dir = old_fid->is_dir; strcpy(new_fid->path, old_fid->path); new_fid->uid = old_fid->uid; } @@ -445,7 +452,6 @@ static void virtio_p9_attach(struct p9_dev *p9dev, fid = get_fid(p9dev, fid_val); fid->uid = uid; - fid->is_dir = 1; strcpy(fid->path, "/"); virtio_p9_pdu_writef(pdu, "Q", &qid); @@ -547,7 +553,7 @@ static void virtio_p9_readdir(struct p9_dev *p9dev, virtio_p9_pdu_readf(pdu, "dqd", &fid_val, &offset, &count); fid = get_fid(p9dev, fid_val); - if (!fid->is_dir) { + if (!is_dir(fid)) { errno = EINVAL; goto err_out; }