From patchwork Tue Apr 28 22:05:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 6292341 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AD46FBEEE1 for ; Tue, 28 Apr 2015 22:06:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE4E120225 for ; Tue, 28 Apr 2015 22:06:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE7C1202C8 for ; Tue, 28 Apr 2015 22:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030989AbbD1WFy (ORCPT ); Tue, 28 Apr 2015 18:05:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51132 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030444AbbD1WFv (ORCPT ); Tue, 28 Apr 2015 18:05:51 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3SM5o7Y024541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 28 Apr 2015 18:05:50 -0400 Received: from rh2.redhat.com (vpn-49-183.rdu2.redhat.com [10.10.49.183]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3SM5mbN013102 for ; Tue, 28 Apr 2015 18:05:50 -0400 From: mchristi@redhat.com To: ceph-devel@vger.kernel.org Subject: [PATCH 02/10] ceph: add start/finish encoding helpers Date: Tue, 28 Apr 2015 17:05:39 -0500 Message-Id: <1430258747-12506-3-git-send-email-mchristi@redhat.com> In-Reply-To: <1430258747-12506-1-git-send-email-mchristi@redhat.com> References: <1430258747-12506-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mike Christie This patch adds helpers to encode/decode the starting blocks locking code. They are the equivalent of ENCODE_START and DECODE_START_LEGACY_COMPAT_LEN in the userspace ceph code. Signed-off-by: Mike Christie --- include/linux/ceph/decode.h | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h index a6ef9cc..96ec43d 100644 --- a/include/linux/ceph/decode.h +++ b/include/linux/ceph/decode.h @@ -217,6 +217,61 @@ static inline void ceph_encode_string(void **p, void *end, *p += len; } +/* + * version and length starting block encoders/decoders + */ + +/* current code version (u8) + compat code version (u8) + len of struct (u32) */ +#define CEPH_ENCODING_START_BLK_LEN 6 + +/** + * ceph_start_encoding - start encoding block + * @p: buffer to encode data in + * @curr_ver: current (code) version of the encoding + * @compat_ver: oldest code version that can decode it + * @len: length of data that will be encoded in buffer + */ +static inline void ceph_start_encoding(void **p, u8 curr_ver, u8 compat_ver, + u32 len) +{ + ceph_encode_8(p, curr_ver); + ceph_encode_8(p, compat_ver); + ceph_encode_32(p, len); +} + +/** + * ceph_start_decoding_compat - decode block with legacy support for older schemes + * @p: buffer to decode + * @end: end of decode buffer + * @curr_ver: current version of the encoding that the code supports/encode + * @compat_ver: oldest version that includes a __u8 compat version field + * @len_ver: oldest version that includes a __u32 length wrapper + * @len: buffer to return len of data in buffer + */ +static inline int ceph_start_decoding_compat(void **p, void *end, u8 curr_ver, + u8 compat_ver, u8 len_ver, u32 *len) +{ + u8 struct_ver, struct_compat; + + ceph_decode_8_safe(p, end, struct_ver, fail); + if (struct_ver >= curr_ver) { + ceph_decode_8_safe(p, end, struct_compat, fail); + if (curr_ver < struct_compat) + return -EINVAL; + } + + if (struct_ver >= len_ver) { + ceph_decode_32_safe(p, end, *len, fail); + } else { + *len = 0; + } + + return 0; +fail: + return -ERANGE; +} + + #define ceph_encode_need(p, end, n, bad) \ do { \ if (!likely(ceph_has_room(p, end, n))) \