add patch set-lazytime-on-remount
[ext4-patch-queue.git] / minor-cleanup-of-ext4_da_reserve_space
blob9c8e3b3bbd5570b271d26c759e308da2b1566f39
1 ext4: minor cleanup of ext4_da_reserve_space()
3 From: Eric Whitney <enwlinux@gmail.com>
5 Remove outdated comments and dead code from ext4_da_reserve_space.
6 Clean up its trace point, and relocate it to make it more useful.
8 While we're at it, fix a nearby conditional used to determine if
9 we have a non-bigalloc file system.  It doesn't match usage elsewhere
10 in the code, and misleadingly suggests that an s_cluster_ratio value
11 of 0 would be legal.
13 Signed-off-by: Eric Whitney <enwlinux@gmail.com>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 ---
16  fs/ext4/inode.c             | 22 +++++-----------------
17  include/trace/events/ext4.h | 10 ++++------
18  2 files changed, 9 insertions(+), 23 deletions(-)
20 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
21 index 7eb70b7..fecc1d0 100644
22 --- a/fs/ext4/inode.c
23 +++ b/fs/ext4/inode.c
24 @@ -1262,13 +1262,12 @@ static int ext4_journalled_write_end(struct file *file,
25  }
27  /*
28 - * Reserve a single cluster located at lblock
29 + * Reserve space for a single cluster
30   */
31 -static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock)
32 +static int ext4_da_reserve_space(struct inode *inode)
33  {
34         struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
35         struct ext4_inode_info *ei = EXT4_I(inode);
36 -       unsigned int md_needed;
37         int ret;
39         /*
40 @@ -1280,25 +1279,14 @@ static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock)
41         if (ret)
42                 return ret;
44 -       /*
45 -        * recalculate the amount of metadata blocks to reserve
46 -        * in order to allocate nrblocks
47 -        * worse case is one extent per block
48 -        */
49         spin_lock(&ei->i_block_reservation_lock);
50 -       /*
51 -        * ext4_calc_metadata_amount() has side effects, which we have
52 -        * to be prepared undo if we fail to claim space.
53 -        */
54 -       md_needed = 0;
55 -       trace_ext4_da_reserve_space(inode, 0);
57         if (ext4_claim_free_clusters(sbi, 1, 0)) {
58                 spin_unlock(&ei->i_block_reservation_lock);
59                 dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1));
60                 return -ENOSPC;
61         }
62         ei->i_reserved_data_blocks++;
63 +       trace_ext4_da_reserve_space(inode);
64         spin_unlock(&ei->i_block_reservation_lock);
66         return 0;       /* success */
67 @@ -1567,9 +1555,9 @@ add_delayed:
68                  * then we don't need to reserve it again. However we still need
69                  * to reserve metadata for every block we're going to write.
70                  */
71 -               if (EXT4_SB(inode->i_sb)->s_cluster_ratio <= 1 ||
72 +               if (EXT4_SB(inode->i_sb)->s_cluster_ratio == 1 ||
73                     !ext4_find_delalloc_cluster(inode, map->m_lblk)) {
74 -                       ret = ext4_da_reserve_space(inode, iblock);
75 +                       ret = ext4_da_reserve_space(inode);
76                         if (ret) {
77                                 /* not enough space to reserve */
78                                 retval = ret;
79 diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
80 index 6e5abd6..6ed16df 100644
81 --- a/include/trace/events/ext4.h
82 +++ b/include/trace/events/ext4.h
83 @@ -1185,15 +1185,14 @@ TRACE_EVENT(ext4_da_update_reserve_space,
84  );
86  TRACE_EVENT(ext4_da_reserve_space,
87 -       TP_PROTO(struct inode *inode, int md_needed),
88 +       TP_PROTO(struct inode *inode),
90 -       TP_ARGS(inode, md_needed),
91 +       TP_ARGS(inode),
93         TP_STRUCT__entry(
94                 __field(        dev_t,  dev                     )
95                 __field(        ino_t,  ino                     )
96                 __field(        __u64,  i_blocks                )
97 -               __field(        int,    md_needed               )
98                 __field(        int,    reserved_data_blocks    )
99                 __field(        int,    reserved_meta_blocks    )
100                 __field(        __u16,  mode                    )
101 @@ -1203,18 +1202,17 @@ TRACE_EVENT(ext4_da_reserve_space,
102                 __entry->dev    = inode->i_sb->s_dev;
103                 __entry->ino    = inode->i_ino;
104                 __entry->i_blocks = inode->i_blocks;
105 -               __entry->md_needed = md_needed;
106                 __entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks;
107                 __entry->reserved_meta_blocks = EXT4_I(inode)->i_reserved_meta_blocks;
108                 __entry->mode   = inode->i_mode;
109         ),
111 -       TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu md_needed %d "
112 +       TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu "
113                   "reserved_data_blocks %d reserved_meta_blocks %d",
114                   MAJOR(__entry->dev), MINOR(__entry->dev),
115                   (unsigned long) __entry->ino,
116                   __entry->mode, __entry->i_blocks,
117 -                 __entry->md_needed, __entry->reserved_data_blocks,
118 +                 __entry->reserved_data_blocks,
119                   __entry->reserved_meta_blocks)
120  );
122 -- 
123 2.1.0