shmem.c (5402b976ae0be96b3a32f3508ab7308c380d6477) | shmem.c (5b04c6890f0dc7ea6c85b9adebc883c55c667d97) |
---|---|
1/* 2 * Resizable virtual memory filesystem for Linux. 3 * 4 * Copyright (C) 2000 Linus Torvalds. 5 * 2000 Transmeta Corp. 6 * 2000-2001 Christoph Rohland 7 * 2000-2001 SAP AG 8 * 2002 Red Hat Inc. --- 191 unchanged lines hidden (view full) --- 200 if (sbinfo->max_blocks) { 201 spin_lock(&sbinfo->stat_lock); 202 sbinfo->free_blocks += pages; 203 inode->i_blocks -= pages*BLOCKS_PER_PAGE; 204 spin_unlock(&sbinfo->stat_lock); 205 } 206} 207 | 1/* 2 * Resizable virtual memory filesystem for Linux. 3 * 4 * Copyright (C) 2000 Linus Torvalds. 5 * 2000 Transmeta Corp. 6 * 2000-2001 Christoph Rohland 7 * 2000-2001 SAP AG 8 * 2002 Red Hat Inc. --- 191 unchanged lines hidden (view full) --- 200 if (sbinfo->max_blocks) { 201 spin_lock(&sbinfo->stat_lock); 202 sbinfo->free_blocks += pages; 203 inode->i_blocks -= pages*BLOCKS_PER_PAGE; 204 spin_unlock(&sbinfo->stat_lock); 205 } 206} 207 |
208static int shmem_reserve_inode(struct super_block *sb) 209{ 210 struct shmem_sb_info *sbinfo = SHMEM_SB(sb); 211 if (sbinfo->max_inodes) { 212 spin_lock(&sbinfo->stat_lock); 213 if (!sbinfo->free_inodes) { 214 spin_unlock(&sbinfo->stat_lock); 215 return -ENOSPC; 216 } 217 sbinfo->free_inodes--; 218 spin_unlock(&sbinfo->stat_lock); 219 } 220 return 0; 221} 222 223static void shmem_free_inode(struct super_block *sb) 224{ 225 struct shmem_sb_info *sbinfo = SHMEM_SB(sb); 226 if (sbinfo->max_inodes) { 227 spin_lock(&sbinfo->stat_lock); 228 sbinfo->free_inodes++; 229 spin_unlock(&sbinfo->stat_lock); 230 } 231} 232 |
|
208/* 209 * shmem_recalc_inode - recalculate the size of an inode 210 * 211 * @inode: inode to recalc 212 * 213 * We have to calculate the free blocks since the mm can drop 214 * undirtied hole pages behind our back. 215 * --- 541 unchanged lines hidden (view full) --- 757#endif 758 if (page) 759 page_cache_release(page); 760 return error; 761} 762 763static void shmem_delete_inode(struct inode *inode) 764{ | 233/* 234 * shmem_recalc_inode - recalculate the size of an inode 235 * 236 * @inode: inode to recalc 237 * 238 * We have to calculate the free blocks since the mm can drop 239 * undirtied hole pages behind our back. 240 * --- 541 unchanged lines hidden (view full) --- 782#endif 783 if (page) 784 page_cache_release(page); 785 return error; 786} 787 788static void shmem_delete_inode(struct inode *inode) 789{ |
765 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); | |
766 struct shmem_inode_info *info = SHMEM_I(inode); 767 768 if (inode->i_op->truncate == shmem_truncate) { 769 truncate_inode_pages(inode->i_mapping, 0); 770 shmem_unacct_size(info->flags, inode->i_size); 771 inode->i_size = 0; 772 shmem_truncate(inode); 773 if (!list_empty(&info->swaplist)) { 774 spin_lock(&shmem_swaplist_lock); 775 list_del_init(&info->swaplist); 776 spin_unlock(&shmem_swaplist_lock); 777 } 778 } 779 BUG_ON(inode->i_blocks); | 790 struct shmem_inode_info *info = SHMEM_I(inode); 791 792 if (inode->i_op->truncate == shmem_truncate) { 793 truncate_inode_pages(inode->i_mapping, 0); 794 shmem_unacct_size(info->flags, inode->i_size); 795 inode->i_size = 0; 796 shmem_truncate(inode); 797 if (!list_empty(&info->swaplist)) { 798 spin_lock(&shmem_swaplist_lock); 799 list_del_init(&info->swaplist); 800 spin_unlock(&shmem_swaplist_lock); 801 } 802 } 803 BUG_ON(inode->i_blocks); |
780 if (sbinfo->max_inodes) { 781 spin_lock(&sbinfo->stat_lock); 782 sbinfo->free_inodes++; 783 spin_unlock(&sbinfo->stat_lock); 784 } | 804 shmem_free_inode(inode->i_sb); |
785 clear_inode(inode); 786} 787 788static inline int shmem_find_swp(swp_entry_t entry, swp_entry_t *dir, swp_entry_t *edir) 789{ 790 swp_entry_t *ptr; 791 792 for (ptr = dir; ptr < edir; ptr++) { --- 573 unchanged lines hidden (view full) --- 1366 1367static struct inode * 1368shmem_get_inode(struct super_block *sb, int mode, dev_t dev) 1369{ 1370 struct inode *inode; 1371 struct shmem_inode_info *info; 1372 struct shmem_sb_info *sbinfo = SHMEM_SB(sb); 1373 | 805 clear_inode(inode); 806} 807 808static inline int shmem_find_swp(swp_entry_t entry, swp_entry_t *dir, swp_entry_t *edir) 809{ 810 swp_entry_t *ptr; 811 812 for (ptr = dir; ptr < edir; ptr++) { --- 573 unchanged lines hidden (view full) --- 1386 1387static struct inode * 1388shmem_get_inode(struct super_block *sb, int mode, dev_t dev) 1389{ 1390 struct inode *inode; 1391 struct shmem_inode_info *info; 1392 struct shmem_sb_info *sbinfo = SHMEM_SB(sb); 1393 |
1374 if (sbinfo->max_inodes) { 1375 spin_lock(&sbinfo->stat_lock); 1376 if (!sbinfo->free_inodes) { 1377 spin_unlock(&sbinfo->stat_lock); 1378 return NULL; 1379 } 1380 sbinfo->free_inodes--; 1381 spin_unlock(&sbinfo->stat_lock); 1382 } | 1394 if (shmem_reserve_inode(sb)) 1395 return NULL; |
1383 1384 inode = new_inode(sb); 1385 if (inode) { 1386 inode->i_mode = mode; 1387 inode->i_uid = current->fsuid; 1388 inode->i_gid = current->fsgid; 1389 inode->i_blocks = 0; 1390 inode->i_mapping->a_ops = &shmem_aops; --- 27 unchanged lines hidden (view full) --- 1418 /* 1419 * Must not load anything in the rbtree, 1420 * mpol_free_shared_policy will not be called. 1421 */ 1422 mpol_shared_policy_init(&info->policy, MPOL_DEFAULT, 1423 NULL); 1424 break; 1425 } | 1396 1397 inode = new_inode(sb); 1398 if (inode) { 1399 inode->i_mode = mode; 1400 inode->i_uid = current->fsuid; 1401 inode->i_gid = current->fsgid; 1402 inode->i_blocks = 0; 1403 inode->i_mapping->a_ops = &shmem_aops; --- 27 unchanged lines hidden (view full) --- 1431 /* 1432 * Must not load anything in the rbtree, 1433 * mpol_free_shared_policy will not be called. 1434 */ 1435 mpol_shared_policy_init(&info->policy, MPOL_DEFAULT, 1436 NULL); 1437 break; 1438 } |
1426 } else if (sbinfo->max_inodes) { 1427 spin_lock(&sbinfo->stat_lock); 1428 sbinfo->free_inodes++; 1429 spin_unlock(&sbinfo->stat_lock); 1430 } | 1439 } else 1440 shmem_free_inode(sb); |
1431 return inode; 1432} 1433 1434#ifdef CONFIG_TMPFS 1435static const struct inode_operations shmem_symlink_inode_operations; 1436static const struct inode_operations shmem_symlink_inline_operations; 1437 1438/* --- 226 unchanged lines hidden (view full) --- 1665} 1666 1667/* 1668 * Link a file.. 1669 */ 1670static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 1671{ 1672 struct inode *inode = old_dentry->d_inode; | 1441 return inode; 1442} 1443 1444#ifdef CONFIG_TMPFS 1445static const struct inode_operations shmem_symlink_inode_operations; 1446static const struct inode_operations shmem_symlink_inline_operations; 1447 1448/* --- 226 unchanged lines hidden (view full) --- 1675} 1676 1677/* 1678 * Link a file.. 1679 */ 1680static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 1681{ 1682 struct inode *inode = old_dentry->d_inode; |
1673 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); | 1683 int ret; |
1674 1675 /* 1676 * No ordinary (disk based) filesystem counts links as inodes; 1677 * but each new link needs a new dentry, pinning lowmem, and 1678 * tmpfs dentries cannot be pruned until they are unlinked. 1679 */ | 1684 1685 /* 1686 * No ordinary (disk based) filesystem counts links as inodes; 1687 * but each new link needs a new dentry, pinning lowmem, and 1688 * tmpfs dentries cannot be pruned until they are unlinked. 1689 */ |
1680 if (sbinfo->max_inodes) { 1681 spin_lock(&sbinfo->stat_lock); 1682 if (!sbinfo->free_inodes) { 1683 spin_unlock(&sbinfo->stat_lock); 1684 return -ENOSPC; 1685 } 1686 sbinfo->free_inodes--; 1687 spin_unlock(&sbinfo->stat_lock); 1688 } | 1690 ret = shmem_reserve_inode(inode->i_sb); 1691 if (ret) 1692 goto out; |
1689 1690 dir->i_size += BOGO_DIRENT_SIZE; 1691 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 1692 inc_nlink(inode); 1693 atomic_inc(&inode->i_count); /* New dentry reference */ 1694 dget(dentry); /* Extra pinning count for the created dentry */ 1695 d_instantiate(dentry, inode); | 1693 1694 dir->i_size += BOGO_DIRENT_SIZE; 1695 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 1696 inc_nlink(inode); 1697 atomic_inc(&inode->i_count); /* New dentry reference */ 1698 dget(dentry); /* Extra pinning count for the created dentry */ 1699 d_instantiate(dentry, inode); |
1696 return 0; | 1700out: 1701 return ret; |
1697} 1698 1699static int shmem_unlink(struct inode *dir, struct dentry *dentry) 1700{ 1701 struct inode *inode = dentry->d_inode; 1702 | 1702} 1703 1704static int shmem_unlink(struct inode *dir, struct dentry *dentry) 1705{ 1706 struct inode *inode = dentry->d_inode; 1707 |
1703 if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode)) { 1704 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); 1705 if (sbinfo->max_inodes) { 1706 spin_lock(&sbinfo->stat_lock); 1707 sbinfo->free_inodes++; 1708 spin_unlock(&sbinfo->stat_lock); 1709 } 1710 } | 1708 if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode)) 1709 shmem_free_inode(inode->i_sb); |
1711 1712 dir->i_size -= BOGO_DIRENT_SIZE; 1713 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 1714 drop_nlink(inode); 1715 dput(dentry); /* Undo the count from "create" - this does all the work */ 1716 return 0; 1717} 1718 --- 743 unchanged lines hidden --- | 1710 1711 dir->i_size -= BOGO_DIRENT_SIZE; 1712 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 1713 drop_nlink(inode); 1714 dput(dentry); /* Undo the count from "create" - this does all the work */ 1715 return 0; 1716} 1717 --- 743 unchanged lines hidden --- |