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