diff --git a/cbt/Makefile.am b/cbt/Makefile.am index b663be89..9250bdcc 100644 --- a/cbt/Makefile.am +++ b/cbt/Makefile.am @@ -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 diff --git a/drivers/block-crypto.c b/drivers/block-crypto.c index 93d0d7d5..73889261 100644 --- a/drivers/block-crypto.c +++ b/drivers/block-crypto.c @@ -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" @@ -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; @@ -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; } diff --git a/drivers/block-vhd.c b/drivers/block-vhd.c index f71cd679..0095726a 100644 --- a/drivers/block-vhd.c +++ b/drivers/block-vhd.c @@ -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) { @@ -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; diff --git a/drivers/tapdisk-blktap.c b/drivers/tapdisk-blktap.c index d706724c..790a8975 100644 --- a/drivers/tapdisk-blktap.c +++ b/drivers/tapdisk-blktap.c @@ -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) diff --git a/drivers/tapdisk-vbd.c b/drivers/tapdisk-vbd.c index 81645fc4..0f4eccf9 100644 --- a/drivers/tapdisk-vbd.c +++ b/drivers/tapdisk-vbd.c @@ -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); -} diff --git a/drivers/tapdisk-vbd.h b/drivers/tapdisk-vbd.h index aae9404e..b27818f6 100644 --- a/drivers/tapdisk-vbd.h +++ b/drivers/tapdisk-vbd.h @@ -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 diff --git a/drivers/td-blkif.c b/drivers/td-blkif.c index 631f96d8..50b4206e 100644 --- a/drivers/td-blkif.c +++ b/drivers/td-blkif.c @@ -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) { @@ -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) { diff --git a/drivers/td-blkif.h b/drivers/td-blkif.h index b50fa8a5..7aa77ec2 100644 --- a/drivers/td-blkif.h +++ b/drivers/td-blkif.h @@ -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. */ diff --git a/lvm/lvm-util.c b/lvm/lvm-util.c index ab22c38c..d3ac0ba2 100644 --- a/lvm/lvm-util.c +++ b/lvm/lvm-util.c @@ -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; } @@ -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; @@ -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; diff --git a/vhd/lib/libvhd.c b/vhd/lib/libvhd.c index 9dd7cd78..d63c4f53 100644 --- a/vhd/lib/libvhd.c +++ b/vhd/lib/libvhd.c @@ -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); }