From patchwork Mon Jun 27 09:41:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9200205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CE1060752 for ; Mon, 27 Jun 2016 09:42:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D9A3284D4 for ; Mon, 27 Jun 2016 09:42:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 724A62856B; Mon, 27 Jun 2016 09:42:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 251F7284D4 for ; Mon, 27 Jun 2016 09:42:30 +0000 (UTC) Received: from localhost ([::1]:57494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3k-00087i-SA for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Jun 2016 05:42:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT2y-0007ZH-EN for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHT2v-0004wa-7i for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:40 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32923 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT2v-0004wU-13 for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:37 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dLZb052628 for ; Mon, 27 Jun 2016 05:41:36 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 23snxtnvjq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:41:36 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 03:41:35 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 03:41:33 -0600 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id D1C3419D8026; Mon, 27 Jun 2016 03:41:10 -0600 (MDT) Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9fWbW51642544; Mon, 27 Jun 2016 02:41:32 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9093C6A03F; Mon, 27 Jun 2016 03:41:32 -0600 (MDT) Received: from bahia.lan (unknown [9.164.189.130]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 556456A03B; Mon, 27 Jun 2016 03:41:30 -0600 (MDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:41:28 +0200 In-Reply-To: <146702045511.5764.17551224268217330628.stgit@bahia.lan> References: <146702045511.5764.17551224268217330628.stgit@bahia.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062709-0028-0000-0000-0000050B38E9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0029-0000-0000-00002D04B5D3 Message-Id: <146702048893.5764.17454103249529126852.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-27_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606270110 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 04/13] 9p: getattr: use fstat if we have a fd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Van Hensbergen , v9fs-developer@lists.sourceforge.net, "Aneesh Kumar K.V" , Greg Kurz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If we have an opened fd, it is better to call fstat() as the underlying file may have been unlinked and lstat() will fail. The fid_has_file() helper will be used by other file descriptor based ops. Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 626d4aa8ebb6..3301cef0980d 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -253,6 +253,23 @@ int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs) return fd; } +static bool fid_has_file(V9fsFidState *fidp) +{ + int fid_type = fidp->fid_type; + + if (fid_type == P9_FID_DIR) { + if (fidp->fs.dir.stream) { + return true; + } + } else if (fid_type == P9_FID_FILE) { + if (fidp->fs.fd > -1) { + return true; + } + } + + return false; +} + static V9fsFidState *get_fid(V9fsPDU *pdu, int32_t fid) { int err; @@ -1044,6 +1061,19 @@ out_nofid: v9fs_string_free(&aname); } +static int v9fs_do_stat(V9fsPDU *pdu, V9fsFidState *fidp, struct stat *stbuf) +{ + int retval; + + if (fid_has_file(fidp)) { + retval = v9fs_co_fstat(pdu, fidp, stbuf); + } else { + retval = v9fs_co_lstat(pdu, &fidp->path, stbuf); + } + + return retval; +} + static void v9fs_stat(void *opaque) { int32_t fid; @@ -1065,7 +1095,7 @@ static void v9fs_stat(void *opaque) err = -ENOENT; goto out_nofid; } - err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); + err = v9fs_do_stat(pdu, fidp, &stbuf); if (err < 0) { goto out; } @@ -1115,7 +1145,7 @@ static void v9fs_getattr(void *opaque) * Currently we only support BASIC fields in stat, so there is no * need to look at request_mask. */ - retval = v9fs_co_lstat(pdu, &fidp->path, &stbuf); + retval = v9fs_do_stat(pdu, fidp, &stbuf); if (retval < 0) { goto out; } @@ -2674,7 +2704,7 @@ static void v9fs_wstat(void *opaque) } if (v9stat.mode != -1) { uint32_t v9_mode; - err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); + err = v9fs_do_stat(pdu, fidp, &stbuf); if (err < 0) { goto out; }