[sheepdog] [PATCH v2 2/2] sheep: add test stub in http/swift
Robin Dong
robin.k.dong at gmail.com
Fri Nov 29 10:10:32 CET 2013
Add uri "/test_lock" and "/test_unlock" for swift so users can
test zk_mutex from web browser.
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
sheep/http/swift.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/sheep/http/swift.c b/sheep/http/swift.c
index 7b3354a..941a7b1 100644
--- a/sheep/http/swift.c
+++ b/sheep/http/swift.c
@@ -9,9 +9,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sheep_priv.h"
#include "http.h"
#include "kv.h"
+#define TEST_MUTEX_ID 2013
+static struct dist_mutex test_mutex;
+
static void make_bucket_path(char *bucket, size_t size, const char *account,
const char *container)
{
@@ -166,6 +170,10 @@ static void swift_delete_object(struct http_request *req, const char *account,
static int swift_init(const char *option)
{
+ if (sys->cdrv->init_mutex(&test_mutex, TEST_MUTEX_ID)) {
+ sd_err("Failed to init mutex %u", TEST_MUTEX_ID);
+ return -1;
+ }
return 0;
}
@@ -192,6 +200,14 @@ static void swift_handle_request(struct http_request *req,
sd_info("%s", str_http_req(req));
+ if (!strcmp("/test_lock", req->uri)) {
+ sys->cdrv->lock_mutex(&test_mutex);
+ sd_debug("--- lock ---");
+ } else if (!strcmp("/test_unlock", req->uri)) {
+ sys->cdrv->unlock_mutex(&test_mutex);
+ sd_debug("--- unlock ---");
+ }
+
if (account == NULL) {
sd_info("invalid uri: %s", req->uri);
http_response_header(req, NOT_FOUND);
--
1.7.1
More information about the sheepdog
mailing list