b4682a63f8
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>
60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
/*
|
|
* QEMU file monitor stub impl
|
|
*
|
|
* Copyright (c) 2018 Red Hat, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/filemonitor.h"
|
|
#include "qemu/error-report.h"
|
|
#include "qapi/error.h"
|
|
|
|
|
|
QFileMonitor *
|
|
qemu_file_monitor_new(Error **errp)
|
|
{
|
|
error_setg(errp, "File monitoring not available on this platform");
|
|
return NULL;
|
|
}
|
|
|
|
|
|
void
|
|
qemu_file_monitor_free(QFileMonitor *mon G_GNUC_UNUSED)
|
|
{
|
|
}
|
|
|
|
|
|
int64_t
|
|
qemu_file_monitor_add_watch(QFileMonitor *mon G_GNUC_UNUSED,
|
|
const char *dirpath G_GNUC_UNUSED,
|
|
const char *filename G_GNUC_UNUSED,
|
|
QFileMonitorHandler cb G_GNUC_UNUSED,
|
|
void *opaque G_GNUC_UNUSED,
|
|
Error **errp)
|
|
{
|
|
error_setg(errp, "File monitoring not available on this platform");
|
|
return -1;
|
|
}
|
|
|
|
|
|
void
|
|
qemu_file_monitor_remove_watch(QFileMonitor *mon G_GNUC_UNUSED,
|
|
const char *dirpath G_GNUC_UNUSED,
|
|
int64_t id G_GNUC_UNUSED)
|
|
{
|
|
}
|