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: 9200209 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 217BD60752 for ; Mon, 27 Jun 2016 09:42:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10BC0284D4 for ; Mon, 27 Jun 2016 09:42:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 059302856B; Mon, 27 Jun 2016 09:42:41 +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=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 782DC284D4 for ; Mon, 27 Jun 2016 09:42:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bHT3v-0003Hi-It; Mon, 27 Jun 2016 09:42:39 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bHT3u-0003Hd-3f for v9fs-developer@lists.sourceforge.net; Mon, 27 Jun 2016 09:42:38 +0000 Received-SPF: softfail (sog-mx-3.v43.ch3.sourceforge.com: transitioning domain of kaod.org does not designate 148.163.158.5 as permitted sender) client-ip=148.163.158.5; envelope-from=groug@kaod.org; helo=mx0a-001b2d01.pphosted.com; Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5] helo=mx0a-001b2d01.pphosted.com) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1bHT3t-0003bX-7r for v9fs-developer@lists.sourceforge.net; Mon, 27 Jun 2016 09:42:38 +0000 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dLro017529 for ; Mon, 27 Jun 2016 05:42:31 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0b-001b2d01.pphosted.com with ESMTP id 23sjvw97wt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:42:31 -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-Headers-End: 1bHT3t-0003bX-7r Cc: Eric Van Hensbergen , v9fs-developer@lists.sourceforge.net, "Aneesh Kumar K.V" , Greg Kurz Subject: [V9fs-developer] [PATCH 11/13] 9p: xattr fid to reference file fid X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: v9fs-developer-bounces@lists.sourceforge.net 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(-) ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape 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 {