From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 547A3C433E0 for ; Fri, 15 Jan 2021 08:31:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0AF7B23118 for ; Fri, 15 Jan 2021 08:31:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0AF7B23118 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.67742.121203 (Exim 4.92) (envelope-from ) id 1l0KVW-0001F0-Ie; Fri, 15 Jan 2021 08:30:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 67742.121203; Fri, 15 Jan 2021 08:30:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVW-0001EX-AB; Fri, 15 Jan 2021 08:30:58 +0000 Received: by outflank-mailman (input) for mailman id 67742; Fri, 15 Jan 2021 08:30:56 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVU-0008HA-O1 for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:56 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 70209202-40b6-475a-8c2c-f9e8a1e79505; Fri, 15 Jan 2021 08:30:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 20AFFB98B; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 70209202-40b6-475a-8c2c-f9e8a1e79505 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o7E68E2skQt7ZQ6fewcb5Nlvjr3t4kMoxMxQJVoybz4=; b=GgXTlLDvG8xOlHqNKqeX70it5iMh298eHDUaJzMx7DrncSzYsDFy5jW7EAS6z7Rwmq4eFJ ACvX2ZxngJfVVZUPB9VGTTI8ltLwFf5N4dKyZs6ceGRj8YOhyVx2TMU1SjsZoyfqwlgXfV 2jDX9fC6hxUlkv/o30AQtvyZPTj/a3k= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v12 14/27] tools/xenstore: allow live update only with no transaction active Date: Fri, 15 Jan 2021 09:29:47 +0100 Message-Id: <20210115083000.14186-15-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In order to simplify live update state dumping only allow live update to happen when no transaction is active. A timeout is used to detect guests which have a transaction active for longer periods of time. In case such a guest is detected when trying to do a live update it will be reported and the update will fail. The admin can then either use a longer timeout, or use the force flag to just ignore the transactions of such a guest, or kill the guest before retrying. Signed-off-by: Juergen Gross --- V11: - reworked timeout logic to be handled in daemon (Edwin Torok) --- tools/xenstore/xenstored_control.c | 29 ++++++++++++++++++++++++-- tools/xenstore/xenstored_core.h | 1 + tools/xenstore/xenstored_transaction.c | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c index d3da6b8111..52fbf31367 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -312,12 +312,37 @@ static const char *lu_arch(const void *ctx, struct connection *conn, static bool lu_check_lu_allowed(void) { - return true; + struct connection *conn; + time_t now = time(NULL); + unsigned int ta_total = 0, ta_long = 0; + + list_for_each_entry(conn, &connections, list) { + if (conn->ta_start_time) { + ta_total++; + if (conn->ta_start_time - now >= lu_status->timeout) + ta_long++; + } + } + + return ta_total ? (lu_status->force && ta_long == ta_total) : true; } static const char *lu_reject_reason(const void *ctx) { - return "BUSY"; + char *ret = NULL; + struct connection *conn; + time_t now = time(NULL); + + list_for_each_entry(conn, &connections, list) { + if (conn->ta_start_time - now >= lu_status->timeout) { + ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld s", + ret ? : "Domains with long running transactions:", + conn->id, + conn->ta_start_time - now); + } + } + + return ret ? (const char *)ret : "Overlapping transactions"; } static const char *lu_dump_state(const void *ctx, struct connection *conn) diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h index d5cdf17160..db70f61f0d 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -107,6 +107,7 @@ struct connection struct list_head transaction_list; uint32_t next_transaction_id; unsigned int transaction_started; + time_t ta_start_time; /* List of delayed requests. */ struct list_head delayed; diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xenstored_transaction.c index 52355f4ed8..cd07fb0f21 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -473,6 +473,8 @@ int do_transaction_start(struct connection *conn, struct buffered_data *in) list_add_tail(&trans->list, &conn->transaction_list); talloc_steal(conn, trans); talloc_set_destructor(trans, destroy_transaction); + if (!conn->transaction_started) + conn->ta_start_time = time(NULL); conn->transaction_started++; wrl_ntransactions++; @@ -511,6 +513,8 @@ int do_transaction_end(struct connection *conn, struct buffered_data *in) conn->transaction = NULL; list_del(&trans->list); conn->transaction_started--; + if (!conn->transaction_started) + conn->ta_start_time = 0; /* Attach transaction to in for auto-cleanup */ talloc_steal(in, trans); @@ -589,6 +593,7 @@ void conn_delete_all_transactions(struct connection *conn) assert(conn->transaction == NULL); conn->transaction_started = 0; + conn->ta_start_time = 0; } int check_transactions(struct hashtable *hash) -- 2.26.2