crypto: Make block callbacks return 0 on success
They currently return the value of their headerlen/buflen parameter on success. Returning 0 instead makes it clear that short reads/writes are not possible. Signed-off-by: Alberto Faria <afaria@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20220609152744.3891847-5-afaria@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
This commit is contained in:
parent
353a5d84b2
commit
757dda54b4
@ -55,7 +55,7 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format,
|
||||
}
|
||||
|
||||
|
||||
static ssize_t block_crypto_read_func(QCryptoBlock *block,
|
||||
static int block_crypto_read_func(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
uint8_t *buf,
|
||||
size_t buflen,
|
||||
@ -70,10 +70,10 @@ static ssize_t block_crypto_read_func(QCryptoBlock *block,
|
||||
error_setg_errno(errp, -ret, "Could not read encryption header");
|
||||
return ret;
|
||||
}
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t block_crypto_write_func(QCryptoBlock *block,
|
||||
static int block_crypto_write_func(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
const uint8_t *buf,
|
||||
size_t buflen,
|
||||
@ -88,7 +88,7 @@ static ssize_t block_crypto_write_func(QCryptoBlock *block,
|
||||
error_setg_errno(errp, -ret, "Could not write encryption header");
|
||||
return ret;
|
||||
}
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ struct BlockCryptoCreateData {
|
||||
};
|
||||
|
||||
|
||||
static ssize_t block_crypto_create_write_func(QCryptoBlock *block,
|
||||
static int block_crypto_create_write_func(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
const uint8_t *buf,
|
||||
size_t buflen,
|
||||
@ -114,10 +114,10 @@ static ssize_t block_crypto_create_write_func(QCryptoBlock *block,
|
||||
error_setg_errno(errp, -ret, "Could not write encryption header");
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t block_crypto_create_init_func(QCryptoBlock *block,
|
||||
static int block_crypto_create_init_func(QCryptoBlock *block,
|
||||
size_t headerlen,
|
||||
void *opaque,
|
||||
Error **errp)
|
||||
@ -139,7 +139,7 @@ static ssize_t block_crypto_create_init_func(QCryptoBlock *block,
|
||||
data->prealloc, 0, &local_error);
|
||||
|
||||
if (ret >= 0) {
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
error:
|
||||
|
@ -94,7 +94,7 @@ static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||
}
|
||||
|
||||
|
||||
static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset,
|
||||
static int qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset,
|
||||
uint8_t *buf, size_t buflen,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
@ -113,11 +113,11 @@ static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset,
|
||||
error_setg_errno(errp, -ret, "Could not read encryption header");
|
||||
return -1;
|
||||
}
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen,
|
||||
static int qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
BlockDriverState *bs = opaque;
|
||||
@ -151,11 +151,11 @@ static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset,
|
||||
static int qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset,
|
||||
const uint8_t *buf, size_t buflen,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
@ -174,7 +174,7 @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset,
|
||||
error_setg_errno(errp, -ret, "Could not read encryption header");
|
||||
return -1;
|
||||
}
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QDict*
|
||||
|
@ -495,7 +495,7 @@ qcrypto_block_luks_load_header(QCryptoBlock *block,
|
||||
void *opaque,
|
||||
Error **errp)
|
||||
{
|
||||
ssize_t rv;
|
||||
int rv;
|
||||
size_t i;
|
||||
QCryptoBlockLUKS *luks = block->opaque;
|
||||
|
||||
@ -856,7 +856,7 @@ qcrypto_block_luks_store_key(QCryptoBlock *block,
|
||||
QCRYPTO_BLOCK_LUKS_SECTOR_SIZE,
|
||||
splitkey, splitkeylen,
|
||||
opaque,
|
||||
errp) != splitkeylen) {
|
||||
errp) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -903,7 +903,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block,
|
||||
g_autofree uint8_t *splitkey = NULL;
|
||||
size_t splitkeylen;
|
||||
g_autofree uint8_t *possiblekey = NULL;
|
||||
ssize_t rv;
|
||||
int rv;
|
||||
g_autoptr(QCryptoCipher) cipher = NULL;
|
||||
uint8_t keydigest[QCRYPTO_BLOCK_LUKS_DIGEST_LEN];
|
||||
g_autoptr(QCryptoIVGen) ivgen = NULL;
|
||||
@ -1193,7 +1193,7 @@ qcrypto_block_luks_erase_key(QCryptoBlock *block,
|
||||
garbagesplitkey,
|
||||
splitkeylen,
|
||||
opaque,
|
||||
&local_err) != splitkeylen) {
|
||||
&local_err) < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
return -1;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
|
||||
}
|
||||
|
||||
|
||||
static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
|
||||
static int qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
|
||||
size_t headerlen, void *opaque, Error **errp)
|
||||
{
|
||||
size_t *headerlenp = opaque;
|
||||
@ -126,12 +126,12 @@ static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
|
||||
}
|
||||
|
||||
|
||||
static ssize_t qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
|
||||
static int qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
|
||||
size_t offset, const uint8_t *buf, size_t buflen,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
/* Discard the bytes, we're not actually writing to an image */
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,19 +29,19 @@ typedef struct QCryptoBlock QCryptoBlock;
|
||||
/* See also QCryptoBlockFormat, QCryptoBlockCreateOptions
|
||||
* and QCryptoBlockOpenOptions in qapi/crypto.json */
|
||||
|
||||
typedef ssize_t (*QCryptoBlockReadFunc)(QCryptoBlock *block,
|
||||
typedef int (*QCryptoBlockReadFunc)(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
uint8_t *buf,
|
||||
size_t buflen,
|
||||
void *opaque,
|
||||
Error **errp);
|
||||
|
||||
typedef ssize_t (*QCryptoBlockInitFunc)(QCryptoBlock *block,
|
||||
typedef int (*QCryptoBlockInitFunc)(QCryptoBlock *block,
|
||||
size_t headerlen,
|
||||
void *opaque,
|
||||
Error **errp);
|
||||
|
||||
typedef ssize_t (*QCryptoBlockWriteFunc)(QCryptoBlock *block,
|
||||
typedef int (*QCryptoBlockWriteFunc)(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
const uint8_t *buf,
|
||||
size_t buflen,
|
||||
|
@ -188,7 +188,7 @@ static struct QCryptoBlockTestData {
|
||||
};
|
||||
|
||||
|
||||
static ssize_t test_block_read_func(QCryptoBlock *block,
|
||||
static int test_block_read_func(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
uint8_t *buf,
|
||||
size_t buflen,
|
||||
@ -201,11 +201,11 @@ static ssize_t test_block_read_func(QCryptoBlock *block,
|
||||
|
||||
memcpy(buf, header->buffer + offset, buflen);
|
||||
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t test_block_init_func(QCryptoBlock *block,
|
||||
static int test_block_init_func(QCryptoBlock *block,
|
||||
size_t headerlen,
|
||||
void *opaque,
|
||||
Error **errp)
|
||||
@ -216,11 +216,11 @@ static ssize_t test_block_init_func(QCryptoBlock *block,
|
||||
|
||||
buffer_reserve(header, headerlen);
|
||||
|
||||
return headerlen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t test_block_write_func(QCryptoBlock *block,
|
||||
static int test_block_write_func(QCryptoBlock *block,
|
||||
size_t offset,
|
||||
const uint8_t *buf,
|
||||
size_t buflen,
|
||||
@ -234,7 +234,7 @@ static ssize_t test_block_write_func(QCryptoBlock *block,
|
||||
memcpy(header->buffer + offset, buf, buflen);
|
||||
header->offset = offset + buflen;
|
||||
|
||||
return buflen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user