The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

GlusterFS::GFAPI::FFI - FFI Perl binding for GlusterFS libgfapi

VERSION

0.4

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: $!"
    }

DESCRIPTION

FUNCTIONS

glfs_init($fs)

    $retval = glfs_init($fs);

glfs_new($volname)

    $fs = glfs_new($volname);

glfs_set_volfile_server($fs, $proto, $node, $port)

    $retval = glfs_set_volfile_server($fs, $proto, $node, $port);

glfs_set_logging($fs, $path, $level)

    $retval = glfs_set_logging($fs, $path, $level);

glfs_fini($fs)

    $retval = glfs_fini($fs);

glfs_get_volumeid($fs, $buf, $bufsz)

    $volid = glfs_get_volumeid($fs, $buf, $bufsz);

glfs_setfsuid($uid)

    $retval = glfs_setfsuid($uid);

glfs_setfsgid($uid)

    $retval = glfs_setfsgid($uid);

glfs_setfsgroups($uid, $gids)

    $retval = glfs_setfsgroups($uid, $gids);

glfs_open($fs, $path, $flags)

    $fd = glfs_open($fs, $path, $flags);

glfs_creat($fs, $path, $flags, $mode)

    $fd = glfs_creat($fs, $path, $flags, $mode);

glfs_close($fd)

    $retval = glfs_close($fd);

glfs_from_glfd($fd)

    $fs = glfs_from_glfd($fd);

glfs_set_xlator_option($fs, $xlator, $key, $value)

    $retval = glfs_set_xlator_option($fs, $xlator, $key, $value);

glfs_read($fd, $buf, $count, $flags)

    $retval = glfs_read($fd, $buf, $count, $flags);

glfs_write($fd, $buf, $count, $flags)

    $retval = glfs_write($fd, $buf, $count, $flags);

glfs_readv($fd, [$buf1, ...], $flags)

    ($retval, @data) = glfs_readv($fd, [$buf1, ...], $flags);

glfs_writev($fd, [$buf1, ...], $flags)

    $retval = glfs_writev($fd, [$buf1, ...], $flags);

glfs_pread($fd, $buf, $count, $offset, $flags)

    $retval = glfs_pread($fd, $buf, $count, $offset, $flags);

glfs_pwrite($fd, $buf, $count, $offset, $flags)

    $retval = glfs_pwrite($fd, $buf, $count, $offset, $flags);

glfs_preadv($fd, [$buf1, ...], $offset, $flags)

    ($retval, @data) = glfs_preadv($fd, [$buf1, ...], $offset, $flags);

glfs_pwritev($fd, [$buf1, ...], $offset, $flags)

    $retval = glfs_pwritev($fd, [$buf1, ...], $offset, $flags);

glfs_lseek($fd, $offset, $whence)

    $retval = glfs_lseek($fd, $offset, $whence);

glfs_truncate($fs, $path, $length)

    $retval = glfs_truncate($fs, $path, $length);

glfs_ftruncate($fd, $length)

    $retval = glfs_ftruncate($fd, $length);

glfs_lstat($fs, $path, $stat)

    $retval = glfs_lstat($fs, $path, $stat);

glfs_stat($fs, $path, $stat)

    $retval = glfs_stat($fs, $path, $stat);

glfs_fstat($fd, $stat)

    $retval = glfs_fstat($fd, $stat);

glfs_fsync($fd)

    $retval = glfs_fsync($fd);

glfs_fdatasync($fd)

    $retval = glfs_fdatasync($fd);

glfs_access($fs, $path, $mode)

    $retval = glfs_access($fs, $path, $mode);

glfs_symlink($fs, $oldpath, $newpath)

    $retval = glfs_symlink($fs, $oldpath, $newpath);

glfs_readlink($fs, $path, $buf, $bufsz)

    $retval = glfs_readlink($fs, $path, $buf, $bufsz);

glfs_mknod($fs, $path, $mode, $dev)

    $retval = glfs_mknod($fs, $path, $mode, $dev);

glfs_mkdir($fs, $path, $mode)

    $retval = glfs_mkdir($fs, $path, $mode);

glfs_unlink($fs, $path)

    $retval = glfs_unlink($fs, $path);

glfs_rmdir($fs, $path)

    $retval = glfs_rmdir($fs, $path);

glfs_rename($fs, $oldpath, $newpath)

    $retval = glfs_rename($fs, $oldpath, $newpath);

glfs_link($fs, $oldpath, $newpath)

    $retval = glfs_link($fs, $oldpath, $newpath);

glfs_opendir($fs, $path)

    $retval = glfs_opendir($fs, $path);

glfs_readdir_r($fd, $dirent, \$result)

    $retval = glfs_readdir_r($fd, $dirent, \$result);

glfs_readdirplus_r($fd, $stat, $dirent, \$result)

    $retval = glfs_readdirplus_r($fd, $stat, $dirent, \$result);

glfs_readdir($fd)

    $dirent = glfs_readdir($fd);

glfs_readdirplus($fd, $stat)

    $dirent = glfs_readdirplus($fd, $stat);

glfs_telldir($fd)

    $retval = glfs_telldir($fd);

glfs_seekdir($fd, $offset)

    $retval = glfs_seekdir($fd, $offset);

glfs_closedir($fd)

    $retval = glfs_closedir($fd);

glfs_statvfs($fs, $path, $statvfs)

    $retval = glfs_statvfs($fs, $path, $statvfs);

glfs_chmod($fs, $path, $mode)

    $retval = glfs_chmod($fs, $path, $mode);

glfs_fchmod($fd, $mode)

    $retval = glfs_fchmod($fd, $mode);

glfs_chown($fs, $path, $uid, $gid)

    $retval = glfs_chown($fs, $path, $uid, $gid);

glfs_lchown($fs, $path, $uid, $gid)

    $retval = glfs_lchown($fs, $path, $uid, $gid);

glfs_fchown($fd, $uid, $gid)

    $retval = glfs_fchown($fd, $uid, $gid);

glfs_utimens($fs, $path, $timespecs)

    $retval = glfs_utimens($fs, $path, $timespecs);

glfs_ltimens($fs, $path, $timespecs)

    $retval = glfs_ltimens($fs, $path, $timespecs);

glfs_ftimens($fd, $timespecs)

    $retval = glfs_ftimens($fd, $timespecs);

glfs_getxattr($fs, $path, $key, $value, $valsz)

    $retval = glfs_getxattr($fs, $path, $key, $value, $valsz);

glfs_lgetxattr($fs, $path, $key, $value, $valsz)

    $retval = glfs_lgetxattr($fs, $path, $key, $value, $valsz);

glfs_lgetxattr($fd, $key, $value, $valsz)

    $retval = glfs_lgetxattr($fd, $key, $value, $valsz);

glfs_listxattr($fs, $path, $value, $valsz)

    $retval = glfs_listxattr($fs, $path, $value, $valsz);

glfs_llistxattr($fs, $path, $value, $valsz)

    $retval = glfs_llistxattr($fs, $path, $value, $valsz);

glfs_flistxattr($fd, $value, $valsz)

    $retval = glfs_flistxattr($fd, $value, $valsz);

glfs_setxattr($fs, $path, $key, $value, $valsz, $flags)

    $retval = glfs_setxattr($fs, $path, $key, $value, $valsz, $flags);

glfs_lsetxattr($fs, $path, $key, $value, $valsz, $flags)

    $retval = glfs_lsetxattr($fs, $path, $key, $value, $valsz, $flags);

glfs_fsetxattr($fd, $key, $value, $valsz, $flags)

    $retval = glfs_fsetxattr($fd, $key, $value, $valsz, $flags);

glfs_removexttr($fd, $path, $key)

    $retval = glfs_removexttr($fd, $path, $key);

glfs_lremovexttr($fd, $path, $key)

    $retval = glfs_lremovexttr($fd, $path, $key);

glfs_fremovexttr($fs, $key)

    $retval = glfs_fremovexttr($fs, $key);

glfs_fallocate($fd, $keepsz, $offset, $len)

    $retval = glfs_fallocate($fd, $keepsz, $offset, $len);

glfs_discard($fd, $offset, $len)

    $retval = glfs_discard($fd, $offset, $len);

glfs_zerofill($fd, $offset, $len)

    $retval = glfs_zerofill($fd, $offset, $len);

glfs_getcwd($fs, $buf, $bufsz)

    $retval = glfs_getcwd($fs, $buf, $bufsz);

glfs_chdir($fs, $path)

    $retval = glfs_chdir($fs, $path);

glfs_fchdir($fd)

    $retval = glfs_fchdir($fd);

glfs_realpath($fs, $path, $resolved)

    $retval = glfs_realpath($fs, $path, $resolved);

glfs_posix_lock($fd, $cmd, $flock)

    $retval = glfs_posix_lock($fd, $cmd, $flock);

glfs_dup($fd)

    $fd = glfs_dup($fd);

glfs_read_async($fd, $buf, $bufsz, $flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_read_async($fd, $buf, $bufsz, $flags, $cbk, $data);

glfs_write_async($fd, $buf, $bufsz, $flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_write_async($fd, $buf, $bufsz, $flags, $cbk, $data);

glfs_readv_async($fd, [$buf1, ...], $flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_readv_async($fd, [$buf1, ...], $flags, $cbk, $data);

glfs_writev_async($fd, [$buf1, ...], $flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_writev_async($fd, [$buf1, ...], $flags, $cbk, $data);

glfs_pread_async($fd, $buf, $bufsz, $offset, flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_pread_async($fd, $buf, $bufsz, $offset, flags, $cbk, $data);

glfs_pwrite_async($fd, $buf, $bufsz, $offset, flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_pwrite_async($fd, $buf, $bufsz, $offset, flags, $cbk, $data);

glfs_preadv_async($fd, [$buf1, ...], $offset, $flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_preadv_async($fd, [$buf1, ...], $offset, $flags, $cbk, $data);

glfs_pwritev_async($fd, [$buf1, ...], $offset, $flags, $cbk, $data)

This function is not supported yet!

    $retval = glfs_pwritev_async($fd, [$buf1, ...], $offset, $flags, $cbk, $data);

glfs_ftruncate_async($fd, $length, $cbk, $data)

This function is not supported yet!

    $retval = glfs_ftruncate_async($fd, $length, $cbk, $data);

glfs_fsync_async($fd, $cbk, $data)

This function is not supported yet!

    $retval = glfs_fsync_async($fd, $cbk, $data);

glfs_fdatasync_async($fd, $cbk, $data)

This function is not supported yet!

    $retval = glfs_fdatasync_async($fd, $cbk, $data);

glfs_discard_async($fd, $offset, $len, $cbk, $data)

This function is not supported yet!

    $retval = glfs_discard_async($fd, $offset, $len, $cbk, $data);

glfs_zerofill_async($fd, $offset, $len, $cbk, $data)

This function is not supported yet!

    $retval = glfs_zerofill_async($fd, $offset, $len, $cbk, $data);

BUGS

SEE ALSO

https://www.gluster.org
https://github.com/gluster/libgfapi-perl
overload
Fcntl
POSIX
Carp
Tiny::Try
File::Spec
List::MoreUtils
Moo
Generator::Object
FFI::Platypus
FFI::CheckLib

AUTHOR

Ji-Hyeon Gim <potatogim@gluesys.com>

CONTRIBUTORS

Tae-Hwa Lee <alghost@gmail.com>

COPYRIGHT AND LICENSE

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

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