__mapfile_lock.release()
+def resfile_lock():
+ __resfile_lock.acquire()
+
+def resfile_unlock():
+ __resfile_lock.release()
+
+
def refresh_security_policy():
"""
retrieves security policy
return False
try:
- __resfile_lock.acquire()
+ resfile_lock()
try:
access_control = dictio.dict_read("resources",
res_label_filename)
return __resources_compatible_with_vmlabel(xspol, dominfo, vmlabel,
access_control)
finally:
- __resfile_lock.release()
+ resfile_unlock()
return False
return -xsconstants.XSERR_RESOURCE_IN_USE
try:
- __resfile_lock.acquire()
+ resfile_lock()
access_control = {}
try:
access_control = dictio.dict_read("resources", res_label_filename)
del access_control[resource]
dictio.dict_write(access_control, "resources", res_label_filename)
finally:
- __resfile_lock.release()
+ resfile_unlock()
return xsconstants.XSERR_SUCCESS
def rm_resource_label(resource, oldlabel_xapi):
@return list of labeled resources
"""
try:
- __resfile_lock.acquire()
+ resfile_lock()
try:
access_control = dictio.dict_read("resources", res_label_filename)
except:
return {}
finally:
- __resfile_lock.release()
+ resfile_unlock()
return access_control
- Attempt changes in the hypervisor; if this step fails,
roll back the relabeling of resources and VMs
- Make the relabeling of resources and VMs permanent
+
+ This function should be called with the lock to the domains
+ held (XendDomain.instance().domains_lock)
"""
rc = xsconstants.XSERR_SUCCESS
errors=""
try:
- __resfile_lock.acquire()
+ resfile_lock()
mapfile_lock()
# Get all domains' dominfo.
access_control = dictio.dict_read("resources", res_label_filename)
except:
pass
+
for key, labeldata in access_control.items():
if len(labeldata) == 2:
policy, label = labeldata
finally:
log.info("----------------------------------------------")
mapfile_unlock()
- __resfile_lock.release()
+ resfile_unlock()
return rc, errors
If flags is True, then any existing policy will be removed from
the system and the new one will be installed
"""
+ from xen.xend import XendDomain
+ domains = XendDomain.instance()
+ try:
+ domains.domains_lock.acquire()
+ return self.__add_acmpolicy_to_system(xmltext, flags, overwrite)
+ finally:
+ domains.domains_lock.release()
+
+ def __add_acmpolicy_to_system(self, xmltext, flags, overwrite):
errors = ""
loadedpol = self.get_loaded_policy()
if loadedpol:
return xsconstants.XSERR_SUCCESS
def activate_xspolicy(self, xspol, flags):
+ from xen.xend import XendDomain
+ domains = XendDomain.instance()
+ try:
+ domains.domains_lock.acquire()
+ return self.__activate_xspolicy(xspol, flags)
+ finally:
+ domains.domains_lock.release()
+
+ def __activate_xspolicy(self, xspol, flags):
rc = xsconstants.XSERR_SUCCESS
if flags & xsconstants.XS_INST_LOAD:
rc = xspol.loadintohv()