Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libceph: introduce ceph_pagelist_alloc()

struct ceph_pagelist cannot be embedded into anything else because it
has its own refcount. Merge allocation and initialization together.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

+28 -26
+1 -2
fs/ceph/acl.c
··· 206 206 tmp_buf = kmalloc(max(val_size1, val_size2), GFP_KERNEL); 207 207 if (!tmp_buf) 208 208 goto out_err; 209 - pagelist = kmalloc(sizeof(struct ceph_pagelist), GFP_KERNEL); 209 + pagelist = ceph_pagelist_alloc(GFP_KERNEL); 210 210 if (!pagelist) 211 211 goto out_err; 212 - ceph_pagelist_init(pagelist); 213 212 214 213 err = ceph_pagelist_reserve(pagelist, PAGE_SIZE); 215 214 if (err)
+1 -2
fs/ceph/mds_client.c
··· 3126 3126 3127 3127 pr_info("mds%d reconnect start\n", mds); 3128 3128 3129 - pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS); 3129 + pagelist = ceph_pagelist_alloc(GFP_NOFS); 3130 3130 if (!pagelist) 3131 3131 goto fail_nopagelist; 3132 - ceph_pagelist_init(pagelist); 3133 3132 3134 3133 reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, GFP_NOFS, false); 3135 3134 if (!reply)
+1 -2
fs/ceph/xattr.c
··· 951 951 952 952 if (size > 0) { 953 953 /* copy value into pagelist */ 954 - pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS); 954 + pagelist = ceph_pagelist_alloc(GFP_NOFS); 955 955 if (!pagelist) 956 956 return -ENOMEM; 957 957 958 - ceph_pagelist_init(pagelist); 959 958 err = ceph_pagelist_append(pagelist, value, size); 960 959 if (err) 961 960 goto out;
+1 -10
include/linux/ceph/pagelist.h
··· 23 23 size_t room; /* room remaining to reset to */ 24 24 }; 25 25 26 - static inline void ceph_pagelist_init(struct ceph_pagelist *pl) 27 - { 28 - INIT_LIST_HEAD(&pl->head); 29 - pl->mapped_tail = NULL; 30 - pl->length = 0; 31 - pl->room = 0; 32 - INIT_LIST_HEAD(&pl->free_list); 33 - pl->num_pages_free = 0; 34 - refcount_set(&pl->refcnt, 1); 35 - } 26 + struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags); 36 27 37 28 extern void ceph_pagelist_release(struct ceph_pagelist *pl); 38 29
+4 -10
net/ceph/osd_client.c
··· 776 776 777 777 op = _osd_req_op_init(osd_req, which, CEPH_OSD_OP_CALL, 0); 778 778 779 - pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS); 779 + pagelist = ceph_pagelist_alloc(GFP_NOFS); 780 780 if (!pagelist) 781 781 return -ENOMEM; 782 - 783 - ceph_pagelist_init(pagelist); 784 782 785 783 op->cls.class_name = class; 786 784 size = strlen(class); ··· 812 814 813 815 BUG_ON(opcode != CEPH_OSD_OP_SETXATTR && opcode != CEPH_OSD_OP_CMPXATTR); 814 816 815 - pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS); 817 + pagelist = ceph_pagelist_alloc(GFP_NOFS); 816 818 if (!pagelist) 817 819 return -ENOMEM; 818 - 819 - ceph_pagelist_init(pagelist); 820 820 821 821 payload_len = strlen(name); 822 822 op->xattr.name_len = payload_len; ··· 4594 4598 4595 4599 op = _osd_req_op_init(req, which, CEPH_OSD_OP_NOTIFY_ACK, 0); 4596 4600 4597 - pl = kmalloc(sizeof(*pl), GFP_NOIO); 4601 + pl = ceph_pagelist_alloc(GFP_NOIO); 4598 4602 if (!pl) 4599 4603 return -ENOMEM; 4600 4604 4601 - ceph_pagelist_init(pl); 4602 4605 ret = ceph_pagelist_encode_64(pl, notify_id); 4603 4606 ret |= ceph_pagelist_encode_64(pl, cookie); 4604 4607 if (payload) { ··· 4664 4669 op = _osd_req_op_init(req, which, CEPH_OSD_OP_NOTIFY, 0); 4665 4670 op->notify.cookie = cookie; 4666 4671 4667 - pl = kmalloc(sizeof(*pl), GFP_NOIO); 4672 + pl = ceph_pagelist_alloc(GFP_NOIO); 4668 4673 if (!pl) 4669 4674 return -ENOMEM; 4670 4675 4671 - ceph_pagelist_init(pl); 4672 4676 ret = ceph_pagelist_encode_32(pl, 1); /* prot_ver */ 4673 4677 ret |= ceph_pagelist_encode_32(pl, timeout); 4674 4678 ret |= ceph_pagelist_encode_32(pl, payload_len);
+20
net/ceph/pagelist.c
··· 6 6 #include <linux/highmem.h> 7 7 #include <linux/ceph/pagelist.h> 8 8 9 + struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags) 10 + { 11 + struct ceph_pagelist *pl; 12 + 13 + pl = kmalloc(sizeof(*pl), gfp_flags); 14 + if (!pl) 15 + return NULL; 16 + 17 + INIT_LIST_HEAD(&pl->head); 18 + pl->mapped_tail = NULL; 19 + pl->length = 0; 20 + pl->room = 0; 21 + INIT_LIST_HEAD(&pl->free_list); 22 + pl->num_pages_free = 0; 23 + refcount_set(&pl->refcnt, 1); 24 + 25 + return pl; 26 + } 27 + EXPORT_SYMBOL(ceph_pagelist_alloc); 28 + 9 29 static void ceph_pagelist_unmap_tail(struct ceph_pagelist *pl) 10 30 { 11 31 if (pl->mapped_tail) {