mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 02:54:58 -06:00
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>
This commit is contained in:
parent
610dc187e5
commit
cdafeda357
3 changed files with 21 additions and 3 deletions
10
hw/9pfs/9p.c
10
hw/9pfs/9p.c
|
@ -510,7 +510,15 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu)
|
||||||
err = (f->fid_type == P9_FID_DIR) ?
|
err = (f->fid_type == P9_FID_DIR) ?
|
||||||
s->ops->closedir(&s->ctx, &f->fs_reclaim) :
|
s->ops->closedir(&s->ctx, &f->fs_reclaim) :
|
||||||
s->ops->close(&s->ctx, &f->fs_reclaim);
|
s->ops->close(&s->ctx, &f->fs_reclaim);
|
||||||
if (!err) {
|
|
||||||
|
/* 'man 2 close' suggests to ignore close() errors except of EBADF */
|
||||||
|
if (unlikely(err && errno == EBADF)) {
|
||||||
|
/*
|
||||||
|
* unexpected case as FIDs were picked above by having a valid
|
||||||
|
* file descriptor
|
||||||
|
*/
|
||||||
|
error_report("9pfs: v9fs_reclaim_fd() WARNING: close() failed with EBADF");
|
||||||
|
} else {
|
||||||
/* total_open_fd must only be mutated on main thread */
|
/* total_open_fd must only be mutated on main thread */
|
||||||
nclosed++;
|
nclosed++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "fsdev/qemu-fsdev.h"
|
#include "fsdev/qemu-fsdev.h"
|
||||||
#include "qemu/thread.h"
|
#include "qemu/thread.h"
|
||||||
#include "qemu/main-loop.h"
|
#include "qemu/main-loop.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
#include "coth.h"
|
#include "coth.h"
|
||||||
#include "9p-xattr.h"
|
#include "9p-xattr.h"
|
||||||
#include "9p-util.h"
|
#include "9p-util.h"
|
||||||
|
@ -353,7 +354,11 @@ int coroutine_fn v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
|
||||||
err = -errno;
|
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--;
|
total_open_fd--;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "fsdev/qemu-fsdev.h"
|
#include "fsdev/qemu-fsdev.h"
|
||||||
#include "qemu/thread.h"
|
#include "qemu/thread.h"
|
||||||
#include "qemu/main-loop.h"
|
#include "qemu/main-loop.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
#include "coth.h"
|
#include "coth.h"
|
||||||
|
|
||||||
int coroutine_fn v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
|
int coroutine_fn v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
|
||||||
|
@ -197,7 +198,11 @@ int coroutine_fn v9fs_co_close(V9fsPDU *pdu, V9fsFidOpenState *fs)
|
||||||
err = -errno;
|
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_close() failed with EBADF");
|
||||||
|
} else {
|
||||||
total_open_fd--;
|
total_open_fd--;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue