From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/blkfront: properly fail packet requests Date: Tue, 14 Feb 2012 11:32:12 +0000 Message-ID: <4F3A544C0200007800072DC6@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part77590F2C.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part77590F2C.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline c/s 1036:f5635e334aa5 ("blkfront: forward unknown IOCTLs to scsi_cmd_ioctl() for /dev/sdX") uncovered a problem in blkfront's request handling: blk_pc_request()-s, among other sources resulting from the handling of the SG_IO ioctl in scsi_cmd_ioctl(), must not be passed to end_request() without prior adjustment: Neither is their ->hard_cur_sectors necessarily correct (potentially resulting in an infinite loop), nor is ->errors ever getting set properly to reflect the failure (sg_io() intentionally ignores the return value from blk_execute_rq()). As blktap2's internally created devices have the same deficiency, fix this there too. Signed-off-by: Jan Beulich --- a/drivers/xen/blkfront/blkfront.c +++ b/drivers/xen/blkfront/blkfront.c @@ -709,6 +709,12 @@ void do_blkif_request(request_queue_t *r while ((req =3D elv_next_request(rq)) !=3D NULL) { info =3D req->rq_disk->private_data; if (!blk_fs_request(req)) { + if (blk_pc_request(req)) { + req->errors =3D (DID_ERROR << 16) + | (DRIVER_INVALID << 24); + req->hard_cur_sectors =3D (req->data_len + + 511) >> 9; + } end_request(req, 0); continue; } --- a/drivers/xen/blktap2/device.c +++ b/drivers/xen/blktap2/device.c @@ -3,6 +3,7 @@ #include #include #include +#include #include =20 #include @@ -825,6 +826,12 @@ blktap_device_run_queue(struct blktap *t =20 while ((req =3D elv_next_request(rq)) !=3D NULL) { if (!blk_fs_request(req)) { + if (blk_pc_request(req)) { + req->errors =3D (DID_ERROR << 16) + | (DRIVER_INVALID << 24); + req->hard_cur_sectors =3D (req->data_len + + 511) >> 9; + } end_request(req, 0); continue; } @@ -912,9 +919,16 @@ blktap_device_do_request(request_queue_t =20 fail: while ((req =3D elv_next_request(rq))) { - BTERR("device closed: failing secs %llu - %llu\n", - (unsigned long long)req->sector, - (unsigned long long)req->sector + req->nr_sectors); + if (blk_fs_request(req)) { + unsigned long long sec =3D req->sector; + + BTERR("device closed: failing secs %#Lx-%#Lx\n", + sec, sec + req->nr_sectors - 1); + } else if (blk_pc_request(req)) { + req->errors =3D (DID_ERROR << 16) + | (DRIVER_INVALID << 24); + req->hard_cur_sectors =3D (req->data_len + 511) >> = 9; + } end_request(req, 0); } } --=__Part77590F2C.0__= Content-Type: text/plain; name="xen-blkfront-sg_io.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-blkfront-sg_io.patch" blkfront: properly fail packet requests=0A=0Ac/s 1036:f5635e334aa5 = ("blkfront: forward unknown IOCTLs to=0Ascsi_cmd_ioctl() for /dev/sdX") = uncovered a problem in blkfront's=0Arequest handling: blk_pc_request()-s, = among other sources resulting=0Afrom the handling of the SG_IO ioctl in = scsi_cmd_ioctl(), must not be=0Apassed to end_request() without prior = adjustment: Neither is their=0A->hard_cur_sectors necessarily correct = (potentially resulting in an=0Ainfinite loop), nor is ->errors ever = getting set properly to reflect=0Athe failure (sg_io() intentionally = ignores the return value from=0Ablk_execute_rq()).=0A=0AAs blktap2's = internally created devices have the same deficiency, fix=0Athis there = too.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/drivers/xen/blkfront/blkfront.c=0A+++ b/drivers/xen/blkfront/blkfront.c= =0A@@ -709,6 +709,12 @@ void do_blkif_request(request_queue_t *r=0A = while ((req =3D elv_next_request(rq)) !=3D NULL) {=0A info =3D = req->rq_disk->private_data;=0A if (!blk_fs_request(req)) {=0A+ = if (blk_pc_request(req)) {=0A+ req->errors= =3D (DID_ERROR << 16)=0A+ | = (DRIVER_INVALID << 24);=0A+ req->hard_cur_secto= rs =3D (req->data_len=0A+ = + 511) >> 9;=0A+ }=0A end_request= (req, 0);=0A continue;=0A }=0A--- a/drivers/x= en/blktap2/device.c=0A+++ b/drivers/xen/blktap2/device.c=0A@@ -3,6 +3,7 = @@=0A #include =0A #include =0A #include = =0A+#include =0A #include =0A = =0A #include =0A@@ -825,6 +826,12 @@ blktap_device_run_queue(s= truct blktap *t=0A =0A while ((req =3D elv_next_request(rq)) !=3D NULL) = {=0A if (!blk_fs_request(req)) {=0A+ if = (blk_pc_request(req)) {=0A+ req->errors =3D = (DID_ERROR << 16)=0A+ | (DRIVER_INV= ALID << 24);=0A+ req->hard_cur_sectors =3D = (req->data_len=0A+ + = 511) >> 9;=0A+ }=0A end_request(req, = 0);=0A continue;=0A }=0A@@ -912,9 +919,16 @@ = blktap_device_do_request(request_queue_t=0A =0A fail:=0A while = ((req =3D elv_next_request(rq))) {=0A- BTERR("device closed: = failing secs %llu - %llu\n",=0A- (unsigned long = long)req->sector,=0A- (unsigned long long)req->sector + = req->nr_sectors);=0A+ if (blk_fs_request(req)) {=0A+ = unsigned long long sec =3D req->sector;=0A+=0A+ BTERR("devi= ce closed: failing secs %#Lx-%#Lx\n",=0A+ sec, = sec + req->nr_sectors - 1);=0A+ } else if (blk_pc_request(req)) = {=0A+ req->errors =3D (DID_ERROR << 16)=0A+ = | (DRIVER_INVALID << 24);=0A+ req->hard_c= ur_sectors =3D (req->data_len + 511) >> 9;=0A+ }=0A = end_request(req, 0);=0A }=0A }=0A --=__Part77590F2C.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part77590F2C.0__=--