forked from illumos/illumos-gate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Robert Mustacchi <rm@joyent.com>
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This file and its contents are supplied under the terms of the | ||
* Common Development and Distribution License ("CDDL"), version 1.0. | ||
* You may only use this file in accordance with the terms of version | ||
* 1.0 of the CDDL. | ||
* | ||
* A full copy of the text of the CDDL should have accompanied this | ||
* source. A copy of the CDDL is also available via the Internet at | ||
* http://www.illumos.org/license/CDDL. | ||
*/ | ||
|
||
/* | ||
* Copyright 2017 Joyent, Inc. | ||
*/ | ||
|
||
#include <sys/param.h> | ||
#include <sys/types.h> | ||
#include <sys/mutex.h> | ||
#include <sys/debug.h> | ||
|
||
static kmutex_t hvm_excl_lock; | ||
static const char *hvm_excl_holder = NULL; | ||
|
||
/* | ||
* HVM Exclusion Interface | ||
* | ||
* To avoid VMX/SVM conflicts from arising when multiple hypervisor providers | ||
* (eg. KVM, bhyve) are shipped with the system, this simple advisory locking | ||
* system is presented for their use. Until a proper hypervisor API, like the | ||
* one in OSX, is shipped in illumos, this will serve as opt-in regulation to | ||
* dictate that only a single hypervisor be allowed to configure the system and | ||
* run at any given time. | ||
*/ | ||
|
||
boolean_t | ||
hvm_excl_hold(const char *consumer) | ||
{ | ||
boolean_t res = B_FALSE; | ||
|
||
mutex_enter(&hvm_excl_lock); | ||
if (hvm_excl_holder == NULL) { | ||
hvm_excl_holder = consumer; | ||
res = B_TRUE; | ||
} | ||
mutex_exit(&hvm_excl_lock); | ||
|
||
return (res); | ||
} | ||
|
||
void | ||
hvm_excl_rele(const char *consumer) | ||
{ | ||
mutex_enter(&hvm_excl_lock); | ||
VERIFY(consumer == hvm_excl_holder); | ||
hvm_excl_holder = NULL; | ||
mutex_exit(&hvm_excl_lock); | ||
} |
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,35 @@ | ||
/* | ||
* This file and its contents are supplied under the terms of the | ||
* Common Development and Distribution License ("CDDL"), version 1.0. | ||
* You may only use this file in accordance with the terms of version | ||
* 1.0 of the CDDL. | ||
* | ||
* A full copy of the text of the CDDL should have accompanied this | ||
* source. A copy of the CDDL is also available via the Internet at | ||
* http://www.illumos.org/license/CDDL. | ||
*/ | ||
|
||
/* | ||
* Copyright 2017 Joyent, Inc. | ||
*/ | ||
|
||
|
||
#ifndef _PC_HVM_H | ||
#define _PC_HVM_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if defined(_KERNEL) | ||
|
||
extern boolean_t hvm_excl_hold(const char *); | ||
extern void hvm_excl_rele(const char *); | ||
|
||
#endif /* defined(_KERNEL) */ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _PC_HVM_H */ |