Skip to content
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

OpenXT build fixes #383

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions cbt/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sbin_PROGRAMS = cbt-util
noinst_LTLIBRARIES = libcbtutil.la

libcbtutil_la_SOURCES = cbt-util.c

libcbtutil_la_LIBADD = -luuid

cbt_util_SOURCES = main.c
Expand Down
12 changes: 8 additions & 4 deletions drivers/block-crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "libvhd.h"
#include "tapdisk.h"
#include "vhd-util.h"
#include "util.h"

#include "crypto/compat-crypto-openssl.h"
#include "crypto/xts_aes.h"
Expand Down Expand Up @@ -133,7 +134,7 @@ find_keyfile(char **keyfile, const char *dirs,
*keyfile = NULL;

while (dirs && strlen(dirs) > 0) {
char keydir[256] = { 0 }, path[256] = { 0 };
char keydir[256] = { 0 }, path[277] = { 0 };
struct stat st;
int err;

Expand Down Expand Up @@ -348,20 +349,23 @@ vhd_open_crypto(vhd_context_t *vhd, const uint8_t *key, size_t key_bytes, const
struct vhd_keyhash keyhash;
int err;
#ifdef OPEN_XT
uint8_t key[MAX_AES_XTS_PLAIN_KEYSIZE / sizeof(uint8_t)] = { 0 };
int keysize = 0;
uint8_t keybuf[MAX_AES_XTS_PLAIN_KEYSIZE / sizeof(uint8_t)] = { 0 };
key = keybuf;
int key_bits;
#endif

if (vhd->xts_tfm)
return 0;

#ifdef OPEN_XT
err = chain_find_keyed_vhd(vhd, key, &keysize, &keyhash);
err = chain_find_keyed_vhd(vhd, keybuf, &key_bits, &keyhash);
if (err) {
DPRINTF("error in vhd chain: %d\n", err);
return err;
}

key_bytes = key_bits / 8;

if (keyhash.cookie == 0) {
return 0;
}
Expand Down
18 changes: 12 additions & 6 deletions drivers/block-vhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,19 @@ void dummy_close_crypto(vhd_context_t *vhd)
static int
__load_crypto(struct td_vbd_encryption *encryption)
{
bool load_crypto = encryption->encryption_key != NULL;

crypto_interface = malloc(sizeof(struct crypto_interface));
if (!crypto_interface) {
EPRINTF("Failed to allocate memory\n");
return -ENOMEM;
}

if (encryption->encryption_key == NULL) {
crypto_interface->vhd_open_crypto = dummy_open_crypto;
crypto_interface->vhd_close_crypto = dummy_close_crypto;
crypto_interface->vhd_crypto_encrypt = NULL;
crypto_interface->vhd_crypto_decrypt = NULL;
} else {
#ifdef OPEN_XT
load_crypto = true;
#endif

if (load_crypto) {
dlerror();
crypto_handle = dlopen(LIBBLOCKCRYPTO_NAME, RTLD_LAZY);
if (crypto_handle == NULL) {
Expand Down Expand Up @@ -739,6 +740,11 @@ __load_crypto(struct td_vbd_encryption *encryption)
return -EINVAL;
}
DPRINTF("Loaded cryptography library\n");
} else {
crypto_interface->vhd_open_crypto = dummy_open_crypto;
crypto_interface->vhd_close_crypto = dummy_close_crypto;
crypto_interface->vhd_crypto_encrypt = NULL;
crypto_interface->vhd_crypto_decrypt = NULL;
}

return 0;
Expand Down
6 changes: 0 additions & 6 deletions drivers/tapdisk-blktap.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
#define WARN(_f, _a...) tlog_syslog(TLOG_WARN, "WARNING: "_f "in %s:%d", \
##_a, __func__, __LINE__)

#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))

#define BLKTAP_RD32(_n) __RD32(_n)
#define BLKTAP_RING_SIZE __BLKTAP_RING_SIZE(PAGE_SIZE)

Expand Down
7 changes: 0 additions & 7 deletions drivers/tapdisk-vbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,10 +1891,3 @@ tapdisk_vbd_stats(td_vbd_t *vbd, td_stats_t *st)

tapdisk_stats_leave(st, '}');
}


bool
tapdisk_vbd_contains_dead_rings(td_vbd_t * vbd)
{
return !list_empty(&vbd->dead_rings);
}
6 changes: 5 additions & 1 deletion drivers/tapdisk-vbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,9 @@ void tapdisk_vbd_complete_block_status_request(td_request_t, int);
/**
* Tells whether the VBD contains at least one dead ring.
*/
bool tapdisk_vbd_contains_dead_rings(td_vbd_t * vbd);
static inline bool
tapdisk_vbd_contains_dead_rings(td_vbd_t * vbd)
{
return !list_empty(&vbd->dead_rings);
}
#endif
56 changes: 35 additions & 21 deletions drivers/td-blkif.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@
#include "td-ctx.h"
#include "td-req.h"


/**
* Returns the event ID associated with the event channel. Since the event
* channel can be shared by multiple block interfaces, the event ID will be
* shared as well.
*/
static inline event_id_t
tapdisk_xenblkif_evtchn_event_id(const struct td_xenblkif *blkif)
{
return blkif->ctx->ring_event;
}


/**
* Returns the event ID associated with checking the ring. This is a private
* event.
*/
static inline event_id_t
tapdisk_xenblkif_chkrng_event_id(const struct td_xenblkif * const blkif)
{
return blkif->chkrng_event;
}


/**
* Returns the event ID associated with stopping polling. This is a private
* event.
*/
static inline event_id_t
tapdisk_xenblkif_stoppolling_event_id(const struct td_xenblkif * const blkif)
{
return blkif->stoppolling_event;
}


struct td_xenblkif *
tapdisk_xenblkif_find(const domid_t domid, const int devid)
{
Expand Down Expand Up @@ -627,27 +662,6 @@ tapdisk_xenblkif_connect(domid_t domid, int devid, const grant_ref_t * grefs,
}


event_id_t
tapdisk_xenblkif_evtchn_event_id(const struct td_xenblkif *blkif)
{
return blkif->ctx->ring_event;
}


event_id_t
tapdisk_xenblkif_chkrng_event_id(const struct td_xenblkif *blkif)
{
return blkif->chkrng_event;
}


event_id_t
tapdisk_xenblkif_stoppolling_event_id(const struct td_xenblkif *blkif)
{
return blkif->stoppolling_event;
}


int
tapdisk_xenblkif_ring_stats_update(struct td_xenblkif *blkif)
{
Expand Down
22 changes: 0 additions & 22 deletions drivers/td-blkif.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,6 @@ tapdisk_xenblkif_destroy(struct td_xenblkif * blkif);
struct td_xenblkif *
tapdisk_xenblkif_find(const domid_t domid, const int devid);

/**
* Returns the event ID associated with the event channel. Since the event
* channel can be shared by multiple block interfaces, the event ID will be
* shared as well.
*/
extern event_id_t
tapdisk_xenblkif_evtchn_event_id(const struct td_xenblkif *blkif);

/**
* Returns the event ID associated wit checking the ring. This is a private
* event.
*/
extern event_id_t
tapdisk_xenblkif_chkrng_event_id(const struct td_xenblkif * const blkif);

/**
* Returns the event ID associated with stopping polling. This is a private
* event.
*/
extern event_id_t
tapdisk_xenblkif_stoppolling_event_id(const struct td_xenblkif * const blkif);

/**
* Updates ring stats.
*/
Expand Down
6 changes: 3 additions & 3 deletions lvm/lvm-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ lvm_copy_name(char *dst, const char *src, size_t size)
if (strnlen(src, size) == size)
return -ENAMETOOLONG;

safe_strncpy(dst, src, size);
strncpy(dst, src, size);
return 0;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ lvm_parse_pv(struct vg *vg, const char *name, int pvs, uint64_t start)
if (i == pvs)
return -ENOMEM;

err = lvm_copy_name(pv->name, name, sizeof(pv->name) - 1);
err = lvm_copy_name(pv->name, name, sizeof(pv->name));
if (err)
return err;

Expand Down Expand Up @@ -286,7 +286,7 @@ lvm_scan_lvs(struct vg *vg)
lv->segments = segs;
lv->first_segment = seg;

err = lvm_copy_name(lv->name, name, sizeof(lv->name) - 1);
err = lvm_copy_name(lv->name, name, sizeof(lv->name));
if (err)
goto out;
err = -EINVAL;
Expand Down
5 changes: 4 additions & 1 deletion vhd/lib/libvhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,10 @@ vhd_initialize_footer(vhd_context_t *ctx, int type, uint64_t size)
ctx->footer.type = type;
ctx->footer.saved = 0;
ctx->footer.data_offset = 0xFFFFFFFFFFFFFFFFULL;
safe_strncpy(ctx->footer.crtr_app, "tap", sizeof(ctx->footer.crtr_app));
ctx->footer.crtr_app[0] = 't';
ctx->footer.crtr_app[1] = 'a';
ctx->footer.crtr_app[2] = 'p';
ctx->footer.crtr_app[3] = '\0';
uuid_generate(ctx->footer.uuid);
}

Expand Down