All of lore.kernel.org
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <1430258747-12506-3-git-send-email-mchristi@redhat.com> (raw)
In-Reply-To: <1430258747-12506-1-git-send-email-mchristi@redhat.com>

From: Mike Christie <michaelc@cs.wisc.edu>

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 <michaelc@cs.wisc.edu>
---
 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)))		\
-- 
1.8.3.1


  parent reply	other threads:[~2015-04-28 22:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-28 22:05 [PATCH 00/10] ceph/rbd: initial support for lio ha mchristi
2015-04-28 22:05 ` [PATCH 01/10] rbd: add obj request execution helper mchristi
2015-04-29 21:33   ` Alex Elder
2015-04-28 22:05 ` mchristi [this message]
2015-04-29 21:54   ` [PATCH 02/10] ceph: add start/finish encoding helpers Alex Elder
2015-04-30 12:22   ` Alex Elder
2015-05-01 19:39     ` Mike Christie
2015-05-01 19:47       ` Mike Christie
2015-05-01 19:53         ` Alex Elder
2015-04-28 22:05 ` [PATCH 03/10] ceph: export ceph_entity_type_name mchristi
2015-04-28 22:05 ` [PATCH 04/10] ceph/rbd: add support for watch notify payloads mchristi
2015-04-28 22:05 ` [PATCH 05/10] ceph: decode start helper mchristi
2015-04-28 22:05 ` [PATCH 06/10] ceph/rbd: add support for header version 2 and 3 mchristi
2015-04-28 22:05 ` [PATCH 07/10] ceph/rbd: update watch-notify ceph_osd_op mchristi
2015-04-28 22:05 ` [PATCH 08/10] ceph/rbd: add notify support mchristi
2015-04-30  0:50   ` Jason Dillaman
2015-04-28 22:05 ` [PATCH 09/10] rbd: add rados locking mchristi
2015-04-28 22:05 ` [PATCH 10/10] rbd: distribute scsi pr info through rbd class calls mchristi
2015-04-30  7:56   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430258747-12506-3-git-send-email-mchristi@redhat.com \
    --to=mchristi@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.