From patchwork Wed Apr 20 18:06:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 563987 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp4409927map; Wed, 20 Apr 2022 11:23:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxulbqTJL80zM4FnvO1wF89KS54aE3mEu2FSOIvo5Mm3F1Ay9nSR0T2RekEoGOUIwU9/SIA X-Received: by 2002:a81:ecd:0:b0:2eb:f1d0:9513 with SMTP id 196-20020a810ecd000000b002ebf1d09513mr22366655ywo.452.1650478983607; Wed, 20 Apr 2022 11:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650478983; cv=none; d=google.com; s=arc-20160816; b=qiWBXEw9ibeDQrlkdnIWpOpXOgqjmOGC9HKBDFdFQ52IXnj1GCiR/LiTiZn06OjPui OZ6JW218x1AnYk09I7/KaBQO1ELx6ndqYySH89gIUfLte5zAi8kYQbBf/7wAq4T79TsC sFzN9JY/eNc//ied5K/s2rD7BBpKG2B9oHzvSPp6I/AP6tJsJoDIy91xvMVe4kK1lMtL JAilnzKSIRmrYc0nHLWOA1Mqb+SX2/8nWNbY0m7Xn7ZHITVCLa74j331N7Mn0VurWoI/ jMZNRQ6kwCroC8BeCcf8qldFzHbmTLlrIEQEhb+Dt7vDU6T6N/yPi1T/pSqkor1t/8zq TJ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=24qJPC1oFAO3Id/yaILSHNoaXDm+P/+xDRz86KIt45U=; b=JEGHmjVRCKRXub2to5oNI3w5BkM3NCpevE7r9Rzk1Txvn6RoyEX5NbrXoFutFbY4rC mH1Dyq4UW5vx1NJhDCXX4uNiL1wZKSQXfQuh7A9+LvSaWbfIj3si8zx+LX5L8gps064r gJ+woSb+jaqx7Ty6XDhvKBP0bFnTwmGboNOTZR6OqzKk2ykk4Qr9V29uxisrwsSNet0p mhj3YvdaZ62rZb1MJUVRviYTrGB5wNcoK4y73pTXIh32qzbfHfEvyokQZuXMOqgZdT3N Tu6SOmKwoThe6PnsOeBV0eXkH56OoKfXAxc+X62FP+SFCSN6ue29CzxQneRxNUJ3F4jY nAWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x0qrO7uL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r14-20020a0de80e000000b002e5be453663si628398ywe.176.2022.04.20.11.23.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Apr 2022 11:23:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x0qrO7uL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhEyl-0007R7-4S for patch@linaro.org; Wed, 20 Apr 2022 14:23:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhEjE-0006bL-UT for qemu-devel@nongnu.org; Wed, 20 Apr 2022 14:07:01 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:43604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhEjD-0001Ny-AM for qemu-devel@nongnu.org; Wed, 20 Apr 2022 14:07:00 -0400 Received: by mail-pj1-x102b.google.com with SMTP id j8-20020a17090a060800b001cd4fb60dccso2772219pjj.2 for ; Wed, 20 Apr 2022 11:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=24qJPC1oFAO3Id/yaILSHNoaXDm+P/+xDRz86KIt45U=; b=x0qrO7uLDZDDUgkkVsiXjRfZagK4HkX3hTzqX5/SINlT4vbvXnvIzpBMWNr+Wtjx+z C3KAWmZntYNvZNEiUdUJ0uzedCDorCIesynOFjL+/2CV2CfxXitXOT/z4nJFkSIYdtz4 /IgpNhna80UHj+QJyW9LNHx7PmBxCXxUiytrXNTh+KynHZCLElPScS0XR5dEbN+m0QOj eVcKEzIYy1D6J7OmSwLgVKEhOPsfasw7SkIStMCA9clWxF6FcB27tbTcUlwKeH14zwn8 qz1VKg0C8bfc/PvIWz+zJ/jroAteRhe1NAf5GCcG+fJaJmDNg9zopmZVRSt+EA0hGHuK dX5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=24qJPC1oFAO3Id/yaILSHNoaXDm+P/+xDRz86KIt45U=; b=uDOMnfk0QWvxuzUN3E4T8JJ3XTMonpIf0VmI2GvPhJs+RDSA4kw75qFZC53WKDPw2f QFUhboiuXALbf+iihPtBgdfljSJPrNmpTeImn15pyfi9aV7yy5JPXf96SGUH682txJde ySHKZX4cxytnIATPzBJnEszfmoIbaDXWw9Udehw8FdaaJDUla5hL+fhCeueQfHpNp7OS xlG6IupVHvaN4jWT82Rv5BO4J6bqX2YT1nPSgpt/5eM1JFS35ASezZtd6Oo7g/0Wqv3N EqyInxWoKpE5Ss+Ho/pNmW0g/CUtNGYs2wtTELKFTbQHXOtmO5rOZuY44aUdNTV4+gq3 pb+A== X-Gm-Message-State: AOAM530eoiV4EtwdPoCya6gOWYMSB5Df2hqc8AeuMoJt5ItgqpD+4P/D /C+lWvN4TzQE/KgVsWXdHlAjPGCrpGyA6w== X-Received: by 2002:a17:902:c941:b0:158:f9ca:7769 with SMTP id i1-20020a170902c94100b00158f9ca7769mr16258391pla.161.1650478017803; Wed, 20 Apr 2022 11:06:57 -0700 (PDT) Received: from stoup.. (174-21-142-130.tukw.qwest.net. [174.21.142.130]) by smtp.gmail.com with ESMTPSA id i2-20020a17090a058200b001d2fc489b8asm56681pji.25.2022.04.20.11.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 11:06:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 37/39] util/log: Rename QemuLogFile to RCUCloseFILE Date: Wed, 20 Apr 2022 11:06:16 -0700 Message-Id: <20220420180618.1183855-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220420180618.1183855-1-richard.henderson@linaro.org> References: <20220420180618.1183855-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.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, SPF_HELO_NONE=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: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" s/QemuLogFile/RCUCloseFILE/ s/qemu_logfile_free/rcu_close_file/ Emphasize that this is only a carrier for passing a pointer to call_rcu for closing, and not the real logfile. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20220417183019.755276-38-richard.henderson@linaro.org> --- util/log.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/util/log.c b/util/log.c index 21da961d8d..eb6e85b2f0 100644 --- a/util/log.c +++ b/util/log.c @@ -29,15 +29,15 @@ #include "qemu/rcu.h" -typedef struct QemuLogFile { +typedef struct RCUCloseFILE { struct rcu_head rcu; FILE *fd; -} QemuLogFile; +} RCUCloseFILE; /* Mutex covering the other global_* variables. */ static QemuMutex global_mutex; static char *global_filename; -static QemuLogFile *global_file; +static RCUCloseFILE *global_file; int qemu_loglevel; static int log_append = 0; @@ -52,7 +52,7 @@ bool qemu_log_enabled(void) /* Returns true if qemu_log() will write somewhere other than stderr. */ bool qemu_log_separate(void) { - QemuLogFile *logfile; + RCUCloseFILE *logfile; bool res = false; rcu_read_lock(); @@ -68,7 +68,7 @@ bool qemu_log_separate(void) FILE *qemu_log_trylock(void) { - QemuLogFile *logfile; + RCUCloseFILE *logfile; rcu_read_lock(); logfile = qatomic_rcu_read(&global_file); @@ -108,14 +108,12 @@ static void __attribute__((__constructor__)) startup(void) qemu_mutex_init(&global_mutex); } -static void qemu_logfile_free(QemuLogFile *logfile) +static void rcu_close_file(RCUCloseFILE *r) { - g_assert(logfile); - - if (logfile->fd != stderr) { - fclose(logfile->fd); + if (r->fd != stderr) { + fclose(r->fd); } - g_free(logfile); + g_free(r); } /* enable or disable low levels log */ @@ -124,7 +122,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name, { bool need_to_open_file; bool daemonized; - QemuLogFile *logfile; + RCUCloseFILE *logfile; QEMU_LOCK_GUARD(&global_mutex); logfile = global_file; @@ -178,7 +176,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name, if (logfile && (!need_to_open_file || changed_name)) { qatomic_rcu_set(&global_file, NULL); - call_rcu(logfile, qemu_logfile_free, rcu); + call_rcu(logfile, rcu_close_file, rcu); logfile = NULL; } @@ -196,7 +194,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name, if (daemonized) { dup2(fileno(fd), STDERR_FILENO); fclose(fd); - /* This will skip closing logfile in qemu_logfile_free. */ + /* This will skip closing logfile in rcu_close_file. */ fd = stderr; } } else { @@ -207,7 +205,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name, log_append = 1; - logfile = g_new0(QemuLogFile, 1); + logfile = g_new0(RCUCloseFILE, 1); logfile->fd = fd; qatomic_rcu_set(&global_file, logfile); }