diff options
Diffstat (limited to 'fs/nilfs2/sufile.c')
-rw-r--r-- | fs/nilfs2/sufile.c | 119 |
1 files changed, 110 insertions, 9 deletions
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c index 98e68677f045..37994d4a59cc 100644 --- a/fs/nilfs2/sufile.c +++ b/fs/nilfs2/sufile.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * | 19 | * |
20 | * Written by Koji Sato <koji@osrg.net>. | 20 | * Written by Koji Sato <koji@osrg.net>. |
21 | * Rivised by Ryusuke Konishi <ryusuke@osrg.net>. | ||
21 | */ | 22 | */ |
22 | 23 | ||
23 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
@@ -108,6 +109,102 @@ static void nilfs_sufile_mod_counter(struct buffer_head *header_bh, | |||
108 | nilfs_mdt_mark_buffer_dirty(header_bh); | 109 | nilfs_mdt_mark_buffer_dirty(header_bh); |
109 | } | 110 | } |
110 | 111 | ||
112 | /** | ||
113 | * nilfs_sufile_updatev - modify multiple segment usages at a time | ||
114 | * @sufile: inode of segment usage file | ||
115 | * @segnumv: array of segment numbers | ||
116 | * @nsegs: size of @segnumv array | ||
117 | * @create: creation flag | ||
118 | * @ndone: place to store number of modified segments on @segnumv | ||
119 | * @dofunc: primitive operation for the update | ||
120 | * | ||
121 | * Description: nilfs_sufile_updatev() repeatedly calls @dofunc | ||
122 | * against the given array of segments. The @dofunc is called with | ||
123 | * buffers of a header block and the sufile block in which the target | ||
124 | * segment usage entry is contained. If @ndone is given, the number | ||
125 | * of successfully modified segments from the head is stored in the | ||
126 | * place @ndone points to. | ||
127 | * | ||
128 | * Return Value: On success, zero is returned. On error, one of the | ||
129 | * following negative error codes is returned. | ||
130 | * | ||
131 | * %-EIO - I/O error. | ||
132 | * | ||
133 | * %-ENOMEM - Insufficient amount of memory available. | ||
134 | * | ||
135 | * %-ENOENT - Given segment usage is in hole block (may be returned if | ||
136 | * @create is zero) | ||
137 | * | ||
138 | * %-EINVAL - Invalid segment usage number | ||
139 | */ | ||
140 | int nilfs_sufile_updatev(struct inode *sufile, __u64 *segnumv, size_t nsegs, | ||
141 | int create, size_t *ndone, | ||
142 | void (*dofunc)(struct inode *, __u64, | ||
143 | struct buffer_head *, | ||
144 | struct buffer_head *)) | ||
145 | { | ||
146 | struct buffer_head *header_bh, *bh; | ||
147 | unsigned long blkoff, prev_blkoff; | ||
148 | __u64 *seg; | ||
149 | size_t nerr = 0, n = 0; | ||
150 | int ret = 0; | ||
151 | |||
152 | if (unlikely(nsegs == 0)) | ||
153 | goto out; | ||
154 | |||
155 | down_write(&NILFS_MDT(sufile)->mi_sem); | ||
156 | for (seg = segnumv; seg < segnumv + nsegs; seg++) { | ||
157 | if (unlikely(*seg >= nilfs_sufile_get_nsegments(sufile))) { | ||
158 | printk(KERN_WARNING | ||
159 | "%s: invalid segment number: %llu\n", __func__, | ||
160 | (unsigned long long)*seg); | ||
161 | nerr++; | ||
162 | } | ||
163 | } | ||
164 | if (nerr > 0) { | ||
165 | ret = -EINVAL; | ||
166 | goto out_sem; | ||
167 | } | ||
168 | |||
169 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | ||
170 | if (ret < 0) | ||
171 | goto out_sem; | ||
172 | |||
173 | seg = segnumv; | ||
174 | blkoff = nilfs_sufile_get_blkoff(sufile, *seg); | ||
175 | ret = nilfs_mdt_get_block(sufile, blkoff, create, NULL, &bh); | ||
176 | if (ret < 0) | ||
177 | goto out_header; | ||
178 | |||
179 | for (;;) { | ||
180 | dofunc(sufile, *seg, header_bh, bh); | ||
181 | |||
182 | if (++seg >= segnumv + nsegs) | ||
183 | break; | ||
184 | prev_blkoff = blkoff; | ||
185 | blkoff = nilfs_sufile_get_blkoff(sufile, *seg); | ||
186 | if (blkoff == prev_blkoff) | ||
187 | continue; | ||
188 | |||
189 | /* get different block */ | ||
190 | brelse(bh); | ||
191 | ret = nilfs_mdt_get_block(sufile, blkoff, create, NULL, &bh); | ||
192 | if (unlikely(ret < 0)) | ||
193 | goto out_header; | ||
194 | } | ||
195 | brelse(bh); | ||
196 | |||
197 | out_header: | ||
198 | n = seg - segnumv; | ||
199 | brelse(header_bh); | ||
200 | out_sem: | ||
201 | up_write(&NILFS_MDT(sufile)->mi_sem); | ||
202 | out: | ||
203 | if (ndone) | ||
204 | *ndone = n; | ||
205 | return ret; | ||
206 | } | ||
207 | |||
111 | int nilfs_sufile_update(struct inode *sufile, __u64 segnum, int create, | 208 | int nilfs_sufile_update(struct inode *sufile, __u64 segnum, int create, |
112 | void (*dofunc)(struct inode *, __u64, | 209 | void (*dofunc)(struct inode *, __u64, |
113 | struct buffer_head *, | 210 | struct buffer_head *, |
@@ -490,7 +587,8 @@ void nilfs_sufile_do_set_error(struct inode *sufile, __u64 segnum, | |||
490 | * nilfs_sufile_get_suinfo - | 587 | * nilfs_sufile_get_suinfo - |
491 | * @sufile: inode of segment usage file | 588 | * @sufile: inode of segment usage file |
492 | * @segnum: segment number to start looking | 589 | * @segnum: segment number to start looking |
493 | * @si: array of suinfo | 590 | * @buf: array of suinfo |
591 | * @sisz: byte size of suinfo | ||
494 | * @nsi: size of suinfo array | 592 | * @nsi: size of suinfo array |
495 | * | 593 | * |
496 | * Description: | 594 | * Description: |
@@ -502,11 +600,12 @@ void nilfs_sufile_do_set_error(struct inode *sufile, __u64 segnum, | |||
502 | * | 600 | * |
503 | * %-ENOMEM - Insufficient amount of memory available. | 601 | * %-ENOMEM - Insufficient amount of memory available. |
504 | */ | 602 | */ |
505 | ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, | 603 | ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf, |
506 | struct nilfs_suinfo *si, size_t nsi) | 604 | unsigned sisz, size_t nsi) |
507 | { | 605 | { |
508 | struct buffer_head *su_bh; | 606 | struct buffer_head *su_bh; |
509 | struct nilfs_segment_usage *su; | 607 | struct nilfs_segment_usage *su; |
608 | struct nilfs_suinfo *si = buf; | ||
510 | size_t susz = NILFS_MDT(sufile)->mi_entry_size; | 609 | size_t susz = NILFS_MDT(sufile)->mi_entry_size; |
511 | struct the_nilfs *nilfs = NILFS_MDT(sufile)->mi_nilfs; | 610 | struct the_nilfs *nilfs = NILFS_MDT(sufile)->mi_nilfs; |
512 | void *kaddr; | 611 | void *kaddr; |
@@ -531,20 +630,22 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, | |||
531 | if (ret != -ENOENT) | 630 | if (ret != -ENOENT) |
532 | goto out; | 631 | goto out; |
533 | /* hole */ | 632 | /* hole */ |
534 | memset(&si[i], 0, sizeof(struct nilfs_suinfo) * n); | 633 | memset(si, 0, sisz * n); |
634 | si = (void *)si + sisz * n; | ||
535 | continue; | 635 | continue; |
536 | } | 636 | } |
537 | 637 | ||
538 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); | 638 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); |
539 | su = nilfs_sufile_block_get_segment_usage( | 639 | su = nilfs_sufile_block_get_segment_usage( |
540 | sufile, segnum, su_bh, kaddr); | 640 | sufile, segnum, su_bh, kaddr); |
541 | for (j = 0; j < n; j++, su = (void *)su + susz) { | 641 | for (j = 0; j < n; |
542 | si[i + j].sui_lastmod = le64_to_cpu(su->su_lastmod); | 642 | j++, su = (void *)su + susz, si = (void *)si + sisz) { |
543 | si[i + j].sui_nblocks = le32_to_cpu(su->su_nblocks); | 643 | si->sui_lastmod = le64_to_cpu(su->su_lastmod); |
544 | si[i + j].sui_flags = le32_to_cpu(su->su_flags) & | 644 | si->sui_nblocks = le32_to_cpu(su->su_nblocks); |
645 | si->sui_flags = le32_to_cpu(su->su_flags) & | ||
545 | ~(1UL << NILFS_SEGMENT_USAGE_ACTIVE); | 646 | ~(1UL << NILFS_SEGMENT_USAGE_ACTIVE); |
546 | if (nilfs_segment_is_active(nilfs, segnum + j)) | 647 | if (nilfs_segment_is_active(nilfs, segnum + j)) |
547 | si[i + j].sui_flags |= | 648 | si->sui_flags |= |
548 | (1UL << NILFS_SEGMENT_USAGE_ACTIVE); | 649 | (1UL << NILFS_SEGMENT_USAGE_ACTIVE); |
549 | } | 650 | } |
550 | kunmap_atomic(kaddr, KM_USER0); | 651 | kunmap_atomic(kaddr, KM_USER0); |