From nobody Fri Mar 29 05:25:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1592923592; cv=none; d=zohomail.com; s=zohoarc; b=eZr9xuT1zQblYp0PZFM9hJkJoJapAokL4JBA29v3NAtWX+afVALRoQ8aNQi+ZgYMin48MmdGGb7CztPS/6BHkUjA4utHshqAHolvkOtWyBbfssKMyoi55dLmq7+RpsTwt9wBm8QcIkkKwiit8pfacTH5E2rSk32PpcYGN9BTSOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592923592; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=P3Unw1EXcbsPX3rQNzDhlRvuyZNKGoxGjjtQy1qvkI0=; b=W57MP3riJ3pnAyiMzRNJCervehGd2s8xozztOBd7d1OSfL7LS87Wr/UTxH4izmKAZOjWZhaaVcrUCj6iskqzg0bJ2DYT3O/57Tht97OVY9M2PJX4dC0W3A2WZvUj50yo+Ps6G3roEs0J43oXkLBAMWtDXfoQ6LVKcNPL6Dfcy+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1592923592356774.2263313646146; Tue, 23 Jun 2020 07:46:32 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-183-F4QOpMiQPcuHqgaaIzRr7Q-1; Tue, 23 Jun 2020 10:46:27 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 328D98031CB; Tue, 23 Jun 2020 14:46:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DA9310013D2; Tue, 23 Jun 2020 14:46:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CF3231800433; Tue, 23 Jun 2020 14:46:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05NEjqbP015956 for ; Tue, 23 Jun 2020 10:45:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id D74D3B3015; Tue, 23 Jun 2020 14:45:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D078AB302C for ; Tue, 23 Jun 2020 14:45:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65A8081DA50 for ; Tue, 23 Jun 2020 14:45:50 +0000 (UTC) Received: from relay3.sw.ru (relay.sw.ru [185.231.240.75]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-HuH4xSf2O7GWp9dsIDbpGw-1; Tue, 23 Jun 2020 10:45:44 -0400 Received: from [172.16.25.65] (helo=dhcp-172-16-25-65.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jnkB0-000298-Db for libvir-list@redhat.com; Tue, 23 Jun 2020 17:45:30 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592923591; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=P3Unw1EXcbsPX3rQNzDhlRvuyZNKGoxGjjtQy1qvkI0=; b=ZHkax3A+JOJ87mYStnUtgKqv4VUd5JniVQSgV2ZdEzj3yxgaHO85TBCPv1wIlJOAP1Z9Px y31FLDnS2eylS2D3kbFhnpKX4NVv9Y/xgMXjtoqeCUOyhbCyU7WhoXLi0KlzuOJY45X6tH l3MG6e+Z1q1HhiSRCvRZyPi5/wE+hMU= X-MC-Unique: F4QOpMiQPcuHqgaaIzRr7Q-1 X-MC-Unique: HuH4xSf2O7GWp9dsIDbpGw-1 From: Dmitry Nesterenko To: libvir-list@redhat.com Subject: [PATCH v2 1/3] virhook: refactoring for support hooks placed in several files Date: Tue, 23 Jun 2020 17:45:33 +0300 Message-Id: <20200623144535.149179-2-dmitry.nesterenko@virtuozzo.com> In-Reply-To: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> References: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Dmitry Nesterenko Reviewed-by: Michal Privoznik --- src/util/virhook.c | 74 +++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index e499841f66..64ee9a2307 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -221,6 +221,57 @@ virHookPresent(int driver) return 1; } =20 +/** + * virRunScript: + * @path: the script path + * @id: an id for the object '-' if non available for example on daemon ho= oks + * @op: the operation on the id + * @subop: a sub_operation, currently unused + * @extra: optional string information + * @input: extra input given to the script on stdin + * @output: optional address of variable to store malloced result buffer + * + * Implement a execution of script. This is a synchronous call, we wait for + * execution completion. If @output is non-NULL, *output is guaranteed to = be + * allocated after successful virRunScript, and is best-effort allocated a= fter + * failed virRunScript; the caller is responsible for freeing *output. + * + * Returns: 0 if the execution succeeded, -1 if script returned an error + */ +static int +virRunScript(const char *path, + const char *id, + const char *op, + const char *subop, + const char *extra, + const char *input, + char **output) +{ + int ret; + g_autoptr(virCommand) cmd =3D NULL; + + VIR_DEBUG("Calling hook %s id=3D%s op=3D%s subop=3D%s extra=3D%s", + path, id, op, subop, extra); + + cmd =3D virCommandNewArgList(path, id, op, subop, extra, NULL); + + virCommandAddEnvPassCommon(cmd); + + if (input) + virCommandSetInputBuffer(cmd, input); + if (output) + virCommandSetOutputBuffer(cmd, output); + + ret =3D virCommandRun(cmd, NULL); + if (ret < 0) { + /* Convert INTERNAL_ERROR into known error. */ + virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s", + virGetLastErrorMessage()); + } + + return ret; +} + /** * virHookCall: * @driver: the driver number (from virHookDriver enum) @@ -249,7 +300,6 @@ virHookCall(int driver, const char *input, char **output) { - int ret; g_autofree char *path =3D NULL; g_autoptr(virCommand) cmd =3D NULL; const char *drvstr; @@ -318,24 +368,6 @@ virHookCall(int driver, return -1; } =20 - VIR_DEBUG("Calling hook opstr=3D%s subopstr=3D%s extra=3D%s", - opstr, subopstr, extra); - - cmd =3D virCommandNewArgList(path, id, opstr, subopstr, extra, NULL); - - virCommandAddEnvPassCommon(cmd); - - if (input) - virCommandSetInputBuffer(cmd, input); - if (output) - virCommandSetOutputBuffer(cmd, output); - - ret =3D virCommandRun(cmd, NULL); - if (ret < 0) { - /* Convert INTERNAL_ERROR into known error. */ - virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s", - virGetLastErrorMessage()); - } - - return ret; + return virRunScript(path, id, opstr, subopstr, extra, + input, output); } --=20 2.18.4 From nobody Fri Mar 29 05:25:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1592923589; cv=none; d=zohomail.com; s=zohoarc; b=jIpw1A9K5iUCCs/3+PNQAUGq7+xEjzu0dSW6OiVBwW9eqiVgC1vq8+4cPzZdqceQ0sgtoBw/xb+KN7+05XfsEbKgAsytPujU7YGiWY/NmBYLNd+8nyzXqWH93w9301Z/5ozaeRUfhLR/RqCaSZC/TP4b+z+zGwusKHYsuCCRITU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592923589; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=KITFLCyuHI/Jyv2RI/8f5k+7agwEQxGRmHWq7yu46xo=; b=lgNCA6g4Bo6RfxcxOH3/8w8Lg0iMmo0400otdbukAdeplSadfIy2BwzrqRGpjU7c6XJdI8rr92E4IszzKRIz0cu6zsShIzltW9wMCmakesYQjumvZTlkVLGSxfnDHysuBBo8t3uu3aNgUxACVs+2nwuIgpvgNGahNFmY9y2Pd+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1592923589717443.92824053795107; Tue, 23 Jun 2020 07:46:29 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-454-SB6LWxaVPoqbixC0wneVCg-1; Tue, 23 Jun 2020 10:46:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3BD5107ACCA; Tue, 23 Jun 2020 14:46:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94D217166A; Tue, 23 Jun 2020 14:46:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6588B1809547; Tue, 23 Jun 2020 14:46:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05NEjorn015937 for ; Tue, 23 Jun 2020 10:45:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2380D1007381; Tue, 23 Jun 2020 14:45:50 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1998A1007389 for ; Tue, 23 Jun 2020 14:45:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DCBE8026A2 for ; Tue, 23 Jun 2020 14:45:46 +0000 (UTC) Received: from relay3.sw.ru (relay.sw.ru [185.231.240.75]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-b_Ue4QmbNImVal-Pat0dNw-1; Tue, 23 Jun 2020 10:45:43 -0400 Received: from [172.16.25.65] (helo=dhcp-172-16-25-65.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jnkB0-000298-LW for libvir-list@redhat.com; Tue, 23 Jun 2020 17:45:30 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592923588; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KITFLCyuHI/Jyv2RI/8f5k+7agwEQxGRmHWq7yu46xo=; b=JEHUYQv/NeOMO++oUxOJ7yocoEtWho3HOkaswfApsFyt25LHb7W6kpHDhC/SC4/WWQDyhr mk8a1Kpjo6Lcj9G9RLIxizi8b9K31g41avLthCf2tFcfLVtVM8QPey7AQzDXoRnres2yT0 BteUWYj59Iw86VLy49lTynOU2tyJteQ= X-MC-Unique: SB6LWxaVPoqbixC0wneVCg-1 X-MC-Unique: b_Ue4QmbNImVal-Pat0dNw-1 From: Dmitry Nesterenko To: libvir-list@redhat.com Subject: [PATCH v2 2/3] virhook: support hooks placed in several files Date: Tue, 23 Jun 2020 17:45:34 +0300 Message-Id: <20200623144535.149179-3-dmitry.nesterenko@virtuozzo.com> In-Reply-To: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> References: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Dmitry Nesterenko Reviewed-by: Michal Privoznik --- src/util/virhook.c | 106 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 9 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index 64ee9a2307..cd26c8c9bd 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -33,6 +33,7 @@ #include "virfile.h" #include "configmake.h" #include "vircommand.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_HOOK =20 @@ -141,7 +142,11 @@ static int virHooksFound =3D -1; static int virHookCheck(int no, const char *driver) { + int ret; + DIR *dir; + struct dirent *entry; g_autofree char *path =3D NULL; + g_autofree char *dir_path =3D NULL; =20 if (driver =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -158,16 +163,39 @@ virHookCheck(int no, const char *driver) =20 if (!virFileExists(path)) { VIR_DEBUG("No hook script %s", path); - return 0; + } else if (!virFileIsExecutable(path)) { + VIR_WARN("Non-executable hook script %s", path); + } else { + VIR_DEBUG("Found hook script %s", path); + return 1; } =20 - if (!virFileIsExecutable(path)) { - VIR_WARN("Non-executable hook script %s", path); + dir_path =3D g_strdup_printf("%s.d", path); + if ((ret =3D virDirOpenIfExists(&dir, dir_path)) < 0) + return -1; + + if (!ret) { + VIR_DEBUG("No hook script dir %s", dir_path); return 0; } =20 - VIR_DEBUG("Found hook script %s", path); - return 1; + while ((ret =3D virDirRead(dir, &entry, dir_path)) > 0) { + g_autofree char *entry_path =3D g_build_filename(dir_path, + entry->d_name, + NULL); + if (!virFileIsExecutable(entry_path)) { + VIR_WARN("Non-executable hook script %s", entry_path); + continue; + } + + VIR_DEBUG("Found hook script %s", entry_path); + ret =3D 1; + break; + } + + VIR_DIR_CLOSE(dir); + + return ret; } =20 /* @@ -282,7 +310,7 @@ virRunScript(const char *path, * @input: extra input given to the script on stdin * @output: optional address of variable to store malloced result buffer * - * Implement a hook call, where the external script for the driver is + * Implement a hook call, where the external scripts for the driver is * called with the given information. This is a synchronous call, we wait = for * execution completion. If @output is non-NULL, *output is guaranteed to = be * allocated after successful virHookCall, and is best-effort allocated af= ter @@ -300,11 +328,16 @@ virHookCall(int driver, const char *input, char **output) { + int ret, script_ret; + DIR *dir; + struct dirent *entry; g_autofree char *path =3D NULL; - g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *dir_path =3D NULL; + VIR_AUTOSTRINGLIST entries =3D NULL; const char *drvstr; const char *opstr; const char *subopstr; + size_t i, nentries; =20 if (output) *output =3D NULL; @@ -368,6 +401,61 @@ virHookCall(int driver, return -1; } =20 - return virRunScript(path, id, opstr, subopstr, extra, - input, output); + script_ret =3D 1; + + if (virFileIsExecutable(path)) { + script_ret =3D virRunScript(path, id, opstr, subopstr, extra, + input, output); + } + + dir_path =3D g_strdup_printf("%s.d", path); + if ((ret =3D virDirOpenIfExists(&dir, dir_path)) < 0) + return -1; + + if (!ret) + return script_ret; + + while ((ret =3D virDirRead(dir, &entry, dir_path)) > 0) { + g_autofree char *entry_path =3D g_build_filename(dir_path, + entry->d_name, + NULL); + if (!virFileIsExecutable(entry_path)) + continue; + + virStringListAdd(&entries, entry_path); + } + + VIR_DIR_CLOSE(dir); + + if (ret < 0) + return -1; + + if (!entries) + return script_ret; + + nentries =3D virStringListLength((const char **)entries); + qsort(entries, nentries, sizeof(*entries), virStringSortCompare); + + for (i =3D 0; i < nentries; i++) { + int entry_ret; + char *entry_input; + g_autofree char *entry_output =3D NULL; + + /* Get input from previous output */ + entry_input =3D (!script_ret && output && + !virStringIsEmpty(*output)) ? *output : (char *)inp= ut; + entry_ret =3D virRunScript(entries[i], id, opstr, + subopstr, extra, entry_input, + (output) ? &entry_output : NULL); + if (entry_ret < script_ret) + script_ret =3D entry_ret; + + /* Replace output to new output from item */ + if (!entry_ret && output && !virStringIsEmpty(entry_output)) { + g_free(*output); + *output =3D g_steal_pointer(&entry_output); + } + } + + return script_ret; } --=20 2.18.4 From nobody Fri Mar 29 05:25:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1592923566; cv=none; d=zohomail.com; s=zohoarc; b=l13xvEnjHFAsoujcN1nksauvHrAAl7aM1kgbo3rE6qUc4APdvmVhHdw6VJUoMUjSHI+/f0NM4O5ht+w5QcwqtH0xzsAIday20S7ewKkdSkl9wrgTxbuecCsN3+K89QE1u/Z0Vt3GOklpOnDLk+WnGykJ7OhCSu4E05B63OjOoaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592923566; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=FSvzIT1L8GwC9em9lBlIaKdDGY6gKeSToEpMyYwjxBk=; b=iiROQblc+9tIOypUoHHRxIGBMypb/630Vj07CiyLn9GaIwEA9Ar299FRnlJCXPFjyyadIgNNTfKKFmYrOzyqM8WBw7+Ky0FUwuO1D7YGs3Occiilmobp7/d72lyD6i/953CkokRNsaOq+A4xjG3GcXZuVS1JpLxWu92iofFWiQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1592923566484411.3722560057362; Tue, 23 Jun 2020 07:46:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-426-D66B2hlVPrifMI4qXbhEWQ-1; Tue, 23 Jun 2020 10:46:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF0CFBFC3; Tue, 23 Jun 2020 14:45:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C4F07CAA3; Tue, 23 Jun 2020 14:45:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 71034833C6; Tue, 23 Jun 2020 14:45:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05NEjmXC015925 for ; Tue, 23 Jun 2020 10:45:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id CED662156720; Tue, 23 Jun 2020 14:45:48 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAD28215671E for ; Tue, 23 Jun 2020 14:45:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5CA0585A5B1 for ; Tue, 23 Jun 2020 14:45:46 +0000 (UTC) Received: from relay3.sw.ru (relay.sw.ru [185.231.240.75]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-ARPnNekmOBCZE3gyQmrmmQ-1; Tue, 23 Jun 2020 10:45:44 -0400 Received: from [172.16.25.65] (helo=dhcp-172-16-25-65.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jnkB0-000298-Th for libvir-list@redhat.com; Tue, 23 Jun 2020 17:45:30 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592923565; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FSvzIT1L8GwC9em9lBlIaKdDGY6gKeSToEpMyYwjxBk=; b=PX80Sf8LNGInfvcL1uw2Waw573sR6kPED/YurVU46MbDSNOa8fei6spJBkw8TjyoaxDkr/ MmK8BAmp7W5ShHjeDkuO9TB6V+7lSIUgj9Glx/QidOL+N0voFnN6fzSpb6MaoqltwKigb7 mIW2aAT9eNMkqIz3a6zEsIKBYF2eBjI= X-MC-Unique: D66B2hlVPrifMI4qXbhEWQ-1 X-MC-Unique: ARPnNekmOBCZE3gyQmrmmQ-1 From: Dmitry Nesterenko To: libvir-list@redhat.com Subject: [PATCH v2 3/3] virhook: changes in docs about support hooks placed in several files Date: Tue, 23 Jun 2020 17:45:35 +0300 Message-Id: <20200623144535.149179-4-dmitry.nesterenko@virtuozzo.com> In-Reply-To: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> References: <20200623144535.149179-1-dmitry.nesterenko@virtuozzo.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Dmitry Nesterenko Reviewed-by: Michal Privoznik --- NEWS.rst | 6 ++++++ docs/hooks.html.in | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 42d159b233..18917d9e95 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -28,6 +28,12 @@ v6.5.0 (unreleased) schema for node devices was expanded to support attributes for mediated devices. =20 + * virhook: Support hooks placed in several files + + Running all scripts from directory /etc/libvirt/hooks/.d in + alphabetical order. Hook script in old place will be executed + as first for backward compatibility. + * **Improvements** =20 * **Bug fixes** diff --git a/docs/hooks.html.in b/docs/hooks.html.in index 7c9d3ef7f3..a38ba05522 100644 --- a/docs/hooks.html.in +++ b/docs/hooks.html.in @@ -36,6 +36,9 @@
  • If your installation of libvirt has instead been compiled from source, it is likely to be /usr/local/etc/libvirt/hooks/.
  • +
  • Since 6.5.0, you can also place sev= eral + hook scripts in the directories + /etc/libvirt/hooks/<driver>.d/.
  • To use hook scripts, you will need to create this hooks directory manually, place the desired hook scripts inside, then make @@ -59,6 +62,10 @@ Executed when a network is started or stopped or an interface is plugged/unplugged to/from the network +

    Since 6.5.0, you can also have + several scripts with any name in the directories + /etc/libvirt/hooks/<driver>.d/. They are + executed in alphabetical order after main script.


    =20

    Script structure

    @@ -191,6 +198,16 @@ script returns failure or the output XML is not valid, restore of = the image will be aborted. This hook may be used, e.g., to change location of disk images for restored domains. +
  • Since 6.5.0, you can also place sev= eral + hook scripts in the directory + /etc/libvirt/hooks/qemu.d/. They are executed in + alphabetical order after main script. In this case each script also + acts as filter and can modify the domain XML and print it out on + its standart output. This script output is passed to standard input + next script in order. Empty output from any script is also identic= al + to copying the input XML without changing it. + In case any script returns failure common process will be aborted, + but all scripts from the directory will are executed.
  • Since 0.9.13, the qemu hook script is also called when the libvirtd daemon restarts and reconnects to previously running QEMU processes. If the script fails, the @@ -274,6 +291,16 @@ script returns failure or the output XML is not valid, incoming migration will be canceled. This hook may be used, e.g., to change location of disk images for incoming domains.
  • +
  • Since 6.5.0, you can also place sev= eral + hook scripts in the directory + /etc/libvirt/hooks/libxl.d/. They are executed in + alphabetical order after main script. In this case each script also + acts as filter and can modify the domain XML and print it out on + its standart output. This script output is passed to standard input + next script in order. Empty output from any script is also identic= al + to copying the input XML without changing it. + In case any script returns failure common process will be aborted, + but all scripts from the directory will are executed.
  • Since 2.1.0, the libxl hook script is also called when the libvirtd daemon restarts and reconnects to previously running Xen domains. If the script fails, the --=20 2.18.4