netfs: Allow the netfs to make the io (sub)request alloc larger
authorDavid Howells <dhowells@redhat.com>
Wed, 9 Mar 2022 11:01:12 +0000 (11:01 +0000)
committerDavid Howells <dhowells@redhat.com>
Sun, 24 Dec 2023 15:08:50 +0000 (15:08 +0000)
Allow the network filesystem to specify extra space to be allocated on the
end of the io (sub)request.  This allows cifs, for example, to use this
space rather than allocating its own cifs_readdata struct.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org

fs/netfs/objects.c
include/linux/netfs.h

index 85f428fc52e6fb33db3f28136c16332ffa2ab12d..c4229c5f3f5409060da4e3e86b923628f3d6f3b2 100644 (file)
@@ -22,7 +22,8 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
        struct netfs_io_request *rreq;
        int ret;
 
-       rreq = kzalloc(sizeof(struct netfs_io_request), GFP_KERNEL);
+       rreq = kzalloc(ctx->ops->io_request_size ?: sizeof(struct netfs_io_request),
+                      GFP_KERNEL);
        if (!rreq)
                return ERR_PTR(-ENOMEM);
 
@@ -114,7 +115,9 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq
 {
        struct netfs_io_subrequest *subreq;
 
-       subreq = kzalloc(sizeof(struct netfs_io_subrequest), GFP_KERNEL);
+       subreq = kzalloc(rreq->netfs_ops->io_subrequest_size ?:
+                        sizeof(struct netfs_io_subrequest),
+                        GFP_KERNEL);
        if (subreq) {
                INIT_LIST_HEAD(&subreq->rreq_link);
                refcount_set(&subreq->ref, 2);
index 7244ddebd974cc3d30c0bf6031f5fa7eeb0316ac..d6f27000eeb0711a7e7cc839d6e30ae7ed49f41b 100644 (file)
@@ -210,6 +210,8 @@ struct netfs_io_request {
  * Operations the network filesystem can/must provide to the helpers.
  */
 struct netfs_request_ops {
+       unsigned int    io_request_size;        /* Alloc size for netfs_io_request struct */
+       unsigned int    io_subrequest_size;     /* Alloc size for netfs_io_subrequest struct */
        int (*init_request)(struct netfs_io_request *rreq, struct file *file);
        void (*free_request)(struct netfs_io_request *rreq);