From patchwork Mon Jun 27 09:42:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9200225 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 F320260752 for ; Mon, 27 Jun 2016 09:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E300028326 for ; Mon, 27 Jun 2016 09:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5CD828572; Mon, 27 Jun 2016 09:50:47 +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 4BD221FF10 for ; Mon, 27 Jun 2016 09:50:47 +0000 (UTC) Received: from localhost ([::1]:57538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHTBm-0002mk-A4 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Jun 2016 05:50:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3s-0000kn-Fb for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHT3p-0005FO-97 for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43587) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3p-0005F8-0m for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:33 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dJaq018593 for ; Mon, 27 Jun 2016 05:42:32 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 23sp1ne2hk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:42:32 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 05:42:31 -0400 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 05:42:29 -0400 X-IBM-Helo: d01dlp03.pok.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 36402C90042; Mon, 27 Jun 2016 05:42:20 -0400 (EDT) Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9gUub9961778; Mon, 27 Jun 2016 09:42:30 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1F7C9112073; Mon, 27 Jun 2016 05:42:29 -0400 (EDT) Received: from bahia.lan (unknown [9.164.189.130]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id E4B6011206F; Mon, 27 Jun 2016 05:42:27 -0400 (EDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:42:26 +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-0040-0000-0000-000000AA682F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0041-0000-0000-000004845DF2 Message-Id: <146702054693.5764.4075650484995253066.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.156.1 Subject: [Qemu-devel] [PATCH 11/13] 9p: xattr fid to reference file fid 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 The flistxattr() and fgetxattr() syscalls in the guest are implementend with XATTRWALK. In v9fs_xattrwalk(), we then create a xattr fid to hold the the file path, and retrieve the xattr from the fs backend with llistxattr() or lgetxattr(). This patch brings file descriptor support to fids with type P9_FID_XATTR, so that the backend can use flistxattr() and fgetxattr(). This is done by keeping a reference to the original fid until the xattr fid gets clunked. Xattr fids created during XATTRCREATE (setxattr/removexattr in the guest), are not affected: the guest does not provide the related open fid and we have no reference to keep. In this case, the xattr operation will continue to be based on the path. Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 28 ++++++++++++++++++++++++---- hw/9pfs/9p.h | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 8824b71f364b..d02f95634b97 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -248,6 +248,12 @@ int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs) fd = dirfd(fs->dir.stream); } else if (fid_type == P9_FID_FILE) { fd = fs->fd; + } else if (fid_type == P9_FID_XATTR) { + V9fsFidState *fidp = fs->xattr.file; + + if (fidp) { + return v9fs_get_fd_fid(fidp->fid_type, &fidp->fs); + } } return fd; @@ -265,6 +271,12 @@ static bool fid_has_file(V9fsFidState *fidp) if (fidp->fs.fd > -1) { return true; } + } else if (fid_type == P9_FID_XATTR) { + V9fsFidState *file = fidp->fs.xattr.file; + + if (file) { + return fid_has_file(file); + } } return false; @@ -368,6 +380,8 @@ free_value: return retval; } +static int put_fid(V9fsPDU *pdu, V9fsFidState *fidp); + static int free_fid(V9fsPDU *pdu, V9fsFidState *fidp) { int retval = 0; @@ -382,7 +396,13 @@ static int free_fid(V9fsPDU *pdu, V9fsFidState *fidp) retval = v9fs_co_closedir(pdu, &fidp->fs); } } else if (fidp->fid_type == P9_FID_XATTR) { + V9fsFidState *file_fidp = fidp->fs.xattr.file; + retval = v9fs_xattr_fid_clunk(pdu, fidp); + if (file_fidp) { + fidp->fs.xattr.file = NULL; + put_fid(pdu, file_fidp); + } } v9fs_path_free(&fidp->path); g_free(fidp); @@ -3125,6 +3145,10 @@ static void v9fs_xattrwalk(void *opaque) goto out; } v9fs_path_copy(&xattr_fidp->path, &file_fidp->path); + xattr_fidp->fid_type = P9_FID_XATTR; + xattr_fidp->fs.xattr.copied_len = -1; + xattr_fidp->fs.xattr.file = file_fidp; + file_fidp->ref++; if (name.data == NULL) { /* * listxattr request. Get the size first @@ -3139,8 +3163,6 @@ static void v9fs_xattrwalk(void *opaque) * Read the xattr value */ xattr_fidp->fs.xattr.len = size; - xattr_fidp->fid_type = P9_FID_XATTR; - xattr_fidp->fs.xattr.copied_len = -1; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); err = v9fs_co_llistxattr(pdu, &xattr_fidp->path, @@ -3172,8 +3194,6 @@ static void v9fs_xattrwalk(void *opaque) * Read the xattr value */ xattr_fidp->fs.xattr.len = size; - xattr_fidp->fid_type = P9_FID_XATTR; - xattr_fidp->fs.xattr.copied_len = -1; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index d0ccc0089771..0b9db6bd8c38 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -164,6 +164,7 @@ typedef struct V9fsXattr void *value; V9fsString name; int flags; + V9fsFidState *file; } V9fsXattr; typedef struct V9fsDir {