aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-02-01 12:02:49 -0500
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-03-08 03:12:49 -0500
commit3c89f396dc78671cfbc1eb20ef1d5be6a9a02780 (patch)
tree6ed2ba3d484f8b92eed00b619128a79ecd094f4d /fs/ubifs
parentca2ec61d157f23ec24aaa200f8016ea0a8aeb617 (diff)
UBIFS: introduce write-buffer size field
Currently we assume write-buffer size is always min_io_size. But this is about to change and write-buffers may be of variable size. Namely, they will be of max_write_size at the beginning, but will get smaller when we are approaching the end of LEB. This is a preparation patch which introduces 'size' field in the write-buffer structure which carries the current write-buffer size. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs')
-rw-r--r--fs/ubifs/io.c28
-rw-r--r--fs/ubifs/ubifs.h2
2 files changed, 21 insertions, 9 deletions
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
index d1fe56203a1d..7c2a014b59f9 100644
--- a/fs/ubifs/io.c
+++ b/fs/ubifs/io.c
@@ -361,7 +361,10 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf)
361 dbg_io("LEB %d:%d, %d bytes, jhead %s", 361 dbg_io("LEB %d:%d, %d bytes, jhead %s",
362 wbuf->lnum, wbuf->offs, wbuf->used, dbg_jhead(wbuf->jhead)); 362 wbuf->lnum, wbuf->offs, wbuf->used, dbg_jhead(wbuf->jhead));
363 ubifs_assert(!(wbuf->avail & 7)); 363 ubifs_assert(!(wbuf->avail & 7));
364 ubifs_assert(wbuf->offs + c->min_io_size <= c->leb_size); 364 ubifs_assert(wbuf->offs + wbuf->size <= c->leb_size);
365 ubifs_assert(wbuf->size >= c->min_io_size);
366 ubifs_assert(wbuf->size <= c->max_write_size);
367 ubifs_assert(wbuf->size % c->min_io_size == 0);
365 ubifs_assert(!c->ro_media && !c->ro_mount); 368 ubifs_assert(!c->ro_media && !c->ro_mount);
366 369
367 if (c->ro_error) 370 if (c->ro_error)
@@ -369,10 +372,10 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf)
369 372
370 ubifs_pad(c, wbuf->buf + wbuf->used, wbuf->avail); 373 ubifs_pad(c, wbuf->buf + wbuf->used, wbuf->avail);
371 err = ubi_leb_write(c->ubi, wbuf->lnum, wbuf->buf, wbuf->offs, 374 err = ubi_leb_write(c->ubi, wbuf->lnum, wbuf->buf, wbuf->offs,
372 c->min_io_size, wbuf->dtype); 375 wbuf->size, wbuf->dtype);
373 if (err) { 376 if (err) {
374 ubifs_err("cannot write %d bytes to LEB %d:%d", 377 ubifs_err("cannot write %d bytes to LEB %d:%d",
375 c->min_io_size, wbuf->lnum, wbuf->offs); 378 wbuf->size, wbuf->lnum, wbuf->offs);
376 dbg_dump_stack(); 379 dbg_dump_stack();
377 return err; 380 return err;
378 } 381 }
@@ -380,8 +383,9 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf)
380 dirt = wbuf->avail; 383 dirt = wbuf->avail;
381 384
382 spin_lock(&wbuf->lock); 385 spin_lock(&wbuf->lock);
383 wbuf->offs += c->min_io_size; 386 wbuf->offs += wbuf->size;
384 wbuf->avail = c->min_io_size; 387 wbuf->avail = c->min_io_size;
388 wbuf->size = c->min_io_size;
385 wbuf->used = 0; 389 wbuf->used = 0;
386 wbuf->next_ino = 0; 390 wbuf->next_ino = 0;
387 spin_unlock(&wbuf->lock); 391 spin_unlock(&wbuf->lock);
@@ -425,6 +429,7 @@ int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs,
425 wbuf->lnum = lnum; 429 wbuf->lnum = lnum;
426 wbuf->offs = offs; 430 wbuf->offs = offs;
427 wbuf->avail = c->min_io_size; 431 wbuf->avail = c->min_io_size;
432 wbuf->size = c->min_io_size;
428 wbuf->used = 0; 433 wbuf->used = 0;
429 spin_unlock(&wbuf->lock); 434 spin_unlock(&wbuf->lock);
430 wbuf->dtype = dtype; 435 wbuf->dtype = dtype;
@@ -522,7 +527,10 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
522 ubifs_assert(len > 0 && wbuf->lnum >= 0 && wbuf->lnum < c->leb_cnt); 527 ubifs_assert(len > 0 && wbuf->lnum >= 0 && wbuf->lnum < c->leb_cnt);
523 ubifs_assert(wbuf->offs >= 0 && wbuf->offs % c->min_io_size == 0); 528 ubifs_assert(wbuf->offs >= 0 && wbuf->offs % c->min_io_size == 0);
524 ubifs_assert(!(wbuf->offs & 7) && wbuf->offs <= c->leb_size); 529 ubifs_assert(!(wbuf->offs & 7) && wbuf->offs <= c->leb_size);
525 ubifs_assert(wbuf->avail > 0 && wbuf->avail <= c->min_io_size); 530 ubifs_assert(wbuf->avail > 0 && wbuf->avail <= wbuf->size);
531 ubifs_assert(wbuf->size >= c->min_io_size);
532 ubifs_assert(wbuf->size <= c->max_write_size);
533 ubifs_assert(wbuf->size % c->min_io_size == 0);
526 ubifs_assert(mutex_is_locked(&wbuf->io_mutex)); 534 ubifs_assert(mutex_is_locked(&wbuf->io_mutex));
527 ubifs_assert(!c->ro_media && !c->ro_mount); 535 ubifs_assert(!c->ro_media && !c->ro_mount);
528 536
@@ -547,7 +555,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
547 dbg_io("flush jhead %s wbuf to LEB %d:%d", 555 dbg_io("flush jhead %s wbuf to LEB %d:%d",
548 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); 556 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs);
549 err = ubi_leb_write(c->ubi, wbuf->lnum, wbuf->buf, 557 err = ubi_leb_write(c->ubi, wbuf->lnum, wbuf->buf,
550 wbuf->offs, c->min_io_size, 558 wbuf->offs, wbuf->size,
551 wbuf->dtype); 559 wbuf->dtype);
552 if (err) 560 if (err)
553 goto out; 561 goto out;
@@ -555,6 +563,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
555 spin_lock(&wbuf->lock); 563 spin_lock(&wbuf->lock);
556 wbuf->offs += c->min_io_size; 564 wbuf->offs += c->min_io_size;
557 wbuf->avail = c->min_io_size; 565 wbuf->avail = c->min_io_size;
566 wbuf->size = c->min_io_size;
558 wbuf->used = 0; 567 wbuf->used = 0;
559 wbuf->next_ino = 0; 568 wbuf->next_ino = 0;
560 spin_unlock(&wbuf->lock); 569 spin_unlock(&wbuf->lock);
@@ -577,11 +586,11 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
577 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); 586 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs);
578 memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail); 587 memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail);
579 err = ubi_leb_write(c->ubi, wbuf->lnum, wbuf->buf, wbuf->offs, 588 err = ubi_leb_write(c->ubi, wbuf->lnum, wbuf->buf, wbuf->offs,
580 c->min_io_size, wbuf->dtype); 589 wbuf->size, wbuf->dtype);
581 if (err) 590 if (err)
582 goto out; 591 goto out;
583 592
584 offs = wbuf->offs + c->min_io_size; 593 offs = wbuf->offs + wbuf->size;
585 len -= wbuf->avail; 594 len -= wbuf->avail;
586 aligned_len -= wbuf->avail; 595 aligned_len -= wbuf->avail;
587 written = wbuf->avail; 596 written = wbuf->avail;
@@ -618,6 +627,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
618 wbuf->offs = offs; 627 wbuf->offs = offs;
619 wbuf->used = aligned_len; 628 wbuf->used = aligned_len;
620 wbuf->avail = c->min_io_size - aligned_len; 629 wbuf->avail = c->min_io_size - aligned_len;
630 wbuf->size = c->min_io_size;
621 wbuf->next_ino = 0; 631 wbuf->next_ino = 0;
622 spin_unlock(&wbuf->lock); 632 spin_unlock(&wbuf->lock);
623 633
@@ -855,7 +865,7 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf)
855 865
856 wbuf->used = 0; 866 wbuf->used = 0;
857 wbuf->lnum = wbuf->offs = -1; 867 wbuf->lnum = wbuf->offs = -1;
858 wbuf->avail = c->min_io_size; 868 wbuf->avail = wbuf->size = c->min_io_size;
859 wbuf->dtype = UBI_UNKNOWN; 869 wbuf->dtype = UBI_UNKNOWN;
860 wbuf->sync_callback = NULL; 870 wbuf->sync_callback = NULL;
861 mutex_init(&wbuf->io_mutex); 871 mutex_init(&wbuf->io_mutex);
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 942c1d3cb0db..362495078489 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -646,6 +646,7 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
646 * @offs: write-buffer offset in this logical eraseblock 646 * @offs: write-buffer offset in this logical eraseblock
647 * @avail: number of bytes available in the write-buffer 647 * @avail: number of bytes available in the write-buffer
648 * @used: number of used bytes in the write-buffer 648 * @used: number of used bytes in the write-buffer
649 * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range)
649 * @dtype: type of data stored in this LEB (%UBI_LONGTERM, %UBI_SHORTTERM, 650 * @dtype: type of data stored in this LEB (%UBI_LONGTERM, %UBI_SHORTTERM,
650 * %UBI_UNKNOWN) 651 * %UBI_UNKNOWN)
651 * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep 652 * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep
@@ -680,6 +681,7 @@ struct ubifs_wbuf {
680 int offs; 681 int offs;
681 int avail; 682 int avail;
682 int used; 683 int used;
684 int size;
683 int dtype; 685 int dtype;
684 int jhead; 686 int jhead;
685 int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); 687 int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);