From nobody Thu Apr 18 08:31:00 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=1666807145; cv=none; d=zohomail.com; s=zohoarc; b=Wp5C49a+pEpq8NIEXA1PlUl3nxPqXMmMOk7Ti30VO2Q0AwNO9wd2L8nfnjnHOVN8t/oWzRD3B76IVRutrOxF+rWOCMVl12IUNl8NxWv3e1bprisnHI85FYwNVKc+nTSaG8fGu2FbqtAp9RTFNmzcMUomInBto6qd1WY9MNqXujY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807145; h=Content-Type:Content-Transfer-Encoding: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=2iUMF2Ut8nhKI3m5KrXUaUz+X7rgCqvtIoWEFoFpmAg=; b=cPPnoBgvkksfWKMMxFepV0R8V4SlRudydgT/cITaBN0ASfjMbp1wtAija8OFsbWqspgClmqy9QEv8cSZID/Jog0MqZ35bU9aXYXYj9/bUzn86HMq8+pd9PJQc1jZ2LOxdLhkSIyjCWUwPj6H6+r8ptxC8PRUTt28aMmxZfH2SvU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666807145069555.0112027706832; Wed, 26 Oct 2022 10:59:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkcw-0008WH-18; Wed, 26 Oct 2022 13:55:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkct-0008Rh-To for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkco-0005eU-QC for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-s6Vs0pC6MMKeam-F81ZSBQ-1; Wed, 26 Oct 2022 13:55:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4955857AAA; Wed, 26 Oct 2022 17:55:32 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00AF62166B41; Wed, 26 Oct 2022 17:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2iUMF2Ut8nhKI3m5KrXUaUz+X7rgCqvtIoWEFoFpmAg=; b=WgXNzEYLSSAls8mTveBJO9JGC6+rBEN7azjKKVbNAe8vB9oZTVBQebvwyWs3nEnzqHdIiH NU9Fsy+qocmWyvqtGRWLimU52NjPjimlGaFYNbabZ22jIFcnrbYiPzG9Mdt8Q/BHDe0ogs ky2E20Q4aeMcYPnS/NntCptvf3q+GnY= X-MC-Unique: s6Vs0pC6MMKeam-F81ZSBQ-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 1/8] qga: Add initial FreeBSD support Date: Wed, 26 Oct 2022 20:55:11 +0300 Message-Id: <20221026175518.2636846-2-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807145830100001 From: Alexander Ivanov - Fix device path. - Fix virtio-serial channel initialization. - Make the code buildable in FreeBSD. Reviewed-by: Konstantin Kostiuk Acked-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- meson.build | 2 +- qga/channel-posix.c | 19 +++++++++++++++++++ qga/commands-posix.c | 8 ++++++++ qga/main.c | 6 +++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index b686dfef75..71fe72ea06 100644 --- a/meson.build +++ b/meson.build @@ -75,7 +75,7 @@ have_tools =3D get_option('tools') \ .allowed() have_ga =3D get_option('guest_agent') \ .disable_auto_if(not have_system and not have_tools) \ - .require(targetos in ['sunos', 'linux', 'windows'], + .require(targetos in ['sunos', 'linux', 'windows', 'freebsd'], error_message: 'unsupported OS for QEMU guest agent') \ .allowed() have_block =3D have_system or have_tools diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 6796a02cff..568350ded4 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -149,6 +149,25 @@ static gboolean ga_channel_open(GAChannel *c, const gc= har *path, return false; } #endif +#ifdef __FreeBSD__ + /* + * In the default state channel sends echo of every command to a + * client. The client programm doesn't expect this and raises an + * error. Suppress echo by resetting ECHO terminal flag. + */ + struct termios tio; + if (tcgetattr(fd, &tio) < 0) { + error_setg_errno(errp, errno, "error getting channel termios a= ttrs"); + close(fd); + return false; + } + tio.c_lflag &=3D ~ECHO; + if (tcsetattr(fd, TCSAFLUSH, &tio) < 0) { + error_setg_errno(errp, errno, "error setting channel termios a= ttrs"); + close(fd); + return false; + } +#endif /* __FreeBSD__ */ ret =3D ga_channel_client_add(c, fd); if (ret) { error_setg(errp, "error adding channel to main loop"); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index eea819cff0..16d67e9f6d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -51,6 +51,14 @@ #endif #endif =20 +#ifdef __FreeBSD__ +/* + * The code under HAVE_GETIFADDRS condition can't be compiled in FreeBSD. + * Fix it in one of the following patches. + */ +#undef HAVE_GETIFADDRS +#endif + #ifdef HAVE_GETIFADDRS #include #include diff --git a/qga/main.c b/qga/main.c index 5a9d8252e0..0d27c97d38 100644 --- a/qga/main.c +++ b/qga/main.c @@ -45,9 +45,13 @@ #endif =20 #ifndef _WIN32 +#ifdef __FreeBSD__ +#define QGA_VIRTIO_PATH_DEFAULT "/dev/vtcon/org.qemu.guest_agent.0" +#else /* __FreeBSD__ */ #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" -#define QGA_STATE_RELATIVE_DIR "run" +#endif /* __FreeBSD__ */ #define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0" +#define QGA_STATE_RELATIVE_DIR "run" #else #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0" #define QGA_STATE_RELATIVE_DIR "qemu-ga" --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807116; cv=none; d=zohomail.com; s=zohoarc; b=M8Wb3tyQ3ysziIjT0Y/uf8VmoThrWjizHDHWD7pWHrxCDuyTZRuyyLbwatRKYRjV85yePEJ/KTAKiHoAbSX7IlncH689WNzJAKd1Zrz/2E2YRjKz0ZPx0nNUAnPHiJTZF1fQBbfu2Azyc1XgNEwgtHpy1DZgf/gS1wAC/tVg4RA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807116; h=Content-Type:Content-Transfer-Encoding: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=mnv0neNcobe/ntnl4axxcr5ar9MYcckbikluPly7YVg=; b=AyuAzHsv6Ypcw8daZqZDtK2tqhRDhOgWXF75enQykesD+bQat0wMZCHbyqOWM2pWypNwSkdlf9/YD/PjpJBq+9wQE3kViHzXSNdNuCmSnxSiVCD3mqbfH71rca+cDe3Vxx0geiI/hytUDmLOjcE6t9KYPkDgIvAg9LpWvet4m88= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666807116374796.6141456392561; Wed, 26 Oct 2022 10:58:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkct-0008QC-Oh; Wed, 26 Oct 2022 13:55:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcq-00086b-7L for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcn-0005e4-A0 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:35 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-168-W7seIXaJM4CFE39OZI7W1g-1; Wed, 26 Oct 2022 13:55:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0BF5D8828C9; Wed, 26 Oct 2022 17:55:30 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CC792166B4C; Wed, 26 Oct 2022 17:55:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mnv0neNcobe/ntnl4axxcr5ar9MYcckbikluPly7YVg=; b=GwanLVBMch3vA5Z5xjw1OWINHtKagKXtEOoRKh82BPy2qMZ+FKzyd25gTWmGZm3Jo89qY0 ENX4GrwgoszlRwJsY9GXPKwUcQx8NaO9WqPbbaonLxzo9vWvMeHNKpOni0jJZAUEhbzqU9 iqkSEnFk5XbfS873ZERvlFIIjgoS3g8= X-MC-Unique: W7seIXaJM4CFE39OZI7W1g-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 2/8] qga: Move Linux-specific FS freeze/thaw code to a separate file Date: Wed, 26 Oct 2022 20:55:12 +0300 Message-Id: <20221026175518.2636846-3-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807117767100001 From: Alexander Ivanov In the next patches we are going to add FreeBSD support for QEMU Guest Agent. In the result, code in commands-posix.c will be too cumbersome. Move Linux-specific FS freeze/thaw code to a separate file commands-linux.c keeping common POSIX code in commands-posix.c. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- qga/commands-common.h | 34 +++++ qga/commands-linux.c | 286 +++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 287 +++--------------------------------------- qga/meson.build | 3 + 4 files changed, 338 insertions(+), 272 deletions(-) create mode 100644 qga/commands-linux.c diff --git a/qga/commands-common.h b/qga/commands-common.h index d0e4a9696f..cb51b1c6e9 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -10,6 +10,40 @@ #define QGA_COMMANDS_COMMON_H =20 #include "qga-qapi-types.h" +#include "guest-agent-core.h" +#include "qemu/queue.h" + +#if defined(__linux__) +#include +#ifdef FIFREEZE +#define CONFIG_FSFREEZE +#endif +#ifdef FITRIM +#define CONFIG_FSTRIM +#endif +#endif /* __linux__ */ + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +typedef struct FsMount { + char *dirname; + char *devtype; + unsigned int devmajor, devminor; + QTAILQ_ENTRY(FsMount) next; +} FsMount; + +typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList; + +bool build_fs_mount_list(FsMountList *mounts, Error **errp); +void free_fs_mount_list(FsMountList *mounts); +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#if defined(CONFIG_FSFREEZE) +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp); +int qmp_guest_fsfreeze_do_thaw(Error **errp); +#endif /* CONFIG_FSFREEZE */ =20 typedef struct GuestFileHandle GuestFileHandle; =20 diff --git a/qga/commands-linux.c b/qga/commands-linux.c new file mode 100644 index 0000000000..214e408fcd --- /dev/null +++ b/qga/commands-linux.c @@ -0,0 +1,286 @@ +/* + * QEMU Guest Agent Linux-specific command implementations + * + * Copyright IBM Corp. 2011 + * + * Authors: + * Michael Roth + * Michal Privoznik + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "commands-common.h" +#include "cutils.h" +#include +#include + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +static int dev_major_minor(const char *devpath, + unsigned int *devmajor, unsigned int *devminor) +{ + struct stat st; + + *devmajor =3D 0; + *devminor =3D 0; + + if (stat(devpath, &st) < 0) { + slog("failed to stat device file '%s': %s", devpath, strerror(errn= o)); + return -1; + } + if (S_ISDIR(st.st_mode)) { + /* It is bind mount */ + return -2; + } + if (S_ISBLK(st.st_mode)) { + *devmajor =3D major(st.st_rdev); + *devminor =3D minor(st.st_rdev); + return 0; + } + return -1; +} + +static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **err= p) +{ + struct mntent *ment; + FsMount *mount; + char const *mtab =3D "/proc/self/mounts"; + FILE *fp; + unsigned int devmajor, devminor; + + fp =3D setmntent(mtab, "r"); + if (!fp) { + error_setg(errp, "failed to open mtab file: '%s'", mtab); + return false; + } + + while ((ment =3D getmntent(fp))) { + /* + * An entry which device name doesn't start with a '/' is + * either a dummy file system or a network file system. + * Add special handling for smbfs and cifs as is done by + * coreutils as well. + */ + if ((ment->mnt_fsname[0] !=3D '/') || + (strcmp(ment->mnt_type, "smbfs") =3D=3D 0) || + (strcmp(ment->mnt_type, "cifs") =3D=3D 0)) { + continue; + } + if (dev_major_minor(ment->mnt_fsname, &devmajor, &devminor) =3D=3D= -2) { + /* Skip bind mounts */ + continue; + } + + mount =3D g_new0(FsMount, 1); + mount->dirname =3D g_strdup(ment->mnt_dir); + mount->devtype =3D g_strdup(ment->mnt_type); + mount->devmajor =3D devmajor; + mount->devminor =3D devminor; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + + endmntent(fp); + return true; +} + +static void decode_mntname(char *name, int len) +{ + int i, j =3D 0; + for (i =3D 0; i <=3D len; i++) { + if (name[i] !=3D '\\') { + name[j++] =3D name[i]; + } else if (name[i + 1] =3D=3D '\\') { + name[j++] =3D '\\'; + i++; + } else if (name[i + 1] >=3D '0' && name[i + 1] <=3D '3' && + name[i + 2] >=3D '0' && name[i + 2] <=3D '7' && + name[i + 3] >=3D '0' && name[i + 3] <=3D '7') { + name[j++] =3D (name[i + 1] - '0') * 64 + + (name[i + 2] - '0') * 8 + + (name[i + 3] - '0'); + i +=3D 3; + } else { + name[j++] =3D name[i]; + } + } +} + +/* + * Walk the mount table and build a list of local file systems + */ +bool build_fs_mount_list(FsMountList *mounts, Error **errp) +{ + FsMount *mount; + char const *mountinfo =3D "/proc/self/mountinfo"; + FILE *fp; + char *line =3D NULL, *dash; + size_t n; + char check; + unsigned int devmajor, devminor; + int ret, dir_s, dir_e, type_s, type_e, dev_s, dev_e; + + fp =3D fopen(mountinfo, "r"); + if (!fp) { + return build_fs_mount_list_from_mtab(mounts, errp); + } + + while (getline(&line, &n, fp) !=3D -1) { + ret =3D sscanf(line, "%*u %*u %u:%u %*s %n%*s%n%c", + &devmajor, &devminor, &dir_s, &dir_e, &check); + if (ret < 3) { + continue; + } + dash =3D strstr(line + dir_e, " - "); + if (!dash) { + continue; + } + ret =3D sscanf(dash, " - %n%*s%n %n%*s%n%c", + &type_s, &type_e, &dev_s, &dev_e, &check); + if (ret < 1) { + continue; + } + line[dir_e] =3D 0; + dash[type_e] =3D 0; + dash[dev_e] =3D 0; + decode_mntname(line + dir_s, dir_e - dir_s); + decode_mntname(dash + dev_s, dev_e - dev_s); + if (devmajor =3D=3D 0) { + /* btrfs reports major number =3D 0 */ + if (strcmp("btrfs", dash + type_s) !=3D 0 || + dev_major_minor(dash + dev_s, &devmajor, &devminor) < 0) { + continue; + } + } + + mount =3D g_new0(FsMount, 1); + mount->dirname =3D g_strdup(line + dir_s); + mount->devtype =3D g_strdup(dash + type_s); + mount->devmajor =3D devmajor; + mount->devminor =3D devminor; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + free(line); + + fclose(fp); + return true; +} +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#ifdef CONFIG_FSFREEZE +/* + * Walk list of mounted file systems in the guest, and freeze the ones whi= ch + * are real local file systems. + */ +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp) +{ + struct FsMount *mount; + strList *list; + int fd, ret, i =3D 0; + + QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { + /* To issue fsfreeze in the reverse order of mounts, check if the + * mount is listed in the list here */ + if (has_mountpoints) { + for (list =3D mountpoints; list; list =3D list->next) { + if (strcmp(list->value, mount->dirname) =3D=3D 0) { + break; + } + } + if (!list) { + continue; + } + } + + fd =3D qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd =3D=3D -1) { + error_setg_errno(errp, errno, "failed to open %s", mount->dirn= ame); + return -1; + } + + /* we try to cull filesystems we know won't work in advance, but o= ther + * filesystems may not implement fsfreeze for less obvious reasons. + * these will report EOPNOTSUPP. we simply ignore these when tally= ing + * the number of frozen filesystems. + * if a filesystem is mounted more than once (aka bind mount) a + * consecutive attempt to freeze an already frozen filesystem will + * return EBUSY. + * + * any other error means a failure to freeze a filesystem we + * expect to be freezable, so return an error in those cases + * and return system to thawed state. + */ + ret =3D ioctl(fd, FIFREEZE); + if (ret =3D=3D -1) { + if (errno !=3D EOPNOTSUPP && errno !=3D EBUSY) { + error_setg_errno(errp, errno, "failed to freeze %s", + mount->dirname); + close(fd); + return -1; + } + } else { + i++; + } + close(fd); + } + return i; +} + +int qmp_guest_fsfreeze_do_thaw(Error **errp) +{ + int ret; + FsMountList mounts; + FsMount *mount; + int fd, i =3D 0, logged; + Error *local_err =3D NULL; + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return -1; + } + + QTAILQ_FOREACH(mount, &mounts, next) { + logged =3D false; + fd =3D qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd =3D=3D -1) { + continue; + } + /* we have no way of knowing whether a filesystem was actually unf= rozen + * as a result of a successful call to FITHAW, only that if an err= or + * was returned the filesystem was *not* unfrozen by that particul= ar + * call. + * + * since multiple preceding FIFREEZEs require multiple calls to FI= THAW + * to unfreeze, continuing issuing FITHAW until an error is return= ed, + * in which case either the filesystem is in an unfreezable state,= or, + * more likely, it was thawed previously (and remains so afterward= ). + * + * also, since the most recent successful call is the one that did + * the actual unfreeze, we can use this to provide an accurate cou= nt + * of the number of filesystems unfrozen by guest-fsfreeze-thaw, w= hich + * may * be useful for determining whether a filesystem was unfroz= en + * during the freeze/thaw phase by a process other than qemu-ga. + */ + do { + ret =3D ioctl(fd, FITHAW); + if (ret =3D=3D 0 && !logged) { + i++; + logged =3D true; + } + } while (ret =3D=3D 0); + close(fd); + } + + free_fs_mount_list(&mounts); + + return i; +} +#endif /* CONFIG_FSFREEZE */ diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 16d67e9f6d..d24f2fafd8 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -16,11 +16,9 @@ #include #include #include -#include "guest-agent-core.h" #include "qga-qapi-commands.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" -#include "qemu/queue.h" #include "qemu/host-utils.h" #include "qemu/sockets.h" #include "qemu/base64.h" @@ -629,16 +627,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp) #if defined(__linux__) =20 #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) -typedef struct FsMount { - char *dirname; - char *devtype; - unsigned int devmajor, devminor; - QTAILQ_ENTRY(FsMount) next; -} FsMount; - -typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList; - -static void free_fs_mount_list(FsMountList *mounts) +void free_fs_mount_list(FsMountList *mounts) { FsMount *mount, *temp; =20 @@ -653,157 +642,6 @@ static void free_fs_mount_list(FsMountList *mounts) g_free(mount); } } - -static int dev_major_minor(const char *devpath, - unsigned int *devmajor, unsigned int *devminor) -{ - struct stat st; - - *devmajor =3D 0; - *devminor =3D 0; - - if (stat(devpath, &st) < 0) { - slog("failed to stat device file '%s': %s", devpath, strerror(errn= o)); - return -1; - } - if (S_ISDIR(st.st_mode)) { - /* It is bind mount */ - return -2; - } - if (S_ISBLK(st.st_mode)) { - *devmajor =3D major(st.st_rdev); - *devminor =3D minor(st.st_rdev); - return 0; - } - return -1; -} - -/* - * Walk the mount table and build a list of local file systems - */ -static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **err= p) -{ - struct mntent *ment; - FsMount *mount; - char const *mtab =3D "/proc/self/mounts"; - FILE *fp; - unsigned int devmajor, devminor; - - fp =3D setmntent(mtab, "r"); - if (!fp) { - error_setg(errp, "failed to open mtab file: '%s'", mtab); - return false; - } - - while ((ment =3D getmntent(fp))) { - /* - * An entry which device name doesn't start with a '/' is - * either a dummy file system or a network file system. - * Add special handling for smbfs and cifs as is done by - * coreutils as well. - */ - if ((ment->mnt_fsname[0] !=3D '/') || - (strcmp(ment->mnt_type, "smbfs") =3D=3D 0) || - (strcmp(ment->mnt_type, "cifs") =3D=3D 0)) { - continue; - } - if (dev_major_minor(ment->mnt_fsname, &devmajor, &devminor) =3D=3D= -2) { - /* Skip bind mounts */ - continue; - } - - mount =3D g_new0(FsMount, 1); - mount->dirname =3D g_strdup(ment->mnt_dir); - mount->devtype =3D g_strdup(ment->mnt_type); - mount->devmajor =3D devmajor; - mount->devminor =3D devminor; - - QTAILQ_INSERT_TAIL(mounts, mount, next); - } - - endmntent(fp); - return true; -} - -static void decode_mntname(char *name, int len) -{ - int i, j =3D 0; - for (i =3D 0; i <=3D len; i++) { - if (name[i] !=3D '\\') { - name[j++] =3D name[i]; - } else if (name[i + 1] =3D=3D '\\') { - name[j++] =3D '\\'; - i++; - } else if (name[i + 1] >=3D '0' && name[i + 1] <=3D '3' && - name[i + 2] >=3D '0' && name[i + 2] <=3D '7' && - name[i + 3] >=3D '0' && name[i + 3] <=3D '7') { - name[j++] =3D (name[i + 1] - '0') * 64 + - (name[i + 2] - '0') * 8 + - (name[i + 3] - '0'); - i +=3D 3; - } else { - name[j++] =3D name[i]; - } - } -} - -static bool build_fs_mount_list(FsMountList *mounts, Error **errp) -{ - FsMount *mount; - char const *mountinfo =3D "/proc/self/mountinfo"; - FILE *fp; - char *line =3D NULL, *dash; - size_t n; - char check; - unsigned int devmajor, devminor; - int ret, dir_s, dir_e, type_s, type_e, dev_s, dev_e; - - fp =3D fopen(mountinfo, "r"); - if (!fp) { - return build_fs_mount_list_from_mtab(mounts, errp); - } - - while (getline(&line, &n, fp) !=3D -1) { - ret =3D sscanf(line, "%*u %*u %u:%u %*s %n%*s%n%c", - &devmajor, &devminor, &dir_s, &dir_e, &check); - if (ret < 3) { - continue; - } - dash =3D strstr(line + dir_e, " - "); - if (!dash) { - continue; - } - ret =3D sscanf(dash, " - %n%*s%n %n%*s%n%c", - &type_s, &type_e, &dev_s, &dev_e, &check); - if (ret < 1) { - continue; - } - line[dir_e] =3D 0; - dash[type_e] =3D 0; - dash[dev_e] =3D 0; - decode_mntname(line + dir_s, dir_e - dir_s); - decode_mntname(dash + dev_s, dev_e - dev_s); - if (devmajor =3D=3D 0) { - /* btrfs reports major number =3D 0 */ - if (strcmp("btrfs", dash + type_s) !=3D 0 || - dev_major_minor(dash + dev_s, &devmajor, &devminor) < 0) { - continue; - } - } - - mount =3D g_new0(FsMount, 1); - mount->dirname =3D g_strdup(line + dir_s); - mount->devtype =3D g_strdup(dash + type_s); - mount->devmajor =3D devmajor; - mount->devminor =3D devminor; - - QTAILQ_INSERT_TAIL(mounts, mount, next); - } - free(line); - - fclose(fp); - return true; -} #endif =20 #if defined(CONFIG_FSFREEZE) @@ -1708,20 +1546,13 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); } =20 -/* - * Walk list of mounted file systems in the guest, and freeze the ones whi= ch - * are real local file systems. - */ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, Error **errp) { - int ret =3D 0, i =3D 0; - strList *list; + int ret; FsMountList mounts; - struct FsMount *mount; Error *local_err =3D NULL; - int fd; =20 slog("guest-fsfreeze called"); =20 @@ -1740,122 +1571,34 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mo= untpoints, /* cannot risk guest agent blocking itself on a write in this state */ ga_set_frozen(ga_state); =20 - QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { - /* To issue fsfreeze in the reverse order of mounts, check if the - * mount is listed in the list here */ - if (has_mountpoints) { - for (list =3D mountpoints; list; list =3D list->next) { - if (strcmp(list->value, mount->dirname) =3D=3D 0) { - break; - } - } - if (!list) { - continue; - } - } - - fd =3D qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "failed to open %s", mount->dirn= ame); - goto error; - } - - /* we try to cull filesystems we know won't work in advance, but o= ther - * filesystems may not implement fsfreeze for less obvious reasons. - * these will report EOPNOTSUPP. we simply ignore these when tally= ing - * the number of frozen filesystems. - * if a filesystem is mounted more than once (aka bind mount) a - * consecutive attempt to freeze an already frozen filesystem will - * return EBUSY. - * - * any other error means a failure to freeze a filesystem we - * expect to be freezable, so return an error in those cases - * and return system to thawed state. - */ - ret =3D ioctl(fd, FIFREEZE); - if (ret =3D=3D -1) { - if (errno !=3D EOPNOTSUPP && errno !=3D EBUSY) { - error_setg_errno(errp, errno, "failed to freeze %s", - mount->dirname); - close(fd); - goto error; - } - } else { - i++; - } - close(fd); - } + ret =3D qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, + mounts, errp); =20 free_fs_mount_list(&mounts); /* We may not issue any FIFREEZE here. * Just unset ga_state here and ready for the next call. */ - if (i =3D=3D 0) { + if (ret =3D=3D 0) { ga_unset_frozen(ga_state); + } else if (ret < 0) { + qmp_guest_fsfreeze_thaw(NULL); } - return i; - -error: - free_fs_mount_list(&mounts); - qmp_guest_fsfreeze_thaw(NULL); - return 0; + return ret; } =20 -/* - * Walk list of frozen file systems in the guest, and thaw them. - */ int64_t qmp_guest_fsfreeze_thaw(Error **errp) { int ret; - FsMountList mounts; - FsMount *mount; - int fd, i =3D 0, logged; - Error *local_err =3D NULL; =20 - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return 0; - } - - QTAILQ_FOREACH(mount, &mounts, next) { - logged =3D false; - fd =3D qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd =3D=3D -1) { - continue; - } - /* we have no way of knowing whether a filesystem was actually unf= rozen - * as a result of a successful call to FITHAW, only that if an err= or - * was returned the filesystem was *not* unfrozen by that particul= ar - * call. - * - * since multiple preceding FIFREEZEs require multiple calls to FI= THAW - * to unfreeze, continuing issuing FITHAW until an error is return= ed, - * in which case either the filesystem is in an unfreezable state,= or, - * more likely, it was thawed previously (and remains so afterward= ). - * - * also, since the most recent successful call is the one that did - * the actual unfreeze, we can use this to provide an accurate cou= nt - * of the number of filesystems unfrozen by guest-fsfreeze-thaw, w= hich - * may * be useful for determining whether a filesystem was unfroz= en - * during the freeze/thaw phase by a process other than qemu-ga. - */ - do { - ret =3D ioctl(fd, FITHAW); - if (ret =3D=3D 0 && !logged) { - i++; - logged =3D true; - } - } while (ret =3D=3D 0); - close(fd); + ret =3D qmp_guest_fsfreeze_do_thaw(errp); + if (ret >=3D 0) { + ga_unset_frozen(ga_state); + execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); + } else { + ret =3D 0; } =20 - ga_unset_frozen(ga_state); - free_fs_mount_list(&mounts); - - execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); - - return i; + return ret; } =20 static void guest_fsfreeze_cleanup(void) diff --git a/qga/meson.build b/qga/meson.build index a0ffd6d268..932b4e7ca8 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -72,6 +72,9 @@ qga_ss.add(when: 'CONFIG_POSIX', if_true: files( 'commands-posix.c', 'commands-posix-ssh.c', )) +qga_ss.add(when: 'CONFIG_LINUX', if_true: files( + 'commands-linux.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807291; cv=none; d=zohomail.com; s=zohoarc; b=WPP4PH+rAoUtOgzvUsC7VazUXUCljegdinF4WhHkNBghhH4ZjtDxWg4HeYug5HxYolrwtRAEkDnY3uPA+HMT4v4/TX8UuldtlmzsJIw5Gfrp+alK03R9ZoF9t7WsMmwdtHJFAP8l7nouHGXX3dKZiUAnGpbYKZ1+5KOpyQN5gRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807291; h=Content-Type:Content-Transfer-Encoding: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=OymUfhOXLF9xfFCS1tHul9cBOUru080vQqs3cL3tkFU=; b=aEoVJzQkq774yv8tt/HgcTq2zwB7duipqI2us1uzF1eOtc6k3NqMTMjwqe5vvDcix/ZvIwPqE2YKVqCvFXqPVgxy6Xnhdg2rDPVY7Lt6RymgRRFNYPJHCfMMM1CgkpepoVRVQMDpDH138MNtU23RZkP5+yYy6OarRk3s3TnVy/Y= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666807291403171.90271330923304; Wed, 26 Oct 2022 11:01:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkcv-0008Vy-CH; Wed, 26 Oct 2022 13:55:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcs-0008IH-7m for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkco-0005eK-Qr for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:37 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-IkXQS7IIOuWswPY2ehufUw-1; Wed, 26 Oct 2022 13:55:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC5703814957; Wed, 26 Oct 2022 17:55:31 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83D3C2166B2B; Wed, 26 Oct 2022 17:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OymUfhOXLF9xfFCS1tHul9cBOUru080vQqs3cL3tkFU=; b=fVmNgQXguLd/WMM3hJAAGz4myMnwN5vJQC4tBI/iEjtJDUWYNdrHpuCP6BGJnyhz+44g3E A6Ab+8VnJ45z6Zpf2HqpQHW8RHZYa1G5uMySFSIsf+VGsQmW0PCU2yY3Fjybv6c9059zil E4qrpvQxCtHDnRXPi7H+b8Sr8G9gSBg= X-MC-Unique: IkXQS7IIOuWswPY2ehufUw-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 3/8] qga: Add UFS freeze/thaw support for FreeBSD Date: Wed, 26 Oct 2022 20:55:13 +0300 Message-Id: <20221026175518.2636846-4-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.129.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807292849100003 From: Alexander Ivanov UFS supports FS freezing through ioctl UFSSUSPEND on /dev/ufssuspend. Frozen FS can be thawed by closing /dev/ufssuspend file descriptior. Use getmntinfo to get a list of mounted FS. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- qga/commands-bsd.c | 169 +++++++++++++++++++++++ qga/commands-common.h | 11 ++ qga/commands-posix.c | 308 ++++++++++++++++++++---------------------- qga/main.c | 7 +- qga/meson.build | 3 + 5 files changed, 334 insertions(+), 164 deletions(-) create mode 100644 qga/commands-bsd.c diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c new file mode 100644 index 0000000000..ca06692179 --- /dev/null +++ b/qga/commands-bsd.c @@ -0,0 +1,169 @@ +/* + * QEMU Guest Agent BSD-specific command implementations + * + * Copyright (c) Virtuozzo International GmbH. + * + * Authors: + * Alexander Ivanov + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qga-qapi-commands.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "qemu/queue.h" +#include "commands-common.h" +#include +#include +#include +#include +#include + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +bool build_fs_mount_list(FsMountList *mounts, Error **errp) +{ + FsMount *mount; + struct statfs *mntbuf, *mntp; + struct stat statbuf; + int i, count, ret; + + count =3D getmntinfo(&mntbuf, MNT_NOWAIT); + if (count =3D=3D 0) { + error_setg_errno(errp, errno, "getmntinfo failed"); + return false; + } + + for (i =3D 0; i < count; i++) { + mntp =3D &mntbuf[i]; + ret =3D stat(mntp->f_mntonname, &statbuf); + if (ret !=3D 0) { + error_setg_errno(errp, errno, "stat failed on %s", + mntp->f_mntonname); + return false; + } + + mount =3D g_new0(FsMount, 1); + + mount->dirname =3D g_strdup(mntp->f_mntonname); + mount->devtype =3D g_strdup(mntp->f_fstypename); + mount->devmajor =3D major(mount->dev); + mount->devminor =3D minor(mount->dev); + mount->fsid =3D mntp->f_fsid; + mount->dev =3D statbuf.st_dev; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + return true; +} +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#if defined(CONFIG_FSFREEZE) +static int ufssuspend_fd =3D -1; +static int ufssuspend_cnt; + +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp) +{ + int ret; + strList *list; + struct FsMount *mount; + + if (ufssuspend_fd !=3D -1) { + error_setg(errp, "filesystems have already frozen"); + return -1; + } + + ufssuspend_cnt =3D 0; + ufssuspend_fd =3D qemu_open(_PATH_UFSSUSPEND, O_RDWR, errp); + if (ufssuspend_fd =3D=3D -1) { + return -1; + } + + QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { + /* + * To issue fsfreeze in the reverse order of mounts, check if the + * mount is listed in the list here + */ + if (has_mountpoints) { + for (list =3D mountpoints; list; list =3D list->next) { + if (g_str_equal(list->value, mount->dirname)) { + break; + } + } + if (!list) { + continue; + } + } + + /* Only UFS supports suspend */ + if (!g_str_equal(mount->devtype, "ufs")) { + continue; + } + + ret =3D ioctl(ufssuspend_fd, UFSSUSPEND, &mount->fsid); + if (ret =3D=3D -1) { + /* + * ioctl returns EBUSY for all the FS except the first one + * that was suspended + */ + if (errno =3D=3D EBUSY) { + continue; + } + error_setg_errno(errp, errno, "failed to freeze %s", + mount->dirname); + goto error; + } + ufssuspend_cnt++; + } + return ufssuspend_cnt; +error: + close(ufssuspend_fd); + ufssuspend_fd =3D -1; + return -1; + +} + +/* + * We don't need to call UFSRESUME ioctl because all the frozen FS + * are thawed on /dev/ufssuspend closing. + */ +int qmp_guest_fsfreeze_do_thaw(Error **errp) +{ + int ret =3D ufssuspend_cnt; + ufssuspend_cnt =3D 0; + if (ufssuspend_fd !=3D -1) { + close(ufssuspend_fd); + ufssuspend_fd =3D -1; + } + return ret; +} + +GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} +#endif /* CONFIG_FSFREEZE */ diff --git a/qga/commands-common.h b/qga/commands-common.h index cb51b1c6e9..d0583c6ddb 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -23,11 +23,22 @@ #endif #endif /* __linux__ */ =20 +#ifdef __FreeBSD__ +#include +#ifdef UFSSUSPEND +#define CONFIG_FSFREEZE +#endif +#endif /* __FreeBSD__ */ + #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) typedef struct FsMount { char *dirname; char *devtype; unsigned int devmajor, devminor; +#if defined(__FreeBSD__) + dev_t dev; + fsid_t fsid; +#endif QTAILQ_ENTRY(FsMount) next; } FsMount; =20 diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d24f2fafd8..6875ea8888 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -33,20 +33,12 @@ =20 #if defined(__linux__) #include -#include #include #include =20 #ifdef CONFIG_LIBUDEV #include #endif - -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#ifdef FITRIM -#define CONFIG_FSTRIM -#endif #endif =20 #ifdef __FreeBSD__ @@ -623,9 +615,6 @@ void qmp_guest_file_flush(int64_t handle, Error **errp) } } =20 -/* linux-specific implementations. avoid this if at all possible. */ -#if defined(__linux__) - #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) void free_fs_mount_list(FsMountList *mounts) { @@ -644,6 +633,156 @@ void free_fs_mount_list(FsMountList *mounts) } #endif =20 +#if defined(CONFIG_FSFREEZE) +typedef enum { + FSFREEZE_HOOK_THAW =3D 0, + FSFREEZE_HOOK_FREEZE, +} FsfreezeHookArg; + +static const char *fsfreeze_hook_arg_string[] =3D { + "thaw", + "freeze", +}; + +static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) +{ + int status; + pid_t pid; + const char *hook; + const char *arg_str =3D fsfreeze_hook_arg_string[arg]; + Error *local_err =3D NULL; + + hook =3D ga_fsfreeze_hook(ga_state); + if (!hook) { + return; + } + if (access(hook, X_OK) !=3D 0) { + error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", h= ook); + return; + } + + slog("executing fsfreeze hook with arg '%s'", arg_str); + pid =3D fork(); + if (pid =3D=3D 0) { + setsid(); + reopen_fd_to_null(0); + reopen_fd_to_null(1); + reopen_fd_to_null(2); + + execl(hook, hook, arg_str, NULL); + _exit(EXIT_FAILURE); + } else if (pid < 0) { + error_setg_errno(errp, errno, "failed to create child process"); + return; + } + + ga_wait_child(pid, &status, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (!WIFEXITED(status)) { + error_setg(errp, "fsfreeze hook has terminated abnormally"); + return; + } + + status =3D WEXITSTATUS(status); + if (status) { + error_setg(errp, "fsfreeze hook has failed with status %d", status= ); + return; + } +} + +/* + * Return status of freeze/thaw + */ +GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) +{ + if (ga_is_frozen(ga_state)) { + return GUEST_FSFREEZE_STATUS_FROZEN; + } + + return GUEST_FSFREEZE_STATUS_THAWED; +} + +int64_t qmp_guest_fsfreeze_freeze(Error **errp) +{ + return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); +} + +int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, + strList *mountpoints, + Error **errp) +{ + int ret; + FsMountList mounts; + Error *local_err =3D NULL; + + slog("guest-fsfreeze called"); + + execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -1; + } + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return -1; + } + + /* cannot risk guest agent blocking itself on a write in this state */ + ga_set_frozen(ga_state); + + ret =3D qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, + mounts, errp); + + free_fs_mount_list(&mounts); + /* We may not issue any FIFREEZE here. + * Just unset ga_state here and ready for the next call. + */ + if (ret =3D=3D 0) { + ga_unset_frozen(ga_state); + } else if (ret < 0) { + qmp_guest_fsfreeze_thaw(NULL); + } + return ret; +} + +int64_t qmp_guest_fsfreeze_thaw(Error **errp) +{ + int ret; + + ret =3D qmp_guest_fsfreeze_do_thaw(errp); + if (ret >=3D 0) { + ga_unset_frozen(ga_state); + execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); + } else { + ret =3D 0; + } + + return ret; +} + +static void guest_fsfreeze_cleanup(void) +{ + Error *err =3D NULL; + + if (ga_is_frozen(ga_state) =3D=3D GUEST_FSFREEZE_STATUS_FROZEN) { + qmp_guest_fsfreeze_thaw(&err); + if (err) { + slog("failed to clean up frozen filesystems: %s", + error_get_pretty(err)); + error_free(err); + } + } +} +#endif + +/* linux-specific implementations. avoid this if at all possible. */ +#if defined(__linux__) #if defined(CONFIG_FSFREEZE) =20 static char *get_pci_driver(char const *syspath, int pathlen, Error **errp) @@ -1467,153 +1606,6 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error= **errp) free_fs_mount_list(&mounts); return ret; } - - -typedef enum { - FSFREEZE_HOOK_THAW =3D 0, - FSFREEZE_HOOK_FREEZE, -} FsfreezeHookArg; - -static const char *fsfreeze_hook_arg_string[] =3D { - "thaw", - "freeze", -}; - -static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) -{ - int status; - pid_t pid; - const char *hook; - const char *arg_str =3D fsfreeze_hook_arg_string[arg]; - Error *local_err =3D NULL; - - hook =3D ga_fsfreeze_hook(ga_state); - if (!hook) { - return; - } - if (access(hook, X_OK) !=3D 0) { - error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", h= ook); - return; - } - - slog("executing fsfreeze hook with arg '%s'", arg_str); - pid =3D fork(); - if (pid =3D=3D 0) { - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - execl(hook, hook, arg_str, NULL); - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } - - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - if (!WIFEXITED(status)) { - error_setg(errp, "fsfreeze hook has terminated abnormally"); - return; - } - - status =3D WEXITSTATUS(status); - if (status) { - error_setg(errp, "fsfreeze hook has failed with status %d", status= ); - return; - } -} - -/* - * Return status of freeze/thaw - */ -GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) -{ - if (ga_is_frozen(ga_state)) { - return GUEST_FSFREEZE_STATUS_FROZEN; - } - - return GUEST_FSFREEZE_STATUS_THAWED; -} - -int64_t qmp_guest_fsfreeze_freeze(Error **errp) -{ - return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); -} - -int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, - strList *mountpoints, - Error **errp) -{ - int ret; - FsMountList mounts; - Error *local_err =3D NULL; - - slog("guest-fsfreeze called"); - - execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return -1; - } - - /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); - - ret =3D qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, - mounts, errp); - - free_fs_mount_list(&mounts); - /* We may not issue any FIFREEZE here. - * Just unset ga_state here and ready for the next call. - */ - if (ret =3D=3D 0) { - ga_unset_frozen(ga_state); - } else if (ret < 0) { - qmp_guest_fsfreeze_thaw(NULL); - } - return ret; -} - -int64_t qmp_guest_fsfreeze_thaw(Error **errp) -{ - int ret; - - ret =3D qmp_guest_fsfreeze_do_thaw(errp); - if (ret >=3D 0) { - ga_unset_frozen(ga_state); - execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); - } else { - ret =3D 0; - } - - return ret; -} - -static void guest_fsfreeze_cleanup(void) -{ - Error *err =3D NULL; - - if (ga_is_frozen(ga_state) =3D=3D GUEST_FSFREEZE_STATUS_FROZEN) { - qmp_guest_fsfreeze_thaw(&err); - if (err) { - slog("failed to clean up frozen filesystems: %s", - error_get_pretty(err)); - error_free(err); - } - } -} #endif /* CONFIG_FSFREEZE */ =20 #if defined(CONFIG_FSTRIM) diff --git a/qga/main.c b/qga/main.c index 0d27c97d38..b3580508fa 100644 --- a/qga/main.c +++ b/qga/main.c @@ -37,12 +37,7 @@ #include "qga/service-win32.h" #include "qga/vss-win32.h" #endif -#ifdef __linux__ -#include -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#endif +#include "commands-common.h" =20 #ifndef _WIN32 #ifdef __FreeBSD__ diff --git a/qga/meson.build b/qga/meson.build index 932b4e7ca8..3cfb9166e5 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -75,6 +75,9 @@ qga_ss.add(when: 'CONFIG_POSIX', if_true: files( qga_ss.add(when: 'CONFIG_LINUX', if_true: files( 'commands-linux.c', )) +qga_ss.add(when: 'CONFIG_BSD', if_true: files( + 'commands-bsd.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807137; cv=none; d=zohomail.com; s=zohoarc; b=AIcZ6yHVrGzJosHbgIu8jGcBVC+mGWfnUAsnYCd3ZB46OpokbvbtK+Lm/0ZrP57D7H3RRzMpZ7EE5B+pib3MKW7VTBXNRfhq7cE85CYgnZFJKBNGTgn0ifna7Rou3Lvs8ZsvgjytxGT4nZqpDn7w976U2bxNuRJpOcAPyqccuV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807137; h=Content-Type:Content-Transfer-Encoding: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=uzJAzjMNjcDM7GPHxFlvvDuJ8dRcnmI+OdDNr+sXSbA=; b=E29mU9oS5Ixa/zTYHhywXoUh5LGvwcO5iW1wSsGwpx5GQa8AEqnqbbkr1dEApX/2hzgG6es64x5ZjKe/EF9FrkBs09YkkoIl5Ut4HtTS4l8zjfPIdk9K74K18FGKT9RMo/uUnK94zXVAeQdLBiYC/L8CrhwjWR9XX7IFuLtBlME= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666807137476995.2991355406381; Wed, 26 Oct 2022 10:58:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkcu-0008Vc-P6; Wed, 26 Oct 2022 13:55:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcs-0008Ii-A7 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcq-0005ee-OZ for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-prtJywTSM7WFFbmZZwW98g-1; Wed, 26 Oct 2022 13:55:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B8BC1C08993; Wed, 26 Oct 2022 17:55:33 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B8BA2166B2B; Wed, 26 Oct 2022 17:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uzJAzjMNjcDM7GPHxFlvvDuJ8dRcnmI+OdDNr+sXSbA=; b=CXZrgwl0OyBCA4LYKUVPP9CAlWoy8eih/hVmVfEmq2fCR8QRHEoiKqxb+lnCQJb0ICzcfw w+7UZ9BP2XybTPVo9FPZEjd7jmrrjbugFmXdPrQaxHHT6nlrqpYWvbwXtUYSYn5ud5b6Z/ ojEvtly6M1btWF5l2J3HxRrOTS1FUGQ= X-MC-Unique: prtJywTSM7WFFbmZZwW98g-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 4/8] qga: Add shutdown/halt/reboot support for FreeBSD Date: Wed, 26 Oct 2022 20:55:14 +0300 Message-Id: <20221026175518.2636846-5-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807137818100003 From: Alexander Ivanov Add appropriate shutdown command arguments to qmp_guest_shutdown() for FreeBSD. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- qga/commands-posix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 6875ea8888..b0b467ebdb 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -90,6 +90,10 @@ void qmp_guest_shutdown(bool has_mode, const char *mode,= Error **errp) const char *powerdown_flag =3D "-i5"; const char *halt_flag =3D "-i0"; const char *reboot_flag =3D "-i6"; +#elif defined(CONFIG_BSD) + const char *powerdown_flag =3D "-p"; + const char *halt_flag =3D "-h"; + const char *reboot_flag =3D "-r"; #else const char *powerdown_flag =3D "-P"; const char *halt_flag =3D "-H"; @@ -120,6 +124,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode= , Error **errp) #ifdef CONFIG_SOLARIS execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y", "hypervisor initiated shutdown", (char *)NULL); +#elif defined(CONFIG_BSD) + execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char *)NULL); #else execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", "hypervisor initiated shutdown", (char *)NULL); --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807166; cv=none; d=zohomail.com; s=zohoarc; b=CxIqXcK5YyYfmTo12OW6YcbbleiNejtVMv4DN6u9VERH6rrKSds1b09LZZW7z6RfhU5DCPIOLoPDuBgvpbeB9Hb3UTB2YBoMpNNVNctJ0FlPxcF9KjPVY8/fMoVHoTJsxxQXsTNxcE0t1d6Bk2IT8E37kbRYoA7NgvYROAvAL1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807166; h=Content-Type:Content-Transfer-Encoding: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=Ejm/cEzdb3Hv0kLNQBLSKUcI2nJyG5881heACUYA0ts=; b=SSqiTCozVgvVt/SD/R8qY49u6urvw8nqxq3q94OgAy+8K9DTATdr65yw/cTZzXcUaKftqjSPLYrDQSutaQmVFCiDl75eEa16IurP0HRxVcriNrNHsl1p2bkPdfgdavgSV62fgL0b4+KSXxUMeifhv9KxXXPdUrPGuBMtmOGIzws= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16668071661241021.4719747001831; Wed, 26 Oct 2022 10:59:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkcw-00004u-LQ; Wed, 26 Oct 2022 13:55:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcu-0008VN-GS for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcs-0005fO-VP for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-xs4r5TqENDqhzU495Hy1RA-1; Wed, 26 Oct 2022 13:55:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7E69857D15; Wed, 26 Oct 2022 17:55:34 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7A6F2166B39; Wed, 26 Oct 2022 17:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ejm/cEzdb3Hv0kLNQBLSKUcI2nJyG5881heACUYA0ts=; b=ByrqbtZ4cuAXatGhR5r7nsqlqGc02Hgfs4KAdLtF4ZLfmFDrJMFoMwRKqUMRNgvMGReIoA MxoZnTRu0uBzX0T2LNE4pRGD/tZXaDC6/D8J+FrEUDd78yUogzX2zAsrCUGkgR46tS2QSS repXJLpF8TFx9KeASLpEXWoznBYtaJU= X-MC-Unique: xs4r5TqENDqhzU495Hy1RA-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 5/8] qga: Add support for user password setting in FreeBSD Date: Wed, 26 Oct 2022 20:55:15 +0300 Message-Id: <20221026175518.2636846-6-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.129.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807167914100001 From: Alexander Ivanov Move qmp_guest_set_user_password() from __linux__ condition to (__linux__ || __FreeBSD__) condition. Add command and arguments for password setting in FreeBSD. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- qga/commands-posix.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index b0b467ebdb..e0ee0bea00 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2122,7 +2122,9 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList= *vcpus, Error **errp) =20 return processed; } +#endif /* __linux__ */ =20 +#if defined(__linux__) || defined(__FreeBSD__) void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, @@ -2156,10 +2158,15 @@ void qmp_guest_set_user_password(const char *userna= me, goto out; } =20 +#ifdef __FreeBSD__ + chpasswddata =3D g_strdup(rawpasswddata); + passwd_path =3D g_find_program_in_path("pw"); +#else chpasswddata =3D g_strdup_printf("%s:%s\n", username, rawpasswddata); - chpasswdlen =3D strlen(chpasswddata); - passwd_path =3D g_find_program_in_path("chpasswd"); +#endif + + chpasswdlen =3D strlen(chpasswddata); =20 if (!passwd_path) { error_setg(errp, "cannot find 'passwd' program in PATH"); @@ -2180,11 +2187,17 @@ void qmp_guest_set_user_password(const char *userna= me, reopen_fd_to_null(1); reopen_fd_to_null(2); =20 +#ifdef __FreeBSD__ + const char *h_arg; + h_arg =3D (crypted) ? "-H" : "-h"; + execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NU= LL); +#else if (crypted) { execl(passwd_path, "chpasswd", "-e", NULL); } else { execl(passwd_path, "chpasswd", NULL); } +#endif _exit(EXIT_FAILURE); } else if (pid < 0) { error_setg_errno(errp, errno, "failed to create child process"); @@ -2227,7 +2240,17 @@ out: close(datafd[1]); } } +#else /* __linux__ || __FreeBSD__ */ +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); +} +#endif /* __linux__ || __FreeBSD__ */ =20 +#ifdef __linux__ static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, int size, Error **errp) { @@ -2764,14 +2787,6 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLis= t *vcpus, Error **errp) return -1; } =20 -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { error_setg(errp, QERR_UNSUPPORTED); --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807123; cv=none; d=zohomail.com; s=zohoarc; b=IDXqYt9QC0BQLyawRh6eXm7djdNZca0fRm7AhDmp0bBFNKgq6vaDZ+XTkNnSPRWeqhDHizWHu7kFGHOo8Oe5GWzjpe5mQ/hY4m2MZfAXLR3jnKsee+v17HS9qiMOn3A1xhMSYlKmNX3PcLRjI4XBsj4lv+g0bxNY6GSmYVVPfd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807123; h=Content-Type:Content-Transfer-Encoding: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=6NbN/bsOBAfri9fgQ6JE01uG9HT7lgfPFRus+BIxDMU=; b=FkA1EyxFdSzc/yQ2am5TBXVAqpcMawPRQ3G6L4+5NFHlpOkV8E0QZ3uisvjbMq9JJNJlv/i+kszIhOKPbnY5R9cJP3bsEQq6tUZoBc07MENBj1H1osj6g0UIQG3ypEYviOVftH/7696vK8fPTW78Wcr7C5aaEcS8lprZGUXrr/A= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666807123663770.9208751486915; Wed, 26 Oct 2022 10:58:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkd2-000064-7y; Wed, 26 Oct 2022 13:55:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcz-00005k-6F for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcu-0005fW-CX for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:44 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-170-naHFagsfMqOVN3AvRiJxyA-1; Wed, 26 Oct 2022 13:55:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D6DE857D15; Wed, 26 Oct 2022 17:55:36 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 152D62166B2B; Wed, 26 Oct 2022 17:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6NbN/bsOBAfri9fgQ6JE01uG9HT7lgfPFRus+BIxDMU=; b=CensaxdodppNo1gZkE0ZLLgbfIWiq9l6d1lG9O5kC3wavHtDfEljMr4WsSLRgNAx3/QcfH BfEpFUzGGResk5I29aWKXghikLvaZ5MN/9NR3fEQRWAFCZHftinnWFSfkGGxWiPbn33y6c 9v02PUEP+5VWngZk6FCTdgXYq/W58uQ= X-MC-Unique: naHFagsfMqOVN3AvRiJxyA-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 6/8] qga: Move HW address getting to a separate function Date: Wed, 26 Oct 2022 20:55:16 +0300 Message-Id: <20221026175518.2636846-7-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807125774100003 From: Alexander Ivanov In the next patch FreeBSD support for guest-network-get-interfaces will be added. Previously move Linux-specific code of HW address getting to a separate functions and add a dumb function to commands-bsd.c. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- qga/commands-bsd.c | 16 +++++++ qga/commands-common.h | 6 +++ qga/commands-posix.c | 98 ++++++++++++++++++++++++------------------- 3 files changed, 78 insertions(+), 42 deletions(-) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ca06692179..ebf0fb8b0f 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -167,3 +167,19 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) return NULL; } #endif /* CONFIG_FSFREEZE */ + +#ifdef HAVE_GETIFADDRS +/* + * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a + * buffer with ETHER_ADDR_LEN length at least. + * + * Returns false in case of an error, otherwise true. "obtained" arguument + * is true if a MAC address was obtained successful, otherwise false. + */ +bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp) +{ + *obtained =3D false; + return true; +} +#endif /* HAVE_GETIFADDRS */ diff --git a/qga/commands-common.h b/qga/commands-common.h index d0583c6ddb..8c1c56aac9 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -56,6 +56,12 @@ int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mount= points, int qmp_guest_fsfreeze_do_thaw(Error **errp); #endif /* CONFIG_FSFREEZE */ =20 +#ifdef HAVE_GETIFADDRS +#include +bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp); +#endif + typedef struct GuestFileHandle GuestFileHandle; =20 GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index e0ee0bea00..32493d6383 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -41,20 +41,12 @@ #endif #endif =20 -#ifdef __FreeBSD__ -/* - * The code under HAVE_GETIFADDRS condition can't be compiled in FreeBSD. - * Fix it in one of the following patches. - */ -#undef HAVE_GETIFADDRS -#endif - #ifdef HAVE_GETIFADDRS #include #include #include +#include #include -#include #ifdef CONFIG_SOLARIS #include #endif @@ -2889,6 +2881,57 @@ static int guest_get_network_stats(const char *name, return -1; } =20 +#ifndef __FreeBSD__ +/* + * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a + * buffer with ETHER_ADDR_LEN length at least. + * + * Returns false in case of an error, otherwise true. "obtained" argument + * is true if a MAC address was obtained successful, otherwise false. + */ +bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp) +{ + struct ifreq ifr; + int sock; + + *obtained =3D false; + + /* we haven't obtained HW address yet */ + sock =3D socket(PF_INET, SOCK_STREAM, 0); + if (sock =3D=3D -1) { + error_setg_errno(errp, errno, "failed to create socket"); + return false; + } + + memset(&ifr, 0, sizeof(ifr)); + pstrcpy(ifr.ifr_name, IF_NAMESIZE, ifa->ifa_name); + if (ioctl(sock, SIOCGIFHWADDR, &ifr) =3D=3D -1) { + /* + * We can't get the hw addr of this interface, but that's not a + * fatal error. + */ + if (errno =3D=3D EADDRNOTAVAIL) { + /* The interface doesn't have a hw addr (e.g. loopback). */ + g_debug("failed to get MAC address of %s: %s", + ifa->ifa_name, strerror(errno)); + } else{ + g_warning("failed to get MAC address of %s: %s", + ifa->ifa_name, strerror(errno)); + } + } else { +#ifdef CONFIG_SOLARIS + memcpy(buf, &ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); +#else + memcpy(buf, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); +#endif + *obtained =3D true; + } + close(sock); + return true; +} +#endif /* __FreeBSD__ */ + /* * Build information about guest interfaces */ @@ -2909,9 +2952,8 @@ GuestNetworkInterfaceList *qmp_guest_network_get_inte= rfaces(Error **errp) GuestNetworkInterfaceStat *interface_stat =3D NULL; char addr4[INET_ADDRSTRLEN]; char addr6[INET6_ADDRSTRLEN]; - int sock; - struct ifreq ifr; - unsigned char *mac_addr; + unsigned char mac_addr[ETHER_ADDR_LEN]; + bool obtained; void *p; =20 g_debug("Processing %s interface", ifa->ifa_name); @@ -2926,45 +2968,17 @@ GuestNetworkInterfaceList *qmp_guest_network_get_in= terfaces(Error **errp) } =20 if (!info->has_hardware_address) { - /* we haven't obtained HW address yet */ - sock =3D socket(PF_INET, SOCK_STREAM, 0); - if (sock =3D=3D -1) { - error_setg_errno(errp, errno, "failed to create socket"); + if (!guest_get_hw_addr(ifa, mac_addr, &obtained, errp)) { goto error; } - - memset(&ifr, 0, sizeof(ifr)); - pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->name); - if (ioctl(sock, SIOCGIFHWADDR, &ifr) =3D=3D -1) { - /* - * We can't get the hw addr of this interface, but that's = not a - * fatal error. Don't set info->hardware_address, but keep - * going. - */ - if (errno =3D=3D EADDRNOTAVAIL) { - /* The interface doesn't have a hw addr (e.g. loopback= ). */ - g_debug("failed to get MAC address of %s: %s", - ifa->ifa_name, strerror(errno)); - } else{ - g_warning("failed to get MAC address of %s: %s", - ifa->ifa_name, strerror(errno)); - } - - } else { -#ifdef CONFIG_SOLARIS - mac_addr =3D (unsigned char *) &ifr.ifr_addr.sa_data; -#else - mac_addr =3D (unsigned char *) &ifr.ifr_hwaddr.sa_data; -#endif + if (obtained) { info->hardware_address =3D g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x", (int) mac_addr[0], (int) mac_addr[1], (int) mac_addr[2], (int) mac_addr[3], (int) mac_addr[4], (int) mac_addr[5]); - info->has_hardware_address =3D true; } - close(sock); } =20 if (ifa->ifa_addr && --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807167; cv=none; d=zohomail.com; s=zohoarc; b=TA3oAO1oO1be2CwHYNdE+jrw9U6IRNaHseN6t8NCqYaLR08HYO5gnkF+bVADW65go3S49khF9FLT/qFtQ0vqwvsYvpOLKoULqb50rM88atSse7XDtA5v9nrGR/5Mn1dhHYJTpoCRI/iikiz9GDbirDM5UdljsPYUTUogJFD5j84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807167; h=Content-Type:Content-Transfer-Encoding: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=+ZAqmK1x4NQ3GxoKv0wHJKJGpehWaLuPjvqzLYjvfok=; b=aaAkyQMGeobIm9nX0boTI1Jy5lZanswAWap+B0j9vKBUZPMdxgh/3vR505Hq1UvNF4UzAcQ3fOTobjbMo5LWUCijTJ40MQ4lcPNdaD1M970Lwx5xCjfRDmyBZJdAaU3Kj9JuQkKomBG6j4Pua1RTgFrqKAXU+XV0fLPicRYuSoE= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166680716723735.0029820863474; Wed, 26 Oct 2022 10:59:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkcz-000060-Iy; Wed, 26 Oct 2022 13:55:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcy-00005K-2P for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcv-0005fj-Op for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-vR7s5jrTNbqZ_yd2qx0KJg-1; Wed, 26 Oct 2022 13:55:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87621101CC6B; Wed, 26 Oct 2022 17:55:37 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D5C12166B2B; Wed, 26 Oct 2022 17:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ZAqmK1x4NQ3GxoKv0wHJKJGpehWaLuPjvqzLYjvfok=; b=DCQrVFWRjPcDTYVyyZwlVWxMtwF3yu4x+AiPMVPFEmSA8mQbG6UUjwUq9EWZBamfdceozg sksNNz63ydkhFxXWEO/0ne3LFoEzomKp5xua1e+gxu7750bMtDfAPxY4JOw1LEL2dcirgz EFP4c2OxmLsrONAu+Ki2G1T1ghvG5ZA= X-MC-Unique: vR7s5jrTNbqZ_yd2qx0KJg-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 7/8] qga: Add HW address getting for FreeBSD Date: Wed, 26 Oct 2022 20:55:17 +0300 Message-Id: <20221026175518.2636846-8-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.129.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807167921100002 From: Alexander Ivanov Replace a dumb function in commands-bsd.c by the code of HW address getting. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Ivanov Signed-off-by: Konstantin Kostiuk --- qga/commands-bsd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ebf0fb8b0f..15cade2d4c 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include =20 #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) @@ -179,7 +181,20 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, bool *obtained, Error **errp) { + struct sockaddr_dl *sdp; + *obtained =3D false; + + if (ifa->ifa_addr->sa_family !=3D AF_LINK) { + /* We can get HW address only for AF_LINK family. */ + g_debug("failed to get MAC address of %s", ifa->ifa_name); + return true; + } + + sdp =3D (struct sockaddr_dl *)ifa->ifa_addr; + memcpy(buf, sdp->sdl_data + sdp->sdl_nlen, ETHER_ADDR_LEN); + *obtained =3D true; + return true; } #endif /* HAVE_GETIFADDRS */ --=20 2.25.1 From nobody Thu Apr 18 08:31:00 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=1666807407; cv=none; d=zohomail.com; s=zohoarc; b=Hj0M01hut5eBvHKSOpRScHYCW4vLQU8xWgVGf+jIjPK9Uf/lDw3b6kBKJuSCE7h/eTON4t9AH1WJ+cQqqmmoSu4fgIjaCQFAqGUTDXxTB0l3MTyS6IBDesifvzukPZOWOQL8wZvZLTOQ2FuuY5OQL6/wHeXCs2Jn30kIBP33FOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666807407; h=Content-Type:Content-Transfer-Encoding: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=P2vxqhrSgxGLaLWSHgWAQ+Sz40NyHDNGkkC8Hulk6Fo=; b=gReMZN0sB6EInA9LIparz+OoxRLyKZ/LNSf0NoeDynUtc6WHNhvNQ3Ge9FrNjwp9YoOLEZB7NtNJ9YBOY+3Vt5r+Qa6Ok76fVQx9Ze+i0vMUxbakxyN1J4yxMgN//nCgami1/YFkipqo9pmDyMO81p6xLsJOPn8uCwQF73S7wjU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666807407051169.9184079947654; Wed, 26 Oct 2022 11:03:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onkcy-00005V-Cz; Wed, 26 Oct 2022 13:55:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcx-00005C-6D for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onkcv-0005ff-Cg for qemu-devel@nongnu.org; Wed, 26 Oct 2022 13:55:42 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-86w05p53OuSD28xtn4O8Uw-1; Wed, 26 Oct 2022 13:55:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1383857D1E; Wed, 26 Oct 2022 17:55:38 +0000 (UTC) Received: from kostyanf14nb.redhat.com (ovpn-192-17.brq.redhat.com [10.40.192.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E34512166B2B; Wed, 26 Oct 2022 17:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666806940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P2vxqhrSgxGLaLWSHgWAQ+Sz40NyHDNGkkC8Hulk6Fo=; b=ZKz1vpIF7oNg8p/TdKYA/M3HyPisD4aolE/+OEwuHtbTg6MyqyEw6bCo4lrG3mtAX+02Rk ClLzEyM0jM1w4TYOFxkdDRJc8VnE695X/x88h/0/y+cS1NXyJYYiYfYmcBu8oinjvHPUin ewW+dba5Wg+686UoZZclE2zTv/NeSH0= X-MC-Unique: 86w05p53OuSD28xtn4O8Uw-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 8/8] qga: add channel path to error messages Date: Wed, 26 Oct 2022 20:55:18 +0300 Message-Id: <20221026175518.2636846-9-kkostiuk@redhat.com> In-Reply-To: <20221026175518.2636846-1-kkostiuk@redhat.com> References: <20221026175518.2636846-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.129.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666807409075100001 From: Bj=C3=B8rn Forsman It's useful to know which device was used if/when it fails. channel-win32.c had this since 2015, with c69403fcd4a0cb89f838a212ab71e4a1a3464c95 ("qemu-ga: debug printouts to help troubleshoot installation"), this brings channel-posix.c up to speed. Signed-off-by: Bj=C3=B8rn Forsman Reviewed-by: Konstantin Kostiuk Signed-off-by: Konstantin Kostiuk --- qga/channel-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 568350ded4..0c5175d957 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -138,7 +138,7 @@ static gboolean ga_channel_open(GAChannel *c, const gch= ar *path, 0 ); if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "error opening channel"); + error_setg_errno(errp, errno, "error opening channel '%s'", pa= th); return false; } #ifdef CONFIG_SOLARIS @@ -182,7 +182,7 @@ static gboolean ga_channel_open(GAChannel *c, const gch= ar *path, assert(fd < 0); fd =3D qga_open_cloexec(path, O_RDWR | O_NOCTTY | O_NONBLOCK, 0); if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "error opening channel"); + error_setg_errno(errp, errno, "error opening channel '%s'", pa= th); return false; } tcgetattr(fd, &tio); --=20 2.25.1