Merge pull request #65 from ceph/connected-state

Connected state
This commit is contained in:
Noah Watkins 2018-09-14 15:10:35 -07:00 committed by GitHub
commit 28db807c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 712 additions and 788 deletions

View File

@ -6,13 +6,20 @@ branches:
except:
- gh-pages
#matrix:
# include:
# - env: CEPH_RELEASE=jewel
# - env: CEPH_RELEASE=kraken
matrix:
include:
- env: CEPH_VERSION=luminous
- env: CEPH_VERSION=mimic
before_install:
- docker build -t ceph-golang-ci .
before_install: |
if [[ "${CEPH_VERSION}" == "luminous" ]]; then
docker build --build-arg CEPH_REPO_URL=https://download.ceph.com/debian-luminous/ -t ceph-golang-ci .
elif [[ "${CEPH_VERSION}" == "mimic" ]]; then
docker build --build-arg CEPH_REPO_URL=https://download.ceph.com/debian-mimic/ -t ceph-golang-ci .
else
echo "unsupported ceph version"
exit 1
fi
script:
- docker run --rm -it -v ${PWD}:/go/src/github.com/ceph/go-ceph:z ceph-golang-ci

View File

@ -3,19 +3,22 @@ FROM ubuntu:xenial
RUN apt-get update && apt-get install -y \
apt-transport-https \
git \
golang-go \
software-properties-common \
uuid-runtime \
wget
ARG CEPH_REPO_URL=https://download.ceph.com/debian-luminous/
RUN wget -q -O- 'https://download.ceph.com/keys/release.asc' | apt-key add -
RUN apt-add-repository 'deb https://download.ceph.com/debian-luminous/ xenial main'
RUN apt-add-repository "deb ${CEPH_REPO_URL} xenial main"
RUN add-apt-repository ppa:gophers/archive
RUN apt-get update && apt-get install -y \
ceph \
libcephfs-dev \
librados-dev \
librbd-dev
librbd-dev \
golang-1.10-go
ENV GOPATH /go
WORKDIR /go/src/github.com/ceph/go-ceph

View File

@ -99,6 +99,14 @@ docker run --rm -it --net=host
ceph-golang
```
Run against a `vstart.sh` cluster without installing Ceph:
```
export CGO_CPPFLAGS="-I/ceph/src/include"
export CGO_LDFLAGS="-L/ceph/build/lib"
go build
```
## Contributing
Contributions are welcome & greatly appreciated, every little bit helps. Make code changes via Github pull requests:

View File

@ -6,7 +6,9 @@ mkdir /tmp/ceph
/micro-osd.sh /tmp/ceph
export CEPH_CONF=/tmp/ceph/ceph.conf
go vet ./...
export PATH=/usr/lib/go-1.10/bin:$PATH
go get -t -v ./...
go list ./...
#go vet ./...
#go list ./...
go test -v $(go list ./... | grep -v cephfs)

View File

@ -39,7 +39,7 @@ auth service required = none
auth client required = none
osd pool default size = 1
[mon.0]
[mon.a]
log file = ${LOG_DIR}/mon.log
chdir = ""
mon cluster log file = ${LOG_DIR}/mon-cluster.log
@ -61,9 +61,9 @@ EOF
export CEPH_CONF=${DIR}/ceph.conf
# start an osd
ceph-mon --id 0 --mkfs --keyring /dev/null
ceph-mon --id a --mkfs --keyring /dev/null
touch ${MON_DATA}/keyring
ceph-mon --id 0
ceph-mon --id a
# start an osd
OSD_ID=$(ceph osd create)

View File

@ -7,6 +7,7 @@ import "C"
import "unsafe"
import "bytes"
import "fmt"
// ClusterStat represents Ceph cluster statistics.
type ClusterStat struct {
@ -18,7 +19,8 @@ type ClusterStat struct {
// Conn is a connection handle to a Ceph cluster.
type Conn struct {
cluster C.rados_t
cluster C.rados_t
connected bool
}
// PingMonitor sends a ping to a monitor and returns the reply.
@ -45,6 +47,7 @@ func (c *Conn) PingMonitor(id string) (string, error) {
func (c *Conn) Connect() error {
ret := C.rados_connect(c.cluster)
if ret == 0 {
c.connected = true
return nil
} else {
return RadosError(int(ret))
@ -53,6 +56,9 @@ func (c *Conn) Connect() error {
// Shutdown disconnects from the cluster.
func (c *Conn) Shutdown() {
if err := c.ensure_connected(); err != nil {
return
}
C.rados_shutdown(c.cluster)
}
@ -162,9 +168,20 @@ func (c *Conn) WaitForLatestOSDMap() error {
}
}
func (c *Conn) ensure_connected() error {
if c.connected {
return nil
} else {
return RadosError(1)
}
}
// GetClusterStat returns statistics about the cluster associated with the
// connection.
func (c *Conn) GetClusterStats() (stat ClusterStat, err error) {
if err := c.ensure_connected(); err != nil {
return ClusterStat{}, err
}
c_stat := C.struct_rados_cluster_stat_t{}
ret := C.rados_cluster_stat(c.cluster, &c_stat)
if ret < 0 {
@ -250,6 +267,10 @@ func (c *Conn) MakePool(name string) error {
// DeletePool deletes a pool and all the data inside the pool.
func (c *Conn) DeletePool(name string) error {
if err := c.ensure_connected(); err != nil {
fmt.Println("NOT CONNECTED WHOOPS")
return err
}
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
ret := int(C.rados_pool_delete(c.cluster, c_name))

View File

@ -101,7 +101,7 @@ func (ioctx *IOContext) Write(oid string, data []byte, offset uint64) error {
dataPointer := unsafe.Pointer(nil)
if len(data) > 0 {
dataPointer = unsafe.Pointer(&data[0])
dataPointer = unsafe.Pointer(&data[0])
}
ret := C.rados_write(ioctx.ioctx, c_oid,
@ -141,17 +141,18 @@ func (ioctx *IOContext) Append(oid string, data []byte) error {
// Read reads up to len(data) bytes from the object with key oid starting at byte
// offset offset. It returns the number of bytes read and an error, if any.
func (ioctx *IOContext) Read(oid string, data []byte, offset uint64) (int, error) {
if len(data) == 0 {
return 0, nil
}
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
var buf *C.char
if len(data) > 0 {
buf = (*C.char)(unsafe.Pointer(&data[0]))
}
ret := C.rados_read(
ioctx.ioctx,
c_oid,
(*C.char)(unsafe.Pointer(&data[0])),
buf,
(C.size_t)(len(data)),
(C.uint64_t)(offset))

View File

@ -17,7 +17,7 @@ func (e RadosError) Error() string {
return fmt.Sprintf("rados: %s", C.GoString(C.strerror(C.int(-e))))
}
var RadosAllNamespaces = "\x01"
var RadosAllNamespaces = C.LIBRADOS_ALL_NSPACES
var RadosErrorNotFound = RadosError(-C.ENOENT)
var RadosErrorPermissionDenied = RadosError(-C.EPERM)
@ -37,11 +37,13 @@ func Version() (int, int, int) {
return int(c_major), int(c_minor), int(c_patch)
}
// NewConn creates a new connection object. It returns the connection and an
// error, if any.
func NewConn() (*Conn, error) {
conn := &Conn{}
ret := C.rados_create(&conn.cluster, nil)
func makeConn() *Conn {
return &Conn{connected: false}
}
func newConn(user *C.char) (*Conn, error) {
conn := makeConn()
ret := C.rados_create(&conn.cluster, user)
if ret == 0 {
return conn, nil
@ -50,20 +52,18 @@ func NewConn() (*Conn, error) {
}
}
// NewConn creates a new connection object. It returns the connection and an
// error, if any.
func NewConn() (*Conn, error) {
return newConn(nil)
}
// NewConnWithUser creates a new connection object with a custom username.
// It returns the connection and an error, if any.
func NewConnWithUser(user string) (*Conn, error) {
c_user := C.CString(user)
defer C.free(unsafe.Pointer(c_user))
conn := &Conn{}
ret := C.rados_create(&conn.cluster, c_user)
if ret == 0 {
return conn, nil
} else {
return nil, RadosError(int(ret))
}
return newConn(c_user)
}
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
@ -75,7 +75,7 @@ func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, erro
c_name := C.CString(userName)
defer C.free(unsafe.Pointer(c_name))
conn := &Conn{}
conn := makeConn()
ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0)
if ret == 0 {
return conn, nil

File diff suppressed because it is too large Load Diff