diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/bitmap.c | 43 | ||||
-rw-r--r-- | src/basic/missing.h | 6 | ||||
-rw-r--r-- | src/basic/virt.c | 20 |
3 files changed, 44 insertions, 25 deletions
diff --git a/src/basic/bitmap.c b/src/basic/bitmap.c index 7e47c2d09f..bf9d8d4d7c 100644 --- a/src/basic/bitmap.c +++ b/src/basic/bitmap.c @@ -24,7 +24,7 @@ #include "bitmap.h" struct Bitmap { - long long unsigned *bitmaps; + uint64_t *bitmaps; size_t n_bitmaps; size_t bitmaps_allocated; }; @@ -37,9 +37,9 @@ struct Bitmap { /* This indicates that we reached the end of the bitmap */ #define BITMAP_END ((unsigned) -1) -#define BITMAP_NUM_TO_OFFSET(n) ((n) / (sizeof(long long unsigned) * 8)) -#define BITMAP_NUM_TO_REM(n) ((n) % (sizeof(long long unsigned) * 8)) -#define BITMAP_OFFSET_TO_NUM(offset, rem) ((offset) * sizeof(long long unsigned) * 8 + (rem)) +#define BITMAP_NUM_TO_OFFSET(n) ((n) / (sizeof(uint64_t) * 8)) +#define BITMAP_NUM_TO_REM(n) ((n) % (sizeof(uint64_t) * 8)) +#define BITMAP_OFFSET_TO_NUM(offset, rem) ((offset) * sizeof(uint64_t) * 8 + (rem)) Bitmap *bitmap_new(void) { return new0(Bitmap, 1); @@ -56,6 +56,8 @@ void bitmap_free(Bitmap *b) { int bitmap_ensure_allocated(Bitmap **b) { Bitmap *a; + assert(b); + if (*b) return 0; @@ -69,7 +71,7 @@ int bitmap_ensure_allocated(Bitmap **b) { } int bitmap_set(Bitmap *b, unsigned n) { - long long unsigned bitmask; + uint64_t bitmask; unsigned offset; assert(b); @@ -87,7 +89,7 @@ int bitmap_set(Bitmap *b, unsigned n) { b->n_bitmaps = offset + 1; } - bitmask = 1ULL << BITMAP_NUM_TO_REM(n); + bitmask = UINT64_C(1) << BITMAP_NUM_TO_REM(n); b->bitmaps[offset] |= bitmask; @@ -95,26 +97,27 @@ int bitmap_set(Bitmap *b, unsigned n) { } void bitmap_unset(Bitmap *b, unsigned n) { - long long unsigned bitmask; + uint64_t bitmask; unsigned offset; - assert(b); + if (!b) + return; offset = BITMAP_NUM_TO_OFFSET(n); if (offset >= b->n_bitmaps) return; - bitmask = 1ULL << BITMAP_NUM_TO_REM(n); + bitmask = UINT64_C(1) << BITMAP_NUM_TO_REM(n); b->bitmaps[offset] &= ~bitmask; } bool bitmap_isset(Bitmap *b, unsigned n) { - long long unsigned bitmask; + uint64_t bitmask; unsigned offset; - if (!b || !b->bitmaps) + if (!b) return false; offset = BITMAP_NUM_TO_OFFSET(n); @@ -122,7 +125,7 @@ bool bitmap_isset(Bitmap *b, unsigned n) { if (offset >= b->n_bitmaps) return false; - bitmask = 1ULL << BITMAP_NUM_TO_REM(n); + bitmask = UINT64_C(1) << BITMAP_NUM_TO_REM(n); return !!(b->bitmaps[offset] & bitmask); } @@ -133,7 +136,7 @@ bool bitmap_isclear(Bitmap *b) { assert(b); for (i = 0; i < b->n_bitmaps; i++) - if (b->bitmaps[i]) + if (b->bitmaps[i] != 0) return false; return true; @@ -146,15 +149,18 @@ void bitmap_clear(Bitmap *b) { } bool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n) { - long long unsigned bitmask; + uint64_t bitmask; unsigned offset, rem; + assert(i); + assert(n); + if (!b || i->idx == BITMAP_END) return false; offset = BITMAP_NUM_TO_OFFSET(i->idx); rem = BITMAP_NUM_TO_REM(i->idx); - bitmask = 1ULL << rem; + bitmask = UINT64_C(1) << rem; for (; offset < b->n_bitmaps; offset ++) { if (b->bitmaps[offset]) { @@ -178,7 +184,6 @@ bool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n) { } bool bitmap_equal(Bitmap *a, Bitmap *b) { - unsigned i; if (!a ^ !b) return false; @@ -189,9 +194,5 @@ bool bitmap_equal(Bitmap *a, Bitmap *b) { if (a->n_bitmaps != b->n_bitmaps) return false; - for (i = 0; i < a->n_bitmaps; i++) - if (a->bitmaps[i] != b->bitmaps[i]) - return false; - - return true; + return memcmp(a->bitmaps, b->bitmaps, sizeof(uint64_t) * a->n_bitmaps) == 0; } diff --git a/src/basic/missing.h b/src/basic/missing.h index bd49f10e76..ed6cd80c75 100644 --- a/src/basic/missing.h +++ b/src/basic/missing.h @@ -832,7 +832,7 @@ static inline int setns(int fd, int nstype) { #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) #endif -#if !HAVE_DECL_IFLA_BRPORT_UNICAST_FLOOD +#if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC #define IFLA_BRPORT_UNSPEC 0 #define IFLA_BRPORT_STATE 1 #define IFLA_BRPORT_PRIORITY 2 @@ -843,7 +843,9 @@ static inline int setns(int fd, int nstype) { #define IFLA_BRPORT_FAST_LEAVE 7 #define IFLA_BRPORT_LEARNING 8 #define IFLA_BRPORT_UNICAST_FLOOD 9 -#define __IFLA_BRPORT_MAX 10 +#define IFLA_BRPORT_PROXYARP 10 +#define IFLA_BRPORT_LEARNING_SYNC 11 +#define __IFLA_BRPORT_MAX 12 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1) #endif diff --git a/src/basic/virt.c b/src/basic/virt.c index 1299a75ed5..a8d26716a1 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -188,7 +188,7 @@ int detect_vm(const char **id) { _cleanup_free_ char *domcap = NULL, *cpuinfo_contents = NULL; static thread_local int cached_found = -1; static thread_local const char *cached_id = NULL; - const char *_id = NULL; + const char *_id = NULL, *_id_cpuid = NULL; int r; if (_likely_(cached_found >= 0)) { @@ -234,10 +234,26 @@ int detect_vm(const char **id) { /* this will set _id to "other" and return 0 for unknown hypervisors */ r = detect_vm_cpuid(&_id); - if (r != 0) + + /* finish when found a known hypervisor other than kvm */ + if (r < 0 || (r > 0 && !streq(_id, "kvm"))) goto finish; + _id_cpuid = _id; + r = detect_vm_dmi(&_id); + + /* kvm with and without Virtualbox */ + if (streq_ptr(_id_cpuid, "kvm")) { + if (r > 0 && streq(_id, "oracle")) + goto finish; + + _id = _id_cpuid; + r = 1; + goto finish; + } + + /* information from dmi */ if (r != 0) goto finish; |