buffer.c 639 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "ceph_debug.h"
  2. #include "buffer.h"
  3. struct ceph_buffer *ceph_buffer_new(gfp_t gfp)
  4. {
  5. struct ceph_buffer *b;
  6. b = kmalloc(sizeof(*b), gfp);
  7. if (!b)
  8. return NULL;
  9. atomic_set(&b->nref, 1);
  10. b->vec.iov_base = NULL;
  11. b->vec.iov_len = 0;
  12. b->alloc_len = 0;
  13. return b;
  14. }
  15. int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp)
  16. {
  17. b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN);
  18. if (b->vec.iov_base) {
  19. b->is_vmalloc = false;
  20. } else {
  21. b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
  22. b->is_vmalloc = true;
  23. }
  24. if (!b->vec.iov_base)
  25. return -ENOMEM;
  26. b->alloc_len = len;
  27. b->vec.iov_len = len;
  28. return 0;
  29. }