aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c78
1 files changed, 62 insertions, 16 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 913ab2d9a5d1..643ac43e5a5c 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -17,6 +17,7 @@
17#include <linux/hash.h> 17#include <linux/hash.h>
18#include <linux/swap.h> 18#include <linux/swap.h>
19#include <linux/security.h> 19#include <linux/security.h>
20#include <linux/ima.h>
20#include <linux/pagemap.h> 21#include <linux/pagemap.h>
21#include <linux/cdev.h> 22#include <linux/cdev.h>
22#include <linux/bootmem.h> 23#include <linux/bootmem.h>
@@ -147,13 +148,13 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
147 inode->i_cdev = NULL; 148 inode->i_cdev = NULL;
148 inode->i_rdev = 0; 149 inode->i_rdev = 0;
149 inode->dirtied_when = 0; 150 inode->dirtied_when = 0;
150 if (security_inode_alloc(inode)) { 151
151 if (inode->i_sb->s_op->destroy_inode) 152 if (security_inode_alloc(inode))
152 inode->i_sb->s_op->destroy_inode(inode); 153 goto out_free_inode;
153 else 154
154 kmem_cache_free(inode_cachep, (inode)); 155 /* allocate and initialize an i_integrity */
155 return NULL; 156 if (ima_inode_alloc(inode))
156 } 157 goto out_free_security;
157 158
158 spin_lock_init(&inode->i_lock); 159 spin_lock_init(&inode->i_lock);
159 lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); 160 lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
@@ -189,6 +190,15 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
189 inode->i_mapping = mapping; 190 inode->i_mapping = mapping;
190 191
191 return inode; 192 return inode;
193
194out_free_security:
195 security_inode_free(inode);
196out_free_inode:
197 if (inode->i_sb->s_op->destroy_inode)
198 inode->i_sb->s_op->destroy_inode(inode);
199 else
200 kmem_cache_free(inode_cachep, (inode));
201 return NULL;
192} 202}
193EXPORT_SYMBOL(inode_init_always); 203EXPORT_SYMBOL(inode_init_always);
194 204
@@ -359,6 +369,7 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
359 invalidate_inode_buffers(inode); 369 invalidate_inode_buffers(inode);
360 if (!atomic_read(&inode->i_count)) { 370 if (!atomic_read(&inode->i_count)) {
361 list_move(&inode->i_list, dispose); 371 list_move(&inode->i_list, dispose);
372 WARN_ON(inode->i_state & I_NEW);
362 inode->i_state |= I_FREEING; 373 inode->i_state |= I_FREEING;
363 count++; 374 count++;
364 continue; 375 continue;
@@ -460,6 +471,7 @@ static void prune_icache(int nr_to_scan)
460 continue; 471 continue;
461 } 472 }
462 list_move(&inode->i_list, &freeable); 473 list_move(&inode->i_list, &freeable);
474 WARN_ON(inode->i_state & I_NEW);
463 inode->i_state |= I_FREEING; 475 inode->i_state |= I_FREEING;
464 nr_pruned++; 476 nr_pruned++;
465 } 477 }
@@ -656,6 +668,7 @@ void unlock_new_inode(struct inode *inode)
656 * just created it (so there can be no old holders 668 * just created it (so there can be no old holders
657 * that haven't tested I_LOCK). 669 * that haven't tested I_LOCK).
658 */ 670 */
671 WARN_ON((inode->i_state & (I_LOCK|I_NEW)) != (I_LOCK|I_NEW));
659 inode->i_state &= ~(I_LOCK|I_NEW); 672 inode->i_state &= ~(I_LOCK|I_NEW);
660 wake_up_inode(inode); 673 wake_up_inode(inode);
661} 674}
@@ -1145,6 +1158,7 @@ void generic_delete_inode(struct inode *inode)
1145 1158
1146 list_del_init(&inode->i_list); 1159 list_del_init(&inode->i_list);
1147 list_del_init(&inode->i_sb_list); 1160 list_del_init(&inode->i_sb_list);
1161 WARN_ON(inode->i_state & I_NEW);
1148 inode->i_state |= I_FREEING; 1162 inode->i_state |= I_FREEING;
1149 inodes_stat.nr_inodes--; 1163 inodes_stat.nr_inodes--;
1150 spin_unlock(&inode_lock); 1164 spin_unlock(&inode_lock);
@@ -1186,16 +1200,19 @@ static void generic_forget_inode(struct inode *inode)
1186 spin_unlock(&inode_lock); 1200 spin_unlock(&inode_lock);
1187 return; 1201 return;
1188 } 1202 }
1203 WARN_ON(inode->i_state & I_NEW);
1189 inode->i_state |= I_WILL_FREE; 1204 inode->i_state |= I_WILL_FREE;
1190 spin_unlock(&inode_lock); 1205 spin_unlock(&inode_lock);
1191 write_inode_now(inode, 1); 1206 write_inode_now(inode, 1);
1192 spin_lock(&inode_lock); 1207 spin_lock(&inode_lock);
1208 WARN_ON(inode->i_state & I_NEW);
1193 inode->i_state &= ~I_WILL_FREE; 1209 inode->i_state &= ~I_WILL_FREE;
1194 inodes_stat.nr_unused--; 1210 inodes_stat.nr_unused--;
1195 hlist_del_init(&inode->i_hash); 1211 hlist_del_init(&inode->i_hash);
1196 } 1212 }
1197 list_del_init(&inode->i_list); 1213 list_del_init(&inode->i_list);
1198 list_del_init(&inode->i_sb_list); 1214 list_del_init(&inode->i_sb_list);
1215 WARN_ON(inode->i_state & I_NEW);
1199 inode->i_state |= I_FREEING; 1216 inode->i_state |= I_FREEING;
1200 inodes_stat.nr_inodes--; 1217 inodes_stat.nr_inodes--;
1201 spin_unlock(&inode_lock); 1218 spin_unlock(&inode_lock);
@@ -1283,6 +1300,40 @@ sector_t bmap(struct inode * inode, sector_t block)
1283} 1300}
1284EXPORT_SYMBOL(bmap); 1301EXPORT_SYMBOL(bmap);
1285 1302
1303/*
1304 * With relative atime, only update atime if the previous atime is
1305 * earlier than either the ctime or mtime or if at least a day has
1306 * passed since the last atime update.
1307 */
1308static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1309 struct timespec now)
1310{
1311
1312 if (!(mnt->mnt_flags & MNT_RELATIME))
1313 return 1;
1314 /*
1315 * Is mtime younger than atime? If yes, update atime:
1316 */
1317 if (timespec_compare(&inode->i_mtime, &inode->i_atime) >= 0)
1318 return 1;
1319 /*
1320 * Is ctime younger than atime? If yes, update atime:
1321 */
1322 if (timespec_compare(&inode->i_ctime, &inode->i_atime) >= 0)
1323 return 1;
1324
1325 /*
1326 * Is the previous atime value older than a day? If yes,
1327 * update atime:
1328 */
1329 if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
1330 return 1;
1331 /*
1332 * Good, we can skip the atime update:
1333 */
1334 return 0;
1335}
1336
1286/** 1337/**
1287 * touch_atime - update the access time 1338 * touch_atime - update the access time
1288 * @mnt: mount the inode is accessed on 1339 * @mnt: mount the inode is accessed on
@@ -1310,17 +1361,12 @@ void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
1310 goto out; 1361 goto out;
1311 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)) 1362 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1312 goto out; 1363 goto out;
1313 if (mnt->mnt_flags & MNT_RELATIME) {
1314 /*
1315 * With relative atime, only update atime if the previous
1316 * atime is earlier than either the ctime or mtime.
1317 */
1318 if (timespec_compare(&inode->i_mtime, &inode->i_atime) < 0 &&
1319 timespec_compare(&inode->i_ctime, &inode->i_atime) < 0)
1320 goto out;
1321 }
1322 1364
1323 now = current_fs_time(inode->i_sb); 1365 now = current_fs_time(inode->i_sb);
1366
1367 if (!relatime_need_update(mnt, inode, now))
1368 goto out;
1369
1324 if (timespec_equal(&inode->i_atime, &now)) 1370 if (timespec_equal(&inode->i_atime, &now))
1325 goto out; 1371 goto out;
1326 1372