patch-2.2.17 linux/drivers/scsi/sg.c

Next file: linux/drivers/scsi/sr_ioctl.c
Previous file: linux/drivers/scsi/scsi_ioctl.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.16/drivers/scsi/sg.c linux/drivers/scsi/sg.c
@@ -16,8 +16,8 @@
  *
  *  Borrows code from st driver. Thanks to Alessandro Rubini's "dd" book.
  */
- static char * sg_version_str = "Version: 2.1.38 (20000527)";
- static int sg_version_num = 20138; /* 2 digits for each component */
+ static char * sg_version_str = "Version: 2.1.39 (20000626)";
+ static int sg_version_num = 20139; /* 2 digits for each component */
 /*
  *  D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes:
  *      - scsi logging is available via SCSI_LOG_TIMEOUT macros. First
@@ -1376,9 +1376,9 @@
     Sg_scatter_hold * req_schp = &srp->data;
     Sg_scatter_hold * rsv_schp = &sfp->reserve;
 
+    srp->res_used = 1;
     SCSI_LOG_TIMEOUT(4, printk("sg_link_reserve: size=%d\n", size)); 
-    /* round request up to next highest SG_SECTOR_SZ byte boundary */
-    size = (size + SG_SECTOR_MSK) & (~SG_SECTOR_MSK);
+    size = (size + 1) & (~1);   /* round to even for aha1542 */
     if (rsv_schp->use_sg > 0) {
         int k, num;
         int rem = size;
@@ -1387,22 +1387,26 @@
         for (k = 0; k < rsv_schp->use_sg; ++k, ++sclp) {
             num = (int)sclp->length;
             if (rem <= num) {
-                sfp->save_scat_len = num;
-                sclp->length = (unsigned)rem;
+                if (0 == k) {
+                    req_schp->use_sg = 0;
+                    req_schp->buffer = sclp->address;
+                }
+                else {
+                    sfp->save_scat_len = num;
+                    sclp->length = (unsigned)rem;
+                    req_schp->use_sg = k + 1;
+                    req_schp->sglist_len = rsv_schp->sglist_len;
+                    req_schp->buffer = rsv_schp->buffer;
+                }
+                req_schp->bufflen = size;
+                req_schp->mem_src = rsv_schp->mem_src;
+                req_schp->b_malloc_len = rsv_schp->b_malloc_len;
                 break;
             }
             else
                 rem -= num;
         }
-        if (k < rsv_schp->use_sg) {
-            req_schp->use_sg = k + 1;   /* adjust scatter list length */
-            req_schp->bufflen = size;
-            req_schp->sglist_len = rsv_schp->sglist_len;
-            req_schp->buffer = rsv_schp->buffer;
-            req_schp->mem_src = rsv_schp->mem_src;
-            req_schp->b_malloc_len = rsv_schp->b_malloc_len;
-        }
-        else
+        if (k >= rsv_schp->use_sg)
             SCSI_LOG_TIMEOUT(1, printk("sg_link_reserve: BAD size\n")); 
     }
     else {
@@ -1410,10 +1414,8 @@
         req_schp->bufflen = size;
         req_schp->buffer = rsv_schp->buffer;
         req_schp->mem_src = rsv_schp->mem_src;
-        req_schp->use_sg = rsv_schp->use_sg;
         req_schp->b_malloc_len = rsv_schp->b_malloc_len;
     }
-    srp->res_used = 1;
 }
 
 static void sg_unlink_reserve(Sg_fd * sfp, Sg_request * srp)
@@ -1423,7 +1425,7 @@
 
     SCSI_LOG_TIMEOUT(4, printk("sg_unlink_reserve: req->use_sg=%d\n",
                                (int)req_schp->use_sg)); 
-    if (rsv_schp->use_sg > 0) {
+    if ((rsv_schp->use_sg > 0) && (req_schp->use_sg > 0)) {
         struct scatterlist * sclp = (struct scatterlist *)rsv_schp->buffer;
 
         if (sfp->save_scat_len > 0) 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)