From patchwork Mon Mar 11 23:59:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 13589427 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2007C54E58 for ; Mon, 11 Mar 2024 23:59:38 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rjpYO-0006An-Nj; Mon, 11 Mar 2024 23:59:37 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rjpYM-0006Ag-SS for linux-f2fs-devel@lists.sourceforge.net; Mon, 11 Mar 2024 23:59:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=bqpi+pK0eQZfpPuAwyq71F3S97nx5NBT8dYXZNYP/vo=; b=RmRGNaAsOL04ZePMLOuEb55+/O 5lswU9/IbBrEyTcisn2LIrcTahAkH0AR9P+TXWLpg2PQfJLb7Eb1Abboc/FIh5CPTHnt4MPs0LlYp u9EuYlPZvazV77Nn7g5q1GAZUIAtkbuR63sXAUz4z9L6lG6a4MjYGOn0EKoLs0AgYjdU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=bqpi+pK0eQZfpPuAwyq71F3S97nx5NBT8dYXZNYP/vo=; b=H Wko7BYz7qHRrDhoKY4ujWAPJnokXfNQz1Ge9kM5XcHYsmJMHDGF+/b4zr8SGZzOoPwIB/fDFOjrwn Jw1B2ReRBGZNAosb52gNqHLdv2w4LRe/ciDlb80eXeSPuQVbmVZCQsoSLl5T8dhMOn2boN32WQ9Cv uw0ohWDHNRcV0BL8=; Received: from mail-pl1-f174.google.com ([209.85.214.174]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1rjpYC-0006aN-TQ for linux-f2fs-devel@lists.sourceforge.net; Mon, 11 Mar 2024 23:59:35 +0000 Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1dd10a37d68so42108935ad.2 for ; Mon, 11 Mar 2024 16:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710201565; x=1710806365; darn=lists.sourceforge.net; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bqpi+pK0eQZfpPuAwyq71F3S97nx5NBT8dYXZNYP/vo=; b=bdTCoKdW8OX+Ra/b8cWb83Hf0Lh7CMSDE9OP9JArlti1bTDCB86k3mu3lucOPS0Mku ovxqsL4cuT6UsYjQf2ocTbJ9dxefcofmORe1xQSS7aNZqy/pqNKBD1z70fp745qiQbzr rndvvWUCj9rlesTA7vOAaObXqydkREJt/2JKHKhSD069KopNCWdPsbzUYe3JsFBTcjQg HJOmXfw+aO2Lj9roiozdyJNXOoWWnaD7cBXAd8KwRcyEpMyKa3Y5kB4qpLD+OPuN+0A7 f5gn5LvuXwgwiIhRYOwx1L39fo175EKwv5MfoxdDZG4kaDko43L7eET7XLzb1T5xM/lc UDNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710201565; x=1710806365; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bqpi+pK0eQZfpPuAwyq71F3S97nx5NBT8dYXZNYP/vo=; b=ivnnsCrPgqeNS09fT18LjTMvdDsM7Lw3t7oYKtKTRdn4mvMHMigk/iJ/obqT6/DsuH qOPiBc6ytPdM1HBwLrj4NsvPQW/gzQ1YUqOFr+JbDgKIMb8iUX0MGdLQLVJ2BRY5Dz9n sjxhzEAPkBidMBQetILdO8fktmXS5y+bAAyYCYt0JfyUTfHu298IYJhsV60SQcVowfZ0 6E8mT1wswZDyoMDIffuDVFr3rIAkevyB+Rb0+K+sZLMud5NX2waP3uzYgcr/UggLtN7t VEeDnwyVxfgMKBysL8w6XiartNXg4BynM9nG5FCU5l4PaZGMZypDg4ZtS3r46OkINuiP wjtQ== X-Forwarded-Encrypted: i=1; AJvYcCWBCpjUUDXSaw2lj6uBZO0MhYd5ES0N8xavz89cdoIvMqD/8MV0Ps3NBlaYlLjYK7W/FmEoiHN7GwQwwVJA8WIHlkfA0+a9a0ILFKL627Ss+bvz4VxlDQ== X-Gm-Message-State: AOJu0YzrfTB4HoFdVchN1z1HNKMI3rlcPt60JPkWbAtGdwdtty+6uzN/ iU0dBsi1c+Jvhd+Fvw8vStSAM3C2TJmAvY6GmZRq0BQdIyF9i4bV X-Google-Smtp-Source: AGHT+IHn75XVEeeY8/1CG7cnADq6V0jic+dEdxIKLujyLw/Dffes5RFhnhz2xzg1f3QKb1JYtA3MzQ== X-Received: by 2002:a17:902:e801:b0:1dd:5872:386a with SMTP id u1-20020a170902e80100b001dd5872386amr8937023plg.59.1710201565055; Mon, 11 Mar 2024 16:59:25 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:d706:f56a:f0d2:75d]) by smtp.gmail.com with ESMTPSA id n5-20020a170902d2c500b001dc8f8730f3sm3473272plc.285.2024.03.11.16.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 16:59:24 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Date: Mon, 11 Mar 2024 16:59:19 -0700 Message-ID: <20240311235921.1832684-1-daeho43@gmail.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog MIME-Version: 1.0 X-Headers-End: 1rjpYC-0006aN-TQ Subject: [f2fs-dev] [PATCH 1/2] f2fs: prevent atomic write on pinned file X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daeho Jeong Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Daeho Jeong Since atomic write way was changed to out-place-update, we should prevent it on pinned files. Signed-off-by: Daeho Jeong Reviewed-by: Chao Yu --- fs/f2fs/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 1c044fb19c87..82277e95c88f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2085,7 +2085,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) inode_lock(inode); - if (!f2fs_disable_compressed_file(inode)) { + if (!f2fs_disable_compressed_file(inode) || + f2fs_is_pinned_file(inode)) { ret = -EINVAL; goto out; } From patchwork Mon Mar 11 23:59:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 13589428 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0114C5475B for ; Mon, 11 Mar 2024 23:59:39 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rjpYQ-0006SX-Pj; Mon, 11 Mar 2024 23:59:39 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rjpYO-0006SP-KJ for linux-f2fs-devel@lists.sourceforge.net; Mon, 11 Mar 2024 23:59:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LsKPWyHq5LYsk7GmH1W3pe42SNKM0nIJT896aTATdGM=; b=l3wXQD/CnrlojXHSr6OCKsJKmV 0U7LE+TAjNtKqXp0X9CZrHAjqeT0gxbaNriy6DoBWScFv7OLdX7AQ+ST6zdVBYznl96gDFZr5FZEv ELlkLVFkrSUcyuLZAgA+kLwN4jHv1R6KQLJqWYA9Hv30QGuFe8p6CvTwX2YTxXsXt550=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LsKPWyHq5LYsk7GmH1W3pe42SNKM0nIJT896aTATdGM=; b=c9Id6Wnz4Gd7izx/hw3luHjkaN 5cfVWaXAowJd5+Spn6S3SByQaCZMo1dD0nbZ4WY7ufC729M51gpXgWA19Ktw7I1KxJFK2CcfGCGc5 oCs7wGbczhZ0NWNindogJrGAXqg1IY6xc/sD1UeNNlxkkogresMmqH1vzBoB5IztO1Vg=; Received: from mail-pl1-f179.google.com ([209.85.214.179]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1rjpYE-0006aQ-EF for linux-f2fs-devel@lists.sourceforge.net; Mon, 11 Mar 2024 23:59:36 +0000 Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1dd955753edso15317745ad.1 for ; Mon, 11 Mar 2024 16:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710201567; x=1710806367; darn=lists.sourceforge.net; 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; bh=LsKPWyHq5LYsk7GmH1W3pe42SNKM0nIJT896aTATdGM=; b=HsEfEotjy51VluyZvysr5pH+xhNLWR8cVPBVWdpl/p1vsZn0PvbaLWBJ/Q5IQ2W41l UN3fyWXbGZrG1DjkVtuyYhphm/MRe6gejizwCxgysOzFLwQYwHZHFN5NA6Rf1nFB6ZYD utj6EFe4QmsL1gmO4HGO3LM365WYvFq2mx0qB7yMXozpsgbpkvaK9/P/LGP/f+FlcuOq YDmE2NBlW6e64OXPw+uEdS4sFcmUSUopMdC4SXHoQcuhae+G0ycFMFNhXNB4y4GLCJtt G/bHKNYcmXd/6ZUaHzWazuKxf9/5YwEEJu16N422pstaBL8WUA6loLn5wm0kHtvtLkuz gKHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710201567; x=1710806367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LsKPWyHq5LYsk7GmH1W3pe42SNKM0nIJT896aTATdGM=; b=FCigupHIp5Ir3CgLQguXM04Y6OvmzVCJeFj5LsFkbWrvW66mNJPf1g10JO4tT+W5yI FGG6I/KBL3sBR97gPVNA/NOvVzBf2NXVtxAae2Yk2u0FM0zJuqsZbE2Zw6oxXi0ox2F6 8d5oTILkd11Wu3Bu7PQzkR2WGbH4NE27wSQG+w9qJ0KVJHNr0aPVqF9KdSgWqdE85tbZ u5iaibYeHlpMdZhtR0OMmhn8fgLgCkllZVSzcMV2rjhvT+X04kY2phbXNo6aN9J1D/qo a1W+6omnjsB/aItAKMKQuahPm9+UC+v+QGobhq0ANv10cRHoj+v19I/ihznr4aI3CbBJ mDrA== X-Forwarded-Encrypted: i=1; AJvYcCW6Hg6qaw4NF53wh6wvF+NuT8+HhuDTXqJAFDEs0/GfsniDKRe+lME4NSPGwFzqXW0Fdd44SIJuavrwM2sgK6cMN755iB8zEnBRmM6hQ9GaujJr1g1rjA== X-Gm-Message-State: AOJu0Yzx+mMAYEyEmaQA9cbyUuEfIGWHP/8OciMbaiqT5nl4SIMAWi9D 2n9Khrlu/I8XF9J1ZgCoAfTXt/psMZoK1DU7/HCsSWHp9qJZUv6p X-Google-Smtp-Source: AGHT+IF1ABXbK5i77LpXCYRbv/tMLOus7tMygDXhPh8Ov+wEPEEPpqo8jJgj3TyfgoigtHBBcQVnLg== X-Received: by 2002:a17:903:2b0c:b0:1dd:a608:483d with SMTP id mc12-20020a1709032b0c00b001dda608483dmr3329862plb.1.1710201566787; Mon, 11 Mar 2024 16:59:26 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:d706:f56a:f0d2:75d]) by smtp.gmail.com with ESMTPSA id n5-20020a170902d2c500b001dc8f8730f3sm3473272plc.285.2024.03.11.16.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 16:59:26 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Date: Mon, 11 Mar 2024 16:59:20 -0700 Message-ID: <20240311235921.1832684-2-daeho43@gmail.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog In-Reply-To: <20240311235921.1832684-1-daeho43@gmail.com> References: <20240311235921.1832684-1-daeho43@gmail.com> MIME-Version: 1.0 X-Headers-End: 1rjpYE-0006aQ-EF Subject: [f2fs-dev] [PATCH 2/2] f2fs: prevent writing without fallocate() for pinned files X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daeho Jeong Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Daeho Jeong In a case writing without fallocate(), we can't guarantee it's allocated in the conventional area for zoned stroage. Signed-off-by: Daeho Jeong --- fs/f2fs/data.c | 7 +++++++ fs/f2fs/file.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c21b92f18463..5e4c11a719a0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3378,6 +3378,8 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, f2fs_map_lock(sbi, flag); locked = true; } else if ((pos & PAGE_MASK) >= i_size_read(inode)) { + if (f2fs_is_pinned_file(inode)) + return -EIO; f2fs_map_lock(sbi, flag); locked = true; } @@ -3407,6 +3409,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, if (!f2fs_lookup_read_extent_cache_block(inode, index, &dn.data_blkaddr)) { + if (f2fs_is_pinned_file(inode)) { + err = -EIO; + goto out; + } + if (locked) { err = f2fs_reserve_block(&dn, index); goto out; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 82277e95c88f..f98730932fc4 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4611,6 +4611,10 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter, return ret; } + /* For pinned files, it should be fallocate()-ed in advance. */ + if (f2fs_is_pinned_file(inode)) + return 0; + /* Do not preallocate blocks that will be written partially in 4KB. */ map.m_lblk = F2FS_BLK_ALIGN(pos); map.m_len = F2FS_BYTES_TO_BLK(pos + count);