Advertisement
Guest User

tio reform

a guest
Mar 27th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.56 KB | None | 0 0
  1. Index: trunk/kernel/block-io.c
  2. ===================================================================
  3. --- trunk/kernel/block-io.c (revision 470)
  4. +++ trunk/kernel/block-io.c (working copy)
  5. @@ -58,14 +58,13 @@
  6. struct bio *tio_bio = NULL, *bio = NULL, *biotail = NULL;
  7. struct blk_plug plug;
  8.  
  9. - u32 offset = tio->offset;
  10. u32 size = tio->size;
  11. u32 tio_index = 0;
  12.  
  13. int max_pages = 1;
  14. int err = 0;
  15.  
  16. - loff_t ppos = ((loff_t) tio->idx << PAGE_SHIFT) + offset;
  17. + loff_t ppos = tio->offset;
  18.  
  19. /* Calculate max_pages for bio_alloc (memory saver) */
  20. if (bdev_q)
  21. @@ -102,19 +101,17 @@
  22.  
  23. /* Loop for filling bio */
  24. while (tio_index < tio->pg_cnt) {
  25. - unsigned int bytes = PAGE_SIZE - offset;
  26. + unsigned int bytes = PAGE_SIZE;
  27.  
  28. if (bytes > size)
  29. bytes = size;
  30.  
  31. - if (!bio_add_page(bio, tio->pvec[tio_index], bytes, offset))
  32. + if (!bio_add_page(bio, tio->pvec[tio_index], bytes, 0))
  33. break;
  34.  
  35. size -= bytes;
  36. ppos += bytes;
  37.  
  38. - offset = 0;
  39. -
  40. tio_index++;
  41. }
  42. }
  43. Index: trunk/kernel/target_disk.c
  44. ===================================================================
  45. --- trunk/kernel/target_disk.c (revision 470)
  46. +++ trunk/kernel/target_disk.c (working copy)
  47. @@ -291,7 +291,7 @@
  48. size = min(size & ~(8 - 1), len + 8);
  49.  
  50. assert(!tio);
  51. - tio = cmnd->tio = tio_alloc(get_pgcnt(size, 0));
  52. + tio = cmnd->tio = tio_alloc(get_pgcnt(size));
  53. tio_set(tio, size, 0);
  54.  
  55. data = page_address(tio->pvec[idx]);
  56. Index: trunk/kernel/iscsi.c
  57. ===================================================================
  58. --- trunk/kernel/iscsi.c (revision 470)
  59. +++ trunk/kernel/iscsi.c (working copy)
  60. @@ -331,8 +331,7 @@
  61. rsp->pdu.datasize = sizeof(struct iscsi_sense_data) +
  62. IET_SENSE_BUF_SIZE;
  63.  
  64. - rsp->tio->size = (rsp->pdu.datasize + 3) & -4;
  65. - rsp->tio->offset = 0;
  66. + tio_set(rsp->tio, (rsp->pdu.datasize + 3) & -4, 0);
  67. }
  68.  
  69. return rsp;
  70. @@ -706,18 +705,15 @@
  71. char *addr;
  72.  
  73. dprintk(D_GENERIC, "%p %u,%u\n", tio, offset, size);
  74. - offset += tio->offset;
  75.  
  76. if (!size)
  77. return 0;
  78.  
  79. - if (!(offset < tio->offset + tio->size) ||
  80. - !(offset + size <= tio->offset + tio->size)) {
  81. - eprintk("%u %u %u %u", offset, size, tio->offset, tio->size);
  82. + if (!(offset + size <= tio->pg_cnt * PAGE_CACHE_SIZE)) {
  83. + eprintk("bad offset: o:%u s:%u total:%lu",
  84. + offset, size, tio->pg_cnt * PAGE_CACHE_SIZE);
  85. return -EIO;
  86. }
  87. - assert(offset < tio->offset + tio->size);
  88. - assert(offset + size <= tio->offset + tio->size);
  89.  
  90. idx = offset >> PAGE_CACHE_SHIFT;
  91. offset &= ~PAGE_CACHE_MASK;
  92. @@ -924,7 +920,7 @@
  93. conn->read_msg.msg_iov = conn->read_iov;
  94. if (cmnd->pdu.bhs.itt != cpu_to_be32(ISCSI_RESERVED_TAG)) {
  95. struct tio *tio;
  96. - int pg_cnt = get_pgcnt(size, 0);
  97. + int pg_cnt = get_pgcnt(size);
  98.  
  99. assert(pg_cnt < ISCSI_CONN_IOV_MAX);
  100. cmnd->tio = tio = tio_alloc(pg_cnt);
  101. @@ -1030,7 +1026,7 @@
  102. }
  103.  
  104. set_offset_and_length(req->lun, req_hdr->scb, &offset, &length);
  105. - req->tio = tio_alloc(get_pgcnt(length, offset));
  106. + req->tio = tio_alloc(get_pgcnt(length));
  107. tio_set(req->tio, length, offset);
  108. break;
  109. }
  110. @@ -1070,7 +1066,7 @@
  111. if (cmnd_write_size(req) != length)
  112. eprintk("%x %u %u\n", cmnd_itt(req), cmnd_write_size(req), length);
  113.  
  114. - req->tio = tio_alloc(get_pgcnt(length, offset));
  115. + req->tio = tio_alloc(get_pgcnt(length));
  116. tio_set(req->tio, length, offset);
  117.  
  118. if (req->pdu.datasize) {
  119. @@ -1451,7 +1447,7 @@
  120. rsp->tio = req->tio;
  121. }
  122.  
  123. - assert(get_pgcnt(req->pdu.datasize, 0) < ISCSI_CONN_IOV_MAX);
  124. + assert(get_pgcnt(req->pdu.datasize) < ISCSI_CONN_IOV_MAX);
  125. rsp->pdu.datasize = req->pdu.datasize;
  126. iscsi_cmnd_init_write(rsp);
  127. } else {
  128. @@ -1609,10 +1605,8 @@
  129. static void __cmnd_send_pdu(struct iscsi_conn *conn, struct tio *tio, u32 offset, u32 size)
  130. {
  131. dprintk(D_GENERIC, "%p %u,%u\n", tio, offset, size);
  132. - offset += tio->offset;
  133.  
  134. - assert(offset <= tio->offset + tio->size);
  135. - assert(offset + size <= tio->offset + tio->size);
  136. + assert(offset + size <= tio->pg_cnt * PAGE_CACHE_SIZE);
  137.  
  138. conn->write_tcmnd = tio;
  139. conn->write_offset = offset;
  140. Index: trunk/kernel/digest.c
  141. ===================================================================
  142. --- trunk/kernel/digest.c (revision 470)
  143. +++ trunk/kernel/digest.c (working copy)
  144. @@ -200,29 +200,22 @@
  145. {
  146. struct scatterlist *sg = cmnd->conn->hash_sg;
  147. u32 size, length;
  148. - int i, idx, count;
  149. + int i, idx;
  150. unsigned int nbytes;
  151.  
  152. size = cmnd->pdu.datasize;
  153. nbytes = size = (size + 3) & ~3;
  154.  
  155. - offset += tio->offset;
  156. idx = offset >> PAGE_CACHE_SHIFT;
  157. offset &= ~PAGE_CACHE_MASK;
  158. - count = get_pgcnt(size, offset);
  159. - assert(idx + count <= tio->pg_cnt);
  160.  
  161. - assert(count <= ISCSI_CONN_IOV_MAX);
  162. + assert(idx <= ISCSI_CONN_IOV_MAX);
  163.  
  164. sg_init_table(sg, ARRAY_SIZE(cmnd->conn->hash_sg));
  165. crypto_hash_init(hash);
  166.  
  167. - for (i = 0; size; i++) {
  168. - if (offset + size > PAGE_CACHE_SIZE)
  169. - length = PAGE_CACHE_SIZE - offset;
  170. - else
  171. - length = size;
  172. -
  173. + for (i = 0; size > 0; i++) {
  174. + length = min_t(u32, PAGE_CACHE_SIZE - offset, size);
  175. sg_set_page(&sg[i], tio->pvec[idx + i], length, offset);
  176. size -= length;
  177. offset = 0;
  178. Index: trunk/kernel/iscsi.h
  179. ===================================================================
  180. --- trunk/kernel/iscsi.h (revision 470)
  181. +++ trunk/kernel/iscsi.h (working copy)
  182. @@ -56,16 +56,15 @@
  183. int nop_timeout;
  184. };
  185.  
  186. +/* target io */
  187. struct tio {
  188. - u32 pg_cnt;
  189. + u32 pg_cnt; /* total page count */
  190.  
  191. - pgoff_t idx;
  192. - u32 offset;
  193. - u32 size;
  194. + loff_t offset; /* byte offset on target */
  195. + u32 size; /* total io bytes */
  196. + struct page **pvec; /* array of pages holding data */
  197.  
  198. - struct page **pvec;
  199. -
  200. - atomic_t count;
  201. + atomic_t count; /* ref count */
  202. };
  203.  
  204. struct tio_iterator {
  205. @@ -455,7 +454,7 @@
  206. void ua_establish_for_all_sessions(struct iscsi_target *, u32 lun, u8 asc,
  207. u8 ascq);
  208.  
  209. -#define get_pgcnt(size, offset) ((((size) + ((offset) & ~PAGE_CACHE_MASK)) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)
  210. +#define get_pgcnt(size) (((size) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)
  211.  
  212. static inline void iscsi_cmnd_get_length(struct iscsi_pdu *pdu)
  213. {
  214. Index: trunk/kernel/file-io.c
  215. ===================================================================
  216. --- trunk/kernel/file-io.c (revision 470)
  217. +++ trunk/kernel/file-io.c (working copy)
  218. @@ -24,31 +24,22 @@
  219. struct file *filp;
  220. mm_segment_t oldfs;
  221. struct page *page;
  222. - u32 offset, size;
  223. - loff_t ppos, count;
  224. + loff_t ppos;
  225. char *buf;
  226. int i, err = 0;
  227. - ssize_t ret;
  228. + u32 count, size, ret;
  229.  
  230. assert(p);
  231. filp = p->filp;
  232. size = tio->size;
  233. - offset= tio->offset;
  234. + ppos = tio->offset;
  235.  
  236. - ppos = (loff_t) tio->idx << PAGE_CACHE_SHIFT;
  237. - ppos += offset;
  238. -
  239. for (i = 0; i < tio->pg_cnt; i++) {
  240. page = tio->pvec[i];
  241. assert(page);
  242. buf = page_address(page);
  243. - buf += offset;
  244. + count = min_t(u32, PAGE_CACHE_SIZE, size);
  245.  
  246. - if (offset + size > PAGE_CACHE_SIZE)
  247. - count = PAGE_CACHE_SIZE - offset;
  248. - else
  249. - count = size;
  250. -
  251. oldfs = get_fs();
  252. set_fs(get_ds());
  253.  
  254. @@ -60,12 +51,12 @@
  255. set_fs(oldfs);
  256.  
  257. if (ret != count) {
  258. - eprintk("I/O error %lld, %ld\n", count, (long) ret);
  259. + eprintk("I/O error %u, %ld\n", count, (long) ret);
  260. err = -EIO;
  261. + break;
  262. }
  263.  
  264. size -= count;
  265. - offset = 0;
  266. }
  267. assert(!size);
  268.  
  269. @@ -81,8 +72,7 @@
  270. int res;
  271.  
  272. if (tio) {
  273. - ppos = (loff_t) tio->idx << PAGE_CACHE_SHIFT;
  274. - ppos += tio->offset;
  275. + ppos = tio->offset;
  276. count = tio->size;
  277. } else {
  278. ppos = 0;
  279. Index: trunk/kernel/persist.c
  280. ===================================================================
  281. --- trunk/kernel/persist.c (revision 470)
  282. +++ trunk/kernel/persist.c (working copy)
  283. @@ -261,7 +261,7 @@
  284. case SERVICE_ACTION_READ_FULL_STATUS:
  285. if (allocation_length == 0)
  286. return;
  287. - cmnd->tio = tio_alloc(get_pgcnt(allocation_length, 0));
  288. + cmnd->tio = tio_alloc(get_pgcnt(allocation_length));
  289. break;
  290. default:
  291. eprintk("%#Lx:%hu: invalid PR In Service Action %x\n",
  292. Index: trunk/kernel/tio.c
  293. ===================================================================
  294. --- trunk/kernel/tio.c (revision 470)
  295. +++ trunk/kernel/tio.c (working copy)
  296. @@ -44,7 +44,6 @@
  297. tio = kmem_cache_alloc(tio_cache, GFP_KERNEL | __GFP_NOFAIL);
  298.  
  299. tio->pg_cnt = 0;
  300. - tio->idx = 0;
  301. tio->offset = 0;
  302. tio->size = 0;
  303. tio->pvec = NULL;
  304. @@ -119,8 +118,7 @@
  305.  
  306. void tio_set(struct tio *tio, u32 size, loff_t offset)
  307. {
  308. - tio->idx = offset >> PAGE_CACHE_SHIFT;
  309. - tio->offset = offset & ~PAGE_CACHE_MASK;
  310. + tio->offset = offset;
  311. tio->size = size;
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement