From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-b6-smtp.messagingengine.com (fout-b6-smtp.messagingengine.com [202.12.124.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F27113090D7; Mon, 6 Apr 2026 05:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.149 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775454750; cv=none; b=hV+2zeKV8kjH3/YOENuQELwZizeju1VRHeFmPmAFDwW+6WHEa+CrSV7G37FvlcXKpTvoJjeVKsOWiyv4ovD6NdW10u4IpnKp5Z95TOlW08g3aVKYgor4aE3MnU+5VChTbbisVI/HINt9MxJVORUw9m4wr+ve8h2d931gqA8PvhE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775454750; c=relaxed/simple; bh=StyoTtiFauK1NiIHx2nmnaY/PWfJuf/+KfywM5p8fFw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XOjTJ6iyvonRiZPoGICzIsWRyLbX1rFmvxeD2lMtlHjEFwsCEUGykFIhRRc/yBqyo2xhkyyQo0qowleYoCKZOfdN0Fd9GyYZJIbIzSUCA6CPt/WY/qeb/IdHNqJm/6q94t0OkLt3svgnKBEb5QZo1mn0DvZLthdV37YHGHHlc0w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tyhicks.com; spf=pass smtp.mailfrom=tyhicks.com; dkim=pass (2048-bit key) header.d=tyhicks.com header.i=@tyhicks.com header.b=j2R1mifb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qVyahMET; arc=none smtp.client-ip=202.12.124.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tyhicks.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tyhicks.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tyhicks.com header.i=@tyhicks.com header.b="j2R1mifb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qVyahMET" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 236951D00060; Mon, 6 Apr 2026 01:52:28 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Mon, 06 Apr 2026 01:52:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tyhicks.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1775454747; x=1775541147; bh=Hcq4NYCmJB JQ46frfHk7PYTcI6CUok84E6cFHjFP7fw=; b=j2R1mifbFJTWpZkcvS5Ykl3wJF 1mcpSucTkJMqpGgmlI9Ld6RCrIHDPzIC1LbI1BQiXQmQMPWIvBrrh332jAbL27oo +0WRX8sD18funGAqvixE9i99czLMIfVR1H0jnFpkpyDLa5yJhQWboWRaBh9n2wHx 2e5RCvuAvBzN+HeprRf8I1UH5tu7vzUtt4AkADshM4Qhwji4vHR1fheIX+LFgPbJ XbpE00JTmTcfP8m3ogACxCFQsVy7eJhe4bv1mVgeY+N9PSmR+eBo3NN+YXebXl6g L+Dq11vY1ePrGIEfGsBXtrcbB/YK50wGll2vCYq0pg//9KSLseB4Xfb4urDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1775454747; x=1775541147; bh=Hcq4NYCmJBJQ46frfHk7PYTcI6CUok84E6c FHjFP7fw=; b=qVyahMET2Z569JWdszrlBQlEpb9uABMjS6eyWNcRoZiy1Og77lG ecATPFYNd2SwIXFwx5xJnfrkgNXZ/NRJgm95EBknrFaefzCI5OKgxiW67cHXKvb6 0tqe9LpnrqP0INc+TG4oU+7m4pLq3d4q8bxRwrWxxYOVryspCrTO4i1AxM1Miy7I u8AY4rLBMP+ctxD9R5lM2EgGy1l/UMal+lRrOCfzVyDUIWnpnqL1mwOSxkRm9INY 8252aW5cKpDXn8D1yM18CMQLyeqVQaeIgKh4LA60zTQs6X20OYPfk+1SKwmEMXjq cjdEvnvYokD4JfBc0eMO2deMWj2PgH/knBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduieeklecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdortddttddvnecuhfhrohhmpefvhihlvghrucfj ihgtkhhsuceotghouggvsehthihhihgtkhhsrdgtohhmqeenucggtffrrghtthgvrhhnpe ffudfhuddvheeuffeuffeftddukeeukeefgeevffdvgedvteffhfeigeeiheefvdenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegtohguvgesth ihhhhitghkshdrtghomhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohephhgthheslhhsthdruggvpdhrtghpthhtohepvggtrhihphhtfhhsse hvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgv lhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i78e14604:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Apr 2026 01:52:26 -0400 (EDT) Date: Mon, 6 Apr 2026 00:52:05 -0500 From: Tyler Hicks To: Christoph Hellwig Cc: ecryptfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 1/7] ecryptfs: streamline truncate_upper Message-ID: References: <20260331153752.4049454-1-hch@lst.de> <20260331153752.4049454-2-hch@lst.de> Precedence: bulk X-Mailing-List: ecryptfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260331153752.4049454-2-hch@lst.de> On 2026-03-31 17:37:22, Christoph Hellwig wrote: > Use a few strategic gotos to keep reduce indentation and keep the > main reduce size flow outside of branches. Switch all touched comments I think that first sentence was supposed to say, "Use a few strategic gotos to reduce indentation and keep the main flow outside of branches." Could you confirm? > to normal kernel style and avoid breaks in printed strings for all > the code touched. > > Signed-off-by: Christoph Hellwig > --- > fs/ecryptfs/inode.c | 115 +++++++++++++++++++++++--------------------- > 1 file changed, 60 insertions(+), 55 deletions(-) > > diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c > index 8ab014db3e03..cf20873a9cc4 100644 > --- a/fs/ecryptfs/inode.c > +++ b/fs/ecryptfs/inode.c > @@ -725,83 +725,88 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat, > static int truncate_upper(struct dentry *dentry, struct iattr *ia, > struct iattr *lower_ia) > { > - int rc = 0; > struct inode *inode = d_inode(dentry); > struct ecryptfs_crypt_stat *crypt_stat; > loff_t i_size = i_size_read(inode); > loff_t lower_size_before_truncate; > loff_t lower_size_after_truncate; > + size_t num_zeros; > + int rc; > > if (unlikely((ia->ia_size == i_size))) { > lower_ia->ia_valid &= ~ATTR_SIZE; > return 0; > } > + > rc = ecryptfs_get_lower_file(dentry, inode); > if (rc) > return rc; > - crypt_stat = &ecryptfs_inode_to_private(d_inode(dentry))->crypt_stat; > - /* Switch on growing or shrinking file */ > + > if (ia->ia_size > i_size) { > char zero[] = { 0x00 }; > > + /* > + * Write a single 0 at the last position of the file; this > + * triggers code that will fill in 0's throughout the > + * intermediate portion of the previous end of the file and the > + * new and of the file. Since we're touching this comment, we might as well fix the typo: s/new and of the file/new end of the file/ I can do both of these small changes when merging, if we don't have a better reason to respin this series. Tyler > + */ > + rc = ecryptfs_write(inode, zero, ia->ia_size - 1, 1); > lower_ia->ia_valid &= ~ATTR_SIZE; > - /* Write a single 0 at the last position of the file; > - * this triggers code that will fill in 0's throughout > - * the intermediate portion of the previous end of the > - * file and the new and of the file */ > - rc = ecryptfs_write(inode, zero, > - (ia->ia_size - 1), 1); > - } else { /* ia->ia_size < i_size_read(inode) */ > - /* We're chopping off all the pages down to the page > - * in which ia->ia_size is located. Fill in the end of > - * that page from (ia->ia_size & ~PAGE_MASK) to > - * PAGE_SIZE with zeros. */ > - size_t num_zeros = (PAGE_SIZE > - - (ia->ia_size & ~PAGE_MASK)); > - > - if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { > - truncate_setsize(inode, ia->ia_size); > - lower_ia->ia_size = ia->ia_size; > - lower_ia->ia_valid |= ATTR_SIZE; > - goto out; > - } > - if (num_zeros) { > - char *zeros_virt; > + goto out; > + } > > - zeros_virt = kzalloc(num_zeros, GFP_KERNEL); > - if (!zeros_virt) { > - rc = -ENOMEM; > - goto out; > - } > - rc = ecryptfs_write(inode, zeros_virt, > - ia->ia_size, num_zeros); > - kfree(zeros_virt); > - if (rc) { > - printk(KERN_ERR "Error attempting to zero out " > - "the remainder of the end page on " > - "reducing truncate; rc = [%d]\n", rc); > - goto out; > - } > - } > + crypt_stat = &ecryptfs_inode_to_private(d_inode(dentry))->crypt_stat; > + if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { > truncate_setsize(inode, ia->ia_size); > - rc = ecryptfs_write_inode_size_to_metadata(inode); > + lower_ia->ia_size = ia->ia_size; > + lower_ia->ia_valid |= ATTR_SIZE; > + goto out; > + } > + > + /* > + * We're chopping off all the pages down to the page in which > + * ia->ia_size is located. Fill in the end of that page from > + * (ia->ia_size & ~PAGE_MASK) to PAGE_SIZE with zeros. > + */ > + num_zeros = PAGE_SIZE - (ia->ia_size & ~PAGE_MASK); > + if (num_zeros) { > + char *zeros_virt; > + > + zeros_virt = kzalloc(num_zeros, GFP_KERNEL); > + if (!zeros_virt) { > + rc = -ENOMEM; > + goto out; > + } > + rc = ecryptfs_write(inode, zeros_virt, ia->ia_size, num_zeros); > + kfree(zeros_virt); > if (rc) { > - printk(KERN_ERR "Problem with " > - "ecryptfs_write_inode_size_to_metadata; " > - "rc = [%d]\n", rc); > + pr_err("Error attempting to zero out the remainder of the end page on reducing truncate; rc = [%d]\n", > + rc); > goto out; > } > - /* We are reducing the size of the ecryptfs file, and need to > - * know if we need to reduce the size of the lower file. */ > - lower_size_before_truncate = > - upper_size_to_lower_size(crypt_stat, i_size); > - lower_size_after_truncate = > - upper_size_to_lower_size(crypt_stat, ia->ia_size); > - if (lower_size_after_truncate < lower_size_before_truncate) { > - lower_ia->ia_size = lower_size_after_truncate; > - lower_ia->ia_valid |= ATTR_SIZE; > - } else > - lower_ia->ia_valid &= ~ATTR_SIZE; > + } > + truncate_setsize(inode, ia->ia_size); > + rc = ecryptfs_write_inode_size_to_metadata(inode); > + if (rc) { > + pr_err("Problem with ecryptfs_write_inode_size_to_metadata; rc = [%d]\n", > + rc); > + goto out; > + } > + > + /* > + * We are reducing the size of the ecryptfs file, and need to know if we > + * need to reduce the size of the lower file. > + */ > + lower_size_before_truncate = > + upper_size_to_lower_size(crypt_stat, i_size); > + lower_size_after_truncate = > + upper_size_to_lower_size(crypt_stat, ia->ia_size); > + if (lower_size_after_truncate < lower_size_before_truncate) { > + lower_ia->ia_size = lower_size_after_truncate; > + lower_ia->ia_valid |= ATTR_SIZE; > + } else { > + lower_ia->ia_valid &= ~ATTR_SIZE; > } > out: > ecryptfs_put_lower_file(inode); > -- > 2.47.3 >