timespec: move to internal pkg

There are functions from librbd that can use the Timespec type too.
Instead of consuming 'cephfs.Timespec' in the rbd package, create an
internal type that can be exposed through both packages.

This looks a bit like duplication, but it does not break the current
users of Timespec in the cephfs package.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-17 15:10:27 +02:00 committed by John Mulligan
parent 3a0bacb039
commit c4714165a6
2 changed files with 21 additions and 6 deletions

View File

@ -7,6 +7,13 @@ package cephfs
*/
import "C"
import (
ts "github.com/ceph/go-ceph/internal/timespec"
)
// Timespec is a public type for the internal C 'struct timespec'
type Timespec ts.Timespec
// StatxMask values contain bit-flags indicating what data should be
// populated by a statx-type call.
type StatxMask uint32
@ -109,10 +116,10 @@ func cStructToCephStatx(s C.struct_ceph_statx) *CephStatx {
Blocks: uint64(s.stx_blocks),
Dev: uint64(s.stx_dev),
Rdev: uint64(s.stx_rdev),
Atime: cStructToTimespec(s.stx_atime),
Ctime: cStructToTimespec(s.stx_ctime),
Mtime: cStructToTimespec(s.stx_mtime),
Btime: cStructToTimespec(s.stx_btime),
Atime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_atime))),
Ctime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_ctime))),
Mtime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_mtime))),
Btime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_btime))),
Version: uint64(s.stx_version),
}
}

View File

@ -1,4 +1,4 @@
package cephfs
package timespec
/*
#include <time.h>
@ -6,6 +6,8 @@ package cephfs
import "C"
import (
"unsafe"
"golang.org/x/sys/unix"
)
@ -14,7 +16,13 @@ import (
// apis that could be lossy with the use of Go time types.
type Timespec unix.Timespec
func cStructToTimespec(t C.struct_timespec) Timespec {
// CTimespecPtr is an unsafe pointer wrapping C's `struct timespec`.
type CTimespecPtr unsafe.Pointer
// CStructToTimespec creates a new Timespec for the C 'struct timespec'.
func CStructToTimespec(cts CTimespecPtr) Timespec {
t := (*C.struct_timespec)(cts)
return Timespec{
Sec: int64(t.tv_sec),
Nsec: int64(t.tv_nsec),