#include <linux/ceph/ceph_debug.h>

#include <linux/module.h>
#include <linux/slab.h>

#include <linux/ceph/buffer.h>
#include <linux/ceph/decode.h>
#include <linux/ceph/libceph.h> /* for ceph_kvmalloc */

struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
{
	struct ceph_buffer *b;

	b = kmalloc(sizeof(*b), gfp);
	if (!b)
		return NULL;

	b->vec.iov_base = ceph_kvmalloc(len, gfp);
	if (!b->vec.iov_base) {
		kfree(b);
		return NULL;
	}

	kref_init(&b->kref);
	b->alloc_len = len;
	b->vec.iov_len = len;
	dout("buffer_new %p\n", b);
	return b;
}
EXPORT_SYMBOL(ceph_buffer_new);

void ceph_buffer_release(struct kref *kref)
{
	struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);

	dout("buffer_release %p\n", b);
	kvfree(b->vec.iov_base);
	kfree(b);
}
EXPORT_SYMBOL(ceph_buffer_release);

int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end)
{
	size_t len;

	ceph_decode_need(p, end, sizeof(u32), bad);
	len = ceph_decode_32(p);
	dout("decode_buffer len %d\n", (int)len);
	ceph_decode_need(p, end, len, bad);
	*b = ceph_buffer_new(len, GFP_NOFS);
	if (!*b)
		return -ENOMEM;
	ceph_decode_copy(p, (*b)->vec.iov_base, len);
	return 0;
bad:
	return -EINVAL;
}
p-back</option>
<option value='packet-rx-pump-back'>packet-rx-pump-back</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>net-next plumbings</td><td class='sub right'>Tobias Klauser</td></tr></table>
<table class='tabs'><tr><td>
<a href='/cgit.cgi/linux/net-next.git/'>summary</a><a href='/cgit.cgi/linux/net-next.git/refs/?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>refs</a><a class='active' href='/cgit.cgi/linux/net-next.git/log/include/net/nexthop.h'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/include/net/nexthop.h?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>tree</a><a href='/cgit.cgi/linux/net-next.git/commit/include/net/nexthop.h?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/include/net/nexthop.h?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/include/net/nexthop.h'>
<input type='hidden' name='id' value='b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/include?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>include</a>/<a href='/cgit.cgi/linux/net-next.git/log/include/net?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>net</a>/<a href='/cgit.cgi/linux/net-next.git/log/include/net/nexthop.h?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07'>nexthop.h</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/include/net/nexthop.h?id=b4c4ebcf3ca22bf9b04fa9c6ccfbfdfe0a256d07&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>