Skip to content

Commit 4deb14a

Browse files
ukernelidryomov
authored andcommitted
ceph: optimize flock encoding during reconnect
Don't malloc if there is no flock. Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent c6db847 commit 4deb14a

2 files changed

Lines changed: 30 additions & 21 deletions

File tree

‎fs/ceph/locks.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,19 +431,22 @@ int ceph_locks_to_pagelist(struct ceph_filelock *flocks,
431431
if (err)
432432
goto out_fail;
433433

434-
err = ceph_pagelist_append(pagelist, flocks,
435-
num_fcntl_locks * sizeof(*flocks));
436-
if (err)
437-
goto out_fail;
434+
if (num_fcntl_locks > 0) {
435+
err = ceph_pagelist_append(pagelist, flocks,
436+
num_fcntl_locks * sizeof(*flocks));
437+
if (err)
438+
goto out_fail;
439+
}
438440

439441
nlocks = cpu_to_le32(num_flock_locks);
440442
err = ceph_pagelist_append(pagelist, &nlocks, sizeof(nlocks));
441443
if (err)
442444
goto out_fail;
443445

444-
err = ceph_pagelist_append(pagelist,
445-
&flocks[num_fcntl_locks],
446-
num_flock_locks * sizeof(*flocks));
446+
if (num_flock_locks > 0) {
447+
err = ceph_pagelist_append(pagelist, &flocks[num_fcntl_locks],
448+
num_flock_locks * sizeof(*flocks));
449+
}
447450
out_fail:
448451
return err;
449452
}

‎fs/ceph/mds_client.c‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,26 +2899,32 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
28992899

29002900
if (recon_state->msg_version >= 2) {
29012901
int num_fcntl_locks, num_flock_locks;
2902-
struct ceph_filelock *flocks;
2902+
struct ceph_filelock *flocks = NULL;
29032903
size_t struct_len, total_len = 0;
29042904
u8 struct_v = 0;
29052905

29062906
encode_again:
29072907
ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
2908-
flocks = kmalloc((num_fcntl_locks+num_flock_locks) *
2909-
sizeof(struct ceph_filelock), GFP_NOFS);
2910-
if (!flocks) {
2911-
err = -ENOMEM;
2912-
goto out_free;
2913-
}
2914-
err = ceph_encode_locks_to_buffer(inode, flocks,
2915-
num_fcntl_locks,
2916-
num_flock_locks);
2917-
if (err) {
2908+
if (num_fcntl_locks + num_flock_locks > 0) {
2909+
flocks = kmalloc((num_fcntl_locks + num_flock_locks) *
2910+
sizeof(struct ceph_filelock), GFP_NOFS);
2911+
if (!flocks) {
2912+
err = -ENOMEM;
2913+
goto out_free;
2914+
}
2915+
err = ceph_encode_locks_to_buffer(inode, flocks,
2916+
num_fcntl_locks,
2917+
num_flock_locks);
2918+
if (err) {
2919+
kfree(flocks);
2920+
flocks = NULL;
2921+
if (err == -ENOSPC)
2922+
goto encode_again;
2923+
goto out_free;
2924+
}
2925+
} else {
29182926
kfree(flocks);
2919-
if (err == -ENOSPC)
2920-
goto encode_again;
2921-
goto out_free;
2927+
flocks = NULL;
29222928
}
29232929

29242930
if (recon_state->msg_version >= 3) {

0 commit comments

Comments
 (0)