Lines Matching refs:wbuf
477 struct ubifs_wbuf *wbuf = container_of(timer, struct ubifs_wbuf, timer); in wbuf_timer_callback_nolock() local
479 dbg_io("jhead %s", dbg_jhead(wbuf->jhead)); in wbuf_timer_callback_nolock()
480 wbuf->need_sync = 1; in wbuf_timer_callback_nolock()
481 wbuf->c->need_wbuf_sync = 1; in wbuf_timer_callback_nolock()
482 ubifs_wake_up_bgt(wbuf->c); in wbuf_timer_callback_nolock()
491 static void new_wbuf_timer_nolock(struct ubifs_info *c, struct ubifs_wbuf *wbuf) in new_wbuf_timer_nolock() argument
499 ubifs_assert(c, !hrtimer_active(&wbuf->timer)); in new_wbuf_timer_nolock()
502 if (wbuf->no_timer) in new_wbuf_timer_nolock()
505 dbg_jhead(wbuf->jhead), in new_wbuf_timer_nolock()
508 hrtimer_start_range_ns(&wbuf->timer, softlimit, delta, in new_wbuf_timer_nolock()
516 static void cancel_wbuf_timer_nolock(struct ubifs_wbuf *wbuf) in cancel_wbuf_timer_nolock() argument
518 if (wbuf->no_timer) in cancel_wbuf_timer_nolock()
520 wbuf->need_sync = 0; in cancel_wbuf_timer_nolock()
521 hrtimer_cancel(&wbuf->timer); in cancel_wbuf_timer_nolock()
537 int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf) in ubifs_wbuf_sync_nolock() argument
539 struct ubifs_info *c = wbuf->c; in ubifs_wbuf_sync_nolock()
542 cancel_wbuf_timer_nolock(wbuf); in ubifs_wbuf_sync_nolock()
543 if (!wbuf->used || wbuf->lnum == -1) in ubifs_wbuf_sync_nolock()
548 wbuf->lnum, wbuf->offs, wbuf->used, dbg_jhead(wbuf->jhead)); in ubifs_wbuf_sync_nolock()
549 ubifs_assert(c, !(wbuf->avail & 7)); in ubifs_wbuf_sync_nolock()
550 ubifs_assert(c, wbuf->offs + wbuf->size <= c->leb_size); in ubifs_wbuf_sync_nolock()
551 ubifs_assert(c, wbuf->size >= c->min_io_size); in ubifs_wbuf_sync_nolock()
552 ubifs_assert(c, wbuf->size <= c->max_write_size); in ubifs_wbuf_sync_nolock()
553 ubifs_assert(c, wbuf->size % c->min_io_size == 0); in ubifs_wbuf_sync_nolock()
555 if (c->leb_size - wbuf->offs >= c->max_write_size) in ubifs_wbuf_sync_nolock()
556 ubifs_assert(c, !((wbuf->offs + wbuf->size) % c->max_write_size)); in ubifs_wbuf_sync_nolock()
565 sync_len = ALIGN(wbuf->used, c->min_io_size); in ubifs_wbuf_sync_nolock()
566 dirt = sync_len - wbuf->used; in ubifs_wbuf_sync_nolock()
568 ubifs_pad(c, wbuf->buf + wbuf->used, dirt); in ubifs_wbuf_sync_nolock()
569 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, sync_len); in ubifs_wbuf_sync_nolock()
573 spin_lock(&wbuf->lock); in ubifs_wbuf_sync_nolock()
574 wbuf->offs += sync_len; in ubifs_wbuf_sync_nolock()
585 if (c->leb_size - wbuf->offs < c->max_write_size) in ubifs_wbuf_sync_nolock()
586 wbuf->size = c->leb_size - wbuf->offs; in ubifs_wbuf_sync_nolock()
587 else if (wbuf->offs & (c->max_write_size - 1)) in ubifs_wbuf_sync_nolock()
588 wbuf->size = ALIGN(wbuf->offs, c->max_write_size) - wbuf->offs; in ubifs_wbuf_sync_nolock()
590 wbuf->size = c->max_write_size; in ubifs_wbuf_sync_nolock()
591 wbuf->avail = wbuf->size; in ubifs_wbuf_sync_nolock()
592 wbuf->used = 0; in ubifs_wbuf_sync_nolock()
593 wbuf->next_ino = 0; in ubifs_wbuf_sync_nolock()
594 spin_unlock(&wbuf->lock); in ubifs_wbuf_sync_nolock()
596 if (wbuf->sync_callback) in ubifs_wbuf_sync_nolock()
597 err = wbuf->sync_callback(c, wbuf->lnum, in ubifs_wbuf_sync_nolock()
598 c->leb_size - wbuf->offs, dirt); in ubifs_wbuf_sync_nolock()
612 int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs) in ubifs_wbuf_seek_nolock() argument
614 const struct ubifs_info *c = wbuf->c; in ubifs_wbuf_seek_nolock()
616 dbg_io("LEB %d:%d, jhead %s", lnum, offs, dbg_jhead(wbuf->jhead)); in ubifs_wbuf_seek_nolock()
620 ubifs_assert(c, lnum != wbuf->lnum); in ubifs_wbuf_seek_nolock()
621 ubifs_assert(c, wbuf->used == 0); in ubifs_wbuf_seek_nolock()
623 spin_lock(&wbuf->lock); in ubifs_wbuf_seek_nolock()
624 wbuf->lnum = lnum; in ubifs_wbuf_seek_nolock()
625 wbuf->offs = offs; in ubifs_wbuf_seek_nolock()
626 if (c->leb_size - wbuf->offs < c->max_write_size) in ubifs_wbuf_seek_nolock()
627 wbuf->size = c->leb_size - wbuf->offs; in ubifs_wbuf_seek_nolock()
628 else if (wbuf->offs & (c->max_write_size - 1)) in ubifs_wbuf_seek_nolock()
629 wbuf->size = ALIGN(wbuf->offs, c->max_write_size) - wbuf->offs; in ubifs_wbuf_seek_nolock()
631 wbuf->size = c->max_write_size; in ubifs_wbuf_seek_nolock()
632 wbuf->avail = wbuf->size; in ubifs_wbuf_seek_nolock()
633 wbuf->used = 0; in ubifs_wbuf_seek_nolock()
634 spin_unlock(&wbuf->lock); in ubifs_wbuf_seek_nolock()
663 struct ubifs_wbuf *wbuf = &c->jheads[i].wbuf; in ubifs_bg_wbufs_sync() local
671 if (mutex_is_locked(&wbuf->io_mutex)) in ubifs_bg_wbufs_sync()
674 mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead); in ubifs_bg_wbufs_sync()
675 if (!wbuf->need_sync) { in ubifs_bg_wbufs_sync()
676 mutex_unlock(&wbuf->io_mutex); in ubifs_bg_wbufs_sync()
680 err = ubifs_wbuf_sync_nolock(wbuf); in ubifs_bg_wbufs_sync()
681 mutex_unlock(&wbuf->io_mutex); in ubifs_bg_wbufs_sync()
694 struct ubifs_wbuf *wbuf = &c->jheads[i].wbuf; in ubifs_bg_wbufs_sync() local
696 mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead); in ubifs_bg_wbufs_sync()
697 cancel_wbuf_timer_nolock(wbuf); in ubifs_bg_wbufs_sync()
698 mutex_unlock(&wbuf->io_mutex); in ubifs_bg_wbufs_sync()
719 int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) in ubifs_wbuf_write_nolock() argument
721 struct ubifs_info *c = wbuf->c; in ubifs_wbuf_write_nolock()
726 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs + wbuf->used); in ubifs_wbuf_write_nolock()
727 ubifs_assert(c, len > 0 && wbuf->lnum >= 0 && wbuf->lnum < c->leb_cnt); in ubifs_wbuf_write_nolock()
728 ubifs_assert(c, wbuf->offs >= 0 && wbuf->offs % c->min_io_size == 0); in ubifs_wbuf_write_nolock()
729 ubifs_assert(c, !(wbuf->offs & 7) && wbuf->offs <= c->leb_size); in ubifs_wbuf_write_nolock()
730 ubifs_assert(c, wbuf->avail > 0 && wbuf->avail <= wbuf->size); in ubifs_wbuf_write_nolock()
731 ubifs_assert(c, wbuf->size >= c->min_io_size); in ubifs_wbuf_write_nolock()
732 ubifs_assert(c, wbuf->size <= c->max_write_size); in ubifs_wbuf_write_nolock()
733 ubifs_assert(c, wbuf->size % c->min_io_size == 0); in ubifs_wbuf_write_nolock()
734 ubifs_assert(c, mutex_is_locked(&wbuf->io_mutex)); in ubifs_wbuf_write_nolock()
737 if (c->leb_size - wbuf->offs >= c->max_write_size) in ubifs_wbuf_write_nolock()
738 ubifs_assert(c, !((wbuf->offs + wbuf->size) % c->max_write_size)); in ubifs_wbuf_write_nolock()
740 if (c->leb_size - wbuf->offs - wbuf->used < aligned_len) { in ubifs_wbuf_write_nolock()
745 cancel_wbuf_timer_nolock(wbuf); in ubifs_wbuf_write_nolock()
750 if (aligned_len <= wbuf->avail) { in ubifs_wbuf_write_nolock()
755 memcpy(wbuf->buf + wbuf->used, buf, len); in ubifs_wbuf_write_nolock()
758 ubifs_pad(c, wbuf->buf + wbuf->used + len, aligned_len - len); in ubifs_wbuf_write_nolock()
761 if (aligned_len == wbuf->avail) { in ubifs_wbuf_write_nolock()
763 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); in ubifs_wbuf_write_nolock()
764 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, in ubifs_wbuf_write_nolock()
765 wbuf->offs, wbuf->size); in ubifs_wbuf_write_nolock()
769 spin_lock(&wbuf->lock); in ubifs_wbuf_write_nolock()
770 wbuf->offs += wbuf->size; in ubifs_wbuf_write_nolock()
771 if (c->leb_size - wbuf->offs >= c->max_write_size) in ubifs_wbuf_write_nolock()
772 wbuf->size = c->max_write_size; in ubifs_wbuf_write_nolock()
774 wbuf->size = c->leb_size - wbuf->offs; in ubifs_wbuf_write_nolock()
775 wbuf->avail = wbuf->size; in ubifs_wbuf_write_nolock()
776 wbuf->used = 0; in ubifs_wbuf_write_nolock()
777 wbuf->next_ino = 0; in ubifs_wbuf_write_nolock()
778 spin_unlock(&wbuf->lock); in ubifs_wbuf_write_nolock()
780 spin_lock(&wbuf->lock); in ubifs_wbuf_write_nolock()
781 wbuf->avail -= aligned_len; in ubifs_wbuf_write_nolock()
782 wbuf->used += aligned_len; in ubifs_wbuf_write_nolock()
783 spin_unlock(&wbuf->lock); in ubifs_wbuf_write_nolock()
789 if (wbuf->used) { in ubifs_wbuf_write_nolock()
796 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); in ubifs_wbuf_write_nolock()
797 memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail); in ubifs_wbuf_write_nolock()
798 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, in ubifs_wbuf_write_nolock()
799 wbuf->size); in ubifs_wbuf_write_nolock()
803 wbuf->offs += wbuf->size; in ubifs_wbuf_write_nolock()
804 len -= wbuf->avail; in ubifs_wbuf_write_nolock()
805 aligned_len -= wbuf->avail; in ubifs_wbuf_write_nolock()
806 written += wbuf->avail; in ubifs_wbuf_write_nolock()
807 } else if (wbuf->offs & (c->max_write_size - 1)) { in ubifs_wbuf_write_nolock()
816 wbuf->size, wbuf->lnum, wbuf->offs); in ubifs_wbuf_write_nolock()
817 err = ubifs_leb_write(c, wbuf->lnum, buf, wbuf->offs, in ubifs_wbuf_write_nolock()
818 wbuf->size); in ubifs_wbuf_write_nolock()
822 wbuf->offs += wbuf->size; in ubifs_wbuf_write_nolock()
823 len -= wbuf->size; in ubifs_wbuf_write_nolock()
824 aligned_len -= wbuf->size; in ubifs_wbuf_write_nolock()
825 written += wbuf->size; in ubifs_wbuf_write_nolock()
838 dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum, in ubifs_wbuf_write_nolock()
839 wbuf->offs); in ubifs_wbuf_write_nolock()
844 err = ubifs_leb_write(c, wbuf->lnum, buf + written, in ubifs_wbuf_write_nolock()
845 wbuf->offs, m); in ubifs_wbuf_write_nolock()
848 wbuf->offs += m; in ubifs_wbuf_write_nolock()
860 memcpy(wbuf->buf, buf + written, min(len, n)); in ubifs_wbuf_write_nolock()
863 ubifs_pad(c, wbuf->buf + len, n - len); in ubifs_wbuf_write_nolock()
866 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, n); in ubifs_wbuf_write_nolock()
869 wbuf->offs += n; in ubifs_wbuf_write_nolock()
875 spin_lock(&wbuf->lock); in ubifs_wbuf_write_nolock()
882 memcpy(wbuf->buf, buf + written, len); in ubifs_wbuf_write_nolock()
885 ubifs_pad(c, wbuf->buf + len, aligned_len - len); in ubifs_wbuf_write_nolock()
889 if (c->leb_size - wbuf->offs >= c->max_write_size) in ubifs_wbuf_write_nolock()
890 wbuf->size = c->max_write_size; in ubifs_wbuf_write_nolock()
892 wbuf->size = c->leb_size - wbuf->offs; in ubifs_wbuf_write_nolock()
893 wbuf->avail = wbuf->size - aligned_len; in ubifs_wbuf_write_nolock()
894 wbuf->used = aligned_len; in ubifs_wbuf_write_nolock()
895 wbuf->next_ino = 0; in ubifs_wbuf_write_nolock()
896 spin_unlock(&wbuf->lock); in ubifs_wbuf_write_nolock()
899 if (wbuf->sync_callback) { in ubifs_wbuf_write_nolock()
900 int free = c->leb_size - wbuf->offs - wbuf->used; in ubifs_wbuf_write_nolock()
902 err = wbuf->sync_callback(c, wbuf->lnum, free, 0); in ubifs_wbuf_write_nolock()
907 if (wbuf->used) in ubifs_wbuf_write_nolock()
908 new_wbuf_timer_nolock(c, wbuf); in ubifs_wbuf_write_nolock()
914 len, wbuf->lnum, wbuf->offs, err); in ubifs_wbuf_write_nolock()
917 ubifs_dump_leb(c, wbuf->lnum); in ubifs_wbuf_write_nolock()
998 int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, in ubifs_read_node_wbuf() argument
1001 const struct ubifs_info *c = wbuf->c; in ubifs_read_node_wbuf()
1006 dbg_ntype(type), len, dbg_jhead(wbuf->jhead)); in ubifs_read_node_wbuf()
1007 ubifs_assert(c, wbuf && lnum >= 0 && lnum < c->leb_cnt && offs >= 0); in ubifs_read_node_wbuf()
1011 spin_lock(&wbuf->lock); in ubifs_read_node_wbuf()
1012 overlap = (lnum == wbuf->lnum && offs + len > wbuf->offs); in ubifs_read_node_wbuf()
1015 spin_unlock(&wbuf->lock); in ubifs_read_node_wbuf()
1020 rlen = wbuf->offs - offs; in ubifs_read_node_wbuf()
1025 memcpy(buf + rlen, wbuf->buf + offs + rlen - wbuf->offs, len - rlen); in ubifs_read_node_wbuf()
1026 spin_unlock(&wbuf->lock); in ubifs_read_node_wbuf()
1129 int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf) in ubifs_wbuf_init() argument
1133 wbuf->buf = kmalloc(c->max_write_size, GFP_KERNEL); in ubifs_wbuf_init()
1134 if (!wbuf->buf) in ubifs_wbuf_init()
1138 wbuf->inodes = kmalloc(size, GFP_KERNEL); in ubifs_wbuf_init()
1139 if (!wbuf->inodes) { in ubifs_wbuf_init()
1140 kfree(wbuf->buf); in ubifs_wbuf_init()
1141 wbuf->buf = NULL; in ubifs_wbuf_init()
1145 wbuf->used = 0; in ubifs_wbuf_init()
1146 wbuf->lnum = wbuf->offs = -1; in ubifs_wbuf_init()
1154 wbuf->avail = wbuf->size = size; in ubifs_wbuf_init()
1155 wbuf->sync_callback = NULL; in ubifs_wbuf_init()
1156 mutex_init(&wbuf->io_mutex); in ubifs_wbuf_init()
1157 spin_lock_init(&wbuf->lock); in ubifs_wbuf_init()
1158 wbuf->c = c; in ubifs_wbuf_init()
1159 wbuf->next_ino = 0; in ubifs_wbuf_init()
1161 hrtimer_init(&wbuf->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in ubifs_wbuf_init()
1162 wbuf->timer.function = wbuf_timer_callback_nolock; in ubifs_wbuf_init()
1173 void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum) in ubifs_wbuf_add_ino_nolock() argument
1175 if (!wbuf->buf) in ubifs_wbuf_add_ino_nolock()
1179 spin_lock(&wbuf->lock); in ubifs_wbuf_add_ino_nolock()
1180 if (wbuf->used) in ubifs_wbuf_add_ino_nolock()
1181 wbuf->inodes[wbuf->next_ino++] = inum; in ubifs_wbuf_add_ino_nolock()
1182 spin_unlock(&wbuf->lock); in ubifs_wbuf_add_ino_nolock()
1193 static int wbuf_has_ino(struct ubifs_wbuf *wbuf, ino_t inum) in wbuf_has_ino() argument
1197 spin_lock(&wbuf->lock); in wbuf_has_ino()
1198 for (i = 0; i < wbuf->next_ino; i++) in wbuf_has_ino()
1199 if (inum == wbuf->inodes[i]) { in wbuf_has_ino()
1203 spin_unlock(&wbuf->lock); in wbuf_has_ino()
1222 struct ubifs_wbuf *wbuf = &c->jheads[i].wbuf; in ubifs_sync_wbufs_by_inode() local
1233 if (!wbuf_has_ino(wbuf, inode->i_ino)) in ubifs_sync_wbufs_by_inode()
1236 mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead); in ubifs_sync_wbufs_by_inode()
1237 if (wbuf_has_ino(wbuf, inode->i_ino)) in ubifs_sync_wbufs_by_inode()
1238 err = ubifs_wbuf_sync_nolock(wbuf); in ubifs_sync_wbufs_by_inode()
1239 mutex_unlock(&wbuf->io_mutex); in ubifs_sync_wbufs_by_inode()