Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xcopy: loop over devices using idr helper

This converts the xcopy code to use the idr helper. The next patch
will drop the g_device_list and make g_device_mutex local to the
target_core_device.c file.

Signed-off-by: Mike Christie <mchristi@redhat.com>
Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Mike Christie and committed by
Nicholas Bellinger
6906d008 b1943fd4

+48 -36
+48 -36
drivers/target/target_core_xcopy.c
··· 55 55 return 0; 56 56 } 57 57 58 - static int target_xcopy_locate_se_dev_e4(const unsigned char *dev_wwn, 59 - struct se_device **found_dev) 58 + struct xcopy_dev_search_info { 59 + const unsigned char *dev_wwn; 60 + struct se_device *found_dev; 61 + }; 62 + 63 + static int target_xcopy_locate_se_dev_e4_iter(struct se_device *se_dev, 64 + void *data) 60 65 { 61 - struct se_device *se_dev; 66 + struct xcopy_dev_search_info *info = data; 62 67 unsigned char tmp_dev_wwn[XCOPY_NAA_IEEE_REGEX_LEN]; 63 68 int rc; 64 69 65 - mutex_lock(&g_device_mutex); 66 - list_for_each_entry(se_dev, &g_device_list, g_dev_node) { 67 - 68 - if (!se_dev->dev_attrib.emulate_3pc) 69 - continue; 70 - 71 - memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); 72 - target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]); 73 - 74 - rc = memcmp(&tmp_dev_wwn[0], dev_wwn, XCOPY_NAA_IEEE_REGEX_LEN); 75 - if (rc != 0) 76 - continue; 77 - 78 - *found_dev = se_dev; 79 - pr_debug("XCOPY 0xe4: located se_dev: %p\n", se_dev); 80 - 81 - rc = target_depend_item(&se_dev->dev_group.cg_item); 82 - if (rc != 0) { 83 - pr_err("configfs_depend_item attempt failed:" 84 - " %d for se_dev: %p\n", rc, se_dev); 85 - mutex_unlock(&g_device_mutex); 86 - return rc; 87 - } 88 - 89 - pr_debug("Called configfs_depend_item for se_dev: %p" 90 - " se_dev->se_dev_group: %p\n", se_dev, 91 - &se_dev->dev_group); 92 - 93 - mutex_unlock(&g_device_mutex); 70 + if (!se_dev->dev_attrib.emulate_3pc) 94 71 return 0; 95 - } 96 - mutex_unlock(&g_device_mutex); 97 72 98 - pr_debug_ratelimited("Unable to locate 0xe4 descriptor for EXTENDED_COPY\n"); 99 - return -EINVAL; 73 + memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); 74 + target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]); 75 + 76 + rc = memcmp(&tmp_dev_wwn[0], info->dev_wwn, XCOPY_NAA_IEEE_REGEX_LEN); 77 + if (rc != 0) 78 + return 0; 79 + 80 + info->found_dev = se_dev; 81 + pr_debug("XCOPY 0xe4: located se_dev: %p\n", se_dev); 82 + 83 + rc = target_depend_item(&se_dev->dev_group.cg_item); 84 + if (rc != 0) { 85 + pr_err("configfs_depend_item attempt failed: %d for se_dev: %p\n", 86 + rc, se_dev); 87 + return rc; 88 + } 89 + 90 + pr_debug("Called configfs_depend_item for se_dev: %p se_dev->se_dev_group: %p\n", 91 + se_dev, &se_dev->dev_group); 92 + return 1; 93 + } 94 + 95 + static int target_xcopy_locate_se_dev_e4(const unsigned char *dev_wwn, 96 + struct se_device **found_dev) 97 + { 98 + struct xcopy_dev_search_info info; 99 + int ret; 100 + 101 + memset(&info, 0, sizeof(info)); 102 + info.dev_wwn = dev_wwn; 103 + 104 + ret = target_for_each_device(target_xcopy_locate_se_dev_e4_iter, &info); 105 + if (ret == 1) { 106 + *found_dev = info.found_dev; 107 + return 0; 108 + } else { 109 + pr_debug_ratelimited("Unable to locate 0xe4 descriptor for EXTENDED_COPY\n"); 110 + return -EINVAL; 111 + } 100 112 } 101 113 102 114 static int target_xcopy_parse_tiddesc_e4(struct se_cmd *se_cmd, struct xcopy_op *xop,