Commit 4deb14a2 authored by Yan, Zheng's avatar Yan, Zheng Committed by Ilya Dryomov

ceph: optimize flock encoding during reconnect

Don't malloc if there is no flock.
Signed-off-by: default avatar"Yan, Zheng" <zyan@redhat.com>
Reviewed-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent c6db8472
...@@ -431,19 +431,22 @@ int ceph_locks_to_pagelist(struct ceph_filelock *flocks, ...@@ -431,19 +431,22 @@ int ceph_locks_to_pagelist(struct ceph_filelock *flocks,
if (err) if (err)
goto out_fail; goto out_fail;
err = ceph_pagelist_append(pagelist, flocks, if (num_fcntl_locks > 0) {
num_fcntl_locks * sizeof(*flocks)); err = ceph_pagelist_append(pagelist, flocks,
if (err) num_fcntl_locks * sizeof(*flocks));
goto out_fail; if (err)
goto out_fail;
}
nlocks = cpu_to_le32(num_flock_locks); nlocks = cpu_to_le32(num_flock_locks);
err = ceph_pagelist_append(pagelist, &nlocks, sizeof(nlocks)); err = ceph_pagelist_append(pagelist, &nlocks, sizeof(nlocks));
if (err) if (err)
goto out_fail; goto out_fail;
err = ceph_pagelist_append(pagelist, if (num_flock_locks > 0) {
&flocks[num_fcntl_locks], err = ceph_pagelist_append(pagelist, &flocks[num_fcntl_locks],
num_flock_locks * sizeof(*flocks)); num_flock_locks * sizeof(*flocks));
}
out_fail: out_fail:
return err; return err;
} }
...@@ -2899,26 +2899,32 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap, ...@@ -2899,26 +2899,32 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
if (recon_state->msg_version >= 2) { if (recon_state->msg_version >= 2) {
int num_fcntl_locks, num_flock_locks; int num_fcntl_locks, num_flock_locks;
struct ceph_filelock *flocks; struct ceph_filelock *flocks = NULL;
size_t struct_len, total_len = 0; size_t struct_len, total_len = 0;
u8 struct_v = 0; u8 struct_v = 0;
encode_again: encode_again:
ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks); ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
flocks = kmalloc((num_fcntl_locks+num_flock_locks) * if (num_fcntl_locks + num_flock_locks > 0) {
sizeof(struct ceph_filelock), GFP_NOFS); flocks = kmalloc((num_fcntl_locks + num_flock_locks) *
if (!flocks) { sizeof(struct ceph_filelock), GFP_NOFS);
err = -ENOMEM; if (!flocks) {
goto out_free; err = -ENOMEM;
} goto out_free;
err = ceph_encode_locks_to_buffer(inode, flocks, }
num_fcntl_locks, err = ceph_encode_locks_to_buffer(inode, flocks,
num_flock_locks); num_fcntl_locks,
if (err) { num_flock_locks);
if (err) {
kfree(flocks);
flocks = NULL;
if (err == -ENOSPC)
goto encode_again;
goto out_free;
}
} else {
kfree(flocks); kfree(flocks);
if (err == -ENOSPC) flocks = NULL;
goto encode_again;
goto out_free;
} }
if (recon_state->msg_version >= 3) { if (recon_state->msg_version >= 3) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment