Commit 436960c9 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/berrange/tags/filemon-next-pull-request' into staging



filemon: various fixes / improvements to file monitor for USB MTP

Ensure watch IDs unique within a monitor and avoid integer wraparound
issues when many watches are set & unset over time.

# gpg: Signature made Tue 02 Apr 2019 13:53:40 BST
# gpg:                using RSA key BE86EBB415104FDF
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full]
# gpg:                 aka "Daniel P. Berrange <berrange@redhat.com>" [full]
# Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E  8E3F BE86 EBB4 1510 4FDF

* remotes/berrange/tags/filemon-next-pull-request:
  filemon: fix watch IDs to avoid potential wraparound issues
  filemon: ensure watch IDs are unique to QFileMonitor scope
  tests: refactor file monitor test to make it more understandable

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 9a363f0b b4682a63
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ qauthz_list_file_load(QAuthZListFile *fauthz, Error **errp)


static void
qauthz_list_file_event(int wd G_GNUC_UNUSED,
qauthz_list_file_event(int64_t wd G_GNUC_UNUSED,
                       QFileMonitorEvent ev G_GNUC_UNUSED,
                       const char *name G_GNUC_UNUSED,
                       void *opaque)
+5 −5
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ struct MTPObject {
    char         *path;
    struct stat  stat;
    /* file monitor watch id */
    int          watchid;
    int64_t      watchid;
    MTPObject    *parent;
    uint32_t     nchildren;
    QLIST_HEAD(, MTPObject) children;
@@ -498,7 +498,7 @@ static MTPObject *usb_mtp_object_lookup_name(MTPObject *parent,
    return NULL;
}

static MTPObject *usb_mtp_object_lookup_id(MTPState *s, int id)
static MTPObject *usb_mtp_object_lookup_id(MTPState *s, int64_t id)
{
    MTPObject *iter;

@@ -511,7 +511,7 @@ static MTPObject *usb_mtp_object_lookup_id(MTPState *s, int id)
    return NULL;
}

static void file_monitor_event(int id,
static void file_monitor_event(int64_t id,
                               QFileMonitorEvent ev,
                               const char *name,
                               void *opaque)
@@ -625,7 +625,7 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o)
    }

    if (s->file_monitor) {
        int id = qemu_file_monitor_add_watch(s->file_monitor, o->path, NULL,
        int64_t id = qemu_file_monitor_add_watch(s->file_monitor, o->path, NULL,
                                                 file_monitor_event, s, &err);
        if (id == -1) {
            error_report("usb-mtp: failed to add watch for %s: %s", o->path,
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ struct QAuthZListFile {
    char *filename;
    bool refresh;
    QFileMonitor *file_monitor;
    int file_watch;
    int64_t file_watch;
};


+8 −8
Original line number Diff line number Diff line
@@ -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,7 +103,7 @@ 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,
int64_t qemu_file_monitor_add_watch(QFileMonitor *mon,
                                    const char *dirpath,
                                    const char *filename,
                                    QFileMonitorHandler cb,
@@ -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 */
+323 −327

File changed.

Preview size limit exceeded, changes collapsed.

Loading