~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/jfs/jfs_discard.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  *   Copyright (C) Tino Reichardt, 2012
  4  */
  5 
  6 #include <linux/fs.h>
  7 #include <linux/slab.h>
  8 #include <linux/blkdev.h>
  9 
 10 #include "jfs_incore.h"
 11 #include "jfs_superblock.h"
 12 #include "jfs_discard.h"
 13 #include "jfs_dmap.h"
 14 #include "jfs_debug.h"
 15 
 16 
 17 /*
 18  * NAME:        jfs_issue_discard()
 19  *
 20  * FUNCTION:    TRIM the specified block range on device, if supported
 21  *
 22  * PARAMETERS:
 23  *      ip      - pointer to in-core inode
 24  *      blkno   - starting block number to be trimmed (0..N)
 25  *      nblocks - number of blocks to be trimmed
 26  *
 27  * RETURN VALUES:
 28  *      none
 29  *
 30  * serialization: IREAD_LOCK(ipbmap) held on entry/exit;
 31  */
 32 void jfs_issue_discard(struct inode *ip, u64 blkno, u64 nblocks)
 33 {
 34         struct super_block *sb = ip->i_sb;
 35         int r = 0;
 36 
 37         r = sb_issue_discard(sb, blkno, nblocks, GFP_NOFS, 0);
 38         if (unlikely(r != 0)) {
 39                 jfs_err("JFS: sb_issue_discard(%p, %llu, %llu, GFP_NOFS, 0) = %d => failed!",
 40                         sb, (unsigned long long)blkno,
 41                         (unsigned long long)nblocks, r);
 42         }
 43 
 44         jfs_info("JFS: sb_issue_discard(%p, %llu, %llu, GFP_NOFS, 0) = %d",
 45                 sb, (unsigned long long)blkno,
 46                 (unsigned long long)nblocks, r);
 47 
 48         return;
 49 }
 50 
 51 /*
 52  * NAME:        jfs_ioc_trim()
 53  *
 54  * FUNCTION:    attempt to discard (TRIM) all free blocks from the
 55  *              filesystem.
 56  *
 57  * PARAMETERS:
 58  *      ip      - pointer to in-core inode;
 59  *      range   - the range, given by user space
 60  *
 61  * RETURN VALUES:
 62  *      0       - success
 63  *      -EIO    - i/o error
 64  */
 65 int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
 66 {
 67         struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
 68         struct bmap *bmp;
 69         struct super_block *sb = ipbmap->i_sb;
 70         int agno, agno_end;
 71         u64 start, end, minlen;
 72         u64 trimmed = 0;
 73 
 74         /**
 75          * convert byte values to block size of filesystem:
 76          * start:       First Byte to trim
 77          * len:         number of Bytes to trim from start
 78          * minlen:      minimum extent length in Bytes
 79          */
 80         start = range->start >> sb->s_blocksize_bits;
 81         end = start + (range->len >> sb->s_blocksize_bits) - 1;
 82         minlen = range->minlen >> sb->s_blocksize_bits;
 83         if (minlen == 0)
 84                 minlen = 1;
 85 
 86         down_read(&sb->s_umount);
 87         bmp = JFS_SBI(ip->i_sb)->bmap;
 88 
 89         if (minlen > bmp->db_agsize ||
 90             start >= bmp->db_mapsize ||
 91             range->len < sb->s_blocksize) {
 92                 up_read(&sb->s_umount);
 93                 return -EINVAL;
 94         }
 95 
 96         if (end >= bmp->db_mapsize)
 97                 end = bmp->db_mapsize - 1;
 98 
 99         /**
100          * we trim all ag's within the range
101          */
102         agno = BLKTOAG(start, JFS_SBI(ip->i_sb));
103         agno_end = BLKTOAG(end, JFS_SBI(ip->i_sb));
104         while (agno <= agno_end) {
105                 trimmed += dbDiscardAG(ip, agno, minlen);
106                 agno++;
107         }
108 
109         up_read(&sb->s_umount);
110         range->len = trimmed << sb->s_blocksize_bits;
111 
112         return 0;
113 }
114 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php