Irqbalance / irqbalance

The irqbalance source tree - The new official site for irqbalance
http://irqbalance.github.io/irqbalance/
GNU General Public License v2.0
576 stars 139 forks source link

Fclose needs flushing after writing to file. #301

Closed rmalz-c closed 6 months ago

rmalz-c commented 6 months ago

fclose can randomy return error if no flush was performed after write. Patch below (don't have access to open PR)


Date:   Thu Mar 14 13:36:15 2024 +0100

    Flush file before closing

    After writing to file, before closing, flush is required.
    Without it fclose can randomly return IO error.

    Signed-off-by: Robert Malz <robert.malz@canonical.com>

diff --git a/activate.c b/activate.c
index d3f99f7..e30d0f0 100644
--- a/activate.c
+++ b/activate.c
@@ -82,6 +82,7 @@ static void activate_mapping(struct irq_info *info, void *data __attribute__((un
        cpumask_scnprintf(buf, PATH_MAX, applied_mask);
        ret = fprintf(file, "%s", buf);
        errsave = errno;
+       fflush(file);
        if (fclose(file)) {
                errsave = errno;
                goto error;`
rmalz-c commented 6 months ago

Tested locally on 6.8.0-11-generic (Ubuntu, Noble) irqbalance could return following error: Mar 14 11:59:45 pre-noble systemd[1]: Started irqbalance.service - irqbalance daemon. Mar 14 11:59:45 pre-noble (qbalance)[1536]: irqbalance.service: Referenced but unset environment variable evaluates to an empty string: IRQBALANCE_ARGS Mar 14 11:59:55 pre-noble irqbalance[1536]: Cannot change IRQ 27 affinity: Input/output error Mar 14 11:59:55 pre-noble irqbalance[1536]: IRQ 27 affinity is now unmanaged

After adding flush issue is no longer reproducible

nhorman commented 6 months ago

open a PR please

rmalz-c commented 6 months ago

done: https://github.com/Irqbalance/irqbalance/pull/302

rmalz-c commented 6 months ago

Fixed with https://github.com/Irqbalance/irqbalance/pull/302