1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/fs.h>
20#include <linux/slab.h>
21#include <linux/blkdev.h>
22
23#include "jfs_incore.h"
24#include "jfs_superblock.h"
25#include "jfs_discard.h"
26#include "jfs_dmap.h"
27#include "jfs_debug.h"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45void jfs_issue_discard(struct inode *ip, u64 blkno, u64 nblocks)
46{
47 struct super_block *sb = ip->i_sb;
48 int r = 0;
49
50 r = sb_issue_discard(sb, blkno, nblocks, GFP_NOFS, 0);
51 if (unlikely(r != 0)) {
52 jfs_err("JFS: sb_issue_discard(%p, %llu, %llu, GFP_NOFS, 0) = %d => failed!",
53 sb, (unsigned long long)blkno,
54 (unsigned long long)nblocks, r);
55 }
56
57 jfs_info("JFS: sb_issue_discard(%p, %llu, %llu, GFP_NOFS, 0) = %d",
58 sb, (unsigned long long)blkno,
59 (unsigned long long)nblocks, r);
60
61 return;
62}
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
79{
80 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
81 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
82 struct super_block *sb = ipbmap->i_sb;
83 int agno, agno_end;
84 u64 start, end, minlen;
85 u64 trimmed = 0;
86
87
88
89
90
91
92
93 start = range->start >> sb->s_blocksize_bits;
94 end = start + (range->len >> sb->s_blocksize_bits) - 1;
95 minlen = range->minlen >> sb->s_blocksize_bits;
96 if (minlen == 0)
97 minlen = 1;
98
99 if (minlen > bmp->db_agsize ||
100 start >= bmp->db_mapsize ||
101 range->len < sb->s_blocksize)
102 return -EINVAL;
103
104 if (end >= bmp->db_mapsize)
105 end = bmp->db_mapsize - 1;
106
107
108
109
110 agno = BLKTOAG(start, JFS_SBI(ip->i_sb));
111 agno_end = BLKTOAG(end, JFS_SBI(ip->i_sb));
112 while (agno <= agno_end) {
113 trimmed += dbDiscardAG(ip, agno, minlen);
114 agno++;
115 }
116 range->len = trimmed << sb->s_blocksize_bits;
117
118 return 0;
119}
120