From b324e317311974fbbb9ba13548364213a7a7a41a Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Thu, 12 Jul 2012 15:40:43 -0700 Subject: glfsxmp: libgfapi based example This is an example application which uses libgfapi. It is a complete autotools based build system which demonstrates the required changes in configure.ac, Makefile.am etc to successfuly detect for and build an application against libgfapi. There are two approaches to building a libgfapi based application: 1. In the presence of pkg-config in your build system. This is the recommended approach which is also used in this example. For this approach to work, you need to build glusterfs by passing --pkgconfigdir=/usr/lib64/pkgconfig (or the appropriate directory) in your distro. This already happens if you build RPMs with the glusterfs.spec provided in glusterfs.git. You will also need to install glusterfs-api RPM. 2. In the absence of pkg-config in your build system. Make sure your LDFLAGS includes -L/path/to/lib where libgfapi.so is installed and -I/path/to/include/glusterfs where the 'api' directory Change-Id: Ic4eab2df002d7e8d20593a03e643859423048848 BUG: 839950 Signed-off-by: Anand Avati Reviewed-on: http://review.gluster.com/3666 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi --- api/examples/Makefile.am | 4 ++++ api/examples/README | 19 ++++++++++++++++ api/examples/autogen.sh | 5 +++++ api/examples/configure.ac | 12 ++++++++++ api/examples/glfsxmp.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 api/examples/Makefile.am create mode 100644 api/examples/README create mode 100755 api/examples/autogen.sh create mode 100644 api/examples/configure.ac create mode 100644 api/examples/glfsxmp.c (limited to 'api/examples') diff --git a/api/examples/Makefile.am b/api/examples/Makefile.am new file mode 100644 index 00000000000..6048bb1c8b7 --- /dev/null +++ b/api/examples/Makefile.am @@ -0,0 +1,4 @@ +noinst_PROGRAMS = glfsxmp +glfsxmp_SOURCES = glfsxmp.c +glfsxmp_CFLAGS = $(GLFS_CFLAGS) -Wall +glfsxmp_LDADD = $(GLFS_LIBS) \ No newline at end of file diff --git a/api/examples/README b/api/examples/README new file mode 100644 index 00000000000..8f0bab697d3 --- /dev/null +++ b/api/examples/README @@ -0,0 +1,19 @@ +This is an example application which uses libgfapi. It is +a complete autotools based build system which demonstrates the +required changes in configure.ac, Makefile.am etc to successfuly +detect for and build an application against libgfapi. + +There are two approaches to building a libgfapi based application: + +1. In the presence of pkg-config in your build system. +This is the recommended approach which is also used in this example. +For this approach to work, you need to build glusterfs by passing +--pkgconfigdir=/usr/lib64/pkgconfig (or the appropriate directory) +in your distro. This already happens if you build RPMs with the +glusterfs.spec provided in glusterfs.git. You will also need to +install glusterfs-api RPM. + +2. In the absence of pkg-config in your build system. +Make sure your LDFLAGS includes -L/path/to/lib where libgfapi.so is +installed and -I/path/to/include/glusterfs where the 'api' directory +containing the headers are available. diff --git a/api/examples/autogen.sh b/api/examples/autogen.sh new file mode 100755 index 00000000000..1fee6be11bb --- /dev/null +++ b/api/examples/autogen.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +aclocal +autoconf +automake --foreign diff --git a/api/examples/configure.ac b/api/examples/configure.ac new file mode 100644 index 00000000000..b80177a4e87 --- /dev/null +++ b/api/examples/configure.ac @@ -0,0 +1,12 @@ + +AC_INIT([glfs-test],[0.1],[gluster-devel@nongu.org]) + +AM_INIT_AUTOMAKE + +AC_CONFIG_FILES([Makefile]) + +AC_PROG_CC + +PKG_CHECK_MODULES([GLFS], [glusterfs-api >= 3]) + +AC_OUTPUT diff --git a/api/examples/glfsxmp.c b/api/examples/glfsxmp.c new file mode 100644 index 00000000000..1883b54bc92 --- /dev/null +++ b/api/examples/glfsxmp.c @@ -0,0 +1,57 @@ +#include +#include +#include "api/glfs.h" +#include +#include + +int +main (int argc, char *argv[]) +{ + glfs_t *fs = NULL; + int ret = 0; + glfs_fd_t *fd = NULL; + struct stat sb = {0, }; + char readbuf[32]; + char writebuf[32]; + + char *volname = "iops"; + char *filename = "/filename2"; + + fs = glfs_new (volname); + if (!fs) { + fprintf (stderr, "glfs_new: returned NULL\n"); + return 1; + } + +// ret = glfs_set_volfile (fs, "/tmp/filename.vol"); + + ret = glfs_set_volfile_server (fs, "socket", "localhost", 24007); + +// ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); + + ret = glfs_set_logging (fs, "/dev/stderr", 7); + + ret = glfs_init (fs); + + fprintf (stderr, "glfs_init: returned %d\n", ret); + + + ret = glfs_lstat (fs, filename, &sb); + fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + + fd = glfs_creat (fs, filename, O_RDWR, 0644); + fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); + + sprintf (writebuf, "hi there\n"); + ret = glfs_write (fd, writebuf, 32, 0); + + glfs_lseek (fd, 0, SEEK_SET); + + ret = glfs_read (fd, readbuf, 32, 0); + + printf ("read %d, %s", ret, readbuf); + + glfs_close (fd); + + return ret; +} -- cgit