Skip to contentSkip to conversation

cld: Create cldc_call_opts_get_data API for GET

PATCH In review Colin McCabe 2 participants 5 messages Feb 4, 2010 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 cld: Create cldc_call_opts_get_data API for GET

Create the cldc_call_opts_get_data API. This allows users of the async CLD api to access the GET buffer returned from CLD without playing with parts of the cld_call_opts marked 'private, lib-owned.'

---
 include/cldc.h         |    2 ++
 lib/cldc.c             |    7 +++++++
 test/load-file-event.c |    7 +++++--
 tools/cldcli.c         |   23 ++++++++++++++++-------
 4 files changed, 30 insertions(+), 9 deletions(-)
include/cldc.h +2 -0
index 0f4242e..afcba71 100644
@@ -209,6 +209,8 @@ extern int cldc_dirent_next(struct cld_dirent_cur *dc);
 extern void cldc_dirent_cur_init(struct cld_dirent_cur *dc, const void *buf, size_t buflen);
 extern void cldc_dirent_cur_fini(struct cld_dirent_cur *dc);
 extern char *cldc_dirent_name(struct cld_dirent_cur *dc);
+extern void cldc_call_opts_get_data(const struct cldc_call_opts *copts,
+				const char **data, size_t *data_len);
 
 /* cldc-udp */
 extern void cldc_udp_free(struct cldc_udp *udp);
lib/cldc.c +7 -0
index 50f102f..56070e2 100644
@@ -1308,6 +1308,13 @@ char *cldc_dirent_name(struct cld_dirent_cur *dc)
 	return s;
 }
 
+void cldc_call_opts_get_data(const struct cldc_call_opts *copts,
+				const char **data, size_t *data_len)
+{
+	*data = copts->u.get.buf;
+	*data_len = copts->u.get.size;
+}
+
 /*
  * For extra safety, call cldc_init after g_thread_init, if present.
  * Currently we just call srand(), but since we use GLib, we may need
test/load-file-event.c +5 -2
index 94e0421..477cad8 100644
@@ -147,18 +147,21 @@ static int read_1_cb(struct cldc_call_opts *coptarg, enum cle_err_codes errc)
 	struct run *rp = coptarg->private;
 	struct cldc_call_opts copts;
 	int rc;
+	const char *data;
+	size_t data_len;
 
 	if (errc != CLE_OK) {
 		fprintf(stderr, "first-get failed: %d\n", errc);
 		exit(1);
 	}
 
-	if (coptarg->u.get.size != TESTLEN) {
+	cldc_call_opts_get_data(coptarg, &data, &data_len);
+	if (data_len != TESTLEN) {
 		fprintf(stderr, "Bad CLD file length %d\n", coptarg->u.get.size);
 		exit(1);
 	}
 
-	if (memcmp(coptarg->u.get.buf, TESTSTR, TESTLEN)) {
+	if (memcmp(data, TESTSTR, TESTLEN)) {
 		fprintf(stderr, "Bad CLD file content\n");
 		exit(1);
 	}
tools/cldcli.c +16 -7
index c4735d0..567a5c5 100644
@@ -217,6 +217,8 @@ static int cb_ls_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 	struct cldc_call_opts copts = { NULL, };
 	struct cld_dirent_cur dc;
 	int rc, i;
+	const char *data;
+	size_t data_len;
 	bool first = true;
 
 	if (errc != CLE_OK) {
@@ -224,8 +226,9 @@ static int cb_ls_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 		write_from_thread(&cresp, sizeof(cresp));
 		return 0;
 	}
+	cldc_call_opts_get_data(copts_in, &data, &data_len);
 
-	rc = cldc_dirent_count(copts_in->u.get.buf, copts_in->u.get.size);
+	rc = cldc_dirent_count(data, data_len);
 	if (rc < 0) {
 		write_from_thread(&cresp, sizeof(cresp));
 		return 0;
@@ -236,7 +239,7 @@ static int cb_ls_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 
 	write_from_thread(&cresp, sizeof(cresp));
 
-	cldc_dirent_cur_init(&dc, copts_in->u.get.buf, copts_in->u.get.size);
+	cldc_dirent_cur_init(&dc, data, data_len);
 
 	for (i = 0; i < rc; i++) {
 		struct ls_rec lsr;
@@ -294,6 +297,8 @@ static int cb_cat_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 {
 	struct cresp cresp = { .tcode = TC_FAILED, };
 	struct cldc_call_opts copts = { NULL, };
+	const char *data;
+	size_t data_len;
 
 	if (errc != CLE_OK) {
 		errc_msg(&cresp, errc);
@@ -301,11 +306,13 @@ static int cb_cat_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 		return 0;
 	}
 
+	cldc_call_opts_get_data(copts_in, &data, &data_len);
+
 	cresp.tcode = TC_OK;
-	cresp.u.file_len = copts_in->u.get.size;
+	cresp.u.file_len = data_len;
 
 	write_from_thread(&cresp, sizeof(cresp));
-	write_from_thread(copts_in->u.get.buf, copts_in->u.get.size);
+	write_from_thread(data, data_len);
 
 	/* FIXME: race; should wait until close succeeds/fails before
 	 * returning any data.  'fh' may still be in use, otherwise.
@@ -338,18 +345,20 @@ static int cb_cp_cf_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 {
 	struct cresp cresp = { .tcode = TC_FAILED, };
 	struct cldc_call_opts copts = { NULL, };
+	const char *data;
+	size_t data_len;
 
 	if (errc != CLE_OK) {
 		errc_msg(&cresp, errc);
 		write_from_thread(&cresp, sizeof(cresp));
 		return 0;
 	}
-
+	cldc_call_opts_get_data(copts_in, &data, &data_len);
 	cresp.tcode = TC_OK;
-	cresp.u.file_len = copts_in->u.get.size;
+	cresp.u.file_len = data_len;
 
 	write_from_thread(&cresp, sizeof(cresp));
-	write_from_thread(copts_in->u.get.buf, copts_in->u.get.size);
+	write_from_thread(data, data_len);
 
 	/* FIXME: race; should wait until close succeeds/fails before
 	 * returning any data.  'fh' may still be in use, otherwise.
Signature · 1 line
1.6.2.5
#1 lore raw

PATCH 2/3 cld: Add XDR files to gitignore

---
 .gitignore |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
.gitignore +4 -0
index 79a4cd3..805fa22 100644
@@ -32,5 +32,9 @@ cld-config.h*
 cscope.*
 ncscope.*
 
+# XDR files
+*_rpc.h
+*_rpc_xdr.c
+
 # ignore Doxygen output directory
 gendoc
Signature · 1 line
1.6.2.5
#2 lore raw

Re: [PATCH 2/3] cld: Add XDR files to gitignore

Quoted 4 lines · Colin McCabe
---
  .gitignore |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)

While patch #1 seems OK at first glance, patches 2 and 3 definitely belong in the big XDR patch, because they refer to things not yet in the tree.

Cosmetic patches breaking lines or moving code around are fine, in preparation for an upcoming patch. Those can be thought of as logically separate from the big XDR patch, even if they are -preparing- for said patch. For example, I am thinking that the next move might be to move existing code into smaller functions as you did -- ie. accept_seqid() -- while still keeping the existing, pre-XDR code logic. That makes the diff smaller, easier to read and review, while not specifically doing anything XDR related.

Jeff

#3 lore raw

PATCH 3/3 cld: Add XDR support to lib/Makefile.am

In reply to Colin McCabe

Add support for processing XDR files to lib/Makefile.am

---
 lib/Makefile.am |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
lib/Makefile.am +9 -0
index e6509e4..7d5f8c2 100644
@@ -5,6 +5,15 @@ EXTRA_DIST =
 INCLUDES		= -I$(top_srcdir)/include	\
 			  @GLIB_CFLAGS@
 
+mostlyclean-local:
+	rm -f *_rpc.h *_rpc_xdr.c
+
+%_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
Signature · 1 line
1.6.2.5
#4 lore raw
In reply to Colin McCabe
Quoted 5 lines · Colin McCabe

Create the cldc_call_opts_get_data API. This allows users of the async CLD api to access the GET buffer returned from CLD without playing with parts of the cld_call_opts marked 'private, lib-owned.'

applied as commit 6d74266c8bdb4f74668b86157b3e044b96b8d06e. I cosmetically modified the changes in your patch, so as to better sync up precisely with the code locations in the XDR patch.

Attached is my XDR working tree, as of commit 6d74266c8bdb4f74668b86157b3e044b96b8d06e.

.gitignore +4 -0
diff -X /garz/tmp/dontdiff -urNp cld/.gitignore cld.rpcgen/.gitignore
@@ -32,5 +32,9 @@ cld-config.h*
 cscope.*
 ncscope.*
 
+# XDR files
+*_rpc.h
+*_rpc_xdr.c
+
 # ignore Doxygen output directory
 gendoc
include/cldc.h +12 -19
diff -X /garz/tmp/dontdiff -urNp cld/include/cldc.h cld.rpcgen/include/cldc.h
@@ -22,7 +22,7 @@
 #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,34 +35,27 @@ 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 + 1];
-		} get;
-	} u;
+	struct cld_msg_get_resp resp;
 };
 
 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_op op;
 	struct cldc_session *sess;
 
 	ssize_t		(*cb)(struct cldc_msg *, const void *, size_t,
-			      enum cle_err_codes);
+				enum cle_err_codes resp_rc);
 	void		*cb_private;
 
 	struct cldc_call_opts copts;
@@ -71,18 +64,15 @@ struct cldc_msg {
 
 	time_t		expire_time;
 
-	int		data_len;
 	int		n_pkts;
 
-	uint8_t		*data;
-
 	/* must be at end of struct */
 	struct cldc_pkt_info *pkt_info[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;
 };
@@ -129,8 +119,11 @@ struct cldc_session {
 
 	bool		confirmed;
 
+	enum cld_msg_op msg_buf_op;
 	unsigned int	msg_buf_len;
 	char		msg_buf[CLD_MAX_MSG_SZ];
+	char		payload[CLD_MAX_PAYLOAD_SZ];
+	char		inode_name_temp[CLD_INODE_NAME_MAX];
 };
 
 /** Information for a single CLD server host */
@@ -210,7 +203,7 @@ extern void cldc_dirent_cur_init(struct 
 extern void cldc_dirent_cur_fini(struct cld_dirent_cur *dc);
 extern char *cldc_dirent_name(struct cld_dirent_cur *dc);
 extern void cldc_call_opts_get_data(const struct cldc_call_opts *copts,
-				    const char **data, size_t *data_len);
+				    char **data, size_t *data_len);
 
 /* cldc-udp */
 extern void cldc_udp_free(struct cldc_udp *udp);
include/cld_common.h +2 -2
diff -X /garz/tmp/dontdiff -urNp cld/include/cld_common.h cld.rpcgen/include/cld_common.h
@@ -3,7 +3,6 @@
 
 /*
  * Copyright 2009 Red Hat, Inc.
- * Copyright 2010, Colin McCabe
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +23,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <time.h>
+#include <cld_msg_rpc.h>
 
 #define CLD_ALIGN8(n) ((8 - ((n) & 7)) & 7)
 
@@ -91,7 +91,7 @@ extern int __cld_authsign(struct hail_lo
 			  const void *buf, size_t buf_len, void *sha);
 
 /* Returns a constant string representing a message operation */
-extern const char *__cld_opstr(enum cld_msg_ops op);
+extern const char *__cld_opstr(enum cld_msg_op);
 
 /*
  * We use a unified format for sid so it can be searched in log files (* in vi).
include/cld_msg.h +0 -245

245 lines not on this page · raw message

include/cld_pkt.h +56 -0

56 lines not on this page · raw message

include/Makefile.am +1 -1
diff -X /garz/tmp/dontdiff -urNp cld/include/Makefile.am cld.rpcgen/include/Makefile.am
@@ -1,5 +1,5 @@
 
 EXTRA_DIST = cld-private.h
 
-include_HEADERS = cldc.h hail_log.h cld_common.h cld_msg.h
+include_HEADERS = cldc.h hail_log.h cld_common.h cld_pkt.h
 
lib/cldc.c +343 -383

1,157 lines not on this page · raw message

lib/cld_msg_rpc.x +218 -0

218 lines not on this page · raw message

lib/common.c +5 -1
diff -X /garz/tmp/dontdiff -urNp cld/lib/common.c cld.rpcgen/lib/common.c
@@ -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]))
lib/Makefile.am +14 -1
diff -X /garz/tmp/dontdiff -urNp cld/lib/Makefile.am cld.rpcgen/lib/Makefile.am
@@ -1,10 +1,21 @@
 
+BUILT_SOURCES		= cld_msg_rpc.h
+
 EXTRA_DIST =
 	libcldc.pc.in libcldc-uninstalled.pc.in
 
 INCLUDES		= -I$(top_srcdir)/include	\
 			  @GLIB_CFLAGS@
 
+mostlyclean-local:
+	rm -f *_rpc.h *_rpc_xdr.c
+
+%_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
@@ -15,7 +26,8 @@ libcldc_la_SOURCES	=	\
 	cldc-dns.c		\
 	common.c		\
 	libtimer.c		\
-	pkt.c
+	pkt.c			\
+	cld_msg_rpc_xdr.c
 
 libcldc_la_LDFLAGS = \
 	-version-info $(LIBCLDC_CURRENT):$(LIBCLDC_REVISION):$(LIBCLDC_AGE) \
@@ -25,3 +37,4 @@ libcldc_la_LDFLAGS = \
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libcldc.pc
 
+include_HEADERS = cld_msg_rpc.h
lib/pkt.c +100 -2

121 lines not on this page · raw message

server/cldb.h +1 -1
diff -X /garz/tmp/dontdiff -urNp cld/server/cldb.h cld.rpcgen/server/cldb.h
@@ -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/cld.h +66 -29

134 lines not on this page · raw message

server/Makefile.am +3 -1
diff -X /garz/tmp/dontdiff -urNp cld/server/Makefile.am cld.rpcgen/server/Makefile.am
@@ -1,5 +1,6 @@
 
 INCLUDES	= -I$(top_srcdir)/include	\
+		  -I$(top_srcdir)/lib		\
 		  @GLIB_CFLAGS@			\
 		  -DCLD_LIBDIR=\""$(libdir)"\"	\
 		  -DCLD_LOCAL_STATE_DIR="\"$(localstatedir)\""
@@ -8,7 +9,8 @@ sbin_PROGRAMS	= cld cldbadm
 
 cld_SOURCES	= cldb.h cld.h \
 		  ../lib/common.c ../lib/libtimer.c ../lib/pkt.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	= @CRYPTO_LIBS@ @GLIB_LIBS@ @DB4_LIBS@
 
 cldbadm_SOURCES	= cldb.h cldbadm.c
server/msg.c +102 -195

604 lines not on this page · raw message

server/server.c +418 -283

273 lines not on this page · raw message

server/session.c +186 -223

409 lines not on this page · raw message

test/load-file-event.c +1 -1
diff -X /garz/tmp/dontdiff -urNp cld/test/load-file-event.c cld.rpcgen/test/load-file-event.c

Lines of this file are not shown. View the raw message.

test/Makefile.am +1 -0
diff -X /garz/tmp/dontdiff -urNp cld/test/Makefile.am cld.rpcgen/test/Makefile.am

Lines of this file are not shown. View the raw message.

tools/cldcli.c +3 -3
diff -X /garz/tmp/dontdiff -urNp cld/tools/cldcli.c cld.rpcgen/tools/cldcli.c

Lines of this file are not shown. View the raw message.

tools/Makefile.am +1 -0
diff -X /garz/tmp/dontdiff -urNp cld/tools/Makefile.am cld.rpcgen/tools/Makefile.am

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.