From nobody Mon Sep 28 04:54:15 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA3E368D7B for ; Wed, 26 Aug 2026 13:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787751705; cv=none; b=hiGnVvITepOW2MzUtdrWgqViCHpm+Miyii0OgvltslMqH9VXEr242sKlvmU+kJS65Z3Np6OqSUcKQSOMVVsp2V8ud86G9dtX07VLi387UmwGB1S4L0py4redeZKlzK6LVWhOJjj+zjRLvJP2XTKI1+faXzN49KX6pGJWNlQcx4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787751705; c=relaxed/simple; bh=QZd0NILJX8au3PgC2K06h3ujSUZBBV8dcasg/nYJ3r0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CI9u4/G5HjD1XgDInKGsOkiFaJYWGui1UiZJzxB5jJXRrRZMbBG6ecU/Q4LxIZLtx18fwU3RUWt7Qvs6SuN4BsApJzKnDpjkGVSjnKUBw/uge6Yl2bWwqZY7ylOG7rnRRd9mcITU1ODGIhmC5DhvA37kE+0JmF7h135yUhtByxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X/ICyiEN; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X/ICyiEN" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2d032846c95so13952755ad.1 for ; Wed, 26 Aug 2026 06:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787751697; x=1788356497; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NFQ51HJ7fyE1u0r/xRDp9ewL6yDSIMejUbH85HRUqXg=; b=X/ICyiENktPMRq7dfLgdQ+mUpTRYwhYn3s8aoVFPF/DdUwkGl9sJzFrHouEtn5rVcs MzB9BULgu/JuKbEYMQRWQGrip+denDP/Fwzn78ipgas7QQn844wOAoboBvzC6LLuCeN8 ezSWGGDs2QgUViq9r+FniKyAnpfnZSlcMK9WGgy/KpF7JVmaBKoNwXdd1XPMmu8Ep8wI 6L1uwEa2DqLxA174YO/K0etk+tNI1d9yFjlUFYySzca+cjAHDg5nQbBZiqedgatW/DP8 gxKg86SeKDbN2cXBq8WMKlM0Er3N4Z7RQgosXawEcVmabxrnUl0iXSrYHpBIQPHlRHpj awvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787751697; x=1788356497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NFQ51HJ7fyE1u0r/xRDp9ewL6yDSIMejUbH85HRUqXg=; b=BxpzJrxanYsxSMquXJ4uIPSmdM6YMT6w+Qx3yPWGGtX5QNCtZwW1G5NCh1FpY0X/k5 ARVvMsvgcy0BbaxEGYlV+lZLO6fgWYyVDsbGyQBkGM1SDJk+udnsUEPng0VtOwWofSgS Xi6xMSaIXre1ULbXgU+sdonBMq5oPf1MdjPmUfIO/5ivkeOfaY1kN3bvVZ9TpbZX6qhL zm9uDIL45akri8z8IAD+1tRHzvi5OzNFtbrWHRxoko7Dh3oHbNnHK3EANro3s5MqbTsT fPukYI6S4mhTZbdnOtp9AwAPxTp+9YOT71fVQyR8TygwU3arg0RhNd3D4+LmJc6oaiBj akfQ== X-Forwarded-Encrypted: i=1; AHgh+RrDZXHsv4QZU9QpXbsr7TMRWq5Ju2j3DZA2O7yX4uZc/cTQsJRJL0s9/8soowPpItxrWX5J4xJRV7nnJJU=@vger.kernel.org X-Gm-Message-State: AFuF++kVDJsvP0ijUQ1x3eM10LUlUTXpfQMX3lbTQ8/oNk3BqOXGC0w1 vlnmrf94uR+ekZ2+/rXGp7WwFzYjFOFAFw59EAXTW+ecGCxKTPeH3M7K99HZ5xsy X-Gm-Gg: AR+sD12PmSTVf6EMaY1VG7rhShdSJRSfpnpOUO+1q5TCCg/TxGb8jV7Oja/dS7gSZ8U yyeU8WpdH2uvFRw+0YL3sQFmdYcZx/ILjI+J3i+Cf+le3qhElA1v+KQgbjbaXYBUO8QAh/m3oKb 9z1UUAnjivYQU0cja8gio45Ijnhdu2f8Xnp6PDF1RuLNuHPhMUXID3s+WkQECouvgEHtKApDZFi xiezqBSxx97j2bW0424RCfhjqmzmiuZqe0Dil0yPH8XiPPO9DI6vK50771CbbNXz5o1OznMPpts gqYDH7IAdMhbBkl7OpOrV45H0ZMaOt/udfI5g+tlxZ3W98rhfru9DNQI19w7s2wP/LXrQhuY3qI f/ftff3Rmlj2K/YyLypwmuMfx06V4AvNJGYzHlcuwADN0WGkDhtuxnEKOkJqaecQexC5eI+rd0h gMDUVw1vMrdWn+j1VeaWQ+06vpxJSQngo5+RbROD85QJntuxu2wZwAlHdO2rB8KzEOXAKHATd72 VPH24slzZQAY709mMUX6O3l X-Received: by 2002:a17:90a:d2ce:b0:393:1d92:db5 with SMTP id 98e67ed59e1d1-3966d3dc5ecmr15674934a91.10.1787751697387; Wed, 26 Aug 2026 06:41:37 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39645d69065sm8906472a91.13.2026.08.26.06.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 06:41:36 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, qwjhust@gmail.com, daehojeong@google.com Subject: [PATCH 1/2] f2fs: persist device alias inode across remount Date: Wed, 26 Aug 2026 21:41:25 +0800 Message-ID: <20260826134126.3729507-2-qiwenjie@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260826134126.3729507-1-qiwenjie@xiaomi.com> References: <20260826134126.3729507-1-qiwenjie@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A released device alias loses its extent. Reserve then identifies the target device by matching the alias filename against the device basename, which fails when mkfs used a custom alias name. Store each alias inode number at its device index in the superblock reserved area. Record the mapping before releasing blocks and use it to identify the device during reserve. Reject conflicting mappings and keep the basename lookup for images without a recorded mapping. Leave released alias inodes without an extent so existing fsck does not account the freed device range as live blocks. Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device alia= sing") Signed-off-by: Wenjie Qi --- fs/f2fs/file.c | 96 +++++++++++++++++++++++++++++++++++------ include/linux/f2fs_fs.h | 3 +- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d440231b8cb9..7f1dc00031ba 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3725,25 +3725,44 @@ static int f2fs_ioc_get_dev_alias_file(struct file = *filp, unsigned long arg) (u32 __user *)arg); } =20 -static bool f2fs_get_dev_alias_extent(struct f2fs_sb_info *sbi, - struct dentry *dentry, - struct extent_info *ei) +static int f2fs_get_dev_alias_index(struct f2fs_sb_info *sbi, + struct inode *inode, + struct dentry *dentry) { + int devi =3D -ENOENT; int i; =20 + f2fs_down_read(&sbi->sb_lock); + for (i =3D 0; i < MAX_DEVICES; i++) { + if (le32_to_cpu(sbi->raw_super->dev_alias_ino[i]) !=3D + inode->i_ino) + continue; + if (!i || i >=3D sbi->s_ndevs) { + devi =3D -EFSCORRUPTED; + goto out; + } + if (devi >=3D 0) { + devi =3D -EFSCORRUPTED; + goto out; + } + devi =3D i; + } + if (devi >=3D 0) + goto out; + for (i =3D 1; i < sbi->s_ndevs; i++) { char *name =3D strrchr(FDEV(i).path, '/'); =20 name =3D name ? name + 1 : FDEV(i).path; if (strcmp(name, dentry->d_name.name)) continue; - - ei->blk =3D FDEV(i).start_blk; - ei->len =3D FDEV(i).total_segments << sbi->log_blocks_per_seg; - ei->fofs =3D 0; - return true; + devi =3D sbi->raw_super->dev_alias_ino[i] ? + -EFSCORRUPTED : i; + break; } - return false; +out: + f2fs_up_read(&sbi->sb_lock); + return devi; } =20 static int f2fs_ioc_reserve_dev_alias(struct file *filp) @@ -3756,7 +3775,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *fi= lp) struct f2fs_lock_context lc, glc; blkcnt_t count; unsigned int start, end; - int type, err; + int devi, type, err; =20 if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -3780,7 +3799,8 @@ static int f2fs_ioc_reserve_dev_alias(struct file *fi= lp) goto out_inode_unlock; } =20 - if (!f2fs_get_dev_alias_extent(sbi, filp->f_path.dentry, &ei)) { + devi =3D f2fs_get_dev_alias_index(sbi, inode, filp->f_path.dentry); + if (devi < 0) { f2fs_warn(sbi, "device alias file (%s, ino=3D%llu) has no matching devic= e", filp->f_path.dentry->d_name.name, (unsigned long long)inode->i_ino); @@ -3790,6 +3810,10 @@ static int f2fs_ioc_reserve_dev_alias(struct file *f= ilp) goto out_inode_unlock; } =20 + ei.blk =3D FDEV(devi).start_blk; + ei.len =3D FDEV(devi).total_segments << sbi->log_blocks_per_seg; + ei.fofs =3D 0; + spin_lock(&sbi->stat_lock); if (sbi->total_valid_block_count + ei.len > get_available_block_count(sbi, inode, true)) { @@ -3801,7 +3825,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *fi= lp) spin_unlock(&sbi->stat_lock); =20 spin_lock(&FREE_I(sbi)->segmap_lock); - FDEV(f2fs_target_device_index(sbi, ei.blk)).is_reserving =3D true; + FDEV(devi).is_reserving =3D true; spin_unlock(&FREE_I(sbi)->segmap_lock); =20 start =3D GET_SEGNO(sbi, ei.blk); @@ -3853,7 +3877,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *fi= lp) f2fs_update_inode_page(inode); =20 spin_lock(&FREE_I(sbi)->segmap_lock); - FDEV(f2fs_target_device_index(sbi, ei.blk)).is_reserving =3D false; + FDEV(devi).is_reserving =3D false; spin_unlock(&FREE_I(sbi)->segmap_lock); =20 f2fs_unlock_op(sbi, &lc); @@ -3870,7 +3894,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *fi= lp) spin_unlock(&sbi->stat_lock); =20 spin_lock(&FREE_I(sbi)->segmap_lock); - FDEV(f2fs_target_device_index(sbi, ei.blk)).is_reserving =3D false; + FDEV(devi).is_reserving =3D false; spin_unlock(&FREE_I(sbi)->segmap_lock); f2fs_up_write_trace(&sbi->gc_lock, &glc); =20 @@ -3880,6 +3904,44 @@ static int f2fs_ioc_reserve_dev_alias(struct file *f= ilp) return err; } =20 +static int f2fs_record_dev_alias_inode(struct f2fs_sb_info *sbi, + struct inode *inode, int devi) +{ + __le32 old_ino; + int err =3D 0; + int i; + + f2fs_down_write(&sbi->sb_lock); + old_ino =3D sbi->raw_super->dev_alias_ino[devi]; + if (old_ino && le32_to_cpu(old_ino) !=3D inode->i_ino) + goto conflict; + + for (i =3D 0; i < MAX_DEVICES; i++) { + if (i !=3D devi && + le32_to_cpu(sbi->raw_super->dev_alias_ino[i]) =3D=3D + inode->i_ino) + goto conflict; + } + + if (!old_ino) { + sbi->raw_super->dev_alias_ino[devi] =3D + cpu_to_le32(inode->i_ino); + err =3D f2fs_commit_super(sbi, false); + if (err) + sbi->raw_super->dev_alias_ino[devi] =3D old_ino; + } + goto out; + +conflict: + f2fs_warn(sbi, "conflicting device alias inode mapping for device %d", + devi); + set_sbi_flag(sbi, SBI_NEED_FSCK); + err =3D -EFSCORRUPTED; +out: + f2fs_up_write(&sbi->sb_lock); + return err; +} + static int f2fs_ioc_release_dev_alias(struct file *filp) { struct inode *inode =3D file_inode(filp); @@ -3888,6 +3950,7 @@ static int f2fs_ioc_release_dev_alias(struct file *fi= lp) struct extent_info ei =3D {0, }; struct cp_control cpc =3D { CP_SYNC, 0, 0, 0 }; struct f2fs_lock_context lc, glc; + int devi; int err; =20 if (!capable(CAP_SYS_ADMIN)) @@ -3920,6 +3983,11 @@ static int f2fs_ioc_release_dev_alias(struct file *f= ilp) ei =3D et->largest; read_unlock(&et->lock); =20 + devi =3D f2fs_target_device_index(sbi, ei.blk); + err =3D f2fs_record_dev_alias_inode(sbi, inode, devi); + if (err) + goto out_inode_unlock; + f2fs_down_write_trace(&sbi->gc_lock, &glc); f2fs_lock_op(sbi, &lc); =20 diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bb2b6cd5d507..2130bacdbe93 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -158,7 +158,8 @@ struct f2fs_super_block { __le16 s_encoding_flags; /* Filename charset encoding flags */ __u8 s_stop_reason[MAX_STOP_REASON]; /* stop checkpoint reason */ __u8 s_errors[MAX_F2FS_ERRORS]; /* reason of image corrupts */ - __u8 reserved[258]; /* valid reserved region */ + __le32 dev_alias_ino[MAX_DEVICES]; /* device alias inode numbers */ + __u8 reserved[226]; /* valid reserved region */ __le32 crc; /* checksum of superblock */ } __packed; =20 --=20 2.43.0 From nobody Mon Sep 28 04:54:15 2026 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99F2743BDB3 for ; Wed, 26 Aug 2026 13:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787751707; cv=none; b=nqoqga6n2K3yrjUhK4aNO/CeSXSBaxYoK8Sa23FDg2NCs1gYkaiNMmSRfP9N7u9mRSBVJDww0TmmeF2CotytFCS1gFOplA5EFb0VOL2l5yMrnidR49bPmzcLGBsoIz2KkgaqWy9q6E/FCnoRGlEJUXRN7iooXDq1gQ9YiC9lUWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787751707; c=relaxed/simple; bh=Wl5ibRlmj3ktLmW2m6ymNlb9ssCdD8WqkDnfT3Y1Xjg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=To0kv5RwjSvRGPKSkroZbyOYAOHyetBGnXdfFHnDWcMU3EWX7cTHyYVx54K/xYFedDtsjQOH2paxoRd5HKvpLBSiiwUFu2uSfiHpj6vTvX49IolPnQRg/CTltKTQxP5dud/LeR1EprUISKN5o8SHMUNIFgmOsS4TZjuYyuCVJhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jJxbBAMZ; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jJxbBAMZ" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-39682983a0fso616089a91.3 for ; Wed, 26 Aug 2026 06:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787751702; x=1788356502; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eNt0yaNbWkmDvlN5726CptDGSbQ5oBacQBTHAIzZvf4=; b=jJxbBAMZZU1EWJR98lW/Qd+xPtmzU4mcaVB97p0ccESL3wJx0LITfLvDtw71nz1W0W ZtMeVWJ3SCpq25tDElJFfJXOaUn1M+fprLzOxQpy9Ht/zl95rS8FcdLyYbVRegKHq4Tj KHVNZoDoOkP9eUci4Kh72Wa2T6oc6odPMQlLI3juG1QQBbCDQpDZvkxrCZ4cU3I71rWy CRs6YG5WwydBiMovbT7svBE/xBA5aGwXZhX4yQyyMzOuzDltg8ff5Z8mlLi9szar7p72 TVHHqOT8KX+eHjtpavYBHuOEseHK7mDqoOdkrLJck7sSgyxlmTlfuD7cOOVwSs2RnFy8 Z4+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787751702; x=1788356502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=eNt0yaNbWkmDvlN5726CptDGSbQ5oBacQBTHAIzZvf4=; b=fFEn+JPLmSWAU8ZEYtiklPUQIsAiP9KGgshBQNet+86Ho96Q5Io3PiJKJTuIr1+NQ0 ItcVsux/pAyChZtgj1hk49yoj2aLVLn3mR2qt+tnphGwK8T5CrLDHK05umhCOyoIQEUV mn+G+lpUmzcSkCvw/6VWIwBU6Q/yInCC5DQ/VZZEDConoqIYOIYfCxmpiztruD2P0xQw TfgMZtnw5dme0JVT+Scb2L+5znD38u4/RuW3g6jJtjbnQEOQu6A4rYmwYIfGngygWCga xiAQcX6DX2Y55leox4kmk5Wa4wYNS6kat2/QkrE+kTHTmMC6PA5TJx4Ha4hessDSXu+X JiuA== X-Forwarded-Encrypted: i=1; AHgh+RpLN76OtPYZCcXW/b4Ts1WxX4UrBIojZNVEMAyx/51z2YRbmhty8nKytJJZ3XDhSA/h12kbzJk1OUJgGkk=@vger.kernel.org X-Gm-Message-State: AFuF++miiuBY3jGtKe2ZUTrLM98pr9TI4pUekErNbxXZmjDppI5RyRic IND9fxKuALXI8VJOLxjASnDdJRgan2RN/lm24lnDcg8CRoDTz75IiBli X-Gm-Gg: AR+sD13LOqciSTLASbVWJSKqiSioo7QxMYUmBodzUPRVYHc8hwjf1LMbrR6YXKG6acI uy7ydHgZh1wWiCSrjd1GQrcRzjqLZ396n8E74lv+ugTeEBcaKSgzGWEU1q47QEltrhhYvY30eoU mxlwOhzGqH5XqkHj242UJ3ebUAT333EWwl5yXQDLped9+a2qZgehfsNDFUMOP2YGNib3Pjr8+iO M8Vb8a8uegtdr0NretgBbpBrLXXrOwY0gKpV5tYAVpMldKRK54dCUxKUWuTlG3HYNRSZwqsc1z0 XnFMm8bQ4ArYglXPxYDwcNSxuBs96lftH/vmNxhGBIeMtdPepcLRe/vX3Bu7K1emFx/s2PL3+yI +vzjo0LO8P2tXOOTWskVvsjMdvzzJSWLN/CjdK5O5GFvcsE/XFXhngUZ5nfLDduqezbSLE6OeeD AhgH9fO8g1s5iEMKWrgUz5GjtDAccX109GpHaK4AGoyHR9Qev7TccrQvY4XdTQFUDMrr6sxGtz5 EulvMkQmjtFVKwNsylQJVxqAQ== X-Received: by 2002:a17:90b:390e:b0:38e:7f1b:efa with SMTP id 98e67ed59e1d1-3966d5d9a71mr12882557a91.11.1787751702056; Wed, 26 Aug 2026 06:41:42 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39645d69065sm8906472a91.13.2026.08.26.06.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 06:41:41 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, qwjhust@gmail.com, daehojeong@google.com Subject: [PATCH 2/2] f2fs: keep released alias devices out of pinned allocation Date: Wed, 26 Aug 2026 21:41:26 +0800 Message-ID: <20260826134126.3729507-3-qiwenjie@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260826134126.3729507-1-qiwenjie@xiaomi.com> References: <20260826134126.3729507-1-qiwenjie@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Release makes a device alias range free, but a custom alias name prevents the basename lookup from setting has_alias again after remount. Pinned allocation can then place immovable blocks on the released device and prevent a later reserve. Set has_alias after the persistent inode mapping is committed and before release frees the range. At mount, restore it from the recorded mapping and validate the alias inode and any live reserved extent. Keep devices with suspect mappings blocked from pinned allocation. Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device alia= sing") Signed-off-by: Wenjie Qi --- fs/f2fs/file.c | 4 ++++ fs/f2fs/super.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 7f1dc00031ba..10dadde70a13 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3988,6 +3988,10 @@ static int f2fs_ioc_release_dev_alias(struct file *f= ilp) if (err) goto out_inode_unlock; =20 + spin_lock(&FREE_I(sbi)->segmap_lock); + FDEV(devi).has_alias =3D true; + spin_unlock(&FREE_I(sbi)->segmap_lock); + f2fs_down_write_trace(&sbi->gc_lock, &glc); f2fs_lock_op(sbi, &lc); =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index c1e315282ec6..3a07d91b41ce 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -5035,6 +5035,21 @@ static void f2fs_tuning_parameters(struct f2fs_sb_in= fo *sbi) sbi->readdir_ra =3D true; } =20 +static bool f2fs_valid_dev_alias_mapping(struct f2fs_sb_info *sbi, + struct inode *inode, int devi) +{ + struct extent_info ei; + + if (!IS_DEVICE_ALIASING(inode)) + return false; + if (!F2FS_HAS_BLOCKS(inode)) + return true; + if (!f2fs_lookup_read_extent_cache(inode, 0, &ei)) + return false; + return !ei.fofs && ei.blk =3D=3D FDEV(devi).start_blk && + ei.len =3D=3D FDEV(devi).total_segments << sbi->log_blocks_per_seg; +} + static void f2fs_restore_device_alias(struct f2fs_sb_info *sbi) { struct inode *root =3D d_inode(sbi->sb->s_root); @@ -5045,6 +5060,39 @@ static void f2fs_restore_device_alias(struct f2fs_sb= _info *sbi) if (!f2fs_sb_has_device_alias(sbi)) return; =20 + for (i =3D 1; i < sbi->s_ndevs; i++) { + nid_t ino =3D le32_to_cpu(sbi->raw_super->dev_alias_ino[i]); + struct inode *inode; + int j; + + if (!ino) + continue; + FDEV(i).has_alias =3D true; + + for (j =3D 0; j < MAX_DEVICES; j++) + if (j !=3D i && + le32_to_cpu(sbi->raw_super->dev_alias_ino[j]) =3D=3D ino) + break; + if (j < MAX_DEVICES) + goto invalid_mapping; + + inode =3D f2fs_iget(sbi->sb, ino); + if (IS_ERR(inode)) + goto invalid_mapping; + if (!f2fs_valid_dev_alias_mapping(sbi, inode, i)) { + iput(inode); + goto invalid_mapping; + } + iput(inode); + continue; + +invalid_mapping: + f2fs_warn(sbi, + "invalid device alias inode mapping: device=3D%d, ino=3D%u", + i, ino); + set_sbi_flag(sbi, SBI_NEED_FSCK); + } + for (i =3D 1; i < sbi->s_ndevs; i++) { char *name =3D strrchr(FDEV(i).path, '/'); struct inode *inode; --=20 2.43.0