From patchwork Mon Jun 27 09:41:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9200197 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 C548860752 for ; Mon, 27 Jun 2016 09:42:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5C68284D4 for ; Mon, 27 Jun 2016 09:42:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA2232856B; Mon, 27 Jun 2016 09:42:01 +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 3B3D3284D4 for ; Mon, 27 Jun 2016 09:42:00 +0000 (UTC) Received: from localhost ([::1]:57490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3I-0007LI-4z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Jun 2016 05:42:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT2j-0007J9-F1 for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHT2g-0004sY-7F for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT2f-0004sR-Vv for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:41:22 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dJGF131502 for ; Mon, 27 Jun 2016 05:41:20 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 23sjug1kps-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:41:20 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 03:41:19 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 03:41:15 -0600 X-IBM-Helo: d03dlp01.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 d03dlp01.boulder.ibm.com (Postfix) with ESMTP id EF6BA1FF001E; Mon, 27 Jun 2016 03:40:58 -0600 (MDT) Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9fFps51904604; Mon, 27 Jun 2016 02:41:15 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 324FE6E038; Mon, 27 Jun 2016 03:41:15 -0600 (MDT) Received: from bahia.lan (unknown [9.164.189.130]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 8A5176E035; Mon, 27 Jun 2016 03:41:13 -0600 (MDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:41:11 +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-0016-0000-0000-0000040C0852 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0017-0000-0000-0000309408B0 Message-Id: <146702047178.5764.3699385716749689462.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 02/13] 9p: factour out duplicate code from local_fstat() and local_lstat() 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 This does not change functionality. Signed-off-by: Greg Kurz --- hw/9pfs/9p-local.c | 68 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 3f271fcbd2c5..b363711fe2f0 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -117,36 +117,55 @@ static void local_mapped_file_attr(FsContext *ctx, const char *path, fclose(fp); } -static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) +static int local_do_getxattr(int fd, const char *path, + const char *name, void *value, size_t size) { - int err; - char *buffer; - char *path = fs_path->data; - - buffer = rpath(fs_ctx, path); - err = lstat(buffer, stbuf); - if (err) { - goto err_out; + if (path) { + return getxattr(path, name, value, size); + } else { + return fgetxattr(fd, name, value, size); } - if (fs_ctx->export_flags & V9FS_SM_MAPPED) { +} + +static void local_mapped_attr(int fd, char *path, struct stat *stbuf) +{ /* Actual credentials are part of extended attrs */ uid_t tmp_uid; gid_t tmp_gid; mode_t tmp_mode; dev_t tmp_dev; - if (getxattr(buffer, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) { + + if (local_do_getxattr(fd, path, "user.virtfs.uid", &tmp_uid, + sizeof(uid_t)) > 0) { stbuf->st_uid = le32_to_cpu(tmp_uid); } - if (getxattr(buffer, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) { + if (local_do_getxattr(fd, path, "user.virtfs.gid", &tmp_gid, + sizeof(gid_t)) > 0) { stbuf->st_gid = le32_to_cpu(tmp_gid); } - if (getxattr(buffer, "user.virtfs.mode", - &tmp_mode, sizeof(mode_t)) > 0) { + if (local_do_getxattr(fd, path, "user.virtfs.mode", &tmp_mode, + sizeof(mode_t)) > 0) { stbuf->st_mode = le32_to_cpu(tmp_mode); } - if (getxattr(buffer, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) { + if (local_do_getxattr(fd, path, "user.virtfs.rdev", &tmp_dev, + sizeof(dev_t)) > 0) { stbuf->st_rdev = le64_to_cpu(tmp_dev); } +} + +static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) +{ + int err; + char *buffer; + char *path = fs_path->data; + + buffer = rpath(fs_ctx, path); + err = lstat(buffer, stbuf); + if (err) { + goto err_out; + } + if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + local_mapped_attr(-1, buffer, stbuf); } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { local_mapped_file_attr(fs_ctx, path, stbuf); } @@ -622,24 +641,7 @@ static int local_fstat(FsContext *fs_ctx, int fid_type, return err; } if (fs_ctx->export_flags & V9FS_SM_MAPPED) { - /* Actual credentials are part of extended attrs */ - uid_t tmp_uid; - gid_t tmp_gid; - mode_t tmp_mode; - dev_t tmp_dev; - - if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) { - stbuf->st_uid = le32_to_cpu(tmp_uid); - } - if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) { - stbuf->st_gid = le32_to_cpu(tmp_gid); - } - if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) { - stbuf->st_mode = le32_to_cpu(tmp_mode); - } - if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) { - stbuf->st_rdev = le64_to_cpu(tmp_dev); - } + local_mapped_attr(fd, NULL, stbuf); } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { errno = EOPNOTSUPP; return -1;