首页 > 代码库 > manila nfs 删除 share 分析
manila nfs 删除 share 分析
1、mania/share/manager.py 2144行,调用delete_share_instance删除share instance
def delete_share_instance(self, context, share_instance_id, force=False): """Delete a share instance.""" context = context.elevated() share_instance = self._get_share_instance(context, share_instance_id) share_server = self._get_share_server(context, share_instance) try: self.access_helper.update_access_rules( context, share_instance_id, delete_rules="all", share_server=share_server ) except exception.ShareResourceNotFound: LOG.warning(_LW("Share instance %s does not exist in the " "backend."), share_instance_id) except Exception: with excutils.save_and_reraise_exception() as exc_context: if force: msg = _LE("The driver was unable to delete access rules " "for the instance: %s. Will attempt to delete " "the instance anyway.") LOG.error(msg, share_instance_id) exc_context.reraise = False else: self.db.share_instance_update( context, share_instance_id, {‘status‘: constants.STATUS_ERROR_DELETING}) try: self.driver.delete_share(context, share_instance, share_server=share_server) except exception.ShareResourceNotFound: LOG.warning(_LW("Share instance %s does not exist in the " "backend."), share_instance_id) except Exception: with excutils.save_and_reraise_exception() as exc_context: if force: msg = _LE("The driver was unable to delete the share " "instance: %s on the backend. Since this " "operation is forced, the instance will be " "deleted from Manila‘s database. A cleanup on " "the backend may be necessary.") LOG.error(msg, share_instance_id) exc_context.reraise = False else: self.db.share_instance_update( context, share_instance_id, {‘status‘: constants.STATUS_ERROR_DELETING}) self.db.share_instance_delete(context, share_instance_id) LOG.info(_LI("Share instance %s: deleted successfully."), share_instance_id) self._check_delete_share_server(context, share_instance)
2、在2175行,有如下方法
self.driver.delete_share(context, share_instance, share_server=share_server)
3、self.driver.delete_share调用mania/share/drivers/generic.py中的delete_share
def delete_share(self, context, share, share_server=None): """Deletes share.""" helper = self._get_helper(share) if not self.driver_handles_share_servers: share_server = self.service_instance_manager.get_common_server() if self._is_share_server_active(context, share_server): helper.remove_export( share_server[‘backend_details‘], share[‘name‘]) self._unmount_device(share, share_server[‘backend_details‘]) self._detach_volume(self.admin_context, share, share_server[‘backend_details‘]) # Note(jun): It is an intended breakage to deal with the cases # with any reason that caused absence of Nova instances. self._deallocate_container(self.admin_context, share) self.private_storage.delete(share[‘id‘])
4、generic.py中的delete_share执行如下操作:
remove_export:移除所有nfs export,remove_export位于mania/share/drivers/helpers.py156行,remove_export没有做实际操作,remove_export实际由manager.py中delete_share_instance方法2151行,self.access_helper.update_access_rules完成
卸载volume文件系统:self._umount_device
卸载cinder volume:self._detach_volume
删除cinder volume,保留nova instance,如果有新的share instance 创建,会将保留的nova instance用于提供share instance
5、manager.py中delete_share_instance方法2151行,self.access_helper.update_access_rules 调用,mania/share/access.py中的update_access_rules
def update_access_rules(self, context, share_instance_id, add_rules=None, delete_rules=None, share_server=None): """Update access rules in driver and database for given share instance. :param context: current context :param share_instance_id: Id of the share instance model :param add_rules: list with ShareAccessMapping models or None - rules which should be added :param delete_rules: list with ShareAccessMapping models, "all", None - rules which should be deleted. If "all" is provided - all rules will be deleted. :param share_server: Share server model or None """ share_instance = self.db.share_instance_get( context, share_instance_id, with_share_data=http://www.mamicode.com/True)"share_id"] @utils.synchronized( "update_access_rules_for_share_%s" % share_id, external=True) def _update_access_rules_locked(*args, **kwargs): return self._update_access_rules(*args, **kwargs) _update_access_rules_locked( context=context, share_instance_id=share_instance_id, add_rules=add_rules, delete_rules=delete_rules, share_server=share_server, )
6、update_access_rules通过self._update_access_rules方法,调用self.driver.update_access完成access的删除
7、self.driver.update_access即generic.py中的upate_access,genery.py update_access调用mania/share/drivers/helpers.py中class NFSHelper的upate_access方法完成access的删除
delete_share_instance(manager.py)------>update_access_rules(access.py) | | | | | | | ------>upate_access(generic.py) | | | | | | | ------>update_access(helpers.py,NFSHelper) | | | | ------>delete_share(generic.py)
本文出自 “武陵荒草” 博客,请务必保留此出处http://penguintux.blog.51cto.com/3021117/1882540
manila nfs 删除 share 分析