Giter VIP home page Giter VIP logo

libgfapi-perl's Introduction

libgfapi-perl

Releases Build Status codecov.io License: GPL v2 License: LGPL v3

GlusterFS libgfapi binding for Perl 5

The libgfapi-perl provides declarations and linkage for the Gluster gfapi C library with FFI for many Perl mongers.

To use it, you can use test code that exists under 't/' directory for reference.

SYNOPSIS

# make GlusterFS Volume instance
my $fs = GlusterFS::GFAPI::FFI::glfs_new('libgfapi-perl');

# set server information for a volume
if (GlusterFS::GFAPI::FFI::glfs_set_volfile_server($fs, 'tcp', 'node1', 24007))
{
    die "Failed to set volfile server: $!";
}

# initialize connection for a GlusterFS Volume
if (GlusterFS::GFAPI::FFI::glfs_init($fs))
{
    die "Failed to init connection: $!";
}

# get a Volume-ID
my $len = 16;
my $id  = "\0" x $len;

if (GlusterFS::GFAPI::FFI::glfs_get_volumeid($fs, $id, $len) < 0)
{
    die "Failed to get volume-id: $!";
}

printf "Volume-ID: %s\n", join('-', unpack('H8 H4 H4 H4 H12', $id));

# get stat for a volume
my $stat = GlusterFS::GFAPI::FFI::Statvfs->new();

if (GlusterFS::GFAPI::FFI::glfs_statvfs($fs, '/', $stat))
{
    die "Failed to get statvfs: $!";
}

printf "- f_bsize   : %d\n",   $stat->f_bsize;
printf "- f_frsize  : %d\n",   $stat->f_frsize;
printf "- f_blocks  : %d\n",   $stat->f_blocks;
printf "- f bfree   : %d\n",   $stat->f_bfree;
printf "- f_bavail  : %d\n",   $stat->f_bavail;
printf "- f_files   : %d\n",   $stat->f_files;
printf "- f_ffree   : %d\n",   $stat->f_ffree;
printf "- f_favail  : %d\n",   $stat->f_favail;
printf "- f_fsid    : %d\n",   $stat->f_fsid;
printf "- f_flag    : 0x%o\n", $stat->f_flag;
printf "- f_namemax : %d\n",   $stat->f_namemax;

# create a file and take file-descriptor
my $fd = GlusterFS::GFAPI::FFI::glfs_creat($fs, "/potato", O_RDWR, 0644);

# get stat for a file
$stat = GlusterFS::GFAPI::FFI::Stat->new();

if (GlusterFS::GFAPI::FFI::glfs_stat($fs, "/potato", $stat))
{
    die "Failed to stat: $!";
}

printf "- ino     : %d\n",   $stat->st_ino;
printf "- mode    : 0x%o\n", $stat->st_mode;
printf "- size    : %d\n",   $stat->st_size;
printf "- blksize : %d\n",   $stat->st_blksize;
printf "- uid     : %d\n",   $stat->st_uid;
printf "- gid     : %d\n",   $stat->st_gid;
printf "- atime   : %d\n",   $stat->st_atime;
printf "- mtime   : %d\n",   $stat->st_mtime;
printf "- ctime   : %d\n",   $stat->st_ctime;

# write data to a file
my $buffer = 'this is a lipsum';

if (GlusterFS::GFAPI::FFI::glfs_write($fd, $buffer, length($buffer), 0) == -1)
{
    die "Failed to write: $!";
}

# seek a file offset
if (GlusterFS::GFAPI::FFI::glfs_lseek($fd, 0, 0))
{
    die "Failed to seek: $!";
}

# read data from a file
$buffer = "\0" x 256;

if (GlusterFS::GFAPI::FFI::glfs_read($fd, $buffer, 256, 0) == -1)
{
    die "Failed to read: $!";
}

printf "read: %s\n", $buffer;

# close a file
if (GlusterFS::GFAPI::FFI::glfs_close($fd))
{
    die "Failed to close: $!";
}

# destroy a connection
if (GlusterFS::GFAPI::FFI::glfs_fini($fs))
{
    die "Failed to terminate: $!"
}

REQUIREMENTS

It uses gfapi C library so you should install that before using.

Please follow steps;

# RHEL/CentOS
sudo yum install glusterfs-api

# Debian/Ubuntu
sudo apt-get install glusterfs-common

LIMITATIONS

Asynchronous I/O

libgfapi-perl does not support some asynchronous I/O functions that using closure(callback) yet.

  • glfs_read_async()
  • glfs_write_async()
  • glfs_readv_async()
  • glfs_writev_async()
  • glfs_pread_async()
  • glfs_pwrite_async()
  • glfs_preadv_async()
  • glfs_pwritev_async()
  • glfs_ftruncate_async()
  • glfs_fsync_async()
  • glfs_fdatasync_async()
  • glfs_discard_async()
  • glfs_zerofill_async()

SEE ALSO

AUTHOR

Author: Ji-Hyeon Gim (@potatogim)

Contributors

COPYRIGHT AND LICENSE

This software is copyright 2017-2019 by Ji-Hyeon Gim.

This is free software; you can redistribute it and/or modify it under the same terms as the GPLv2/LGPLv3.

libgfapi-perl's People

Contributors

alghost avatar potatogim avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

libgfapi-perl's Issues

Suggest that you add tiny contents into your README

Hi, I'm a new in perl.

so, I had been confused when using this binding because of error message.

It means that this binding does not work if glusterfs-api-devel is not installed on systems.

so I think you are supposed to add requirements into your README like below;

  • To use this, you have to install glusterfs devel packages such as glusterfs-devel and glusterfs-api-devel

Thanks.

Mocking up test code

For now, test code is terrible so we need to improve it for more stability/reliability.

Support asynchronous I/O

We do not support asynchronous I/O(such as glfs_read_async(), glfs_write_async()) for now, but it is very important features for better performance.

Documentation for mongers

We need some documentations to use it.

For now, It only exists test code that when we work with it.

Support vectored(scatter/gather) I/O

We do not support scatter/gather I/O(such as glfs_readv(), glfs_writev()) for now, but it is very important features for better efficiency/performance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.