From patchwork Mon Jun 27 09:42:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9200217 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 9F09260752 for ; Mon, 27 Jun 2016 09:46:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D4502856D for ; Mon, 27 Jun 2016 09:46:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8187528570; Mon, 27 Jun 2016 09:46:17 +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 E84462856D for ; Mon, 27 Jun 2016 09:46:16 +0000 (UTC) Received: from localhost ([::1]:57513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT7Q-0005DZ-2v for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Jun 2016 05:46:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3n-0000f6-8s for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHT3j-0005D4-00 for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:25910 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3i-0005Ct-QD for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:26 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dNsv025966 for ; Mon, 27 Jun 2016 05:42:26 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 23sp4ynbv3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:42:26 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 03:42:24 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 03:42:22 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 1E9BB3E40047; Mon, 27 Jun 2016 03:42:22 -0600 (MDT) Received: from b01ledav03.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9gLud57213078; Mon, 27 Jun 2016 09:42:21 GMT Received: from b01ledav03.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AEEEAB2046; Mon, 27 Jun 2016 05:42:21 -0400 (EDT) Received: from bahia.lan (unknown [9.164.189.130]) by b01ledav03.gho.pok.ibm.com (Postfix) with ESMTP id 5B63DB204E; Mon, 27 Jun 2016 05:42:20 -0400 (EDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:42:19 +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-0008-0000-0000-000004EA699E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0009-0000-0000-000038C5B5B6 Message-Id: <146702053933.5764.3461001250809532780.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.158.5 Subject: [Qemu-devel] [PATCH 10/13] 9p: introduce fchmod file op 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 allows fchmod() in the guest to stay functional even if the file was unlinked. Signed-off-by: Greg Kurz --- fsdev/file-op-9p.h | 1 + hw/9pfs/9p-handle.c | 10 ++++++++++ hw/9pfs/9p-local.c | 21 +++++++++++++++++++++ hw/9pfs/9p-proxy.c | 10 ++++++++++ hw/9pfs/9p-synth.c | 8 ++++++++ hw/9pfs/9p.c | 20 ++++++++++++++++---- hw/9pfs/cofs.c | 21 +++++++++++++++++++++ hw/9pfs/coth.h | 1 + 8 files changed, 88 insertions(+), 4 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 1c15d6efdaea..8094d2c6c438 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -144,6 +144,7 @@ struct FileOperations int (*futimens)(FsContext *, int, V9fsFidOpenState *, const struct timespec *); int (*fchown)(FsContext *, int, V9fsFidOpenState *, FsCred *); + int (*fchmod)(FsContext *, int, V9fsFidOpenState *, FsCred *); void *opaque; }; diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 7e8e776cdab0..f345217aa8e1 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -218,6 +218,15 @@ static int handle_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) return ret; } +static int handle_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return fchmod(fd, credp->fc_mode); +} + static int handle_mknod(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, FsCred *credp) { @@ -726,4 +735,5 @@ FileOperations handle_ops = { .ftruncate = handle_ftruncate, .futimens = handle_futimens, .fchown = handle_fchown, + .fchmod = handle_fchmod, }; diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index bc8d3bff1308..e51c58037266 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -516,6 +516,26 @@ static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) return ret; } +static int local_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + int ret = -1; + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + + if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + ret = local_set_xattr(fd, NULL, credp); + } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { + errno = ENOTSUP; + return -1; + } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || + (fs_ctx->export_flags & V9FS_SM_NONE)) { + ret = fchmod(fd, credp->fc_mode); + } + return ret; +} + static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, FsCred *credp) { @@ -1336,4 +1356,5 @@ FileOperations local_ops = { .ftruncate = local_ftruncate, .futimens = local_futimens, .fchown = local_fchown, + .fchmod = local_fchmod, }; diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 8f2e27c6f8e4..dec4a861a073 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -743,6 +743,15 @@ static int proxy_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) return retval; } +static int proxy_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return fchmod(fd, credp->fc_mode); +} + static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, FsCred *credp) { @@ -1241,4 +1250,5 @@ FileOperations proxy_ops = { .ftruncate = proxy_ftruncate, .futimens = proxy_futimens, .fchown = proxy_fchown, + .fchmod = proxy_fchmod, }; diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index b0f9b0cd67f6..ec2e301de8c6 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -357,6 +357,13 @@ static int synth_chmod(FsContext *fs_ctx, V9fsPath *path, FsCred *credp) return -1; } +static int synth_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + errno = EPERM; + return -1; +} + static int synth_mknod(FsContext *fs_ctx, V9fsPath *path, const char *buf, FsCred *credp) { @@ -590,4 +597,5 @@ FileOperations synth_ops = { .ftruncate = synth_ftruncate, .futimens = synth_futimens, .fchown = synth_fchown, + .fchmod = synth_fchmod, }; diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 351bbdde4748..8824b71f364b 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1221,6 +1221,19 @@ static int v9fs_do_chown(V9fsPDU *pdu, V9fsFidState *fidp, uid_t uid, gid_t gid) return err; } +static int v9fs_do_chmod(V9fsPDU *pdu, V9fsFidState *fidp, mode_t mode) +{ + int err; + + if (fid_has_file(fidp)) { + err = v9fs_co_fchmod(pdu, fidp, mode); + } else { + err = v9fs_co_chmod(pdu, &fidp->path, mode); + } + + return err; +} + /* Attribute flags */ #define P9_ATTR_MODE (1 << 0) #define P9_ATTR_UID (1 << 1) @@ -1254,7 +1267,7 @@ static void v9fs_setattr(void *opaque) goto out_nofid; } if (v9iattr.valid & P9_ATTR_MODE) { - err = v9fs_co_chmod(pdu, &fidp->path, v9iattr.mode); + err = v9fs_do_chmod(pdu, fidp, v9iattr.mode); if (err < 0) { goto out; } @@ -2754,9 +2767,8 @@ static void v9fs_wstat(void *opaque) err = -EIO; goto out; } - err = v9fs_co_chmod(pdu, &fidp->path, - v9mode_to_mode(v9stat.mode, - &v9stat.extension)); + err = v9fs_do_chmod(pdu, fidp, v9mode_to_mode(v9stat.mode, + &v9stat.extension)); if (err < 0) { goto out; } diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c index 4e8fbbe2b24e..779997dc0e33 100644 --- a/hw/9pfs/cofs.c +++ b/hw/9pfs/cofs.c @@ -112,6 +112,27 @@ int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode) return err; } +int v9fs_co_fchmod(V9fsPDU *pdu, V9fsFidState *fidp, mode_t mode) +{ + int err; + FsCred cred; + V9fsState *s = pdu->s; + + if (v9fs_request_cancelled(pdu)) { + return -EINTR; + } + cred_init(&cred); + cred.fc_mode = mode; + v9fs_co_run_in_worker( + { + err = s->ops->fchmod(&s->ctx, fidp->fid_type, &fidp->fs, &cred); + if (err < 0) { + err = -errno; + } + }); + return err; +} + int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path, struct timespec times[2]) { diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h index 7050298f7170..ee819a7eed54 100644 --- a/hw/9pfs/coth.h +++ b/hw/9pfs/coth.h @@ -97,5 +97,6 @@ extern int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t, 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); #endif