Skip to contentSkip to conversation

Support rados locking

RFC PATCH New Douglas Fuller 1 participant 7 messages Jun 30, 2015 Ceph common code (libceph)

lore
Share & tools
lore
#0 lore raw

cover Support rados locking

Add decoding support for some commonly exchanged data structures. Adapt Mike's code to serve as a generic client for cls::lock in userspace.

Discussion points:
Is this how we want to represent object classes in the kernel client?

This defines ceph_locker to contain ceph_locker_id and ceph_locker_info from userspace. Is that what we want for adaptation of userspace data structures (in this case std::map<locker_id_t, locker_info_t>)?

There are quite a few strings in these data structures. Do we want to add utility functions to properly free them at some level?

Douglas Fuller (4):
auth.c: added ceph_entity_name_encode
osd_client: added single object method call
cls_lock: add rados locking
cls_lock: add support for lock_info

Mike Christie (2):
Add support for userspace ceph DECODE_START.
ceph: add start/finish encoding helpers

 include/linux/ceph/auth.h       |   2 +
 include/linux/ceph/cls_lock.h   |  39 +++++
 include/linux/ceph/decode.h     |  78 ++++++++++
 include/linux/ceph/osd_client.h |   6 +
 net/ceph/Makefile               |   1 +
 net/ceph/auth.c                 |  11 ++
 net/ceph/cls_lock.c             | 329 ++++++++++++++++++++++++++++++++++++++++
 net/ceph/osd_client.c           |  44 ++++++
 8 files changed, 510 insertions(+)
 create mode 100644 include/linux/ceph/cls_lock.h
 create mode 100644 net/ceph/cls_lock.c
Signature · 1 line
1.9.3
#1 lore raw

RFC PATCH 1/6 Add support for userspace ceph DECODE_START.

From: Mike Christie <[email protected]>

---
 include/linux/ceph/decode.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
include/linux/ceph/decode.h +23 -0
index a6ef9cc..b55c7fd 100644
@@ -255,5 +255,28 @@ static inline void ceph_encode_string(void **p, void *end,
 		ceph_encode_string(p, end, s, n);		\
 	} while (0)
 
+/**
+ * ceph_start_decoding - start a decoding block
+ * @p: buffer to decode
+ * @end: end of buffer
+ * @curr_ver: current version of the encoding that the code supports/encode
+ * @len: buffer to return len of data in buffer
+ */
+static inline int ceph_start_decoding(void **p, void *end, u8 curr_ver,
+				      u32 *len)
+{
+	u8 struct_ver, struct_compat;
+
+	ceph_decode_8_safe(p, end, struct_ver, fail);
+	ceph_decode_8_safe(p, end, struct_compat, fail);
+
+	if (curr_ver < struct_compat)
+		return -EINVAL;
+
+	ceph_decode_32_safe(p, end, *len, fail);
+	return 0;
+fail:
+	return -ERANGE;
+}
 
 #endif
Signature · 1 line
1.9.3
#2 lore raw

RFC PATCH 2/6 ceph: add start/finish encoding helpers

In reply to Douglas Fuller

From: Mike Christie <[email protected]>

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.

[djf: added fixup from mailing list]
---
 include/linux/ceph/decode.h | 55 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
include/linux/ceph/decode.h +55 -0
index b55c7fd..c81f096 100644
@@ -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 >= compat_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)))		\
Signature · 1 line
1.9.3
#3 lore raw

RFC PATCH 3/6 auth.c: added ceph_entity_name_encode

In reply to Douglas Fuller
---
 include/linux/ceph/auth.h |  2 ++
 net/ceph/auth.c           | 11 +++++++++++
 2 files changed, 13 insertions(+)
include/linux/ceph/auth.h +2 -0
index 260d78b..7687918 100644
@@ -104,6 +104,8 @@ extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
 				  void *buf, size_t len,
 				  void *reply_buf, size_t reply_len);
 extern int ceph_entity_name_encode(const char *name, void **p, void *end);
+extern int ceph_entity_name_decode(struct ceph_entity_name *name, void **p,
+				   void *end);
 
 extern int ceph_build_auth(struct ceph_auth_client *ac,
 		    void *msg_buf, size_t msg_len);
net/ceph/auth.c +11 -0
index 6b923bc..50baee6 100644
@@ -94,6 +94,17 @@ int ceph_entity_name_encode(const char *name, void **p, void *end)
 	return 0;
 }
 
+int ceph_entity_name_decode(struct ceph_entity_name *name, void **p, void *end)
+{
+	ceph_decode_8_safe(p, end, name->type, bad);
+	ceph_decode_64_safe(p, end, name->num, bad);
+
+	return 0;
+
+bad:
+	return -ERANGE;
+}
+
 /*
  * Initiate protocol negotiation with monitor.  Include entity name
  * and list supported protocols.
Signature · 1 line
1.9.3
#4 lore raw

RFC PATCH 4/6 osd_client: added single object method call

In reply to Douglas Fuller

Add a convenience function to osd_client to call class ops. The interface assumes that request and reply data each consist of single pages.

---
 include/linux/ceph/osd_client.h |  6 ++++++
 net/ceph/osd_client.c           | 44 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
include/linux/ceph/osd_client.h +6 -0
index 7fbbd22..40561ff 100644
@@ -362,6 +362,12 @@ extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
 				      u32 truncate_seq, u64 truncate_size,
 				      bool use_mempool);
 
+extern int ceph_osd_op_cls_call(struct ceph_osd_client *osdc, int poolid,
+				char *obj_name, char *class, char *method,
+				int flags, struct page **req_data,
+				size_t req_len, struct page **resp_data,
+				size_t *resp_len);
+
 extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
 					 struct ceph_osd_request *req);
 
net/ceph/osd_client.c +44 -0

50 lines not on this page · raw message

Signature · 1 line
1.9.3
#5 lore raw

RFC PATCH 5/6 cls_lock: add rados locking

In reply to Douglas Fuller

This patch adds support for rados lock, unlock and break lock. This will be used to sync up scsi pr info manipulation and TMF execution.

[djf: broke out lock functions and moved to new source file]
[djf: changed interface to make use of osd_client utility functions]
[djf: snipped paragraph from commit message related to rbd code not moved]
---
 include/linux/ceph/cls_lock.h |  12 +++
 net/ceph/Makefile             |   1 +
 net/ceph/cls_lock.c           | 173 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 include/linux/ceph/cls_lock.h
 create mode 100644 net/ceph/cls_lock.c
include/linux/ceph/cls_lock.h new file +12 -0
new file mode 100644
index 0000000..2c24eb2
@@ -0,0 +1,12 @@
+#ifndef _NET_CEPH_RADOS_LOCK_H
+#define _NET_CEPH_RADOS_LOCK_H
+
+int ceph_cls_lock(struct ceph_osd_client *osdc, int poolid, char *obj_name,
+		  char *lock_name, u8 type, char *cookie, char *tag, char *desc,
+		  u8 flags);
+int ceph_cls_unlock(struct ceph_osd_client *osdc, int poolid, char *obj_name,
+		    char *lock_name, char *cookie);
+int ceph_cls_break_lock(struct ceph_osd_client *osdc, int poolid,
+			char *obj_name, char *lock_name, u8 entity_type,
+			u64 num, char *cookie);
+#endif
net/ceph/Makefile +1 -0
index 958d9856..f76ee18 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_CEPH_LIB) += libceph.o
 
 libceph-y := ceph_common.o messenger.o msgpool.o buffer.o pagelist.o \
 	mon_client.o \
+	cls_lock.o \
 	osd_client.o osdmap.o crush/crush.o crush/mapper.o crush/hash.o \
 	debugfs.o \
 	auth.o auth_none.o \
net/ceph/cls_lock.c new file +173 -0

173 lines not on this page · raw message

Signature · 1 line
1.9.3
#6 lore raw

RFC PATCH 6/6 cls_lock: add support for lock_info

In reply to Douglas Fuller

Add an interface for the lock.lock_info method and associated data structures.

Based heavily on Mike Christie's code originally authored for the previous commit.

---
 include/linux/ceph/cls_lock.h |  27 ++++++++
 net/ceph/cls_lock.c           | 156 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 183 insertions(+)
include/linux/ceph/cls_lock.h +27 -0
index 2c24eb2..d6d3636 100644
@@ -1,6 +1,33 @@
 #ifndef _NET_CEPH_RADOS_LOCK_H
 #define _NET_CEPH_RADOS_LOCK_H
 
+#include <linux/ceph/types.h>
+#include <linux/ceph/msgpool.h>
+#include <linux/ceph/messenger.h>
+#include <linux/ceph/osdmap.h>
+#include <linux/ceph/osd_client.h>
+
+struct ceph_locker_id {
+	struct ceph_entity_name name;
+	size_t cookie_len;
+	char *cookie;
+};
+
+struct ceph_locker_info {
+	struct timespec ts;
+	struct ceph_entity_addr addr;
+	size_t desc_len;
+	char *desc;
+};
+
+struct ceph_locker {
+	struct ceph_locker_id id;
+	struct ceph_locker_info info;
+};
+
+int ceph_cls_lock_info(struct ceph_osd_client *osdc, int poolid, char *obj_name,
+		       char * lock_name, int *num_lockers,
+		       struct ceph_locker **lockers, u8 *lock_type, char **tag);
 int ceph_cls_lock(struct ceph_osd_client *osdc, int poolid, char *obj_name,
 		  char *lock_name, u8 type, char *cookie, char *tag, char *desc,
 		  u8 flags);
net/ceph/cls_lock.c +156 -0

167 lines not on this page · raw message

Signature · 1 line
1.9.3