hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/target/target_core_device.c
....@@ -724,10 +724,23 @@
724724 {
725725 struct se_device *dev;
726726 struct se_lun *xcopy_lun;
727
+ int i;
727728
728729 dev = hba->backend->ops->alloc_device(hba, name);
729730 if (!dev)
730731 return NULL;
732
+
733
+ dev->queues = kcalloc(nr_cpu_ids, sizeof(*dev->queues), GFP_KERNEL);
734
+ if (!dev->queues) {
735
+ dev->transport->free_device(dev);
736
+ return NULL;
737
+ }
738
+
739
+ dev->queue_cnt = nr_cpu_ids;
740
+ for (i = 0; i < dev->queue_cnt; i++) {
741
+ INIT_LIST_HEAD(&dev->queues[i].state_list);
742
+ spin_lock_init(&dev->queues[i].lock);
743
+ }
731744
732745 dev->se_hba = hba;
733746 dev->transport = hba->backend->ops;
....@@ -738,9 +751,7 @@
738751 INIT_LIST_HEAD(&dev->dev_sep_list);
739752 INIT_LIST_HEAD(&dev->dev_tmr_list);
740753 INIT_LIST_HEAD(&dev->delayed_cmd_list);
741
- INIT_LIST_HEAD(&dev->state_list);
742754 INIT_LIST_HEAD(&dev->qf_cmd_list);
743
- spin_lock_init(&dev->execute_task_lock);
744755 spin_lock_init(&dev->delayed_cmd_lock);
745756 spin_lock_init(&dev->dev_reservation_lock);
746757 spin_lock_init(&dev->se_port_lock);
....@@ -759,6 +770,7 @@
759770 spin_lock_init(&dev->t10_alua.lba_map_lock);
760771
761772 INIT_WORK(&dev->delayed_cmd_work, target_do_delayed_work);
773
+ mutex_init(&dev->lun_reset_mutex);
762774
763775 dev->t10_wwn.t10_dev = dev;
764776 dev->t10_alua.t10_dev = dev;
....@@ -855,7 +867,6 @@
855867 EXPORT_SYMBOL(target_to_linux_sector);
856868
857869 struct devices_idr_iter {
858
- struct config_item *prev_item;
859870 int (*fn)(struct se_device *dev, void *data);
860871 void *data;
861872 };
....@@ -865,10 +876,8 @@
865876 {
866877 struct devices_idr_iter *iter = data;
867878 struct se_device *dev = p;
879
+ struct config_item *item;
868880 int ret;
869
-
870
- config_item_put(iter->prev_item);
871
- iter->prev_item = NULL;
872881
873882 /*
874883 * We add the device early to the idr, so it can be used
....@@ -879,12 +888,13 @@
879888 if (!target_dev_configured(dev))
880889 return 0;
881890
882
- iter->prev_item = config_item_get_unless_zero(&dev->dev_group.cg_item);
883
- if (!iter->prev_item)
891
+ item = config_item_get_unless_zero(&dev->dev_group.cg_item);
892
+ if (!item)
884893 return 0;
885894 mutex_unlock(&device_mutex);
886895
887896 ret = iter->fn(dev, iter->data);
897
+ config_item_put(item);
888898
889899 mutex_lock(&device_mutex);
890900 return ret;
....@@ -907,7 +917,6 @@
907917 mutex_lock(&device_mutex);
908918 ret = idr_for_each(&devices_idr, target_devices_idr_iter, &iter);
909919 mutex_unlock(&device_mutex);
910
- config_item_put(iter.prev_item);
911920 return ret;
912921 }
913922
....@@ -1014,6 +1023,7 @@
10141023 if (dev->transport->free_prot)
10151024 dev->transport->free_prot(dev);
10161025
1026
+ kfree(dev->queues);
10171027 dev->transport->free_device(dev);
10181028 }
10191029