docs: add package and doc comments for exported identifiers
Document every exported type, function and method in the migration, storage and cephfsnative packages and add package comments for migration and the cephmig command, following the commentary rules of Effective Go. Comments on unexported helpers now start with the name they describe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7413b9a43a
commit
c2ef7a6c3b
12 files changed
+150
-7
No files matched your search
@@ -58,6 +58,7 @@ import (
|
||||
"git.zb-server.de/Sebi/CephfsMig/internal/storage"
|
||||
)
|
||||
|
||||
// Client is a libcephfs connection that implements storage.FS.
|
||||
type Client struct{ mount *C.struct_ceph_mount_info }
|
||||
|
||||
func errno(ret C.int) error {
|
||||
@@ -70,6 +71,9 @@ func str(s string) (*C.char, func()) {
|
||||
p := C.CString(s)
|
||||
return p, func() { C.free(unsafe.Pointer(p)) }
|
||||
}
|
||||
|
||||
// Open connects to the cluster described by o and mounts the root of the
|
||||
// selected filesystem in userspace.
|
||||
func Open(o storage.Options) (*Client, error) {
|
||||
c := &Client{}
|
||||
user := strings.TrimPrefix(o.User, "client.")
|
||||
@@ -117,6 +121,8 @@ func Open(o storage.Options) (*Client, error) {
|
||||
failed = false
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Close unmounts and releases the connection. It is safe to call twice.
|
||||
func (c *Client) Close() error {
|
||||
if c.mount != nil {
|
||||
C.ceph_shutdown(c.mount)
|
||||
@@ -130,6 +136,8 @@ func node(s C.struct_ceph_statx) storage.Node {
|
||||
Rdev: uint64(s.stx_rdev), UID: uint32(s.stx_uid), GID: uint32(s.stx_gid),
|
||||
Mtime: time.Unix(int64(s.stx_mtime.tv_sec), int64(s.stx_mtime.tv_nsec))}
|
||||
}
|
||||
|
||||
// Stat returns the attributes of path without following a final symlink.
|
||||
func (c *Client) Stat(path string) (storage.Node, error) {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -148,6 +156,8 @@ func nativeStatFlags(path string) C.int {
|
||||
}
|
||||
return flags
|
||||
}
|
||||
|
||||
// Open opens the file at path with open(2) flags and mode.
|
||||
func (c *Client) Open(path string, flags int, mode uint32) (storage.File, error) {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -215,6 +225,7 @@ type dir struct {
|
||||
flags C.int
|
||||
}
|
||||
|
||||
// OpenDir opens the directory at path for iteration.
|
||||
func (c *Client) OpenDir(path string) (storage.DirectoryStream, error) {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -244,21 +255,29 @@ func (d *dir) Next() (*storage.Entry, error) {
|
||||
}
|
||||
}
|
||||
func (d *dir) Close() error { return errno(C.ceph_closedir(d.client.mount, d.handle)) }
|
||||
|
||||
// Mkdir creates a directory.
|
||||
func (c *Client) Mkdir(path string, mode uint32) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
return errno(C.ceph_mkdir(c.mount, p, C.mode_t(mode)))
|
||||
}
|
||||
|
||||
// Unlink removes a non-directory entry.
|
||||
func (c *Client) Unlink(path string) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
return errno(C.ceph_unlink(c.mount, p))
|
||||
}
|
||||
|
||||
// Rmdir removes an empty directory.
|
||||
func (c *Client) Rmdir(path string) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
return errno(C.ceph_rmdir(c.mount, p))
|
||||
}
|
||||
|
||||
// Rename renames a to b.
|
||||
func (c *Client) Rename(a, b string) error {
|
||||
p, f := str(a)
|
||||
defer f()
|
||||
@@ -266,6 +285,8 @@ func (c *Client) Rename(a, b string) error {
|
||||
defer g()
|
||||
return errno(C.ceph_rename(c.mount, p, q))
|
||||
}
|
||||
|
||||
// Link creates the hard link b to a without following a symlink at a.
|
||||
func (c *Client) Link(a, b string) error {
|
||||
p, f := str(a)
|
||||
defer f()
|
||||
@@ -275,6 +296,8 @@ func (c *Client) Link(a, b string) error {
|
||||
defer h()
|
||||
return errno(C.cm_link_nofollow(c.mount, p, q, name))
|
||||
}
|
||||
|
||||
// Symlink creates the symbolic link b pointing to a.
|
||||
func (c *Client) Symlink(a, b string) error {
|
||||
p, f := str(a)
|
||||
defer f()
|
||||
@@ -282,11 +305,15 @@ func (c *Client) Symlink(a, b string) error {
|
||||
defer g()
|
||||
return errno(C.ceph_symlink(c.mount, p, q))
|
||||
}
|
||||
|
||||
// Mknod creates a special file.
|
||||
func (c *Client) Mknod(path string, mode uint32, dev uint64) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
return errno(C.ceph_mknod(c.mount, p, C.mode_t(mode), C.dev_t(dev)))
|
||||
}
|
||||
|
||||
// Readlink returns the target of a symbolic link.
|
||||
func (c *Client) Readlink(path string) (string, error) {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -302,11 +329,15 @@ func (c *Client) Readlink(path string) (string, error) {
|
||||
}
|
||||
return "", errors.New("symlink target exceeds 1 MiB")
|
||||
}
|
||||
|
||||
// SetAttr sets numeric owner, mode and mtime without following symlinks.
|
||||
func (c *Client) SetAttr(path string, n storage.Node) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
return errno(C.cm_attr(c.mount, p, C.uint(n.Mode), C.uint(n.UID), C.uint(n.GID), C.long(n.Mtime.Unix()), C.long(n.Mtime.Nanosecond())))
|
||||
}
|
||||
|
||||
// GetXattr returns the value of an extended attribute.
|
||||
func (c *Client) GetXattr(path, key string) ([]byte, error) {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -325,6 +356,8 @@ func (c *Client) GetXattr(path, key string) ([]byte, error) {
|
||||
}
|
||||
return nil, errors.New("xattr exceeds 1 MiB")
|
||||
}
|
||||
|
||||
// ListXattr returns the names of all extended attributes of path.
|
||||
func (c *Client) ListXattr(path string) ([]string, error) {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -347,6 +380,8 @@ func (c *Client) ListXattr(path string) ([]string, error) {
|
||||
}
|
||||
return nil, errors.New("xattr list exceeds 1 MiB")
|
||||
}
|
||||
|
||||
// SetXattr sets an extended attribute.
|
||||
func (c *Client) SetXattr(path, key string, b []byte) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -358,6 +393,8 @@ func (c *Client) SetXattr(path, key string, b []byte) error {
|
||||
}
|
||||
return errno(C.ceph_lsetxattr(c.mount, p, k, ptr, C.size_t(len(b)), 0))
|
||||
}
|
||||
|
||||
// RemoveXattr removes an extended attribute.
|
||||
func (c *Client) RemoveXattr(path, key string) error {
|
||||
p, f := str(path)
|
||||
defer f()
|
||||
@@ -365,10 +402,14 @@ func (c *Client) RemoveXattr(path, key string) error {
|
||||
defer g()
|
||||
return errno(C.ceph_lremovexattr(c.mount, p, k))
|
||||
}
|
||||
|
||||
// Sync flushes all dirty data and metadata of the filesystem.
|
||||
func (c *Client) Sync() error { return errno(C.ceph_sync_fs(c.mount)) }
|
||||
|
||||
type snapDiff struct{ info C.struct_ceph_snapdiff_info }
|
||||
|
||||
// SnapDiff lists the entries below root/rel that differ between
|
||||
// snapshots a and b.
|
||||
func (c *Client) SnapDiff(root, rel, a, b string) (storage.DiffStream, error) {
|
||||
p, f := str(root)
|
||||
defer f()
|
||||
@@ -408,6 +449,8 @@ type blockDiff struct {
|
||||
done bool
|
||||
}
|
||||
|
||||
// BlockDiff lists the changed extents of the file root/rel between
|
||||
// snapshots a and b.
|
||||
func (c *Client) BlockDiff(root, rel, a, b string) (storage.BlockStream, error) {
|
||||
p, f := str(root)
|
||||
defer f()
|
||||
|
||||
Reference in new issue
Block a user