From patchwork Wed Mar 11 02:43:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Shewmaker X-Patchwork-Id: 5981681 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0F8CBBF440 for ; Wed, 11 Mar 2015 02:44:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15A9B203B0 for ; Wed, 11 Mar 2015 02:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1859F2040F for ; Wed, 11 Mar 2015 02:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751981AbbCKCoR (ORCPT ); Tue, 10 Mar 2015 22:44:17 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:44199 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751024AbbCKCoK (ORCPT ); Tue, 10 Mar 2015 22:44:10 -0400 Received: by padet14 with SMTP id et14so7303156pad.11 for ; Tue, 10 Mar 2015 19:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oD2CmbtP6fHP7unnbE69PAeMnpN8p7OhE57M8KtfJs4=; b=oONRGzwws/EMKH9YrMDxO6Bb8P/OrNoRzapUWv3796WKPYSxm4ssGr7pr0anK2THfo FDlkKNFtcVBV1cqi2szRG7Tj40uxX6/ckEgmAs+7tWX8HTBg9dGmDGuy/WWk5ddX5afj SiwyA3b6FWWtwCElahu+VHXrEjjjpKIobX+Xm9ST+Vkxeo+0wztEriWsomdmWa9Bc6aZ SQtzKH4kRl7IU4NhZMd4YvawBMYxocguV6As0Y305PdbuBk9ha63xJp/o7DbE8OplLoH 3zfQhohdxGDQMhcVmhC+SmNBfctjBvW6f9TU2hWddKrRPthv8EuH4rAmzNxgRLlHbED3 aMtw== X-Received: by 10.66.100.138 with SMTP id ey10mr67761235pab.142.1426041850496; Tue, 10 Mar 2015 19:44:10 -0700 (PDT) Received: from scruffy.soe.ucsc.edu (scruffy.soe.ucsc.edu. [128.114.53.124]) by mx.google.com with ESMTPSA id d4sm3179934pdm.50.2015.03.10.19.44.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Mar 2015 19:44:09 -0700 (PDT) From: Andrew Shewmaker To: ceph-devel@vger.kernel.org Cc: agshew@gmail.com, marioskogias@gmail.com, chendi.xue@intel.com Subject: [PATCH V6 5/5] Rados example for blkin (LTTng + Zipkin) tracing Date: Tue, 10 Mar 2015 19:43:30 -0700 Message-Id: <1426041810-3942-6-git-send-email-agshew@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426041810-3942-1-git-send-email-agshew@gmail.com> References: <1426041810-3942-1-git-send-email-agshew@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This code is Marios', with the following exceptions: * split out example from other tracing changes * changed name of example * whitespace issues have been fixed * Makefile cleans up the new example Signed-off-by: Marios-Evaggelos Kogias Signed-off-by: Filippos Giannakos Signed-off-by: Andrew Shewmaker --- Makefile | 9 ++++ hello_blkin.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 examples/librados/hello_blkin.c -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/examples/librados/Makefile b/examples/librados/Makefile index 190cca2..f8d8e1d 100644 --- a/examples/librados/Makefile +++ b/examples/librados/Makefile @@ -1,4 +1,8 @@ +ifdef WITH_BLKIN +all: librados_hello_world librados_hello_world_c librados_hello_blkin +else all: librados_hello_world librados_hello_world_c +endif librados_hello_world: hello_world.cc g++ -g -c hello_world.cc -o hello_world.o $(CFLAGS) @@ -8,6 +12,11 @@ librados_hello_world_c: hello_world_c.c cc -g -c hello_world_c.c -o hello_world_c.o $(CFLAGS) cc -g hello_world_c.o -lrados -o librados_hello_world_c $(LDFLAGS) +librados_hello_blkin: hello_blkin.c + cc -g -c hello_blkin.c -o hello_blkin.o $(CFLAGS) + cc -g hello_blkin.o -lrados -lblkin-front -o librados_hello_blkin $(LDFLAGS) + clean: rm hello_world.o librados_hello_world rm hello_world_c.o librados_hello_world_c + rm hello_blkin.o librados_hello_blkin diff --git a/examples/librados/hello_blkin.c b/examples/librados/hello_blkin.c new file mode 100644 index 0000000..1bc1c50 --- /dev/null +++ b/examples/librados/hello_blkin.c @@ -0,0 +1,107 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include +#include +#include +#include + +#define POOL "data" + +const char *object_name = "hello_world_object"; +const char *object_val = "hello world!"; + +rados_ioctx_t *connect_to_rados() +{ + rados_t rados; + rados_ioctx_t *ioctx = malloc(sizeof(rados_ioctx_t)); + + if (rados_create(&rados, NULL) < 0) { + return NULL; + } + if (rados_conf_read_file(rados, NULL) < 0){ + return NULL; + } + if (rados_connect(rados) < 0) { + printf("Could not connect\n"); + rados_shutdown(rados); + return NULL; + } + if (rados_pool_lookup(rados, POOL) < 0) { + printf("Could not find pool\n"); + rados_shutdown(rados); + return NULL; + } + if (rados_ioctx_create(rados, POOL, ioctx) < 0){ + rados_shutdown(rados); + return NULL; + } + return ioctx; +} + +void end_read(rados_completion_t c, void *arg) +{ + fprintf(stderr, "just read\n"); +} + +void end_write(rados_completion_t c, void *arg) +{ + fprintf(stderr, "just wrote\n"); +} + +int main() +{ + int r, i; + char temp[12]; + rados_completion_t compl; + rados_ioctx_t *rados_ctx; + /*initialize lib*/ + r = blkin_init(); + if (r < 0) { + fprintf(stderr, "Could not initialize blkin\n"); + exit(1); + } + /*initialize endpoint*/ + struct blkin_endpoint endp; + blkin_init_endpoint(&endp, "10.0.0.1", 5000, "rados client"); + struct blkin_trace trace; + blkin_init_new_trace(&trace, "client", &endp); + BLKIN_TIMESTAMP(&trace, &endp, "start"); + + //connect + rados_ctx = connect_to_rados(); + if (rados_ctx == NULL){ + printf("Connect return NULL\n"); + exit(1); + } + printf("connected\n"); + + //write an object + r = rados_aio_create_completion(NULL, end_write, end_write, &compl); + if (r<0) { + printf("could not create completion\n"); + exit(1); + } + printf("created completion\n"); + r = rados_aio_write_traced(*rados_ctx, object_name, compl, object_val, 12, + 0, &trace.info); + + rados_aio_wait_for_complete(compl); + printf("completed\n"); + + //read an object + r = rados_aio_create_completion(NULL, end_read, end_read, &compl); + if (r<0) { + printf("could not create completion\n"); + exit(1); + } + printf("created completion\n"); + r = rados_aio_read_traced(*rados_ctx, object_name, compl, temp, 12, 0, + &trace.info); + rados_aio_wait_for_complete(compl); + printf("I read:\n"); + for (i=0;i<12;i++) + printf("%c",temp[i]); + printf("completed\n"); + BLKIN_TIMESTAMP(&trace, &endp, "Span ended"); +}