From nobody Sun May 5 05:36:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660302535823870.2687530977298; Fri, 12 Aug 2022 04:08:55 -0700 (PDT) Received: from localhost ([::1]:38478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMSX8-0002N3-9D for importer@patchew.org; Fri, 12 Aug 2022 07:08:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMSQI-0008Hy-Hq for qemu-devel@nongnu.org; Fri, 12 Aug 2022 07:01:50 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.222]:50462 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMSQC-0003CI-RU for qemu-devel@nongnu.org; Fri, 12 Aug 2022 07:01:50 -0400 Received: from clientip-36.111.64.85 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id D2D452800B6; Fri, 12 Aug 2022 19:01:28 +0800 (CST) Received: from ([172.18.0.48]) by app0024 with ESMTP id 6f113a3c3a7f46fda2f82f41d7dbbe91 for armbru@redhat.com; Fri, 12 Aug 2022 19:01:32 CST HMM_SOURCE_IP: 172.18.0.48:33104.1040593120 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +tugy@chinatelecom.cn X-Transaction-ID: 6f113a3c3a7f46fda2f82f41d7dbbe91 X-Real-From: tugy@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 Message-ID: Date: Fri, 12 Aug 2022 19:01:27 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Markus Armbruster , "Dr. David Alan Gilbert" , Peter Maydell , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Richard Henderson , Christian Schoenebeck , =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= Cc: qemu-devel@nongnu.org, tugy@chinatelecom.cn From: Guoyi Tu Subject: [PATCH] osdep: Introduce qemu_get_fd() to wrap the common codes Content-Type: text/plain; charset="utf-8"; format="flowed" 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=42.123.76.222; envelope-from=tugy@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1660302539155100001 socket_get_fd() have much the same codes as monitor_fd_param(), so qemu_get_fd() is introduced to implement the common logic. now socket_get_fd() and monitor_fd_param() directly call this function. Signed-off-by: Guoyi Tu --- =C2=A0include/qemu/osdep.h |=C2=A0 1 + =C2=A0monitor/misc.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 21 +-----------= --------- =C2=A0util/osdep.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 25 ++= +++++++++++++++++++++++ =C2=A0util/qemu-sockets.c=C2=A0 | 17 +++++------------ =C2=A04 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index b1c161c035..b920f128a7 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -491,6 +491,7 @@ int qemu_open_old(const char *name, int flags, ...); =C2=A0int qemu_open(const char *name, int flags, Error **errp); =C2=A0int qemu_create(const char *name, int flags, mode_t mode, Error **er= rp); =C2=A0int qemu_close(int fd); +int qemu_get_fd(Monitor *mon, const char *fdname, Error **errp); =C2=A0int qemu_unlink(const char *name); =C2=A0#ifndef _WIN32 =C2=A0int qemu_dup_flags(int fd, int flags); diff --git a/monitor/misc.c b/monitor/misc.c index 3d2312ba8d..0d3372cf2b 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1395,26 +1395,7 @@ void monitor_fdset_dup_fd_remove(int dup_fd) =C2=A0int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) =C2=A0{ -=C2=A0=C2=A0=C2=A0 int fd; -=C2=A0=C2=A0=C2=A0 Error *local_err =3D NULL; - -=C2=A0=C2=A0=C2=A0 if (!qemu_isdigit(fdname[0]) && mon) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fd =3D monitor_get_fd(mon, fdna= me, &local_err); -=C2=A0=C2=A0=C2=A0 } else { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fd =3D qemu_parse_fd(fdname); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (fd =3D=3D -1) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_s= etg(&local_err, "Invalid file descriptor number '%s'", -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fdname); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } -=C2=A0=C2=A0=C2=A0 } -=C2=A0=C2=A0=C2=A0 if (local_err) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_propagate(errp, local_err= ); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assert(fd =3D=3D -1); -=C2=A0=C2=A0=C2=A0 } else { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assert(fd !=3D -1); -=C2=A0=C2=A0=C2=A0 } - -=C2=A0=C2=A0=C2=A0 return fd; +=C2=A0=C2=A0=C2=A0 return qemu_get_fd(mon, fdname, errp); =C2=A0} =C2=A0/* Please update hmp-commands.hx when adding or changing commands */ diff --git a/util/osdep.c b/util/osdep.c index 60fcbbaebe..c57551ca78 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -23,6 +23,7 @@ =C2=A0 */ =C2=A0#include "qemu/osdep.h" =C2=A0#include "qapi/error.h" +#include "qemu/ctype.h" =C2=A0#include "qemu/cutils.h" =C2=A0#include "qemu/sockets.h" =C2=A0#include "qemu/error-report.h" @@ -413,6 +414,30 @@ int qemu_close(int fd) =C2=A0=C2=A0=C2=A0=C2=A0 return close(fd); =C2=A0} +int qemu_get_fd(Monitor *mon, const char *fdname, Error **errp) +{ +=C2=A0=C2=A0=C2=A0 int fd; +=C2=A0=C2=A0=C2=A0 Error *local_err =3D NULL; + +=C2=A0=C2=A0=C2=A0 if (!qemu_isdigit(fdname[0]) && mon) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fd =3D monitor_get_fd(mon, fdna= me, &local_err); +=C2=A0=C2=A0=C2=A0 } else { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fd =3D qemu_parse_fd(fdname); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (fd =3D=3D -1) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_s= etg(&local_err, "Invalid file descriptor number '%s'", +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fdname); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0 if (local_err) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_propagate(errp, local_err= ); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assert(fd =3D=3D -1); +=C2=A0=C2=A0=C2=A0 } else { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assert(fd !=3D -1); +=C2=A0=C2=A0=C2=A0 } + +=C2=A0=C2=A0=C2=A0 return fd; +} + =C2=A0/* =C2=A0 * Delete a file from the filesystem, unless the filename is=20 /dev/fdset/... =C2=A0 * diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 13b5b197f9..92960ee6eb 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1142,19 +1142,12 @@ static int socket_get_fd(const char *fdstr,=20 Error **errp) =C2=A0{ =C2=A0=C2=A0=C2=A0=C2=A0 Monitor *cur_mon =3D monitor_cur(); =C2=A0=C2=A0=C2=A0=C2=A0 int fd; -=C2=A0=C2=A0=C2=A0 if (cur_mon) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fd =3D monitor_get_fd(cur_mon, = fdstr, errp); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (fd < 0) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return = -1; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } -=C2=A0=C2=A0=C2=A0 } else { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (qemu_strtoi(fdstr, NULL, 10= , &fd) < 0) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_s= etg_errno(errp, errno, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 "Unable to parse FD number %s", -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 fdstr); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return = -1; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } + +=C2=A0=C2=A0=C2=A0 fd =3D qemu_get_fd(cur_mon, fdstr, errp); +=C2=A0=C2=A0=C2=A0 if (fd < 0) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return -1; =C2=A0=C2=A0=C2=A0=C2=A0 } + =C2=A0=C2=A0=C2=A0=C2=A0 if (!fd_is_socket(fd)) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_setg(errp, "File de= scriptor '%s' is not a socket", fdstr); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 close(fd); --=20 2.25.1