cld: use XDR for all messages
PATCH 1/1 cld: use XDR for all messages
This patch moves CLD from using manual data serialization to using XDR (via rpcgen). Both the packet header and the message body are now serialized and deserialized using XDR. This makes it easy to have a variable-length packet header, as well as a variable-length message body.
Message definitions are now in cld_msg.x. Helper functions for using messages are in cld_fmt.c. The new client and server-side functions for sending messages don't require the caller to precompute the size of the message. Instead, you simply tell it what type of message you have, and give it the data. It handles determining message size and encoding.
The only fields that I did not choose to deal with using XDR are the packet sequence ID and the packet SHA checksum. The seqid would have been inconvenient and inefficient to store in the XDR header, because we have to check a lot of packets' seqids against the ACKs we receive very frequently. The SHA checksum can't be computed until the rest of the packet has been serialized, which is counter to the way XDR works (it is a single-pass serialization system.) So these fields are in the packet footer, which comes at the end of every packet.
This patch introduces a minor libcldc API change in struct cldc_call_opts.
--- .gitignore | 4 + include/Makefile.am | 2 +- include/cld_common.h | 10 + include/cld_fmt.h | 78 ++++ include/cld_msg.h | 252 ------------- include/cldc.h | 37 +- lib/Makefile.am | 14 +- lib/cld_fmt.c | 189 ++++++++++ lib/cld_msg_rpc.x | 212 +++++++++++ lib/cldc.c | 960 +++++++++++++++++++++--------------------------- lib/common.c | 6 +- server/Makefile.am | 9 +- server/cld.h | 97 ++++-- server/cldb.h | 2 +- server/msg.c | 304 ++++++---------- server/server.c | 743 ++++++++++++++++++++----------------- server/session.c | 396 ++++++++++----------- test/load-file-event.c | 14 +- test/save-file-event.c | 2 - tools/cldcli.c | 22 +- 20 files changed, 1744 insertions(+), 1609 deletions(-) create mode 100644 include/cld_fmt.h delete mode 100644 include/cld_msg.h create mode 100644 lib/cld_fmt.c create mode 100644 lib/cld_msg_rpc.x
.gitignore +4 -0
@@ -32,5 +32,9 @@ cld-config.h* cscope.* ncscope.* +# XDR files +*_rpc.h +*_rpc_xdr.c + # ignore Doxygen output directory gendoc
include/Makefile.am +1 -1
@@ -1,5 +1,5 @@ EXTRA_DIST = cld-private.h libtimer.h -include_HEADERS = cldc.h cld_msg.h hail_log.h cld_common.h +include_HEADERS = cldc.h hail_log.h cld_common.h
include/cld_common.h +10 -0
@@ -20,10 +20,20 @@*/ #include <stdint.h> +#include <cld_msg_rpc.h> + +#define CLD_ALIGN8 (n) ((8 - ((n) & 7)) & 7)unsigned long long cld_sid2llu (const uint8_t *sid);void __cld_rand64 (void *p);const char *cld_errstr (enum cle_err_codes ecode);int cld_readport (const char *fname); +/* +* * We use a unified format for sid so it can be searched in log files (* in +* vi). +*/ +#define SIDFMT "%016llX" +#define SIDARG (sid) cld_sid2llu(sid) +#endif /* __CLD_COMMON_H__ */
include/cld_fmt.h new file +78 -0
78 lines not on this page · raw message
include/cld_msg.h deleted +0 -252
252 lines not on this page · raw message
include/cldc.h +17 -20
@@ -19,10 +19,11 @@* */ +#include <sys/types.h> #include <stdbool.h> #include <glib.h> -#include <cld_msg.h> +#include <cld_msg_rpc.h> #include <cld_common.h> #include <hail_log.h>
@@ -35,33 +36,33 @@ struct cldc_call_opts {void *private;/* private; lib-owned */ -enum cld_msg_ops op; -union { -struct { -struct cld_msg_get_resp resp; -const char *buf; -unsigned int size; -char inode_name[CLD_INODE_NAME_MAX ]; - } get; - } u; +enum cld_msg_type type; +struct cld_msg_get_resp resp; +char inode_name[CLD_INODE_NAME_MAX ]; +char data[CLD_MAX_MSG_SZ ]; }; +void cldc_call_opts_get_data (struct cldc_call_opts *copts, +char **data,size_t *data_len); +struct cldc_pkt_info {int pkt_len; +int hdr_len;int retries; +char user[CLD_MAX_USERNAME ];/* must be at end of struct */ -struct cld_packet pkt; -uint8_t data[0 ]; +char data[0 ]; };/** an outgoing message, from client to server */ struct cldc_msg {uint64_t xid; - +enum cld_msg_type type;struct cldc_session *sess; -ssize_t (*cb)(struct cldc_msg *,const void *,size_t ,bool ); +ssize_t (*cb)(struct cldc_msg *,const void *,size_t , +enum cle_err_codes resp_rc);void *cb_private;struct cldc_call_opts copts;
@@ -70,18 +71,13 @@ struct cldc_msg {time_t expire_time; -int data_len;int n_pkts; -struct cldc_pkt_info *pkt_info[CLD_MAX_PKT_MSG ]; - -/* must be at end of struct */ -uint8_t data[0 ]; };/** an open file handle associated with a session */ struct cldc_fh { -uint64_t fh_le;/* fh id, LE */ +uint64_t fh;struct cldc_session *sess;bool valid; };
@@ -128,6 +124,7 @@ struct cldc_session {bool confirmed; +enum cld_msg_type msg_buf_type;unsigned int msg_buf_len;char msg_buf[CLD_MAX_MSG_SZ ]; };
lib/Makefile.am +13 -1
@@ -5,11 +5,22 @@ EXTRA_DIST = INCLUDES = -I$(top_srcdir)/include \ @GLIB_CFLAGS@ +%_rpc.h: %_rpc.x + rpcgen -h $< > $@ + +%_rpc_xdr.c: %_rpc.x + rpcgen -c $< > $@ + LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lib_LTLIBRARIES = libcldc.la -libcldc_la_SOURCES = cldc.c cldc-udp.c cldc-dns.c common.c +libcldc_la_SOURCES = cldc.c \ + cldc-udp.c \ + cldc-dns.c \ + common.c \ + cld_fmt.c \ + cld_msg_rpc_xdr.c libcldc_la_LDFLAGS = \ -version-info $(LIBCLDC_CURRENT):$(LIBCLDC_REVISION):$(LIBCLDC_AGE) \
@@ -21,3 +32,4 @@ noinst_LIBRARIES = libtimer.a pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libcldc.pc +include_HEADERS = cld_msg_rpc.h
lib/cld_fmt.c new file +189 -0
189 lines not on this page · raw message
lib/cld_msg_rpc.x new file +212 -0
212 lines not on this page · raw message
lib/cldc.c +411 -549
1,393 lines not on this page · raw message
lib/common.c +5 -1
@@ -26,7 +26,11 @@#include <errno.h> #include <glib.h> #include <cld-private.h> -#include "cld_msg.h" +#include <openssl/sha.h> +#include <openssl/hmac.h> +#include "cld_msg_rpc.h" +#include <hail_log.h> +#include <syslog.h> /* duplicated from tools/cldcli.c; put in common header somewhere? */ #define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]))
server/Makefile.am +7 -2
@@ -1,13 +1,18 @@ -INCLUDES = -I$(top_srcdir)/include @GLIB_CFLAGS@ \ +INCLUDES = -I$(top_srcdir)/include \ + -I$(top_srcdir)/lib \ + @GLIB_CFLAGS@ \ -DCLD_LIBDIR=\""$(libdir)"\" \ -DCLD_LOCAL_STATE_DIR="\"$(localstatedir)\"" sbin_PROGRAMS = cld cldbadm cld_SOURCES = cldb.h cld.h \ + ../lib/cld_fmt.c \ ../lib/common.c \ - cldb.c msg.c server.c session.c util.c + cldb.c msg.c server.c session.c util.c \ + ../lib/cld_msg_rpc_xdr.c + cld_LDADD = ../lib/libtimer.a \ @CRYPTO_LIBS@ @GLIB_LIBS@ @DB4_LIBS@
server/cld.h +66 -31
139 lines not on this page · raw message
server/cldb.h +1 -1
@@ -23,7 +23,7 @@#include <stdbool.h> #include <db.h> #include <cld-private.h> -#include <cld_msg.h> +#include <cld_msg_rpc.h> typedef uint64_t cldino_t ;
server/msg.c +111 -193
551 lines not on this page · raw message
server/server.c +407 -336
743 lines not on this page · raw message
server/session.c +187 -209
396 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.6.2.5
Part of the diff is not shown here. View the raw message.
Quoted 45 lines · Colin McCabe
This patch moves CLD from using manual data serialization to using XDR (via rpcgen). Both the packet header and the message body are now serialized and deserialized using XDR. This makes it easy to have a variable-length packet header, as well as a variable-length message body.
Message definitions are now in cld_msg.x. Helper functions for using messages are in
cld_fmt.c. The new client and server-side functions for sending messages don't require the caller to precompute the size of the message. Instead, you simply tell it what type of message you have, and give it the data. It handles determining message size and encoding.The only fields that I did not choose to deal with using XDR are the packet sequence ID and the packet SHA checksum. The seqid would have been inconvenient and inefficient to store in the XDR header, because we have to check a lot of packets' seqids against the ACKs we receive very frequently. The SHA checksum can't be computed until the rest of the packet has been serialized, which is counter to the way XDR works (it is a single-pass serialization system.) So these fields are in the packet footer, which comes at the end of every packet.
This patch introduces a minor libcldc API change in struct
cldc_call_opts.Signed-off-by Colin McCabe<[email protected]>--- .gitignore | 4 + include/Makefile.am | 2 +- include/cld_common.h | 10 + include/cld_fmt.h | 78 ++++ include/cld_msg.h | 252 ------------- include/cldc.h | 37 +- lib/Makefile.am | 14 +- lib/cld_fmt.c | 189 ++++++++++ lib/cld_msg_rpc.x | 212 +++++++++++ lib/cldc.c | 960 +++++++++++++++++++++--------------------------- lib/common.c | 6 +- server/Makefile.am | 9 +- server/cld.h | 97 ++++-- server/cldb.h | 2 +- server/msg.c | 304 ++++++---------- server/server.c | 743 ++++++++++++++++++++----------------- server/session.c | 396 ++++++++++----------- test/load-file-event.c | 14 +- test/save-file-event.c | 2 - tools/cldcli.c | 22 +- 20 files changed, 1744 insertions(+), 1609 deletions(-)
Quoted 4 lines
create mode 100644
include/cld_fmt.h
delete mode 100644include/cld_msg.h
create mode 100644lib/cld_fmt.c
create mode 100644lib/cld_msg_rpc.x
Fantastic! This will take a day or two to review, so please be a little bit patient, waiting for the patch to be applied.
At first glance, it looks pretty good.
Thanks, this will really help with future protocol changes, most notably (a) fleshing out multi-master support and (b) introducing cache coherency.
Jeff
Quoted 45 lines · Colin McCabe
This patch moves CLD from using manual data serialization to using XDR (via rpcgen). Both the packet header and the message body are now serialized and deserialized using XDR. This makes it easy to have a variable-length packet header, as well as a variable-length message body.
Message definitions are now in cld_msg.x. Helper functions for using messages are in
cld_fmt.c. The new client and server-side functions for sending messages don't require the caller to precompute the size of the message. Instead, you simply tell it what type of message you have, and give it the data. It handles determining message size and encoding.The only fields that I did not choose to deal with using XDR are the packet sequence ID and the packet SHA checksum. The seqid would have been inconvenient and inefficient to store in the XDR header, because we have to check a lot of packets' seqids against the ACKs we receive very frequently. The SHA checksum can't be computed until the rest of the packet has been serialized, which is counter to the way XDR works (it is a single-pass serialization system.) So these fields are in the packet footer, which comes at the end of every packet.
This patch introduces a minor libcldc API change in struct
cldc_call_opts.Signed-off-by Colin McCabe<[email protected]>--- .gitignore | 4 + include/Makefile.am | 2 +- include/cld_common.h | 10 + include/cld_fmt.h | 78 ++++ include/cld_msg.h | 252 ------------- include/cldc.h | 37 +- lib/Makefile.am | 14 +- lib/cld_fmt.c | 189 ++++++++++ lib/cld_msg_rpc.x | 212 +++++++++++ lib/cldc.c | 960 +++++++++++++++++++++--------------------------- lib/common.c | 6 +- server/Makefile.am | 9 +- server/cld.h | 97 ++++-- server/cldb.h | 2 +- server/msg.c | 304 ++++++---------- server/server.c | 743 ++++++++++++++++++++----------------- server/session.c | 396 ++++++++++----------- test/load-file-event.c | 14 +- test/save-file-event.c | 2 - tools/cldcli.c | 22 +- 20 files changed, 1744 insertions(+), 1609 deletions(-)
Quoted 4 lines
create mode 100644
include/cld_fmt.h
delete mode 100644include/cld_msg.h
create mode 100644lib/cld_fmt.c
create mode 100644lib/cld_msg_rpc.x
Well, this definitely does not build as-is. lib/Makefile.am needs
BUILT_SOURCES = cld_msg_rpc.h
otherwise nothing builds at all, because cld_msg_rpc.h does not exist. test/Makefile.am and tools/Makefile.am both need
-I$(top_srcdir)/lib
added to their INCLUDES. And you should probably examine http://www.gnu.org/software/automake/manual/automake.html#Clean to make sure that "make distclean" and "make clean" work.
Still playing with it. You definitely need to make sure your patch builds and runs against a fresh git repo check + autogen.sh + ./configure run.
Jeff
Quoted 10 lines · On Wed, 13 Jan 2010 16:03:45 -0500 Jeff Garzik <[email protected]> wrote:
Well, this definitely does not build as-is.
lib/Makefile.amneeds
BUILT_SOURCES=cld_msg_rpc.hotherwise nothing builds at all, because
cld_msg_rpc.hdoes not exist. test/Makefile.am andtools/Makefile.amboth need-I$(top_srcdir)/libadded to their INCLUDES. []
Kernel places generated files into the top include directory, e.g. autoconf.h and asm-offsets.h for asm/. It's probably easier than piling up include paths. I dunno.
-- Pete
Quoted 10 lines · Pete Zaitcev
Quoted 7 lines · On Wed, 13 Jan 2010 16:03:45 -0500 Jeff Garzik<[email protected]> wrote:
Well, this definitely does not build as-is.
lib/Makefile.amneeds
BUILT_SOURCES=cld_msg_rpc.hotherwise nothing builds at all, because
cld_msg_rpc.hdoes not exist. test/Makefile.am andtools/Makefile.amboth need
Quoted 7 lines
Quoted 3 lines
-I$(top_srcdir)/libadded to their INCLUDES. []
Kernel places generated files into the top include directory, e.g.
autoconf.handasm-offsets.hfor asm/. It's probably easier than piling up include paths. I dunno.
Anything other than $(top_srcdir)/include requires an addition to INCLUDES. (remember, build-dir != src-dir always, especially with 'make distcheck')
Speaking of 'make distcheck', that is broken in the XDR patch, too. include/Makefile.am needs cld_fmt.h added to include_HEADERS.
Jeff
Quoted 45 lines · Colin McCabe
This patch moves CLD from using manual data serialization to using XDR (via rpcgen). Both the packet header and the message body are now serialized and deserialized using XDR. This makes it easy to have a variable-length packet header, as well as a variable-length message body.
Message definitions are now in cld_msg.x. Helper functions for using messages are in
cld_fmt.c. The new client and server-side functions for sending messages don't require the caller to precompute the size of the message. Instead, you simply tell it what type of message you have, and give it the data. It handles determining message size and encoding.The only fields that I did not choose to deal with using XDR are the packet sequence ID and the packet SHA checksum. The seqid would have been inconvenient and inefficient to store in the XDR header, because we have to check a lot of packets' seqids against the ACKs we receive very frequently. The SHA checksum can't be computed until the rest of the packet has been serialized, which is counter to the way XDR works (it is a single-pass serialization system.) So these fields are in the packet footer, which comes at the end of every packet.
This patch introduces a minor libcldc API change in struct
cldc_call_opts.Signed-off-by Colin McCabe<[email protected]>--- .gitignore | 4 + include/Makefile.am | 2 +- include/cld_common.h | 10 + include/cld_fmt.h | 78 ++++ include/cld_msg.h | 252 ------------- include/cldc.h | 37 +- lib/Makefile.am | 14 +- lib/cld_fmt.c | 189 ++++++++++ lib/cld_msg_rpc.x | 212 +++++++++++ lib/cldc.c | 960 +++++++++++++++++++++--------------------------- lib/common.c | 6 +- server/Makefile.am | 9 +- server/cld.h | 97 ++++-- server/cldb.h | 2 +- server/msg.c | 304 ++++++---------- server/server.c | 743 ++++++++++++++++++++----------------- server/session.c | 396 ++++++++++----------- test/load-file-event.c | 14 +- test/save-file-event.c | 2 - tools/cldcli.c | 22 +- 20 files changed, 1744 insertions(+), 1609 deletions(-)
Quoted 4 lines
create mode 100644
include/cld_fmt.h
delete mode 100644include/cld_msg.h
create mode 100644lib/cld_fmt.c
create mode 100644lib/cld_msg_rpc.x
OK, final review. Please fix these problems and resend (some of these repeated from other emails; putting here to consolidate):
* needs to build patch builds and runs against a fresh git repo clone + ./autogen.sh + ./configure + make distcheck
* one build fix I applied was adding the generated header to BUILT_SOURCES in lib/Makefile.am, referring to http://www.gnu.org/software/automake/manual/automake.html#Sources
* make sure the generated header can be found for distcheck builds. For me, I needed to add lib/ to the INCLUDE dirs. YMMV. As Pete says, better solutions could be found. You could always put cld_msg_rpc.x in include/, generate the XDR header first thing (reorder SUBDIRS in ./Makefile.am), and then generate the xdr.c file by referencing source file ../include/cld_msg_rpc.x.
It's ugly, but cld_msg_rpc.h is definitely an exported header that needs special treatment. This solution, as a side effect, would work within existing INCLUDES Makefile.am setups.
* include/Makefile.am needs cld_fmt.h added to include_HEADERS
* verify that 'make clean' and 'make distclean' work as expected, removing the built objects (clean) and generated source files (distclean). distclean requires a ./configure step before the tree is buildable... ie. it takes the working tree back to just-unpacked-from-tarball state.
* you increased the size of struct cldc_call_opts to over 256k! That is unworkable in multi-thread programs, where struct cldc_call_opts may be allocated on the stack -- as it is in most of the tool and test code using libcldc. another solution, acceptable to usage within a thread (often limited to 8k stacks) must be found.
* it would be nice if this patch were separated out a bit, as there are a lot of semi-related changes and cleanups mixed in amongst the XDR conversion. These changes are technically correct, such as
lib/cldc.c static void cldc_errlog(int prio, const char *fmt, ...) · line 167
Quoted 9 lines
lib/cldc.c +5
-4-HAIL_DEBUG (&sess->log,"rx_gen: comparing req->xid (%llu) " -"with resp->xid_in (%llu)" , - (unsigned long long )le64_to_cpu (req->xid), - (unsigned long long )le64_to_cpu (resp->xid_in)); +HAIL_DEBUG (&sess->log,"%s: comparing req->xid (%llu) " +"with resp.xid_in (%llu)" , + __func__, + (unsigned long long ) req->xid, + (unsigned long long ) resp.xid_in);
but adding __func__ to HAIL_DEBUG() statement is clearly not something strictly related to XDR conversion. Pulling out these cleanups into a patch 1/2 would make XDR patch, 2/2, a much smaller patch. It's not a _huge_ deal, if the split is large PITA, but it is preferred to separate out logical change sets.
other, minor stuff:
-------------------
* do we really need separate pkt_is_first() and pkt_is_last() ? I tend to prefer a flags-based approach, where the code tests bits in a 'flags' variable.
* the stuff in cld_fmt.h is essentially global application identifier namespace. as such, exporting functions like 'dump_buf' or 'opstr' may run into trouble. suggest '__cld_' prefix, perhaps.
Overall, though, great work! The change is accepted in principle; I think the patch needs some revisions, but we definitely want this change. It will make non-C language clients easier to write and maintain, better document the network protocol, and reduce the difficulty of changing the network protocol.
Jeff
Quoted 5 lines · Jeff Garzik
OK, final review. Please fix these problems and resend (some of these repeated from other emails; putting here to consolidate):
* needs to build patch builds and runs against a fresh git repo clone + ./autogen.sh + ./configure + make distcheck...
Arg! Looks like it needs more work in the automake department.
FWIW (which isn't much), ./autogen + ./configure + make did work for me. I probably had some previous build products hanging around in the system include paths.
Also, your point about "make clean" is well taken.
Quoted 5 lines
* you increased the size of struct
cldc_call_optsto over 256k! That is unworkable in multi-thread programs, where structcldc_call_optsmay be allocated on the stack -- as it is in most of the tool and test code using libcldc. another solution, acceptable to usage within a thread (often limited to 8k stacks) must be found.
Good point. It could be solved by dynamically allocating the buffer, or by moving the statically allocated temporary buffer into cldc_session. Dynamic allocation is probably better, but it will require API users to free the buffer after use.
Quoted 3 lines
* it would be nice if this patch were separated out a bit, as there are a lot of semi-related changes and cleanups mixed in amongst the XDR conversion.
I'm not 100% sure how much work this would be. I can take a look, at least...
Quoted 3 lines
* do we really need separate
pkt_is_first()andpkt_is_last()? I tend to prefer a flags-based approach, where the code tests bits in a 'flags' variable.
I'll make it flag-based.
Quoted 4 lines
* the stuff in
cld_fmt.his essentially global application identifier namespace. as such, exporting functions like 'dump_buf' or 'opstr' may run into trouble. suggest '__cld_' prefix, perhaps.
Yeah, cld_fmt.c functions get linked into libcldc, so it's best to prefix them with "cldc_"
sincerely,
Colin