From: "Jan Beulich" Subject: Re: [PATCH][linux 2.6.18] remove pointless error handling in scsiback Date: Wed, 02 Jul 2014 12:57:22 +0100 Message-ID: <53B40FC2020000780001F774@mail.emea.novell.com> References: <1404285980-10817-1-git-send-email-jgross@suse.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC9FB24B2.0__=" Return-path: In-Reply-To: <1404285980-10817-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: Juergen Gross Cc: xen-devel@lists.xen.org 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. --=__PartC9FB24B2.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 02.07.14 at 09:26, <"jgross@suse.com".non-mime.internet> wrote: > Changeset 610:3bcc901cbd7a added a retry logic for reporting LUNs to the > frontend. The idea was to retry the operation if a LUN was added between > counting the LUNs (needed for calculating the needed buffer size) and > processing them (filling the buffer). The number of retries was limited = to > three. Reasoning was "one error is very unlikely, 4 of them are way = off". >=20 > Unfortunately above changeset was wrong: The retry didn't include = recounting > the LUNs, so the buffer size would not be changed. The number of found = was not > resetted, so the first found LUN would again trigger the retry logic = until the > number of retries would be exhausted. >=20 > While one error is really very unlikely (there was no report of failure = and > as shown above, the first error would have led to failure at once), even = in > case of a correct retry logic following errors are not completely = impossible: > If a target with many LUNs is being added to the frontend, the single = LUNs are > added one after another. A parallel running "report LUNs" could see a = fast > increasing number of LUNs, so even a few retries might fail. >=20 > So just remove the retry logic again. I'm still not convinced of this being the right action: I can see a point in the original argumentation, so why don't we just fix it instead of removing it (see below/attached)? Jan scsiback: fix retry handling in __report_luns() Neither did lun_cnt get reset when invoking a retry here, nor did the intermediate buffer get resized to fit the larger amount. Fix this, at once - adding spare extra buffer space growing with the number of retries, - correct a couple of signed/unsigned issues here and its helper function __nr_luns_under_host(), - drop pointless NULL checks before kfree() invocations (not only does kfree() deal fine with NULL, in the first of the two cases it was plain impossible for the pointer to be NULL). Reported-by: Juergen Gross Signed-off-by: Jan Beulich --- a/drivers/xen/scsiback/emulate.c +++ b/drivers/xen/scsiback/emulate.c @@ -193,12 +193,12 @@ static int __maybe_unused __copy_from_sg return 0; } =20 -static int __nr_luns_under_host(struct vscsibk_info *info) +static unsigned int __nr_luns_under_host(struct vscsibk_info *info) { struct v2p_entry *entry; struct list_head *head =3D &(info->v2p_entry_lists); unsigned long flags; - int lun_cnt =3D 0; + unsigned int lun_cnt =3D 0; =20 spin_lock_irqsave(&info->v2p_lock, flags); list_for_each_entry(entry, head, l) { @@ -213,6 +213,7 @@ static int __nr_luns_under_host(struct v /* REPORT LUNS Define*/ #define VSCSI_REPORT_LUNS_HEADER 8 #define VSCSI_REPORT_LUNS_RETRY 3 +#define VSCSI_REPORT_LUNS_SPARE 3 =20 /* quoted scsi_debug.c/resp_report_luns() */ static void __report_luns(pending_req_t *pending_req, void *data) @@ -229,8 +230,8 @@ static void __report_luns(pending_req_t=20 unsigned int req_bufflen =3D 0; unsigned int actual_len =3D 0; unsigned int retry_cnt =3D 0; - int select_report =3D (int)cmd[2]; - int i, lun_cnt =3D 0, lun, upper, err =3D 0; + int err, select_report =3D (int)cmd[2]; + unsigned int i, lun_cnt, lun, upper; =09 struct v2p_entry *entry; struct list_head *head =3D &(info->v2p_entry_lists); @@ -242,16 +243,18 @@ static void __report_luns(pending_req_t=20 if ((req_bufflen < 4) || (select_report !=3D 0)) goto fail; =20 - alloc_luns =3D __nr_luns_under_host(info); +retry: + alloc_luns =3D __nr_luns_under_host(info) + + retry_cnt * VSCSI_REPORT_LUNS_SPARE; alloc_len =3D sizeof(struct scsi_lun) * alloc_luns + VSCSI_REPORT_LUNS_HEADER; -retry: if ((buff =3D kzalloc(alloc_len, GFP_KERNEL)) =3D=3D NULL) { printk(KERN_ERR "scsiback:%s kmalloc err\n", __FUNCTION__);= goto fail; } =20 - one_lun =3D (struct scsi_lun *) &buff[8]; + one_lun =3D (struct scsi_lun *)&buff[VSCSI_REPORT_LUNS_HEADER]; + lun_cnt =3D 0; spin_lock_irqsave(&info->v2p_lock, flags); list_for_each_entry(entry, head, l) { if ((entry->v.chn =3D=3D channel) && @@ -264,8 +267,7 @@ retry: =20 if (retry_cnt < VSCSI_REPORT_LUNS_RETRY) { retry_cnt++; - if (buff) - kfree(buff); + kfree(buff); goto retry; } =20 @@ -309,8 +311,7 @@ fail: INVALID_FIELD_IN_CDB, 0); pending_req->rslt =3D check_condition_result; pending_req->resid =3D 0; - if (buff) - kfree(buff); + kfree(buff); return; } =20 --=__PartC9FB24B2.0__= Content-Type: text/plain; name="xen-scsiback-report-LUNs-retry.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-scsiback-report-LUNs-retry.patch" scsiback: fix retry handling in __report_luns()=0A=0ANeither did lun_cnt = get reset when invoking a retry here, nor did the=0Aintermediate buffer = get resized to fit the larger amount. Fix this, at=0Aonce=0A- adding spare = extra buffer space growing with the number of retries,=0A- correct a = couple of signed/unsigned issues here and its helper=0A function = __nr_luns_under_host(),=0A- drop pointless NULL checks before kfree() = invocations (not only does=0A kfree() deal fine with NULL, in the first = of the two cases it was=0A plain impossible for the pointer to be = NULL).=0A=0AReported-by: Juergen Gross =0ASigned-off-by: = Jan Beulich =0A=0A--- a/drivers/xen/scsiback/emulate.c= =0A+++ b/drivers/xen/scsiback/emulate.c=0A@@ -193,12 +193,12 @@ static int = __maybe_unused __copy_from_sg=0A return 0;=0A }=0A =0A-static int = __nr_luns_under_host(struct vscsibk_info *info)=0A+static unsigned int = __nr_luns_under_host(struct vscsibk_info *info)=0A {=0A struct = v2p_entry *entry;=0A struct list_head *head =3D &(info->v2p_entry_lists)= ;=0A unsigned long flags;=0A- int lun_cnt =3D 0;=0A+ unsigned = int lun_cnt =3D 0;=0A =0A spin_lock_irqsave(&info->v2p_lock, = flags);=0A list_for_each_entry(entry, head, l) {=0A@@ -213,6 +213,7 = @@ static int __nr_luns_under_host(struct v=0A /* REPORT LUNS Define*/=0A = #define VSCSI_REPORT_LUNS_HEADER 8=0A #define VSCSI_REPORT_LUNS_RETR= Y 3=0A+#define VSCSI_REPORT_LUNS_SPARE 3=0A =0A = /* quoted scsi_debug.c/resp_report_luns() */=0A static void __report_luns(p= ending_req_t *pending_req, void *data)=0A@@ -229,8 +230,8 @@ static void = __report_luns(pending_req_t =0A unsigned int req_bufflen =3D 0;=0A = unsigned int actual_len =3D 0;=0A unsigned int retry_cnt =3D = 0;=0A- int select_report =3D (int)cmd[2];=0A- int i, lun_cnt =3D 0, lun, = upper, err =3D 0;=0A+ int err, select_report =3D (int)cmd[2];=0A+ = unsigned int i, lun_cnt, lun, upper;=0A =0A struct v2p_entry = *entry;=0A struct list_head *head =3D &(info->v2p_entry_lists);=0A@@ = -242,16 +243,18 @@ static void __report_luns(pending_req_t =0A if = ((req_bufflen < 4) || (select_report !=3D 0))=0A goto = fail;=0A =0A- alloc_luns =3D __nr_luns_under_host(info);=0A+retry:=0A+ = alloc_luns =3D __nr_luns_under_host(info)=0A+ + retry_cnt * = VSCSI_REPORT_LUNS_SPARE;=0A alloc_len =3D sizeof(struct scsi_lun) * = alloc_luns=0A + VSCSI_REPORT_LUNS_HEADER;=0A-retr= y:=0A if ((buff =3D kzalloc(alloc_len, GFP_KERNEL)) =3D=3D NULL) {=0A = printk(KERN_ERR "scsiback:%s kmalloc err\n", __FUNCTION__);=0A = goto fail;=0A }=0A =0A- one_lun =3D (struct scsi_lun *) = &buff[8];=0A+ one_lun =3D (struct scsi_lun *)&buff[VSCSI_REPORT_LUNS_HEAD= ER];=0A+ lun_cnt =3D 0;=0A spin_lock_irqsave(&info->v2p_lock, = flags);=0A list_for_each_entry(entry, head, l) {=0A if = ((entry->v.chn =3D=3D channel) &&=0A@@ -264,8 +267,7 @@ retry:=0A =0A = if (retry_cnt < VSCSI_REPORT_LUNS_RETRY) {=0A = retry_cnt++;=0A- if = (buff)=0A- kfree(buff);=0A+ = kfree(buff);=0A = goto retry;=0A }=0A =0A@@ -309,8 +311,7 = @@ fail:=0A INVALID_FIELD_IN_CDB, 0);=0A pending_req->rslt = =3D check_condition_result;=0A pending_req->resid =3D 0;=0A- if = (buff)=0A- kfree(buff);=0A+ kfree(buff);=0A = return;=0A }=0A =0A --=__PartC9FB24B2.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 --=__PartC9FB24B2.0__=--