From patchwork Mon Jun 27 09:42:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9200211 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 BFD2C60752 for ; Mon, 27 Jun 2016 09:42:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE35E284D4 for ; Mon, 27 Jun 2016 09:42:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A30222856B; Mon, 27 Jun 2016 09:42:55 +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 7B477284D4 for ; Mon, 27 Jun 2016 09:42:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bHT44-00019K-B9; Mon, 27 Jun 2016 09:42:48 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bHT43-00019A-BG for v9fs-developer@lists.sourceforge.net; Mon, 27 Jun 2016 09:42:47 +0000 Received-SPF: softfail (sog-mx-4.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-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1bHT42-0007EM-9m for v9fs-developer@lists.sourceforge.net; Mon, 27 Jun 2016 09:42:47 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dKPN069557 for ; Mon, 27 Jun 2016 05:42:40 -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 23snu2wvqm-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:42:40 -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:40 -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:37 -0400 X-IBM-Helo: d01dlp03.pok.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 99166C90041; Mon, 27 Jun 2016 05:42:27 -0400 (EDT) Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9gaKQ60686500; Mon, 27 Jun 2016 09:42:36 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 889A0AE04E; Mon, 27 Jun 2016 05:42:36 -0400 (EDT) Received: from bahia.lan (unknown [9.164.189.130]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 65CB1AE03C; Mon, 27 Jun 2016 05:42:35 -0400 (EDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:42:34 +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-000000AA6840 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0041-0000-0000-000004845E01 Message-Id: <146702055438.5764.1869722864191388933.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: 1bHT42-0007EM-9m Cc: Eric Van Hensbergen , v9fs-developer@lists.sourceforge.net, "Aneesh Kumar K.V" , Greg Kurz Subject: [V9fs-developer] [PATCH 12/13] 9p: introduce fgetxattr file op 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 This allows fgetxattr() in the guest to stay functional even if the file was unlinked. Signed-off-by: Greg Kurz --- fsdev/file-op-9p.h | 2 ++ hw/9pfs/9p-handle.c | 11 +++++++++++ hw/9pfs/9p-local.c | 11 +++++++++++ hw/9pfs/9p-proxy.c | 12 ++++++++++++ hw/9pfs/9p-synth.c | 9 +++++++++ hw/9pfs/9p.c | 21 +++++++++++++++------ hw/9pfs/coth.h | 2 ++ hw/9pfs/coxattr.c | 22 ++++++++++++++++++++++ 8 files changed, 84 insertions(+), 6 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/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 8094d2c6c438..683596797b51 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -145,6 +145,8 @@ struct FileOperations const struct timespec *); int (*fchown)(FsContext *, int, V9fsFidOpenState *, FsCred *); int (*fchmod)(FsContext *, int, V9fsFidOpenState *, FsCred *); + ssize_t (*fgetxattr)(FsContext *, int, V9fsFidOpenState *, + const char *, void *, size_t); void *opaque; }; diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index f345217aa8e1..3153acff663c 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -477,6 +477,16 @@ static ssize_t handle_lgetxattr(FsContext *ctx, V9fsPath *fs_path, return ret; } +static ssize_t handle_fgetxattr(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, const char *name, + void *value, size_t size) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return fgetxattr(fd, name, value, size); +} + static ssize_t handle_llistxattr(FsContext *ctx, V9fsPath *fs_path, void *value, size_t size) { @@ -736,4 +746,5 @@ FileOperations handle_ops = { .futimens = handle_futimens, .fchown = handle_fchown, .fchmod = handle_fchmod, + .fgetxattr = handle_fgetxattr, }; diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index e51c58037266..206849a3ed83 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1104,6 +1104,16 @@ static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path, return v9fs_get_xattr(ctx, -1, path, name, value, size); } +static ssize_t local_fgetxattr(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, const char *name, + void *value, size_t size) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return v9fs_get_xattr(ctx, fd, NULL, name, value, size); +} + static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path, void *value, size_t size) { @@ -1357,4 +1367,5 @@ FileOperations local_ops = { .futimens = local_futimens, .fchown = local_fchown, .fchmod = local_fchmod, + .fgetxattr = local_fgetxattr, }; diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index dec4a861a073..074799027873 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -17,6 +17,7 @@ #include "qemu/error-report.h" #include "fsdev/qemu-fsdev.h" #include "9p-proxy.h" +#include "qemu/xattr.h" typedef struct V9fsProxy { int sockfd; @@ -1006,6 +1007,16 @@ static ssize_t proxy_lgetxattr(FsContext *ctx, V9fsPath *fs_path, return retval; } +static ssize_t proxy_fgetxattr(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, const char *name, + void *value, size_t size) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return fgetxattr(fd, name, value, size); +} + static ssize_t proxy_llistxattr(FsContext *ctx, V9fsPath *fs_path, void *value, size_t size) { @@ -1251,4 +1262,5 @@ FileOperations proxy_ops = { .futimens = proxy_futimens, .fchown = proxy_fchown, .fchmod = proxy_fchmod, + .fgetxattr = proxy_fgetxattr, }; diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index ec2e301de8c6..24505fc2f621 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -464,6 +464,14 @@ static ssize_t synth_lgetxattr(FsContext *ctx, V9fsPath *path, return -1; } +static ssize_t synth_fgetxattr(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, const char *name, + void *value, size_t size) +{ + errno = ENOTSUP; + return -1; +} + static ssize_t synth_llistxattr(FsContext *ctx, V9fsPath *path, void *value, size_t size) { @@ -598,4 +606,5 @@ FileOperations synth_ops = { .futimens = synth_futimens, .fchown = synth_fchown, .fchmod = synth_fchmod, + .fgetxattr = synth_fgetxattr, }; diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index d02f95634b97..435100f85be3 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3115,6 +3115,16 @@ out_nofid: v9fs_string_free(&name); } +static int v9fs_do_getxattr(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, + void *value, size_t size) +{ + if (fid_has_file(fidp)) { + return v9fs_co_fgetxattr(pdu, fidp, name, value, size); + } else { + return v9fs_co_lgetxattr(pdu, &fidp->path, name, value, size); + } +} + static void v9fs_xattrwalk(void *opaque) { int64_t size; @@ -3181,10 +3191,9 @@ static void v9fs_xattrwalk(void *opaque) } else { /* * specific xattr fid. We check for xattr - * presence also collect the xattr size + * presence also collect the xattr size. */ - size = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, - &name, NULL, 0); + size = v9fs_do_getxattr(pdu, xattr_fidp, &name, NULL, 0); if (size < 0) { err = size; clunk_fid(s, xattr_fidp->fid); @@ -3196,9 +3205,9 @@ static void v9fs_xattrwalk(void *opaque) xattr_fidp->fs.xattr.len = size; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); - err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, - &name, xattr_fidp->fs.xattr.value, - xattr_fidp->fs.xattr.len); + err = v9fs_do_getxattr(pdu, xattr_fidp, &name, + xattr_fidp->fs.xattr.value, + xattr_fidp->fs.xattr.len); if (err < 0) { clunk_fid(s, xattr_fidp->fid); goto out; diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h index ee819a7eed54..2e507939d01d 100644 --- a/hw/9pfs/coth.h +++ b/hw/9pfs/coth.h @@ -98,5 +98,7 @@ extern int v9fs_co_ftruncate(V9fsPDU *, V9fsFidState *, off_t); extern int v9fs_co_futimens(V9fsPDU *, V9fsFidState *, struct timespec [2]); extern int v9fs_co_fchown(V9fsPDU *, V9fsFidState *, uid_t, gid_t); extern int v9fs_co_fchmod(V9fsPDU *, V9fsFidState *, mode_t); +extern int v9fs_co_fgetxattr(V9fsPDU *, V9fsFidState *, V9fsString *, void *, + size_t); #endif diff --git a/hw/9pfs/coxattr.c b/hw/9pfs/coxattr.c index 133c4ead37b6..72e3f38fb371 100644 --- a/hw/9pfs/coxattr.c +++ b/hw/9pfs/coxattr.c @@ -61,6 +61,28 @@ int v9fs_co_lgetxattr(V9fsPDU *pdu, V9fsPath *path, return err; } +int v9fs_co_fgetxattr(V9fsPDU *pdu, V9fsFidState *fidp, + V9fsString *xattr_name, + void *value, size_t size) +{ + int err; + V9fsState *s = pdu->s; + + if (v9fs_request_cancelled(pdu)) { + return -EINTR; + } + v9fs_co_run_in_worker( + { + err = s->ops->fgetxattr(&s->ctx, fidp->fid_type, &fidp->fs, + xattr_name->data, + value, size); + if (err < 0) { + err = -errno; + } + }); + return err; +} + int v9fs_co_lsetxattr(V9fsPDU *pdu, V9fsPath *path, V9fsString *xattr_name, void *value, size_t size, int flags)