diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2019-03-19 15:47:47 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2019-04-02 13:52:02 +0100 |
commit | b4682a63f86ed81abcaa543ea6135e17f9e99d01 (patch) | |
tree | b5096dd2bc5394a56e9eeb3fee0cd268201b60e4 /include | |
parent | ff3dc8fefe953fd3650279e064bf63b212c5699a (diff) |
filemon: fix watch IDs to avoid potential wraparound issues
Watch IDs are allocated from incrementing a int counter against
the QFileMonitor object. In very long life QEMU processes with
a huge amount of USB MTP activity creating & deleting directories
it is just about conceivable that the int counter can wrap
around. This would result in incorrect behaviour of the file
monitor watch APIs due to clashing watch IDs.
Instead of trying to detect this situation, this patch changes
the way watch IDs are allocated. It is turned into an int64_t
variable where the high 32 bits are set from the underlying
inotify "int" ID. This gives an ID that is guaranteed unique
for the directory as a whole, and we can rely on the kernel
to enforce this. QFileMonitor then sets the low 32 bits from
a per-directory counter.
The USB MTP device only sets watches on the directory as a
whole, not files within, so there is no risk of guest
triggered wrap around on the low 32 bits.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/authz/listfile.h | 2 | ||||
-rw-r--r-- | include/qemu/filemonitor.h | 16 |
2 files changed, 9 insertions, 9 deletions
diff --git a/include/authz/listfile.h b/include/authz/listfile.h index ebbd5a4288..0d618c903c 100644 --- a/include/authz/listfile.h +++ b/include/authz/listfile.h @@ -92,7 +92,7 @@ struct QAuthZListFile { char *filename; bool refresh; QFileMonitor *file_monitor; - int file_watch; + int64_t file_watch; }; diff --git a/include/qemu/filemonitor.h b/include/qemu/filemonitor.h index cd031832ed..64267d09b2 100644 --- a/include/qemu/filemonitor.h +++ b/include/qemu/filemonitor.h @@ -52,7 +52,7 @@ typedef enum { * empty. * */ -typedef void (*QFileMonitorHandler)(int id, +typedef void (*QFileMonitorHandler)(int64_t id, QFileMonitorEvent event, const char *filename, void *opaque); @@ -103,12 +103,12 @@ void qemu_file_monitor_free(QFileMonitor *mon); * * Returns: a positive integer watch ID, or -1 on error */ -int qemu_file_monitor_add_watch(QFileMonitor *mon, - const char *dirpath, - const char *filename, - QFileMonitorHandler cb, - void *opaque, - Error **errp); +int64_t qemu_file_monitor_add_watch(QFileMonitor *mon, + const char *dirpath, + const char *filename, + QFileMonitorHandler cb, + void *opaque, + Error **errp); /** * qemu_file_monitor_remove_watch: @@ -123,6 +123,6 @@ int qemu_file_monitor_add_watch(QFileMonitor *mon, */ void qemu_file_monitor_remove_watch(QFileMonitor *mon, const char *dirpath, - int id); + int64_t id); #endif /* QEMU_FILE_MONITOR_H */ |