JFFS2 & SMP

Estelle HAMMACHE estelle.hammache at st.com
Fri Nov 5 04:06:55 EST 2004


Artem,

you are right of course. The patch I proposed would only make sense
in a very specific environment which is very different from the
way JFFS2 and linux work. So you can forget about my previous message.
I guess there is no way around using a mutex.

Estelle


"Artem B. Bityuckiy" wrote:
> 
> Estelle,
> 
> I don't cleanly understand your Idea, I'll think more.
> 
> Could you please answer: does it handle the following "use-case" (if
> yes, how?):
> 
> Suppose we are reading node, which is in the wbuf so far.
> 
> int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len,
> size_t *retlen, u_char *buf)
> {
>          loff_t  orbf = 0, owbf = 0, lwbf = 0;
>          int     ret;
> 
>          /* Read flash */
>          if (!jffs2_can_mark_obsolete(c)) {
>                  ret = c->mtd->read_ecc(c->mtd, ofs, len, retlen, buf,
> NULL, c->oobinfo);
> 
>                  if ( (ret == -EBADMSG) && (*retlen == len) ) {
>                          printk(KERN_WARNING "mtd->read(0x%zx bytes from
> 0x%llx) returned ECC error\n",
>                                 len, ofs);
>                          /*
>                           * We have the raw data without ECC correction
> in the buffer, maybe
>                           * we are lucky and all data or parts are
> correct. We check the node.
>                           * If data are corrupted node check will sort
> it out.
>                           * We keep this block, it will fail on write or
> erase and the we
>                           * mark it bad. Or should we do that now? But
> we should give him a chance.
>                           * Maybe we had a system crash or power loss
> before the ecc write or
>                           * a erase was completed.
>                           * So we return success. :)
>                           */
>                          ret = 0;
>                   }
>          } else
>                  return c->mtd->read(c->mtd, ofs, len, retlen, buf);
> /*________________________
> Suppose the page we have read is empty because of its data is still in
> wbuf. We have read all 0xFF. Suppose we are preempted at this point.
> Somebody else made write, the wbuf became full and was flushed to the
> correspondent flash page. Then we wake up. We see, the wbuf_len == 0.
> And we exit. Result: we have read all 0xFF instead of node....
> ________________________*/
> 
>          /* if no writebuffer available or write buffer empty, return */
>          if (!c->wbuf_pagesize || !c->wbuf_len)
>                  return ret; /* <---------------------- we exit here.... */
> 
>          /* if we read in a different block, return */
>          if ( (ofs & ~(c->sector_size-1)) != (c->wbuf_ofs &
> ~(c->sector_size-1)) )
>                  return ret;
> 
>          if (ofs >= c->wbuf_ofs) {
>                  owbf = (ofs - c->wbuf_ofs);     /* offset in write
> buffer */
>                  if (owbf > c->wbuf_len)         /* is read beyond write
> buffer ? */
>                          return ret;
>                  lwbf = c->wbuf_len - owbf;      /* number of bytes to
> copy */
>                  if (lwbf > len)
>                          lwbf = len;
>          } else {
>                  orbf = (c->wbuf_ofs - ofs);     /* offset in read buffer */
>                  if (orbf > len)                 /* is write beyond
> write buffer ? */
>                          return ret;
>                  lwbf = len - orbf;              /* number of bytes to
> copy */
>                  if (lwbf > c->wbuf_len)
>                          lwbf = c->wbuf_len;
>          }
>          if (lwbf > 0)
>                  memcpy(buf+orbf,c->wbuf+owbf,lwbf);
> 
>          return ret;
> }
>




More information about the linux-mtd mailing list