-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rbd: add EncryptionLoad2 implementing rbd_encryption_load2 #1061
Draft
phlogistonjohn
wants to merge
8
commits into
ceph:master
Choose a base branch
from
phlogistonjohn:jjm-rbd-enc-load2-1059
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b8b523b
rbd: fix a pair of erroneous comments
phlogistonjohn 2d638fd
rbd: clean up rbd encryption load test case
phlogistonjohn d6bec46
rbd: add EncryptionLoad2 implementing rbd_encryption_load2
phlogistonjohn 443d19f
rbd: add EncryptionOptionsLUKS for opening LUKS images
phlogistonjohn 3beaad6
xxx:squash: C objects only for C call
phlogistonjohn f138ee4
xxx:sqaush: C object style for new type
phlogistonjohn a97b653
entrypoint: increase test timeout needed for rbd
phlogistonjohn 2ca6350
xxx:squash: doc update
phlogistonjohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ func (opts EncryptionOptionsLUKS1) allocateEncryptionOptions() cEncryptionData { | |
var cOpts C.rbd_encryption_luks1_format_options_t | ||
var retData cEncryptionData | ||
cOpts.alg = C.rbd_encryption_algorithm_t(opts.Alg) | ||
//CBytes allocates memory which we'll free by calling cOptsFree() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just outdated? Because I don't see any change regarding |
||
// CBytes allocates memory. it will be freed when cEncryptionData.free is called | ||
cOpts.passphrase = (*C.char)(C.CBytes(opts.Passphrase)) | ||
cOpts.passphrase_size = C.size_t(len(opts.Passphrase)) | ||
retData.opts = C.rbd_encryption_options_t(&cOpts) | ||
|
@@ -78,7 +78,7 @@ func (opts EncryptionOptionsLUKS2) allocateEncryptionOptions() cEncryptionData { | |
var cOpts C.rbd_encryption_luks2_format_options_t | ||
var retData cEncryptionData | ||
cOpts.alg = C.rbd_encryption_algorithm_t(opts.Alg) | ||
//CBytes allocates memory which we'll free by calling cOptsFree() | ||
// CBytes allocates memory. it will be freed when cEncryptionData.free is called | ||
cOpts.passphrase = (*C.char)(C.CBytes(opts.Passphrase)) | ||
cOpts.passphrase_size = C.size_t(len(opts.Passphrase)) | ||
retData.opts = C.rbd_encryption_options_t(&cOpts) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//go:build !octopus && !pacific && !quincy && ceph_preview | ||
|
||
package rbd | ||
|
||
// #cgo LDFLAGS: -lrbd | ||
// /* force XSI-complaint strerror_r() */ | ||
// #define _POSIX_C_SOURCE 200112L | ||
// #undef _GNU_SOURCE | ||
// #include <stdlib.h> | ||
// #include <rbd/librbd.h> | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
type encryptionOptions2 interface { | ||
EncryptionOptions | ||
writeEncryptionSpec(spec *C.rbd_encryption_spec_t) func() | ||
} | ||
|
||
func (opts EncryptionOptionsLUKS1) writeEncryptionSpec(spec *C.rbd_encryption_spec_t) func() { | ||
/* only C memory should be attached to spec */ | ||
cPassphrase := (*C.char)(C.CBytes(opts.Passphrase)) | ||
cOptsSize := C.size_t(C.sizeof_rbd_encryption_luks1_format_options_t) | ||
cOpts := (*C.rbd_encryption_luks1_format_options_t)(C.malloc(cOptsSize)) | ||
cOpts.alg = C.rbd_encryption_algorithm_t(opts.Alg) | ||
cOpts.passphrase = cPassphrase | ||
cOpts.passphrase_size = C.size_t(len(opts.Passphrase)) | ||
|
||
spec.format = C.RBD_ENCRYPTION_FORMAT_LUKS1 | ||
spec.opts = C.rbd_encryption_options_t(cOpts) | ||
spec.opts_size = cOptsSize | ||
return func() { | ||
C.free(unsafe.Pointer(cOpts.passphrase)) | ||
C.free(unsafe.Pointer(cOpts)) | ||
} | ||
} | ||
|
||
func (opts EncryptionOptionsLUKS2) writeEncryptionSpec(spec *C.rbd_encryption_spec_t) func() { | ||
/* only C memory should be attached to spec */ | ||
cPassphrase := (*C.char)(C.CBytes(opts.Passphrase)) | ||
cOptsSize := C.size_t(C.sizeof_rbd_encryption_luks2_format_options_t) | ||
cOpts := (*C.rbd_encryption_luks2_format_options_t)(C.malloc(cOptsSize)) | ||
cOpts.alg = C.rbd_encryption_algorithm_t(opts.Alg) | ||
cOpts.passphrase = cPassphrase | ||
cOpts.passphrase_size = C.size_t(len(opts.Passphrase)) | ||
|
||
spec.format = C.RBD_ENCRYPTION_FORMAT_LUKS2 | ||
spec.opts = C.rbd_encryption_options_t(cOpts) | ||
spec.opts_size = cOptsSize | ||
return func() { | ||
C.free(unsafe.Pointer(cOpts.passphrase)) | ||
C.free(unsafe.Pointer(cOpts)) | ||
} | ||
} | ||
|
||
// EncryptionLoad2 enables IO on an open encrypted image. Multiple encryption | ||
// option values can be passed to this call in a slice. For more information | ||
// about how items in the slice are applied to images, and possibly ancestor | ||
// images refer to the documentation in the C api for rbd_encryption_load2. | ||
// | ||
// Implements: | ||
// | ||
// int rbd_encryption_load2(rbd_image_t image, | ||
// const rbd_encryption_spec_t *specs, | ||
// size_t spec_count); | ||
func (image *Image) EncryptionLoad2(opts []EncryptionOptions) error { | ||
if image.image == nil { | ||
return ErrImageNotOpen | ||
} | ||
for _, o := range opts { | ||
if _, ok := o.(encryptionOptions2); !ok { | ||
return ErrImageNotOpen /* fixme */ | ||
} | ||
} | ||
|
||
length := len(opts) | ||
cspecs := (*C.rbd_encryption_spec_t)(C.malloc( | ||
C.size_t(C.sizeof_rbd_encryption_spec_t * length))) | ||
specs := unsafe.Slice(cspecs, length) | ||
freeFuncs := make([]func(), length) | ||
|
||
for idx, option := range opts { | ||
f := option.(encryptionOptions2).writeEncryptionSpec(&specs[idx]) | ||
freeFuncs[idx] = f | ||
} | ||
defer func() { | ||
for _, f := range freeFuncs { | ||
f() | ||
} | ||
C.free(unsafe.Pointer(cspecs)) | ||
}() | ||
|
||
ret := C.rbd_encryption_load2( | ||
image.image, | ||
cspecs, | ||
C.size_t(length)) | ||
return getError(ret) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this always the case that we hit the timeout with these additional tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, running all 3 new tests causes the rbd run to take just over 10m. Note that rbd is the only package that takes this long, but I am far too lazy to try and customize the timeout only for rbd.