Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glusterfs: update for new API #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
language: go

go:
- 1.11.x
- 1.10.x

go_import_path: github.com/gluster/gogfapi

dist: xenial
addons:
apt:
update: true
packages:
- glusterfs-common

services:
- docker

matrix:
include:
- env: GFAPI_APIS=legacy
- env: GFAPI_APIS=enhanced

before_install: |
make ci-image GFAPI_APIS=${GFAPI_APIS}

before_script:
- bash -x test_setup.sh
- make setup-test-container GFAPI_APIS=${GFAPI_APIS}

script:
- go test -v ./...
- make test-container GFAPI_APIS=${GFAPI_APIS}
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CI_IMAGE_NAME = gogfapi-ci
CONTAINER_CMD := docker
CONTAINER_NAME := gluster-test
CONTAINER_CONFIG_DIR := testing/containers

GFAPI_APIS := enhanced
GFAPI_APIS_TEST_TAGS :=
GLUSTER_VERSION := latest

ifeq ($(GFAPI_APIS),legacy)
GLUSTER_VERSION = gluster-4.1
GFAPI_APIS_TEST_TAGS = -tags glusterfs_legacy_api
endif

# the name of the image plus ceph version as tag
CI_IMAGE_TAG=$(CI_IMAGE_NAME):$(GLUSTER_VERSION)

test:
go test -v ./...

.PHONY: ci-image
ci-image:
$(CONTAINER_CMD) build --build-arg GLUSTER_VERSION=$(GLUSTER_VERSION) -t $(CI_IMAGE_TAG) -f $(CONTAINER_CONFIG_DIR)/Dockerfile .

.PHONY: setup-test-container
setup-test-container:
CI_IMAGE_TAG=${CI_IMAGE_TAG} CONTAINER_NAME=${CONTAINER_NAME} ./testing/test_setup.sh

test-container:
$(CONTAINER_CMD) exec ${CONTAINER_NAME} go test ${GFAPI_APIS_TEST_TAGS} -v ./...
38 changes: 0 additions & 38 deletions gfapi/fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,6 @@ func (fd *Fd) Fstat(stat *syscall.Stat_t) error {
return nil
}

// Fsync performs an fsync on the Fd
//
// Returns error on failure
func (fd *Fd) Fsync() error {
ret, err := C.glfs_fsync(fd.fd)
if ret < 0 {
return err
}
return nil
}

// Ftruncate truncates the size of the Fd to the given size
//
// Returns error on failure
func (fd *Fd) Ftruncate(size int64) error {
_, err := C.glfs_ftruncate(fd.fd, C.off_t(size))

return err
}

// Pread reads at most len(b) bytes into b from offset off in Fd
//
// Returns number of bytes read on success and error on failure
func (fd *Fd) Pread(b []byte, off int64) (int, error) {
n, err := C.glfs_pread(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0)

return int(n), err
}

// Pwrite writes len(b) bytes from b into the Fd from offset off
//
// Returns number of bytes written on success and error on failure
func (fd *Fd) Pwrite(b []byte, off int64) (int, error) {
n, err := C.glfs_pwrite(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0)

return int(n), err
}

// Read reads at most len(b) bytes into b from Fd
//
// Returns number of bytes read on success and error on failure
Expand Down
49 changes: 49 additions & 0 deletions gfapi/fd_enhanced.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// +build !glusterfs_legacy_api

package gfapi

// #cgo pkg-config: glusterfs-api
// #include "glusterfs/api/glfs.h"
// #include <stdlib.h>
import "C"
import (
"unsafe"
)

// Fsync performs an fsync on the Fd
//
// Returns error on failure
func (fd *Fd) Fsync() error {
ret, err := C.glfs_fsync(fd.fd, nil, nil)
if ret < 0 {
return err
}
return nil
}

// Ftruncate truncates the size of the Fd to the given size
//
// Returns error on failure
func (fd *Fd) Ftruncate(size int64) error {
_, err := C.glfs_ftruncate(fd.fd, C.off_t(size), nil, nil)

return err
}

// Pread reads at most len(b) bytes into b from offset off in Fd
//
// Returns number of bytes read on success and error on failure
func (fd *Fd) Pread(b []byte, off int64) (int, error) {
n, err := C.glfs_pread(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0, nil)

return int(n), err
}

// Pwrite writes len(b) bytes from b into the Fd from offset off
//
// Returns number of bytes written on success and error on failure
func (fd *Fd) Pwrite(b []byte, off int64) (int, error) {
n, err := C.glfs_pwrite(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0, nil, nil)

return int(n), err
}
49 changes: 49 additions & 0 deletions gfapi/fd_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// +build glusterfs_legacy_api

package gfapi

// #cgo pkg-config: glusterfs-api
// #include "glusterfs/api/glfs.h"
// #include <stdlib.h>
import "C"
import (
"unsafe"
)

// Fsync performs an fsync on the Fd
//
// Returns error on failure
func (fd *Fd) Fsync() error {
ret, err := C.glfs_fsync(fd.fd)
if ret < 0 {
return err
}
return nil
}

// Ftruncate truncates the size of the Fd to the given size
//
// Returns error on failure
func (fd *Fd) Ftruncate(size int64) error {
_, err := C.glfs_ftruncate(fd.fd, C.off_t(size))

return err
}

// Pread reads at most len(b) bytes into b from offset off in Fd
//
// Returns number of bytes read on success and error on failure
func (fd *Fd) Pread(b []byte, off int64) (int, error) {
n, err := C.glfs_pread(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0)

return int(n), err
}

// Pwrite writes len(b) bytes from b into the Fd from offset off
//
// Returns number of bytes written on success and error on failure
func (fd *Fd) Pwrite(b []byte, off int64) (int, error) {
n, err := C.glfs_pwrite(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0)

return int(n), err
}
17 changes: 0 additions & 17 deletions test_setup.sh

This file was deleted.

23 changes: 23 additions & 0 deletions testing/containers/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG GLUSTER_VERSION
FROM quay.io/gluster/gluster-centos:${GLUSTER_VERSION:-latest}

RUN true && \
yum clean all && \
gv="$(rpm -q --queryformat '%{version}-%{release}' glusterfs-server)" && \
yum install -y \
git wget make gcc curl "glusterfs-api-devel-${gv}" && \
true

ENV GOTAR=go1.14.9.linux-amd64.tar.gz
RUN true && \
curl -o /tmp/${GOTAR} https://dl.google.com/go/${GOTAR} && \
tar -x -C /opt/ -f /tmp/${GOTAR} && \
rm -f /tmp/${GOTAR} && \
true

ENV PATH="${PATH}:/opt/go/bin"
ENV GOROOT=/opt/go
ENV GO111MODULE=off
ENV GOPATH /go
WORKDIR /go/src/github.com/gluster/gogfapi
VOLUME /go/src/github.com/gluster/gogfapi
18 changes: 18 additions & 0 deletions testing/test_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

docker run -d --name ${CONTAINER_NAME} \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged=true \
-v $(pwd):/go/src/github.com/gluster/gogfapi \
${CI_IMAGE_TAG}

# wait for glusterd service to be active
while ! docker exec ${CONTAINER_NAME} systemctl is-active glusterd; do
sleep 1
done

docker exec ${CONTAINER_NAME} /bin/sh -c "echo '127.0.1.1 $(hostname)' >> /etc/hosts"
docker exec ${CONTAINER_NAME} gluster volume create test $(hostname):/srv force
docker exec ${CONTAINER_NAME} gluster volume set test storage.owner-uid $(id -u)
docker exec ${CONTAINER_NAME} gluster volume start test