Skip to content

Commit 9fb2cfa

Browse files
committed
Merge tag 'pull-ufs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull ufs updates from Al Viro: "ufs cleanups, fixes and folio conversion" * tag 'pull-ufs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: ufs: ufs_sb_private_info: remove unused s_{2,3}apb fields ufs: Convert ufs_change_blocknr() to take a folio ufs: Pass a folio to ufs_new_fragments() ufs: Convert ufs_inode_getfrag() to take a folio ufs: Convert ufs_extend_tail() to take a folio ufs: Convert ufs_inode_getblock() to take a folio ufs: take the handling of free block counters into a helper clean ufs_trunc_direct() up a bit... ufs: get rid of ubh_{ubhcpymem,memcpyubh}() ufs_inode_getfrag(): remove junk comment ufs_free_fragments(): fix the braino in sanity check ufs_clusteracct(): switch to passing fragment number ufs: untangle ubh_...block...(), part 3 ufs: untangle ubh_...block...(), part 2 ufs: untangle ubh_...block...() macros, part 1 ufs: fix ufs_read_cylinder() failure handling ufs: missing ->splice_write() ufs: fix handling of delete_entry and set_link failures
2 parents 82339c4 + 6cfe56f commit 9fb2cfa

File tree

11 files changed

+222
-336
lines changed

11 files changed

+222
-336
lines changed

fs/ufs/balloc.c

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ static u64 ufs_bitmap_search (struct super_block *, struct ufs_cg_private_info *
3333
static unsigned char ufs_fragtable_8fpb[], ufs_fragtable_other[];
3434
static void ufs_clusteracct(struct super_block *, struct ufs_cg_private_info *, unsigned, int);
3535

36+
static void adjust_free_blocks(struct super_block *sb,
37+
struct ufs_cylinder_group *ucg,
38+
struct ufs_cg_private_info *ucpi,
39+
unsigned fragment, int delta)
40+
{
41+
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
42+
43+
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
44+
ufs_clusteracct(sb, ucpi, fragment, delta);
45+
46+
fs32_add(sb, &ucg->cg_cs.cs_nbfree, delta);
47+
uspi->cs_total.cs_nbfree += delta;
48+
fs32_add(sb, &UFS_SB(sb)->fs_cs(ucpi->c_cgx).cs_nbfree, delta);
49+
50+
if (uspi->fs_magic != UFS2_MAGIC) {
51+
unsigned cylno = ufs_cbtocylno(fragment);
52+
53+
fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
54+
ufs_cbtorpos(fragment)), delta);
55+
fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), delta);
56+
}
57+
}
58+
3659
/*
3760
* Free 'count' fragments from fragment number 'fragment'
3861
*/
@@ -43,15 +66,14 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
4366
struct ufs_cg_private_info * ucpi;
4467
struct ufs_cylinder_group * ucg;
4568
unsigned cgno, bit, end_bit, bbase, blkmap, i;
46-
u64 blkno;
4769

4870
sb = inode->i_sb;
4971
uspi = UFS_SB(sb)->s_uspi;
5072

5173
UFSD("ENTER, fragment %llu, count %u\n",
5274
(unsigned long long)fragment, count);
5375

54-
if (ufs_fragnum(fragment) + count > uspi->s_fpg)
76+
if (ufs_fragnum(fragment) + count > uspi->s_fpb)
5577
ufs_error (sb, "ufs_free_fragments", "internal error");
5678

5779
mutex_lock(&UFS_SB(sb)->s_lock);
@@ -94,23 +116,11 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
94116
/*
95117
* Trying to reassemble free fragments into block
96118
*/
97-
blkno = ufs_fragstoblks (bbase);
98-
if (ubh_isblockset(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno)) {
119+
if (ubh_isblockset(uspi, ucpi, bbase)) {
99120
fs32_sub(sb, &ucg->cg_cs.cs_nffree, uspi->s_fpb);
100121
uspi->cs_total.cs_nffree -= uspi->s_fpb;
101122
fs32_sub(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, uspi->s_fpb);
102-
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
103-
ufs_clusteracct (sb, ucpi, blkno, 1);
104-
fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
105-
uspi->cs_total.cs_nbfree++;
106-
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1);
107-
if (uspi->fs_magic != UFS2_MAGIC) {
108-
unsigned cylno = ufs_cbtocylno (bbase);
109-
110-
fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
111-
ufs_cbtorpos(bbase)), 1);
112-
fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1);
113-
}
123+
adjust_free_blocks(sb, ucg, ucpi, bbase, 1);
114124
}
115125

116126
ubh_mark_buffer_dirty (USPI_UBH(uspi));
@@ -139,7 +149,6 @@ void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
139149
struct ufs_cg_private_info * ucpi;
140150
struct ufs_cylinder_group * ucg;
141151
unsigned overflow, cgno, bit, end_bit, i;
142-
u64 blkno;
143152

144153
sb = inode->i_sb;
145154
uspi = UFS_SB(sb)->s_uspi;
@@ -181,26 +190,12 @@ void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
181190
}
182191

183192
for (i = bit; i < end_bit; i += uspi->s_fpb) {
184-
blkno = ufs_fragstoblks(i);
185-
if (ubh_isblockset(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno)) {
193+
if (ubh_isblockset(uspi, ucpi, i)) {
186194
ufs_error(sb, "ufs_free_blocks", "freeing free fragment");
187195
}
188-
ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
196+
ubh_setblock(uspi, ucpi, i);
189197
inode_sub_bytes(inode, uspi->s_fpb << uspi->s_fshift);
190-
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
191-
ufs_clusteracct (sb, ucpi, blkno, 1);
192-
193-
fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
194-
uspi->cs_total.cs_nbfree++;
195-
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1);
196-
197-
if (uspi->fs_magic != UFS2_MAGIC) {
198-
unsigned cylno = ufs_cbtocylno(i);
199-
200-
fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
201-
ufs_cbtorpos(i)), 1);
202-
fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1);
203-
}
198+
adjust_free_blocks(sb, ucg, ucpi, i, 1);
204199
}
205200

206201
ubh_mark_buffer_dirty (USPI_UBH(uspi));
@@ -234,13 +229,13 @@ void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
234229
* situated at the end of file.
235230
*
236231
* We can come here from ufs_writepage or ufs_prepare_write,
237-
* locked_page is argument of these functions, so we already lock it.
232+
* locked_folio is argument of these functions, so we already lock it.
238233
*/
239234
static void ufs_change_blocknr(struct inode *inode, sector_t beg,
240235
unsigned int count, sector_t oldb,
241-
sector_t newb, struct page *locked_page)
236+
sector_t newb, struct folio *locked_folio)
242237
{
243-
struct folio *folio, *locked_folio = page_folio(locked_page);
238+
struct folio *folio;
244239
const unsigned blks_per_page =
245240
1 << (PAGE_SHIFT - inode->i_blkbits);
246241
const unsigned mask = blks_per_page - 1;
@@ -337,7 +332,7 @@ static void ufs_clear_frags(struct inode *inode, sector_t beg, unsigned int n,
337332

338333
u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
339334
u64 goal, unsigned count, int *err,
340-
struct page *locked_page)
335+
struct folio *locked_folio)
341336
{
342337
struct super_block * sb;
343338
struct ufs_sb_private_info * uspi;
@@ -417,7 +412,7 @@ u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
417412
result = ufs_alloc_fragments (inode, cgno, goal, count, err);
418413
if (result) {
419414
ufs_clear_frags(inode, result + oldcount,
420-
newcount - oldcount, locked_page != NULL);
415+
newcount - oldcount, locked_folio != NULL);
421416
*err = 0;
422417
write_seqlock(&UFS_I(inode)->meta_lock);
423418
ufs_cpu_to_data_ptr(sb, p, result);
@@ -441,7 +436,7 @@ u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
441436
fragment + count);
442437
read_sequnlock_excl(&UFS_I(inode)->meta_lock);
443438
ufs_clear_frags(inode, result + oldcount, newcount - oldcount,
444-
locked_page != NULL);
439+
locked_folio != NULL);
445440
mutex_unlock(&UFS_SB(sb)->s_lock);
446441
UFSD("EXIT, result %llu\n", (unsigned long long)result);
447442
return result;
@@ -462,11 +457,11 @@ u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
462457
result = ufs_alloc_fragments (inode, cgno, goal, request, err);
463458
if (result) {
464459
ufs_clear_frags(inode, result + oldcount, newcount - oldcount,
465-
locked_page != NULL);
460+
locked_folio != NULL);
466461
mutex_unlock(&UFS_SB(sb)->s_lock);
467462
ufs_change_blocknr(inode, fragment - oldcount, oldcount,
468463
uspi->s_sbbase + tmp,
469-
uspi->s_sbbase + result, locked_page);
464+
uspi->s_sbbase + result, locked_folio);
470465
*err = 0;
471466
write_seqlock(&UFS_I(inode)->meta_lock);
472467
ufs_cpu_to_data_ptr(sb, p, result);
@@ -698,7 +693,7 @@ static u64 ufs_alloccg_block(struct inode *inode,
698693
struct super_block * sb;
699694
struct ufs_sb_private_info * uspi;
700695
struct ufs_cylinder_group * ucg;
701-
u64 result, blkno;
696+
u64 result;
702697

703698
UFSD("ENTER, goal %llu\n", (unsigned long long)goal);
704699

@@ -716,7 +711,7 @@ static u64 ufs_alloccg_block(struct inode *inode,
716711
/*
717712
* If the requested block is available, use it.
718713
*/
719-
if (ubh_isblockset(UCPI_UBH(ucpi), ucpi->c_freeoff, ufs_fragstoblks(goal))) {
714+
if (ubh_isblockset(uspi, ucpi, goal)) {
720715
result = goal;
721716
goto gotit;
722717
}
@@ -729,22 +724,8 @@ static u64 ufs_alloccg_block(struct inode *inode,
729724
gotit:
730725
if (!try_add_frags(inode, uspi->s_fpb))
731726
return 0;
732-
blkno = ufs_fragstoblks(result);
733-
ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
734-
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
735-
ufs_clusteracct (sb, ucpi, blkno, -1);
736-
737-
fs32_sub(sb, &ucg->cg_cs.cs_nbfree, 1);
738-
uspi->cs_total.cs_nbfree--;
739-
fs32_sub(sb, &UFS_SB(sb)->fs_cs(ucpi->c_cgx).cs_nbfree, 1);
740-
741-
if (uspi->fs_magic != UFS2_MAGIC) {
742-
unsigned cylno = ufs_cbtocylno((unsigned)result);
743-
744-
fs16_sub(sb, &ubh_cg_blks(ucpi, cylno,
745-
ufs_cbtorpos((unsigned)result)), 1);
746-
fs32_sub(sb, &ubh_cg_blktot(ucpi, cylno), 1);
747-
}
727+
ubh_clrblock(uspi, ucpi, result);
728+
adjust_free_blocks(sb, ucg, ucpi, result, -1);
748729

749730
UFSD("EXIT, result %llu\n", (unsigned long long)result);
750731

@@ -863,12 +844,12 @@ static u64 ufs_bitmap_search(struct super_block *sb,
863844
}
864845

865846
static void ufs_clusteracct(struct super_block * sb,
866-
struct ufs_cg_private_info * ucpi, unsigned blkno, int cnt)
847+
struct ufs_cg_private_info * ucpi, unsigned frag, int cnt)
867848
{
868-
struct ufs_sb_private_info * uspi;
849+
struct ufs_sb_private_info * uspi = UFS_SB(sb)->s_uspi;
869850
int i, start, end, forw, back;
851+
unsigned blkno = ufs_fragstoblks(frag);
870852

871-
uspi = UFS_SB(sb)->s_uspi;
872853
if (uspi->s_contigsumsize <= 0)
873854
return;
874855

fs/ufs/cylinder.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Read cylinder group into cache. The memory space for ufs_cg_private_info
2727
* structure is already allocated during ufs_read_super.
2828
*/
29-
static void ufs_read_cylinder (struct super_block * sb,
29+
static bool ufs_read_cylinder(struct super_block *sb,
3030
unsigned cgno, unsigned bitmap_nr)
3131
{
3232
struct ufs_sb_info * sbi = UFS_SB(sb);
@@ -46,9 +46,11 @@ static void ufs_read_cylinder (struct super_block * sb,
4646
* We have already the first fragment of cylinder group block in buffer
4747
*/
4848
UCPI_UBH(ucpi)->bh[0] = sbi->s_ucg[cgno];
49-
for (i = 1; i < UCPI_UBH(ucpi)->count; i++)
50-
if (!(UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i)))
49+
for (i = 1; i < UCPI_UBH(ucpi)->count; i++) {
50+
UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i);
51+
if (!UCPI_UBH(ucpi)->bh[i])
5152
goto failed;
53+
}
5254
sbi->s_cgno[bitmap_nr] = cgno;
5355

5456
ucpi->c_cgx = fs32_to_cpu(sb, ucg->cg_cgx);
@@ -67,13 +69,14 @@ static void ufs_read_cylinder (struct super_block * sb,
6769
ucpi->c_clusteroff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clusteroff);
6870
ucpi->c_nclusterblks = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_nclusterblks);
6971
UFSD("EXIT\n");
70-
return;
72+
return true;
7173

7274
failed:
7375
for (j = 1; j < i; j++)
74-
brelse (sbi->s_ucg[j]);
76+
brelse(UCPI_UBH(ucpi)->bh[j]);
7577
sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY;
7678
ufs_error (sb, "ufs_read_cylinder", "can't read cylinder group block %u", cgno);
79+
return false;
7780
}
7881

7982
/*
@@ -156,15 +159,14 @@ struct ufs_cg_private_info * ufs_load_cylinder (
156159
UFSD("EXIT (FAILED)\n");
157160
return NULL;
158161
}
159-
else {
160-
UFSD("EXIT\n");
161-
return sbi->s_ucpi[cgno];
162-
}
163162
} else {
164-
ufs_read_cylinder (sb, cgno, cgno);
165-
UFSD("EXIT\n");
166-
return sbi->s_ucpi[cgno];
163+
if (unlikely(!ufs_read_cylinder (sb, cgno, cgno))) {
164+
UFSD("EXIT (FAILED)\n");
165+
return NULL;
166+
}
167167
}
168+
UFSD("EXIT\n");
169+
return sbi->s_ucpi[cgno];
168170
}
169171
/*
170172
* Cylinder group number cg is in cache but it was not last used,
@@ -195,7 +197,10 @@ struct ufs_cg_private_info * ufs_load_cylinder (
195197
sbi->s_ucpi[j] = sbi->s_ucpi[j-1];
196198
}
197199
sbi->s_ucpi[0] = ucpi;
198-
ufs_read_cylinder (sb, cgno, 0);
200+
if (unlikely(!ufs_read_cylinder (sb, cgno, 0))) {
201+
UFSD("EXIT (FAILED)\n");
202+
return NULL;
203+
}
199204
}
200205
UFSD("EXIT\n");
201206
return sbi->s_ucpi[0];

fs/ufs/dir.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,29 @@ ino_t ufs_inode_by_name(struct inode *dir, const struct qstr *qstr)
8181
}
8282

8383

84-
/* Releases the page */
85-
void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de,
86-
struct folio *folio, struct inode *inode,
87-
bool update_times)
84+
int ufs_set_link(struct inode *dir, struct ufs_dir_entry *de,
85+
struct folio *folio, struct inode *inode,
86+
bool update_times)
8887
{
8988
loff_t pos = folio_pos(folio) + offset_in_folio(folio, de);
9089
unsigned len = fs16_to_cpu(dir->i_sb, de->d_reclen);
9190
int err;
9291

9392
folio_lock(folio);
9493
err = ufs_prepare_chunk(folio, pos, len);
95-
BUG_ON(err);
94+
if (unlikely(err)) {
95+
folio_unlock(folio);
96+
return err;
97+
}
9698

9799
de->d_ino = cpu_to_fs32(dir->i_sb, inode->i_ino);
98100
ufs_set_de_type(dir->i_sb, de, inode->i_mode);
99101

100102
ufs_commit_chunk(folio, pos, len);
101-
folio_release_kmap(folio, de);
102103
if (update_times)
103104
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
104105
mark_inode_dirty(dir);
105-
ufs_handle_dirsync(dir);
106+
return ufs_handle_dirsync(dir);
106107
}
107108

108109
static bool ufs_check_folio(struct folio *folio, char *kaddr)
@@ -505,8 +506,7 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
505506
if (de->d_reclen == 0) {
506507
ufs_error(inode->i_sb, __func__,
507508
"zero-length directory entry");
508-
err = -EIO;
509-
goto out;
509+
return -EIO;
510510
}
511511
pde = de;
512512
de = ufs_next_entry(sb, de);
@@ -516,18 +516,17 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
516516
pos = folio_pos(folio) + from;
517517
folio_lock(folio);
518518
err = ufs_prepare_chunk(folio, pos, to - from);
519-
BUG_ON(err);
519+
if (unlikely(err)) {
520+
folio_unlock(folio);
521+
return err;
522+
}
520523
if (pde)
521524
pde->d_reclen = cpu_to_fs16(sb, to - from);
522525
dir->d_ino = 0;
523526
ufs_commit_chunk(folio, pos, to - from);
524527
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
525528
mark_inode_dirty(inode);
526-
err = ufs_handle_dirsync(inode);
527-
out:
528-
folio_release_kmap(folio, kaddr);
529-
UFSD("EXIT\n");
530-
return err;
529+
return ufs_handle_dirsync(inode);
531530
}
532531

533532
int ufs_make_empty(struct inode * inode, struct inode *dir)

fs/ufs/file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ const struct file_operations ufs_file_operations = {
4242
.open = generic_file_open,
4343
.fsync = generic_file_fsync,
4444
.splice_read = filemap_splice_read,
45+
.splice_write = iter_file_splice_write,
4546
};

0 commit comments

Comments
 (0)