dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0018-virtiofsd-remove-unused-notify-reply-support.patch

1d442b
From: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:00:47 +0000
1d442b
Subject: [PATCH] virtiofsd: remove unused notify reply support
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
Notify reply support is unused by virtiofsd.  The code would need to be
1d442b
updated to validate input buffer sizes.  Remove this unused code since
1d442b
changes to it are untestable.
1d442b
1d442b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 64c6f408a29ef03e9b8da9f5a5d8fd511b0d801e)
1d442b
---
1d442b
 tools/virtiofsd/fuse_lowlevel.c | 147 +-------------------------------
1d442b
 tools/virtiofsd/fuse_lowlevel.h |  47 ----------
1d442b
 2 files changed, 1 insertion(+), 193 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
1d442b
index 2f32c68161..eb0ec49d38 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.c
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.c
1d442b
@@ -31,12 +31,6 @@
1d442b
 #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
1d442b
 #define OFFSET_MAX 0x7fffffffffffffffLL
1d442b
 
1d442b
-#define container_of(ptr, type, member)                    \
1d442b
-    ({                                                     \
1d442b
-        const typeof(((type *)0)->member) *__mptr = (ptr); \
1d442b
-        (type *)((char *)__mptr - offsetof(type, member)); \
1d442b
-    })
1d442b
-
1d442b
 struct fuse_pollhandle {
1d442b
     uint64_t kh;
1d442b
     struct fuse_session *se;
1d442b
@@ -1862,52 +1856,6 @@ static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1d442b
     send_reply_ok(req, NULL, 0);
1d442b
 }
1d442b
 
1d442b
-static void list_del_nreq(struct fuse_notify_req *nreq)
1d442b
-{
1d442b
-    struct fuse_notify_req *prev = nreq->prev;
1d442b
-    struct fuse_notify_req *next = nreq->next;
1d442b
-    prev->next = next;
1d442b
-    next->prev = prev;
1d442b
-}
1d442b
-
1d442b
-static void list_add_nreq(struct fuse_notify_req *nreq,
1d442b
-                          struct fuse_notify_req *next)
1d442b
-{
1d442b
-    struct fuse_notify_req *prev = next->prev;
1d442b
-    nreq->next = next;
1d442b
-    nreq->prev = prev;
1d442b
-    prev->next = nreq;
1d442b
-    next->prev = nreq;
1d442b
-}
1d442b
-
1d442b
-static void list_init_nreq(struct fuse_notify_req *nreq)
1d442b
-{
1d442b
-    nreq->next = nreq;
1d442b
-    nreq->prev = nreq;
1d442b
-}
1d442b
-
1d442b
-static void do_notify_reply(fuse_req_t req, fuse_ino_t nodeid,
1d442b
-                            const void *inarg, const struct fuse_buf *buf)
1d442b
-{
1d442b
-    struct fuse_session *se = req->se;
1d442b
-    struct fuse_notify_req *nreq;
1d442b
-    struct fuse_notify_req *head;
1d442b
-
1d442b
-    pthread_mutex_lock(&se->lock);
1d442b
-    head = &se->notify_list;
1d442b
-    for (nreq = head->next; nreq != head; nreq = nreq->next) {
1d442b
-        if (nreq->unique == req->unique) {
1d442b
-            list_del_nreq(nreq);
1d442b
-            break;
1d442b
-        }
1d442b
-    }
1d442b
-    pthread_mutex_unlock(&se->lock);
1d442b
-
1d442b
-    if (nreq != head) {
1d442b
-        nreq->reply(nreq, req, nodeid, inarg, buf);
1d442b
-    }
1d442b
-}
1d442b
-
1d442b
 static int send_notify_iov(struct fuse_session *se, int notify_code,
1d442b
                            struct iovec *iov, int count)
1d442b
 {
1d442b
@@ -2059,95 +2007,6 @@ int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1d442b
     return res;
1d442b
 }
1d442b
 
1d442b
-struct fuse_retrieve_req {
1d442b
-    struct fuse_notify_req nreq;
1d442b
-    void *cookie;
1d442b
-};
1d442b
-
1d442b
-static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq, fuse_req_t req,
1d442b
-                                   fuse_ino_t ino, const void *inarg,
1d442b
-                                   const struct fuse_buf *ibuf)
1d442b
-{
1d442b
-    struct fuse_session *se = req->se;
1d442b
-    struct fuse_retrieve_req *rreq =
1d442b
-        container_of(nreq, struct fuse_retrieve_req, nreq);
1d442b
-    const struct fuse_notify_retrieve_in *arg = inarg;
1d442b
-    struct fuse_bufvec bufv = {
1d442b
-        .buf[0] = *ibuf,
1d442b
-        .count = 1,
1d442b
-    };
1d442b
-
1d442b
-    if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD)) {
1d442b
-        bufv.buf[0].mem = PARAM(arg);
1d442b
-    }
1d442b
-
1d442b
-    bufv.buf[0].size -=
1d442b
-        sizeof(struct fuse_in_header) + sizeof(struct fuse_notify_retrieve_in);
1d442b
-
1d442b
-    if (bufv.buf[0].size < arg->size) {
1d442b
-        fuse_log(FUSE_LOG_ERR, "fuse: retrieve reply: buffer size too small\n");
1d442b
-        fuse_reply_none(req);
1d442b
-        goto out;
1d442b
-    }
1d442b
-    bufv.buf[0].size = arg->size;
1d442b
-
1d442b
-    if (se->op.retrieve_reply) {
1d442b
-        se->op.retrieve_reply(req, rreq->cookie, ino, arg->offset, &bufv);
1d442b
-    } else {
1d442b
-        fuse_reply_none(req);
1d442b
-    }
1d442b
-out:
1d442b
-    free(rreq);
1d442b
-}
1d442b
-
1d442b
-int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1d442b
-                                  size_t size, off_t offset, void *cookie)
1d442b
-{
1d442b
-    struct fuse_notify_retrieve_out outarg;
1d442b
-    struct iovec iov[2];
1d442b
-    struct fuse_retrieve_req *rreq;
1d442b
-    int err;
1d442b
-
1d442b
-    if (!se) {
1d442b
-        return -EINVAL;
1d442b
-    }
1d442b
-
1d442b
-    if (se->conn.proto_major < 6 || se->conn.proto_minor < 15) {
1d442b
-        return -ENOSYS;
1d442b
-    }
1d442b
-
1d442b
-    rreq = malloc(sizeof(*rreq));
1d442b
-    if (rreq == NULL) {
1d442b
-        return -ENOMEM;
1d442b
-    }
1d442b
-
1d442b
-    pthread_mutex_lock(&se->lock);
1d442b
-    rreq->cookie = cookie;
1d442b
-    rreq->nreq.unique = se->notify_ctr++;
1d442b
-    rreq->nreq.reply = fuse_ll_retrieve_reply;
1d442b
-    list_add_nreq(&rreq->nreq, &se->notify_list);
1d442b
-    pthread_mutex_unlock(&se->lock);
1d442b
-
1d442b
-    outarg.notify_unique = rreq->nreq.unique;
1d442b
-    outarg.nodeid = ino;
1d442b
-    outarg.offset = offset;
1d442b
-    outarg.size = size;
1d442b
-    outarg.padding = 0;
1d442b
-
1d442b
-    iov[1].iov_base = &outarg;
1d442b
-    iov[1].iov_len = sizeof(outarg);
1d442b
-
1d442b
-    err = send_notify_iov(se, FUSE_NOTIFY_RETRIEVE, iov, 2);
1d442b
-    if (err) {
1d442b
-        pthread_mutex_lock(&se->lock);
1d442b
-        list_del_nreq(&rreq->nreq);
1d442b
-        pthread_mutex_unlock(&se->lock);
1d442b
-        free(rreq);
1d442b
-    }
1d442b
-
1d442b
-    return err;
1d442b
-}
1d442b
-
1d442b
 void *fuse_req_userdata(fuse_req_t req)
1d442b
 {
1d442b
     return req->se->userdata;
1d442b
@@ -2226,7 +2085,7 @@ static struct {
1d442b
     [FUSE_POLL] = { do_poll, "POLL" },
1d442b
     [FUSE_FALLOCATE] = { do_fallocate, "FALLOCATE" },
1d442b
     [FUSE_DESTROY] = { do_destroy, "DESTROY" },
1d442b
-    [FUSE_NOTIFY_REPLY] = { (void *)1, "NOTIFY_REPLY" },
1d442b
+    [FUSE_NOTIFY_REPLY] = { NULL, "NOTIFY_REPLY" },
1d442b
     [FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" },
1d442b
     [FUSE_READDIRPLUS] = { do_readdirplus, "READDIRPLUS" },
1d442b
     [FUSE_RENAME2] = { do_rename2, "RENAME2" },
1d442b
@@ -2333,8 +2192,6 @@ void fuse_session_process_buf_int(struct fuse_session *se,
1d442b
     inarg = (void *)&in[1];
1d442b
     if (in->opcode == FUSE_WRITE && se->op.write_buf) {
1d442b
         do_write_buf(req, in->nodeid, inarg, buf);
1d442b
-    } else if (in->opcode == FUSE_NOTIFY_REPLY) {
1d442b
-        do_notify_reply(req, in->nodeid, inarg, buf);
1d442b
     } else {
1d442b
         fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
1d442b
     }
1d442b
@@ -2437,8 +2294,6 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
1d442b
 
1d442b
     list_init_req(&se->list);
1d442b
     list_init_req(&se->interrupts);
1d442b
-    list_init_nreq(&se->notify_list);
1d442b
-    se->notify_ctr = 1;
1d442b
     fuse_mutex_init(&se->lock);
1d442b
 
1d442b
     memcpy(&se->op, op, op_size);
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowlevel.h
1d442b
index 8d8909b35d..12a84b460f 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.h
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.h
1d442b
@@ -1084,21 +1084,6 @@ struct fuse_lowlevel_ops {
1d442b
     void (*write_buf)(fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv,
1d442b
                       off_t off, struct fuse_file_info *fi);
1d442b
 
1d442b
-    /**
1d442b
-     * Callback function for the retrieve request
1d442b
-     *
1d442b
-     * Valid replies:
1d442b
-     *  fuse_reply_none
1d442b
-     *
1d442b
-     * @param req request handle
1d442b
-     * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
1d442b
-     * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
1d442b
-     * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
1d442b
-     * @param bufv the buffer containing the returned data
1d442b
-     */
1d442b
-    void (*retrieve_reply)(fuse_req_t req, void *cookie, fuse_ino_t ino,
1d442b
-                           off_t offset, struct fuse_bufvec *bufv);
1d442b
-
1d442b
     /**
1d442b
      * Forget about multiple inodes
1d442b
      *
1d442b
@@ -1726,38 +1711,6 @@ int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent,
1d442b
 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1d442b
                                off_t offset, struct fuse_bufvec *bufv,
1d442b
                                enum fuse_buf_copy_flags flags);
1d442b
-/**
1d442b
- * Retrieve data from the kernel buffers
1d442b
- *
1d442b
- * Retrieve data in the kernel buffers belonging to the given inode.
1d442b
- * If successful then the retrieve_reply() method will be called with
1d442b
- * the returned data.
1d442b
- *
1d442b
- * Only present pages are returned in the retrieve reply.  Retrieving
1d442b
- * stops when it finds a non-present page and only data prior to that
1d442b
- * is returned.
1d442b
- *
1d442b
- * If this function returns an error, then the retrieve will not be
1d442b
- * completed and no reply will be sent.
1d442b
- *
1d442b
- * This function doesn't change the dirty state of pages in the kernel
1d442b
- * buffer.  For dirty pages the write() method will be called
1d442b
- * regardless of having been retrieved previously.
1d442b
- *
1d442b
- * Added in FUSE protocol version 7.15. If the kernel does not support
1d442b
- * this (or a newer) version, the function will return -ENOSYS and do
1d442b
- * nothing.
1d442b
- *
1d442b
- * @param se the session object
1d442b
- * @param ino the inode number
1d442b
- * @param size the number of bytes to retrieve
1d442b
- * @param offset the starting offset into the file to retrieve from
1d442b
- * @param cookie user data to supply to the reply callback
1d442b
- * @return zero for success, -errno for failure
1d442b
- */
1d442b
-int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1d442b
-                                  size_t size, off_t offset, void *cookie);
1d442b
-
1d442b
 
1d442b
 /*
1d442b
  * Utility functions