From 8d82e0bbd78d06d9d781130c935f46c575bba0d8 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 27 Jan 2020 16:31:11 +0100 Subject: [PATCH] [DNM] dep: use wip/for-ceph-csi from nixpanic/go-ceph --- Gopkg.lock | 6 +- Gopkg.toml | 2 +- vendor/github.com/ceph/go-ceph/rados/conn.go | 104 +++++------ vendor/github.com/ceph/go-ceph/rados/ioctx.go | 142 ++++++++------- vendor/github.com/ceph/go-ceph/rados/rados.go | 17 +- .../github.com/ceph/go-ceph/rbd/features.go | 4 + vendor/github.com/ceph/go-ceph/rbd/options.go | 47 +++++ vendor/github.com/ceph/go-ceph/rbd/rbd.go | 167 +++++++++++------- 8 files changed, 300 insertions(+), 189 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index cae2f9684a1e..a17d51f5bd38 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -26,8 +26,8 @@ version = "v3.6.1" [[projects]] - branch = "wip/rbd/features" - digest = "1:06c11b0d54f55aa5423c0c8113f1f0d05cde9970324ab744fcb3cd052cf6340c" + branch = "wip/for-ceph-csi" + digest = "1:80515bd92a05744008890cbca9bec0ce9d3b3b09c068cf73c27af810e5728250" name = "github.com/ceph/go-ceph" packages = [ "errutil", @@ -35,7 +35,7 @@ "rbd", ] pruneopts = "NUT" - revision = "e7569e5aaf34d4f7909c988fa5e6ef6450f19032" + revision = "468fed3b7316b89156bfe06192ceecaf4889e452" source = "github.com/nixpanic/go-ceph" [[projects]] diff --git a/Gopkg.toml b/Gopkg.toml index 3b53e4ccad7e..7cbfd166f034 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -76,7 +76,7 @@ name = "k8s.io/utils" [[constraint]] - branch = "wip/rbd/features" + branch = "wip/for-ceph-csi" source = "github.com/nixpanic/go-ceph" name = "github.com/ceph/go-ceph" diff --git a/vendor/github.com/ceph/go-ceph/rados/conn.go b/vendor/github.com/ceph/go-ceph/rados/conn.go index ce76619787ab..0e1d09833157 100644 --- a/vendor/github.com/ceph/go-ceph/rados/conn.go +++ b/vendor/github.com/ceph/go-ceph/rados/conn.go @@ -12,6 +12,7 @@ import ( ) var ( + // ErrNotConnected is returned when functions are called without a RADOS connection ErrNotConnected = errors.New("RADOS not connected") ) @@ -43,9 +44,8 @@ func (c *Conn) PingMonitor(id string) (string, error) { if ret == 0 { reply := C.GoStringN(strout, (C.int)(strlen)) return reply, nil - } else { - return "", RadosError(int(ret)) } + return "", RadosError(int(ret)) } // Connect establishes a connection to a RADOS cluster. It returns an error, @@ -72,24 +72,21 @@ func (c *Conn) ReadConfigFile(path string) error { c_path := C.CString(path) defer C.free(unsafe.Pointer(c_path)) ret := C.rados_conf_read_file(c.cluster, c_path) - if ret == 0 { - return nil - } else { - return RadosError(int(ret)) - } + return getRadosError(int(ret)) } // ReadDefaultConfigFile configures the connection using a Ceph configuration // file located at default locations. func (c *Conn) ReadDefaultConfigFile() error { ret := C.rados_conf_read_file(c.cluster, nil) - if ret == 0 { - return nil - } else { - return RadosError(int(ret)) - } + return getRadosError(int(ret)) } +// OpenIOContext creates and returns a new IOContext for the given pool. +// +// Implements: +// int rados_ioctx_create(rados_t cluster, const char *pool_name, +// rados_ioctx_t *ioctx); func (c *Conn) OpenIOContext(pool string) (*IOContext, error) { c_pool := C.CString(pool) defer C.free(unsafe.Pointer(c_pool)) @@ -97,9 +94,8 @@ func (c *Conn) OpenIOContext(pool string) (*IOContext, error) { ret := C.rados_ioctx_create(c.cluster, c_pool, &ioctx.ioctx) if ret == 0 { return ioctx, nil - } else { - return nil, RadosError(int(ret)) } + return nil, RadosError(int(ret)) } // ListPools returns the names of all existing pools. @@ -136,11 +132,7 @@ func (c *Conn) SetConfigOption(option, value string) error { defer C.free(unsafe.Pointer(c_opt)) defer C.free(unsafe.Pointer(c_val)) ret := C.rados_conf_set(c.cluster, c_opt, c_val) - if ret < 0 { - return RadosError(int(ret)) - } else { - return nil - } + return getRadosError(int(ret)) } // GetConfigOption returns the value of the Ceph configuration option @@ -157,28 +149,22 @@ func (c *Conn) GetConfigOption(name string) (value string, err error) { if ret == 0 { value = C.GoString((*C.char)(unsafe.Pointer(&buf[0]))) return value, nil - } else { - return "", RadosError(ret) } + return "", RadosError(ret) } // WaitForLatestOSDMap blocks the caller until the latest OSD map has been // retrieved. func (c *Conn) WaitForLatestOSDMap() error { ret := C.rados_wait_for_latest_osdmap(c.cluster) - if ret < 0 { - return RadosError(int(ret)) - } else { - return nil - } + return getRadosError(int(ret)) } func (c *Conn) ensure_connected() error { if c.connected { return nil - } else { - return ErrNotConnected } + return ErrNotConnected } // GetClusterStats returns statistics about the cluster associated with the @@ -191,14 +177,13 @@ func (c *Conn) GetClusterStats() (stat ClusterStat, err error) { ret := C.rados_cluster_stat(c.cluster, &c_stat) if ret < 0 { return ClusterStat{}, RadosError(int(ret)) - } else { - return ClusterStat{ - Kb: uint64(c_stat.kb), - Kb_used: uint64(c_stat.kb_used), - Kb_avail: uint64(c_stat.kb_avail), - Num_objects: uint64(c_stat.num_objects), - }, nil } + return ClusterStat{ + Kb: uint64(c_stat.kb), + Kb_used: uint64(c_stat.kb_used), + Kb_avail: uint64(c_stat.kb_avail), + Num_objects: uint64(c_stat.num_objects), + }, nil } // ParseCmdLineArgs configures the connection from command line arguments. @@ -218,22 +203,14 @@ func (c *Conn) ParseCmdLineArgs(args []string) error { } ret := C.rados_conf_parse_argv(c.cluster, argc, &argv[0]) - if ret < 0 { - return RadosError(int(ret)) - } else { - return nil - } + return getRadosError(int(ret)) } // ParseDefaultConfigEnv configures the connection from the default Ceph // environment variable(s). func (c *Conn) ParseDefaultConfigEnv() error { ret := C.rados_conf_parse_env(c.cluster, nil) - if ret == 0 { - return nil - } else { - return RadosError(int(ret)) - } + return getRadosError(int(ret)) } // GetFSID returns the fsid of the cluster as a hexadecimal string. The fsid @@ -246,9 +223,8 @@ func (c *Conn) GetFSID() (fsid string, err error) { if ret == 36 { fsid = C.GoString((*C.char)(unsafe.Pointer(&buf[0]))) return fsid, nil - } else { - return "", RadosError(int(ret)) } + return "", RadosError(int(ret)) } // GetInstanceID returns a globally unique identifier for the cluster @@ -263,11 +239,7 @@ func (c *Conn) MakePool(name string) error { c_name := C.CString(name) defer C.free(unsafe.Pointer(c_name)) ret := int(C.rados_pool_create(c.cluster, c_name)) - if ret == 0 { - return nil - } else { - return RadosError(ret) - } + return getRadosError(int(ret)) } // DeletePool deletes a pool and all the data inside the pool. @@ -278,11 +250,7 @@ func (c *Conn) DeletePool(name string) error { c_name := C.CString(name) defer C.free(unsafe.Pointer(c_name)) ret := int(C.rados_pool_delete(c.cluster, c_name)) - if ret == 0 { - return nil - } else { - return RadosError(ret) - } + return getRadosError(int(ret)) } // GetPoolByName returns the ID of the pool with a given name. @@ -295,9 +263,8 @@ func (c *Conn) GetPoolByName(name string) (int64, error) { ret := int64(C.rados_pool_lookup(c.cluster, c_name)) if ret < 0 { return 0, RadosError(ret) - } else { - return ret, nil } + return ret, nil } // GetPoolByID returns the name of a pool by a given ID. @@ -310,9 +277,8 @@ func (c *Conn) GetPoolByID(id int64) (string, error) { ret := int(C.rados_pool_reverse_lookup(c.cluster, c_id, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))) if ret < 0 { return "", RadosError(ret) - } else { - return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), nil } + return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), nil } // MonCommand sends a command to one of the monitors @@ -363,11 +329,25 @@ func (c *Conn) monCommand(args, inputBuffer []byte) (buffer []byte, info string, } // PGCommand sends a command to one of the PGs +// +// Implements: +// int rados_pg_command(rados_t cluster, const char *pgstr, +// const char **cmd, size_t cmdlen, +// const char *inbuf, size_t inbuflen, +// char **outbuf, size_t *outbuflen, +// char **outs, size_t *outslen); func (c *Conn) PGCommand(pgid []byte, args [][]byte) (buffer []byte, info string, err error) { return c.pgCommand(pgid, args, nil) } -// PGCommand sends a command to one of the PGs, with an input buffer +// PGCommandWithInputBuffer sends a command to one of the PGs, with an input buffer +// +// Implements: +// int rados_pg_command(rados_t cluster, const char *pgstr, +// const char **cmd, size_t cmdlen, +// const char *inbuf, size_t inbuflen, +// char **outbuf, size_t *outbuflen, +// char **outs, size_t *outslen); func (c *Conn) PGCommandWithInputBuffer(pgid []byte, args [][]byte, inputBuffer []byte) (buffer []byte, info string, err error) { return c.pgCommand(pgid, args, inputBuffer) } diff --git a/vendor/github.com/ceph/go-ceph/rados/ioctx.go b/vendor/github.com/ceph/go-ceph/rados/ioctx.go index 08eb835cd1c0..b9ef93194f5c 100644 --- a/vendor/github.com/ceph/go-ceph/rados/ioctx.go +++ b/vendor/github.com/ceph/go-ceph/rados/ioctx.go @@ -30,6 +30,13 @@ import ( "unsafe" ) +type RadosCreateOption int + +const ( + RadosCreateExclusive = C.LIBRADOS_CREATE_EXCLUSIVE + RadosCreateIdempotent = C.LIBRADOS_CREATE_IDEMPOTENT +) + // PoolStat represents Ceph pool statistics. type PoolStat struct { // space used in bytes @@ -93,6 +100,23 @@ func (ioctx *IOContext) SetNamespace(namespace string) { C.rados_ioctx_set_namespace(ioctx.ioctx, c_ns) } +// Create a new object with key oid. +// +// Implements: +// void rados_write_op_create(rados_write_op_t write_op, int exclusive, +// const char* category) +func (ioctx *IOContext) Create(oid string, exclusive RadosCreateOption) error { + c_oid := C.CString(oid) + defer C.free(unsafe.Pointer(c_oid)) + + op := C.rados_create_write_op() + C.rados_write_op_create(op, C.int(exclusive), nil) + ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) + C.rados_release_write_op(op) + + return getRadosError(int(ret)) +} + // Write writes len(data) bytes to the object with key oid starting at byte // offset offset. It returns an error, if any. func (ioctx *IOContext) Write(oid string, data []byte, offset uint64) error { @@ -109,7 +133,7 @@ func (ioctx *IOContext) Write(oid string, data []byte, offset uint64) error { (C.size_t)(len(data)), (C.uint64_t)(offset)) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } // WriteFull writes len(data) bytes to the object with key oid. @@ -122,7 +146,7 @@ func (ioctx *IOContext) WriteFull(oid string, data []byte) error { ret := C.rados_write_full(ioctx.ioctx, c_oid, (*C.char)(unsafe.Pointer(&data[0])), (C.size_t)(len(data))) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } // Append appends len(data) bytes to the object with key oid. @@ -135,7 +159,7 @@ func (ioctx *IOContext) Append(oid string, data []byte) error { ret := C.rados_append(ioctx.ioctx, c_oid, (*C.char)(unsafe.Pointer(&data[0])), (C.size_t)(len(data))) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } // Read reads up to len(data) bytes from the object with key oid starting at byte @@ -158,9 +182,8 @@ func (ioctx *IOContext) Read(oid string, data []byte, offset uint64) (int, error if ret >= 0 { return int(ret), nil - } else { - return 0, GetRadosError(int(ret)) } + return 0, getRadosError(int(ret)) } // Delete deletes the object with key oid. It returns an error, if any. @@ -168,7 +191,7 @@ func (ioctx *IOContext) Delete(oid string) error { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) - return GetRadosError(int(C.rados_remove(ioctx.ioctx, c_oid))) + return getRadosError(int(C.rados_remove(ioctx.ioctx, c_oid))) } // Truncate resizes the object with key oid to size size. If the operation @@ -179,7 +202,7 @@ func (ioctx *IOContext) Truncate(oid string, size uint64) error { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) - return GetRadosError(int(C.rados_trunc(ioctx.ioctx, c_oid, (C.uint64_t)(size)))) + return getRadosError(int(C.rados_trunc(ioctx.ioctx, c_oid, (C.uint64_t)(size)))) } // Destroy informs librados that the I/O context is no longer in use. @@ -189,29 +212,32 @@ func (ioctx *IOContext) Destroy() { C.rados_ioctx_destroy(ioctx.ioctx) } -// Stat returns a set of statistics about the pool associated with this I/O +// GetPoolStats returns a set of statistics about the pool associated with this I/O // context. +// +// Implements: +// int rados_ioctx_pool_stat(rados_ioctx_t io, +// struct rados_pool_stat_t *stats); func (ioctx *IOContext) GetPoolStats() (stat PoolStat, err error) { c_stat := C.struct_rados_pool_stat_t{} ret := C.rados_ioctx_pool_stat(ioctx.ioctx, &c_stat) if ret < 0 { - return PoolStat{}, GetRadosError(int(ret)) - } else { - return PoolStat{ - Num_bytes: uint64(c_stat.num_bytes), - Num_kb: uint64(c_stat.num_kb), - Num_objects: uint64(c_stat.num_objects), - Num_object_clones: uint64(c_stat.num_object_clones), - Num_object_copies: uint64(c_stat.num_object_copies), - Num_objects_missing_on_primary: uint64(c_stat.num_objects_missing_on_primary), - Num_objects_unfound: uint64(c_stat.num_objects_unfound), - Num_objects_degraded: uint64(c_stat.num_objects_degraded), - Num_rd: uint64(c_stat.num_rd), - Num_rd_kb: uint64(c_stat.num_rd_kb), - Num_wr: uint64(c_stat.num_wr), - Num_wr_kb: uint64(c_stat.num_wr_kb), - }, nil - } + return PoolStat{}, getRadosError(int(ret)) + } + return PoolStat{ + Num_bytes: uint64(c_stat.num_bytes), + Num_kb: uint64(c_stat.num_kb), + Num_objects: uint64(c_stat.num_objects), + Num_object_clones: uint64(c_stat.num_object_clones), + Num_object_copies: uint64(c_stat.num_object_copies), + Num_objects_missing_on_primary: uint64(c_stat.num_objects_missing_on_primary), + Num_objects_unfound: uint64(c_stat.num_objects_unfound), + Num_objects_degraded: uint64(c_stat.num_objects_degraded), + Num_rd: uint64(c_stat.num_rd), + Num_rd_kb: uint64(c_stat.num_rd_kb), + Num_wr: uint64(c_stat.num_wr), + Num_wr_kb: uint64(c_stat.num_wr_kb), + }, nil } // GetPoolName returns the name of the pool associated with the I/O context. @@ -224,7 +250,7 @@ func (ioctx *IOContext) GetPoolName() (name string, err error) { buf = make([]byte, len(buf)*2) continue } else if ret < 0 { - return "", GetRadosError(int(ret)) + return "", getRadosError(int(ret)) } name = C.GoStringN((*C.char)(unsafe.Pointer(&buf[0])), ret) return name, nil @@ -244,7 +270,7 @@ func (ioctx *IOContext) ListObjects(listFn ObjectListFunc) error { var ctx C.rados_list_ctx_t ret := C.rados_nobjects_list_open(ioctx.ioctx, &ctx) if ret < 0 { - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } defer func() { C.rados_nobjects_list_close(ctx) }() @@ -254,7 +280,7 @@ func (ioctx *IOContext) ListObjects(listFn ObjectListFunc) error { if ret == -C.ENOENT { return nil } else if ret < 0 { - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } listFn(C.GoString(c_entry)) } @@ -274,13 +300,12 @@ func (ioctx *IOContext) Stat(object string) (stat ObjectStat, err error) { &c_pmtime) if ret < 0 { - return ObjectStat{}, GetRadosError(int(ret)) - } else { - return ObjectStat{ - Size: uint64(c_psize), - ModTime: time.Unix(int64(c_pmtime), 0), - }, nil + return ObjectStat{}, getRadosError(int(ret)) } + return ObjectStat{ + Size: uint64(c_psize), + ModTime: time.Unix(int64(c_pmtime), 0), + }, nil } // GetXattr gets an xattr with key `name`, it returns the length of @@ -300,12 +325,11 @@ func (ioctx *IOContext) GetXattr(object string, name string, data []byte) (int, if ret >= 0 { return int(ret), nil - } else { - return 0, GetRadosError(int(ret)) } + return 0, getRadosError(int(ret)) } -// Sets an xattr for an object with key `name` with value as `data` +// SetXattr sets an xattr for an object with key `name` with value as `data` func (ioctx *IOContext) SetXattr(object string, name string, data []byte) error { c_object := C.CString(object) c_name := C.CString(name) @@ -319,12 +343,11 @@ func (ioctx *IOContext) SetXattr(object string, name string, data []byte) error (*C.char)(unsafe.Pointer(&data[0])), (C.size_t)(len(data))) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } -// function that lists all the xattrs for an object, since xattrs are -// a k-v pair, this function returns a map of k-v pairs on -// success, error code on failure +// ListXattrs lists all the xattrs for an object. The xattrs are returned as a +// mapping of string keys and byte-slice values. func (ioctx *IOContext) ListXattrs(oid string) (map[string][]byte, error) { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) @@ -333,7 +356,7 @@ func (ioctx *IOContext) ListXattrs(oid string) (map[string][]byte, error) { ret := C.rados_getxattrs(ioctx.ioctx, c_oid, &it) if ret < 0 { - return nil, GetRadosError(int(ret)) + return nil, getRadosError(int(ret)) } defer func() { C.rados_getxattrs_end(it) }() m := make(map[string][]byte) @@ -345,7 +368,7 @@ func (ioctx *IOContext) ListXattrs(oid string) (map[string][]byte, error) { ret := C.rados_getxattrs_next(it, &c_name, &c_val, &c_len) if ret < 0 { - return nil, GetRadosError(int(ret)) + return nil, getRadosError(int(ret)) } // rados api returns a null name,val & 0-length upon // end of iteration @@ -368,10 +391,10 @@ func (ioctx *IOContext) RmXattr(oid string, name string) error { c_oid, c_name) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } -// Append the map `pairs` to the omap `oid` +// SetOmap appends the map `pairs` to the omap `oid` func (ioctx *IOContext) SetOmap(oid string, pairs map[string][]byte) error { c_oid := C.CString(oid) defer C.free(unsafe.Pointer(c_oid)) @@ -424,7 +447,7 @@ func (ioctx *IOContext) SetOmap(oid string, pairs map[string][]byte) error { ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } // OmapListFunc is the type of the function called for each omap key @@ -463,7 +486,7 @@ func (ioctx *IOContext) ListOmapValues(oid string, startAfter string, filterPref ret := C.rados_read_op_operate(op, ioctx.ioctx, c_oid, 0) if int(ret) != 0 { - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } else if int(c_prval) != 0 { return RadosError(int(c_prval)) } @@ -476,7 +499,7 @@ func (ioctx *IOContext) ListOmapValues(oid string, startAfter string, filterPref ret = C.rados_omap_get_next(c_iter, &c_key, &c_val, &c_len) if int(ret) != 0 { - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } if c_key == nil { @@ -569,7 +592,7 @@ func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error { ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } // CleanOmap clears the omap `oid` @@ -583,7 +606,7 @@ func (ioctx *IOContext) CleanOmap(oid string) error { ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0) C.rados_release_write_op(op) - return GetRadosError(int(ret)) + return getRadosError(int(ret)) } type Iter struct { @@ -599,7 +622,7 @@ type IterToken uint32 func (ioctx *IOContext) Iter() (*Iter, error) { iter := Iter{} if cerr := C.rados_nobjects_list_open(ioctx.ioctx, &iter.ctx); cerr < 0 { - return nil, GetRadosError(int(cerr)) + return nil, getRadosError(int(cerr)) } return &iter, nil } @@ -631,7 +654,7 @@ func (iter *Iter) Next() bool { var c_entry *C.char var c_namespace *C.char if cerr := C.rados_nobjects_list_next(iter.ctx, &c_entry, nil, &c_namespace); cerr < 0 { - iter.err = GetRadosError(int(cerr)) + iter.err = getRadosError(int(cerr)) return false } iter.entry = C.GoString(c_entry) @@ -768,7 +791,7 @@ func (ioctx *IOContext) LockShared(oid, name, cookie, tag, desc string, duration } } -// Release a shared or exclusive lock on an object. +// Unlock releases a shared or exclusive lock on an object. func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error) { c_oid := C.CString(oid) c_name := C.CString(name) @@ -797,9 +820,11 @@ func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error) { } } -// List clients that have locked the named object lock and information about the lock. -// The number of bytes required in each buffer is put in the corresponding size out parameter. -// If any of the provided buffers are too short, -ERANGE is returned after these sizes are filled in. +// ListLockers lists clients that have locked the named object lock and +// information about the lock. +// The number of bytes required in each buffer is put in the corresponding size +// out parameter. If any of the provided buffers are too short, -ERANGE is +// returned after these sizes are filled in. func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error) { c_oid := C.CString(oid) c_name := C.CString(name) @@ -849,12 +874,11 @@ func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error) { if ret < 0 { return nil, RadosError(int(ret)) - } else { - return &LockInfo{int(ret), c_exclusive == 1, C.GoString(c_tag), splitCString(c_clients, c_clients_len), splitCString(c_cookies, c_cookies_len), splitCString(c_addrs, c_addrs_len)}, nil } + return &LockInfo{int(ret), c_exclusive == 1, C.GoString(c_tag), splitCString(c_clients, c_clients_len), splitCString(c_cookies, c_cookies_len), splitCString(c_addrs, c_addrs_len)}, nil } -// Releases a shared or exclusive lock on an object, which was taken by the specified client. +// BreakLock releases a shared or exclusive lock on an object, which was taken by the specified client. func (ioctx *IOContext) BreakLock(oid, name, client, cookie string) (int, error) { c_oid := C.CString(oid) c_name := C.CString(name) diff --git a/vendor/github.com/ceph/go-ceph/rados/rados.go b/vendor/github.com/ceph/go-ceph/rados/rados.go index 22714c2a5d95..18b382d3cc26 100644 --- a/vendor/github.com/ceph/go-ceph/rados/rados.go +++ b/vendor/github.com/ceph/go-ceph/rados/rados.go @@ -14,8 +14,10 @@ import ( "github.com/ceph/go-ceph/errutil" ) +// RadosError represents an error condition returned from the Ceph RADOS APIs. type RadosError int +// Error returns the error string for the RadosError type. func (e RadosError) Error() string { errno, s := errutil.FormatErrno(int(e)) if s == "" { @@ -24,12 +26,19 @@ func (e RadosError) Error() string { return fmt.Sprintf("rados: ret=%d, %s", errno, s) } -var RadosAllNamespaces = C.LIBRADOS_ALL_NSPACES +var ( + // RadosAllNamespaces is used to reset a selected namespace to all namespaces. See the IOContext SetNamespace function. + RadosAllNamespaces = C.LIBRADOS_ALL_NSPACES -var RadosErrorNotFound = RadosError(-C.ENOENT) -var RadosErrorPermissionDenied = RadosError(-C.EPERM) + // RadosErrorNotFound indicates a missing resource. + RadosErrorNotFound = RadosError(-C.ENOENT) + // RadosErrorPermissionDenied indicates a permissions issue. + RadosErrorPermissionDenied = RadosError(-C.EPERM) + // RadosErrorObjectExists indicates that an exclusive object creation failed. + RadosErrorObjectExist = RadosError(-C.EEXIST) +) -func GetRadosError(err int) error { +func getRadosError(err int) error { if err == 0 { return nil } diff --git a/vendor/github.com/ceph/go-ceph/rbd/features.go b/vendor/github.com/ceph/go-ceph/rbd/features.go index 58ab08371b3b..ecffc73dd49b 100644 --- a/vendor/github.com/ceph/go-ceph/rbd/features.go +++ b/vendor/github.com/ceph/go-ceph/rbd/features.go @@ -114,6 +114,10 @@ func GetFeatureByName(name string) *Feature { return nil } +// GetFeatures returns the features bitmask for the rbd image. +// +// Implements: +// int rbd_get_features(rbd_image_t image, uint64_t *features); func (image *Image) GetFeatures() (features uint64, err error) { if err := image.validate(imageIsOpen); err != nil { return 0, err diff --git a/vendor/github.com/ceph/go-ceph/rbd/options.go b/vendor/github.com/ceph/go-ceph/rbd/options.go index b5aa17944396..696b04ec6b1f 100644 --- a/vendor/github.com/ceph/go-ceph/rbd/options.go +++ b/vendor/github.com/ceph/go-ceph/rbd/options.go @@ -33,16 +33,30 @@ type RbdImageOptions struct { type RbdImageOption C.int +// NewRbdImageOptions creates a new RbdImageOptions struct. Call +// RbdImageOptions.Destroy() to free the resources. +// +// Implements: +// void rbd_image_options_create(rbd_image_options_t* opts) func NewRbdImageOptions() *RbdImageOptions { rio := &RbdImageOptions{} C.rbd_image_options_create(&rio.options) return rio } +// Destroy a RbdImageOptions struct and free the associated resources. +// +// Implements: +// void rbd_image_options_destroy(rbd_image_options_t opts); func (rio *RbdImageOptions) Destroy() { C.rbd_image_options_destroy(rio.options) } +// SetString sets the value of the RbdImageOption to the given string. +// +// Implements: +// int rbd_image_options_set_string(rbd_image_options_t opts, int optname, +// const char* optval); func (rio *RbdImageOptions) SetString(option RbdImageOption, value string) error { c_value := C.CString(value) defer C.free(unsafe.Pointer(c_value)) @@ -56,6 +70,11 @@ func (rio *RbdImageOptions) SetString(option RbdImageOption, value string) error return nil } +// GetString returns the string value of the RbdImageOption. +// +// Implements: +// int rbd_image_options_get_string(rbd_image_options_t opts, int optname, +// char* optval, size_t maxlen); func (rio *RbdImageOptions) GetString(option RbdImageOption) (string, error) { value := make([]byte, 4096) @@ -69,6 +88,11 @@ func (rio *RbdImageOptions) GetString(option RbdImageOption) (string, error) { return C.GoString((*C.char)(unsafe.Pointer(&value[0]))), nil } +// SetUint64 sets the value of the RbdImageOption to the given uint64. +// +// Implements: +// int rbd_image_options_set_uint64(rbd_image_options_t opts, int optname, +// const uint64_t optval); func (rio *RbdImageOptions) SetUint64(option RbdImageOption, value uint64) error { c_value := C.uint64_t(value) @@ -81,6 +105,11 @@ func (rio *RbdImageOptions) SetUint64(option RbdImageOption, value uint64) error return nil } +// GetUint64 returns the uint64 value of the RbdImageOption. +// +// Implements: +// int rbd_image_options_get_uint64(rbd_image_options_t opts, int optname, +// uint64_t* optval); func (rio *RbdImageOptions) GetUint64(option RbdImageOption) (uint64, error) { var c_value C.uint64_t @@ -92,6 +121,11 @@ func (rio *RbdImageOptions) GetUint64(option RbdImageOption) (uint64, error) { return uint64(c_value), nil } +// IsSet returns a true if the RbdImageOption is set, false otherwise. +// +// Implements: +// int rbd_image_options_is_set(rbd_image_options_t opts, int optname, +// bool* is_set); func (rio *RbdImageOptions) IsSet(option RbdImageOption) (bool, error) { var c_set C.bool @@ -103,6 +137,10 @@ func (rio *RbdImageOptions) IsSet(option RbdImageOption) (bool, error) { return bool(c_set), nil } +// Unset a given RbdImageOption. +// +// Implements: +// int rbd_image_options_unset(rbd_image_options_t opts, int optname) func (rio *RbdImageOptions) Unset(option RbdImageOption) error { ret := C.rbd_image_options_unset(rio.options, C.int(option)) if ret != 0 { @@ -112,10 +150,19 @@ func (rio *RbdImageOptions) Unset(option RbdImageOption) error { return nil } +// Clear all options in the RbdImageOptions. +// +// Implements: +// void rbd_image_options_clear(rbd_image_options_t opts) func (rio *RbdImageOptions) Clear() { C.rbd_image_options_clear(rio.options) } +// IsEmpty returns true if there are no options set in the RbdImageOptions, +// false otherwise. +// +// Implements: +// int rbd_image_options_is_empty(rbd_image_options_t opts) func (rio *RbdImageOptions) IsEmpty() bool { ret := C.rbd_image_options_is_empty(rio.options) return ret != 0 diff --git a/vendor/github.com/ceph/go-ceph/rbd/rbd.go b/vendor/github.com/ceph/go-ceph/rbd/rbd.go index 149673f003c7..2ec930297bd1 100644 --- a/vendor/github.com/ceph/go-ceph/rbd/rbd.go +++ b/vendor/github.com/ceph/go-ceph/rbd/rbd.go @@ -168,7 +168,7 @@ func GetError(err C.int) error { } } -// +// Version returns the major, minor, and patch level of the librbd library. func Version() (int, int, int) { var c_major, c_minor, c_patch C.int C.rbd_version(&c_major, &c_minor, &c_patch) @@ -199,7 +199,7 @@ func GetImageNames(ioctx *rados.IOContext) (names []string, err error) { } } -// +// GetImage gets a reference to a previously created rbd image. func GetImage(ioctx *rados.IOContext, name string) *Image { return &Image{ ioctx: ioctx, @@ -207,12 +207,15 @@ func GetImage(ioctx *rados.IOContext, name string) *Image { } } -// int rbd_create(rados_ioctx_t io, const char *name, uint64_t size, int *order); +// Create a new rbd image. +// +// Implements: +// int rbd_create(rados_ioctx_t io, const char *name, uint64_t size, int *order); // -// But also (for backward compability): -// int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size, +// Also implements (for backward compatibility): +// int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size, // uint64_t features, int *order); -// int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size, +// int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size, // uint64_t features, int *order, // uint64_t stripe_unit, uint64_t stripe_count); func Create(ioctx *rados.IOContext, name string, size uint64, order int, @@ -247,7 +250,10 @@ func Create(ioctx *rados.IOContext, name string, size uint64, order int, }, nil } -// int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size, +// Create2 creates a new rbd image using provided features. +// +// Implements: +// int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size, // uint64_t features, int *order); func Create2(ioctx *rados.IOContext, name string, size uint64, features uint64, order int) (image *Image, err error) { @@ -270,7 +276,11 @@ func Create2(ioctx *rados.IOContext, name string, size uint64, features uint64, }, nil } -// int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size, +// Create3 creates a new rbd image using provided features and stripe +// parameters. +// +// Implements: +// int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size, // uint64_t features, int *order, // uint64_t stripe_unit, uint64_t stripe_count); func Create3(ioctx *rados.IOContext, name string, size uint64, features uint64, @@ -295,7 +305,10 @@ func Create3(ioctx *rados.IOContext, name string, size uint64, features uint64, }, nil } -// int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size, +// Create4 creates a new rbd image using provided image options. +// +// Implements: +// int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size, // rbd_image_options_t opts); func Create4(ioctx *rados.IOContext, name string, size uint64, rio *RbdImageOptions) (image *Image, err error) { if rio == nil { @@ -318,34 +331,12 @@ func Create4(ioctx *rados.IOContext, name string, size uint64, rio *RbdImageOpti }, nil } -func CreateWithOptions(ioctx *rados.IOContext, name string, size uint64, rio *RbdImageOptions) (image *Image, err error) { - if rio == nil { - return nil, RBDError(C.EINVAL) - } - - c_name := C.CString(name) - defer C.free(unsafe.Pointer(c_name)) - - ret := C.rbd_create4(C.rados_ioctx_t(ioctx.Pointer()), c_name, - C.uint64_t(size), C.rbd_image_options_t(rio.options)) - - if ret < 0 { - return nil, RBDError(ret) - } - - return &Image{ - ioctx: ioctx, - name: name, - }, nil -} - -// int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name, +// Clone a new rbd image from a snapshot. +// +// Implements: +// int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name, // const char *p_snapname, rados_ioctx_t c_ioctx, // const char *c_name, uint64_t features, int *c_order); -// int rbd_clone2(rados_ioctx_t p_ioctx, const char *p_name, -// const char *p_snapname, rados_ioctx_t c_ioctx, -// const char *c_name, uint64_t features, int *c_order, -// uint64_t stripe_unit, int stripe_count); func (image *Image) Clone(snapname string, c_ioctx *rados.IOContext, c_name string, features uint64, order int) (*Image, error) { if err := image.validate(imageNeedsIOContext); err != nil { return nil, err @@ -374,9 +365,10 @@ func (image *Image) Clone(snapname string, c_ioctx *rados.IOContext, c_name stri }, nil } -// int rbd_remove(rados_ioctx_t io, const char *name); -// int rbd_remove_with_progress(rados_ioctx_t io, const char *name, -// librbd_progress_fn_t cb, void *cbdata); +// Remove the specified rbd image. +// +// Implements: +// int rbd_remove(rados_ioctx_t io, const char *name); func (image *Image) Remove() error { if err := image.validate(imageNeedsIOContext | imageNeedsName); err != nil { return err @@ -401,7 +393,10 @@ func (image *Image) Trash(delay time.Duration) error { C.uint64_t(delay.Seconds()))) } -// int rbd_rename(rados_ioctx_t src_io_ctx, const char *srcname, const char *destname); +// Rename an rbd image. +// +// Implements: +// int rbd_rename(rados_ioctx_t src_io_ctx, const char *srcname, const char *destname); func (image *Image) Rename(destname string) error { if err := image.validate(imageNeedsIOContext | imageNeedsName); err != nil { return err @@ -465,7 +460,10 @@ func (image *Image) Open(args ...interface{}) error { return GetError(ret) } -// int rbd_close(rbd_image_t image); +// Close an open rbd image. +// +// Implements: +// int rbd_close(rbd_image_t image); func (image *Image) Close() error { if err := image.validate(imageIsOpen); err != nil { return err @@ -479,7 +477,10 @@ func (image *Image) Close() error { return nil } -// int rbd_resize(rbd_image_t image, uint64_t size); +// Resize an rbd image. +// +// Implements: +// int rbd_resize(rbd_image_t image, uint64_t size); func (image *Image) Resize(size uint64) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -488,7 +489,10 @@ func (image *Image) Resize(size uint64) error { return GetError(C.rbd_resize(image.image, C.uint64_t(size))) } -// int rbd_stat(rbd_image_t image, rbd_image_info_t *info, size_t infosize); +// Stat an rbd image. +// +// Implements: +// int rbd_stat(rbd_image_t image, rbd_image_info_t *info, size_t infosize); func (image *Image) Stat() (info *ImageInfo, err error) { if err := image.validate(imageIsOpen); err != nil { return nil, err @@ -510,7 +514,10 @@ func (image *Image) Stat() (info *ImageInfo, err error) { Parent_name: C.GoString((*C.char)(&c_stat.parent_name[0]))}, nil } -// int rbd_get_old_format(rbd_image_t image, uint8_t *old); +// IsOldFormat returns true if the rbd image uses the old format. +// +// Implements: +// int rbd_get_old_format(rbd_image_t image, uint8_t *old); func (image *Image) IsOldFormat() (old_format bool, err error) { if err := image.validate(imageIsOpen); err != nil { return false, err @@ -526,7 +533,10 @@ func (image *Image) IsOldFormat() (old_format bool, err error) { return c_old_format != 0, nil } -// int rbd_size(rbd_image_t image, uint64_t *size); +// GetSize returns the size of the rbd image. +// +// Implements: +// int rbd_size(rbd_image_t image, uint64_t *size); func (image *Image) GetSize() (size uint64, err error) { if err := image.validate(imageIsOpen); err != nil { return 0, err @@ -539,7 +549,10 @@ func (image *Image) GetSize() (size uint64, err error) { return size, nil } -// int rbd_get_stripe_unit(rbd_image_t image, uint64_t *stripe_unit); +// GetStripeUnit returns the stripe-unit value for the rbd image. +// +// Implements: +// int rbd_get_stripe_unit(rbd_image_t image, uint64_t *stripe_unit); func (image *Image) GetStripeUnit() (stripe_unit uint64, err error) { if err := image.validate(imageIsOpen); err != nil { return 0, err @@ -552,7 +565,10 @@ func (image *Image) GetStripeUnit() (stripe_unit uint64, err error) { return stripe_unit, nil } -// int rbd_get_stripe_count(rbd_image_t image, uint64_t *stripe_count); +// GetStripeCount returns the stripe-count value for the rbd image. +// +// Implements: +// int rbd_get_stripe_count(rbd_image_t image, uint64_t *stripe_count); func (image *Image) GetStripeCount() (stripe_count uint64, err error) { if err := image.validate(imageIsOpen); err != nil { return 0, err @@ -565,7 +581,11 @@ func (image *Image) GetStripeCount() (stripe_count uint64, err error) { return stripe_count, nil } -// int rbd_get_overlap(rbd_image_t image, uint64_t *overlap); +// GetOverlap returns the overlapping bytes between the rbd image and its +// parent. +// +// Implements: +// int rbd_get_overlap(rbd_image_t image, uint64_t *overlap); func (image *Image) GetOverlap() (overlap uint64, err error) { if err := image.validate(imageIsOpen); err != nil { return 0, err @@ -578,7 +598,10 @@ func (image *Image) GetOverlap() (overlap uint64, err error) { return overlap, nil } -// int rbd_copy(rbd_image_t image, rados_ioctx_t dest_io_ctx, const char *destname); +// Copy one rbd image to another. +// +// Implements: +// int rbd_copy(rbd_image_t image, rados_ioctx_t dest_io_ctx, const char *destname); func (image *Image) Copy(ioctx *rados.IOContext, destname string) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -595,7 +618,10 @@ func (image *Image) Copy(ioctx *rados.IOContext, destname string) error { C.rados_ioctx_t(ioctx.Pointer()), c_destname)) } -// int rbd_copy2(rbd_image_t src, rbd_image_t dest); +// Copy one rbd image to another, using an image handle. +// +// Implements: +// int rbd_copy2(rbd_image_t src, rbd_image_t dest); func (image *Image) Copy2(dest *Image) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -606,7 +632,10 @@ func (image *Image) Copy2(dest *Image) error { return GetError(C.rbd_copy2(image.image, dest.image)) } -// int rbd_flatten(rbd_image_t image); +// Flatten removes snapshot references from the image. +// +// Implements: +// int rbd_flatten(rbd_image_t image); func (image *Image) Flatten() error { if err := image.validate(imageIsOpen); err != nil { return err @@ -615,7 +644,10 @@ func (image *Image) Flatten() error { return GetError(C.rbd_flatten(image.image)) } -// ssize_t rbd_list_children(rbd_image_t image, char *pools, size_t *pools_len, +// ListChildren returns a list of images that reference the current snapshot. +// +// Implements: +// ssize_t rbd_list_children(rbd_image_t image, char *pools, size_t *pools_len, // char *images, size_t *images_len); func (image *Image) ListChildren() (pools []string, images []string, err error) { if err := image.validate(imageIsOpen); err != nil { @@ -665,7 +697,10 @@ func (image *Image) ListChildren() (pools []string, images []string, err error) return pools, images, nil } -// ssize_t rbd_list_lockers(rbd_image_t image, int *exclusive, +// ListLockers returns a list of clients that have locks on the image. +// +// Impelemnts: +// ssize_t rbd_list_lockers(rbd_image_t image, int *exclusive, // char *tag, size_t *tag_len, // char *clients, size_t *clients_len, // char *cookies, size_t *cookies_len, @@ -726,7 +761,10 @@ func (image *Image) ListLockers() (tag string, lockers []Locker, err error) { return string(tag_buf), lockers, nil } -// int rbd_lock_exclusive(rbd_image_t image, const char *cookie); +// LockExclusive acquires an exclusive lock on the rbd image. +// +// Implements: +// int rbd_lock_exclusive(rbd_image_t image, const char *cookie); func (image *Image) LockExclusive(cookie string) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -738,7 +776,10 @@ func (image *Image) LockExclusive(cookie string) error { return GetError(C.rbd_lock_exclusive(image.image, c_cookie)) } -// int rbd_lock_shared(rbd_image_t image, const char *cookie, const char *tag); +// LockShared acquires a shared lock on the rbd image. +// +// Implements: +// int rbd_lock_shared(rbd_image_t image, const char *cookie, const char *tag); func (image *Image) LockShared(cookie string, tag string) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -752,7 +793,10 @@ func (image *Image) LockShared(cookie string, tag string) error { return GetError(C.rbd_lock_shared(image.image, c_cookie, c_tag)) } -// int rbd_lock_shared(rbd_image_t image, const char *cookie, const char *tag); +// Unlock releases a lock on the image. +// +// Implements: +// int rbd_lock_shared(rbd_image_t image, const char *cookie, const char *tag); func (image *Image) Unlock(cookie string) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -764,7 +808,10 @@ func (image *Image) Unlock(cookie string) error { return GetError(C.rbd_unlock(image.image, c_cookie)) } -// int rbd_break_lock(rbd_image_t image, const char *client, const char *cookie); +// BreakLock forces the release of a lock held by another client. +// +// Implements: +// int rbd_break_lock(rbd_image_t image, const char *client, const char *cookie); func (image *Image) BreakLock(client string, cookie string) error { if err := image.validate(imageIsOpen); err != nil { return err @@ -787,7 +834,7 @@ func (image *Image) BreakLock(client string, cookie string) error { // const char *fromsnapname, // uint64_t ofs, uint64_t len, // int (*cb)(uint64_t, size_t, int, void *), void *arg); -func (image *Image) Read(data []byte) (n int, err error) { +func (image *Image) Read(data []byte) (int, error) { if err := image.validate(imageIsOpen); err != nil { return 0, err } @@ -807,7 +854,7 @@ func (image *Image) Read(data []byte) (n int, err error) { } image.offset += int64(ret) - if ret < n { + if ret < len(data) { return ret, io.EOF } @@ -866,7 +913,7 @@ func (image *Image) Discard(ofs uint64, length uint64) (int, error) { return int(ret), nil } -func (image *Image) ReadAt(data []byte, off int64) (n int, err error) { +func (image *Image) ReadAt(data []byte, off int64) (int, error) { if err := image.validate(imageIsOpen); err != nil { return 0, err } @@ -885,7 +932,7 @@ func (image *Image) ReadAt(data []byte, off int64) (n int, err error) { return 0, RBDError(ret) } - if ret < n { + if ret < len(data) { return ret, io.EOF }