From patchwork Sun Jun 24 13:06:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10484165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1404E60230 for ; Sun, 24 Jun 2018 13:06:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0445F28891 for ; Sun, 24 Jun 2018 13:06:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED3D6288A9; Sun, 24 Jun 2018 13:06:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84F0228891 for ; Sun, 24 Jun 2018 13:06:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751924AbeFXNGx (ORCPT ); Sun, 24 Jun 2018 09:06:53 -0400 Received: from mout.gmx.net ([212.227.17.22]:59849 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751915AbeFXNGv (ORCPT ); Sun, 24 Jun 2018 09:06:51 -0400 Received: from localhost.localdomain ([122.224.77.194]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MHrk1-1fTVIB0MVp-003drl; Sun, 24 Jun 2018 15:06:46 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH v2 2/2] ceph: use ceph_pagelist_encode_string() for encoding string Date: Sun, 24 Jun 2018 21:06:03 +0800 Message-Id: <20180624130603.16782-2-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180624130603.16782-1-cgxu519@gmx.com> References: <20180624130603.16782-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:EknkbYhzvodj1ZGrkZ22G2AWkQwmsyyQul2oHNhLaLveOnQ+vsJ Ayi8S/k2Ud+xvsi5FS8pA4zHC4DePfBoFNyVoN+T0U7eYX0eLokUIM4beQtgVs+Cd2+zTNq Fwx3zNLQ0xR4Y+BbRCz3ocAHVNXctxEvCQEjqg4VKZxpH7tDif128Lub66sM8mngOBgHsNC Gkwus/ojeTa5mVE6F7FtA== X-UI-Out-Filterresults: notjunk:1; V01:K0:Nge6fJlMDBU=:N4gxLYUkoX8b0Fy2IB/Xj/ AwkBXtJ9PG1Rd3Cig+D5uAGaIIi1vGu3jHwLSjY+1LIgv8vrM+hm3v/BUObML0SY0wjQiJcRF WgMhBS9wVJUub1o5spOMQp/qgibHwQ8YZWpCXAfK9tQj72fhekr48FVOri9f3QQtfE8gjj32C S0aDrh9xRG+tJwP5kRuSdnwvJO7tNhbSVgdE4Y7xjdV4q1ZqcWA7MyJmOPAqBcdQf9wUsMzxw m5yTOlOzrzIAa55ChvO/LaSIXBoW/I3/RPyjx5tj8cf58L1OfGBEYWd3QRxMGUjLdOLtH6gMj Asog14CKLhhdt9Egx1o0d0FrXcvCdGkE7SOiDYJ70Qp6+/MpR7Gp8iD39Nb9GbJcrLdxb4PRL 6bPi5R6SPvvXGBfiJpHyyadeUi74cXhi5TfEW8VdeI5mVrM8cnWyt3IZhhw4DU3NDjqLPyDVV NofLqm92jLnVjDfthXC2l8rHAVA0fpG0V+JuZSrpB5SKgW0/JpHO+LXUASeXzAFJiDO+Oyolv sP7SF4mlCGPwEV5qQQADXptaHbXqS6K0J97c8YOqIULZHsPWnOjwP6eARW007SOIacsEtaK6T pFJTAahLIOAKknNMFQTfJjN3h/+NOSBg70EXrKD4zj30PuzleBB5zRfy/nqfmEr7FuUuRCPyT jXdHsq7twCn4IleppNPbFp0VTz+3th+VltCn1dizs3WZFTZYu4UiqbDvHmxPt1F0p0wZptCZa O05f905UDTAIrRg9H17Hb5sBCZjXaZ5J7BhPkex5h0pK5OiqXoT6hk4QdLY= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using ceph_pagelist_encode_string() instead of combination of ceph_pagelist_encode_32() and ceph_pagelist_append() when encoding string. Meanwhile add return code check for ceph_pagelist_encode_string(). Signed-off-by: Chengguang Xu --- v2: - Add return code check for ceph_pagelist_encode_string(). fs/ceph/acl.c | 18 ++++++++++++------ net/ceph/osd_client.c | 16 +++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c index 5da752751a2b..6f0210984456 100644 --- a/fs/ceph/acl.c +++ b/fs/ceph/acl.c @@ -222,14 +222,17 @@ int ceph_pre_init_acls(struct inode *dir, umode_t *mode, err = ceph_pagelist_reserve(pagelist, len + val_size1 + 8); if (err) goto out_err; - ceph_pagelist_encode_string(pagelist, XATTR_NAME_POSIX_ACL_ACCESS, - len); + err = ceph_pagelist_encode_string(pagelist, + XATTR_NAME_POSIX_ACL_ACCESS, len); + if (err) + goto out_err; err = posix_acl_to_xattr(&init_user_ns, acl, tmp_buf, val_size1); if (err < 0) goto out_err; - ceph_pagelist_encode_32(pagelist, val_size1); - ceph_pagelist_append(pagelist, tmp_buf, val_size1); + err = ceph_pagelist_encode_string(pagelist, tmp_buf, val_size1); + if (err) + goto out_err; } if (default_acl) { size_t len = strlen(XATTR_NAME_POSIX_ACL_DEFAULT); @@ -238,12 +241,15 @@ int ceph_pre_init_acls(struct inode *dir, umode_t *mode, goto out_err; err = ceph_pagelist_encode_string(pagelist, XATTR_NAME_POSIX_ACL_DEFAULT, len); + if (err) + goto out_err; err = posix_acl_to_xattr(&init_user_ns, default_acl, tmp_buf, val_size2); if (err < 0) goto out_err; - ceph_pagelist_encode_32(pagelist, val_size2); - ceph_pagelist_append(pagelist, tmp_buf, val_size2); + err = ceph_pagelist_encode_string(pagelist, tmp_buf, val_size2); + if (err) + goto out_err; } kfree(tmp_buf); diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index f2584fe1246f..720ac564d392 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -4607,14 +4607,15 @@ static int osd_req_op_notify_ack_init(struct ceph_osd_request *req, int which, ceph_pagelist_init(pl); ret = ceph_pagelist_encode_64(pl, notify_id); ret |= ceph_pagelist_encode_64(pl, cookie); - if (payload) { - ret |= ceph_pagelist_encode_32(pl, payload_len); - ret |= ceph_pagelist_append(pl, payload, payload_len); - } else { + if (payload) + ret |= ceph_pagelist_encode_string(pl, payload, payload_len); + else ret |= ceph_pagelist_encode_32(pl, 0); - } + if (ret) { ceph_pagelist_release(pl); + if (ret & -ERANGE) + return -ERANGE; return -ENOMEM; } @@ -4678,10 +4679,11 @@ static int osd_req_op_notify_init(struct ceph_osd_request *req, int which, 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); - ret |= ceph_pagelist_append(pl, payload, payload_len); + ret |= ceph_pagelist_encode_string(pl, payload, payload_len); if (ret) { ceph_pagelist_release(pl); + if (ret & -ERANGE) + return -ERANGE; return -ENOMEM; }