yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtiofsd-remove-unused-notify-reply-support.patch

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