Hi Mark,
After Bark posted an BUG() when CONFIG_DEBUG_SG was used with
LIO-Target, I add the proper usage of sg_table_init() and sg_mark_end()
in the LIO-Target SE. Please update your case (if you are not doing it
already). Here are my new changes for those who are still updating
drivers to use the new include/linux/scatterlist.h API.
--nab
Index: include/iscsi_linux_defs.h
===================================================================
--- include/iscsi_linux_defs.h (revision 214)
+++ include/iscsi_linux_defs.h (revision 215)
@@ -49,11 +49,14 @@
* code, and use inline functions for legacy operation.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+# define SET_SG_TABLE(sg, cnt) sg_init_table((struct scatterlist *)&sg[0], cnt); \
+ sg_mark_end((struct scatterlist *)&sg[cnt - 1]);
# define GET_ADDR_SG(sg) sg_virt(sg)
# define GET_PAGE_SG(sg) sg_page(sg)
# define SET_PAGE_SG(sg, page) sg_assign_page(sg, page)
#else
#include <linux/scatterlist.h>
+#define SET_SG_TABLE(sg, cnt)
static inline void *GET_ADDR_SG(struct scatterlist *sg)
{
return(page_address(sg->page) + sg->offset);
As you can see, the pre 2.6.24 case expands to a nop.
In my case with LIO-Target and generating SC arrays going to the default
path (which is common for PSCSI, IBLOCK, FILE, and RAMDISK_MCP) where
se_mem_t list head struct page is mapped to struct page-link in the
contigious struct scatterlist arrays.
In the iscsi_target_transport.c:transport_calc_sg_num() and scatterlist
allocation for RAMDISK_DR and RAMDISK_MCP, I added the usage of
SET_SG_TABLE right after the array of struct scatterlist right after the
struct scatterlist array has been allocated and memset.
Index: target/iscsi_target_rd.c
===================================================================
--- target/iscsi_target_rd.c (revision 215)
+++ target/iscsi_target_rd.c (revision 217)
@@ -209,6 +209,8 @@
}
memset(sg, 0, sg_per_table * sizeof(struct scatterlist));
+ SET_SG_TABLE(sg, sg_per_table);
+
sg_table[i].sg_table = sg;
sg_table[i].rd_sg_count = sg_per_table;
sg_table[i].page_start_offset = page_offset;
Index: target/iscsi_target_transport.c
===================================================================
--- target/iscsi_target_transport.c (revision 215)
+++ target/iscsi_target_transport.c (revision 217)
@@ -5096,6 +5096,8 @@
}
memset(task->task_buf, 0, task->task_sg_num * sizeof(struct scatterlist));
+ SET_SG_TABLE(task->task_buf, task->task_sg_num);
+
DEBUG_SC("Successfully allocated task->task_sg_num: %u\n", task->task_sg_num);
return(task->task_sg_num);
On Sun, 2008-02-10 at 14:26 -0500, Mark Tuttle wrote: