--------------开源storage代码------------
function pd_identify_service:on_add_drive_call_back(drive)
if drive.presence == 1 then
log:notice('Disk%s add', drive.Id)
self:add_drive(drive)
end
drive.on_presence_changed:on(function(is_presence)
if is_presence then
log:notice('Disk%s add', drive.Id)
self:add_drive(drive)
else
-- 拔盘需要做的处理
log:notice('Disk%s del', drive.Id)
drive.Missing = 0
drive.SerialNumber = common_def.INVALID_STRING
drive.FormFactor = 0
drive.CommandTimeoutTimes = 0
drive.UnexpectedSenseTimes = 0
drive.FirmwareStatus = common_def.INVALID_U8
drive.PredictedMediaLifeLeftPercent = common_def.INVALID_U8
drive.FirmwareStatusError = false
self:set_subhealth_default_values(drive)
self:del_drive(drive)
end
end)
end
-- 删除 drive
-- 1、从未配对 drive_list 中删除
-- 2、搜索已配对列表,并将controller中的pd删除
function pd_identify_service:del_drive(drive)
local idx = self:find_drive_list(drive)
if idx then
table.remove(self.drive_list, idx)
end
local identified_idx = self:find_identified_by_drive(drive)
log:debug('drive:%s del idx:%s, identified_idx:%s', drive.Name, idx, identified_idx)
if identified_idx then
local identified = self.identified_list[identified_idx]
local controller = c_controller_collection.get_instance():get_by_controller_id(identified.drive.RefControllerId)
-- 解除定位
identified.drive:identified(nil)
-- 将controller中的pd删除
local pd_idx = self:find_pd_list(identified.pd)
if pd_idx then
table.remove(self.pd_list, pd_idx)
end
controller.pd_list[identified.pd.key] = nil
-- 从映射表中移除
table.remove(self.identified_list, identified_idx)
end
end
问题描述:
在del_drive中删除硬盘是使用的drive_list的数组下标,那么当我同时存在多快硬盘的在位变化信号发过来时候,前面硬盘的del_drive还没处理完成,新信号导致后面的硬盘先执行完成del_drive, 此时pd_list和identified_list已经发生变化,再执行最初硬盘的del_drive,那么就会出现删除到错误位置的硬盘。
执行插入硬盘时,去数据库找硬盘的持久化数据时,发现该位置有持久化数据,就不去更新硬盘信息
我的方案:然后我当前的修改是将添加和删除硬盘信息函数加入到队列中处理,就没复现这个问题