diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2015-01-21 11:04:00 -0500 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2015-01-30 10:47:49 -0500 |
commit | 9128c3e794a77917a86dd5490ca2c5233a8c6fde (patch) | |
tree | 3d71b14e21ddb2082cc700822af1e868e430f2fe /net/sunrpc/xprtrdma/verbs.c | |
parent | 1392402c405a75de1cdc658d36c6007ea1c037de (diff) |
xprtrdma: Add struct rpcrdma_regbuf and helpers
There are several spots that allocate a buffer via kmalloc (usually
contiguously with another data structure) and then register that
buffer internally. I'd like to split the buffers out of these data
structures to allow the data structures to scale.
Start by adding functions that can kmalloc and register a buffer,
and can manage/preserve the buffer's associated ib_sge and ib_mr
fields.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'net/sunrpc/xprtrdma/verbs.c')
-rw-r--r-- | net/sunrpc/xprtrdma/verbs.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 24ea6dd184e4..cdd6aacc9168 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c | |||
@@ -1828,6 +1828,61 @@ rpcrdma_deregister_internal(struct rpcrdma_ia *ia, | |||
1828 | return rc; | 1828 | return rc; |
1829 | } | 1829 | } |
1830 | 1830 | ||
1831 | /** | ||
1832 | * rpcrdma_alloc_regbuf - kmalloc and register memory for SEND/RECV buffers | ||
1833 | * @ia: controlling rpcrdma_ia | ||
1834 | * @size: size of buffer to be allocated, in bytes | ||
1835 | * @flags: GFP flags | ||
1836 | * | ||
1837 | * Returns pointer to private header of an area of internally | ||
1838 | * registered memory, or an ERR_PTR. The registered buffer follows | ||
1839 | * the end of the private header. | ||
1840 | * | ||
1841 | * xprtrdma uses a regbuf for posting an outgoing RDMA SEND, or for | ||
1842 | * receiving the payload of RDMA RECV operations. regbufs are not | ||
1843 | * used for RDMA READ/WRITE operations, thus are registered only for | ||
1844 | * LOCAL access. | ||
1845 | */ | ||
1846 | struct rpcrdma_regbuf * | ||
1847 | rpcrdma_alloc_regbuf(struct rpcrdma_ia *ia, size_t size, gfp_t flags) | ||
1848 | { | ||
1849 | struct rpcrdma_regbuf *rb; | ||
1850 | int rc; | ||
1851 | |||
1852 | rc = -ENOMEM; | ||
1853 | rb = kmalloc(sizeof(*rb) + size, flags); | ||
1854 | if (rb == NULL) | ||
1855 | goto out; | ||
1856 | |||
1857 | rb->rg_size = size; | ||
1858 | rb->rg_owner = NULL; | ||
1859 | rc = rpcrdma_register_internal(ia, rb->rg_base, size, | ||
1860 | &rb->rg_mr, &rb->rg_iov); | ||
1861 | if (rc) | ||
1862 | goto out_free; | ||
1863 | |||
1864 | return rb; | ||
1865 | |||
1866 | out_free: | ||
1867 | kfree(rb); | ||
1868 | out: | ||
1869 | return ERR_PTR(rc); | ||
1870 | } | ||
1871 | |||
1872 | /** | ||
1873 | * rpcrdma_free_regbuf - deregister and free registered buffer | ||
1874 | * @ia: controlling rpcrdma_ia | ||
1875 | * @rb: regbuf to be deregistered and freed | ||
1876 | */ | ||
1877 | void | ||
1878 | rpcrdma_free_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb) | ||
1879 | { | ||
1880 | if (rb) { | ||
1881 | rpcrdma_deregister_internal(ia, rb->rg_mr, &rb->rg_iov); | ||
1882 | kfree(rb); | ||
1883 | } | ||
1884 | } | ||
1885 | |||
1831 | /* | 1886 | /* |
1832 | * Wrappers for chunk registration, shared by read/write chunk code. | 1887 | * Wrappers for chunk registration, shared by read/write chunk code. |
1833 | */ | 1888 | */ |