Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ecryptfs: keep the lower iattr contained in truncate_upper

Currently the two callers of truncate_upper handle passing information
very differently. ecryptfs_truncate passes a zeroed lower_ia and expects
truncate_upper to fill it in from the upper ia created just for that,
while ecryptfs_setattr passes a fully initialized lower_ia copied from
the upper one. Both of them then call notify_change on the lower_ia.

Switch to only passing the upper ia, and derive the lower ia from it
inside truncate_upper, and call notify_change inside the function itself.
Because the old name is misleading now, rename the resulting function to
__ecryptfs_truncate as it deals with both the lower and upper inodes.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Tyler Hicks <code@tyhicks.com>

authored by

Christoph Hellwig and committed by
Tyler Hicks
e836ec18 5d1f0e8c

+37 -47
+37 -47
fs/ecryptfs/inode.c
··· 721 721 } 722 722 723 723 /** 724 - * truncate_upper 724 + * __ecryptfs_truncate 725 725 * @dentry: The ecryptfs layer dentry 726 726 * @ia: Address of the ecryptfs inode's attributes 727 - * @lower_ia: Address of the lower inode's attributes 728 727 * 729 - * Function to handle truncations modifying the size of the file. Note 730 - * that the file sizes are interpolated. When expanding, we are simply 731 - * writing strings of 0's out. When truncating, we truncate the upper 732 - * inode and update the lower_ia according to the page index 733 - * interpolations. If ATTR_SIZE is set in lower_ia->ia_valid upon return, 734 - * the caller must use lower_ia in a call to notify_change() to perform 735 - * the truncation of the lower inode. 728 + * Handle truncations modifying the size of the file. Note that the file sizes 729 + * are interpolated. When expanding, we are simply writing strings of 0's out. 730 + * When truncating, we truncate the upper inode and update the lower_ia 731 + * according to the page index interpolations. 736 732 * 737 733 * Returns zero on success; non-zero otherwise 738 734 */ 739 - static int truncate_upper(struct dentry *dentry, struct iattr *ia, 740 - struct iattr *lower_ia) 735 + static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia) 741 736 { 737 + struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 742 738 struct inode *inode = d_inode(dentry); 743 739 struct ecryptfs_crypt_stat *crypt_stat; 744 740 loff_t i_size = i_size_read(inode); 745 741 loff_t lower_size_before_truncate; 746 742 loff_t lower_size_after_truncate; 743 + struct iattr lower_ia; 747 744 size_t num_zeros; 748 745 int rc; 749 746 750 - if (unlikely((ia->ia_size == i_size))) { 751 - lower_ia->ia_valid &= ~ATTR_SIZE; 747 + ecryptfs_iattr_to_lower(&lower_ia, ia); 748 + 749 + if (unlikely((ia->ia_size == i_size))) 752 750 return 0; 753 - } 754 751 755 752 crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat; 756 753 lower_size_before_truncate = ··· 780 783 * new end of the file. 781 784 */ 782 785 rc = ecryptfs_write(inode, zero, ia->ia_size - 1, 1); 783 - lower_ia->ia_valid &= ~ATTR_SIZE; 784 786 goto out; 785 787 } 786 788 787 789 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { 788 790 truncate_setsize(inode, ia->ia_size); 789 - lower_ia->ia_size = ia->ia_size; 790 - lower_ia->ia_valid |= ATTR_SIZE; 791 - goto out; 791 + lower_ia.ia_size = ia->ia_size; 792 + goto set_size; 792 793 } 793 794 794 795 /* ··· 816 821 * We are reducing the size of the ecryptfs file, and need to know if we 817 822 * need to reduce the size of the lower file. 818 823 */ 819 - if (lower_size_after_truncate < lower_size_before_truncate) { 820 - lower_ia->ia_size = lower_size_after_truncate; 821 - lower_ia->ia_valid |= ATTR_SIZE; 822 - } else { 823 - lower_ia->ia_valid &= ~ATTR_SIZE; 824 - } 824 + if (lower_size_after_truncate >= lower_size_before_truncate) 825 + goto out; 826 + 827 + lower_ia.ia_size = lower_size_after_truncate; 828 + set_size: 829 + lower_ia.ia_valid |= ATTR_SIZE; 830 + inode_lock(d_inode(lower_dentry)); 831 + rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL); 832 + inode_unlock(d_inode(lower_dentry)); 825 833 out: 826 834 ecryptfs_put_lower_file(inode); 827 835 return rc; ··· 842 844 */ 843 845 int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) 844 846 { 845 - struct iattr ia = { .ia_valid = ATTR_SIZE, .ia_size = new_length }; 846 - struct iattr lower_ia = { .ia_valid = 0 }; 847 - int rc; 847 + const struct iattr ia = { 848 + .ia_valid = ATTR_SIZE, 849 + .ia_size = new_length, 850 + }; 848 851 849 - rc = truncate_upper(dentry, &ia, &lower_ia); 850 - if (!rc && lower_ia.ia_valid & ATTR_SIZE) { 851 - struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 852 - 853 - inode_lock(d_inode(lower_dentry)); 854 - rc = notify_change(&nop_mnt_idmap, lower_dentry, 855 - &lower_ia, NULL); 856 - inode_unlock(d_inode(lower_dentry)); 857 - } 858 - return rc; 852 + return __ecryptfs_truncate(dentry, &ia); 859 853 } 860 854 861 855 static int ··· 877 887 struct inode *inode = d_inode(dentry); 878 888 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 879 889 struct inode *lower_inode = ecryptfs_inode_to_lower(inode); 880 - struct iattr lower_ia; 881 890 struct ecryptfs_crypt_stat *crypt_stat; 882 891 int rc; 883 892 ··· 924 935 if (rc) 925 936 goto out; 926 937 927 - ecryptfs_iattr_to_lower(&lower_ia, ia); 928 938 if (ia->ia_valid & ATTR_SIZE) { 929 - rc = truncate_upper(dentry, ia, &lower_ia); 930 - if (rc < 0) 931 - goto out; 939 + rc = __ecryptfs_truncate(dentry, ia); 940 + } else { 941 + struct iattr lower_ia; 942 + 943 + ecryptfs_iattr_to_lower(&lower_ia, ia); 944 + 945 + inode_lock(d_inode(lower_dentry)); 946 + rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, 947 + NULL); 948 + inode_unlock(d_inode(lower_dentry)); 932 949 } 933 - 934 - 935 - inode_lock(d_inode(lower_dentry)); 936 - rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL); 937 - inode_unlock(d_inode(lower_dentry)); 938 950 out: 939 951 fsstack_copy_attr_all(inode, lower_inode); 940 952 return rc;