From patchwork Mon Jun 27 09:41:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 640905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rdPH16ff1z9sdb for ; Mon, 27 Jun 2016 19:47:09 +1000 (AEST) Received: from localhost ([::1]:57519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT8F-0007eQ-UI for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2016 05:47:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT2p-0007O2-VP for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHT2l-0004tr-OR for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:30 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:2734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT2l-0004te-FR for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:27 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dJkQ101946 for ; Mon, 27 Jun 2016 05:41:26 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 23spf855m0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:41:26 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 03:41:25 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 03:41:24 -0600 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id E83C219D801C; Mon, 27 Jun 2016 03:41:01 -0600 (MDT) Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9fLhr53018634; Mon, 27 Jun 2016 02:41:23 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A33E7136046; Mon, 27 Jun 2016 03:41:23 -0600 (MDT) Received: from bahia.lan (unknown [9.164.189.130]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id 0EB8F13603C; Mon, 27 Jun 2016 03:41:21 -0600 (MDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:41:20 +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-0012-0000-0000-00001007BADD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0013-0000-0000-0000431D2D9F Message-Id: <146702048052.5764.3687111665869095201.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=1 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.156.1 Subject: [Qemu-devel] [PATCH 03/13] 9p: introduce the v9fs_get_fd_fid() helper 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This will be used by all file descriptor based ops. Signed-off-by: Greg Kurz --- hw/9pfs/9p-handle.c | 12 ++---------- hw/9pfs/9p-local.c | 12 ++---------- hw/9pfs/9p-proxy.c | 12 ++---------- hw/9pfs/9p.c | 13 +++++++++++++ hw/9pfs/9p.h | 2 ++ 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 3d77594f9245..2e741535df24 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -259,11 +259,7 @@ static int handle_fstat(FsContext *fs_ctx, int fid_type, { int fd; - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } + fd = v9fs_get_fd_fid(fid_type, fs); return fstat(fd, stbuf); } @@ -406,11 +402,7 @@ static int handle_fsync(FsContext *ctx, int fid_type, { int fd; - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } + fd = v9fs_get_fd_fid(fid_type, fs); if (datasync) { return qemu_fdatasync(fd); diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index b363711fe2f0..6804c6558b8e 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -630,11 +630,7 @@ static int local_fstat(FsContext *fs_ctx, int fid_type, { int err, fd; - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } + fd = v9fs_get_fd_fid(fid_type, fs); err = fstat(fd, stbuf); if (err) { @@ -1001,11 +997,7 @@ static int local_fsync(FsContext *ctx, int fid_type, { int fd; - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } + fd = v9fs_get_fd_fid(fid_type, fs); if (datasync) { return qemu_fdatasync(fd); diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index f265501eac1d..d78ff7b1bd8d 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -788,11 +788,7 @@ static int proxy_fstat(FsContext *fs_ctx, int fid_type, { int fd; - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } + fd = v9fs_get_fd_fid(fid_type, fs); return fstat(fd, stbuf); } @@ -933,11 +929,7 @@ static int proxy_fsync(FsContext *ctx, int fid_type, { int fd; - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } + fd = v9fs_get_fd_fid(fid_type, fs); if (datasync) { return qemu_fdatasync(fd); diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 9acff9293c60..626d4aa8ebb6 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -240,6 +240,19 @@ static int v9fs_reopen_fid(V9fsPDU *pdu, V9fsFidState *f) return err; } +int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs) +{ + int fd = -1; + + if (fid_type == P9_FID_DIR) { + fd = dirfd(fs->dir.stream); + } else if (fid_type == P9_FID_FILE) { + fd = fs->fd; + } + + return fd; +} + static V9fsFidState *get_fid(V9fsPDU *pdu, int32_t fid) { int err; diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index d2030fdf56e9..d0ccc0089771 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -202,6 +202,8 @@ union V9fsFidOpenState { void *private; }; +extern int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs); + struct V9fsFidState { int fid_type;