[libvirt PATCH] qemu: remove pointless qemuDomainLogContextMode

Ján Tomko posted 1 patch 8 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/c686d70b4e8994d4872fba7e02d73c38a1849db4.1692188669.git.jtomko@redhat.com
src/qemu/qemu_domain.c  | 26 +++++++++++---------------
src/qemu/qemu_domain.h  |  9 +--------
src/qemu/qemu_process.c |  3 +--
3 files changed, 13 insertions(+), 25 deletions(-)
[libvirt PATCH] qemu: remove pointless qemuDomainLogContextMode
Posted by Ján Tomko 8 months, 3 weeks ago
Since its introduction in 4d1b771fbb610537b7425e649a490143588b8ed3
it has only been used to differentiate between START and non-START.

Last use of QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH was removed by:

  commit f709377301b919a9fcbfc366e33057f7848bee28
    qemu: Fix qemuDomainObjTaint with virtlogd

QEMU_DOMAIN_LOG_CONTEXT_MODE_STOP is unused since:

  commit cf3ea0769c54a328733bcb0cd27f546e70090c89
    qemu: process: Append the "shutting down" message using the new APIs

Now, the only caller passes QEMU_DOMAIN_LOG_CONTEXT_MODE_START.
Assume that's always the case and remove the 'mode' argument.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_domain.c  | 26 +++++++++++---------------
 src/qemu/qemu_domain.h  |  9 +--------
 src/qemu/qemu_process.c |  3 +--
 3 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 029238a9d7..1269636ce1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7075,8 +7075,7 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
 
 
 qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver,
-                                                virDomainObj *vm,
-                                                qemuDomainLogContextMode mode)
+                                              virDomainObj *vm)
 {
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     qemuDomainLogContext *ctxt = QEMU_DOMAIN_LOG_CONTEXT(g_object_new(QEMU_TYPE_DOMAIN_LOG_CONTEXT, NULL));
@@ -7117,25 +7116,22 @@ qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver,
         /* For unprivileged startup we must truncate the file since
          * we can't rely on logrotate. We don't use O_TRUNC since
          * it is better for SELinux policy if we truncate afterwards */
-        if (mode == QEMU_DOMAIN_LOG_CONTEXT_MODE_START &&
-            !driver->privileged &&
+        if (!driver->privileged &&
             ftruncate(ctxt->writefd, 0) < 0) {
             virReportSystemError(errno, _("failed to truncate %1$s"),
                                  ctxt->path);
             goto error;
         }
 
-        if (mode == QEMU_DOMAIN_LOG_CONTEXT_MODE_START) {
-            if ((ctxt->readfd = open(ctxt->path, O_RDONLY)) < 0) {
-                virReportSystemError(errno, _("failed to open logfile %1$s"),
-                                     ctxt->path);
-                goto error;
-            }
-            if (virSetCloseExec(ctxt->readfd) < 0) {
-                virReportSystemError(errno, _("failed to set close-on-exec flag on %1$s"),
-                                     ctxt->path);
-                goto error;
-            }
+        if ((ctxt->readfd = open(ctxt->path, O_RDONLY)) < 0) {
+            virReportSystemError(errno, _("failed to open logfile %1$s"),
+                                 ctxt->path);
+            goto error;
+        }
+        if (virSetCloseExec(ctxt->readfd) < 0) {
+            virReportSystemError(errno, _("failed to set close-on-exec flag on %1$s"),
+                                 ctxt->path);
+            goto error;
         }
 
         if ((ctxt->pos = lseek(ctxt->writefd, 0, SEEK_END)) < 0) {
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 999190e381..5f42e11428 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -652,15 +652,8 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
                                 virDomainNetDef *net,
                                 qemuDomainLogContext *logCtxt);
 
-typedef enum {
-    QEMU_DOMAIN_LOG_CONTEXT_MODE_START,
-    QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH,
-    QEMU_DOMAIN_LOG_CONTEXT_MODE_STOP,
-} qemuDomainLogContextMode;
-
 qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver,
-                                                virDomainObj *vm,
-                                                qemuDomainLogContextMode mode);
+                                              virDomainObj *vm);
 int qemuDomainLogContextWrite(qemuDomainLogContext *ctxt,
                               const char *fmt, ...) G_GNUC_PRINTF(2, 3);
 ssize_t qemuDomainLogContextRead(qemuDomainLogContext *ctxt,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0644f80161..63be899bf1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7612,8 +7612,7 @@ qemuProcessLaunch(virConnectPtr conn,
     hookData.cfg = cfg;
 
     VIR_DEBUG("Creating domain log file");
-    if (!(logCtxt = qemuDomainLogContextNew(driver, vm,
-                                            QEMU_DOMAIN_LOG_CONTEXT_MODE_START))) {
+    if (!(logCtxt = qemuDomainLogContextNew(driver, vm))) {
         virLastErrorPrefixMessage("%s", _("can't connect to virtlogd"));
         goto cleanup;
     }
-- 
2.41.0

Re: [libvirt PATCH] qemu: remove pointless qemuDomainLogContextMode
Posted by Michal Prívozník 8 months, 2 weeks ago
On 8/16/23 14:24, Ján Tomko wrote:
> Since its introduction in 4d1b771fbb610537b7425e649a490143588b8ed3
> it has only been used to differentiate between START and non-START.
> 
> Last use of QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH was removed by:
> 
>   commit f709377301b919a9fcbfc366e33057f7848bee28
>     qemu: Fix qemuDomainObjTaint with virtlogd
> 
> QEMU_DOMAIN_LOG_CONTEXT_MODE_STOP is unused since:
> 
>   commit cf3ea0769c54a328733bcb0cd27f546e70090c89
>     qemu: process: Append the "shutting down" message using the new APIs
> 
> Now, the only caller passes QEMU_DOMAIN_LOG_CONTEXT_MODE_START.
> Assume that's always the case and remove the 'mode' argument.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  src/qemu/qemu_domain.c  | 26 +++++++++++---------------
>  src/qemu/qemu_domain.h  |  9 +--------
>  src/qemu/qemu_process.c |  3 +--
>  3 files changed, 13 insertions(+), 25 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal