| .. | .. | 
|---|
 | 1 | +// SPDX-License-Identifier: GPL-2.0-only  | 
|---|
| 1 | 2 |  /* | 
|---|
| 2 | 3 |   * (C) 1997 Linus Torvalds | 
|---|
| 3 | 4 |   * (C) 1999 Andrea Arcangeli <andrea@suse.de> (dynamic inode allocation) | 
|---|
| .. | .. | 
|---|
| 10 | 11 |  #include <linux/swap.h> | 
|---|
| 11 | 12 |  #include <linux/security.h> | 
|---|
| 12 | 13 |  #include <linux/cdev.h> | 
|---|
| 13 |  | -#include <linux/bootmem.h>  | 
|---|
 | 14 | +#include <linux/memblock.h>  | 
|---|
| 14 | 15 |  #include <linux/fscrypt.h> | 
|---|
| 15 | 16 |  #include <linux/fsnotify.h> | 
|---|
| 16 | 17 |  #include <linux/mount.h> | 
|---|
| .. | .. | 
|---|
| 107 | 108 |   */ | 
|---|
| 108 | 109 |  #ifdef CONFIG_SYSCTL | 
|---|
| 109 | 110 |  int proc_nr_inodes(struct ctl_table *table, int write, | 
|---|
| 110 |  | -		   void __user *buffer, size_t *lenp, loff_t *ppos)  | 
|---|
 | 111 | +		   void *buffer, size_t *lenp, loff_t *ppos)  | 
|---|
| 111 | 112 |  { | 
|---|
| 112 | 113 |  	inodes_stat.nr_inodes = get_nr_inodes(); | 
|---|
| 113 | 114 |  	inodes_stat.nr_unused = get_nr_inodes_unused(); | 
|---|
| .. | .. | 
|---|
| 157 | 158 |  	inode->i_bdev = NULL; | 
|---|
| 158 | 159 |  	inode->i_cdev = NULL; | 
|---|
| 159 | 160 |  	inode->i_link = NULL; | 
|---|
| 160 |  | -	inode->__i_dir_seq = 0;  | 
|---|
 | 161 | +	inode->i_dir_seq = 0;  | 
|---|
| 161 | 162 |  	inode->i_rdev = 0; | 
|---|
| 162 | 163 |  	inode->dirtied_when = 0; | 
|---|
| 163 | 164 |   | 
|---|
| .. | .. | 
|---|
| 167 | 168 |  	inode->i_wb_frn_history = 0; | 
|---|
| 168 | 169 |  #endif | 
|---|
| 169 | 170 |   | 
|---|
| 170 |  | -	if (security_inode_alloc(inode))  | 
|---|
| 171 |  | -		goto out;  | 
|---|
| 172 | 171 |  	spin_lock_init(&inode->i_lock); | 
|---|
| 173 | 172 |  	lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); | 
|---|
| 174 | 173 |   | 
|---|
| .. | .. | 
|---|
| 180 | 179 |  	mapping->a_ops = &empty_aops; | 
|---|
| 181 | 180 |  	mapping->host = inode; | 
|---|
| 182 | 181 |  	mapping->flags = 0; | 
|---|
 | 182 | +	if (sb->s_type->fs_flags & FS_THP_SUPPORT)  | 
|---|
 | 183 | +		__set_bit(AS_THP_SUPPORT, &mapping->flags);  | 
|---|
| 183 | 184 |  	mapping->wb_err = 0; | 
|---|
| 184 | 185 |  	atomic_set(&mapping->i_mmap_writable, 0); | 
|---|
 | 186 | +#ifdef CONFIG_READ_ONLY_THP_FOR_FS  | 
|---|
 | 187 | +	atomic_set(&mapping->nr_thps, 0);  | 
|---|
 | 188 | +#endif  | 
|---|
| 185 | 189 |  	mapping_set_gfp_mask(mapping, GFP_HIGHUSER_MOVABLE); | 
|---|
| 186 | 190 |  	mapping->private_data = NULL; | 
|---|
| 187 | 191 |  	mapping->writeback_index = 0; | 
|---|
| .. | .. | 
|---|
| 196 | 200 |  	inode->i_fsnotify_mask = 0; | 
|---|
| 197 | 201 |  #endif | 
|---|
| 198 | 202 |  	inode->i_flctx = NULL; | 
|---|
 | 203 | +  | 
|---|
 | 204 | +	if (unlikely(security_inode_alloc(inode)))  | 
|---|
 | 205 | +		return -ENOMEM;  | 
|---|
| 199 | 206 |  	this_cpu_inc(nr_inodes); | 
|---|
| 200 | 207 |   | 
|---|
| 201 | 208 |  	return 0; | 
|---|
| 202 |  | -out:  | 
|---|
| 203 |  | -	return -ENOMEM;  | 
|---|
| 204 | 209 |  } | 
|---|
| 205 | 210 |  EXPORT_SYMBOL(inode_init_always); | 
|---|
| 206 | 211 |   | 
|---|
 | 212 | +void free_inode_nonrcu(struct inode *inode)  | 
|---|
 | 213 | +{  | 
|---|
 | 214 | +	kmem_cache_free(inode_cachep, inode);  | 
|---|
 | 215 | +}  | 
|---|
 | 216 | +EXPORT_SYMBOL(free_inode_nonrcu);  | 
|---|
 | 217 | +  | 
|---|
 | 218 | +static void i_callback(struct rcu_head *head)  | 
|---|
 | 219 | +{  | 
|---|
 | 220 | +	struct inode *inode = container_of(head, struct inode, i_rcu);  | 
|---|
 | 221 | +	if (inode->free_inode)  | 
|---|
 | 222 | +		inode->free_inode(inode);  | 
|---|
 | 223 | +	else  | 
|---|
 | 224 | +		free_inode_nonrcu(inode);  | 
|---|
 | 225 | +}  | 
|---|
 | 226 | +  | 
|---|
| 207 | 227 |  static struct inode *alloc_inode(struct super_block *sb) | 
|---|
| 208 | 228 |  { | 
|---|
 | 229 | +	const struct super_operations *ops = sb->s_op;  | 
|---|
| 209 | 230 |  	struct inode *inode; | 
|---|
| 210 | 231 |   | 
|---|
| 211 |  | -	if (sb->s_op->alloc_inode)  | 
|---|
| 212 |  | -		inode = sb->s_op->alloc_inode(sb);  | 
|---|
 | 232 | +	if (ops->alloc_inode)  | 
|---|
 | 233 | +		inode = ops->alloc_inode(sb);  | 
|---|
| 213 | 234 |  	else | 
|---|
| 214 | 235 |  		inode = kmem_cache_alloc(inode_cachep, GFP_KERNEL); | 
|---|
| 215 | 236 |   | 
|---|
| .. | .. | 
|---|
| 217 | 238 |  		return NULL; | 
|---|
| 218 | 239 |   | 
|---|
| 219 | 240 |  	if (unlikely(inode_init_always(sb, inode))) { | 
|---|
| 220 |  | -		if (inode->i_sb->s_op->destroy_inode)  | 
|---|
| 221 |  | -			inode->i_sb->s_op->destroy_inode(inode);  | 
|---|
| 222 |  | -		else  | 
|---|
| 223 |  | -			kmem_cache_free(inode_cachep, inode);  | 
|---|
 | 241 | +		if (ops->destroy_inode) {  | 
|---|
 | 242 | +			ops->destroy_inode(inode);  | 
|---|
 | 243 | +			if (!ops->free_inode)  | 
|---|
 | 244 | +				return NULL;  | 
|---|
 | 245 | +		}  | 
|---|
 | 246 | +		inode->free_inode = ops->free_inode;  | 
|---|
 | 247 | +		i_callback(&inode->i_rcu);  | 
|---|
| 224 | 248 |  		return NULL; | 
|---|
| 225 | 249 |  	} | 
|---|
| 226 | 250 |   | 
|---|
| 227 | 251 |  	return inode; | 
|---|
| 228 | 252 |  } | 
|---|
| 229 |  | -  | 
|---|
| 230 |  | -void free_inode_nonrcu(struct inode *inode)  | 
|---|
| 231 |  | -{  | 
|---|
| 232 |  | -	kmem_cache_free(inode_cachep, inode);  | 
|---|
| 233 |  | -}  | 
|---|
| 234 |  | -EXPORT_SYMBOL(free_inode_nonrcu);  | 
|---|
| 235 | 253 |   | 
|---|
| 236 | 254 |  void __destroy_inode(struct inode *inode) | 
|---|
| 237 | 255 |  { | 
|---|
| .. | .. | 
|---|
| 255 | 273 |  } | 
|---|
| 256 | 274 |  EXPORT_SYMBOL(__destroy_inode); | 
|---|
| 257 | 275 |   | 
|---|
| 258 |  | -static void i_callback(struct rcu_head *head)  | 
|---|
| 259 |  | -{  | 
|---|
| 260 |  | -	struct inode *inode = container_of(head, struct inode, i_rcu);  | 
|---|
| 261 |  | -	kmem_cache_free(inode_cachep, inode);  | 
|---|
| 262 |  | -}  | 
|---|
| 263 |  | -  | 
|---|
| 264 | 276 |  static void destroy_inode(struct inode *inode) | 
|---|
| 265 | 277 |  { | 
|---|
 | 278 | +	const struct super_operations *ops = inode->i_sb->s_op;  | 
|---|
 | 279 | +  | 
|---|
| 266 | 280 |  	BUG_ON(!list_empty(&inode->i_lru)); | 
|---|
| 267 | 281 |  	__destroy_inode(inode); | 
|---|
| 268 |  | -	if (inode->i_sb->s_op->destroy_inode)  | 
|---|
| 269 |  | -		inode->i_sb->s_op->destroy_inode(inode);  | 
|---|
| 270 |  | -	else  | 
|---|
| 271 |  | -		call_rcu(&inode->i_rcu, i_callback);  | 
|---|
 | 282 | +	if (ops->destroy_inode) {  | 
|---|
 | 283 | +		ops->destroy_inode(inode);  | 
|---|
 | 284 | +		if (!ops->free_inode)  | 
|---|
 | 285 | +			return;  | 
|---|
 | 286 | +	}  | 
|---|
 | 287 | +	inode->free_inode = ops->free_inode;  | 
|---|
 | 288 | +	call_rcu(&inode->i_rcu, i_callback);  | 
|---|
| 272 | 289 |  } | 
|---|
| 273 | 290 |   | 
|---|
| 274 | 291 |  /** | 
|---|
| .. | .. | 
|---|
| 289 | 306 |  	if (!inode->i_nlink) | 
|---|
| 290 | 307 |  		atomic_long_inc(&inode->i_sb->s_remove_count); | 
|---|
| 291 | 308 |  } | 
|---|
| 292 |  | -EXPORT_SYMBOL(drop_nlink);  | 
|---|
 | 309 | +EXPORT_SYMBOL_NS(drop_nlink, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 293 | 310 |   | 
|---|
| 294 | 311 |  /** | 
|---|
| 295 | 312 |   * clear_nlink - directly zero an inode's link count | 
|---|
| .. | .. | 
|---|
| 328 | 345 |  		inode->__i_nlink = nlink; | 
|---|
| 329 | 346 |  	} | 
|---|
| 330 | 347 |  } | 
|---|
| 331 |  | -EXPORT_SYMBOL(set_nlink);  | 
|---|
 | 348 | +EXPORT_SYMBOL_NS(set_nlink, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 332 | 349 |   | 
|---|
| 333 | 350 |  /** | 
|---|
| 334 | 351 |   * inc_nlink - directly increment an inode's link count | 
|---|
| .. | .. | 
|---|
| 351 | 368 |   | 
|---|
| 352 | 369 |  static void __address_space_init_once(struct address_space *mapping) | 
|---|
| 353 | 370 |  { | 
|---|
| 354 |  | -	INIT_RADIX_TREE(&mapping->i_pages, GFP_ATOMIC | __GFP_ACCOUNT);  | 
|---|
 | 371 | +	xa_init_flags(&mapping->i_pages, XA_FLAGS_LOCK_IRQ | XA_FLAGS_ACCOUNT);  | 
|---|
| 355 | 372 |  	init_rwsem(&mapping->i_mmap_rwsem); | 
|---|
| 356 | 373 |  	INIT_LIST_HEAD(&mapping->private_list); | 
|---|
| 357 | 374 |  	spin_lock_init(&mapping->private_lock); | 
|---|
| .. | .. | 
|---|
| 381 | 398 |  	__address_space_init_once(&inode->i_data); | 
|---|
| 382 | 399 |  	i_size_ordered_init(inode); | 
|---|
| 383 | 400 |  } | 
|---|
| 384 |  | -EXPORT_SYMBOL(inode_init_once);  | 
|---|
 | 401 | +EXPORT_SYMBOL_NS(inode_init_once, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 385 | 402 |   | 
|---|
| 386 | 403 |  static void init_once(void *foo) | 
|---|
| 387 | 404 |  { | 
|---|
| .. | .. | 
|---|
| 405 | 422 |  { | 
|---|
| 406 | 423 |  	WARN_ON(atomic_inc_return(&inode->i_count) < 2); | 
|---|
| 407 | 424 |  } | 
|---|
| 408 |  | -EXPORT_SYMBOL(ihold);  | 
|---|
 | 425 | +EXPORT_SYMBOL_NS(ihold, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 409 | 426 |   | 
|---|
| 410 | 427 |  static void inode_lru_list_add(struct inode *inode) | 
|---|
| 411 | 428 |  { | 
|---|
| .. | .. | 
|---|
| 481 | 498 |   | 
|---|
| 482 | 499 |  	spin_lock(&inode_hash_lock); | 
|---|
| 483 | 500 |  	spin_lock(&inode->i_lock); | 
|---|
| 484 |  | -	hlist_add_head(&inode->i_hash, b);  | 
|---|
 | 501 | +	hlist_add_head_rcu(&inode->i_hash, b);  | 
|---|
| 485 | 502 |  	spin_unlock(&inode->i_lock); | 
|---|
| 486 | 503 |  	spin_unlock(&inode_hash_lock); | 
|---|
| 487 | 504 |  } | 
|---|
| 488 |  | -EXPORT_SYMBOL(__insert_inode_hash);  | 
|---|
 | 505 | +EXPORT_SYMBOL_NS(__insert_inode_hash, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 489 | 506 |   | 
|---|
| 490 | 507 |  /** | 
|---|
| 491 | 508 |   *	__remove_inode_hash - remove an inode from the hash | 
|---|
| .. | .. | 
|---|
| 497 | 514 |  { | 
|---|
| 498 | 515 |  	spin_lock(&inode_hash_lock); | 
|---|
| 499 | 516 |  	spin_lock(&inode->i_lock); | 
|---|
| 500 |  | -	hlist_del_init(&inode->i_hash);  | 
|---|
 | 517 | +	hlist_del_init_rcu(&inode->i_hash);  | 
|---|
| 501 | 518 |  	spin_unlock(&inode->i_lock); | 
|---|
| 502 | 519 |  	spin_unlock(&inode_hash_lock); | 
|---|
| 503 | 520 |  } | 
|---|
| 504 |  | -EXPORT_SYMBOL(__remove_inode_hash);  | 
|---|
 | 521 | +EXPORT_SYMBOL_NS(__remove_inode_hash, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 505 | 522 |   | 
|---|
| 506 | 523 |  void clear_inode(struct inode *inode) | 
|---|
| 507 | 524 |  { | 
|---|
| .. | .. | 
|---|
| 521 | 538 |  	/* don't need i_lock here, no concurrent mods to i_state */ | 
|---|
| 522 | 539 |  	inode->i_state = I_FREEING | I_CLEAR; | 
|---|
| 523 | 540 |  } | 
|---|
| 524 |  | -EXPORT_SYMBOL(clear_inode);  | 
|---|
 | 541 | +EXPORT_SYMBOL_NS(clear_inode, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 525 | 542 |   | 
|---|
| 526 | 543 |  /* | 
|---|
| 527 | 544 |   * Free the inode passed in, removing it from the lists it is still connected | 
|---|
| .. | .. | 
|---|
| 983 | 1000 |  	wake_up_bit(&inode->i_state, __I_NEW); | 
|---|
| 984 | 1001 |  	spin_unlock(&inode->i_lock); | 
|---|
| 985 | 1002 |  } | 
|---|
| 986 |  | -EXPORT_SYMBOL(unlock_new_inode);  | 
|---|
 | 1003 | +EXPORT_SYMBOL_NS(unlock_new_inode, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 987 | 1004 |   | 
|---|
| 988 | 1005 |  void discard_new_inode(struct inode *inode) | 
|---|
| 989 | 1006 |  { | 
|---|
| .. | .. | 
|---|
| 1091 | 1108 |  	 */ | 
|---|
| 1092 | 1109 |  	spin_lock(&inode->i_lock); | 
|---|
| 1093 | 1110 |  	inode->i_state |= I_NEW; | 
|---|
| 1094 |  | -	hlist_add_head(&inode->i_hash, head);  | 
|---|
 | 1111 | +	hlist_add_head_rcu(&inode->i_hash, head);  | 
|---|
| 1095 | 1112 |  	spin_unlock(&inode->i_lock); | 
|---|
| 1096 | 1113 |  	if (!creating) | 
|---|
| 1097 | 1114 |  		inode_sb_list_add(inode); | 
|---|
| .. | .. | 
|---|
| 1140 | 1157 |  	} | 
|---|
| 1141 | 1158 |  	return inode; | 
|---|
| 1142 | 1159 |  } | 
|---|
| 1143 |  | -EXPORT_SYMBOL(iget5_locked);  | 
|---|
 | 1160 | +EXPORT_SYMBOL_NS(iget5_locked, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 1144 | 1161 |   | 
|---|
| 1145 | 1162 |  /** | 
|---|
| 1146 | 1163 |   * iget_locked - obtain an inode from a mounted file system | 
|---|
| .. | .. | 
|---|
| 1185 | 1202 |  			inode->i_ino = ino; | 
|---|
| 1186 | 1203 |  			spin_lock(&inode->i_lock); | 
|---|
| 1187 | 1204 |  			inode->i_state = I_NEW; | 
|---|
| 1188 |  | -			hlist_add_head(&inode->i_hash, head);  | 
|---|
 | 1205 | +			hlist_add_head_rcu(&inode->i_hash, head);  | 
|---|
| 1189 | 1206 |  			spin_unlock(&inode->i_lock); | 
|---|
| 1190 | 1207 |  			inode_sb_list_add(inode); | 
|---|
| 1191 | 1208 |  			spin_unlock(&inode_hash_lock); | 
|---|
| .. | .. | 
|---|
| 1228 | 1245 |  	struct hlist_head *b = inode_hashtable + hash(sb, ino); | 
|---|
| 1229 | 1246 |  	struct inode *inode; | 
|---|
| 1230 | 1247 |   | 
|---|
| 1231 |  | -	spin_lock(&inode_hash_lock);  | 
|---|
| 1232 |  | -	hlist_for_each_entry(inode, b, i_hash) {  | 
|---|
| 1233 |  | -		if (inode->i_ino == ino && inode->i_sb == sb) {  | 
|---|
| 1234 |  | -			spin_unlock(&inode_hash_lock);  | 
|---|
 | 1248 | +	hlist_for_each_entry_rcu(inode, b, i_hash) {  | 
|---|
 | 1249 | +		if (inode->i_ino == ino && inode->i_sb == sb)  | 
|---|
| 1235 | 1250 |  			return 0; | 
|---|
| 1236 |  | -		}  | 
|---|
| 1237 | 1251 |  	} | 
|---|
| 1238 |  | -	spin_unlock(&inode_hash_lock);  | 
|---|
| 1239 |  | -  | 
|---|
| 1240 | 1252 |  	return 1; | 
|---|
| 1241 | 1253 |  } | 
|---|
| 1242 | 1254 |   | 
|---|
| .. | .. | 
|---|
| 1265 | 1277 |  	static unsigned int counter; | 
|---|
| 1266 | 1278 |  	ino_t res; | 
|---|
| 1267 | 1279 |   | 
|---|
 | 1280 | +	rcu_read_lock();  | 
|---|
| 1268 | 1281 |  	spin_lock(&iunique_lock); | 
|---|
| 1269 | 1282 |  	do { | 
|---|
| 1270 | 1283 |  		if (counter <= max_reserved) | 
|---|
| .. | .. | 
|---|
| 1272 | 1285 |  		res = counter++; | 
|---|
| 1273 | 1286 |  	} while (!test_inode_iunique(sb, res)); | 
|---|
| 1274 | 1287 |  	spin_unlock(&iunique_lock); | 
|---|
 | 1288 | +	rcu_read_unlock();  | 
|---|
| 1275 | 1289 |   | 
|---|
| 1276 | 1290 |  	return res; | 
|---|
| 1277 | 1291 |  } | 
|---|
| 1278 |  | -EXPORT_SYMBOL(iunique);  | 
|---|
 | 1292 | +EXPORT_SYMBOL_NS(iunique, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 1279 | 1293 |   | 
|---|
| 1280 | 1294 |  struct inode *igrab(struct inode *inode) | 
|---|
| 1281 | 1295 |  { | 
|---|
| .. | .. | 
|---|
| 1358 | 1372 |  	} | 
|---|
| 1359 | 1373 |  	return inode; | 
|---|
| 1360 | 1374 |  } | 
|---|
| 1361 |  | -EXPORT_SYMBOL(ilookup5);  | 
|---|
 | 1375 | +EXPORT_SYMBOL_NS(ilookup5, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 1362 | 1376 |   | 
|---|
| 1363 | 1377 |  /** | 
|---|
| 1364 | 1378 |   * ilookup - search for an inode in the inode cache | 
|---|
| .. | .. | 
|---|
| 1440 | 1454 |  } | 
|---|
| 1441 | 1455 |  EXPORT_SYMBOL(find_inode_nowait); | 
|---|
| 1442 | 1456 |   | 
|---|
 | 1457 | +/**  | 
|---|
 | 1458 | + * find_inode_rcu - find an inode in the inode cache  | 
|---|
 | 1459 | + * @sb:		Super block of file system to search  | 
|---|
 | 1460 | + * @hashval:	Key to hash  | 
|---|
 | 1461 | + * @test:	Function to test match on an inode  | 
|---|
 | 1462 | + * @data:	Data for test function  | 
|---|
 | 1463 | + *  | 
|---|
 | 1464 | + * Search for the inode specified by @hashval and @data in the inode cache,  | 
|---|
 | 1465 | + * where the helper function @test will return 0 if the inode does not match  | 
|---|
 | 1466 | + * and 1 if it does.  The @test function must be responsible for taking the  | 
|---|
 | 1467 | + * i_lock spin_lock and checking i_state for an inode being freed or being  | 
|---|
 | 1468 | + * initialized.  | 
|---|
 | 1469 | + *  | 
|---|
 | 1470 | + * If successful, this will return the inode for which the @test function  | 
|---|
 | 1471 | + * returned 1 and NULL otherwise.  | 
|---|
 | 1472 | + *  | 
|---|
 | 1473 | + * The @test function is not permitted to take a ref on any inode presented.  | 
|---|
 | 1474 | + * It is also not permitted to sleep.  | 
|---|
 | 1475 | + *  | 
|---|
 | 1476 | + * The caller must hold the RCU read lock.  | 
|---|
 | 1477 | + */  | 
|---|
 | 1478 | +struct inode *find_inode_rcu(struct super_block *sb, unsigned long hashval,  | 
|---|
 | 1479 | +			     int (*test)(struct inode *, void *), void *data)  | 
|---|
 | 1480 | +{  | 
|---|
 | 1481 | +	struct hlist_head *head = inode_hashtable + hash(sb, hashval);  | 
|---|
 | 1482 | +	struct inode *inode;  | 
|---|
 | 1483 | +  | 
|---|
 | 1484 | +	RCU_LOCKDEP_WARN(!rcu_read_lock_held(),  | 
|---|
 | 1485 | +			 "suspicious find_inode_rcu() usage");  | 
|---|
 | 1486 | +  | 
|---|
 | 1487 | +	hlist_for_each_entry_rcu(inode, head, i_hash) {  | 
|---|
 | 1488 | +		if (inode->i_sb == sb &&  | 
|---|
 | 1489 | +		    !(READ_ONCE(inode->i_state) & (I_FREEING | I_WILL_FREE)) &&  | 
|---|
 | 1490 | +		    test(inode, data))  | 
|---|
 | 1491 | +			return inode;  | 
|---|
 | 1492 | +	}  | 
|---|
 | 1493 | +	return NULL;  | 
|---|
 | 1494 | +}  | 
|---|
 | 1495 | +EXPORT_SYMBOL(find_inode_rcu);  | 
|---|
 | 1496 | +  | 
|---|
 | 1497 | +/**  | 
|---|
 | 1498 | + * find_inode_by_rcu - Find an inode in the inode cache  | 
|---|
 | 1499 | + * @sb:		Super block of file system to search  | 
|---|
 | 1500 | + * @ino:	The inode number to match  | 
|---|
 | 1501 | + *  | 
|---|
 | 1502 | + * Search for the inode specified by @hashval and @data in the inode cache,  | 
|---|
 | 1503 | + * where the helper function @test will return 0 if the inode does not match  | 
|---|
 | 1504 | + * and 1 if it does.  The @test function must be responsible for taking the  | 
|---|
 | 1505 | + * i_lock spin_lock and checking i_state for an inode being freed or being  | 
|---|
 | 1506 | + * initialized.  | 
|---|
 | 1507 | + *  | 
|---|
 | 1508 | + * If successful, this will return the inode for which the @test function  | 
|---|
 | 1509 | + * returned 1 and NULL otherwise.  | 
|---|
 | 1510 | + *  | 
|---|
 | 1511 | + * The @test function is not permitted to take a ref on any inode presented.  | 
|---|
 | 1512 | + * It is also not permitted to sleep.  | 
|---|
 | 1513 | + *  | 
|---|
 | 1514 | + * The caller must hold the RCU read lock.  | 
|---|
 | 1515 | + */  | 
|---|
 | 1516 | +struct inode *find_inode_by_ino_rcu(struct super_block *sb,  | 
|---|
 | 1517 | +				    unsigned long ino)  | 
|---|
 | 1518 | +{  | 
|---|
 | 1519 | +	struct hlist_head *head = inode_hashtable + hash(sb, ino);  | 
|---|
 | 1520 | +	struct inode *inode;  | 
|---|
 | 1521 | +  | 
|---|
 | 1522 | +	RCU_LOCKDEP_WARN(!rcu_read_lock_held(),  | 
|---|
 | 1523 | +			 "suspicious find_inode_by_ino_rcu() usage");  | 
|---|
 | 1524 | +  | 
|---|
 | 1525 | +	hlist_for_each_entry_rcu(inode, head, i_hash) {  | 
|---|
 | 1526 | +		if (inode->i_ino == ino &&  | 
|---|
 | 1527 | +		    inode->i_sb == sb &&  | 
|---|
 | 1528 | +		    !(READ_ONCE(inode->i_state) & (I_FREEING | I_WILL_FREE)))  | 
|---|
 | 1529 | +		    return inode;  | 
|---|
 | 1530 | +	}  | 
|---|
 | 1531 | +	return NULL;  | 
|---|
 | 1532 | +}  | 
|---|
 | 1533 | +EXPORT_SYMBOL(find_inode_by_ino_rcu);  | 
|---|
 | 1534 | +  | 
|---|
| 1443 | 1535 |  int insert_inode_locked(struct inode *inode) | 
|---|
| 1444 | 1536 |  { | 
|---|
| 1445 | 1537 |  	struct super_block *sb = inode->i_sb; | 
|---|
| .. | .. | 
|---|
| 1464 | 1556 |  		if (likely(!old)) { | 
|---|
| 1465 | 1557 |  			spin_lock(&inode->i_lock); | 
|---|
| 1466 | 1558 |  			inode->i_state |= I_NEW | I_CREATING; | 
|---|
| 1467 |  | -			hlist_add_head(&inode->i_hash, head);  | 
|---|
 | 1559 | +			hlist_add_head_rcu(&inode->i_hash, head);  | 
|---|
| 1468 | 1560 |  			spin_unlock(&inode->i_lock); | 
|---|
| 1469 | 1561 |  			spin_unlock(&inode_hash_lock); | 
|---|
| 1470 | 1562 |  			return 0; | 
|---|
| .. | .. | 
|---|
| 1524 | 1616 |  { | 
|---|
| 1525 | 1617 |  	struct super_block *sb = inode->i_sb; | 
|---|
| 1526 | 1618 |  	const struct super_operations *op = inode->i_sb->s_op; | 
|---|
 | 1619 | +	unsigned long state;  | 
|---|
| 1527 | 1620 |  	int drop; | 
|---|
| 1528 | 1621 |   | 
|---|
| 1529 | 1622 |  	WARN_ON(inode->i_state & I_NEW); | 
|---|
| .. | .. | 
|---|
| 1533 | 1626 |  	else | 
|---|
| 1534 | 1627 |  		drop = generic_drop_inode(inode); | 
|---|
| 1535 | 1628 |   | 
|---|
| 1536 |  | -	if (!drop && (sb->s_flags & SB_ACTIVE)) {  | 
|---|
 | 1629 | +	if (!drop &&  | 
|---|
 | 1630 | +	    !(inode->i_state & I_DONTCACHE) &&  | 
|---|
 | 1631 | +	    (sb->s_flags & SB_ACTIVE)) {  | 
|---|
| 1537 | 1632 |  		inode_add_lru(inode); | 
|---|
| 1538 | 1633 |  		spin_unlock(&inode->i_lock); | 
|---|
| 1539 | 1634 |  		return; | 
|---|
| 1540 | 1635 |  	} | 
|---|
| 1541 | 1636 |   | 
|---|
 | 1637 | +	state = inode->i_state;  | 
|---|
| 1542 | 1638 |  	if (!drop) { | 
|---|
| 1543 |  | -		inode->i_state |= I_WILL_FREE;  | 
|---|
 | 1639 | +		WRITE_ONCE(inode->i_state, state | I_WILL_FREE);  | 
|---|
| 1544 | 1640 |  		spin_unlock(&inode->i_lock); | 
|---|
 | 1641 | +  | 
|---|
| 1545 | 1642 |  		write_inode_now(inode, 1); | 
|---|
 | 1643 | +  | 
|---|
| 1546 | 1644 |  		spin_lock(&inode->i_lock); | 
|---|
| 1547 |  | -		WARN_ON(inode->i_state & I_NEW);  | 
|---|
| 1548 |  | -		inode->i_state &= ~I_WILL_FREE;  | 
|---|
 | 1645 | +		state = inode->i_state;  | 
|---|
 | 1646 | +		WARN_ON(state & I_NEW);  | 
|---|
 | 1647 | +		state &= ~I_WILL_FREE;  | 
|---|
| 1549 | 1648 |  	} | 
|---|
| 1550 | 1649 |   | 
|---|
| 1551 |  | -	inode->i_state |= I_FREEING;  | 
|---|
 | 1650 | +	WRITE_ONCE(inode->i_state, state | I_FREEING);  | 
|---|
| 1552 | 1651 |  	if (!list_empty(&inode->i_lru)) | 
|---|
| 1553 | 1652 |  		inode_lru_list_del(inode); | 
|---|
| 1554 | 1653 |  	spin_unlock(&inode->i_lock); | 
|---|
| .. | .. | 
|---|
| 1584 | 1683 |  } | 
|---|
| 1585 | 1684 |  EXPORT_SYMBOL(iput); | 
|---|
| 1586 | 1685 |   | 
|---|
 | 1686 | +#ifdef CONFIG_BLOCK  | 
|---|
| 1587 | 1687 |  /** | 
|---|
| 1588 | 1688 |   *	bmap	- find a block number in a file | 
|---|
| 1589 |  | - *	@inode: inode of file  | 
|---|
| 1590 |  | - *	@block: block to find  | 
|---|
 | 1689 | + *	@inode:  inode owning the block number being requested  | 
|---|
 | 1690 | + *	@block: pointer containing the block to find  | 
|---|
| 1591 | 1691 |   * | 
|---|
| 1592 |  | - *	Returns the block number on the device holding the inode that  | 
|---|
| 1593 |  | - *	is the disk block number for the block of the file requested.  | 
|---|
| 1594 |  | - *	That is, asked for block 4 of inode 1 the function will return the  | 
|---|
| 1595 |  | - *	disk block relative to the disk start that holds that block of the  | 
|---|
| 1596 |  | - *	file.  | 
|---|
 | 1692 | + *	Replaces the value in ``*block`` with the block number on the device holding  | 
|---|
 | 1693 | + *	corresponding to the requested block number in the file.  | 
|---|
 | 1694 | + *	That is, asked for block 4 of inode 1 the function will replace the  | 
|---|
 | 1695 | + *	4 in ``*block``, with disk block relative to the disk start that holds that  | 
|---|
 | 1696 | + *	block of the file.  | 
|---|
 | 1697 | + *  | 
|---|
 | 1698 | + *	Returns -EINVAL in case of error, 0 otherwise. If mapping falls into a  | 
|---|
 | 1699 | + *	hole, returns 0 and ``*block`` is also set to 0.  | 
|---|
| 1597 | 1700 |   */ | 
|---|
| 1598 |  | -sector_t bmap(struct inode *inode, sector_t block)  | 
|---|
 | 1701 | +int bmap(struct inode *inode, sector_t *block)  | 
|---|
| 1599 | 1702 |  { | 
|---|
| 1600 |  | -	sector_t res = 0;  | 
|---|
| 1601 |  | -	if (inode->i_mapping->a_ops->bmap)  | 
|---|
| 1602 |  | -		res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block);  | 
|---|
| 1603 |  | -	return res;  | 
|---|
 | 1703 | +	if (!inode->i_mapping->a_ops->bmap)  | 
|---|
 | 1704 | +		return -EINVAL;  | 
|---|
 | 1705 | +  | 
|---|
 | 1706 | +	*block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block);  | 
|---|
 | 1707 | +	return 0;  | 
|---|
| 1604 | 1708 |  } | 
|---|
| 1605 | 1709 |  EXPORT_SYMBOL(bmap); | 
|---|
 | 1710 | +#endif  | 
|---|
| 1606 | 1711 |   | 
|---|
| 1607 | 1712 |  /* | 
|---|
| 1608 | 1713 |   * With relative atime, only update atime if the previous atime is | 
|---|
| .. | .. | 
|---|
| 1610 | 1715 |   * passed since the last atime update. | 
|---|
| 1611 | 1716 |   */ | 
|---|
| 1612 | 1717 |  static int relatime_need_update(struct vfsmount *mnt, struct inode *inode, | 
|---|
| 1613 |  | -			     struct timespec now)  | 
|---|
 | 1718 | +			     struct timespec64 now)  | 
|---|
| 1614 | 1719 |  { | 
|---|
| 1615 | 1720 |   | 
|---|
| 1616 | 1721 |  	if (!(mnt->mnt_flags & MNT_RELATIME)) | 
|---|
| .. | .. | 
|---|
| 1666 | 1771 |   * This does the actual work of updating an inodes time or version.  Must have | 
|---|
| 1667 | 1772 |   * had called mnt_want_write() before calling this. | 
|---|
| 1668 | 1773 |   */ | 
|---|
| 1669 |  | -static int update_time(struct inode *inode, struct timespec64 *time, int flags)  | 
|---|
 | 1774 | +int inode_update_time(struct inode *inode, struct timespec64 *time, int flags)  | 
|---|
| 1670 | 1775 |  { | 
|---|
| 1671 |  | -	int (*update_time)(struct inode *, struct timespec64 *, int);  | 
|---|
| 1672 |  | -  | 
|---|
| 1673 |  | -	update_time = inode->i_op->update_time ? inode->i_op->update_time :  | 
|---|
| 1674 |  | -		generic_update_time;  | 
|---|
| 1675 |  | -  | 
|---|
| 1676 |  | -	return update_time(inode, time, flags);  | 
|---|
 | 1776 | +	if (inode->i_op->update_time)  | 
|---|
 | 1777 | +		return inode->i_op->update_time(inode, time, flags);  | 
|---|
 | 1778 | +	return generic_update_time(inode, time, flags);  | 
|---|
| 1677 | 1779 |  } | 
|---|
 | 1780 | +EXPORT_SYMBOL(inode_update_time);  | 
|---|
| 1678 | 1781 |   | 
|---|
| 1679 | 1782 |  /** | 
|---|
| 1680 | 1783 |   *	touch_atime	-	update the access time | 
|---|
| .. | .. | 
|---|
| 1711 | 1814 |   | 
|---|
| 1712 | 1815 |  	now = current_time(inode); | 
|---|
| 1713 | 1816 |   | 
|---|
| 1714 |  | -	if (!relatime_need_update(mnt, inode, timespec64_to_timespec(now)))  | 
|---|
 | 1817 | +	if (!relatime_need_update(mnt, inode, now))  | 
|---|
| 1715 | 1818 |  		return false; | 
|---|
| 1716 | 1819 |   | 
|---|
| 1717 | 1820 |  	if (timespec64_equal(&inode->i_atime, &now)) | 
|---|
| .. | .. | 
|---|
| 1744 | 1847 |  	 * of the fs read only, e.g. subvolumes in Btrfs. | 
|---|
| 1745 | 1848 |  	 */ | 
|---|
| 1746 | 1849 |  	now = current_time(inode); | 
|---|
| 1747 |  | -	update_time(inode, &now, S_ATIME);  | 
|---|
 | 1850 | +	inode_update_time(inode, &now, S_ATIME);  | 
|---|
| 1748 | 1851 |  	__mnt_drop_write(mnt); | 
|---|
| 1749 | 1852 |  skip_update: | 
|---|
| 1750 | 1853 |  	sb_end_write(inode->i_sb); | 
|---|
| 1751 | 1854 |  } | 
|---|
| 1752 |  | -EXPORT_SYMBOL(touch_atime);  | 
|---|
 | 1855 | +EXPORT_SYMBOL_NS(touch_atime, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 1753 | 1856 |   | 
|---|
| 1754 | 1857 |  /* | 
|---|
| 1755 | 1858 |   * The logic we want is | 
|---|
| .. | .. | 
|---|
| 1803 | 1906 |  	return mask; | 
|---|
| 1804 | 1907 |  } | 
|---|
| 1805 | 1908 |   | 
|---|
| 1806 |  | -static int __remove_privs(struct vfsmount *mnt, struct dentry *dentry, int kill)  | 
|---|
 | 1909 | +static int __remove_privs(struct dentry *dentry, int kill)  | 
|---|
| 1807 | 1910 |  { | 
|---|
| 1808 | 1911 |  	struct iattr newattrs; | 
|---|
| 1809 | 1912 |   | 
|---|
| .. | .. | 
|---|
| 1812 | 1915 |  	 * Note we call this on write, so notify_change will not | 
|---|
| 1813 | 1916 |  	 * encounter any conflicting delegations: | 
|---|
| 1814 | 1917 |  	 */ | 
|---|
| 1815 |  | -	return notify_change2(mnt, dentry, &newattrs, NULL);  | 
|---|
 | 1918 | +	return notify_change(dentry, &newattrs, NULL);  | 
|---|
| 1816 | 1919 |  } | 
|---|
| 1817 | 1920 |   | 
|---|
| 1818 | 1921 |  /* | 
|---|
| .. | .. | 
|---|
| 1839 | 1942 |  	if (kill < 0) | 
|---|
| 1840 | 1943 |  		return kill; | 
|---|
| 1841 | 1944 |  	if (kill) | 
|---|
| 1842 |  | -		error = __remove_privs(file->f_path.mnt, dentry, kill);  | 
|---|
 | 1945 | +		error = __remove_privs(dentry, kill);  | 
|---|
| 1843 | 1946 |  	if (!error) | 
|---|
| 1844 | 1947 |  		inode_has_no_xattr(inode); | 
|---|
| 1845 | 1948 |   | 
|---|
| 1846 | 1949 |  	return error; | 
|---|
| 1847 | 1950 |  } | 
|---|
| 1848 |  | -EXPORT_SYMBOL(file_remove_privs);  | 
|---|
 | 1951 | +EXPORT_SYMBOL_NS(file_remove_privs, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 1849 | 1952 |   | 
|---|
| 1850 | 1953 |  /** | 
|---|
| 1851 | 1954 |   *	file_update_time	-	update mtime and ctime time | 
|---|
| .. | .. | 
|---|
| 1888 | 1991 |  	if (__mnt_want_write_file(file)) | 
|---|
| 1889 | 1992 |  		return 0; | 
|---|
| 1890 | 1993 |   | 
|---|
| 1891 |  | -	ret = update_time(inode, &now, sync_it);  | 
|---|
 | 1994 | +	ret = inode_update_time(inode, &now, sync_it);  | 
|---|
| 1892 | 1995 |  	__mnt_drop_write_file(file); | 
|---|
| 1893 | 1996 |   | 
|---|
| 1894 | 1997 |  	return ret; | 
|---|
| 1895 | 1998 |  } | 
|---|
| 1896 | 1999 |  EXPORT_SYMBOL(file_update_time); | 
|---|
 | 2000 | +  | 
|---|
 | 2001 | +/* Caller must hold the file's inode lock */  | 
|---|
 | 2002 | +int file_modified(struct file *file)  | 
|---|
 | 2003 | +{  | 
|---|
 | 2004 | +	int err;  | 
|---|
 | 2005 | +  | 
|---|
 | 2006 | +	/*  | 
|---|
 | 2007 | +	 * Clear the security bits if the process is not being run by root.  | 
|---|
 | 2008 | +	 * This keeps people from modifying setuid and setgid binaries.  | 
|---|
 | 2009 | +	 */  | 
|---|
 | 2010 | +	err = file_remove_privs(file);  | 
|---|
 | 2011 | +	if (err)  | 
|---|
 | 2012 | +		return err;  | 
|---|
 | 2013 | +  | 
|---|
 | 2014 | +	if (unlikely(file->f_mode & FMODE_NOCMTIME))  | 
|---|
 | 2015 | +		return 0;  | 
|---|
 | 2016 | +  | 
|---|
 | 2017 | +	return file_update_time(file);  | 
|---|
 | 2018 | +}  | 
|---|
 | 2019 | +EXPORT_SYMBOL(file_modified);  | 
|---|
| 1897 | 2020 |   | 
|---|
| 1898 | 2021 |  int inode_needs_sync(struct inode *inode) | 
|---|
| 1899 | 2022 |  { | 
|---|
| .. | .. | 
|---|
| 2006 | 2129 |  				  " inode %s:%lu\n", mode, inode->i_sb->s_id, | 
|---|
| 2007 | 2130 |  				  inode->i_ino); | 
|---|
| 2008 | 2131 |  } | 
|---|
| 2009 |  | -EXPORT_SYMBOL(init_special_inode);  | 
|---|
 | 2132 | +EXPORT_SYMBOL_NS(init_special_inode, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 2010 | 2133 |   | 
|---|
| 2011 | 2134 |  /** | 
|---|
| 2012 | 2135 |   * inode_init_owner - Init uid,gid,mode for new inode according to posix standards | 
|---|
| .. | .. | 
|---|
| 2032 | 2155 |  		inode->i_gid = current_fsgid(); | 
|---|
| 2033 | 2156 |  	inode->i_mode = mode; | 
|---|
| 2034 | 2157 |  } | 
|---|
| 2035 |  | -EXPORT_SYMBOL(inode_init_owner);  | 
|---|
 | 2158 | +EXPORT_SYMBOL_NS(inode_init_owner, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 2036 | 2159 |   | 
|---|
| 2037 | 2160 |  /** | 
|---|
| 2038 | 2161 |   * inode_owner_or_capable - check current task permissions to inode | 
|---|
| .. | .. | 
|---|
| 2086 | 2209 |  	if (atomic_read(&inode->i_dio_count)) | 
|---|
| 2087 | 2210 |  		__inode_dio_wait(inode); | 
|---|
| 2088 | 2211 |  } | 
|---|
| 2089 |  | -EXPORT_SYMBOL(inode_dio_wait);  | 
|---|
 | 2212 | +EXPORT_SYMBOL_NS(inode_dio_wait, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 2090 | 2213 |   | 
|---|
| 2091 | 2214 |  /* | 
|---|
| 2092 | 2215 |   * inode_set_flags - atomically set some inode flags | 
|---|
| .. | .. | 
|---|
| 2107 | 2230 |  void inode_set_flags(struct inode *inode, unsigned int flags, | 
|---|
| 2108 | 2231 |  		     unsigned int mask) | 
|---|
| 2109 | 2232 |  { | 
|---|
| 2110 |  | -	unsigned int old_flags, new_flags;  | 
|---|
| 2111 |  | -  | 
|---|
| 2112 | 2233 |  	WARN_ON_ONCE(flags & ~mask); | 
|---|
| 2113 |  | -	do {  | 
|---|
| 2114 |  | -		old_flags = READ_ONCE(inode->i_flags);  | 
|---|
| 2115 |  | -		new_flags = (old_flags & ~mask) | flags;  | 
|---|
| 2116 |  | -	} while (unlikely(cmpxchg(&inode->i_flags, old_flags,  | 
|---|
| 2117 |  | -				  new_flags) != old_flags));  | 
|---|
 | 2234 | +	set_mask_bits(&inode->i_flags, mask, flags);  | 
|---|
| 2118 | 2235 |  } | 
|---|
| 2119 |  | -EXPORT_SYMBOL(inode_set_flags);  | 
|---|
 | 2236 | +EXPORT_SYMBOL_NS(inode_set_flags, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 2120 | 2237 |   | 
|---|
| 2121 | 2238 |  void inode_nohighmem(struct inode *inode) | 
|---|
| 2122 | 2239 |  { | 
|---|
| .. | .. | 
|---|
| 2125 | 2242 |  EXPORT_SYMBOL(inode_nohighmem); | 
|---|
| 2126 | 2243 |   | 
|---|
| 2127 | 2244 |  /** | 
|---|
| 2128 |  | - * timespec64_trunc - Truncate timespec64 to a granularity  | 
|---|
| 2129 |  | - * @t: Timespec64  | 
|---|
| 2130 |  | - * @gran: Granularity in ns.  | 
|---|
 | 2245 | + * timestamp_truncate - Truncate timespec to a granularity  | 
|---|
 | 2246 | + * @t: Timespec  | 
|---|
 | 2247 | + * @inode: inode being updated  | 
|---|
| 2131 | 2248 |   * | 
|---|
| 2132 |  | - * Truncate a timespec64 to a granularity. Always rounds down. gran must  | 
|---|
 | 2249 | + * Truncate a timespec to the granularity supported by the fs  | 
|---|
 | 2250 | + * containing the inode. Always rounds down. gran must  | 
|---|
| 2133 | 2251 |   * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns). | 
|---|
| 2134 | 2252 |   */ | 
|---|
| 2135 |  | -struct timespec64 timespec64_trunc(struct timespec64 t, unsigned gran)  | 
|---|
 | 2253 | +struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode)  | 
|---|
| 2136 | 2254 |  { | 
|---|
| 2137 |  | -	/* Avoid division in the common cases 1 ns and 1 s. */  | 
|---|
| 2138 |  | -	if (gran == 1) {  | 
|---|
| 2139 |  | -		/* nothing */  | 
|---|
| 2140 |  | -	} else if (gran == NSEC_PER_SEC) {  | 
|---|
 | 2255 | +	struct super_block *sb = inode->i_sb;  | 
|---|
 | 2256 | +	unsigned int gran = sb->s_time_gran;  | 
|---|
 | 2257 | +  | 
|---|
 | 2258 | +	t.tv_sec = clamp(t.tv_sec, sb->s_time_min, sb->s_time_max);  | 
|---|
 | 2259 | +	if (unlikely(t.tv_sec == sb->s_time_max || t.tv_sec == sb->s_time_min))  | 
|---|
| 2141 | 2260 |  		t.tv_nsec = 0; | 
|---|
| 2142 |  | -	} else if (gran > 1 && gran < NSEC_PER_SEC) {  | 
|---|
 | 2261 | +  | 
|---|
 | 2262 | +	/* Avoid division in the common cases 1 ns and 1 s. */  | 
|---|
 | 2263 | +	if (gran == 1)  | 
|---|
 | 2264 | +		; /* nothing */  | 
|---|
 | 2265 | +	else if (gran == NSEC_PER_SEC)  | 
|---|
 | 2266 | +		t.tv_nsec = 0;  | 
|---|
 | 2267 | +	else if (gran > 1 && gran < NSEC_PER_SEC)  | 
|---|
| 2143 | 2268 |  		t.tv_nsec -= t.tv_nsec % gran; | 
|---|
| 2144 |  | -	} else {  | 
|---|
| 2145 |  | -		WARN(1, "illegal file time granularity: %u", gran);  | 
|---|
| 2146 |  | -	}  | 
|---|
 | 2269 | +	else  | 
|---|
 | 2270 | +		WARN(1, "invalid file time granularity: %u", gran);  | 
|---|
| 2147 | 2271 |  	return t; | 
|---|
| 2148 | 2272 |  } | 
|---|
| 2149 |  | -EXPORT_SYMBOL(timespec64_trunc);  | 
|---|
 | 2273 | +EXPORT_SYMBOL_NS(timestamp_truncate, ANDROID_GKI_VFS_EXPORT_ONLY);  | 
|---|
| 2150 | 2274 |   | 
|---|
| 2151 | 2275 |  /** | 
|---|
| 2152 | 2276 |   * current_time - Return FS time | 
|---|
| .. | .. | 
|---|
| 2160 | 2284 |   */ | 
|---|
| 2161 | 2285 |  struct timespec64 current_time(struct inode *inode) | 
|---|
| 2162 | 2286 |  { | 
|---|
| 2163 |  | -	struct timespec64 now = current_kernel_time64();  | 
|---|
 | 2287 | +	struct timespec64 now;  | 
|---|
 | 2288 | +  | 
|---|
 | 2289 | +	ktime_get_coarse_real_ts64(&now);  | 
|---|
| 2164 | 2290 |   | 
|---|
| 2165 | 2291 |  	if (unlikely(!inode->i_sb)) { | 
|---|
| 2166 | 2292 |  		WARN(1, "current_time() called with uninitialized super_block in the inode"); | 
|---|
| 2167 | 2293 |  		return now; | 
|---|
| 2168 | 2294 |  	} | 
|---|
| 2169 | 2295 |   | 
|---|
| 2170 |  | -	return timespec64_trunc(now, inode->i_sb->s_time_gran);  | 
|---|
 | 2296 | +	return timestamp_truncate(now, inode);  | 
|---|
| 2171 | 2297 |  } | 
|---|
| 2172 | 2298 |  EXPORT_SYMBOL(current_time); | 
|---|
| 2173 | 2299 |   | 
|---|