• Home
  • Raw
  • Download

Lines Matching +full:nc +full:- +full:si

1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
22 * struct nilfs_sufile_info - on-memory private data of sufile
23 * @mi: on-memory private data of metadata file
43 return NILFS_MDT(sufile)->mi_entries_per_block; in nilfs_sufile_segment_usages_per_block()
49 __u64 t = segnum + NILFS_MDT(sufile)->mi_first_entry_offset; in nilfs_sufile_get_blkoff()
58 __u64 t = segnum + NILFS_MDT(sufile)->mi_first_entry_offset; in nilfs_sufile_get_offset()
68 nilfs_sufile_segment_usages_per_block(sufile) - in nilfs_sufile_segment_usages_in_block()
70 max - curr + 1); in nilfs_sufile_segment_usages_in_block()
79 NILFS_MDT(sufile)->mi_entry_size; in nilfs_sufile_block_get_segment_usage()
110 kaddr = kmap_atomic(header_bh->b_page); in nilfs_sufile_mod_counter()
112 le64_add_cpu(&header->sh_ncleansegs, ncleanadd); in nilfs_sufile_mod_counter()
113 le64_add_cpu(&header->sh_ndirtysegs, ndirtyadd); in nilfs_sufile_mod_counter()
120 * nilfs_sufile_get_ncleansegs - return the number of clean segments
125 return NILFS_SUI(sufile)->ncleansegs; in nilfs_sufile_get_ncleansegs()
129 * nilfs_sufile_updatev - modify multiple segment usages at a time
147 * %-EIO - I/O error.
149 * %-ENOMEM - Insufficient amount of memory available.
151 * %-ENOENT - Given segment usage is in hole block (may be returned if
154 * %-EINVAL - Invalid segment usage number
171 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_updatev()
174 nilfs_warn(sufile->i_sb, in nilfs_sufile_updatev()
181 ret = -EINVAL; in nilfs_sufile_updatev()
214 n = seg - segnumv; in nilfs_sufile_updatev()
217 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_updatev()
233 nilfs_warn(sufile->i_sb, "%s: invalid segment number: %llu", in nilfs_sufile_update()
235 return -EINVAL; in nilfs_sufile_update()
237 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_update()
251 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_update()
256 * nilfs_sufile_set_alloc_range - limit range of segment to be allocated
264 * %-ERANGE - invalid segment region
270 int ret = -ERANGE; in nilfs_sufile_set_alloc_range()
272 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_set_alloc_range()
276 sui->allocmin = start; in nilfs_sufile_set_alloc_range()
277 sui->allocmax = end; in nilfs_sufile_set_alloc_range()
280 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_set_alloc_range()
285 * nilfs_sufile_alloc - allocate a segment
295 * %-EIO - I/O error.
297 * %-ENOMEM - Insufficient amount of memory available.
299 * %-ENOSPC - No clean segment left.
307 size_t susz = NILFS_MDT(sufile)->mi_entry_size; in nilfs_sufile_alloc()
313 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_alloc()
318 kaddr = kmap_atomic(header_bh->b_page); in nilfs_sufile_alloc()
320 last_alloc = le64_to_cpu(header->sh_last_alloc); in nilfs_sufile_alloc()
324 maxsegnum = sui->allocmax; in nilfs_sufile_alloc()
326 if (segnum < sui->allocmin || segnum > sui->allocmax) in nilfs_sufile_alloc()
327 segnum = sui->allocmin; in nilfs_sufile_alloc()
331 if (cnt < sui->allocmax - sui->allocmin + 1) { in nilfs_sufile_alloc()
335 * sui->allocmin, this never happens. in nilfs_sufile_alloc()
337 segnum = sui->allocmin; in nilfs_sufile_alloc()
339 } else if (segnum > sui->allocmin && in nilfs_sufile_alloc()
340 sui->allocmax + 1 < nsegments) { in nilfs_sufile_alloc()
341 segnum = sui->allocmax + 1; in nilfs_sufile_alloc()
342 maxsegnum = nsegments - 1; in nilfs_sufile_alloc()
343 } else if (sui->allocmin > 0) { in nilfs_sufile_alloc()
345 maxsegnum = sui->allocmin - 1; in nilfs_sufile_alloc()
355 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_alloc()
368 kaddr = kmap_atomic(header_bh->b_page); in nilfs_sufile_alloc()
370 le64_add_cpu(&header->sh_ncleansegs, -1); in nilfs_sufile_alloc()
371 le64_add_cpu(&header->sh_ndirtysegs, 1); in nilfs_sufile_alloc()
372 header->sh_last_alloc = cpu_to_le64(segnum); in nilfs_sufile_alloc()
375 sui->ncleansegs--; in nilfs_sufile_alloc()
392 ret = -ENOSPC; in nilfs_sufile_alloc()
398 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_alloc()
409 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_do_cancel_free()
412 nilfs_warn(sufile->i_sb, "%s: segment %llu must be clean", in nilfs_sufile_do_cancel_free()
420 nilfs_sufile_mod_counter(header_bh, -1, 1); in nilfs_sufile_do_cancel_free()
421 NILFS_SUI(sufile)->ncleansegs--; in nilfs_sufile_do_cancel_free()
435 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_do_scrap()
437 if (su->su_flags == cpu_to_le32(BIT(NILFS_SEGMENT_USAGE_DIRTY)) && in nilfs_sufile_do_scrap()
438 su->su_nblocks == cpu_to_le32(0)) { in nilfs_sufile_do_scrap()
446 su->su_lastmod = cpu_to_le64(0); in nilfs_sufile_do_scrap()
447 su->su_nblocks = cpu_to_le32(0); in nilfs_sufile_do_scrap()
448 su->su_flags = cpu_to_le32(BIT(NILFS_SEGMENT_USAGE_DIRTY)); in nilfs_sufile_do_scrap()
451 nilfs_sufile_mod_counter(header_bh, clean ? (u64)-1 : 0, dirty ? 0 : 1); in nilfs_sufile_do_scrap()
452 NILFS_SUI(sufile)->ncleansegs -= clean; in nilfs_sufile_do_scrap()
466 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_do_free()
469 nilfs_warn(sufile->i_sb, "%s: segment %llu is already clean", in nilfs_sufile_do_free()
482 nilfs_sufile_mod_counter(header_bh, 1, sudirty ? (u64)-1 : 0); in nilfs_sufile_do_free()
483 NILFS_SUI(sufile)->ncleansegs++; in nilfs_sufile_do_free()
491 * nilfs_sufile_mark_dirty - mark the buffer having a segment usage dirty
502 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_mark_dirty()
507 kaddr = kmap_atomic(bh->b_page); in nilfs_sufile_mark_dirty()
510 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_mark_dirty()
515 nilfs_error(sufile->i_sb, in nilfs_sufile_mark_dirty()
527 ret = -EIO; in nilfs_sufile_mark_dirty()
536 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_mark_dirty()
541 * nilfs_sufile_set_segment_usage - set usage of a segment
555 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_set_segment_usage()
560 kaddr = kmap_atomic(bh->b_page); in nilfs_sufile_set_segment_usage()
568 su->su_lastmod = cpu_to_le64(modtime); in nilfs_sufile_set_segment_usage()
570 su->su_nblocks = cpu_to_le32(nblocks); in nilfs_sufile_set_segment_usage()
578 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_set_segment_usage()
583 * nilfs_sufile_get_stat - get segment usage statistics
594 * %-EIO - I/O error.
596 * %-ENOMEM - Insufficient amount of memory available.
602 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_get_stat()
606 down_read(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_get_stat()
612 kaddr = kmap_atomic(header_bh->b_page); in nilfs_sufile_get_stat()
614 sustat->ss_nsegs = nilfs_sufile_get_nsegments(sufile); in nilfs_sufile_get_stat()
615 sustat->ss_ncleansegs = le64_to_cpu(header->sh_ncleansegs); in nilfs_sufile_get_stat()
616 sustat->ss_ndirtysegs = le64_to_cpu(header->sh_ndirtysegs); in nilfs_sufile_get_stat()
617 sustat->ss_ctime = nilfs->ns_ctime; in nilfs_sufile_get_stat()
618 sustat->ss_nongc_ctime = nilfs->ns_nongc_ctime; in nilfs_sufile_get_stat()
619 spin_lock(&nilfs->ns_last_segment_lock); in nilfs_sufile_get_stat()
620 sustat->ss_prot_seq = nilfs->ns_prot_seq; in nilfs_sufile_get_stat()
621 spin_unlock(&nilfs->ns_last_segment_lock); in nilfs_sufile_get_stat()
626 up_read(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_get_stat()
638 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_do_set_error()
649 nilfs_sufile_mod_counter(header_bh, -1, 0); in nilfs_sufile_do_set_error()
650 NILFS_SUI(sufile)->ncleansegs--; in nilfs_sufile_do_set_error()
657 * nilfs_sufile_truncate_range - truncate range of segment array
665 * %-EIO - I/O error.
667 * %-ENOMEM - Insufficient amount of memory available.
669 * %-EINVAL - Invalid number of segments specified
671 * %-EBUSY - Dirty or active segments are present in the range
676 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_truncate_range()
680 size_t susz = NILFS_MDT(sufile)->mi_entry_size; in nilfs_sufile_truncate_range()
685 ssize_t n, nc; in nilfs_sufile_truncate_range() local
691 ret = -EINVAL; in nilfs_sufile_truncate_range()
704 segusages_per_block - in nilfs_sufile_truncate_range()
706 end - segnum + 1); in nilfs_sufile_truncate_range()
710 if (ret != -ENOENT) in nilfs_sufile_truncate_range()
715 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_truncate_range()
720 if ((le32_to_cpu(su->su_flags) & in nilfs_sufile_truncate_range()
723 ret = -EBUSY; in nilfs_sufile_truncate_range()
729 nc = 0; in nilfs_sufile_truncate_range()
733 nc++; in nilfs_sufile_truncate_range()
737 if (nc > 0) { in nilfs_sufile_truncate_range()
739 ncleaned += nc; in nilfs_sufile_truncate_range()
752 NILFS_SUI(sufile)->ncleansegs += ncleaned; in nilfs_sufile_truncate_range()
762 * nilfs_sufile_resize - resize segment array
769 * %-EIO - I/O error.
771 * %-ENOMEM - Insufficient amount of memory available.
773 * %-ENOSPC - Enough free space is not left for shrinking
775 * %-EBUSY - Dirty or active segments exist in the region to be truncated
779 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_resize()
787 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_resize()
793 ret = -ENOSPC; in nilfs_sufile_resize()
795 if (newnsegs < nsegs && nsegs - newnsegs + nrsvsegs > sui->ncleansegs) in nilfs_sufile_resize()
803 sui->ncleansegs += newnsegs - nsegs; in nilfs_sufile_resize()
805 ret = nilfs_sufile_truncate_range(sufile, newnsegs, nsegs - 1); in nilfs_sufile_resize()
809 sui->ncleansegs -= nsegs - newnsegs; in nilfs_sufile_resize()
817 sui->allocmax = newnsegs - 1; in nilfs_sufile_resize()
818 sui->allocmin = 0; in nilfs_sufile_resize()
821 kaddr = kmap_atomic(header_bh->b_page); in nilfs_sufile_resize()
823 header->sh_ncleansegs = cpu_to_le64(sui->ncleansegs); in nilfs_sufile_resize()
833 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_resize()
838 * nilfs_sufile_get_suinfo -
850 * %-EIO - I/O error.
852 * %-ENOMEM - Insufficient amount of memory available.
859 struct nilfs_suinfo *si = buf; in nilfs_sufile_get_suinfo() local
860 size_t susz = NILFS_MDT(sufile)->mi_entry_size; in nilfs_sufile_get_suinfo()
861 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_get_suinfo()
867 down_read(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_get_suinfo()
871 nilfs_sufile_get_nsegments(sufile) - segnum, in nilfs_sufile_get_suinfo()
875 segusages_per_block - in nilfs_sufile_get_suinfo()
877 nsegs - i); in nilfs_sufile_get_suinfo()
881 if (ret != -ENOENT) in nilfs_sufile_get_suinfo()
884 memset(si, 0, sisz * n); in nilfs_sufile_get_suinfo()
885 si = (void *)si + sisz * n; in nilfs_sufile_get_suinfo()
889 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_get_suinfo()
893 j++, su = (void *)su + susz, si = (void *)si + sisz) { in nilfs_sufile_get_suinfo()
894 si->sui_lastmod = le64_to_cpu(su->su_lastmod); in nilfs_sufile_get_suinfo()
895 si->sui_nblocks = le32_to_cpu(su->su_nblocks); in nilfs_sufile_get_suinfo()
896 si->sui_flags = le32_to_cpu(su->su_flags) & in nilfs_sufile_get_suinfo()
899 si->sui_flags |= in nilfs_sufile_get_suinfo()
908 up_read(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_get_suinfo()
913 * nilfs_sufile_set_suinfo - sets segment usage info
926 * %-EIO - I/O error.
928 * %-ENOMEM - Insufficient amount of memory available.
930 * %-EINVAL - Invalid values in input (segment number, flags or nblocks)
935 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_set_suinfo()
949 if (sup->sup_segnum >= nilfs->ns_nsegments in nilfs_sufile_set_suinfo()
950 || (sup->sup_flags & in nilfs_sufile_set_suinfo()
953 sup->sup_sui.sui_nblocks > in nilfs_sufile_set_suinfo()
954 nilfs->ns_blocks_per_segment)) in nilfs_sufile_set_suinfo()
955 return -EINVAL; in nilfs_sufile_set_suinfo()
958 down_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_set_suinfo()
965 blkoff = nilfs_sufile_get_blkoff(sufile, sup->sup_segnum); in nilfs_sufile_set_suinfo()
971 kaddr = kmap_atomic(bh->b_page); in nilfs_sufile_set_suinfo()
973 sufile, sup->sup_segnum, bh, kaddr); in nilfs_sufile_set_suinfo()
976 su->su_lastmod = cpu_to_le64(sup->sup_sui.sui_lastmod); in nilfs_sufile_set_suinfo()
979 su->su_nblocks = cpu_to_le32(sup->sup_sui.sui_nblocks); in nilfs_sufile_set_suinfo()
984 * nilfs kernel code - drop it not to write it to in nilfs_sufile_set_suinfo()
987 sup->sup_sui.sui_flags &= in nilfs_sufile_set_suinfo()
990 cleansi = nilfs_suinfo_clean(&sup->sup_sui); in nilfs_sufile_set_suinfo()
992 dirtysi = nilfs_suinfo_dirty(&sup->sup_sui); in nilfs_sufile_set_suinfo()
998 --ncleaned; in nilfs_sufile_set_suinfo()
1003 --ndirtied; in nilfs_sufile_set_suinfo()
1005 su->su_flags = cpu_to_le32(sup->sup_sui.sui_flags); in nilfs_sufile_set_suinfo()
1015 blkoff = nilfs_sufile_get_blkoff(sufile, sup->sup_segnum); in nilfs_sufile_set_suinfo()
1033 NILFS_SUI(sufile)->ncleansegs += ncleaned; in nilfs_sufile_set_suinfo()
1039 up_write(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_set_suinfo()
1044 * nilfs_sufile_trim_fs() - trim ioctl handle function
1061 struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; in nilfs_sufile_trim_fs()
1065 size_t n, i, susz = NILFS_MDT(sufile)->mi_entry_size; in nilfs_sufile_trim_fs()
1072 sects_per_block = (1 << nilfs->ns_blocksize_bits) / in nilfs_sufile_trim_fs()
1073 bdev_logical_block_size(nilfs->ns_bdev); in nilfs_sufile_trim_fs()
1074 len = range->len >> nilfs->ns_blocksize_bits; in nilfs_sufile_trim_fs()
1075 minlen = range->minlen >> nilfs->ns_blocksize_bits; in nilfs_sufile_trim_fs()
1076 max_blocks = ((u64)nilfs->ns_nsegments * nilfs->ns_blocks_per_segment); in nilfs_sufile_trim_fs()
1078 if (!len || range->start >= max_blocks << nilfs->ns_blocksize_bits) in nilfs_sufile_trim_fs()
1079 return -EINVAL; in nilfs_sufile_trim_fs()
1081 start_block = (range->start + nilfs->ns_blocksize - 1) >> in nilfs_sufile_trim_fs()
1082 nilfs->ns_blocksize_bits; in nilfs_sufile_trim_fs()
1085 * range->len can be very large (actually, it is set to in nilfs_sufile_trim_fs()
1086 * ULLONG_MAX by default) - truncate upper end of the range in nilfs_sufile_trim_fs()
1089 if (max_blocks - start_block < len) in nilfs_sufile_trim_fs()
1090 end_block = max_blocks - 1; in nilfs_sufile_trim_fs()
1092 end_block = start_block + len - 1; in nilfs_sufile_trim_fs()
1097 down_read(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_trim_fs()
1106 if (ret != -ENOENT) in nilfs_sufile_trim_fs()
1113 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_trim_fs()
1126 nblocks = seg_end - seg_start + 1; in nilfs_sufile_trim_fs()
1132 nblocks += seg_end - seg_start + 1; in nilfs_sufile_trim_fs()
1138 nblocks -= start_block - start; in nilfs_sufile_trim_fs()
1145 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_sufile_trim_fs()
1155 kaddr = kmap_atomic(su_bh->b_page); in nilfs_sufile_trim_fs()
1162 nblocks = seg_end - seg_start + 1; in nilfs_sufile_trim_fs()
1172 nblocks -= start_block - start; in nilfs_sufile_trim_fs()
1176 nblocks = end_block - start + 1; in nilfs_sufile_trim_fs()
1179 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_sufile_trim_fs()
1189 up_read(&NILFS_MDT(sufile)->mi_sem); in nilfs_sufile_trim_fs()
1191 range->len = ndiscarded << nilfs->ns_blocksize_bits; in nilfs_sufile_trim_fs()
1196 * nilfs_sufile_read - read or get sufile inode
1199 * @raw_inode: on-disk sufile inode
1212 if (susize > sb->s_blocksize) { in nilfs_sufile_read()
1215 return -EINVAL; in nilfs_sufile_read()
1219 return -EINVAL; in nilfs_sufile_read()
1224 return -ENOMEM; in nilfs_sufile_read()
1225 if (!(sufile->i_state & I_NEW)) in nilfs_sufile_read()
1244 kaddr = kmap_atomic(header_bh->b_page); in nilfs_sufile_read()
1246 sui->ncleansegs = le64_to_cpu(header->sh_ncleansegs); in nilfs_sufile_read()
1250 sui->allocmax = nilfs_sufile_get_nsegments(sufile) - 1; in nilfs_sufile_read()
1251 sui->allocmin = 0; in nilfs_sufile_read()