]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - net/sunrpc/svc.c
Merge tag 'nfs-for-5.15-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
[mirror_ubuntu-jammy-kernel.git] / net / sunrpc / svc.c
index 95836bf514b51aeaa0e14e38f03bca69d7487626..a3bbe5ce4570fb7d7cdefd7bc8c24cff00d3f5c0 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <trace/events/sunrpc.h>
 
+#include "fail.h"
+
 #define RPCDBG_FACILITY        RPCDBG_SVCDSP
 
 static void svc_unregister(const struct svc_serv *serv, struct net *net);
@@ -838,6 +840,27 @@ svc_set_num_threads_sync(struct svc_serv *serv, struct svc_pool *pool, int nrser
 }
 EXPORT_SYMBOL_GPL(svc_set_num_threads_sync);
 
+/**
+ * svc_rqst_replace_page - Replace one page in rq_pages[]
+ * @rqstp: svc_rqst with pages to replace
+ * @page: replacement page
+ *
+ * When replacing a page in rq_pages, batch the release of the
+ * replaced pages to avoid hammering the page allocator.
+ */
+void svc_rqst_replace_page(struct svc_rqst *rqstp, struct page *page)
+{
+       if (*rqstp->rq_next_page) {
+               if (!pagevec_space(&rqstp->rq_pvec))
+                       __pagevec_release(&rqstp->rq_pvec);
+               pagevec_add(&rqstp->rq_pvec, *rqstp->rq_next_page);
+       }
+
+       get_page(page);
+       *(rqstp->rq_next_page++) = page;
+}
+EXPORT_SYMBOL_GPL(svc_rqst_replace_page);
+
 /*
  * Called from a server thread as it's exiting. Caller must hold the "service
  * mutex" for the service.
@@ -1486,6 +1509,12 @@ svc_process(struct svc_rqst *rqstp)
        struct svc_serv         *serv = rqstp->rq_server;
        u32                     dir;
 
+#if IS_ENABLED(CONFIG_FAIL_SUNRPC)
+       if (!fail_sunrpc.ignore_server_disconnect &&
+           should_fail(&fail_sunrpc.attr, 1))
+               svc_xprt_deferred_close(rqstp->rq_xprt);
+#endif
+
        /*
         * Setup response xdr_buf.
         * Initially it has just one page
@@ -1612,6 +1641,21 @@ u32 svc_max_payload(const struct svc_rqst *rqstp)
 }
 EXPORT_SYMBOL_GPL(svc_max_payload);
 
+/**
+ * svc_proc_name - Return RPC procedure name in string form
+ * @rqstp: svc_rqst to operate on
+ *
+ * Return value:
+ *   Pointer to a NUL-terminated string
+ */
+const char *svc_proc_name(const struct svc_rqst *rqstp)
+{
+       if (rqstp && rqstp->rq_procinfo)
+               return rqstp->rq_procinfo->pc_name;
+       return "unknown";
+}
+
+
 /**
  * svc_encode_result_payload - mark a range of bytes as a result payload
  * @rqstp: svc_rqst to operate on