From: Tyler Hicks <code@tyhicks.com>
To: Christoph Hellwig <hch@lst.de>
Cc: ecryptfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 7/7] ecryptfs: call notify_change from truncate_upper
Date: Mon, 6 Apr 2026 01:52:11 -0500 [thread overview]
Message-ID: <adNYG1QzgRvBFm5n@yaupon> (raw)
In-Reply-To: <20260331153752.4049454-8-hch@lst.de>
On 2026-03-31 17:37:28, Christoph Hellwig wrote:
> Keep all the truncation logic in one place by also moving the call to
> notify_change into truncate_upper. 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>
> ---
> fs/ecryptfs/inode.c | 61 +++++++++++++++++++++------------------------
> 1 file changed, 28 insertions(+), 33 deletions(-)
>
> diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
> index c87ee3c6ecba..256beed0e47d 100644
> --- a/fs/ecryptfs/inode.c
> +++ b/fs/ecryptfs/inode.c
> @@ -707,7 +707,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
> }
>
> /**
> - * truncate_upper
> + * __ecryptfs_truncate
> * @dentry: The ecryptfs layer dentry
> * @lower_ia: Address of the lower inode's attributes
> *
> @@ -721,9 +721,10 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
> *
> * Returns zero on success; non-zero otherwise
> */
> -static int truncate_upper(struct dentry *dentry, struct iattr *lower_ia)
> +static int __ecryptfs_truncate(struct dentry *dentry, struct iattr *lower_ia)
Could you update the function documentation, as well? This sentence is
no longer true:
* ... If ATTR_SIZE is set in lower_ia->ia_valid upon return,
* the caller must use lower_ia in a call to notify_change() to perform
* the truncation of the lower inode.
The rest looks good.
Tyler
> {
> struct inode *inode = d_inode(dentry);
> + struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
> struct ecryptfs_crypt_stat *crypt_stat;
> loff_t i_size = i_size_read(inode);
> loff_t lower_size_before_truncate;
> @@ -731,10 +732,8 @@ static int truncate_upper(struct dentry *dentry, struct iattr *lower_ia)
> size_t num_zeros;
> int rc;
>
> - if (unlikely(lower_ia->ia_size == i_size)) {
> - lower_ia->ia_valid &= ~ATTR_SIZE;
> + if (unlikely(lower_ia->ia_size == i_size))
> return 0;
> - }
>
> crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
> lower_size_before_truncate =
> @@ -767,13 +766,12 @@ static int truncate_upper(struct dentry *dentry, struct iattr *lower_ia)
> * new and of the file.
> */
> rc = ecryptfs_write(inode, zero, lower_ia->ia_size - 1, 1);
> - lower_ia->ia_valid &= ~ATTR_SIZE;
> goto out;
> }
>
> if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
> truncate_setsize(inode, lower_ia->ia_size);
> - goto out;
> + goto set_size;
> }
>
> /*
> @@ -803,10 +801,14 @@ static int truncate_upper(struct dentry *dentry, struct iattr *lower_ia)
> * We are reducing the size of the ecryptfs file, and need to know if we
> * need to reduce the size of the lower file.
> */
> - if (lower_size_after_truncate < lower_size_before_truncate)
> - lower_ia->ia_size = lower_size_after_truncate;
> - else
> - lower_ia->ia_valid &= ~ATTR_SIZE;
> + if (lower_size_after_truncate >= lower_size_before_truncate)
> + goto out;
> +
> + lower_ia->ia_size = lower_size_after_truncate;
> +set_size:
> + inode_lock(d_inode(lower_dentry));
> + rc = notify_change(&nop_mnt_idmap, lower_dentry, lower_ia, NULL);
> + inode_unlock(d_inode(lower_dentry));
> out:
> ecryptfs_put_lower_file(inode);
> return rc;
> @@ -828,18 +830,8 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
> .ia_valid = ATTR_SIZE,
> .ia_size = new_length,
> };
> - int rc;
> -
> - rc = truncate_upper(dentry, &lower_ia);
> - if (!rc && lower_ia.ia_valid & ATTR_SIZE) {
> - struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
>
> - inode_lock(d_inode(lower_dentry));
> - rc = notify_change(&nop_mnt_idmap, lower_dentry,
> - &lower_ia, NULL);
> - inode_unlock(d_inode(lower_dentry));
> - }
> - return rc;
> + return __ecryptfs_truncate(dentry, &lower_ia);
> }
>
> static int
> @@ -867,7 +859,6 @@ static int ecryptfs_setattr(struct mnt_idmap *idmap,
> struct dentry *dentry, struct iattr *ia)
> {
> struct inode *inode = d_inode(dentry);
> - struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
> struct inode *lower_inode = ecryptfs_inode_to_lower(inode);
> struct iattr lower_ia;
> struct ecryptfs_crypt_stat *crypt_stat;
> @@ -918,13 +909,6 @@ static int ecryptfs_setattr(struct mnt_idmap *idmap,
> goto out;
>
> memcpy(&lower_ia, ia, sizeof(lower_ia));
> - if (ia->ia_valid & ATTR_FILE)
> - lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
> - if (ia->ia_valid & ATTR_SIZE) {
> - rc = truncate_upper(dentry, &lower_ia);
> - if (rc < 0)
> - goto out;
> - }
>
> /*
> * mode change is for clearing setuid/setgid bits. Allow lower fs
> @@ -933,9 +917,20 @@ static int ecryptfs_setattr(struct mnt_idmap *idmap,
> if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
> lower_ia.ia_valid &= ~ATTR_MODE;
>
> - inode_lock(d_inode(lower_dentry));
> - rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL);
> - inode_unlock(d_inode(lower_dentry));
> + if (ia->ia_valid & ATTR_SIZE) {
> + if (ia->ia_valid & ATTR_FILE)
> + lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
> + rc = __ecryptfs_truncate(dentry, &lower_ia);
> + if (rc < 0)
> + goto out;
> + } else {
> + struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
> +
> + inode_lock(d_inode(lower_dentry));
> + rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia,
> + NULL);
> + inode_unlock(d_inode(lower_dentry));
> + }
> out:
> fsstack_copy_attr_all(inode, lower_inode);
> return rc;
> --
> 2.47.3
>
next prev parent reply other threads:[~2026-04-06 6:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 15:37 cleanup truncate handling in ecryptfs Christoph Hellwig
2026-03-31 15:37 ` [PATCH 1/7] ecryptfs: streamline truncate_upper Christoph Hellwig
2026-04-06 5:52 ` Tyler Hicks
2026-04-06 6:28 ` Christoph Hellwig
2026-03-31 15:37 ` [PATCH 2/7] ecryptfs: cleanup ecryptfs_setattr Christoph Hellwig
2026-04-06 5:52 ` Tyler Hicks
2026-03-31 15:37 ` [PATCH 3/7] ecryptfs: use ZERO_PAGE instead of allocating zeroed memory in truncate_upper Christoph Hellwig
2026-04-06 5:52 ` Tyler Hicks
2026-03-31 15:37 ` [PATCH 4/7] ecryptfs: combine the two ATTR_SIZE blocks in ecryptfs_setattr Christoph Hellwig
2026-04-06 5:53 ` Tyler Hicks
2026-03-31 15:37 ` [PATCH 5/7] ecryptfs: sanitize struct iattr handling in truncate_upper Christoph Hellwig
2026-04-06 5:58 ` Tyler Hicks
2026-04-06 6:22 ` Tyler Hicks
2026-04-06 6:27 ` Christoph Hellwig
2026-04-06 6:59 ` Tyler Hicks
2026-03-31 15:37 ` [PATCH 6/7] ecryptfs: merge ecryptfs_inode_newsize_ok into truncate_upper Christoph Hellwig
2026-04-06 6:09 ` Tyler Hicks
2026-03-31 15:37 ` [PATCH 7/7] ecryptfs: call notify_change from truncate_upper Christoph Hellwig
2026-04-06 6:52 ` Tyler Hicks [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-04-07 14:02 cleanup truncate handling in ecryptfs v2 Christoph Hellwig
2026-04-07 14:02 ` [PATCH 7/7] ecryptfs: call notify_change from truncate_upper Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adNYG1QzgRvBFm5n@yaupon \
--to=code@tyhicks.com \
--cc=ecryptfs@vger.kernel.org \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox