From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from down.free-electrons.com ([37.187.137.238] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bkrFs-0002rC-0K for linux-mtd@lists.infradead.org; Fri, 16 Sep 2016 11:24:29 +0000 Date: Fri, 16 Sep 2016 13:23:55 +0200 From: Boris Brezillon To: Richard Weinberger Cc: Artem Bityutskiy , David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 11/17] UBI: simplify recover_peb() code Message-ID: <20160916132355.22c354f8@bbrezillon> In-Reply-To: References: <1473087908-27862-1-git-send-email-boris.brezillon@free-electrons.com> <1473087908-27862-12-git-send-email-boris.brezillon@free-electrons.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Fri, 16 Sep 2016 12:14:04 +0200 Richard Weinberger wrote: > Boris, > > On 05.09.2016 17:05, Boris Brezillon wrote: > > + * This function is called in case of a write failure and moves all good data > > + * from the potentially bad physical eraseblock to a good physical eraseblock. > > + * This function also writes the data which was not written due to the failure. > > + * Returns 0 in case of success, and a negative error code in case of failure. > > + * This function tries %UBI_IO_RETRIES before giving up. > > + */ > > +static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum, > > + const void *buf, int offset, int len) > > +{ > > + int err, idx = vol_id2idx(ubi, vol_id), tries; > > + struct ubi_volume *vol = ubi->volumes[idx]; > > + struct ubi_vid_hdr *vid_hdr; > > + > > + vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); > > + if (!vid_hdr) > > + return -ENOMEM; > > + > > + for (tries = 0; tries <= UBI_IO_RETRIES; tries++) { > > + err = try_recover_peb(vol, pnum, lnum, buf, offset, len, > > + vid_hdr); > > + if (!err || err == -ENOSPC) > > + break; > > Why do you handle ENOSPC as fatal error? Since the loop is bound by UBI_IO_RETRIES > IMHO we can retry also upon ENOSPC. I was just trying to mimic the existing behavior: if ubi_wl_get_peb() fails to return a free PEB it returns -ENOSPC, and the current implementation does not retry in this case. I also realize that we should not retry if the error happened when reading from the source PEB. Maybe we should have an extra 'bool *retry' parameter to let recover_peb() know whether the operation should be retried or not. What do you think?