From nobody Thu May 9 14:10:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602503239; cv=none; d=zohomail.com; s=zohoarc; b=KrWvpuDyB7Ixrqv55x5S4PBrgAHEgJfu5g+hmjwKj5iVOfJMDWPEDd4abGACDW1m3i/ZLEIpnmkzjRnkz5oyoZCmMDJDmbuOMT3H8vnAhQYwD3vKyTBjIPI8qnkmgdR8umwARpPwUqXCakVsskTO8Cj1WqhBVhppUhujKd+n0ps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602503239; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hE5tVBwV/RnyMnB02VZVAukfGpAPywHYUJDs3ZCWRMw=; b=CzFdGdsPt+tvaeX0QqvtMkDLXtqUa7UMtJvpD75ut0LCzKCLr7EHRKrBgcCV8Tk1LpPAvAZBQP52BVty1bKo+SsUq95kgkRrLiIzo+XnRIxeaCI6olTZVr6MfDBYeYN+SUc09y6Fn/ngBHLA2T2mquqZebVE8QHTWAtAdCqyRPk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602503239648320.34104378821803; Mon, 12 Oct 2020 04:47:19 -0700 (PDT) Received: from localhost ([::1]:39012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRwIQ-0002AC-HX for importer@patchew.org; Mon, 12 Oct 2020 07:47:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRwG0-0000Ym-SN for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRwFt-0008A9-Cl for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-NGq-BGeHM2y3bB2OCJJerQ-1; Mon, 12 Oct 2020 07:44:39 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 960B018A8220; Mon, 12 Oct 2020 11:44:37 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6A3519C78; Mon, 12 Oct 2020 11:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602503080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hE5tVBwV/RnyMnB02VZVAukfGpAPywHYUJDs3ZCWRMw=; b=MwD4m3UbLVnIhW/2OrbA2miyEGcPwy2Fs3WF6vPQMcHpgF8gbJlKyXj3vHyJq/c8SYSCl5 /h6u6UtC+XD1KQCWAMTHdgwa9qset61kLbcT57weHVvmyPUWxMOugIGEubT2MdLS9ucMrS w+VZBH8/Eamqif/4soCHeq91zxlWTOg= X-MC-Unique: NGq-BGeHM2y3bB2OCJJerQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 1/6] virtiofsd: Silence gcc warning Date: Mon, 12 Oct 2020 12:44:20 +0100 Message-Id: <20201012114425.104765-2-dgilbert@redhat.com> In-Reply-To: <20201012114425.104765-1-dgilbert@redhat.com> References: <20201012114425.104765-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 23:52:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: "Dr. David Alan Gilbert" Gcc worries fd might be used unset, in reality it's always set if fi is set, and only used if fi is set so it's safe. Initialise it to -1 just to keep gcc happy for now. Signed-off-by: Dr. David Alan Gilbert Message-Id: <20200827153657.111098-2-dgilbert@redhat.com> Reviewed-by: J=C3=A1n Tomko Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 0b229ebd57..36ad46e0c0 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -620,7 +620,7 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, = struct stat *attr, struct lo_inode *inode; int ifd; int res; - int fd; + int fd =3D -1; =20 inode =3D lo_inode(req, ino); if (!inode) { --=20 2.28.0 From nobody Thu May 9 14:10:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602503997; cv=none; d=zohomail.com; s=zohoarc; b=eiLf3YrqOsyE1/mJG9xa9VsvAPm03G/SGSIv3Tpm2dCfoTb8SrQ3x3nS1sUw1PRyf0+z0fV2INUmwGCe9df+eYNSaPuEbRbMIo27vK3brLHB/1WfRW6s9lQOZLCuO3EPzVXseauCvPuRmT8G7vbuXMdsROBCoLS84ujGtbgWgpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602503997; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MIs8GSYndujj/IUhzFBYJYVlEAHzu8gUjnP34Xj8hpI=; b=MbfvRBYcO8rzm4op3utR3qSsj/zyTxlYwqx3fKx1D9cqUrkTJhMgtguJTXnG913MlhQYwvQ5SiJLYAnc7ej4l8JsDgos9ExB6uzbbsIGeXn6nswbf1pVziR13j19g6L2fJWIZrxDfEkEAMGjxSkCXdPfTfNPAm4VSsZquMF2Pf8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602503997453424.6197673647023; Mon, 12 Oct 2020 04:59:57 -0700 (PDT) Received: from localhost ([::1]:45236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRwUb-0008NI-Tl for importer@patchew.org; Mon, 12 Oct 2020 07:59:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRwG4-0000bb-Qs for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRwFx-0008AS-Uk for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-154-uEvCkDEIPB6Pv8stL71KtA-1; Mon, 12 Oct 2020 07:44:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44D4285C706; Mon, 12 Oct 2020 11:44:39 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3D6119C78; Mon, 12 Oct 2020 11:44:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602503082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MIs8GSYndujj/IUhzFBYJYVlEAHzu8gUjnP34Xj8hpI=; b=i/KBkio+AUhJ1ClyXn6ygmtqJZPRjPfdcet12xlmFNAeRfWrXcvvyv5vNXirOxtwzzrA3L vBYF6M65OSQo/7TId3FxZqz7JOoBrizz+g1/bJKYHYZhE4xuVdRF/d7WbLQnhjnnlI+sZu PMm3CSCzJRtwylx5qrflh4RKIE8Eldk= X-MC-Unique: uEvCkDEIPB6Pv8stL71KtA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 2/6] tools/virtiofsd: add support for --socket-group Date: Mon, 12 Oct 2020 12:44:21 +0100 Message-Id: <20201012114425.104765-3-dgilbert@redhat.com> In-Reply-To: <20201012114425.104765-1-dgilbert@redhat.com> References: <20201012114425.104765-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/12 02:58:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Alex Benn=C3=A9e If you like running QEMU as a normal user (very common for TCG runs) but you have to run virtiofsd as a root user you run into connection problems. Adding support for an optional --socket-group allows the users to keep using the command line. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Stefan Hajnoczi Message-Id: <20200925125147.26943-2-alex.bennee@linaro.org> Signed-off-by: Dr. David Alan Gilbert dgilbert: Split long line --- docs/tools/virtiofsd.rst | 4 ++++ tools/virtiofsd/fuse_i.h | 1 + tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ tools/virtiofsd/fuse_virtio.c | 21 +++++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index ae02938a95..7ecee49834 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -87,6 +87,10 @@ Options =20 Listen on vhost-user UNIX domain socket at PATH. =20 +.. option:: --socket-group=3DGROUP + + Set the vhost-user UNIX domain socket gid to GROUP. + .. option:: --fd=3DFDNUM =20 Accept connections from vhost-user UNIX domain socket file descriptor FD= NUM. diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h index 1240828208..492e002181 100644 --- a/tools/virtiofsd/fuse_i.h +++ b/tools/virtiofsd/fuse_i.h @@ -68,6 +68,7 @@ struct fuse_session { size_t bufsize; int error; char *vu_socket_path; + char *vu_socket_group; int vu_listen_fd; int vu_socketfd; struct fv_VuDev *virtio_dev; diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 2dd36ec03b..4d1ba2925d 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -2523,6 +2523,7 @@ static const struct fuse_opt fuse_ll_opts[] =3D { LL_OPTION("--debug", debug, 1), LL_OPTION("allow_root", deny_others, 1), LL_OPTION("--socket-path=3D%s", vu_socket_path, 0), + LL_OPTION("--socket-group=3D%s", vu_socket_group, 0), LL_OPTION("--fd=3D%d", vu_listen_fd, 0), LL_OPTION("--thread-pool-size=3D%d", thread_pool_size, 0), FUSE_OPT_END @@ -2630,6 +2631,11 @@ struct fuse_session *fuse_session_new(struct fuse_ar= gs *args, "fuse: --socket-path and --fd cannot be given together\n"= ); goto out4; } + if (se->vu_socket_group && !se->vu_socket_path) { + fuse_log(FUSE_LOG_ERR, + "fuse: --socket-group can only be used with --socket-path= \n"); + goto out4; + } =20 se->bufsize =3D FUSE_MAX_MAX_PAGES * getpagesize() + FUSE_BUFFER_HEADE= R_SIZE; =20 diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index d5c8e98253..89f537f79b 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include =20 #include "contrib/libvhost-user/libvhost-user.h" @@ -924,15 +926,30 @@ static int fv_create_listen_socket(struct fuse_sessio= n *se) =20 /* * Unfortunately bind doesn't let you set the mask on the socket, - * so set umask to 077 and restore it later. + * so set umask appropriately and restore it later. */ - old_umask =3D umask(0077); + if (se->vu_socket_group) { + old_umask =3D umask(S_IROTH | S_IWOTH | S_IXOTH); + } else { + old_umask =3D umask(S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH); + } if (bind(listen_sock, (struct sockaddr *)&un, addr_len) =3D=3D -1) { fuse_log(FUSE_LOG_ERR, "vhost socket bind: %m\n"); close(listen_sock); umask(old_umask); return -1; } + if (se->vu_socket_group) { + struct group *g =3D getgrnam(se->vu_socket_group); + if (g) { + if (!chown(se->vu_socket_path, -1, g->gr_gid)) { + fuse_log(FUSE_LOG_WARNING, + "vhost socket failed to set group to %s (%d)\n", + se->vu_socket_group, g->gr_gid); + } + } + } umask(old_umask); =20 if (listen(listen_sock, 1) =3D=3D -1) { --=20 2.28.0 From nobody Thu May 9 14:10:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602503353; cv=none; d=zohomail.com; s=zohoarc; b=jKR+fGF4A6X9hnWZR6cX9FbO6pFUYAfc3VGHYM5NokeMUYXJqj6GyHn1bx2Vze6VHj210EEsKaSN9DZ3YG2eoPL969R4DXGejP9j1COphq5nyLR7ejILNUWolBx6JcjdgDYG8Byt89JRlBDEZAf610cfBcxrd3K9UD0cdfxPCcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602503353; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BJR6SWX9PO2YeU8RnGbYoAO1TtPIctVvTm8T9SR/Fy4=; b=CFJUKcHNbM7I+beye3FHWuNPThTgLkkya7CvjLwKzIXPWPS/Tpvzz8nlOsjw8cQHzG9/02XobB0meSi6d56zwg6eYVVkAMkjnbEiuStdO6t4uf1x3j1uwwft/tp2B19rpSEs68q4BdaIz/k5XlE2oMs1LzRqbvmR0PJOThgjY0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602503353841121.77323547819628; Mon, 12 Oct 2020 04:49:13 -0700 (PDT) Received: from localhost ([::1]:45822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRwKG-0004xO-KG for importer@patchew.org; Mon, 12 Oct 2020 07:49:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRwG4-0000bD-PA for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26369) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRwFy-0008Ac-12 for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-kWV_VpIGOyO8y9q6sPc2FA-1; Mon, 12 Oct 2020 07:44:42 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E735564088; Mon, 12 Oct 2020 11:44:40 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FD5446; Mon, 12 Oct 2020 11:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602503084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BJR6SWX9PO2YeU8RnGbYoAO1TtPIctVvTm8T9SR/Fy4=; b=OXSB1xd06Wa/WvWgoVTOMBb6B0bCYLdO0f8wMjCQ2YOOk/DNXtMwF+JoNY18xezA3hXO5c bWnxb9WLMORYVpm5fMOhCUqEshVEKnUBBeiNiTpMBbmsaLdwaISKn68wkHFZQNFAPktcg6 4yF1cVf0d3oYy635sZYNl0qsqv+Kkt8= X-MC-Unique: kWV_VpIGOyO8y9q6sPc2FA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 3/6] virtiofsd: Call qemu_init_exec_dir Date: Mon, 12 Oct 2020 12:44:22 +0100 Message-Id: <20201012114425.104765-4-dgilbert@redhat.com> In-Reply-To: <20201012114425.104765-1-dgilbert@redhat.com> References: <20201012114425.104765-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 23:52:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: "Dr. David Alan Gilbert" Since fcb4f59c879 qemu_get_local_state_pathname relies on the init_exec_dir, and virtiofsd asserts because we never set it. Set it. Reported-by: Alex Benn=C3=A9e Signed-off-by: Dr. David Alan Gilbert Message-Id: <20201002124015.44820-1-dgilbert@redhat.com> Tested-by: Alex Benn=C3=A9e Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Stefan Hajnoczi Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 36ad46e0c0..477e6ee0b5 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2839,6 +2839,8 @@ int main(int argc, char *argv[]) /* Don't mask creation mode, kernel already did that */ umask(0); =20 + qemu_init_exec_dir(argv[0]); + pthread_mutex_init(&lo.mutex, NULL); lo.inodes =3D g_hash_table_new(lo_key_hash, lo_key_equal); lo.root.fd =3D -1; --=20 2.28.0 From nobody Thu May 9 14:10:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602504221; cv=none; d=zohomail.com; s=zohoarc; b=cpjdLJ2P8woI3KwV97fzzWpGx/7ecI8I7FYk8i6Q2+oWHp/2LpWDxwpv3qjeAEMnCR6OO1LuNz8RLQeiy6+fwGuGt5lRDsxe9HX0C1e3UL+x7TJAb7St/ZQi2LESy5LN+FHjkXPaEYpFUHLzmGG28kmf/kHPqg9OBeL0Q6TCJq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602504221; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xiPfig7jG9VC0GE1wxVAHcnqkY098QwCgL+T1oBSk+E=; b=agiQAUvdqeytVUh68lDsBHeRS2zU8iORvB1MXoNIazk4GL/Av5JNzuVtVxkN1EulUlqpS2jj23b3pN3lAHnABoWiubOcSPCTsIJufpH8hmLmFVmmifSDsTiMaIx9C+f9Dl39yxnfr0QvBSrje3zEN5zBaUS/uhI/UBjFc+7fovU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602504221780718.0730331415017; Mon, 12 Oct 2020 05:03:41 -0700 (PDT) Received: from localhost ([::1]:53704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRwYG-0003kT-2x for importer@patchew.org; Mon, 12 Oct 2020 08:03:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRwG9-0000fR-FZ for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55865) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRwG0-0008Aj-Jz for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-vU5ZkUdvMZGnZJmaLLUBYg-1; Mon, 12 Oct 2020 07:44:43 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B06818A8221; Mon, 12 Oct 2020 11:44:42 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4210519C78; Mon, 12 Oct 2020 11:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602503085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xiPfig7jG9VC0GE1wxVAHcnqkY098QwCgL+T1oBSk+E=; b=dWNZ/s5nzC0De+ynLfUQ2rSXW7KQ87nxr98gNhumgz4ffi9rkMFT6nTAkYuxxJ13qYZw5e baP82LLGu7wjt8c3/dTy/TWHHLXI9gq6nNomrSBf2hNzR4Wns/ow0OSvOLSOIsTFz7tgf4 j6X0rZa3kGjbntBNaH5tHItFyBrxxeM= X-MC-Unique: vU5ZkUdvMZGnZJmaLLUBYg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 4/6] virtiofsd: avoid /proc/self/fd tempdir Date: Mon, 12 Oct 2020 12:44:23 +0100 Message-Id: <20201012114425.104765-5-dgilbert@redhat.com> In-Reply-To: <20201012114425.104765-1-dgilbert@redhat.com> References: <20201012114425.104765-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 23:52:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi In order to prevent /proc/self/fd escapes a temporary directory is created where /proc/self/fd is bind-mounted. This doesn't work on read-only file systems. Avoid the temporary directory by bind-mounting /proc/self/fd over /proc. This does not affect other processes since we remounted / with MS_REC | MS_SLAVE. /proc must exist and virtiofsd does not use it so it's safe to do this. Path traversal can be tested with the following function: static void test_proc_fd_escape(struct lo_data *lo) { int fd; int level =3D 0; ino_t last_ino =3D 0; fd =3D lo->proc_self_fd; for (;;) { struct stat st; if (fstat(fd, &st) !=3D 0) { perror("fstat"); return; } if (last_ino && st.st_ino =3D=3D last_ino) { fprintf(stderr, "inode number unchanged, stopping\n"); return; } last_ino =3D st.st_ino; fprintf(stderr, "Level %d dev %lu ino %lu\n", level, (unsigned long)st.st_dev, (unsigned long)last_ino); fd =3D openat(fd, "..", O_PATH | O_DIRECTORY | O_NOFOLLOW); level++; } } Before and after this patch only Level 0 is displayed. Without /proc/self/fd bind-mount protection it is possible to traverse parent directories. Fixes: 397ae982f4df4 ("virtiofsd: jail lo->proc_self_fd") Cc: Miklos Szeredi Cc: Jens Freimann Signed-off-by: Stefan Hajnoczi Message-Id: <20201006095826.59813-1-stefanha@redhat.com> Reviewed-by: Dr. David Alan Gilbert Tested-by: Jens Freimann Reviewed-by: Jens Freimann Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 34 +++++++++++--------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 477e6ee0b5..ff53df4451 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2393,8 +2393,6 @@ static void setup_wait_parent_capabilities(void) static void setup_namespaces(struct lo_data *lo, struct fuse_session *se) { pid_t child; - char template[] =3D "virtiofsd-XXXXXX"; - char *tmpdir; =20 /* * Create a new pid namespace for *child* processes. We'll have to @@ -2458,33 +2456,23 @@ static void setup_namespaces(struct lo_data *lo, st= ruct fuse_session *se) exit(1); } =20 - tmpdir =3D mkdtemp(template); - if (!tmpdir) { - fuse_log(FUSE_LOG_ERR, "tmpdir(%s): %m\n", template); - exit(1); - } - - if (mount("/proc/self/fd", tmpdir, NULL, MS_BIND, NULL) < 0) { - fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, %s, MS_BIND): %m\n", - tmpdir); + /* + * We only need /proc/self/fd. Prevent ".." from accessing parent + * directories of /proc/self/fd by bind-mounting it over /proc. Since = / was + * previously remounted with MS_REC | MS_SLAVE this mount change only + * affects our process. + */ + if (mount("/proc/self/fd", "/proc", NULL, MS_BIND, NULL) < 0) { + fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, MS_BIND): %m\n"); exit(1); } =20 - /* Now we can get our /proc/self/fd directory file descriptor */ - lo->proc_self_fd =3D open(tmpdir, O_PATH); + /* Get the /proc (actually /proc/self/fd, see above) file descriptor */ + lo->proc_self_fd =3D open("/proc", O_PATH); if (lo->proc_self_fd =3D=3D -1) { - fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", tmpdir); + fuse_log(FUSE_LOG_ERR, "open(/proc, O_PATH): %m\n"); exit(1); } - - if (umount2(tmpdir, MNT_DETACH) < 0) { - fuse_log(FUSE_LOG_ERR, "umount2(%s, MNT_DETACH): %m\n", tmpdir); - exit(1); - } - - if (rmdir(tmpdir) < 0) { - fuse_log(FUSE_LOG_ERR, "rmdir(%s): %m\n", tmpdir); - } } =20 /* --=20 2.28.0 From nobody Thu May 9 14:10:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602503413; cv=none; d=zohomail.com; s=zohoarc; b=fBkWZZx+B/Uo4xyqkVosWnmq4wVB7QelVxp5o+KXno/NVtVbMT/MLQf55oQf4d51Xht98FvcvH2DQPq2uNnPPTj3Q785UNFU7Gl5EFZcda6RcEHzsS9M0LXxPBf8NV32hQGX89g2BuM9YAmU1oBxWusBjFg5Z6zwBIaP97Gb0VM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602503413; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=U0f7a6Fc7A+7mZcGUG5Hm7ANHiCXaOvgGvgfUjI3+ow=; b=HvA2qdqG90hTrHLz41M5D07F7mncJf98b5Vko6bZETa9OQlhRy/sNLb/aY6uB8v+5JK2KZUacZtLY6oy9wzSsY+WkLKGA4DmmjcE++kdcXLWcvOy8neZHISdyla8jZv0yKbxMQNXg8iZLA+zMGCFpuHSe1B6QkxLGmIT4cjLPRw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602503413755702.7685730442506; Mon, 12 Oct 2020 04:50:13 -0700 (PDT) Received: from localhost ([::1]:48922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRwLE-0006F8-IB for importer@patchew.org; Mon, 12 Oct 2020 07:50:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRwG7-0000cz-SV for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRwG2-0008B0-EG for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:55 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-tLfwMwT5NkCzlaumZQHK5Q-1; Mon, 12 Oct 2020 07:44:45 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E8DD64083; Mon, 12 Oct 2020 11:44:44 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id E624319C78; Mon, 12 Oct 2020 11:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602503087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U0f7a6Fc7A+7mZcGUG5Hm7ANHiCXaOvgGvgfUjI3+ow=; b=eYEUahmf0T+BX6KhS1r5DqHlJnnqGYm+gLPrjYAx9szzCiRo09Md0FCp9ZxrQMN+0FuxIR s6Cjb6+4Y9vyNOOPvR/FiHFwht8i5jrf/jNMM71VSHBq6h5i+2bVvQfF3NEpHW7vlI/0Bl uqmqys692ApQiyrMlANrQP6Q8iJPac4= X-MC-Unique: tLfwMwT5NkCzlaumZQHK5Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 5/6] migration/dirtyrate: record start_time and calc_time while at the measuring state Date: Mon, 12 Oct 2020 12:44:24 +0100 Message-Id: <20201012114425.104765-6-dgilbert@redhat.com> In-Reply-To: <20201012114425.104765-1-dgilbert@redhat.com> References: <20201012114425.104765-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/12 02:58:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Chuan Zheng Querying could include both the start-time and the calc-time while at the m= easuring state, allowing a caller to determine when they should expect to come back = looking for a result. Signed-off-by: Chuan Zheng Message-Id: <1601350938-128320-2-git-send-email-zhengchuan@huawei.com> Reviewed-by: David Edmondson Signed-off-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 68577ef250..40e41e793e 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -83,14 +83,14 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) return info; } =20 -static void reset_dirtyrate_stat(void) +static void init_dirtyrate_stat(int64_t start_time, int64_t calc_time) { DirtyStat.total_dirty_samples =3D 0; DirtyStat.total_sample_count =3D 0; DirtyStat.total_block_mem_MB =3D 0; DirtyStat.dirty_rate =3D -1; - DirtyStat.start_time =3D 0; - DirtyStat.calc_time =3D 0; + DirtyStat.start_time =3D start_time; + DirtyStat.calc_time =3D calc_time; } =20 static void update_dirtyrate_stat(struct RamblockDirtyInfo *info) @@ -335,7 +335,6 @@ static void calculate_dirtyrate(struct DirtyRateConfig = config) int64_t initial_time; =20 rcu_register_thread(); - reset_dirtyrate_stat(); rcu_read_lock(); initial_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); if (!record_ramblock_hash_info(&block_dinfo, config, &block_count)) { @@ -365,6 +364,8 @@ void *get_dirtyrate_thread(void *arg) { struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)arg; int ret; + int64_t start_time; + int64_t calc_time; =20 ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTA= RTED, DIRTY_RATE_STATUS_MEASURING); @@ -373,6 +374,10 @@ void *get_dirtyrate_thread(void *arg) return NULL; } =20 + start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; + calc_time =3D config.sample_period_seconds; + init_dirtyrate_stat(start_time, calc_time); + calculate_dirtyrate(config); =20 ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_MEASU= RING, --=20 2.28.0 From nobody Thu May 9 14:10:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602503332; cv=none; d=zohomail.com; s=zohoarc; b=YsvoCa8C+w/xANBX1FUIktYU7I8fLgoOeRXQqIENn5CVGfzyZjf9mGMI8Gl5sc9TgpGKPFKa+ImJltS4eXzhe1T/sspRC+7uMbGmLPlZSPmnACAYHnoDW4CvbOf+4cQIdBFXhCxl9L437VYe0muVgctuiDCWRnqJrTXxRKRWMHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602503332; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=04mH/EQN2FMbm79HfXdBhiaZTkRTdOPvt3HTGNa6fxc=; b=Fr9NJFEpMnmmhwoVbtod33Y9UdG9jxpsIOHe9AvIje7cF2GlLKY2J1hs2C8pUCb7OKFNBuJ+z0IDyYA1RnBWcNDkpGz/LmXLrJkq8UlFCjcfsJk+Z6wVhmLOIqbd73zt2bm3Okj5iCgx9psjRwol4Uc6LZrjci7Qk42U4Tq+RS4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602503332141405.15538649820587; Mon, 12 Oct 2020 04:48:52 -0700 (PDT) Received: from localhost ([::1]:45378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRwJv-0004mO-1m for importer@patchew.org; Mon, 12 Oct 2020 07:48:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRwG8-0000dv-8F for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57035) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRwG3-0008BI-P6 for qemu-devel@nongnu.org; Mon, 12 Oct 2020 07:44:55 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170-2j4df_44OH-hXeQLj3vaQg-1; Mon, 12 Oct 2020 07:44:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01B6A18A8227; Mon, 12 Oct 2020 11:44:46 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9990C19C78; Mon, 12 Oct 2020 11:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602503089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=04mH/EQN2FMbm79HfXdBhiaZTkRTdOPvt3HTGNa6fxc=; b=Kvp7zIbPOvrXELVgA2OQ1jWIODkAZ55mNAbg+rKw80ynhZ5Bmw0oEN3x54tJVJ2FfoEEU1 Qe+mHuJhdLT0yPluywSexmM7DkfZAlUrkBPlXIwtfJj1AJgtTEIldDBi2E9P0jIOeDzQzJ 1HyHezSqn+E8bOHih7Jw911sfP4dLp4= X-MC-Unique: 2j4df_44OH-hXeQLj3vaQg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 6/6] migration/dirtyrate: present dirty rate only when querying the rate has completed Date: Mon, 12 Oct 2020 12:44:25 +0100 Message-Id: <20201012114425.104765-7-dgilbert@redhat.com> In-Reply-To: <20201012114425.104765-1-dgilbert@redhat.com> References: <20201012114425.104765-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/12 02:58:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Chuan Zheng Make dirty_rate field optional, present dirty rate only when querying the rate has completed. The qmp results is shown as follow: @unstarted: {"return":{"status":"unstarted","start-time":0,"calc-time":0},"id":"libvirt= -12"} @measuring: {"return":{"status":"measuring","start-time":102931,"calc-time":1},"id":"li= bvirt-85"} @measured: {"return":{"status":"measured","dirty-rate":4,"start-time":150146,"calc-tim= e":1},"id":"libvirt-15"} Signed-off-by: Chuan Zheng Reviewed-by: David Edmondson Message-Id: <1601350938-128320-3-git-send-email-zhengchuan@huawei.com> Signed-off-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 3 +-- qapi/migration.json | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 40e41e793e..ab9e1301f6 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -69,9 +69,8 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) struct DirtyRateInfo *info =3D g_malloc0(sizeof(DirtyRateInfo)); =20 if (qatomic_read(&CalculatingState) =3D=3D DIRTY_RATE_STATUS_MEASURED)= { + info->has_dirty_rate =3D true; info->dirty_rate =3D dirty_rate; - } else { - info->dirty_rate =3D -1; } =20 info->status =3D CalculatingState; diff --git a/qapi/migration.json b/qapi/migration.json index 7f5e6fd681..974021a5c8 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1743,10 +1743,8 @@ # # Information about current dirty page rate of vm. # -# @dirty-rate: @dirtyrate describing the dirty page rate of vm -# in units of MB/s. -# If this field returns '-1', it means querying has not -# yet started or completed. +# @dirty-rate: an estimate of the dirty page rate of the VM in units of +# MB/s, present only when estimating the rate has completed. # # @status: status containing dirtyrate query status includes # 'unstarted' or 'measuring' or 'measured' @@ -1759,7 +1757,7 @@ # ## { 'struct': 'DirtyRateInfo', - 'data': {'dirty-rate': 'int64', + 'data': {'*dirty-rate': 'int64', 'status': 'DirtyRateStatus', 'start-time': 'int64', 'calc-time': 'int64'} } --=20 2.28.0