From patchwork Tue Jan 24 12:17:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113904 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 998F1C61D97 for ; Tue, 24 Jan 2023 12:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233609AbjAXMST (ORCPT ); Tue, 24 Jan 2023 07:18:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233422AbjAXMSR (ORCPT ); Tue, 24 Jan 2023 07:18:17 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C23E23525E for ; Tue, 24 Jan 2023 04:18:15 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 777081FE1C; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DRI4qWEv0uFDa3q6P9RZRAilZAK3cVMS+OYZbEt17mg=; b=lAAZaW/nzU1h4hJ38awEwy0UO1/Mw6IGXo7EivqBbgjFcTtOSCBDM77U6pT1GuQajEUWF7 spwNEu5lHVCakzahomYNkKKPDJgx6ly0M95H1jA4j3zOPlmQ9NnniFgMsFAuoujoz/bqsy n0sBegeMXb/TKKDKu1TS69eEfRy7JU8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DRI4qWEv0uFDa3q6P9RZRAilZAK3cVMS+OYZbEt17mg=; b=0kSrJCUgmEMyL+slFj15pqCSciW5ZpVUf5LjSkJzuNZ8rP6ncK1EFfAhPb6SrQ8y842VeP n0uLDL58wYJQdWBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 65E6C139FB; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id FyfgGIbMz2PINwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 07E59A06B6; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 01/22] udf: Unify types in anchor block detection Date: Tue, 24 Jan 2023 13:17:47 +0100 Message-Id: <20230124121814.25951-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2669; i=jack@suse.cz; h=from:subject; bh=bE8hHAl123golhXRKX5pttpZsk9gLScyiYZp9PnIOkg=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xtxW4zE1ierehLJXHdRbE6z36DcBOnDA9ThX3F u3RJr/yJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MbQAKCRCcnaoHP2RA2fi2CA DUFfS71rbZkj2p741h4tYv01C0QywkhQEMFRVG4+uSt60++yNcRJFEIQATTSZI48AbyelNnuhTuL9j kJRymu5OsDdRa+zHzuo0yeUspFlAq6P+hesLa/bwLjmbBdsaQJneCqyAPe4G4IXJtiO8jDQKBXCK0M lnnZFdcOYhLEPX2leydy1Tie7/Ewo0Ee7iTLOCFZfBUCl7BxQ/9GM9us2WxL9gBgiB+uiKnvEhG6QW d06GcBUAjW/O84/MC0qNzQytgXfX6dR5SzzGBAdsBLR7fW/u2YkuT3kaKgNheJD5/rwCnHzYzbfwoc YIz4iAG6UEw4mm3Gx56A4arb+CLK0f X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When detecting last recorded block and from it derived anchor block position, we were mixing unsigned long, u32, and sector_t types. Since udf supports only 32-bit block numbers this is harmless but sometimes makes things awkward. Convert everything to udf_pblk_t and also handle the situation when block device size would not fit into udf_pblk_t. Signed-off-by: Jan Kara --- fs/udf/lowlevel.c | 7 +++++-- fs/udf/super.c | 4 ++-- fs/udf/udfdecl.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/udf/lowlevel.c b/fs/udf/lowlevel.c index 46d697172197..c87ed942d076 100644 --- a/fs/udf/lowlevel.c +++ b/fs/udf/lowlevel.c @@ -45,7 +45,7 @@ unsigned int udf_get_last_session(struct super_block *sb) return 0; } -unsigned long udf_get_last_block(struct super_block *sb) +udf_pblk_t udf_get_last_block(struct super_block *sb) { struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk); unsigned long lblock = 0; @@ -54,8 +54,11 @@ unsigned long udf_get_last_block(struct super_block *sb) * The cdrom layer call failed or returned obviously bogus value? * Try using the device size... */ - if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0) + if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0) { + if (sb_bdev_nr_blocks(sb) > ~(udf_pblk_t)0) + return 0; lblock = sb_bdev_nr_blocks(sb); + } if (lblock) return lblock - 1; diff --git a/fs/udf/super.c b/fs/udf/super.c index 241b40e886b3..c756d903a862 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -1861,10 +1861,10 @@ static int udf_check_anchor_block(struct super_block *sb, sector_t block, * Returns < 0 on error, 0 on success. -EAGAIN is special - try next set * of anchors. */ -static int udf_scan_anchors(struct super_block *sb, sector_t *lastblock, +static int udf_scan_anchors(struct super_block *sb, udf_pblk_t *lastblock, struct kernel_lb_addr *fileset) { - sector_t last[6]; + udf_pblk_t last[6]; int i; struct udf_sb_info *sbi = UDF_SB(sb); int last_count = 0; diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index d35aa42bb577..eaf9e6fd201e 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -196,7 +196,7 @@ extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int); /* lowlevel.c */ extern unsigned int udf_get_last_session(struct super_block *); -extern unsigned long udf_get_last_block(struct super_block *); +udf_pblk_t udf_get_last_block(struct super_block *); /* partition.c */ extern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t, From patchwork Tue Jan 24 12:17:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47E79C38142 for ; Tue, 24 Jan 2023 12:18:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233652AbjAXMS0 (ORCPT ); Tue, 24 Jan 2023 07:18:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233581AbjAXMSS (ORCPT ); Tue, 24 Jan 2023 07:18:18 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C960037F0D for ; Tue, 24 Jan 2023 04:18:15 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8AA7B2188D; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NrTzcsfeVSPhQW4+qHyxmsmg9W/1UUS0Rh80tO0reIE=; b=gnbd1krrrNydf5atCF8CaDAeU/l3xJA7pqOVc0UxlKdknVkvlUaR75KlWLIiw0NUaKePSf l0PkNX/mMMuPjmBAj8ll9p7hkkbs/NKdu0ekqaiTbKG7q5wMEnlmmTZi0e1ZgsFGkDXg3j 7Ot6Di6dyC4yc854QBGQb3l/re61vJ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NrTzcsfeVSPhQW4+qHyxmsmg9W/1UUS0Rh80tO0reIE=; b=9dE7RHTDnGBvZMWCjOtStwuZ8rpew1M6OYUXvQwlSSX4/qRgYojixAr4JzaQnJh6U6PKlk TUWZdfp6rLjVglCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 76CC1139FF; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wcD4HIbMz2PJNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 0CEF8A06B9; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 02/22] udf: Drop VARCONV support Date: Tue, 24 Jan 2023 13:17:48 +0100 Message-Id: <20230124121814.25951-2-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=10655; i=jack@suse.cz; h=from:subject; bh=X7SvJp8qryRXT2VYhNSSebNhMWTQtYVZuXIh3NOB+Ro=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xuG5rW51uktuSIsv9OO6nAV2AFoc/mtuv3qYoM d6cU5XiJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MbgAKCRCcnaoHP2RA2co4B/ 9la0IYhk22P/0tajAe+dsdSIlwRRik9xnNa6Wpwz7rHns+5MgOjrwbFQQBwp1pTFpTkJMFMQBUxW4T Jw1IVZJkc1MG1Y6nf9t/C29v0qbRNQ1n9PitL2bBPHkW0yqEXT0n3JmWtWmfmLQONXYRQJHEDgYG2U qaVra7sTNmD9c6chyJNWZfTEVFrVD2ajT1l79mowai/+BE0xRF1NMRcKiZLuM+Lk9iuhL2q4HWDmIh KI8tb+7IrtUhkmQpYyNqHxl2o/hPAM8EOB2C5AhOLMcwyIPPrQ1k5D0rpgQGz5X561+Hh0AI0ZFdxT ZROWFKME5L/XGx4b+zwYk4lkAzAOCX X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org UDF was supporting a strange mode where the media was containing 7 blocks of unknown data for every 32 blocks of the filesystem. I have yet to see the media that would need such conversion (maybe it comes from packet writing times) and the conversions have been inconsistent in the code. In particular any write will write to a wrong block and corrupt the media. This is an indication and no user actually needs this so let's just drop the support instead of trying to fix it. Signed-off-by: Jan Kara --- fs/udf/balloc.c | 2 +- fs/udf/directory.c | 4 ++-- fs/udf/inode.c | 11 ++++------ fs/udf/misc.c | 18 +---------------- fs/udf/namei.c | 4 ++-- fs/udf/super.c | 50 +++------------------------------------------- fs/udf/truncate.c | 2 +- fs/udf/udf_sb.h | 1 - fs/udf/udfdecl.h | 6 ------ 9 files changed, 14 insertions(+), 84 deletions(-) diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 8e597db4d971..cdf90928b7f2 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c @@ -42,7 +42,7 @@ static int read_block_bitmap(struct super_block *sb, loc.logicalBlockNum = bitmap->s_extPosition; loc.partitionReferenceNum = UDF_SB(sb)->s_partition; - bh = udf_tread(sb, udf_get_lb_pblock(sb, &loc, block)); + bh = sb_bread(sb, udf_get_lb_pblock(sb, &loc, block)); if (!bh) retval = -EIO; diff --git a/fs/udf/directory.c b/fs/udf/directory.c index 0f3cc095b2a3..ae61814c195b 100644 --- a/fs/udf/directory.c +++ b/fs/udf/directory.c @@ -141,7 +141,7 @@ static void udf_readahead_dir(struct udf_fileident_iter *iter) for (i = 0; i < ralen; i++) { blk = udf_get_lb_pblock(iter->dir->i_sb, &iter->eloc, iter->loffset + i); - tmp = udf_tgetblk(iter->dir->i_sb, blk); + tmp = sb_getblk(iter->dir->i_sb, blk); if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) bha[num++] = tmp; else @@ -160,7 +160,7 @@ static struct buffer_head *udf_fiiter_bread_blk(struct udf_fileident_iter *iter) udf_readahead_dir(iter); blk = udf_get_lb_pblock(iter->dir->i_sb, &iter->eloc, iter->loffset); - return udf_tread(iter->dir->i_sb, blk); + return sb_bread(iter->dir->i_sb, blk); } /* diff --git a/fs/udf/inode.c b/fs/udf/inode.c index a504c7650551..2b3fc897d1b3 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -1594,7 +1594,7 @@ static int udf_update_inode(struct inode *inode, int do_sync) unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; struct udf_inode_info *iinfo = UDF_I(inode); - bh = udf_tgetblk(inode->i_sb, + bh = sb_getblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, &iinfo->i_location, 0)); if (!bh) { udf_debug("getblk failure\n"); @@ -1854,7 +1854,7 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block, neloc.logicalBlockNum = block; neloc.partitionReferenceNum = epos->block.partitionReferenceNum; - bh = udf_tgetblk(sb, udf_get_lb_pblock(sb, &neloc, 0)); + bh = sb_getblk(sb, udf_get_lb_pblock(sb, &neloc, 0)); if (!bh) return -EIO; lock_buffer(bh); @@ -2071,7 +2071,7 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, epos->offset = sizeof(struct allocExtDesc); brelse(epos->bh); block = udf_get_lb_pblock(inode->i_sb, &epos->block, 0); - epos->bh = udf_tread(inode->i_sb, block); + epos->bh = sb_bread(inode->i_sb, block); if (!epos->bh) { udf_debug("reading block %u failed!\n", block); return -1; @@ -2292,8 +2292,5 @@ udf_pblk_t udf_block_map(struct inode *inode, sector_t block) up_read(&UDF_I(inode)->i_data_sem); brelse(epos.bh); - if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV)) - return udf_fixed_to_variable(ret); - else - return ret; + return ret; } diff --git a/fs/udf/misc.c b/fs/udf/misc.c index 1614d308d0f0..3777468d06ce 100644 --- a/fs/udf/misc.c +++ b/fs/udf/misc.c @@ -28,22 +28,6 @@ #include "udf_i.h" #include "udf_sb.h" -struct buffer_head *udf_tgetblk(struct super_block *sb, udf_pblk_t block) -{ - if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV)) - return sb_getblk(sb, udf_fixed_to_variable(block)); - else - return sb_getblk(sb, block); -} - -struct buffer_head *udf_tread(struct super_block *sb, udf_pblk_t block) -{ - if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV)) - return sb_bread(sb, udf_fixed_to_variable(block)); - else - return sb_bread(sb, block); -} - struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size, uint32_t type, uint8_t loc) { @@ -216,7 +200,7 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, if (block == 0xFFFFFFFF) return NULL; - bh = udf_tread(sb, block); + bh = sb_bread(sb, block); if (!bh) { udf_err(sb, "read failed, block=%u, location=%u\n", block, location); diff --git a/fs/udf/namei.c b/fs/udf/namei.c index f8091aa22fcd..49fab30afff3 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -171,7 +171,7 @@ static struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, 0); if (!newblock) return NULL; - dbh = udf_tgetblk(inode->i_sb, newblock); + dbh = sb_getblk(inode->i_sb, newblock); if (!dbh) return NULL; lock_buffer(dbh); @@ -619,7 +619,7 @@ static int udf_symlink(struct user_namespace *mnt_userns, struct inode *dir, block = udf_get_pblock(sb, block, iinfo->i_location.partitionReferenceNum, 0); - epos.bh = udf_tgetblk(sb, block); + epos.bh = sb_getblk(sb, block); if (unlikely(!epos.bh)) { err = -ENOMEM; udf_free_blocks(sb, inode, &eloc, 0, 1); diff --git a/fs/udf/super.c b/fs/udf/super.c index c756d903a862..58a3148173ac 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -734,7 +734,7 @@ static int udf_check_vsd(struct super_block *sb) * added */ for (; !nsr && sector < VSD_MAX_SECTOR_OFFSET; sector += sectorsize) { /* Read a block */ - bh = udf_tread(sb, sector >> sb->s_blocksize_bits); + bh = sb_bread(sb, sector >> sb->s_blocksize_bits); if (!bh) break; @@ -1839,10 +1839,6 @@ static int udf_check_anchor_block(struct super_block *sb, sector_t block, uint16_t ident; int ret; - if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) && - udf_fixed_to_variable(block) >= sb_bdev_nr_blocks(sb)) - return -EAGAIN; - bh = udf_read_tagged(sb, block, block, &ident); if (!bh) return -EAGAIN; @@ -1924,46 +1920,6 @@ static int udf_scan_anchors(struct super_block *sb, udf_pblk_t *lastblock, return udf_check_anchor_block(sb, sbi->s_session + 512, fileset); } -/* - * Find an anchor volume descriptor and load Volume Descriptor Sequence from - * area specified by it. The function expects sbi->s_lastblock to be the last - * block on the media. - * - * Return <0 on error, 0 if anchor found. -EAGAIN is special meaning anchor - * was not found. - */ -static int udf_find_anchor(struct super_block *sb, - struct kernel_lb_addr *fileset) -{ - struct udf_sb_info *sbi = UDF_SB(sb); - sector_t lastblock = sbi->s_last_block; - int ret; - - ret = udf_scan_anchors(sb, &lastblock, fileset); - if (ret != -EAGAIN) - goto out; - - /* No anchor found? Try VARCONV conversion of block numbers */ - UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); - lastblock = udf_variable_to_fixed(sbi->s_last_block); - /* Firstly, we try to not convert number of the last block */ - ret = udf_scan_anchors(sb, &lastblock, fileset); - if (ret != -EAGAIN) - goto out; - - lastblock = sbi->s_last_block; - /* Secondly, we try with converted number of the last block */ - ret = udf_scan_anchors(sb, &lastblock, fileset); - if (ret < 0) { - /* VARCONV didn't help. Clear it. */ - UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV); - } -out: - if (ret == 0) - sbi->s_last_block = lastblock; - return ret; -} - /* * Check Volume Structure Descriptor, find Anchor block and load Volume * Descriptor Sequence. @@ -2004,7 +1960,7 @@ static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt, /* Look for anchor block and load Volume Descriptor Sequence */ sbi->s_anchor = uopt->anchor; - ret = udf_find_anchor(sb, fileset); + ret = udf_scan_anchors(sb, &sbi->s_last_block, fileset); if (ret < 0) { if (!silent && ret == -EAGAIN) udf_warn(sb, "No anchor found\n"); @@ -2455,7 +2411,7 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb, if (bytes) { brelse(bh); newblock = udf_get_lb_pblock(sb, &loc, ++block); - bh = udf_tread(sb, newblock); + bh = sb_bread(sb, newblock); if (!bh) { udf_debug("read failed\n"); goto out; diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c index 036ebd892b85..3d2cfc7a1449 100644 --- a/fs/udf/truncate.c +++ b/fs/udf/truncate.c @@ -240,7 +240,7 @@ int udf_truncate_extents(struct inode *inode) brelse(epos.bh); epos.offset = sizeof(struct allocExtDesc); epos.block = eloc; - epos.bh = udf_tread(sb, + epos.bh = sb_bread(sb, udf_get_lb_pblock(sb, &eloc, 0)); /* Error reading indirect block? */ if (!epos.bh) diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h index 6bccff3c70f5..9af6ff7f9747 100644 --- a/fs/udf/udf_sb.h +++ b/fs/udf/udf_sb.h @@ -23,7 +23,6 @@ #define UDF_FLAG_STRICT 5 #define UDF_FLAG_UNDELETE 6 #define UDF_FLAG_UNHIDE 7 -#define UDF_FLAG_VARCONV 8 #define UDF_FLAG_UID_FORGET 11 /* save -1 for uid to disk */ #define UDF_FLAG_GID_FORGET 12 #define UDF_FLAG_UID_SET 13 diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index eaf9e6fd201e..88667a80795d 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -34,9 +34,6 @@ extern __printf(3, 4) void _udf_warn(struct super_block *sb, #define udf_debug(fmt, ...) \ pr_debug("%s:%d:%s: " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__) -#define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) ) -#define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) ) - #define UDF_EXTENT_LENGTH_MASK 0x3FFFFFFF #define UDF_EXTENT_FLAG_MASK 0xC0000000 @@ -179,9 +176,6 @@ extern int8_t udf_current_aext(struct inode *, struct extent_position *, extern void udf_update_extra_perms(struct inode *inode, umode_t mode); /* misc.c */ -extern struct buffer_head *udf_tgetblk(struct super_block *sb, - udf_pblk_t block); -extern struct buffer_head *udf_tread(struct super_block *sb, udf_pblk_t block); extern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t, uint32_t, uint8_t); extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t, From patchwork Tue Jan 24 12:17:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113902 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D64A7C25B4E for ; Tue, 24 Jan 2023 12:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233580AbjAXMSS (ORCPT ); Tue, 24 Jan 2023 07:18:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233030AbjAXMSQ (ORCPT ); Tue, 24 Jan 2023 07:18:16 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CAC442EA for ; Tue, 24 Jan 2023 04:18:15 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 96ABC2188E; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=47r5ExZRB24cDn2IjtdkIRMHYac0BXu7wUVP0ko8VT8=; b=StabaqjxyLINpvcTNijwJ6YcNaLPwVvSG4IvsItjvU3DBF5nXpAqWxZke3bBvNU1IMfZiw yWa3+CpnSqvV6qHkM8iopYP2SYlqZI14j6MBgfu5vNeRTFyxcViRqkYUIqfg5gcbkQhTAw EaJYu4kbDGEvqMV+jpfAMkNHD+H+hbk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=47r5ExZRB24cDn2IjtdkIRMHYac0BXu7wUVP0ko8VT8=; b=CxukcPpfWAU3KJM8g73XVKBoPifleobmqKt+uH5zGK10HHofZF8QAq9q2LL6cmBoienLSc PkEefxjhaeWCXADg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 891F013A06; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id x09aIYbMz2PSNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 12511A06C5; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 03/22] udf: Move incrementing of goal block directly into inode_getblk() Date: Tue, 24 Jan 2023 13:17:49 +0100 Message-Id: <20230124121814.25951-3-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1280; i=jack@suse.cz; h=from:subject; bh=AlSPZhbo6K1pV5NFVChrTADgN11hy8V5XtSJXgXgye8=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xvLYFCPR79HZCjDxnG5hrlBDtE6MDb/YEYgInH pUd5NTGJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MbwAKCRCcnaoHP2RA2dc7B/ 9+zhB2poRfQZQUswg8+Ne1RDr3QwwHAtzPx7EJBr3uIlKKZwCn+DuFlhb9+Uit2amJdEVE0pVOmKu8 tTS8fFMkHYEHmu2ITzFGce45ocTbCYItP4RYCfo10cjRB7jEKqOE7bLX6E7YPbIS56a4bkO5tRwWKZ h58aiy2tCol5OvDzLIoCLTTXLWzMFt37RDuQOzeeXxwqBweyWx63zkcX1lgi27MeA+ubpRre7vUtSD rHcbd19qoYmEy2ZWRi+TVZyCX4ADr+9C35QdSBjOyYXsAF9sB/iPcaFVdZL1gP2PmMgEp6hPwXFks5 sWQ5vPkgYjQH6TZD2mTqWKF2fXg0jI X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org inode_getblk() sets goal block for the next allocation to the currently allocated block. This is obviously one less than what the goal block should be which we fixup in udf_get_block(). Just set the right goal block directly in inode_getblk(). Signed-off-by: Jan Kara --- fs/udf/inode.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 2b3fc897d1b3..ff414fff354a 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -339,11 +339,6 @@ static int udf_get_block(struct inode *inode, sector_t block, iinfo = UDF_I(inode); down_write(&iinfo->i_data_sem); - if (block == iinfo->i_next_alloc_block + 1) { - iinfo->i_next_alloc_block++; - iinfo->i_next_alloc_goal++; - } - /* * Block beyond EOF and prealloc extents? Just discard preallocation * as it is not useful and complicates things. @@ -812,8 +807,8 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, goto out_free; } *new = 1; - iinfo->i_next_alloc_block = block; - iinfo->i_next_alloc_goal = newblocknum; + iinfo->i_next_alloc_block = block + 1; + iinfo->i_next_alloc_goal = newblocknum + 1; inode->i_ctime = current_time(inode); if (IS_SYNC(inode)) From patchwork Tue Jan 24 12:17:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74E12C25B4E for ; Tue, 24 Jan 2023 12:18:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232143AbjAXMSW (ORCPT ); Tue, 24 Jan 2023 07:18:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233571AbjAXMSR (ORCPT ); Tue, 24 Jan 2023 07:18:17 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9A4442EB for ; Tue, 24 Jan 2023 04:18:15 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 93B611FE1D; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V1bsdbxl58ZoO/U0lADB2VOZb2Ox82ek7358rYvVJaw=; b=rH4H6A9Mw9+BzCg1exNOmIQcPitTU3KImyHEqTuPeESAyLsJsffP1T7uPO14yUr5/HdEW8 S7zT8oUn/51V9F1wM5GNXTHohxNOKtvjIitLRtpXMU7yteQLCzvFSnx6ikj1hDDqmgQnal Tneipk2+lILoTNJW7DzB33QiYg4G6xM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V1bsdbxl58ZoO/U0lADB2VOZb2Ox82ek7358rYvVJaw=; b=8kfc6ZxDADpsDjjMjouq3Ue9FIF5Gl0yowotyIutGcvOXtlkDtyNS4zBpSYL3qbN6wZ4Yd 9Nu9+o1SMdWo/LDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 84EA0139FB; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gKZyIIbMz2PRNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 17BA8A06C6; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 04/22] udf: Factor out block mapping into udf_map_block() Date: Tue, 24 Jan 2023 13:17:50 +0100 Message-Id: <20230124121814.25951-4-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3783; i=jack@suse.cz; h=from:subject; bh=XARw2uPOVJRk2CwMY7RattNwAYAlkAf7Q6VYc3n+OTA=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xw9J8zQPM8PK0LLa2PBcA8p3xRk5IWcmMwt/zs MUcyLhGJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/McAAKCRCcnaoHP2RA2YVvCA CdTVfHbGfttD9q5JJIuyoyYVaxkbXclC+oAWQzfWpxAoemZPH6AISUTbzOHx7RIoTi8VL7D0HqDx/8 mdh+214M5W9x6eXjZ4XjQByos1NwoUXOEjCtdUijUxbyCvIMEF4c3b7w+DYUZ5elkLtUU8IGGjvsuG q28Ca1HWx0ODBT7GlJHXlQ8k4n0XWWhvmtda0Uvj2o3u9Xoi3ALQC5xrqNdcwWsWFlSjyMrWpSZNgi SKF08ifj86z9GS5i7V9kpo6WTjdUJ6E3oHCifsun8dHHrNSpTnsAr4Mbpu8c0haQkTwquh3FFX3DSr 16kaKoFQwiY1kiAQm/YEQtnXSvJ66R X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Create new block mapping function udf_map_block() that takes new udf_map_rq structure describing mapping request. We will convert other places to use this function for block mapping. Signed-off-by: Jan Kara --- fs/udf/inode.c | 70 +++++++++++++++++++++++++++++++++--------------- fs/udf/udfdecl.h | 1 + 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index ff414fff354a..53d2d8fef158 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -52,6 +52,8 @@ #define FE_DELETE_PERMS (FE_PERM_U_DELETE | FE_PERM_G_DELETE | \ FE_PERM_O_DELETE) +struct udf_map_rq; + static umode_t udf_convert_permissions(struct fileEntry *); static int udf_update_inode(struct inode *, int); static int udf_sync_inode(struct inode *inode); @@ -320,43 +322,67 @@ int udf_expand_file_adinicb(struct inode *inode) return err; } -static int udf_get_block(struct inode *inode, sector_t block, - struct buffer_head *bh_result, int create) +#define UDF_MAP_CREATE 0x01 /* Mapping can allocate new blocks */ + +#define UDF_BLK_MAPPED 0x01 /* Block was successfully mapped */ +#define UDF_BLK_NEW 0x02 /* Block was freshly allocated */ + +struct udf_map_rq { + sector_t lblk; + udf_pblk_t pblk; + int iflags; /* UDF_MAP_ flags determining behavior */ + int oflags; /* UDF_BLK_ flags reporting results */ +}; + +static int udf_map_block(struct inode *inode, struct udf_map_rq *map) { int err, new; - sector_t phys = 0; - struct udf_inode_info *iinfo; + struct udf_inode_info *iinfo = UDF_I(inode); - if (!create) { - phys = udf_block_map(inode, block); - if (phys) - map_bh(bh_result, inode->i_sb, phys); + map->oflags = 0; + if (!(map->iflags & UDF_MAP_CREATE)) { + map->pblk = udf_block_map(inode, map->lblk); + if (map->pblk != 0) + map->oflags |= UDF_BLK_MAPPED; return 0; } - err = -EIO; - new = 0; - iinfo = UDF_I(inode); - down_write(&iinfo->i_data_sem); /* * Block beyond EOF and prealloc extents? Just discard preallocation * as it is not useful and complicates things. */ - if (((loff_t)block) << inode->i_blkbits > iinfo->i_lenExtents) + if (((loff_t)map->lblk) << inode->i_blkbits > iinfo->i_lenExtents) udf_discard_prealloc(inode); udf_clear_extent_cache(inode); - phys = inode_getblk(inode, block, &err, &new); - if (!phys) - goto abort; - + map->pblk = inode_getblk(inode, map->lblk, &err, &new); + up_write(&iinfo->i_data_sem); + if (err) + return err; + map->oflags |= UDF_BLK_MAPPED; if (new) - set_buffer_new(bh_result); - map_bh(bh_result, inode->i_sb, phys); + map->oflags |= UDF_BLK_NEW; + return 0; +} -abort: - up_write(&iinfo->i_data_sem); - return err; +static int udf_get_block(struct inode *inode, sector_t block, + struct buffer_head *bh_result, int create) +{ + int err; + struct udf_map_rq map = { + .lblk = block, + .iflags = create ? UDF_MAP_CREATE : 0, + }; + + err = udf_map_block(inode, &map); + if (err < 0) + return err; + if (map.oflags & UDF_BLK_MAPPED) { + map_bh(bh_result, inode->i_sb, map.pblk); + if (map.oflags & UDF_BLK_NEW) + set_buffer_new(bh_result); + } + return 0; } static struct buffer_head *udf_getblk(struct inode *inode, udf_pblk_t block, diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index 88667a80795d..d791458fe52a 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -138,6 +138,7 @@ static inline unsigned int udf_dir_entry_len(struct fileIdentDesc *cfi) /* file.c */ extern long udf_ioctl(struct file *, unsigned int, unsigned long); + /* inode.c */ extern struct inode *__udf_iget(struct super_block *, struct kernel_lb_addr *, bool hidden_inode); From patchwork Tue Jan 24 12:17:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AAB9C25B50 for ; Tue, 24 Jan 2023 12:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233591AbjAXMSS (ORCPT ); Tue, 24 Jan 2023 07:18:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233479AbjAXMSR (ORCPT ); Tue, 24 Jan 2023 07:18:17 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB9A442EE for ; Tue, 24 Jan 2023 04:18:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D8AFF1FDFC; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A5YEYQTPee+bHiWAf9SXhfgsWbBxRwpDlvsCt6+VsNs=; b=PxjEV2V+/s89fu/JCw0ogho67mYekfZRbiiSK6Yl9qJ5AO+Dsvv0V5t1wgviLBEY0zVP8S wi88KEVdutG/Tvtz/Hiw2sLKR6pjVdMWfECjTU7VH/0BU+6slAAJpQGNMYCLCIlbl8G47t e4jG9erqoKztLyvJIrLiuJ7vg78zrAs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A5YEYQTPee+bHiWAf9SXhfgsWbBxRwpDlvsCt6+VsNs=; b=/yNgHj3epYtLM4JoZglHjlENkFgsHbVPCf8dXmyo2ePVQM3gHiM/a+0Tt+fiucntovVH7U idx3it1eopwg90AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CD188139FB; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5koPMobMz2PZNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1D4DDA06D0; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 05/22] udf: Use udf_bread() in udf_get_pblock_virt15() Date: Tue, 24 Jan 2023 13:17:51 +0100 Message-Id: <20230124121814.25951-5-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1120; i=jack@suse.cz; h=from:subject; bh=RFJSVugjUdOJBCZPb34/YpPlYyUVOl3Dphv2WOBy0hk=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xwpfqiFS19wfsP67DXE7gsoPEq2nCkreQqgBIq 6hn1Ww2JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/McAAKCRCcnaoHP2RA2cp+B/ 42GKbw/0bmRZdq3h1fFejDJmCrUvlANL51oL6HxR2NFBW28G2WcHbMAUgI9bp6ncepOftAKLyBACzg DnxTaWE0rxoqr4BVstzJ6RHO2ppJWBRIlwx8j5d0vMNSToUcnGXFwV4jrW+KZknnZ7XVtMb2pNUerU ecZGqKOP6UOE1zSzViyAjMvlvM2CwuNKpfa8kxJyLHvOrS1nsps0aLm2TOD0D8y/TRVfVHyYOwvylf 6s1l3cfrKNdcJ+gI9Lt1dQ1raNy2HuUuPeWWE8uFCQ3V7l8PC/9hWsGA3zqa0HEsjGqVcxhT0Jwdra Arycgw8PzNtiXVxwKKoS9htuuZW+HV X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use udf_bread() instead of mapping and reading buffer head manually in udf_get_pblock_virt15(). Signed-off-by: Jan Kara --- fs/udf/partition.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/udf/partition.c b/fs/udf/partition.c index 4cbf40575965..92765d2f6958 100644 --- a/fs/udf/partition.c +++ b/fs/udf/partition.c @@ -54,6 +54,7 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, struct udf_part_map *map; struct udf_virtual_data *vdata; struct udf_inode_info *iinfo = UDF_I(sbi->s_vat_inode); + int err; map = &sbi->s_partmaps[partition]; vdata = &map->s_type_specific.s_virtual; @@ -79,9 +80,7 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, index = vdata->s_start_offset / sizeof(uint32_t) + block; } - loc = udf_block_map(sbi->s_vat_inode, newblock); - - bh = sb_bread(sb, loc); + bh = udf_bread(sbi->s_vat_inode, newblock, 0, &err); if (!bh) { udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%u,%u) VAT: %u[%u]\n", sb, block, partition, loc, index); From patchwork Tue Jan 24 12:17:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3229C25B4E for ; Tue, 24 Jan 2023 12:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbjAXMSU (ORCPT ); Tue, 24 Jan 2023 07:18:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233506AbjAXMSR (ORCPT ); Tue, 24 Jan 2023 07:18:17 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39205442ED for ; Tue, 24 Jan 2023 04:18:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EA8202188C; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TsEyo1qnv9h4UWXO9UUhyxv8nz/caMYUDMPuiBK/Vi8=; b=BuUPziHiVGNmvNU7fgpMa3DVLNStubmm7+fUg/ckreHhMFpEnEWuHKDMb3aWRfi0ZSEvXn QvtNRrT0oFRtcOd2NYe1NcWnpE9ecgRYrlHBAv4htv9Ery58oIyjRtRbjsB0H3LPzsf5HI pmK333VdGLEml+Vr8ulsfap8TeYz1kE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562694; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TsEyo1qnv9h4UWXO9UUhyxv8nz/caMYUDMPuiBK/Vi8=; b=LOHFshjAT6By0enDc2VG1KsAmunpySh3nWXdSLuAh5FWnab4P7xMIKYJrI+Mhd0XbyytcG 9Ltp0vQ50031MWBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DC2E5139FF; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8ve9NYbMz2PcNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 23249A06D1; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 06/22] udf: Use udf_bread() in udf_load_vat() Date: Tue, 24 Jan 2023 13:17:52 +0100 Message-Id: <20230124121814.25951-6-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1341; i=jack@suse.cz; h=from:subject; bh=n6xJxrlYEz8GHt8c6ZVR7iV2PHp3WFV1VftbBpZofNc=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xxcF2x49xaajEXOl8aFdc/GG40QQLuw8vE6s9K kVIqEu2JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/McQAKCRCcnaoHP2RA2S5DB/ kBFHtDanT2x1kINsF2cMNWrWrWywBvcLZS7XdDMoCucHFQmyKfTH8WOLM4zjl7A6giTAiGzTXqKan2 qJLjoJUlkjOKV/0H7oAyriKbcS8FUIoy49tb0a2MkQtL5hqccCbNz9dXv+aKvn0RxCumueYPNreBWX NH9ZSZRMFpzAjMGxry0CsHfHoGaxkiB7hIvHcl0d3rOYep+NJOAaTIsfNKhBZLF2yVus8Fzn31SAzo qFoV7Tf0dvT8RaX1ciuWTpMuVMB2tD6NTkgifT/pUAKO+nb7tamfCfwFyLYzzJoZmIA9gvPWAU5fPZ pWIIyyRchpXS9hlVf+FhFD7hDQ/iBh X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use udf_bread() instead of mapping and loadign buffer head manually in udf_load_vat(). Signed-off-by: Jan Kara --- fs/udf/super.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/udf/super.c b/fs/udf/super.c index 58a3148173ac..df5287c5d659 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -1176,7 +1176,6 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index) struct udf_part_map *map = &sbi->s_partmaps[p_index]; struct buffer_head *bh = NULL; struct udf_inode_info *vati; - uint32_t pos; struct virtualAllocationTable20 *vat20; sector_t blocks = sb_bdev_nr_blocks(sb); @@ -1198,10 +1197,14 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index) } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { vati = UDF_I(sbi->s_vat_inode); if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { - pos = udf_block_map(sbi->s_vat_inode, 0); - bh = sb_bread(sb, pos); - if (!bh) - return -EIO; + int err = 0; + + bh = udf_bread(sbi->s_vat_inode, 0, 0, &err); + if (!bh) { + if (!err) + err = -EFSCORRUPTED; + return err; + } vat20 = (struct virtualAllocationTable20 *)bh->b_data; } else { vat20 = (struct virtualAllocationTable20 *) From patchwork Tue Jan 24 12:17:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E88F5C25B4E for ; Tue, 24 Jan 2023 12:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233650AbjAXMSf (ORCPT ); Tue, 24 Jan 2023 07:18:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbjAXMSX (ORCPT ); Tue, 24 Jan 2023 07:18:23 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8CC442ED for ; Tue, 24 Jan 2023 04:18:18 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3CC081FE4B; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AgF2+jVQFT/DrkwUQ/i2IFmOa9Lb4Ekn7vziWx+im30=; b=kdDNRm8fqvP2uO+hSSVf/7RO37RKFyTSQ1B22+t8jWTTjN8yUJKXyIsvO0/pPYozmoEsJ7 adpWAJkqFzJcfhQs1Zbap1rSTTzayZ3Cp65YuRbYvdWeBdF8o0c18CTny42roVBvqkIRh6 geJMJGbRkmb9+YkkfNszAofJ3qAxIfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AgF2+jVQFT/DrkwUQ/i2IFmOa9Lb4Ekn7vziWx+im30=; b=ZjIisHIlxOTqgVZWXTSqGE8JGV7MY7gmlYKdmDS7NT/yc0SLpC540JNJEDb5ygUmhRCtx7 tWFU4oxbLkcaD9Bw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 23F2313A09; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SubGCIfMz2PnNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 290F2A06D3; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 07/22] udf: Do not call udf_block_map() on ICB files Date: Tue, 24 Jan 2023 13:17:53 +0100 Message-Id: <20230124121814.25951-7-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2279; i=jack@suse.cz; h=from:subject; bh=w7r+wUrzagF3K6pnVTKKhlEMwrHB5EJvDVvesA5qtXY=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xy4MJFZDRSI38ADJQ6BZWUrg8BfkHCk2WWryjk ioRDxCaJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/McgAKCRCcnaoHP2RA2XofCA DTv1Pvk7/qLgjZb6yasvwEF6aUb4G1ULlK/8sBDlM/Iy1/M1pQ9G/I7UT4106ywPAZBInmHJjqyzSL 1t9p7/DYyKYfh+Jw/23BA/xSyyAslJDNHYtysjKrmaITFclQ5ysXoTP3uwvh0ifINv1Kr3YC6+xk5R 5BURwcVVnCs4mXAgeKU47FtaTIvguN6sVhg0T5Z2a5OYaugGhuqFWzdFs5h/Rptil7TxchWvQWGpem U+XLg4/3iSCJV1vLg/Vp8xREHRQz9AGzuuSUW1sotfkq1nmayI9Xjp5rPXVJFSTWjHycODb9GYxnAM BNZJQwWPqwcddk22Sox1+2JT09TFR7 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently udf_symlink_filler() called udf_block_map() even on files which have data stored inside the ICB. This is invalid as we cannot map blocks for such files (although so far the error got silently ignored). The call happened because we could not call block mapping function once we've acquired i_data_sem and determined whether the file has data stored in the ICB. For symlinks the situation is luckily simple as they get never modified so file type never changes once it is set. Hence we can check the file type even without i_data_sem. Just drop the i_data_sem locking and move block mapping to where it is needed. Signed-off-by: Jan Kara --- fs/udf/symlink.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c index f3642f9c23f8..451d6d6c701e 100644 --- a/fs/udf/symlink.c +++ b/fs/udf/symlink.c @@ -109,27 +109,24 @@ static int udf_symlink_filler(struct file *file, struct folio *folio) unsigned char *symlink; int err; unsigned char *p = page_address(page); - struct udf_inode_info *iinfo; + struct udf_inode_info *iinfo = UDF_I(inode); uint32_t pos; /* We don't support symlinks longer than one block */ if (inode->i_size > inode->i_sb->s_blocksize) { err = -ENAMETOOLONG; - goto out_unmap; + goto out_unlock; } - iinfo = UDF_I(inode); - pos = udf_block_map(inode, 0); - - down_read(&iinfo->i_data_sem); if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { symlink = iinfo->i_data + iinfo->i_lenEAttr; } else { + pos = udf_block_map(inode, 0); bh = sb_bread(inode->i_sb, pos); if (!bh) { err = -EIO; - goto out_unlock_inode; + goto out_err; } symlink = bh->b_data; @@ -138,17 +135,15 @@ static int udf_symlink_filler(struct file *file, struct folio *folio) err = udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p, PAGE_SIZE); brelse(bh); if (err) - goto out_unlock_inode; + goto out_err; - up_read(&iinfo->i_data_sem); SetPageUptodate(page); unlock_page(page); return 0; -out_unlock_inode: - up_read(&iinfo->i_data_sem); +out_err: SetPageError(page); -out_unmap: +out_unlock: unlock_page(page); return err; } From patchwork Tue Jan 24 12:17:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59345C25B50 for ; Tue, 24 Jan 2023 12:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233624AbjAXMSZ (ORCPT ); Tue, 24 Jan 2023 07:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233576AbjAXMSR (ORCPT ); Tue, 24 Jan 2023 07:18:17 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467DD442F1 for ; Tue, 24 Jan 2023 04:18:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 001151FE1E; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KX2l2VM3mQseDoZjciXJXWz/AlvoZ81GcxemuHKONFo=; b=cADyG9DKg0DsmcIdejyyOnRcZ+x/M4pru/rFT8/T2a0DbbusnIkF2lo4n5BXcZKSLHI8yR EVPNdKzelGV8Ncb7J8YMKSeJPIXO3fOr6CGNq7+D9RzSpIdKXj4kvaZIVRHj3fUwYxU8GL BZjBlhBXpED0swBwk7eO8N/FfUQfwF4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KX2l2VM3mQseDoZjciXJXWz/AlvoZ81GcxemuHKONFo=; b=F/2p6unSpqiGVa6QZp+aq9knpzWSMCAo0J/fkBqajYhuQlXwSD0LBykVxeFpTTUN0Dac12 r+es9ZoDcZ1yThBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E5C08139FB; Tue, 24 Jan 2023 12:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dtghOIbMz2PeNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 2EED0A06D4; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 08/22] udf: Convert udf_symlink_filler() to use udf_bread() Date: Tue, 24 Jan 2023 13:17:54 +0100 Message-Id: <20230124121814.25951-8-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1294; i=jack@suse.cz; h=from:subject; bh=FHIKTP5NfPL9Luj4nsfFCPKR0huUs5SW/4yaAzAanjY=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8xzWLyIeumZKzEUlN9maWXCi0V4BdsWybvFLCjp ie7Vw4+JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/McwAKCRCcnaoHP2RA2cFRB/ 0R36hnt/uniZj+4i8uwsjyBIAX4R3pXT1zS5VwUffMXZFE0/1fbY8Vnp24PNYiFfG7ELx2tukO5vj7 AwUz4TZ4TQc1HPUI1FKD1ow7UynXx8xFScYPTk18vEt/uFHBSsolLLnwu+hK6TfPTaJfwnTFgBtcfP 8hD0j7s9/Fu0he8flvAn9KD7dDKrsVlIVkPTgHt8r8d3F/nb8VX3JI99exnOiLKIhY0y01Ig4Wun0O Uc1s9Om6b7rgrelqudSEQSm1JAJY6byhGk+PZ56tWoPVKcaweLcKgcYMCbbmlZVy0fX2rFeztUUd19 Swk+MQica4miZi4pyDKnXA3UI4HSM7 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert udf_symlink_filler() to use udf_bread() instead of mapping and reading buffer head manually. Signed-off-by: Jan Kara --- fs/udf/symlink.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c index 451d6d6c701e..a6cabaa5f1c2 100644 --- a/fs/udf/symlink.c +++ b/fs/udf/symlink.c @@ -107,10 +107,9 @@ static int udf_symlink_filler(struct file *file, struct folio *folio) struct inode *inode = page->mapping->host; struct buffer_head *bh = NULL; unsigned char *symlink; - int err; + int err = 0; unsigned char *p = page_address(page); struct udf_inode_info *iinfo = UDF_I(inode); - uint32_t pos; /* We don't support symlinks longer than one block */ if (inode->i_size > inode->i_sb->s_blocksize) { @@ -121,14 +120,12 @@ static int udf_symlink_filler(struct file *file, struct folio *folio) if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { symlink = iinfo->i_data + iinfo->i_lenEAttr; } else { - pos = udf_block_map(inode, 0); - bh = sb_bread(inode->i_sb, pos); - + bh = udf_bread(inode, 0, 0, &err); if (!bh) { - err = -EIO; + if (!err) + err = -EFSCORRUPTED; goto out_err; } - symlink = bh->b_data; } From patchwork Tue Jan 24 12:17:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D935FC25B50 for ; Tue, 24 Jan 2023 12:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233633AbjAXMSa (ORCPT ); Tue, 24 Jan 2023 07:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233594AbjAXMST (ORCPT ); Tue, 24 Jan 2023 07:18:19 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 085A237F02 for ; Tue, 24 Jan 2023 04:18:18 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2BD512189A; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mpgq7pkFTHUcoHIaiRiSu/kuem1wMOv/RmU/oTrzaXM=; b=L5tr8tRTn8Ih39ueWxHeVcb6RG7qwc+6Y4kpwDUgr8z8ZwnBquQrEy3+7co85Fuzc3q3af 0A06Yd1euUAMny9grEcfuScNQg7Z4qtL5orNrgpmDDHBg+EGiW5WnQOK2JWlQlJs4tkBPt wfh1HR4fGRN+ZHD2OAI4JjZtFitw7l8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mpgq7pkFTHUcoHIaiRiSu/kuem1wMOv/RmU/oTrzaXM=; b=xgvoKj11FfWtJQ0dN33Xv1j0M+yW+z2EKFyY7E6Kn46kmnldb8ONIMynlrq1JXeEuvu0cJ 9Cp4LLFL7y9q9RDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1D81C13A06; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5ss6B4fMz2PrNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 33FC2A06D5; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 09/22] udf: Fold udf_block_map() into udf_map_block() Date: Tue, 24 Jan 2023 13:17:55 +0100 Message-Id: <20230124121814.25951-9-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2385; i=jack@suse.cz; h=from:subject; bh=fCCNH/2GDFZMtrrFOYavCg3Ez2Eg6VO/6hGC8KpoaS4=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x0HnQ92igypy0GPXYLon5LOed9Yr2frRbYxMCC KJIjKJiJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MdAAKCRCcnaoHP2RA2VRcB/ 9u//TlRrMdCXccyoetTvL2cCwuBXu89C06wrMi2sLND4bMeJR7spEzuqf4pRO62EtktGVMbMNhLoz7 NzmiDT8CNLhFiq8pTdU0S9KayBus0KZelQIDhwAp9qMKd3s7Mez91iBGRP23D4NNLog6RjQjGf5Dyk WulxSCqMBQm/S9FHolIZ/owACjcDVbGTlfun0Zf5gcvjGPiM0sbdwGBZGltNuU1zx44gXxJ72rasNp cbQ+W8GQEjFinPKbWPjGRKrjSLYcPQSz4QYKP75mF/4hJgZfWzol5lnuLs+R1fvb4aZ22T9aRRmCir /O5NB15RuhPHrU6IIpFLdQ2BJTJEJm X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org udf_block_map() has now only a single caller. Fold it there. Signed-off-by: Jan Kara --- fs/udf/inode.c | 38 ++++++++++++++------------------------ fs/udf/udfdecl.h | 1 - 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 53d2d8fef158..e098d69991d0 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -341,9 +341,21 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map) map->oflags = 0; if (!(map->iflags & UDF_MAP_CREATE)) { - map->pblk = udf_block_map(inode, map->lblk); - if (map->pblk != 0) + struct kernel_lb_addr eloc; + uint32_t elen; + sector_t offset; + struct extent_position epos = {}; + + down_read(&iinfo->i_data_sem); + if (inode_bmap(inode, map->lblk, &epos, &eloc, &elen, &offset) + == (EXT_RECORDED_ALLOCATED >> 30)) { + map->pblk = udf_get_lb_pblock(inode->i_sb, &eloc, + offset); map->oflags |= UDF_BLK_MAPPED; + } + up_read(&iinfo->i_data_sem); + brelse(epos.bh); + return 0; } @@ -2293,25 +2305,3 @@ int8_t inode_bmap(struct inode *inode, sector_t block, return etype; } - -udf_pblk_t udf_block_map(struct inode *inode, sector_t block) -{ - struct kernel_lb_addr eloc; - uint32_t elen; - sector_t offset; - struct extent_position epos = {}; - udf_pblk_t ret; - - down_read(&UDF_I(inode)->i_data_sem); - - if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == - (EXT_RECORDED_ALLOCATED >> 30)) - ret = udf_get_lb_pblock(inode->i_sb, &eloc, offset); - else - ret = 0; - - up_read(&UDF_I(inode)->i_data_sem); - brelse(epos.bh); - - return ret; -} diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index d791458fe52a..98b4d89b4368 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -158,7 +158,6 @@ extern struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block, extern int udf_setsize(struct inode *, loff_t); extern void udf_evict_inode(struct inode *); extern int udf_write_inode(struct inode *, struct writeback_control *wbc); -extern udf_pblk_t udf_block_map(struct inode *inode, sector_t block); extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *, struct kernel_lb_addr *, uint32_t *, sector_t *); extern int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block, From patchwork Tue Jan 24 12:17:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3350EC38142 for ; Tue, 24 Jan 2023 12:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233674AbjAXMS3 (ORCPT ); Tue, 24 Jan 2023 07:18:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbjAXMSS (ORCPT ); Tue, 24 Jan 2023 07:18:18 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B07442F2 for ; Tue, 24 Jan 2023 04:18:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2121021891; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7YQgsjE0joQXQSCH/IOIe0asDKQRYrNFJhj6ja/et2g=; b=FHqI9OZWQdPDfZ+WXdsWmyZ3UjA/mGDeejwT6jNtXTAOLjyNDcNcv32gIS/Pd8CuZpYHTm BVaPiYu2dTblfreUCCOmB9N6KUYEzwrlA8bclp+aSm0sYbn5Jw4NPCmX4cw5e/Be9Pwc2r m7BL8JGsqfbDpNMRaenNEN5Mi/dK9tY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7YQgsjE0joQXQSCH/IOIe0asDKQRYrNFJhj6ja/et2g=; b=K+5IrFAdIs9MM66PdT1ubKFSW59ucX28L6ps8I6cBa3wjY2fr9vuOP2vfto4pocawKXoIH UmUBXrPLsnoKF0Cg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 11F10139FF; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /5ZfBIfMz2PmNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 3A1E4A06D7; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 10/22] udf: Pass mapping request into inode_getblk() Date: Tue, 24 Jan 2023 13:17:56 +0100 Message-Id: <20230124121814.25951-10-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6182; i=jack@suse.cz; h=from:subject; bh=PaEjSgtpfsCF7D2IprD2LXa6jSEMi5MEez8mF7aNvTA=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x1nxG+ayOnzj1hQF/4o3ErFfVYjyZjXYUXRA/8 WIKFp3CJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MdQAKCRCcnaoHP2RA2czDB/ 9fqq5ruShR8H23QqVcBqodoQQwdO+iSurTBNv9+6eekAULXHo6rCMxYo0XNibeZ43IlwsM3IGdwhV7 oOtjV1YBrbOj0ThpON344uwJled64y7jW3R+mObXcBhevS6BDuaf/fdJl4/HJYh2nP6sFuZVKtqd2n itG2zYXSUVGfwFYO52HYOcjFYrovmSbBIwNzJ/+7++HZ8Y97GtVLmGC3C2s/IcvzW44YxGcFYl8+86 eMZSw9FX3U+yUOwAcm2hmjhyENfFQ5LN1lcebaYAnDFMd1qha/eDAKsW3SfMYYl6urPJRob3zC75uU ERGuvxJ0aMPwCMCJnc4Yn/mthKenIv X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Pass struct udf_map_rq into inode_getblk() instead of unfolding it and the putting the results back. Signed-off-by: Jan Kara --- fs/udf/inode.c | 60 ++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index e098d69991d0..5c6725a5bb88 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -58,7 +58,7 @@ static umode_t udf_convert_permissions(struct fileEntry *); static int udf_update_inode(struct inode *, int); static int udf_sync_inode(struct inode *inode); static int udf_alloc_i_data(struct inode *inode, size_t size); -static sector_t inode_getblk(struct inode *, sector_t, int *, int *); +static int inode_getblk(struct inode *inode, struct udf_map_rq *map); static int udf_insert_aext(struct inode *, struct extent_position, struct kernel_lb_addr, uint32_t); static void udf_split_extents(struct inode *, int *, int, udf_pblk_t, @@ -336,7 +336,7 @@ struct udf_map_rq { static int udf_map_block(struct inode *inode, struct udf_map_rq *map) { - int err, new; + int err; struct udf_inode_info *iinfo = UDF_I(inode); map->oflags = 0; @@ -367,14 +367,9 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map) if (((loff_t)map->lblk) << inode->i_blkbits > iinfo->i_lenExtents) udf_discard_prealloc(inode); udf_clear_extent_cache(inode); - map->pblk = inode_getblk(inode, map->lblk, &err, &new); + err = inode_getblk(inode, map); up_write(&iinfo->i_data_sem); - if (err) - return err; - map->oflags |= UDF_BLK_MAPPED; - if (new) - map->oflags |= UDF_BLK_NEW; - return 0; + return err; } static int udf_get_block(struct inode *inode, sector_t block, @@ -627,8 +622,7 @@ static int udf_extend_file(struct inode *inode, loff_t newsize) return err; } -static sector_t inode_getblk(struct inode *inode, sector_t block, - int *err, int *new) +static int inode_getblk(struct inode *inode, struct udf_map_rq *map) { struct kernel_long_ad laarr[EXTENT_MERGE_SIZE]; struct extent_position prev_epos, cur_epos, next_epos; @@ -637,21 +631,20 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, struct kernel_lb_addr eloc, tmpeloc; int c = 1; loff_t lbcount = 0, b_off = 0; - udf_pblk_t newblocknum, newblock; + udf_pblk_t newblocknum; sector_t offset = 0; int8_t etype; struct udf_inode_info *iinfo = UDF_I(inode); udf_pblk_t goal = 0, pgoal = iinfo->i_location.logicalBlockNum; int lastblock = 0; bool isBeyondEOF; + int ret = 0; - *err = 0; - *new = 0; prev_epos.offset = udf_file_entry_alloc_offset(inode); prev_epos.block = iinfo->i_location; prev_epos.bh = NULL; cur_epos = next_epos = prev_epos; - b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; + b_off = (loff_t)map->lblk << inode->i_sb->s_blocksize_bits; /* find the extent which contains the block we are looking for. alternate between laarr[0] and laarr[1] for locations of the @@ -715,13 +708,13 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, inode->i_sb->s_blocksize); udf_write_aext(inode, &cur_epos, &eloc, elen, 1); } - newblock = udf_get_lb_pblock(inode->i_sb, &eloc, offset); + map->oflags = UDF_BLK_MAPPED; + map->pblk = udf_get_lb_pblock(inode->i_sb, &eloc, offset); goto out_free; } /* Are we beyond EOF and preallocated extent? */ if (etype == -1) { - int ret; loff_t hole_len; isBeyondEOF = true; @@ -741,11 +734,8 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, /* Create extents for the hole between EOF and offset */ hole_len = (loff_t)offset << inode->i_blkbits; ret = udf_do_extend_file(inode, &prev_epos, laarr, hole_len); - if (ret < 0) { - *err = ret; - newblock = 0; + if (ret < 0) goto out_free; - } c = 0; offset = 0; count += ret; @@ -795,7 +785,7 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) newblocknum = laarr[c].extLocation.logicalBlockNum + offset; else { /* otherwise, allocate a new block */ - if (iinfo->i_next_alloc_block == block) + if (iinfo->i_next_alloc_block == map->lblk) goal = iinfo->i_next_alloc_goal; if (!goal) { @@ -805,12 +795,9 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, newblocknum = udf_new_block(inode->i_sb, inode, iinfo->i_location.partitionReferenceNum, - goal, err); - if (!newblocknum) { - *err = -ENOSPC; - newblock = 0; + goal, &ret); + if (!newblocknum) goto out_free; - } if (isBeyondEOF) iinfo->i_lenExtents += inode->i_sb->s_blocksize; } @@ -834,30 +821,31 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, /* write back the new extents, inserting new extents if the new number * of extents is greater than the old number, and deleting extents if * the new number of extents is less than the old number */ - *err = udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); - if (*err < 0) + ret = udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); + if (ret < 0) goto out_free; - newblock = udf_get_pblock(inode->i_sb, newblocknum, + map->pblk = udf_get_pblock(inode->i_sb, newblocknum, iinfo->i_location.partitionReferenceNum, 0); - if (!newblock) { - *err = -EIO; + if (!map->pblk) { + ret = -EFSCORRUPTED; goto out_free; } - *new = 1; - iinfo->i_next_alloc_block = block + 1; - iinfo->i_next_alloc_goal = newblocknum + 1; + map->oflags = UDF_BLK_NEW | UDF_BLK_MAPPED; + iinfo->i_next_alloc_block = map->lblk + 1; + iinfo->i_next_alloc_goal = map->pblk + 1; inode->i_ctime = current_time(inode); if (IS_SYNC(inode)) udf_sync_inode(inode); else mark_inode_dirty(inode); + ret = 0; out_free: brelse(prev_epos.bh); brelse(cur_epos.bh); brelse(next_epos.bh); - return newblock; + return ret; } static void udf_split_extents(struct inode *inode, int *c, int offset, From patchwork Tue Jan 24 12:17:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47870C25B50 for ; Tue, 24 Jan 2023 12:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233663AbjAXMS2 (ORCPT ); Tue, 24 Jan 2023 07:18:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233590AbjAXMSS (ORCPT ); Tue, 24 Jan 2023 07:18:18 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E800442FC for ; Tue, 24 Jan 2023 04:18:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 20BFC1FE48; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=htUAAaELlcI6Pt4tZkmStUv6AH5ZIxV1KiGPmMSRRbQ=; b=XKjrhvk1JlKsKef+m+MWK29lAAolOQuupLYalw8KMouTkRb3BRbyCulLDoUB4MO9QTRh8I nhodX0g81aShzEzTwed0ASRUAEWRU8BH0LTPAzMFl9OFVKZ56Y82ypAF2WLnAzg3N5haYQ ccvb4nJKMFYFQYjuwcPfGHdOQJUS69I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=htUAAaELlcI6Pt4tZkmStUv6AH5ZIxV1KiGPmMSRRbQ=; b=GTF3PSHLbnjIzgEeYRBxBA4bfy1IOB87AV0H/tdF/HnXLcoupOoI81wZiZEsuHmNxB/IW+ og/wXlCseHOCZ9BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 10905139FB; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id B9IJBIfMz2PoNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 4007DA06D8; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 11/22] udf: Add flag to disable block preallocation Date: Tue, 24 Jan 2023 13:17:57 +0100 Message-Id: <20230124121814.25951-11-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2019; i=jack@suse.cz; h=from:subject; bh=DSZ41J9LUfigRPji09asiP/3SOiRhtVAKafdW7IE8yA=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x2xIDOWNsApT+VRjtZNBXMyUV6Pqc2E+eBb3r6 j7SooImJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MdgAKCRCcnaoHP2RA2R5UCA DO0VJoEHOUe+g/RjeDKb69ySC9jX1y6nBDXf2Sa7JU0gQVFbljsDNGSw6lyJ+tjl6Upk05ZbFJAxXp 1IyhetE2Y5wRXAlQDe7F7PrwCoFbsSPpufXitwtVJlL61gdx3k0GlMVyM7kTsjacOnnegkU03bK57C hDin0wEn5JS7TE+FTInmf7KmbkwJC4Y9ru1ooQJPpeKFKo0aUzqfMaOvxrsXSQVumbYZO/uqQMyBTM aOpNedF5InQSIlwjH6MhJUCmDtwl+eisTKSa6vH6XQAnwTtFaJDNpoLcHaRtL15m5jEzwmV7DFz8Lx XRv5Xxgr9lA9dQfZwNgnFR1U6LdQMQ X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In some cases we don't want to create block preallocation when allocating blocks. Add a flag to udf_map_rq controlling the behavior. Signed-off-by: Jan Kara --- fs/udf/inode.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 5c6725a5bb88..daacb793f6f1 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -322,7 +322,8 @@ int udf_expand_file_adinicb(struct inode *inode) return err; } -#define UDF_MAP_CREATE 0x01 /* Mapping can allocate new blocks */ +#define UDF_MAP_CREATE 0x01 /* Mapping can allocate new blocks */ +#define UDF_MAP_NOPREALLOC 0x02 /* Do not preallocate blocks */ #define UDF_BLK_MAPPED 0x01 /* Block was successfully mapped */ #define UDF_BLK_NEW 0x02 /* Block was freshly allocated */ @@ -381,6 +382,14 @@ static int udf_get_block(struct inode *inode, sector_t block, .iflags = create ? UDF_MAP_CREATE : 0, }; + /* + * We preallocate blocks only for regular files. It also makes sense + * for directories but there's a problem when to drop the + * preallocation. We might use some delayed work for that but I feel + * it's overengineering for a filesystem like UDF. + */ + if (!S_ISREG(inode->i_mode)) + map.iflags |= UDF_MAP_NOPREALLOC; err = udf_map_block(inode, &map); if (err < 0) return err; @@ -808,11 +817,7 @@ static int inode_getblk(struct inode *inode, struct udf_map_rq *map) * block */ udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); - /* We preallocate blocks only for regular files. It also makes sense - * for directories but there's a problem when to drop the - * preallocation. We might use some delayed work for that but I feel - * it's overengineering for a filesystem like UDF. */ - if (S_ISREG(inode->i_mode)) + if (!(map->iflags & UDF_MAP_NOPREALLOC)) udf_prealloc_extents(inode, c, lastblock, laarr, &endnum); /* merge any continuous blocks in laarr */ From patchwork Tue Jan 24 12:17:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F088AC54EAA for ; Tue, 24 Jan 2023 12:18:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233643AbjAXMSd (ORCPT ); Tue, 24 Jan 2023 07:18:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233606AbjAXMST (ORCPT ); Tue, 24 Jan 2023 07:18:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7762C442EA for ; Tue, 24 Jan 2023 04:18:18 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 32D8E1FE4A; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mh3HPeY/Udj549kPdT4KFYHO0Njbl/e+zxjftPCfC7c=; b=Xrzth2bhmfwk39z9zHH3x++pZnu29R7df+r8VPQJBQD2eqo0UjXcxhFe52XRsZVWeSEhOG 04uTZREuqB8er3Gznxfv3Hkkzmo6gd29zasfAimR5KQcztRRsrBMP49m2j+dzv//85SCQd 7J3fmG1exw7Sk9ro6XjV4cC0I9p2GkI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mh3HPeY/Udj549kPdT4KFYHO0Njbl/e+zxjftPCfC7c=; b=60+ByVUjdzKA11VTijfy3k3J49jZuWZQqRkxCT331iPojhjBUBuLJKNDzw6WZ804mU2Gx2 OqrqOua6rRjLRtBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 20DDA13A08; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 65UACIfMz2PsNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 46736A06E1; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 12/22] udf: Use udf_map_block() in udf_getblk() Date: Tue, 24 Jan 2023 13:17:58 +0100 Message-Id: <20230124121814.25951-12-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1134; i=jack@suse.cz; h=from:subject; bh=879ZWrfUCtr1ZKR4De4Adoug45It2BMNyLZBEVFtb0s=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x39Ci8th1ObO1LKa+XsqIDfxJ2A85gzzVtzw22 OqQsP5uJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MdwAKCRCcnaoHP2RA2fC2CA DGS84ZNMLSqwoGNlfd4KmujQrlxa4oC2CK41sWZHVbTSKswiNe3M591pgRdYvK3tf9P9hN+qVoawTa i+67x2+EK9OvEvUT3sb3u88mDjOEWBTlHvHtJyZxITRv0YsEZykFNhmYFG5N2ZU00qk6EdF1eU+/K4 Hd8uNXBUBePYv6TRPn+WpV8x0E1QVu9LCAByZI4rn/i3IVlYanK/YD+8VRpkMCcOzotSszAOZhk7RF XwZUOMw31G3/m6iIcoIqHVx7TA4oHtAqzRBqdYcdq8SHwKhZr+CYy5w1xDQwaM0PL5yVIsNkOEMgRw 3BKoI7So0G287e1h8RA4G+D4NmJ6NC X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the new function udf_map_block() in udf_getblk(). Signed-off-by: Jan Kara --- fs/udf/inode.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index daacb793f6f1..4e6b855ffd02 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -405,14 +405,15 @@ static struct buffer_head *udf_getblk(struct inode *inode, udf_pblk_t block, int create, int *err) { struct buffer_head *bh; - struct buffer_head dummy; - - dummy.b_state = 0; - dummy.b_blocknr = -1000; - *err = udf_get_block(inode, block, &dummy, create); - if (!*err && buffer_mapped(&dummy)) { - bh = sb_getblk(inode->i_sb, dummy.b_blocknr); - if (buffer_new(&dummy)) { + struct udf_map_rq map = { + .lblk = block, + .iflags = create ? UDF_MAP_CREATE : 0, + }; + + *err = udf_map_block(inode, &map); + if (!*err && map.oflags & UDF_BLK_MAPPED) { + bh = sb_getblk(inode->i_sb, map.pblk); + if (map.oflags & UDF_BLK_NEW) { lock_buffer(bh); memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); set_buffer_uptodate(bh); From patchwork Tue Jan 24 12:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0631C25B4E for ; Tue, 24 Jan 2023 12:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233692AbjAXMSc (ORCPT ); Tue, 24 Jan 2023 07:18:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjAXMST (ORCPT ); Tue, 24 Jan 2023 07:18:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C1137F0D for ; Tue, 24 Jan 2023 04:18:18 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 294E31FE49; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MvVQ7ivB1pfL459eXGObvMwgerzTX7YhI+zVj0o6Re4=; b=tZCfKHwt+sxrPwunZqZgjl4Tq3UbqLhMJglbhR+Z4AcJWYLiUxK3WNza7PmSGaErvswFS6 Jb4/eITHR9+7JRbwhTiOUbA5l7tIf+4xLiKXGb0eweG6PoErrThl/s1DH4dIjZTN7ddkOf WqpA57cwuZWN2qSDw9NHUAH/rj4NSe0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MvVQ7ivB1pfL459eXGObvMwgerzTX7YhI+zVj0o6Re4=; b=VnkPt2SjFVcgG5wttqZCFADebgqC14Ni20x2S6sWBUwiP/4Y+q0O11PeKSH+7ZD5biVOK2 Z6Qsi8cfl2kKjRDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 18EBF13A04; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6DNTBYfMz2PpNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 4CEBBA06E2; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 13/22] udf: Fold udf_getblk() into udf_bread() Date: Tue, 24 Jan 2023 13:17:59 +0100 Message-Id: <20230124121814.25951-13-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2015; i=jack@suse.cz; h=from:subject; bh=wH/dV+bDpVEl8+ezd55LRPKIH6DdZmDKbjBpS9Q/yzo=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x3pGSn6fbN1XZtcgN1H13KvZRm0+d4PmZ5U1s5 Gw64XDKJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MdwAKCRCcnaoHP2RA2e/NCA DZdLtJh/5/KazHGjiH2byLX1/oJgg52LW15alWr/dvm/Dza9nsMSzwj4CxUsYQxNA34GTLXLnFh4Kk vqzSausoD/MHnUOr4PxfGiQr8ovrMj1iTVMonGfCdixQ0Y/psLlozWdZATrtqyPYPuj4n0tTuVgknZ QRjYVjJVZCZTktvbCij0zOobn7ZceKD7LgK24dn8Uw81eUtrzsRunSLBwJqh00hJ57r/eGdtDXbw5E c2MiAjLERIy0gKnJZmU7Nt0vmwPHvDyN+IzNuf39mL3SXJMp9BiEQCyekhXY8dbdKif5O5DzVow5qu Yl2sum/7QpnGw39uXeQRVuzoDI1bzj X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org udf_getblk() has a single call site. Fold it there. Signed-off-by: Jan Kara --- fs/udf/inode.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 4e6b855ffd02..4554d1e54eb3 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -401,31 +401,6 @@ static int udf_get_block(struct inode *inode, sector_t block, return 0; } -static struct buffer_head *udf_getblk(struct inode *inode, udf_pblk_t block, - int create, int *err) -{ - struct buffer_head *bh; - struct udf_map_rq map = { - .lblk = block, - .iflags = create ? UDF_MAP_CREATE : 0, - }; - - *err = udf_map_block(inode, &map); - if (!*err && map.oflags & UDF_BLK_MAPPED) { - bh = sb_getblk(inode->i_sb, map.pblk); - if (map.oflags & UDF_BLK_NEW) { - lock_buffer(bh); - memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); - set_buffer_uptodate(bh); - unlock_buffer(bh); - mark_buffer_dirty_inode(bh, inode); - } - return bh; - } - - return NULL; -} - /* Extend the file with new blocks totaling 'new_block_bytes', * return the number of extents added */ @@ -1140,10 +1115,28 @@ struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block, int create, int *err) { struct buffer_head *bh = NULL; + struct udf_map_rq map = { + .lblk = block, + .iflags = create ? UDF_MAP_CREATE : 0, + }; - bh = udf_getblk(inode, block, create, err); - if (!bh) + *err = udf_map_block(inode, &map); + if (*err || !(map.oflags & UDF_BLK_MAPPED)) + return NULL; + + bh = sb_getblk(inode->i_sb, map.pblk); + if (!bh) { + *err = -ENOMEM; return NULL; + } + if (map.oflags & UDF_BLK_NEW) { + lock_buffer(bh); + memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); + set_buffer_uptodate(bh); + unlock_buffer(bh); + mark_buffer_dirty_inode(bh, inode); + return bh; + } if (bh_read(bh, 0) >= 0) return bh; From patchwork Tue Jan 24 12:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 838FFC25B50 for ; Tue, 24 Jan 2023 12:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbjAXMSe (ORCPT ); Tue, 24 Jan 2023 07:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233607AbjAXMST (ORCPT ); Tue, 24 Jan 2023 07:18:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE696442EB for ; Tue, 24 Jan 2023 04:18:18 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 453901FE4C; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UzIT2ogqM6g985qdJPjq2SBXyIwASRSm+gjHhyco+Nc=; b=x/+onkdJP4myHMj6m2B4wmVSPvqTEPaQtNjVZv1wHzBdXNaEzIj8/9RW2YMfRvbVHMretZ 4FMFgPyXhIJaiuBDPk2vQRL8I5A4tSQb+8aUrypmulEyWf5Z2nBr2LpOdY3wxPtfBQ2VIq 3ejrAmU5u/EZk2E2kDnN+DQgv9FanlY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UzIT2ogqM6g985qdJPjq2SBXyIwASRSm+gjHhyco+Nc=; b=3e0nzqMYGGpr9cNd9AW1CduEAoMqMq+h+YQICsYrc1GLPYlqTUuem0d80dcIxrsydJ22yG qXOsThmosMC//JAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2BDEE139FB; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nnGzCofMz2PyNwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 52C0AA06E3; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara , syzbot+aebf90eea2671c43112a@syzkaller.appspotmail.com Subject: [PATCH 14/22] udf: Protect rename against modification of moved directory Date: Tue, 24 Jan 2023 13:18:00 +0100 Message-Id: <20230124121814.25951-14-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2092; i=jack@suse.cz; h=from:subject; bh=Zu8Vih3EU1Cmz8d/II2LP6vgNBGzt1ICxuXfhJV63EU=; b=owGbwMvMwME4Z+4qdvsUh5uMp9WSGJLPn6mI/zCpmOvx+yv9XXWL7xzf3qwhvq1y344m14qzT6TW HMuS72Q0ZmFg5GCQFVNkWR15UfvaPKOuraEaMjCDWJlApjBwcQrARF5Lsf/PvRY40fK7lp0ak/2aNU pHZ/onfDTc+mWf5Lva9slHS7rWzXj9auWJVS3tXfbrOuSnbhZ5LdbbmNKhuWJHaseqKMmvqZ84Tlkt vfMm4i+jeklBkktlZQeT/IM5t/87O+w+w91yfQPbncUGJ7n5H/9W2tyl0F1Vm7CfPVChlWF2YHrew9 Tl9xsLw3Y3Vf6J+XOy9Ipj5TI7sYrITaXaDya0uWz6djbBQYZxU2Y3C5ujq9givir9lGZf9+QfmQcu n57Xsq3u8Wmm9lQz/3bF64fsG2x5w1ZO+enSN8GtYF5GcZFWVn2STULqk5okERaJeSeEp7WKREdV9a jo3zCZWRv8gzfNJXNCl7bOvD5pAA== X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When we are renaming a directory to a different directory, we need to update '..' entry in the moved directory. However nothing prevents moved directory from being modified and even converted from the in-ICB format to the normal format which results in a crash. Fix the problem by locking the moved directory. Reported-by: syzbot+aebf90eea2671c43112a@syzkaller.appspotmail.com Signed-off-by: Jan Kara --- fs/udf/namei.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 49fab30afff3..1b0f4c600b63 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -782,6 +782,11 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir, if (!empty_dir(new_inode)) goto out_oiter; } + /* + * We need to protect against old_inode getting converted from + * ICB to normal directory. + */ + inode_lock_nested(old_inode, I_MUTEX_NONDIR2); retval = udf_fiiter_find_entry(old_inode, &dotdot_name, &diriter); if (retval == -ENOENT) { @@ -790,8 +795,10 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir, old_inode->i_ino); retval = -EFSCORRUPTED; } - if (retval) + if (retval) { + inode_unlock(old_inode); goto out_oiter; + } has_diriter = true; tloc = lelb_to_cpu(diriter.fi.icb.extLocation); if (udf_get_lb_pblock(old_inode->i_sb, &tloc, 0) != @@ -869,6 +876,7 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir, udf_dir_entry_len(&diriter.fi)); udf_fiiter_write_fi(&diriter, NULL); udf_fiiter_release(&diriter); + inode_unlock(old_inode); inode_dec_link_count(old_dir); if (new_inode) @@ -880,8 +888,10 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir, } return 0; out_oiter: - if (has_diriter) + if (has_diriter) { udf_fiiter_release(&diriter); + inode_unlock(old_inode); + } udf_fiiter_release(&oiter); return retval; From patchwork Tue Jan 24 12:18:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CA53C25B50 for ; Tue, 24 Jan 2023 12:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233716AbjAXMSo (ORCPT ); Tue, 24 Jan 2023 07:18:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233571AbjAXMSY (ORCPT ); Tue, 24 Jan 2023 07:18:24 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A7544BCA for ; Tue, 24 Jan 2023 04:18:19 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5BDBB1FE4D; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DuRHlhx2mHjz1hrJYA0ACB01C/AufQqOFLhYM4oFqa4=; b=FNYjaZ0FzHTyDIgrPAy4np5RwRG/0ujjMmyzA9MfiOfmF8s6Sja+kbE1SpaKZ8EShhwL6j 3CnLQPDgeoGTTnErHQbtLttl9UDJLSAjs+o2Lqfzt/P/ASHMMfGlAA+BiXT1X4c6a6tew9 zwXK6gZQ/+gZuZnDdUfji0wdrUIIDvA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DuRHlhx2mHjz1hrJYA0ACB01C/AufQqOFLhYM4oFqa4=; b=U6ge9Ga5tsjwwNoyMXQFVZBAvjtW1BGfSy8Mb7DvMxDT1RmyGpPCMY3Ln6gSc7KSTgFcwk k+ww5Pw11f6CAeDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4EBF9139FB; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Yi05E4fMz2P2NwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 58614A06F3; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 15/22] udf: Push i_data_sem locking into udf_expand_file_adinicb() Date: Tue, 24 Jan 2023 13:18:01 +0100 Message-Id: <20230124121814.25951-15-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3436; i=jack@suse.cz; h=from:subject; bh=egCksdVqpUNTMa2JmVa1OO3JlGwu/sZq7LNwywphVOQ=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x5hbvW1xCK+XuiCOd/sp3kv/lJaYlF3uhY67/H Wzm245qJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MeQAKCRCcnaoHP2RA2eLbB/ 0W9emDbtPFyu6N6HkxW9kjRFRNlrhj9RuddYGoCw+SLljZRChFLCka0SqlBbCxlWVN1qaw5Z9EFeBh LdWkEIL3paJTeErRHHfKiUwdDvG5IZLQMKZZxqjwN6N9A/RcRx41eUQ85MHdmJ/+epUVkXeIv2jMee QYH3Hw4f9b0bTBQLqKBx1E1PhDfHDvuV3dxZ8rMja3GlpOuK7qIrceiCiE1QeYIaHKcjfylHBx1h09 llZxvVXCsT/vKA8NU2sNfP6y8iMGZgFnJggciuj7IqycD8kHfgqflpi7KAOjyIsR0swBWhDToPF7eQ Wx/YO4/bCdkKvmuO9nbwrdBNXC4hq3 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The checks we do in udf_setsize() and udf_file_write_iter() are safe to do only with i_rwsem locked as it stabilizes both file type and file size. Hence we don't need to lock i_data_sem before we enter udf_expand_file_adinicb() which simplifies the locking somewhat. Signed-off-by: Jan Kara --- fs/udf/file.c | 11 +++++------ fs/udf/inode.c | 18 ++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/fs/udf/file.c b/fs/udf/file.c index 8be51161f3e5..60524814c594 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -148,7 +148,6 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (retval <= 0) goto out; - down_write(&iinfo->i_data_sem); if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + iocb->ki_pos + iov_iter_count(from))) { @@ -158,15 +157,15 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) udf_debug("udf_expand_adinicb: err=%d\n", err); return err; } - } else - up_write(&iinfo->i_data_sem); + } retval = __generic_file_write_iter(iocb, from); out: - down_write(&iinfo->i_data_sem); - if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && retval > 0) + if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && retval > 0) { + down_write(&iinfo->i_data_sem); iinfo->i_lenAlloc = inode->i_size; - up_write(&iinfo->i_data_sem); + up_write(&iinfo->i_data_sem); + } inode_unlock(inode); if (retval > 0) { diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 4554d1e54eb3..b13c35335dd1 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -247,7 +247,6 @@ const struct address_space_operations udf_aops = { /* * Expand file stored in ICB to a normal one-block-file * - * This function requires i_data_sem for writing and releases it. * This function requires i_mutex held */ int udf_expand_file_adinicb(struct inode *inode) @@ -259,6 +258,7 @@ int udf_expand_file_adinicb(struct inode *inode) WARN_ON_ONCE(!inode_is_locked(inode)); if (!iinfo->i_lenAlloc) { + down_write(&iinfo->i_data_sem); if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; else @@ -269,11 +269,6 @@ int udf_expand_file_adinicb(struct inode *inode) mark_inode_dirty(inode); return 0; } - /* - * Release i_data_sem so that we can lock a page - page lock ranks - * above i_data_sem. i_mutex still protects us against file changes. - */ - up_write(&iinfo->i_data_sem); page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS); if (!page) @@ -1160,19 +1155,18 @@ int udf_setsize(struct inode *inode, loff_t newsize) iinfo = UDF_I(inode); if (newsize > inode->i_size) { - down_write(&iinfo->i_data_sem); if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { - if (bsize < + if (bsize >= (udf_file_entry_alloc_offset(inode) + newsize)) { - err = udf_expand_file_adinicb(inode); - if (err) - return err; down_write(&iinfo->i_data_sem); - } else { iinfo->i_lenAlloc = newsize; goto set_size; } + err = udf_expand_file_adinicb(inode); + if (err) + return err; } + down_write(&iinfo->i_data_sem); err = udf_extend_file(inode, newsize); if (err) { up_write(&iinfo->i_data_sem); From patchwork Tue Jan 24 12:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 636A1C25B50 for ; Tue, 24 Jan 2023 12:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233722AbjAXMSp (ORCPT ); Tue, 24 Jan 2023 07:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbjAXMSY (ORCPT ); Tue, 24 Jan 2023 07:18:24 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3513E44BCB for ; Tue, 24 Jan 2023 04:18:19 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 746711FE4E; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jZVUeTNLEEUx0443mgR5K2SttDqpFw0ZKjkku6TP0Wo=; b=FTU7W/NPycRyOqmbgumlwFRN/Iye3TaSmEULaPd4eVJv0VNy00WkBIwwdYO//b39uO7pqK XZUWphe+5rAZBWgG4mvR3+3ezB6DuVloqbOtLp/R0ZZMySKSGsVuFZ0rItxbmhFvLYRYpv RkIGu+ziCZ8vk6cIeAun4Z2XLoKgJIQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jZVUeTNLEEUx0443mgR5K2SttDqpFw0ZKjkku6TP0Wo=; b=nAOC7Yev8SVK14RHjieC8R1SYMfMttds0axM0RR4IcvcYy5QJh/CbrpeviD313X07t2xLj grdXdOH4xXNscfBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 68567139FB; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IGB4GYfMz2P6NwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 5E528A06FD; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 16/22] udf: Push i_data_sem locking into udf_extend_file() Date: Tue, 24 Jan 2023 13:18:02 +0100 Message-Id: <20230124121814.25951-16-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1494; i=jack@suse.cz; h=from:subject; bh=YKApF8RYDN9TvkwYm3OzvSY4/kL0/650RvrVTrDWQvw=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x6LI9JOYK2v0mUqcAJQMh2kou2Tw7VrgmDtWo+ 499fQBSJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MegAKCRCcnaoHP2RA2UIuB/ 9JXVL9CfLKy6knsB5sB5yyn6jbzueomUsmTURyofmPbX3AtI5+EtmDt19L7JbUUWUfk589Emr2sbvp JTXsA05HjVeRFedf3HdrxvR01RaDQzTHGyi2/DXBBIldOgRv9M5UjhfnJG0ILH7d2RK+KArgyfMS/U 3pByj6NfFuxuVq16ZutBE3CGkOT937kOA8BDQYP0lpRRqMFnh6DO/sFZUacFMjeDpnNGqFx7M2UI5/ FuxwGUPSvXX43L4RCD7RQrlGYFref4UnYOWpHX/sM/B1NQekiYITSAWHMy4H9sp6N2iktYC5YMM6Bm Z0gOC9qQOrIvOR8dU3AnIvVnT0T6ar X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Push i_data_sem locking into udf_extend_file(). It somewhat simplifies the code around it. Signed-off-by: Jan Kara --- fs/udf/inode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index b13c35335dd1..3ffeb5651689 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -555,6 +555,7 @@ static int udf_extend_file(struct inode *inode, loff_t newsize) else BUG(); + down_write(&iinfo->i_data_sem); /* * When creating hole in file, just don't bother with preserving * preallocation. It likely won't be very useful anyway. @@ -599,6 +600,7 @@ static int udf_extend_file(struct inode *inode, loff_t newsize) err = 0; out: brelse(epos.bh); + up_write(&iinfo->i_data_sem); return err; } @@ -1160,20 +1162,17 @@ int udf_setsize(struct inode *inode, loff_t newsize) (udf_file_entry_alloc_offset(inode) + newsize)) { down_write(&iinfo->i_data_sem); iinfo->i_lenAlloc = newsize; + up_write(&iinfo->i_data_sem); goto set_size; } err = udf_expand_file_adinicb(inode); if (err) return err; } - down_write(&iinfo->i_data_sem); err = udf_extend_file(inode, newsize); - if (err) { - up_write(&iinfo->i_data_sem); + if (err) return err; - } set_size: - up_write(&iinfo->i_data_sem); truncate_setsize(inode, newsize); } else { if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { From patchwork Tue Jan 24 12:18:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06DE3C38142 for ; Tue, 24 Jan 2023 12:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232302AbjAXMSt (ORCPT ); Tue, 24 Jan 2023 07:18:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233617AbjAXMSZ (ORCPT ); Tue, 24 Jan 2023 07:18:25 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35A1944BD5 for ; Tue, 24 Jan 2023 04:18:19 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 775461FE4F; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JsT4aRefnQBpHkUR2ma5N39hyZqd1flLstMAiZLHU3k=; b=zIWJ8c/szjh9QIe0G6m6ZL0/UCz1Q+XwxewrMolvHvgoFsAUrXVeXyteUlPczqCWpNtBIS 8KAfFrUX/a1EctFyNZpjg9sQVrmEhHUKwQQun9I3eGb/d6p6jtJ6gx/QjvS6WunwJDfhiY KYPFxhAFc+2QpQ1QBdjQGHZg95e5UN0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JsT4aRefnQBpHkUR2ma5N39hyZqd1flLstMAiZLHU3k=; b=apEnnHu2yGn3oKSnGjX5e5QHy1NUI++1IKtfbry7nrOQeRK36Ip7e2/+7NorOuI0SJhA5A pDStt3xopN8nygDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6D2C4139FF; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rAOnGofMz2P8NwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 642E8A0700; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 17/22] udf: Simplify error handling in udf_file_write_iter() Date: Tue, 24 Jan 2023 13:18:03 +0100 Message-Id: <20230124121814.25951-17-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1218; i=jack@suse.cz; h=from:subject; bh=sd/yUBk+uX8ZycxHsGvjqS2//3XacFWnk0rKsjk47Ss=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x77JKt1HENs4hcTBLHjIIYJc/SUNIKXGoBWywW 0L9JHayJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MewAKCRCcnaoHP2RA2TajCA CC1FiimTLGp63iG/2qlX23NzWcJQur/8m509Z4e4Iqp9Z326asPPHUZpm8fRZOpEY+VsLv2wnwH8GS IEI4oHuwCqEs1xQhULxi9E//3TbLRW21zAs+8GHI46OLgXMAWxh20GROuy+fiL/JdfEsIyjm9IEJDD QhApsKhdJbO1z9CSt6XonURBzc4hcNff3vZOuE+Z4M2p6mLt5LGJZXB8XyxJycbmAGKbcgscm/H2SH nRGiS47X9sROIbU6J8fXsVAEr3eIsVh9V6P9zJo27pGmpsXElDW9RvQwVUHd6CIP76DSj7Cf6Fclwl PQTpKZXevCSy5zKE8PfVD8MhouRpyx X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When udf_expand_file_adinicb() fails, we can now use the standard exit path instead of implementing our own. Signed-off-by: Jan Kara --- fs/udf/file.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/udf/file.c b/fs/udf/file.c index 60524814c594..596d703fb6c8 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -140,7 +140,6 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) struct file *file = iocb->ki_filp; struct inode *inode = file_inode(file); struct udf_inode_info *iinfo = UDF_I(inode); - int err; inode_lock(inode); @@ -151,12 +150,9 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + iocb->ki_pos + iov_iter_count(from))) { - err = udf_expand_file_adinicb(inode); - if (err) { - inode_unlock(inode); - udf_debug("udf_expand_adinicb: err=%d\n", err); - return err; - } + retval = udf_expand_file_adinicb(inode); + if (retval) + goto out; } retval = __generic_file_write_iter(iocb, from); From patchwork Tue Jan 24 12:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9828C38142 for ; Tue, 24 Jan 2023 12:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233688AbjAXMSb (ORCPT ); Tue, 24 Jan 2023 07:18:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233593AbjAXMST (ORCPT ); Tue, 24 Jan 2023 07:18:19 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2F1E3525E for ; Tue, 24 Jan 2023 04:18:17 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8D6CD21888; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=196YHvJ19wKMQw6z3X95DukOPQ9j7aYHN0sgl1/Ahlc=; b=bhy3mSakMBJjDpx5XosRnSA5a7VmfGT1ohjYe7R+SdUHwV4k2W7Hjhi0MlipMJG/sBHya7 cgEQFu0b2jCENDUJ1dAklKwR4uzZXqrQg0bcjQ+lWgJm3N8JNSxnYUvlaqJKgRebCteras tXOIcqIsJXRRV2YFqqQxAFmFK7R2zyg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=196YHvJ19wKMQw6z3X95DukOPQ9j7aYHN0sgl1/Ahlc=; b=HK58xVKnUDt62wF5VrllPIfJ4vAzYqsErgtaGPAgj3/J5Iv42vTcrX9s3kHhdYimLL925B uiRKywwIE1Ms/JBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 80392139FB; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id f/hKH4fMz2P/NwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 6AA0AA0707; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 18/22] udf: Protect truncate and file type conversion with invalidate_lock Date: Tue, 24 Jan 2023 13:18:04 +0100 Message-Id: <20230124121814.25951-18-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2790; i=jack@suse.cz; h=from:subject; bh=mFr59aqWn7clgWTUq5BN0ALZS9t7E1WNUnhUBusUFog=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x8EvMWq4ZCmgPBGl//0skEQRRgXoCoe/bfIhVy N5PyFMuJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MfAAKCRCcnaoHP2RA2dVZB/ 96ZW99dzQ8f595jtlSGI1v4tzQc1arIoRHV1iJrX5RKHGG5NcSAKsXtIpQK6ch1ekXOXF5K4h0UTy2 SFavAsJrx7noHtdW8TkqQgJHxM4sibxjQ8j1YEjjPpeLdiROgUAOh6gwDBKETydfpd+NycsOrV0Nhk Ja7qClCWj5qrspXo+hrmLE6HUAGfMrM8ElZIAMZmdSHcC+rK91BXa3qICeluslh0rBfC3LnJ1pTSUt O/LowPdR7D6E+vRb9VwynNWeGP+MvMKlXQA91DvBWLuRVk1vlJ+olGKB9A5rXIbcG3ntB1VxJJcY5S uoErA4VTdYj7TZtoDST4pa2wrl/LVG X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Protect truncate and file type conversion in udf_file_write_iter() with invalidate lock. That will allow us to serialize these paths with page faults so that the page fault can determine the file type in a racefree way. Signed-off-by: Jan Kara --- fs/udf/file.c | 2 ++ fs/udf/inode.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/udf/file.c b/fs/udf/file.c index 596d703fb6c8..cf050bdffd9e 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -150,7 +150,9 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + iocb->ki_pos + iov_iter_count(from))) { + filemap_invalidate_lock(inode->i_mapping); retval = udf_expand_file_adinicb(inode); + filemap_invalidate_unlock(inode->i_mapping); if (retval) goto out; } diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 3ffeb5651689..7109adcceefe 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -1145,7 +1145,7 @@ struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block, int udf_setsize(struct inode *inode, loff_t newsize) { - int err; + int err = 0; struct udf_inode_info *iinfo; unsigned int bsize = i_blocksize(inode); @@ -1155,6 +1155,7 @@ int udf_setsize(struct inode *inode, loff_t newsize) if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) return -EPERM; + filemap_invalidate_lock(inode->i_mapping); iinfo = UDF_I(inode); if (newsize > inode->i_size) { if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { @@ -1167,11 +1168,11 @@ int udf_setsize(struct inode *inode, loff_t newsize) } err = udf_expand_file_adinicb(inode); if (err) - return err; + goto out_unlock; } err = udf_extend_file(inode, newsize); if (err) - return err; + goto out_unlock; set_size: truncate_setsize(inode, newsize); } else { @@ -1189,14 +1190,14 @@ int udf_setsize(struct inode *inode, loff_t newsize) err = block_truncate_page(inode->i_mapping, newsize, udf_get_block); if (err) - return err; + goto out_unlock; truncate_setsize(inode, newsize); down_write(&iinfo->i_data_sem); udf_clear_extent_cache(inode); err = udf_truncate_extents(inode); up_write(&iinfo->i_data_sem); if (err) - return err; + goto out_unlock; } update_time: inode->i_mtime = inode->i_ctime = current_time(inode); @@ -1204,7 +1205,9 @@ int udf_setsize(struct inode *inode, loff_t newsize) udf_sync_inode(inode); else mark_inode_dirty(inode); - return 0; +out_unlock: + filemap_invalidate_unlock(inode->i_mapping); + return err; } /* From patchwork Tue Jan 24 12:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCE65C25B50 for ; Tue, 24 Jan 2023 12:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233727AbjAXMSt (ORCPT ); Tue, 24 Jan 2023 07:18:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233630AbjAXMSZ (ORCPT ); Tue, 24 Jan 2023 07:18:25 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2DCB44BD7 for ; Tue, 24 Jan 2023 04:18:19 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9F6531FE51; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/LexzJkYyZdL5w07xtp8eX7kMac/zwtvHB+V69eQ6mI=; b=FFCg81xwFEwDX1dNIKMaferuiGbBEwjcVz4PytqXj4/tj5YxVEsbify6GkqsFfnqEl43uF QtFFnJ7GE5/7wwi09V/Np/RHW3RjW2sxGZwfiDvkfulmLxbBRLNaZqLCjjgofFPs6PJqYm n+S6K/p9WeQLM5mNasGuEaK2mcjg+A8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/LexzJkYyZdL5w07xtp8eX7kMac/zwtvHB+V69eQ6mI=; b=nETo4woXX683PDV/GNGrgi+6aH5zTM9IlguTIv9V90wJg5uK6DKbpv0I53ThZtB95NX0+q 8SwO3uOHPdA2hhDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 90C5D139FB; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mgJUI4fMz2MEOAAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 70E65A0709; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 19/22] udf: Allocate blocks on write page fault Date: Tue, 24 Jan 2023 13:18:05 +0100 Message-Id: <20230124121814.25951-19-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4298; i=jack@suse.cz; h=from:subject; bh=9tAb4yLTLO+EwlDOvr7dLHGRtCRctwuLmZopa9FLRyA=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x91DLpx34IN+Hbc9o3MFLgFKzQWZgKIJc9JTmf sTg5C/mJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MfQAKCRCcnaoHP2RA2UvzCA CPWK78LvCrgGjeXW6rENaIkT7VNTbFn+DM+gt6qzKtROw22+tjEGy+AfRhz2BflFbk3yO/E46XXcuO y7bxOYEVFPQD4veUsLmmjRbfpzMFVpKy1qh8iWory/tBijs2A6K/71iwX97FM/Lc6zJBxe5pOTiO6n qmUfDIAaVqnwxPmh2NUu5ppJJUhI4y5tAyKIIvSwcOiMP6RRwSfrM+zIMeyqMVgNYb55q/Jrzg8oPY UjS+EK8khogT/qLolxtlGBwCEbA6bOLFspnPjHO3PJg5IQ9slNJp0ekI3cDMDPHYjNIiy1f9NnqDJX X+ONLM2QNWhtLjTQcwWFO/80B4wdTG X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently if file with holes is mapped, udf allocates blocks for dirtied pages during page writeback. This however creates problems when to truncate final extent to proper size and currently we leave the last extent untruncated which violates UDF standard. So allocate blocks on write page fault instead. In that case the last extent gets truncated the file is closed and everything is happy. Signed-off-by: Jan Kara --- fs/udf/file.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++- fs/udf/inode.c | 1 - fs/udf/udfdecl.h | 1 + 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/fs/udf/file.c b/fs/udf/file.c index cf050bdffd9e..322115c8369d 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -134,6 +134,57 @@ const struct address_space_operations udf_adinicb_aops = { .direct_IO = udf_adinicb_direct_IO, }; +static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf) +{ + struct vm_area_struct *vma = vmf->vma; + struct inode *inode = file_inode(vma->vm_file); + struct address_space *mapping = inode->i_mapping; + struct page *page = vmf->page; + loff_t size; + unsigned int end; + vm_fault_t ret = VM_FAULT_LOCKED; + int err; + + sb_start_pagefault(inode->i_sb); + file_update_time(vma->vm_file); + filemap_invalidate_lock_shared(mapping); + lock_page(page); + size = i_size_read(inode); + if (page->mapping != inode->i_mapping || page_offset(page) >= size) { + unlock_page(page); + ret = VM_FAULT_NOPAGE; + goto out_unlock; + } + /* Space is already allocated for in-ICB file */ + if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) + goto out_dirty; + if (page->index == size >> PAGE_SHIFT) + end = size & ~PAGE_MASK; + else + end = PAGE_SIZE; + err = __block_write_begin(page, 0, end, udf_get_block); + if (!err) + err = block_commit_write(page, 0, end); + if (err < 0) { + unlock_page(page); + ret = block_page_mkwrite_return(err); + goto out_unlock; + } +out_dirty: + set_page_dirty(page); + wait_for_stable_page(page); +out_unlock: + filemap_invalidate_unlock_shared(mapping); + sb_end_pagefault(inode->i_sb); + return ret; +} + +static const struct vm_operations_struct udf_file_vm_ops = { + .fault = filemap_fault, + .map_pages = filemap_map_pages, + .page_mkwrite = udf_page_mkwrite, +}; + static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { ssize_t retval; @@ -238,11 +289,19 @@ static int udf_release_file(struct inode *inode, struct file *filp) return 0; } +static int udf_file_mmap(struct file *file, struct vm_area_struct *vma) +{ + file_accessed(file); + vma->vm_ops = &udf_file_vm_ops; + + return 0; +} + const struct file_operations udf_file_operations = { .read_iter = generic_file_read_iter, .unlocked_ioctl = udf_ioctl, .open = generic_file_open, - .mmap = generic_file_mmap, + .mmap = udf_file_mmap, .write_iter = udf_file_write_iter, .release = udf_release_file, .fsync = generic_file_fsync, diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 7109adcceefe..7fd0aa2439e9 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -68,7 +68,6 @@ static void udf_prealloc_extents(struct inode *, int, int, static void udf_merge_extents(struct inode *, struct kernel_long_ad *, int *); static int udf_update_extents(struct inode *, struct kernel_long_ad *, int, int, struct extent_position *); -static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); static void __udf_clear_extent_cache(struct inode *inode) { diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index 98b4d89b4368..5ba59ab90d48 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -160,6 +160,7 @@ extern void udf_evict_inode(struct inode *); extern int udf_write_inode(struct inode *, struct writeback_control *wbc); extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *, struct kernel_lb_addr *, uint32_t *, sector_t *); +int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); extern int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block, struct extent_position *epos); extern int __udf_add_aext(struct inode *inode, struct extent_position *epos, From patchwork Tue Jan 24 12:18:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E44B9C25B4E for ; Tue, 24 Jan 2023 12:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233725AbjAXMSs (ORCPT ); Tue, 24 Jan 2023 07:18:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233621AbjAXMSZ (ORCPT ); Tue, 24 Jan 2023 07:18:25 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D1744BD6 for ; Tue, 24 Jan 2023 04:18:19 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9CC6C1FE50; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nckLWcQzsYvX8kXlysykKtgVwsDmxdKUhzMbUlGajww=; b=h1PamkActe46zxM/o0FOQoUhAUmlZkcOJt2Fg2n89OxIByPYsqEoYGQ40ug0FuI7/yePAe PoXafF2l8uAi20SaXYHH5BowhGMQV0sGk0Ls4JrsaTjA81RiumP6wnMDEgZC7TYE0qT4vg BCCwH9PIpG2+MMaZa5lOuJuiFWl3M38= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nckLWcQzsYvX8kXlysykKtgVwsDmxdKUhzMbUlGajww=; b=WMMLL9Ip62Ogmr1jINivRVV0XmGa+2BIwSKhqnzGbxf8Q2Blh29usBN1SVQIXlxCv9CRvf HU6GVlRCjR+3+dAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8BF8E139FF; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id R0EoIofMz2MCOAAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 7709AA06B6; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 20/22] udf: Do not allocate blocks on page writeback Date: Tue, 24 Jan 2023 13:18:06 +0100 Message-Id: <20230124121814.25951-20-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3801; i=jack@suse.cz; h=from:subject; bh=UDPzjm9gM+wpwcTYtHdj1kWWmX468c2GslrFahsGWUA=; b=owGbwMvMwME4Z+4qdvsUh5uMp9WSGJLPn6nzd8x+7ejftTjMNHkKf4XZXAExJYezfAmW1gea90jk OTt1MhqzMDByMMiKKbKsjryofW2eUdfWUA0ZmEGsTCBTGLg4BWAilVXs/93yI/Wd5l13aO98ZXpTZj ZvcNQvm8a0E2+4jrjFMGtnSpl1TtSbqulhN9m/k+3GUvangrdzzsocSbrzaWOxxn1VRRbPqKQdid6/ 9W9Oa+PU6500dWXZlC7nBb/+MH6W4tvn9jWfme+My/sPrDe2K7UInurvqt23t3tKbMDH2J0PpuffNL v8ru0XT17clYi7bk9L4ovcjjmGcvpHRnmvbU482p3g9aO2ZGfzVfVftgpWH793bHoh8H/NqbXv1ZMc +n9IxPVyHp33bP7eM4l8mT8XLxXpWHwkUC1WY+8V62kcWm0FG4T65HJCfB+mnU55tnj3YrWio/bC75 tvn3QoZYypifoirTDzv9nqpXyuAA== X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Now when we allocate blocks on write page fault there should be no block allocation happening on page writeback. So just ignore the 'create' flag passed to udf_get_block(). Note that we can spot dirty buffers without underlying blocks allocated in writeback when we race with expanding truncate. However in that case these buffers do not contain valid data so we can safely ignore them and we would just create ourselves problem when to trim the tail extent. Signed-off-by: Jan Kara --- fs/udf/inode.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 7fd0aa2439e9..8f55b37ddcad 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -68,6 +68,8 @@ static void udf_prealloc_extents(struct inode *, int, int, static void udf_merge_extents(struct inode *, struct kernel_long_ad *, int *); static int udf_update_extents(struct inode *, struct kernel_long_ad *, int, int, struct extent_position *); +static int udf_get_block_wb(struct inode *inode, sector_t block, + struct buffer_head *bh_result, int create); static void __udf_clear_extent_cache(struct inode *inode) { @@ -186,7 +188,7 @@ static void udf_write_failed(struct address_space *mapping, loff_t to) static int udf_writepages(struct address_space *mapping, struct writeback_control *wbc) { - return mpage_writepages(mapping, wbc, udf_get_block); + return mpage_writepages(mapping, wbc, udf_get_block_wb); } static int udf_read_folio(struct file *file, struct folio *folio) @@ -367,23 +369,15 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map) return err; } -static int udf_get_block(struct inode *inode, sector_t block, - struct buffer_head *bh_result, int create) +static int __udf_get_block(struct inode *inode, sector_t block, + struct buffer_head *bh_result, int flags) { int err; struct udf_map_rq map = { .lblk = block, - .iflags = create ? UDF_MAP_CREATE : 0, + .iflags = flags, }; - /* - * We preallocate blocks only for regular files. It also makes sense - * for directories but there's a problem when to drop the - * preallocation. We might use some delayed work for that but I feel - * it's overengineering for a filesystem like UDF. - */ - if (!S_ISREG(inode->i_mode)) - map.iflags |= UDF_MAP_NOPREALLOC; err = udf_map_block(inode, &map); if (err < 0) return err; @@ -395,6 +389,34 @@ static int udf_get_block(struct inode *inode, sector_t block, return 0; } +int udf_get_block(struct inode *inode, sector_t block, + struct buffer_head *bh_result, int create) +{ + int flags = create ? UDF_MAP_CREATE : 0; + + /* + * We preallocate blocks only for regular files. It also makes sense + * for directories but there's a problem when to drop the + * preallocation. We might use some delayed work for that but I feel + * it's overengineering for a filesystem like UDF. + */ + if (!S_ISREG(inode->i_mode)) + flags |= UDF_MAP_NOPREALLOC; + return __udf_get_block(inode, block, bh_result, flags); +} + +/* + * We shouldn't be allocating blocks on page writeback since we allocate them + * on page fault. We can spot dirty buffers without allocated blocks though + * when truncate expands file. These however don't have valid data so we can + * safely ignore them. So never allocate blocks from page writeback. + */ +static int udf_get_block_wb(struct inode *inode, sector_t block, + struct buffer_head *bh_result, int create) +{ + return __udf_get_block(inode, block, bh_result, 0); +} + /* Extend the file with new blocks totaling 'new_block_bytes', * return the number of extents added */ From patchwork Tue Jan 24 12:18:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113922 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63859C54EAA for ; Tue, 24 Jan 2023 12:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233726AbjAXMSs (ORCPT ); Tue, 24 Jan 2023 07:18:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233629AbjAXMSZ (ORCPT ); Tue, 24 Jan 2023 07:18:25 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B382F44BDE; Tue, 24 Jan 2023 04:18:19 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A497E1FE52; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m46DRSIGbNxtq+S0X71nQaA8qyjXNFqrFgBCpjCP/VI=; b=RL/yt1/hIrtZVUUJ7ZCLEIM/NZNwHFb/AxCm1CorTS3hnipc/PzFMwtaHTg+4b1PZkS5jX p12Z+VSaMwN62hNpNB0PP/zWPisiHeBFitMpSOXTlQyvWozyZa+5uXIrZ7Zd13kGSxI6Qo IOA0XpXH91MfKA5PsrhUhO7QT4ip4Yw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m46DRSIGbNxtq+S0X71nQaA8qyjXNFqrFgBCpjCP/VI=; b=1j1Vqnh+SNA17y+xnUbwtBdQ4Tmo+FVpGhMf3h3zxAdSAzH62HYkxBfwnVP62ON+V3qnsW Jr9DXzgl7TPEkNBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 97B9213A04; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Q9EFJYfMz2MFOAAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 7C477A0719; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara , stable@vger.kernel.org Subject: [PATCH 21/22] udf: Fix file corruption when appending just after end of preallocated extent Date: Tue, 24 Jan 2023 13:18:07 +0100 Message-Id: <20230124121814.25951-21-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2002; i=jack@suse.cz; h=from:subject; bh=lfwscmtlTLylhleSMfBN6ty0Imfx64TCTX3XBq2sWds=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x+TwOf6Aj5YpvaFbORv23yeEcN43H8u+UW/wsA yKhfUL+JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MfgAKCRCcnaoHP2RA2cI0B/ 420Pzt9o+WwwO2G8nJ6hX0wemTXDkIpwas+DLgVbWIxCzlXoDGlV8B0NZ4X6fqcSiwm+EZMWFRbbqB NW87U3Umh12YWjGCApE+IQKBzO9qlZlwcNISgvHlk9e0Sdp3UyXtXY0F00j32zOZNETJ0HUBUHsqD5 j1PB1lScJcmLtd73TfCfeJZ7S1AhAszG4NcNJj38dlgJwn6rfSvJLz/phLaM2PDGleEA8aQh39pdAB a19uQse3Lk49cwkMSUpnTgLSh2GSORitudw+bboSQBFzHXWkiaH7Fa6PDNWuaoAnjvni5M/lBkRxzU dHYOQXCXI+CHaI3svV8Dxw/W9YkQ/O X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When we append new block just after the end of preallocated extent, the code in inode_getblk() wrongly determined we're going to use the preallocated extent which resulted in adding block into a wrong logical offset in the file. Sequence like this manifests it: xfs_io -f -c "pwrite 0x2cacf 0xd122" -c "truncate 0x2dd6f" \ -c "pwrite 0x27fd9 0x69a9" -c "pwrite 0x32981 0x7244" The code that determined the use of preallocated extent is actually stale because udf_do_extend_file() does not create preallocation anymore so after calling that function we are sure there's no usable preallocation. Just remove the faulty condition. CC: stable@vger.kernel.org Fixes: 16d055656814 ("udf: Discard preallocation before extending file with a hole") Signed-off-by: Jan Kara --- fs/udf/inode.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 8f55b37ddcad..6826c2aa021f 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -742,19 +742,17 @@ static int inode_getblk(struct inode *inode, struct udf_map_rq *map) c = 0; offset = 0; count += ret; - /* We are not covered by a preallocated extent? */ - if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != - EXT_NOT_RECORDED_ALLOCATED) { - /* Is there any real extent? - otherwise we overwrite - * the fake one... */ - if (count) - c = !c; - laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | - inode->i_sb->s_blocksize; - memset(&laarr[c].extLocation, 0x00, - sizeof(struct kernel_lb_addr)); - count++; - } + /* + * Is there any real extent? - otherwise we overwrite the fake + * one... + */ + if (count) + c = !c; + laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | + inode->i_sb->s_blocksize; + memset(&laarr[c].extLocation, 0x00, + sizeof(struct kernel_lb_addr)); + count++; endnum = c + 1; lastblock = 1; } else { From patchwork Tue Jan 24 12:18:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13113919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C000C38142 for ; Tue, 24 Jan 2023 12:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233720AbjAXMSp (ORCPT ); Tue, 24 Jan 2023 07:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233506AbjAXMSX (ORCPT ); Tue, 24 Jan 2023 07:18:23 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0302B442F1; Tue, 24 Jan 2023 04:18:18 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A56A421892; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w15/0UL/apowGdJ7y6J7HeBMbOdAZPHl5hFCfmWK+HY=; b=GVuDKujZOKNY3Qiev05AL+BRhKsUtiORAwYSLdtR0WiC+Mc44vXKO7VxLZZuLz9Ofd/LNM wuY/1U5YLdD00pkTaRusEF8GKWY2Zz6JMl4HAEQIQkoAoAR3f9vKFziTL8s3tLS3FRmtEd 0gm1Tfhu3fvg2nDM1hWCN1Xv5ZXQNeo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674562695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w15/0UL/apowGdJ7y6J7HeBMbOdAZPHl5hFCfmWK+HY=; b=cox9P3pyRB81yzhq01Nix8050qQyFJ5bSJRngdG5SNAv7qaRI30gJCp3C38j26EccpLW+j vzlJGCdcB1ududDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 98FDA13A06; Tue, 24 Jan 2023 12:18:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Ld1hJYfMz2MGOAAAMHmgww (envelope-from ); Tue, 24 Jan 2023 12:18:15 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 8246AA071C; Tue, 24 Jan 2023 13:18:14 +0100 (CET) From: Jan Kara To: Cc: Jan Kara , stable@vger.kernel.org Subject: [PATCH 22/22] udf: Fix off-by-one error when discarding preallocation Date: Tue, 24 Jan 2023 13:18:08 +0100 Message-Id: <20230124121814.25951-22-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230124120835.21728-1-jack@suse.cz> References: <20230124120835.21728-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1058; i=jack@suse.cz; h=from:subject; bh=k3x+adLT4BFXbkMp/FV2130s8476xk1byYMXuARSDQc=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjz8x/5ZkOM49oEAt047qYwMzlE594teF0jR+PwK6N ZMazJN2JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY8/MfwAKCRCcnaoHP2RA2VrNB/ 47o3YgERK+G7Etg5JpZZ8InRqnY11KfgVWtb6JoONKoPqbCf+GT1vJWejcn83nRKt0P44EXUMSxChK KRCtFKvgd/krEVeXBjzCyWbzDXIsXw/3CLPCiRTBCitxH1qY1SkGpbtlgeFD9Zu/Tsw+Ddx6m2OVI9 zxc1dcrVq96+cWGz7g0XfUJHdeqUMrhUwKGAPWgLzUGZEkYlOdpHWuluL4NymwmiUyV2717edwNA5y Zj+O3FaN+T2TvtrIjKR834ee4khj8Yox3/3/5CZjSS84brfUkAtwj45+rqt2/KkqChP5HHdkZWxA+w inCIV0DNQBbCPDqAyEWhT9XjQvNKUF X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The condition determining whether the preallocation can be used had an off-by-one error so we didn't discard preallocation when new allocation was just following it. This can then confuse code in inode_getblk(). CC: stable@vger.kernel.org Fixes: 16d055656814 ("udf: Discard preallocation before extending file with a hole") Signed-off-by: Jan Kara --- fs/udf/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 6826c2aa021f..15e0d9f23c06 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -361,7 +361,7 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map) * Block beyond EOF and prealloc extents? Just discard preallocation * as it is not useful and complicates things. */ - if (((loff_t)map->lblk) << inode->i_blkbits > iinfo->i_lenExtents) + if (((loff_t)map->lblk) << inode->i_blkbits >= iinfo->i_lenExtents) udf_discard_prealloc(inode); udf_clear_extent_cache(inode); err = inode_getblk(inode, map);