summary refs log tree commit diff stats
path: root/hw/9pfs/codir.c
diff options
context:
space:
mode:
authorChristian Schoenebeck <qemu_oss@crudebyte.com>2025-03-20 13:16:20 +0100
committerChristian Schoenebeck <qemu_oss@crudebyte.com>2025-05-05 11:28:29 +0200
commitcdafeda35709ddf8cd982a7eb653c2a5028c8074 (patch)
tree501595a3da3136a9ac157b58bfe3fd45dc5b1e2c /hw/9pfs/codir.c
parent610dc187e52605c8ea8d14c5e7d8e7384f8af290 (diff)
downloadfocaccia-qemu-cdafeda35709ddf8cd982a7eb653c2a5028c8074.tar.gz
focaccia-qemu-cdafeda35709ddf8cd982a7eb653c2a5028c8074.zip
9pfs: fix 'total_open_fd' decrementation
According to 'man 2 close' errors returned by close() should only be used
for either diagnostic purposes or for catching data loss due to a previous
write error, as an error result of close() usually indicates a deferred
error of a previous write operation.

Therefore not decrementing 'total_open_fd' on a close() error is wrong
and would yield in a higher open file descriptor count than actually the
case, leading to 9p server reclaiming open file descriptors too soon.

Based-on: <20250312152933.383967-7-groug@kaod.org>
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <E1tvEyJ-004dMa-So@kylie.crudebyte.com>
Diffstat (limited to 'hw/9pfs/codir.c')
-rw-r--r--hw/9pfs/codir.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 2068a4779d..bce7dd96e9 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -20,6 +20,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
 #include "qemu/main-loop.h"
+#include "qemu/error-report.h"
 #include "coth.h"
 #include "9p-xattr.h"
 #include "9p-util.h"
@@ -353,7 +354,11 @@ int coroutine_fn v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
                 err = -errno;
             }
         });
-    if (!err) {
+    /* 'man 2 close' suggests to ignore close() errors except of EBADF */
+    if (unlikely(err && errno == EBADF)) {
+        /* unexpected case as we should have checked for a valid file handle */
+        error_report("9pfs: WARNING: v9fs_co_closedir() failed with EBADF");
+    } else {
         total_open_fd--;
     }
     return err;