]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
libceph: introduce ceph_pagelist_alloc()
authorIlya Dryomov <idryomov@gmail.com>
Fri, 28 Sep 2018 13:38:34 +0000 (15:38 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 22 Oct 2018 08:28:21 +0000 (10:28 +0200)
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>
fs/ceph/acl.c
fs/ceph/mds_client.c
fs/ceph/xattr.c
include/linux/ceph/pagelist.h
net/ceph/osd_client.c
net/ceph/pagelist.c

index 8a9b562ae4ca3238142dca07853cc377fb94a061..5f0103f4007906032df4c56ecb2414e8f7cc3803 100644 (file)
@@ -206,10 +206,9 @@ int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
        tmp_buf = kmalloc(max(val_size1, val_size2), GFP_KERNEL);
        if (!tmp_buf)
                goto out_err;
-       pagelist = kmalloc(sizeof(struct ceph_pagelist), GFP_KERNEL);
+       pagelist = ceph_pagelist_alloc(GFP_KERNEL);
        if (!pagelist)
                goto out_err;
-       ceph_pagelist_init(pagelist);
 
        err = ceph_pagelist_reserve(pagelist, PAGE_SIZE);
        if (err)
index bc43c822426a27673eb19754dabc282d182bfc12..580a79b9a91fd9c74dfbe80320b692e089c02c8d 100644 (file)
@@ -3126,10 +3126,9 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,
 
        pr_info("mds%d reconnect start\n", mds);
 
-       pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
+       pagelist = ceph_pagelist_alloc(GFP_NOFS);
        if (!pagelist)
                goto fail_nopagelist;
-       ceph_pagelist_init(pagelist);
 
        reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, GFP_NOFS, false);
        if (!reply)
index 5cc8b94f8206972ce6ce988b92b5103504b335b1..316f6ad10644cdce8fd5cd7fbe526b3293a0866e 100644 (file)
@@ -951,11 +951,10 @@ static int ceph_sync_setxattr(struct inode *inode, const char *name,
 
        if (size > 0) {
                /* copy value into pagelist */
-               pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
+               pagelist = ceph_pagelist_alloc(GFP_NOFS);
                if (!pagelist)
                        return -ENOMEM;
 
-               ceph_pagelist_init(pagelist);
                err = ceph_pagelist_append(pagelist, value, size);
                if (err)
                        goto out;
index d0223364349f772ae4086ddc1304e02cf53a9d89..5dead8486fd8f38e9ac2c9333374b6da2b1d21f7 100644 (file)
@@ -23,16 +23,7 @@ struct ceph_pagelist_cursor {
        size_t room;                /* room remaining to reset to */
 };
 
-static inline void ceph_pagelist_init(struct ceph_pagelist *pl)
-{
-       INIT_LIST_HEAD(&pl->head);
-       pl->mapped_tail = NULL;
-       pl->length = 0;
-       pl->room = 0;
-       INIT_LIST_HEAD(&pl->free_list);
-       pl->num_pages_free = 0;
-       refcount_set(&pl->refcnt, 1);
-}
+struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags);
 
 extern void ceph_pagelist_release(struct ceph_pagelist *pl);
 
index a871b234cd907fac257e9857936a010bbfba6683..db2ebc9e5f1f7b96d0c0ff46fe0d1779e74c5f95 100644 (file)
@@ -776,12 +776,10 @@ int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
 
        op = _osd_req_op_init(osd_req, which, CEPH_OSD_OP_CALL, 0);
 
-       pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
+       pagelist = ceph_pagelist_alloc(GFP_NOFS);
        if (!pagelist)
                return -ENOMEM;
 
-       ceph_pagelist_init(pagelist);
-
        op->cls.class_name = class;
        size = strlen(class);
        BUG_ON(size > (size_t) U8_MAX);
@@ -814,12 +812,10 @@ int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
 
        BUG_ON(opcode != CEPH_OSD_OP_SETXATTR && opcode != CEPH_OSD_OP_CMPXATTR);
 
-       pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
+       pagelist = ceph_pagelist_alloc(GFP_NOFS);
        if (!pagelist)
                return -ENOMEM;
 
-       ceph_pagelist_init(pagelist);
-
        payload_len = strlen(name);
        op->xattr.name_len = payload_len;
        ceph_pagelist_append(pagelist, name, payload_len);
@@ -4598,11 +4594,10 @@ static int osd_req_op_notify_ack_init(struct ceph_osd_request *req, int which,
 
        op = _osd_req_op_init(req, which, CEPH_OSD_OP_NOTIFY_ACK, 0);
 
-       pl = kmalloc(sizeof(*pl), GFP_NOIO);
+       pl = ceph_pagelist_alloc(GFP_NOIO);
        if (!pl)
                return -ENOMEM;
 
-       ceph_pagelist_init(pl);
        ret = ceph_pagelist_encode_64(pl, notify_id);
        ret |= ceph_pagelist_encode_64(pl, cookie);
        if (payload) {
@@ -4669,11 +4664,10 @@ static int osd_req_op_notify_init(struct ceph_osd_request *req, int which,
        op = _osd_req_op_init(req, which, CEPH_OSD_OP_NOTIFY, 0);
        op->notify.cookie = cookie;
 
-       pl = kmalloc(sizeof(*pl), GFP_NOIO);
+       pl = ceph_pagelist_alloc(GFP_NOIO);
        if (!pl)
                return -ENOMEM;
 
-       ceph_pagelist_init(pl);
        ret = ceph_pagelist_encode_32(pl, 1); /* prot_ver */
        ret |= ceph_pagelist_encode_32(pl, timeout);
        ret |= ceph_pagelist_encode_32(pl, payload_len);
index 2ea0564771d2d4428be2a3e9642056b85d3b306f..65e34f78b05d4ca662ddceca0d1a24b34eb4007d 100644 (file)
@@ -6,6 +6,26 @@
 #include <linux/highmem.h>
 #include <linux/ceph/pagelist.h>
 
+struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags)
+{
+       struct ceph_pagelist *pl;
+
+       pl = kmalloc(sizeof(*pl), gfp_flags);
+       if (!pl)
+               return NULL;
+
+       INIT_LIST_HEAD(&pl->head);
+       pl->mapped_tail = NULL;
+       pl->length = 0;
+       pl->room = 0;
+       INIT_LIST_HEAD(&pl->free_list);
+       pl->num_pages_free = 0;
+       refcount_set(&pl->refcnt, 1);
+
+       return pl;
+}
+EXPORT_SYMBOL(ceph_pagelist_alloc);
+
 static void ceph_pagelist_unmap_tail(struct ceph_pagelist *pl)
 {
        if (pl->mapped_tail) {