rbd: update doc comments for rbd image Read and Write funcs

The comments above Read and Write were very old and not up to our
current standards. Update them to be accurate and note that the
offset internal to the image type is not concurrency safe.
This also cleans up some old and unhelpful todos.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2021-12-20 13:47:13 -05:00 committed by mergify[bot]
parent 573598cf22
commit dae56d0c65
1 changed files with 14 additions and 10 deletions

View File

@ -706,15 +706,13 @@ func (image *Image) BreakLock(client string, cookie string) error {
return getError(C.rbd_break_lock(image.image, cClient, cCookie)) return getError(C.rbd_break_lock(image.image, cClient, cCookie))
} }
// ssize_t rbd_read(rbd_image_t image, uint64_t ofs, size_t len, char *buf); // Read data from the image. The length of the read is determined by the length
// TODO: int64_t rbd_read_iterate(rbd_image_t image, uint64_t ofs, size_t len, // of the buffer slice. The position of the read is determined by an internal
// int (*cb)(uint64_t, size_t, const char *, void *), void *arg); // offset which is not safe in concurrent code. Prefer ReadAt when possible.
// TODO: int rbd_read_iterate2(rbd_image_t image, uint64_t ofs, uint64_t len, //
// int (*cb)(uint64_t, size_t, const char *, void *), void *arg); // Implements:
// TODO: int rbd_diff_iterate(rbd_image_t image, // ssize_t rbd_read(rbd_image_t image, uint64_t ofs, size_t len,
// const char *fromsnapname, // char *buf);
// uint64_t ofs, uint64_t len,
// int (*cb)(uint64_t, size_t, int, void *), void *arg);
func (image *Image) Read(data []byte) (int, error) { func (image *Image) Read(data []byte) (int, error) {
if err := image.validate(imageIsOpen); err != nil { if err := image.validate(imageIsOpen); err != nil {
return 0, err return 0, err
@ -742,7 +740,13 @@ func (image *Image) Read(data []byte) (int, error) {
return ret, nil return ret, nil
} }
// ssize_t rbd_write(rbd_image_t image, uint64_t ofs, size_t len, const char *buf); // Write data to an image. The length of the write is determined by the length of
// the buffer slice. The position of the write is determined by an internal
// offset which is not safe in concurrent code. Prefer WriteAt when possible.
//
// Implements:
// ssize_t rbd_write(rbd_image_t image, uint64_t ofs, size_t len,
// const char *buf);
func (image *Image) Write(data []byte) (n int, err error) { func (image *Image) Write(data []byte) (n int, err error) {
if err := image.validate(imageIsOpen); err != nil { if err := image.validate(imageIsOpen); err != nil {
return 0, err return 0, err