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

target: add helper to iterate over devices

This adds a wrapper around idr_for_each so the xcopy code can loop over
the devices in the next patch.

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
b1943fd4 b3af66e2

+47
+45
drivers/target/target_core_device.c
··· 904 904 } 905 905 EXPORT_SYMBOL(target_find_device); 906 906 907 + struct devices_idr_iter { 908 + int (*fn)(struct se_device *dev, void *data); 909 + void *data; 910 + }; 911 + 912 + static int target_devices_idr_iter(int id, void *p, void *data) 913 + { 914 + struct devices_idr_iter *iter = data; 915 + struct se_device *dev = p; 916 + 917 + /* 918 + * We add the device early to the idr, so it can be used 919 + * by backend modules during configuration. We do not want 920 + * to allow other callers to access partially setup devices, 921 + * so we skip them here. 922 + */ 923 + if (!(dev->dev_flags & DF_CONFIGURED)) 924 + return 0; 925 + 926 + return iter->fn(dev, iter->data); 927 + } 928 + 929 + /** 930 + * target_for_each_device - iterate over configured devices 931 + * @fn: iterator function 932 + * @data: pointer to data that will be passed to fn 933 + * 934 + * fn must return 0 to continue looping over devices. non-zero will break 935 + * from the loop and return that value to the caller. 936 + */ 937 + int target_for_each_device(int (*fn)(struct se_device *dev, void *data), 938 + void *data) 939 + { 940 + struct devices_idr_iter iter; 941 + int ret; 942 + 943 + iter.fn = fn; 944 + iter.data = data; 945 + 946 + mutex_lock(&g_device_mutex); 947 + ret = idr_for_each(&devices_idr, target_devices_idr_iter, &iter); 948 + mutex_unlock(&g_device_mutex); 949 + return ret; 950 + } 951 + 907 952 int target_configure_device(struct se_device *dev) 908 953 { 909 954 struct se_hba *hba = dev->se_hba;
+2
drivers/target/target_core_internal.h
··· 87 87 struct se_device *target_alloc_device(struct se_hba *hba, const char *name); 88 88 int target_configure_device(struct se_device *dev); 89 89 void target_free_device(struct se_device *); 90 + int target_for_each_device(int (*fn)(struct se_device *dev, void *data), 91 + void *data); 90 92 91 93 /* target_core_configfs.c */ 92 94 void target_setup_backend_cits(struct target_backend *);