From: "Jan Beulich" Subject: [PATCH v2][linux 2.6.18] scsiback: free resources after error Date: Fri, 04 Jul 2014 10:40:45 +0100 Message-ID: <53B692BD02000078000209B8@mail.emea.novell.com> References: <1404448883-10033-1-git-send-email-jgross@suse.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part76449E8D.0__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X2zz4-0002Ma-Gc for xen-devel@lists.xenproject.org; Fri, 04 Jul 2014 09:40:46 +0000 In-Reply-To: <1404448883-10033-1-git-send-email-jgross@suse.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Juergen Gross 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. --=__Part76449E8D.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline From: Juergen Gross In case of an error during preparing an I/O the already allocated = resources should all be freed again and the frontend request should be terminated accordingly. Signed-off-by: Juergen Gross Some formatting adjustments to the changes above, and some more releasing of resources (in the VSCSIIF_ACT_SCSI_RESET and default cases of the = switch in scsiback_do_cmd_fn()). Signed-off-by: Jan Beulich --- a/drivers/xen/scsiback/common.h +++ b/drivers/xen/scsiback/common.h @@ -163,13 +163,13 @@ struct scsi_device *scsiback_do_translat void scsiback_release_translation_entry(struct vscsibk_info *info); =20 =20 -void scsiback_cmd_exec(pending_req_t *pending_req); +int scsiback_cmd_exec(pending_req_t *pending_req); void scsiback_do_resp_with_sense(char *sense_buffer, int32_t result, uint32_t resid, pending_req_t *pending_req); void scsiback_fast_flush_area(pending_req_t *req); =20 void scsiback_rsp_emulation(pending_req_t *pending_req); -void scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req); +int scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req); void scsiback_emulation_init(void); =20 =20 --- a/drivers/xen/scsiback/emulate.c +++ b/drivers/xen/scsiback/emulate.c @@ -345,16 +345,16 @@ void scsiback_rsp_emulation(pending_req_ } =20 =20 -void scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req) +int scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req) { - if (__pre_do_emulation(pending_req, NULL)) { - scsiback_cmd_exec(pending_req); - } - else { - scsiback_fast_flush_area(pending_req); - scsiback_do_resp_with_sense(pending_req->sense_buffer, - pending_req->rslt, pending_req->resid, pending_req); - } + if (__pre_do_emulation(pending_req, NULL)) + return scsiback_cmd_exec(pending_req); + + scsiback_fast_flush_area(pending_req); + scsiback_do_resp_with_sense(pending_req->sense_buffer, + pending_req->rslt, pending_req->resid, + pending_req); + return 0; } =20 =20 --- a/drivers/xen/scsiback/scsiback.c +++ b/drivers/xen/scsiback/scsiback.c @@ -429,14 +429,14 @@ free_bios: } =20 =20 -void scsiback_cmd_exec(pending_req_t *pending_req) +int scsiback_cmd_exec(pending_req_t *pending_req) { int cmd_len =3D (int)pending_req->cmd_len; int data_dir =3D (int)pending_req->sc_data_direction; unsigned int nr_segments =3D (unsigned int)pending_req->nr_segments= ; unsigned int timeout; struct request *rq; - int write; + int write, err; =20 DPRINTK("%s\n",__FUNCTION__); =20 @@ -463,17 +463,19 @@ void scsiback_cmd_exec(pending_req_t *pe rq->end_io_data =3D pending_req; =20 if (nr_segments) { - - if (request_map_sg(rq, pending_req, nr_segments)) { - printk(KERN_ERR "scsiback: SG Request Map = Error\n"); - return; + err =3D request_map_sg(rq, pending_req, nr_segments); + if (err) { + printk(KERN_ERR "scsiback: SG Request Map error = %d\n", + err); + blk_put_request(rq); + return err; } } =20 scsiback_get(pending_req->info); blk_execute_rq_nowait(rq->q, NULL, rq, 1, scsiback_cmd_done); =20 - return ; + return 0; } =20 =20 @@ -615,17 +617,28 @@ static int scsiback_do_cmd_fn(struct vsc switch (err ?: pending_req->act) { case VSCSIIF_ACT_SCSI_CDB: /* The Host mode is through as for Emulation. */ - if (info->feature =3D=3D VSCSI_TYPE_HOST) - scsiback_cmd_exec(pending_req); - else - scsiback_req_emulation_or_cmdexec(pending_r= eq); + if (info->feature =3D=3D VSCSI_TYPE_HOST ? + scsiback_cmd_exec(pending_req) : + scsiback_req_emulation_or_cmdexec(pending_req))= { + scsiback_fast_flush_area(pending_req); + scsiback_do_resp_with_sense(NULL, + DRIVER_ERROR = << 24, + 0, pending_req)= ; + } break; case VSCSIIF_ACT_SCSI_RESET: + /* Just for pointlessly specified segments: */ + scsiback_fast_flush_area(pending_req); scsiback_device_reset_exec(pending_req); break; default: - if(!err && printk_ratelimit()) - printk(KERN_ERR "scsiback: invalid = request\n"); + if(!err) { + scsiback_fast_flush_area(pending_req); + if (printk_ratelimit()) + printk(KERN_ERR + "scsiback: invalid request = %#x\n", + pending_req->act); + } scsiback_do_resp_with_sense(NULL, DRIVER_ERROR << = 24, 0, pending_req); break; --=__Part76449E8D.0__= Content-Type: text/plain; name="xen-scsiback-free-resources-after-error.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-scsiback-free-resources-after-error.patch" scsiback: free resources after error=0A=0AIn case of an error during = preparing an I/O the already allocated resources=0Ashould all be freed = again and the frontend request should be terminated=0Aaccordingly.=0A=0ASig= ned-off-by: Juergen Gross =0A=0ASome formatting adjustment= s to the changes above, and some more releasing=0Aof resources (in the = VSCSIIF_ACT_SCSI_RESET and default cases of the switch=0Ain scsiback_do_cmd= _fn()).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/drivers/xen/scsiback/common.h=0A+++ b/drivers/xen/scsiback/common.h=0A@@ = -163,13 +163,13 @@ struct scsi_device *scsiback_do_translat=0A void = scsiback_release_translation_entry(struct vscsibk_info *info);=0A =0A = =0A-void scsiback_cmd_exec(pending_req_t *pending_req);=0A+int scsiback_cmd= _exec(pending_req_t *pending_req);=0A void scsiback_do_resp_with_sense(char= *sense_buffer, int32_t result,=0A uint32_t resid, = pending_req_t *pending_req);=0A void scsiback_fast_flush_area(pending_req_t= *req);=0A =0A void scsiback_rsp_emulation(pending_req_t *pending_req);=0A-= void scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req);=0A+int = scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req);=0A void = scsiback_emulation_init(void);=0A =0A =0A--- a/drivers/xen/scsiback/emulate= .c=0A+++ b/drivers/xen/scsiback/emulate.c=0A@@ -345,16 +345,16 @@ void = scsiback_rsp_emulation(pending_req_=0A }=0A =0A =0A-void scsiback_req_emula= tion_or_cmdexec(pending_req_t *pending_req)=0A+int scsiback_req_emulation_o= r_cmdexec(pending_req_t *pending_req)=0A {=0A- if (__pre_do_emulation(pend= ing_req, NULL)) {=0A- scsiback_cmd_exec(pending_req);=0A- = }=0A- else {=0A- scsiback_fast_flush_area(pending_req);=0A- = scsiback_do_resp_with_sense(pending_req->sense_buffer,=0A- = pending_req->rslt, pending_req->resid, pending_req);=0A- }=0A+ if = (__pre_do_emulation(pending_req, NULL))=0A+ return scsiback_cmd= _exec(pending_req);=0A+=0A+ scsiback_fast_flush_area(pending_req);=0A+ = scsiback_do_resp_with_sense(pending_req->sense_buffer,=0A+ = pending_req->rslt, pending_req->resid,=0A+ = pending_req);=0A+ return 0;=0A }=0A =0A =0A--- a/drivers/xen/scsiback= /scsiback.c=0A+++ b/drivers/xen/scsiback/scsiback.c=0A@@ -429,14 +429,14 = @@ free_bios:=0A }=0A =0A =0A-void scsiback_cmd_exec(pending_req_t = *pending_req)=0A+int scsiback_cmd_exec(pending_req_t *pending_req)=0A {=0A = int cmd_len =3D (int)pending_req->cmd_len;=0A int data_dir =3D = (int)pending_req->sc_data_direction;=0A unsigned int nr_segments = =3D (unsigned int)pending_req->nr_segments;=0A unsigned int timeout;=0A = struct request *rq;=0A- int write;=0A+ int write, err;=0A =0A DPRINTK("%s= \n",__FUNCTION__);=0A =0A@@ -463,17 +463,19 @@ void scsiback_cmd_exec(pendi= ng_req_t *pe=0A rq->end_io_data =3D pending_req;=0A =0A if = (nr_segments) {=0A-=0A- if (request_map_sg(rq, pending_req, = nr_segments)) {=0A- printk(KERN_ERR "scsiback: SG = Request Map Error\n");=0A- return;=0A+ = err =3D request_map_sg(rq, pending_req, nr_segments);=0A+ if = (err) {=0A+ printk(KERN_ERR "scsiback: SG Request Map = error %d\n",=0A+ err);=0A+ = blk_put_request(rq);=0A+ return err;=0A = }=0A }=0A =0A scsiback_get(pending_req->info);=0A blk_execute= _rq_nowait(rq->q, NULL, rq, 1, scsiback_cmd_done);=0A =0A- return = ;=0A+ return 0;=0A }=0A =0A =0A@@ -615,17 +617,28 @@ static int = scsiback_do_cmd_fn(struct vsc=0A switch (err ?: pending_req-= >act) {=0A case VSCSIIF_ACT_SCSI_CDB:=0A /* = The Host mode is through as for Emulation. */=0A- if = (info->feature =3D=3D VSCSI_TYPE_HOST)=0A- = scsiback_cmd_exec(pending_req);=0A- else=0A- = scsiback_req_emulation_or_cmdexec(pending_req);=0A+ = if (info->feature =3D=3D VSCSI_TYPE_HOST ?=0A+ = scsiback_cmd_exec(pending_req) :=0A+ scsiback_req_em= ulation_or_cmdexec(pending_req)) {=0A+ scsiback_fa= st_flush_area(pending_req);=0A+ scsiback_do_resp_wi= th_sense(NULL,=0A+ = DRIVER_ERROR << 24,=0A+ = 0, pending_req);=0A+ }=0A = break;=0A case VSCSIIF_ACT_SCSI_RESET:=0A+ = /* Just for pointlessly specified segments: */=0A+ = scsiback_fast_flush_area(pending_req);=0A scsiback_de= vice_reset_exec(pending_req);=0A break;=0A = default:=0A- if(!err && printk_ratelimit())=0A- = printk(KERN_ERR "scsiback: invalid request\n");=0A+ = if(!err) {=0A+ scsiback_fast_flush_area(pe= nding_req);=0A+ if (printk_ratelimit())=0A+ = printk(KERN_ERR=0A+ = "scsiback: invalid request %#x\n",=0A+ = pending_req->act);=0A+ }=0A = scsiback_do_resp_with_sense(NULL, DRIVER_ERROR << 24,=0A = 0, pending_req);=0A = break;=0A --=__Part76449E8D.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.xen.org http://lists.xen.org/xen-devel --=__Part76449E8D.0__=--