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