[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 01/17] util: add helper APIs for dealing with
From: |
Bandan Das |
Subject: |
Re: [Qemu-devel] [PATCH v4 01/17] util: add helper APIs for dealing with inotify in portable manner |
Date: |
Tue, 12 Mar 2019 19:07:42 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Daniel P. Berrangé <address@hidden> writes:
...
> +
> +int
> +qemu_file_monitor_add_watch(QFileMonitor *mon,
> + const char *dirpath,
> + const char *filename,
> + QFileMonitorHandler cb,
> + void *opaque,
> + Error **errp)
> +{
> + QFileMonitorDir *dir;
> + QFileMonitorWatch watch;
> + int ret = -1;
> +
> + qemu_mutex_lock(&mon->lock);
> + dir = g_hash_table_lookup(mon->dirs, dirpath);
> + if (!dir) {
> + int rv = inotify_add_watch(mon->fd, dirpath,
> + IN_CREATE | IN_DELETE | IN_MODIFY |
> + IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB);
> +
> + if (rv < 0) {
> + error_setg_errno(errp, errno, "Unable to watch '%s'", dirpath);
> + goto cleanup;
> + }
> +
> + trace_qemu_file_monitor_enable_watch(mon, dirpath, rv);
> +
> + dir = g_new0(QFileMonitorDir, 1);
> + dir->path = g_strdup(dirpath);
> + dir->id = rv;
> + dir->watches = g_array_new(FALSE, TRUE, sizeof(QFileMonitorWatch));
> +
> + g_hash_table_insert(mon->dirs, dir->path, dir);
> + g_hash_table_insert(mon->idmap, GINT_TO_POINTER(rv), dir);
> +
> + if (g_hash_table_size(mon->dirs) == 1) {
> + qemu_set_fd_handler(mon->fd, qemu_file_monitor_watch, NULL, mon);
> + }
> + }
> +
> + watch.id = dir->nextid++;
> + watch.filename = g_strdup(filename);
> + watch.cb = cb;
> + watch.opaque = opaque;
> +
> + g_array_append_val(dir->watches, watch);
> +
> + trace_qemu_file_monitor_add_watch(mon, dirpath,
> + filename ? filename : "<none>",
> + cb, opaque, watch.id);
> +
> + ret = watch.id;
> +
This seems to break usb-mtp since we are returning watch.id.
Why are we not returning dir->id here ? usb-mtp relies on the watch
descriptor to handle events.
Bandan
> + cleanup:
> + qemu_mutex_unlock(&mon->lock);
> + return ret;
> +}
> +
- Re: [Qemu-devel] [PATCH v4 01/17] util: add helper APIs for dealing with inotify in portable manner,
Bandan Das <=