mirror of
https://github.com/ceph/go-ceph
synced 2024-12-22 06:10:09 +00:00
rbd: add Sparsify implementing rbd_sparsify
The sparsify function can be used to make an image sparse by replacing runs of zeros with holes. This change adds a wrapper for the basic rbd_sparsify function and accompanying tests. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
176a163c3c
commit
dbf20aea0a
@ -101,3 +101,17 @@ func (image *Image) GetModifyTimestamp() (Timespec, error) {
|
||||
|
||||
return Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&cts))), nil
|
||||
}
|
||||
|
||||
// Sparsify makes an image sparse by deallocating runs of zeros.
|
||||
// The sparseSize value will be used to find runs of zeros and must be
|
||||
// a power of two no less than 4096 and no larger than the image size.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_sparsify(rbd_image_t image, size_t sparse_size);
|
||||
func (image *Image) Sparsify(sparseSize uint) error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return getError(C.rbd_sparsify(image.image, C.size_t(sparseSize)))
|
||||
}
|
||||
|
@ -77,3 +77,49 @@ func TestClosedImageNautilus(t *testing.T) {
|
||||
_, err = image.GetModifyTimestamp()
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestSparsify(t *testing.T) {
|
||||
conn := radosConnect(t)
|
||||
defer conn.Shutdown()
|
||||
|
||||
poolname := GetUUID()
|
||||
err := conn.MakePool(poolname)
|
||||
require.NoError(t, err)
|
||||
defer conn.DeletePool(poolname)
|
||||
|
||||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
require.NoError(t, err)
|
||||
defer ioctx.Destroy()
|
||||
|
||||
name := GetUUID()
|
||||
err = quickCreate(ioctx, name, testImageSize, testImageOrder)
|
||||
require.NoError(t, err)
|
||||
defer func() { assert.NoError(t, RemoveImage(ioctx, name)) }()
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
img, err := OpenImage(ioctx, name, NoSnapshot)
|
||||
assert.NoError(t, err)
|
||||
defer func() { assert.NoError(t, img.Close()) }()
|
||||
|
||||
err = img.Sparsify(4096)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("invalidValue", func(t *testing.T) {
|
||||
img, err := OpenImage(ioctx, name, NoSnapshot)
|
||||
assert.NoError(t, err)
|
||||
defer func() { assert.NoError(t, img.Close()) }()
|
||||
|
||||
err = img.Sparsify(1024)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("closedImage", func(t *testing.T) {
|
||||
img, err := OpenImage(ioctx, name, NoSnapshot)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, img.Close())
|
||||
|
||||
err = img.Sparsify(1024)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user