From patchwork Mon Jun 27 09:42: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: 640912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rdPQ63zXzz9sdb for ; Mon, 27 Jun 2016 19:53:18 +1000 (AEST) Received: from localhost ([::1]:57552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHTEC-00079V-Ea for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2016 05:53:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3f-0000WW-0n for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHT3b-0005AW-PR for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:22 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54875) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHT3b-0005AQ-GY for qemu-devel@nongnu.org; Mon, 27 Jun 2016 05:42:19 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5R9dKC2100456 for ; Mon, 27 Jun 2016 05:42:18 -0400 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0a-001b2d01.pphosted.com with ESMTP id 23spg6w7hk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 05:42:18 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 05:42:17 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 05:42:14 -0400 X-IBM-Helo: d01dlp01.pok.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 3B9DC38C8046; Mon, 27 Jun 2016 05:42:14 -0400 (EDT) Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5R9gGTn55902418; Mon, 27 Jun 2016 09:42:16 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D6DE12403F; Mon, 27 Jun 2016 05:42:14 -0400 (EDT) Received: from bahia.lan (unknown [9.164.189.130]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP id 92DF2124037; Mon, 27 Jun 2016 05:42:12 -0400 (EDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 11:42: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-0056-0000-0000-000000A133DD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062709-0057-0000-0000-000004BAA8D7 Message-Id: <146702053133.5764.14891011245595156322.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 09/13] 9p: introduce fchown 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This allows fchown() 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 | 22 ++++++++++++++++++++++ hw/9pfs/9p-proxy.c | 10 ++++++++++ hw/9pfs/9p-synth.c | 8 ++++++++ hw/9pfs/9p.c | 18 +++++++++++++++--- hw/9pfs/cofs.c | 22 ++++++++++++++++++++++ hw/9pfs/coth.h | 1 + 8 files changed, 89 insertions(+), 3 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 811ca234cf86..1c15d6efdaea 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -143,6 +143,7 @@ struct FileOperations int (*ftruncate)(FsContext *, int, V9fsFidOpenState *, off_t); int (*futimens)(FsContext *, int, V9fsFidOpenState *, const struct timespec *); + int (*fchown)(FsContext *, int, V9fsFidOpenState *, FsCred *); void *opaque; }; diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 382b4d57927a..7e8e776cdab0 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -384,6 +384,15 @@ static int handle_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) return ret; } +static int handle_fchown(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return fchown(fd, credp->fc_uid, credp->fc_gid); +} + static int handle_utimensat(FsContext *ctx, V9fsPath *fs_path, const struct timespec *buf) { @@ -716,4 +725,5 @@ FileOperations handle_ops = { .unlinkat = handle_unlinkat, .ftruncate = handle_ftruncate, .futimens = handle_futimens, + .fchown = handle_fchown, }; diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 873bd4b9d997..bc8d3bff1308 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -954,6 +954,27 @@ static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) return ret; } +static int local_fchown(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + int ret = -1; + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + + if ((credp->fc_uid == -1 && credp->fc_gid == -1) || + (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || + (fs_ctx->export_flags & V9FS_SM_NONE)) { + ret = fchown(fd, credp->fc_uid, credp->fc_gid); + } else 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 = EOPNOTSUPP; + return -1; + } + return ret; +} + static int local_utimensat(FsContext *s, V9fsPath *fs_path, const struct timespec *buf) { @@ -1314,4 +1335,5 @@ FileOperations local_ops = { .unlinkat = local_unlinkat, .ftruncate = local_ftruncate, .futimens = local_futimens, + .fchown = local_fchown, }; diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index cbc94b645852..8f2e27c6f8e4 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -909,6 +909,15 @@ static int proxy_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) return retval; } +static int proxy_fchown(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + int fd; + + fd = v9fs_get_fd_fid(fid_type, fs); + return fchown(fd, credp->fc_uid, credp->fc_gid); +} + static int proxy_utimensat(FsContext *s, V9fsPath *fs_path, const struct timespec *buf) { @@ -1231,4 +1240,5 @@ FileOperations proxy_ops = { .unlinkat = proxy_unlinkat, .ftruncate = proxy_ftruncate, .futimens = proxy_futimens, + .fchown = proxy_fchown, }; diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index c4770792a79f..b0f9b0cd67f6 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -405,6 +405,13 @@ static int synth_chown(FsContext *fs_ctx, V9fsPath *path, FsCred *credp) return -1; } +static int synth_fchown(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, + FsCred *credp) +{ + errno = EPERM; + return -1; +} + static int synth_utimensat(FsContext *fs_ctx, V9fsPath *path, const struct timespec *buf) { @@ -582,4 +589,5 @@ FileOperations synth_ops = { .unlinkat = synth_unlinkat, .ftruncate = synth_ftruncate, .futimens = synth_futimens, + .fchown = synth_fchown, }; diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 97dba6190809..351bbdde4748 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1208,6 +1208,19 @@ static int v9fs_do_utimens(V9fsPDU *pdu, V9fsFidState *fidp, return err; } +static int v9fs_do_chown(V9fsPDU *pdu, V9fsFidState *fidp, uid_t uid, gid_t gid) +{ + int err; + + if (fid_has_file(fidp)) { + err = v9fs_co_fchown(pdu, fidp, uid, gid); + } else { + err = v9fs_co_chown(pdu, &fidp->path, uid, gid); + } + + return err; +} + /* Attribute flags */ #define P9_ATTR_MODE (1 << 0) #define P9_ATTR_UID (1 << 1) @@ -1286,8 +1299,7 @@ static void v9fs_setattr(void *opaque) if (!(v9iattr.valid & P9_ATTR_GID)) { v9iattr.gid = -1; } - err = v9fs_co_chown(pdu, &fidp->path, v9iattr.uid, - v9iattr.gid); + err = v9fs_do_chown(pdu, fidp, v9iattr.uid, v9iattr.gid); if (err < 0) { goto out; } @@ -2769,7 +2781,7 @@ static void v9fs_wstat(void *opaque) } } if (v9stat.n_gid != -1 || v9stat.n_uid != -1) { - err = v9fs_co_chown(pdu, &fidp->path, v9stat.n_uid, v9stat.n_gid); + err = v9fs_do_chown(pdu, fidp, v9stat.n_uid, v9stat.n_gid); if (err < 0) { goto out; } diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c index 1ed9c298f98d..4e8fbbe2b24e 100644 --- a/hw/9pfs/cofs.c +++ b/hw/9pfs/cofs.c @@ -175,6 +175,28 @@ int v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid, gid_t gid) return err; } +int v9fs_co_fchown(V9fsPDU *pdu, V9fsFidState *fidp, uid_t uid, gid_t gid) +{ + int err; + FsCred cred; + V9fsState *s = pdu->s; + + if (v9fs_request_cancelled(pdu)) { + return -EINTR; + } + cred_init(&cred); + cred.fc_uid = uid; + cred.fc_gid = gid; + v9fs_co_run_in_worker( + { + err = s->ops->fchown(&s->ctx, fidp->fid_type, &fidp->fs, &cred); + if (err < 0) { + err = -errno; + } + }); + return err; +} + int v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size) { int err; diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h index c4e90059f00c..7050298f7170 100644 --- a/hw/9pfs/coth.h +++ b/hw/9pfs/coth.h @@ -96,5 +96,6 @@ extern int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t, V9fsStatDotl *v9stat); 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); #endif