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" \
53 "(%p, %llu, %llu, GFP_NOFS, 0) = %d => failed!\n",
54 sb, (unsigned long long)blkno,
55 (unsigned long long)nblocks, r);
56 }
57
58 jfs_info("JFS: sb_issue_discard" \
59 "(%p, %llu, %llu, GFP_NOFS, 0) = %d\n",
60 sb, (unsigned long long)blkno,
61 (unsigned long long)nblocks, r);
62
63 return;
64}
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
81{
82 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
83 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
84 struct super_block *sb = ipbmap->i_sb;
85 int agno, agno_end;
86 u64 start, end, minlen;
87 u64 trimmed = 0;
88
89
90
91
92
93
94
95 start = range->start >> sb->s_blocksize_bits;
96 end = start + (range->len >> sb->s_blocksize_bits) - 1;
97 minlen = range->minlen >> sb->s_blocksize_bits;
98 if (minlen == 0)
99 minlen = 1;
100
101 if (minlen > bmp->db_agsize ||
102 start >= bmp->db_mapsize ||
103 range->len < sb->s_blocksize)
104 return -EINVAL;
105
106 if (end >= bmp->db_mapsize)
107 end = bmp->db_mapsize - 1;
108
109
110
111
112 agno = BLKTOAG(start, JFS_SBI(ip->i_sb));
113 agno_end = BLKTOAG(end, JFS_SBI(ip->i_sb));
114 while (agno <= agno_end) {
115 trimmed += dbDiscardAG(ip, agno, minlen);
116 agno++;
117 }
118 range->len = trimmed << sb->s_blocksize_bits;
119
120 return 0;
121}
122