The last stage in the user-visible conversion. Further changes will likely take place under the hood, such as storing tiny objects in a DBM (Tokyo Cabinet?) rather than the current one-obj-per-file approach. commit efef1eaf3a81ece54a761478cb8a72780556e97e Author: Jeff Garzik <jeff@xxxxxxxxxx> Date: Thu Nov 5 00:48:07 2009 -0500 libchunkd: API changes to support arbitrary length binary keys Signed-off-by: Jeff Garzik <jgarzik@xxxxxxxxxx> diff --git a/include/chunkc.h b/include/chunkc.h index 1cc8cc7..5e9af58 100644 --- a/include/chunkc.h +++ b/include/chunkc.h @@ -5,6 +5,7 @@ #include <openssl/ssl.h> #include <stdbool.h> #include <stdint.h> +#include <string.h> #include <glib.h> #include <chunk_msg.h> @@ -44,28 +45,58 @@ extern struct st_client *stc_new(const char *service_host, int port, const char *user, const char *secret_key, bool encrypt); -extern bool stc_get(struct st_client *stc, const char *key, +extern bool stc_get(struct st_client *stc, const void *key, size_t key_len, size_t (*write_cb)(void *, size_t, size_t, void *), void *user_data); extern void *stc_get_inline(struct st_client *stc, - const char *key, size_t *len); -extern bool stc_get_start(struct st_client *stc, const char *key, int *pfd, - uint64_t *len); + const void *key, size_t key_len, size_t *len); +extern bool stc_get_start(struct st_client *stc, const void *key, + size_t key_len,int *pfd, uint64_t *len); extern size_t stc_get_recv(struct st_client *stc, void *data, size_t len); -extern bool stc_put(struct st_client *stc, const char *key, +extern bool stc_put(struct st_client *stc, const void *key, size_t key_len, size_t (*read_cb)(void *, size_t, size_t, void *), uint64_t len, void *user_data); -extern bool stc_put_start(struct st_client *stc, const char *key, - uint64_t cont_len, int *pfd); +extern bool stc_put_start(struct st_client *stc, const void *key, + size_t key_len, uint64_t cont_len, int *pfd); extern size_t stc_put_send(struct st_client *stc, void *data, size_t len); extern bool stc_put_sync(struct st_client *stc); -extern bool stc_put_inline(struct st_client *stc, const char *key, - void *data, uint64_t len); -extern bool stc_del(struct st_client *stc, const char *key); +extern bool stc_put_inline(struct st_client *stc, const void *key, + size_t key_len, void *data, uint64_t len); +extern bool stc_del(struct st_client *stc, const void *key, size_t key_len); extern bool stc_ping(struct st_client *stc); extern struct st_keylist *stc_keys(struct st_client *stc); extern int stc_readport(const char *fname); +static inline void *stc_get_inlinez(struct st_client *stc, + const char *key, + size_t *len) +{ + return stc_get_inline(stc, key, strlen(key) + 1, len); +} + +static inline bool stc_get_startz(struct st_client *stc, const char *key, + int *pfd, uint64_t *len) +{ + return stc_get_start(stc, key, strlen(key) + 1, pfd, len); +} + +static inline bool stc_put_inlinez(struct st_client *stc, const char *key, + void *data, uint64_t len) +{ + return stc_put_inline(stc, key, strlen(key) + 1, data, len); +} + +static inline bool stc_put_startz(struct st_client *stc, const char *key, + uint64_t cont_len, int *pfd) +{ + return stc_put_start(stc, key, strlen(key) + 1, cont_len, pfd); +} + +static inline bool stc_delz(struct st_client *stc, const char *key) +{ + return stc_del(stc, key, strlen(key) + 1); +} + #endif /* __STC_H__ */ diff --git a/lib/chunkdc.c b/lib/chunkdc.c index 73731d4..86fc257 100644 --- a/lib/chunkdc.c +++ b/lib/chunkdc.c @@ -228,14 +228,14 @@ static size_t all_data_cb(void *ptr, size_t size, size_t nmemb, void *user_data) /* * Request the transfer in the chunk server. */ -static bool stc_get_req(struct st_client *stc, const char *key, uint64_t *plen) +static bool stc_get_req(struct st_client *stc, const void *key, + size_t key_len, uint64_t *plen) { struct chunksrv_resp_get get_resp; struct chunksrv_req *req = (struct chunksrv_req *) stc->req_buf; - size_t key_len = strlen(key) + 1; /* string content + nul */ if (stc->verbose) - fprintf(stderr, "libstc: GET(%s)\n", key); + fprintf(stderr, "libstc: GET(%u)\n", (unsigned int) key_len); if (key_len > CHD_KEY_SZ) return false; @@ -272,14 +272,14 @@ static bool stc_get_req(struct st_client *stc, const char *key, uint64_t *plen) return true; } -bool stc_get(struct st_client *stc, const char *key, +bool stc_get(struct st_client *stc, const void *key, size_t key_len, size_t (*write_cb)(void *, size_t, size_t, void *), void *user_data) { char netbuf[4096]; uint64_t content_len; - if (!stc_get_req(stc, key, &content_len)) + if (!stc_get_req(stc, key, key_len, &content_len)) return false; /* read response data */ @@ -297,7 +297,8 @@ bool stc_get(struct st_client *stc, const char *key, return true; } -void *stc_get_inline(struct st_client *stc, const char *key, size_t *len) +void *stc_get_inline(struct st_client *stc, const void *key, + size_t key_len, size_t *len) { bool rcb; void *mem; @@ -307,7 +308,7 @@ void *stc_get_inline(struct st_client *stc, const char *key, size_t *len) if (!all_data) return NULL; - rcb = stc_get(stc, key, all_data_cb, all_data); + rcb = stc_get(stc, key, key_len, all_data_cb, all_data); if (!rcb) { g_byte_array_free(all_data, TRUE); return NULL; @@ -327,11 +328,11 @@ void *stc_get_inline(struct st_client *stc, const char *key, size_t *len) * In chunkd protocol, this delivers the size of the presumed object, * and clients are expected to fetch exactly psize amount. */ -bool stc_get_start(struct st_client *stc, const char *key, int *pfd, - uint64_t *psize) +bool stc_get_start(struct st_client *stc, const void *key, size_t key_len, + int *pfd, uint64_t *psize) { - if (!stc_get_req(stc, key, psize)) + if (!stc_get_req(stc, key, key_len, psize)) return false; *pfd = stc->fd; @@ -401,7 +402,7 @@ size_t stc_get_recv(struct st_client *stc, void *data, size_t data_len) return done_cnt; } -bool stc_put(struct st_client *stc, const char *key, +bool stc_put(struct st_client *stc, const void *key, size_t key_len, size_t (*read_cb)(void *, size_t, size_t, void *), uint64_t len, void *user_data) { @@ -409,10 +410,10 @@ bool stc_put(struct st_client *stc, const char *key, struct chunksrv_resp resp; uint64_t content_len = len; struct chunksrv_req *req = (struct chunksrv_req *) stc->req_buf; - size_t key_len = strlen(key) + 1; /* string content + nul */ if (stc->verbose) - fprintf(stderr, "libstc: PUT(%s, %Lu)\n", key, + fprintf(stderr, "libstc: PUT(%u, %Lu)\n", + (unsigned int) key_len, (unsigned long long) len); if (key_len > CHD_KEY_SZ) @@ -470,14 +471,14 @@ err_out: * We return the fd for the polling here because we do not like * library users poking around stc->fd, an implementation detail. */ -bool stc_put_start(struct st_client *stc, const char *key, uint64_t cont_len, - int *pfd) +bool stc_put_start(struct st_client *stc, const void *key, size_t key_len, + uint64_t cont_len, int *pfd) { struct chunksrv_req *req = (struct chunksrv_req *) stc->req_buf; - size_t key_len = strlen(key) + 1; /* string content + nul */ if (stc->verbose) - fprintf(stderr, "libstc: PUT(%s, %Lu) start\n", key, + fprintf(stderr, "libstc: PUT(%u, %Lu) start\n", + (unsigned int) key_len, (unsigned long long) cont_len); if (key_len > CHD_KEY_SZ) @@ -599,22 +600,22 @@ static size_t read_inline_cb(void *ptr, size_t size, size_t nmemb, return len; } -bool stc_put_inline(struct st_client *stc, const char *key, +bool stc_put_inline(struct st_client *stc, const void *key, size_t key_len, void *data, uint64_t len) { struct stc_put_info spi = { data, len }; - return stc_put(stc, key, read_inline_cb, len, &spi); + return stc_put(stc, key, key_len, read_inline_cb, len, &spi); } -bool stc_del(struct st_client *stc, const char *key) +bool stc_del(struct st_client *stc, const void *key, size_t key_len) { struct chunksrv_resp resp; struct chunksrv_req *req = (struct chunksrv_req *) stc->req_buf; - size_t key_len = strlen(key) + 1; /* string content + nul */ if (stc->verbose) - fprintf(stderr, "libstc: DEL(%s)\n", key); + fprintf(stderr, "libstc: DEL(%u)\n", + (unsigned int) key_len); if (key_len > CHD_KEY_SZ) return false; diff --git a/test/auth.c b/test/auth.c index 107b988..f927609 100644 --- a/test/auth.c +++ b/test/auth.c @@ -33,11 +33,11 @@ static void test(bool encrypt) OK(stc2); /* store object 1 */ - rcb = stc_put_inline(stc1, key1, val1, strlen(val1)); + rcb = stc_put_inlinez(stc1, key1, val1, strlen(val1)); OK(rcb); /* store object 2 */ - rcb = stc_put_inline(stc2, key2, val2, strlen(val2)); + rcb = stc_put_inlinez(stc2, key2, val2, strlen(val2)); OK(rcb); /* make sure object 1 appears in list of volume keys */ @@ -75,7 +75,7 @@ static void test(bool encrypt) stc_free_keylist(klist); /* get object 1 */ - mem = stc_get_inline(stc1, key1, &len); + mem = stc_get_inlinez(stc1, key1, &len); OK(mem); OK(len == strlen(val1)); OK(!memcmp(val1, mem, strlen(val1))); @@ -83,11 +83,11 @@ static void test(bool encrypt) free(mem); /* fail to get object 2 */ - mem = stc_get_inline(stc1, key2, &len); + mem = stc_get_inlinez(stc1, key2, &len); OK(mem == NULL); /* get object 2 */ - mem = stc_get_inline(stc2, key2, &len); + mem = stc_get_inlinez(stc2, key2, &len); OK(mem); OK(len == strlen(val2)); OK(!memcmp(val2, mem, strlen(val2))); @@ -95,23 +95,23 @@ static void test(bool encrypt) free(mem); /* fail to get object 1 */ - mem = stc_get_inline(stc2, key1, &len); + mem = stc_get_inlinez(stc2, key1, &len); OK(mem == NULL); /* fail to delete object 2 */ - rcb = stc_del(stc1, key2); + rcb = stc_delz(stc1, key2); OK(rcb == false); /* fail to delete object 1 */ - rcb = stc_del(stc2, key1); + rcb = stc_delz(stc2, key1); OK(rcb == false); /* delete object 1 */ - rcb = stc_del(stc1, key1); + rcb = stc_delz(stc1, key1); OK(rcb); /* delete object 2 */ - rcb = stc_del(stc2, key2); + rcb = stc_delz(stc2, key2); OK(rcb); stc_free(stc1); diff --git a/test/basic-object.c b/test/basic-object.c index 7abb1d7..12652d5 100644 --- a/test/basic-object.c +++ b/test/basic-object.c @@ -28,7 +28,7 @@ static void test(bool encrypt) OK(stc); /* store object */ - rcb = stc_put_inline(stc, key, val, strlen(val)); + rcb = stc_put_inlinez(stc, key, val, strlen(val)); OK(rcb); /* make sure object appears in list of volume keys */ @@ -49,7 +49,7 @@ static void test(bool encrypt) stc_free_keylist(klist); /* get object */ - mem = stc_get_inline(stc, key, &len); + mem = stc_get_inlinez(stc, key, &len); OK(mem); OK(len == strlen(val)); OK(!memcmp(val, mem, strlen(val))); @@ -57,7 +57,7 @@ static void test(bool encrypt) free(mem); /* delete object */ - rcb = stc_del(stc, key); + rcb = stc_delz(stc, key); OK(rcb); stc_free(stc); diff --git a/test/large-object.c b/test/large-object.c index d97ce21..d9a3a2d 100644 --- a/test/large-object.c +++ b/test/large-object.c @@ -98,7 +98,7 @@ static void test(bool encrypt) gettimeofday(&ta, NULL); /* store object */ - rcb = stc_put_start(stc, key, N_BUFS * BUFSZ, &sfd); + rcb = stc_put_startz(stc, key, N_BUFS * BUFSZ, &sfd); OK(rcb); for (i = 0; i < N_BUFS; i++) { rcb = send_buf(stc, sfd, data, BUFSZ); @@ -132,7 +132,7 @@ static void test(bool encrypt) gettimeofday(&ta, NULL); /* initiate get object */ - rcb = stc_get_start(stc, key, &rfd, &len); + rcb = stc_get_startz(stc, key, &rfd, &len); OK(rcb); OK(len == (N_BUFS * BUFSZ)); @@ -149,7 +149,7 @@ static void test(bool encrypt) } /* delete object */ - rcb = stc_del(stc, key); + rcb = stc_delz(stc, key); OK(rcb); stc_free(stc); diff --git a/test/lotsa-objects.c b/test/lotsa-objects.c index a26ecc0..c3e54c5 100644 --- a/test/lotsa-objects.c +++ b/test/lotsa-objects.c @@ -41,7 +41,7 @@ static void test(int n_objects, bool encrypt) /* store object */ for (i = 0; i < n_objects; i++) { sprintf(key, "%x000000", i); - rcb = stc_put_inline(stc, key, val, strlen(val)); + rcb = stc_put_inlinez(stc, key, val, strlen(val)); OK(rcb); keys = g_list_prepend(keys, strdup(key)); @@ -88,7 +88,7 @@ static void test(int n_objects, bool encrypt) k = tmpl->data; len = 0; - mem = stc_get_inline(stc, k, &len); + mem = stc_get_inlinez(stc, k, &len); OK(mem); OK(len == strlen(val)); OK(!memcmp(val, mem, strlen(val))); @@ -106,7 +106,7 @@ static void test(int n_objects, bool encrypt) /* delete object */ for (tmpl = keys; tmpl; tmpl = tmpl->next) { k = tmpl->data; - rcb = stc_del(stc, k); + rcb = stc_delz(stc, k); OK(rcb); free(k); -- To unsubscribe from this list: send the line "unsubscribe hail-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html