From nobody Tue Oct 7 10:32:54 2025 Received: from mx9.didiglobal.com (mx9.didiglobal.com [111.202.70.124]) by smtp.subspace.kernel.org (Postfix) with SMTP id ACE9A2D660E; Thu, 10 Jul 2025 10:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.70.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142466; cv=none; b=NEryNUCSYvKqPXLFigCtOwN0uYAr5486ctf40aFJD/uZjx1bvZVscz7Hjf9SJdrdL8ZHdAyawuiFZEzeiuTOkEF633lt1WV2kM9cqJaHflabaNyeZueo7z3WvTXMPaC81JoQkyEgS5aru0jMAev1GV1n2rRCJ6CebAYVYF982GE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142466; c=relaxed/simple; bh=G4rwVJYLKQqnce8QoPmaSGWeYFRMyGi7Hu7kmAMCExA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version; b=TIR/3cxilY22k0vQLUs6r9DYxo3VMw4XqQlBgT3RyzBzTNoDfqAfEFF7EJzhMXzzVsCJx3trV0nxkrAQAM1iB/0/iazlAYviyAGAlSzmxL1A+lCQReWcaahgFEiZWMRnVGt9CMRGZvb/fmLyOvfDoPp0F0vtf6G2wPmWrGSVtWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com; spf=pass smtp.mailfrom=didiglobal.com; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b=Z6/jK5gL; arc=none smtp.client-ip=111.202.70.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b="Z6/jK5gL" Received: from mail.didiglobal.com (unknown [10.79.71.38]) by mx9.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id 86542181988061; Thu, 10 Jul 2025 18:14:05 +0800 (CST) Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-02.didichuxing.com (10.79.71.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:08 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:08 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e]) by BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e%7]) with mapi id 15.02.1748.010; Thu, 10 Jul 2025 18:14:08 +0800 X-MD-Sfrom: chentaotao@didiglobal.com X-MD-SrcIP: 10.79.71.38 From: =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= To: "tytso@mit.edu" , "hch@infradead.org" , "adilger.kernel@dilger.ca" , "willy@infradead.org" , "brauner@kernel.org" , "jani.nikula@linux.intel.com" , "rodrigo.vivi@intel.com" , "tursulin@ursulin.net" , "airlied@gmail.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-block@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "chentao325@qq.com" , "frank.li@vivo.com" , =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= Subject: [PATCH v5 1/5] drm/i915: Use kernel_write() in shmem object create Thread-Topic: [PATCH v5 1/5] drm/i915: Use kernel_write() in shmem object create Thread-Index: AQHb8YNfdAtlZSbKRkmOcPt/kk2Uzg== Date: Thu, 10 Jul 2025 10:14:08 +0000 Message-ID: <20250710101404.362146-2-chentaotao@didiglobal.com> In-Reply-To: <20250710101404.362146-1-chentaotao@didiglobal.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=didiglobal.com; s=2025; t=1752142447; bh=G4rwVJYLKQqnce8QoPmaSGWeYFRMyGi7Hu7kmAMCExA=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=Z6/jK5gLCbJsbl1surobq42/zdAi8K0ts+lLuOOo9L4Wve9bIiesXsPmhPAF0ZPSV 6gAGXSQuZVL0bCdS8qppbGk5s3xHO0UkTkNCWmJZqiL7CouGgjlKnXAO4j4TRwyUM1 5oqHT1f42ie3Nn9qrDTrpX1cyFOI6vhKMS6fM4BM= Content-Type: text/plain; charset="utf-8" From: Taotao Chen Replace the write_begin/write_end loop in i915_gem_object_create_shmem_from_data() with call to kernel_write(). This function initializes shmem-backed GEM objects. kernel_write() simplifies the code by removing manual folio handling. Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 33 +++++++---------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i9= 15/gem/i915_gem_shmem.c index 19a3eb82dc6a..1e8f66ac48ca 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -637,9 +637,8 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_= private *i915, { struct drm_i915_gem_object *obj; struct file *file; - const struct address_space_operations *aops; - loff_t pos; - int err; + loff_t pos =3D 0; + ssize_t err; =20 GEM_WARN_ON(IS_DGFX(i915)); obj =3D i915_gem_object_create_shmem(i915, round_up(size, PAGE_SIZE)); @@ -649,29 +648,15 @@ i915_gem_object_create_shmem_from_data(struct drm_i91= 5_private *i915, GEM_BUG_ON(obj->write_domain !=3D I915_GEM_DOMAIN_CPU); =20 file =3D obj->base.filp; - aops =3D file->f_mapping->a_ops; - pos =3D 0; - do { - unsigned int len =3D min_t(typeof(size), size, PAGE_SIZE); - struct folio *folio; - void *fsdata; - - err =3D aops->write_begin(file, file->f_mapping, pos, len, - &folio, &fsdata); - if (err < 0) - goto fail; + err =3D kernel_write(file, data, size, &pos); =20 - memcpy_to_folio(folio, offset_in_folio(folio, pos), data, len); + if (err < 0) + goto fail; =20 - err =3D aops->write_end(file, file->f_mapping, pos, len, len, - folio, fsdata); - if (err < 0) - goto fail; - - size -=3D len; - data +=3D len; - pos +=3D len; - } while (size); + if (err !=3D size) { + err =3D -EIO; + goto fail; + } =20 return obj; =20 --=20 2.34.1 From nobody Tue Oct 7 10:32:54 2025 Received: from mx10.didiglobal.com (mx10.didiglobal.com [111.202.70.125]) by smtp.subspace.kernel.org (Postfix) with SMTP id 6CCB52D6618; Thu, 10 Jul 2025 10:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.70.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142486; cv=none; b=iXFU/UWlMMX80+DAfsPfIBi7QaW6PJ3D7fO6joe09g/qkKgV264R6+9uCIgSavn4q/wcxU+KyLN1vPyC02SyjbFIF2ILuGUvH/SVFu/hylyRKEU+w/tL4vGbUy0ht9l3qADDHODYKLFbnCrS93CzMg3JeHc1hEXmd0PZFgkZClo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142486; c=relaxed/simple; bh=2xP5WfN4XUwSSHvH10cIGlaPoQTzYl8jSpkNxauZyN8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version; b=iZjyI5xezMytWwEr95MYShNhapyYUtwUCZJbc1WYnVLK6CI4gctPFoay1MwY7ATcJjttPCl2GFwuDzll0RXtgMxIoGYsyvDItDzpz5k/JfNGuL9CIQHHGGK286rci3ikK5Z8XBeQClhMAzMuQvYIpjtfCR1j1EylWWDKmNGWuF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com; spf=pass smtp.mailfrom=didiglobal.com; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b=D8RvQgp3; arc=none smtp.client-ip=111.202.70.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b="D8RvQgp3" Received: from mail.didiglobal.com (unknown [10.79.65.19]) by mx10.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id A599918387BC57; Thu, 10 Jul 2025 18:13:25 +0800 (CST) Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ02-ACTMBX-01.didichuxing.com (10.79.65.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:10 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:09 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e]) by BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e%7]) with mapi id 15.02.1748.010; Thu, 10 Jul 2025 18:14:09 +0800 X-MD-Sfrom: chentaotao@didiglobal.com X-MD-SrcIP: 10.79.65.19 From: =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= To: "tytso@mit.edu" , "hch@infradead.org" , "adilger.kernel@dilger.ca" , "willy@infradead.org" , "brauner@kernel.org" , "jani.nikula@linux.intel.com" , "rodrigo.vivi@intel.com" , "tursulin@ursulin.net" , "airlied@gmail.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-block@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "chentao325@qq.com" , "frank.li@vivo.com" , =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= Subject: [PATCH v5 2/5] drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter Thread-Topic: [PATCH v5 2/5] drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter Thread-Index: AQHb8YNgme5p4ji+SkaFjOJQbnYYZg== Date: Thu, 10 Jul 2025 10:14:09 +0000 Message-ID: <20250710101404.362146-3-chentaotao@didiglobal.com> In-Reply-To: <20250710101404.362146-1-chentaotao@didiglobal.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=didiglobal.com; s=2025; t=1752142427; bh=2xP5WfN4XUwSSHvH10cIGlaPoQTzYl8jSpkNxauZyN8=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=D8RvQgp3QXqMmkEKBiEuTUVpdBaZ9gIBCifGhYrKaKISYGRY9kVzwgxKv5TFICGWj WtbnB+c4tUgQl1kzt22pePmeIjwbHfyYh4RZoLXTySux90pmbQ59y+XG1mX/pyOtge z685i8hNwK9PJX6Kx2OGLGbDQhfJMuFTiq/5hA1M= Content-Type: text/plain; charset="utf-8" From: Taotao Chen Refactors shmem_pwrite() to replace the ->write_begin/end logic with a write_iter-based implementation using kiocb and iov_iter. While kernel_write() was considered, it caused about 50% performance regression. vfs_write() is not exported for kernel use. Therefore, file->f_op->write_iter() is called directly with a synchronously initialized kiocb to preserve performance and remove write_begin usage. Performance results use gem_pwrite on Intel CPU i7-10700 (average of 10 runs): - ./gem_pwrite --run-subtest bench -s 16384 Before: 0.205s, After: 0.214s - ./gem_pwrite --run-subtest bench -s 524288 Before: 6.1021s, After: 4.8047s Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 81 ++++++----------------- 1 file changed, 21 insertions(+), 60 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i9= 15/gem/i915_gem_shmem.c index 1e8f66ac48ca..43b42be7ca2a 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -400,12 +400,12 @@ static int shmem_pwrite(struct drm_i915_gem_object *obj, const struct drm_i915_gem_pwrite *arg) { - struct address_space *mapping =3D obj->base.filp->f_mapping; - const struct address_space_operations *aops =3D mapping->a_ops; char __user *user_data =3D u64_to_user_ptr(arg->data_ptr); - u64 remain; - loff_t pos; - unsigned int pg; + struct file *file =3D obj->base.filp; + struct kiocb kiocb; + struct iov_iter iter; + ssize_t written; + u64 size =3D arg->size; =20 /* Caller already validated user args */ GEM_BUG_ON(!access_ok(user_data, arg->size)); @@ -428,63 +428,24 @@ shmem_pwrite(struct drm_i915_gem_object *obj, if (obj->mm.madv !=3D I915_MADV_WILLNEED) return -EFAULT; =20 - /* - * Before the pages are instantiated the object is treated as being - * in the CPU domain. The pages will be clflushed as required before - * use, and we can freely write into the pages directly. If userspace - * races pwrite with any other operation; corruption will ensue - - * that is userspace's prerogative! - */ + if (size > MAX_RW_COUNT) + return -EFBIG; =20 - remain =3D arg->size; - pos =3D arg->offset; - pg =3D offset_in_page(pos); + if (!file->f_op->write_iter) + return -EINVAL; =20 - do { - unsigned int len, unwritten; - struct folio *folio; - void *data, *vaddr; - int err; - char __maybe_unused c; - - len =3D PAGE_SIZE - pg; - if (len > remain) - len =3D remain; - - /* Prefault the user page to reduce potential recursion */ - err =3D __get_user(c, user_data); - if (err) - return err; - - err =3D __get_user(c, user_data + len - 1); - if (err) - return err; - - err =3D aops->write_begin(obj->base.filp, mapping, pos, len, - &folio, &data); - if (err < 0) - return err; - - vaddr =3D kmap_local_folio(folio, offset_in_folio(folio, pos)); - pagefault_disable(); - unwritten =3D __copy_from_user_inatomic(vaddr, user_data, len); - pagefault_enable(); - kunmap_local(vaddr); - - err =3D aops->write_end(obj->base.filp, mapping, pos, len, - len - unwritten, folio, data); - if (err < 0) - return err; - - /* We don't handle -EFAULT, leave it to the caller to check */ - if (unwritten) - return -ENODEV; - - remain -=3D len; - user_data +=3D len; - pos +=3D len; - pg =3D 0; - } while (remain); + init_sync_kiocb(&kiocb, file); + kiocb.ki_pos =3D arg->offset; + iov_iter_ubuf(&iter, ITER_SOURCE, (void __user *)user_data, size); + + written =3D file->f_op->write_iter(&kiocb, &iter); + BUG_ON(written =3D=3D -EIOCBQUEUED); + + if (written !=3D size) + return -EIO; + + if (written < 0) + return written; =20 return 0; } --=20 2.34.1 From nobody Tue Oct 7 10:32:54 2025 Received: from mx10.didiglobal.com (mx10.didiglobal.com [111.202.70.125]) by smtp.subspace.kernel.org (Postfix) with SMTP id 61E2E2D6617; Thu, 10 Jul 2025 10:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.70.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142489; cv=none; b=JCIagLD41hrIlCmlgQLRwAvlxOuEkIXOwCM0MjBD78DATAuJDnpFrvfh2NmDLjtgfZPy8z3jHHU6YW/pP+L948XRwXW4cn+T9ZpQOx24zg5jRH4MciERw8tg3d/qLf7k4zyws8GNRcWXpr//OWVKLsEzn5wvMEVIXZzMk1WuOGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142489; c=relaxed/simple; bh=vp3z+U7ciqCMhLmfNSeCw/AD3StPeyMujmYvIaVJ5AY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version; b=g1Q0IHt8hAr0XvsbgxtjvkWL6wKsvahqIkqGMUoQjn5WQ8do6WFoKRFhiUqzw5Q8KGPromXugrOrEqhcD6czxJpHbdA/Z/hdsM596qDpOyusisg0HEjUopeXas6Fu0HGU1O3iITGZiLGDy/TArb4S4on9Symz/jGrn6XNvzPkLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com; spf=pass smtp.mailfrom=didiglobal.com; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b=K2Lgpg4L; arc=none smtp.client-ip=111.202.70.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b="K2Lgpg4L" Received: from mail.didiglobal.com (unknown [10.79.64.20]) by mx10.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id 8A38E18387BC48; Thu, 10 Jul 2025 18:13:27 +0800 (CST) Received: from BJ03-ACTMBX-09.didichuxing.com (10.79.71.36) by BJ01-ACTMBX-01.didichuxing.com (10.79.64.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:11 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-09.didichuxing.com (10.79.71.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:11 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e]) by BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e%7]) with mapi id 15.02.1748.010; Thu, 10 Jul 2025 18:14:11 +0800 X-MD-Sfrom: chentaotao@didiglobal.com X-MD-SrcIP: 10.79.64.20 From: =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= To: "tytso@mit.edu" , "hch@infradead.org" , "adilger.kernel@dilger.ca" , "willy@infradead.org" , "brauner@kernel.org" , "jani.nikula@linux.intel.com" , "rodrigo.vivi@intel.com" , "tursulin@ursulin.net" , "airlied@gmail.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-block@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "chentao325@qq.com" , "frank.li@vivo.com" , =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= Subject: [PATCH v5 3/5] fs: change write_begin/write_end interface to take struct kiocb * Thread-Topic: [PATCH v5 3/5] fs: change write_begin/write_end interface to take struct kiocb * Thread-Index: AQHb8YNhlY+k5v5atUabBLRtCpxDdw== Date: Thu, 10 Jul 2025 10:14:10 +0000 Message-ID: <20250710101404.362146-4-chentaotao@didiglobal.com> In-Reply-To: <20250710101404.362146-1-chentaotao@didiglobal.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=didiglobal.com; s=2025; t=1752142429; bh=vp3z+U7ciqCMhLmfNSeCw/AD3StPeyMujmYvIaVJ5AY=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=K2Lgpg4LaxscQvnPv/rEqi6m+54cF6ecSgCRl+Mj2lFnMOTzVxgui+MDikFDIKuc3 p3qba827hx16fRtdHIg/ei3+N+pxuqMni1ZuE3ELuzrJeTW7Ys60AZum6NP6FWFphO LjxAE3Bj6A7bqlgZeNXeQxm8P7ednM6CPFpyU75s= Content-Type: text/plain; charset="utf-8" From: Taotao Chen Change the address_space_operations callbacks write_begin() and write_end() to take struct kiocb * as the first argument instead of struct file *. Update all affected function prototypes, implementations, call sites, and related documentation across VFS, filesystems, and block layer. Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen --- Documentation/filesystems/locking.rst | 4 ++-- Documentation/filesystems/vfs.rst | 6 +++--- block/fops.c | 13 ++++++++----- fs/adfs/inode.c | 9 +++++---- fs/affs/file.c | 26 ++++++++++++++----------- fs/bcachefs/fs-io-buffered.c | 4 ++-- fs/bcachefs/fs-io-buffered.h | 4 ++-- fs/bfs/file.c | 7 ++++--- fs/buffer.c | 26 ++++++++++++------------- fs/ceph/addr.c | 10 +++++++--- fs/ecryptfs/mmap.c | 10 +++++----- fs/exfat/file.c | 11 +++++------ fs/exfat/inode.c | 16 ++++++++------- fs/ext2/inode.c | 11 ++++++----- fs/ext4/inode.c | 18 +++++++++-------- fs/f2fs/data.c | 8 +++++--- fs/fat/inode.c | 18 +++++++++-------- fs/fuse/file.c | 14 +++++++++----- fs/hfs/hfs_fs.h | 2 +- fs/hfs/inode.c | 4 ++-- fs/hfsplus/hfsplus_fs.h | 6 ++++-- fs/hfsplus/inode.c | 8 +++++--- fs/hostfs/hostfs_kern.c | 8 +++++--- fs/hpfs/file.c | 18 +++++++++-------- fs/hugetlbfs/inode.c | 9 +++++---- fs/jffs2/file.c | 28 +++++++++++++++------------ fs/jfs/inode.c | 16 ++++++++------- fs/libfs.c | 11 ++++++----- fs/minix/inode.c | 7 ++++--- fs/nfs/file.c | 8 ++++++-- fs/nilfs2/inode.c | 8 +++++--- fs/ntfs3/file.c | 4 ++-- fs/ntfs3/inode.c | 7 ++++--- fs/ntfs3/ntfs_fs.h | 10 ++++++---- fs/ocfs2/aops.c | 6 ++++-- fs/omfs/file.c | 7 ++++--- fs/orangefs/inode.c | 16 ++++++++------- fs/ubifs/file.c | 5 +++-- fs/udf/inode.c | 11 +++++++---- fs/ufs/inode.c | 16 ++++++++------- fs/vboxsf/file.c | 5 +++-- include/linux/buffer_head.h | 4 ++-- include/linux/fs.h | 11 ++++++----- mm/filemap.c | 4 ++-- mm/shmem.c | 12 ++++++------ 45 files changed, 265 insertions(+), 201 deletions(-) diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesyst= ems/locking.rst index 2e567e341c3b..580581281ed7 100644 --- a/Documentation/filesystems/locking.rst +++ b/Documentation/filesystems/locking.rst @@ -253,10 +253,10 @@ prototypes:: int (*writepages)(struct address_space *, struct writeback_control *); bool (*dirty_folio)(struct address_space *, struct folio *folio); void (*readahead)(struct readahead_control *); - int (*write_begin)(struct file *, struct address_space *mapping, + int (*write_begin)(const struct kiocb *, struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata); - int (*write_end)(struct file *, struct address_space *mapping, + int (*write_end)(const struct kiocb *, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata); sector_t (*bmap)(struct address_space *, sector_t); diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/= vfs.rst index dd9da7e04a99..57604b07bdc9 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -823,10 +823,10 @@ cache in your filesystem. The following members are = defined: int (*writepages)(struct address_space *, struct writeback_control *); bool (*dirty_folio)(struct address_space *, struct folio *); void (*readahead)(struct readahead_control *); - int (*write_begin)(struct file *, struct address_space *mapping, + int (*write_begin)(const struct kiocb *, struct address_space *mapping, loff_t pos, unsigned len, - struct page **pagep, void **fsdata); - int (*write_end)(struct file *, struct address_space *mapping, + struct page **pagep, void **fsdata); + int (*write_end)(const struct kiocb *, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata); sector_t (*bmap)(struct address_space *, sector_t); diff --git a/block/fops.c b/block/fops.c index 35cea0cb304d..f34e7315c83c 100644 --- a/block/fops.c +++ b/block/fops.c @@ -496,15 +496,18 @@ static void blkdev_readahead(struct readahead_control= *rac) mpage_readahead(rac, blkdev_get_block); } =20 -static int blkdev_write_begin(struct file *file, struct address_space *map= ping, - loff_t pos, unsigned len, struct folio **foliop, void **fsdata) +static int blkdev_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, + unsigned len, struct folio **foliop, + void **fsdata) { return block_write_begin(mapping, pos, len, foliop, blkdev_get_block); } =20 -static int blkdev_write_end(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, unsigned copied, struct folio *folio, - void *fsdata) +static int blkdev_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { int ret; ret =3D block_write_end(pos, len, copied, folio); diff --git a/fs/adfs/inode.c b/fs/adfs/inode.c index 21527189e430..6830f8bc8d4e 100644 --- a/fs/adfs/inode.c +++ b/fs/adfs/inode.c @@ -53,13 +53,14 @@ static void adfs_write_failed(struct address_space *map= ping, loff_t to) truncate_pagecache(inode, inode->i_size); } =20 -static int adfs_write_begin(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int adfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 - ret =3D cont_write_begin(file, mapping, pos, len, foliop, fsdata, + ret =3D cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, adfs_get_block, &ADFS_I(mapping->host)->mmu_private); if (unlikely(ret)) diff --git a/fs/affs/file.c b/fs/affs/file.c index 7a71018e3f67..219ea0353906 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c @@ -415,13 +415,14 @@ affs_direct_IO(struct kiocb *iocb, struct iov_iter *i= ter) return ret; } =20 -static int affs_write_begin(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int affs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 - ret =3D cont_write_begin(file, mapping, pos, len, foliop, fsdata, + ret =3D cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, affs_get_block, &AFFS_I(mapping->host)->mmu_private); if (unlikely(ret)) @@ -430,14 +431,15 @@ static int affs_write_begin(struct file *file, struct= address_space *mapping, return ret; } =20 -static int affs_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned int len, unsigned int copied, +static int affs_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, + unsigned int len, unsigned int copied, struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; int ret; =20 - ret =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + ret =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); =20 /* Clear Archived bit on file writes, as AmigaOS would do */ if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) { @@ -645,7 +647,8 @@ static int affs_read_folio_ofs(struct file *file, struc= t folio *folio) return err; } =20 -static int affs_write_begin_ofs(struct file *file, struct address_space *m= apping, +static int affs_write_begin_ofs(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -684,9 +687,10 @@ static int affs_write_begin_ofs(struct file *file, str= uct address_space *mapping return err; } =20 -static int affs_write_end_ofs(struct file *file, struct address_space *map= ping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int affs_write_end_ofs(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; struct super_block *sb =3D inode->i_sb; diff --git a/fs/bcachefs/fs-io-buffered.c b/fs/bcachefs/fs-io-buffered.c index 66bacdd49f78..1c54b9b5bd69 100644 --- a/fs/bcachefs/fs-io-buffered.c +++ b/fs/bcachefs/fs-io-buffered.c @@ -674,7 +674,7 @@ int bch2_writepages(struct address_space *mapping, stru= ct writeback_control *wbc =20 /* buffered writes: */ =20 -int bch2_write_begin(struct file *file, struct address_space *mapping, +int bch2_write_begin(const struct kiocb *iocb, struct address_space *mappi= ng, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -757,7 +757,7 @@ int bch2_write_begin(struct file *file, struct address_= space *mapping, return bch2_err_class(ret); } =20 -int bch2_write_end(struct file *file, struct address_space *mapping, +int bch2_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { diff --git a/fs/bcachefs/fs-io-buffered.h b/fs/bcachefs/fs-io-buffered.h index 3207ebbb4ab4..14de91c27656 100644 --- a/fs/bcachefs/fs-io-buffered.h +++ b/fs/bcachefs/fs-io-buffered.h @@ -10,9 +10,9 @@ int bch2_read_folio(struct file *, struct folio *); int bch2_writepages(struct address_space *, struct writeback_control *); void bch2_readahead(struct readahead_control *); =20 -int bch2_write_begin(struct file *, struct address_space *, loff_t pos, +int bch2_write_begin(const struct kiocb *, struct address_space *, loff_t = pos, unsigned len, struct folio **, void **); -int bch2_write_end(struct file *, struct address_space *, loff_t, +int bch2_write_end(const struct kiocb *, struct address_space *, loff_t, unsigned len, unsigned copied, struct folio *, void *); =20 ssize_t bch2_write_iter(struct kiocb *, struct iov_iter *); diff --git a/fs/bfs/file.c b/fs/bfs/file.c index fa66a09e496a..10dc0151ea55 100644 --- a/fs/bfs/file.c +++ b/fs/bfs/file.c @@ -170,9 +170,10 @@ static void bfs_write_failed(struct address_space *map= ping, loff_t to) truncate_pagecache(inode, inode->i_size); } =20 -static int bfs_write_begin(struct file *file, struct address_space *mappin= g, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int bfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 diff --git a/fs/buffer.c b/fs/buffer.c index 565fe88773c2..ead4dc85debd 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2297,9 +2297,9 @@ int block_write_end(loff_t pos, unsigned len, unsigne= d copied, } EXPORT_SYMBOL(block_write_end); =20 -int generic_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +int generic_write_end(const struct kiocb *iocb, struct address_space *mapp= ing, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; loff_t old_size =3D inode->i_size; @@ -2494,7 +2494,8 @@ int generic_cont_expand_simple(struct inode *inode, l= off_t size) } EXPORT_SYMBOL(generic_cont_expand_simple); =20 -static int cont_expand_zero(struct file *file, struct address_space *mappi= ng, +static int cont_expand_zero(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, loff_t *bytes) { struct inode *inode =3D mapping->host; @@ -2518,12 +2519,12 @@ static int cont_expand_zero(struct file *file, stru= ct address_space *mapping, } len =3D PAGE_SIZE - zerofrom; =20 - err =3D aops->write_begin(file, mapping, curpos, len, + err =3D aops->write_begin(iocb, mapping, curpos, len, &folio, &fsdata); if (err) goto out; folio_zero_range(folio, offset_in_folio(folio, curpos), len); - err =3D aops->write_end(file, mapping, curpos, len, len, + err =3D aops->write_end(iocb, mapping, curpos, len, len, folio, fsdata); if (err < 0) goto out; @@ -2551,12 +2552,12 @@ static int cont_expand_zero(struct file *file, stru= ct address_space *mapping, } len =3D offset - zerofrom; =20 - err =3D aops->write_begin(file, mapping, curpos, len, + err =3D aops->write_begin(iocb, mapping, curpos, len, &folio, &fsdata); if (err) goto out; folio_zero_range(folio, offset_in_folio(folio, curpos), len); - err =3D aops->write_end(file, mapping, curpos, len, len, + err =3D aops->write_end(iocb, mapping, curpos, len, len, folio, fsdata); if (err < 0) goto out; @@ -2571,17 +2572,16 @@ static int cont_expand_zero(struct file *file, stru= ct address_space *mapping, * For moronic filesystems that do not allow holes in file. * We may have to extend the file. */ -int cont_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata, - get_block_t *get_block, loff_t *bytes) +int cont_write_begin(const struct kiocb *iocb, struct address_space *mappi= ng, + loff_t pos, unsigned len, struct folio **foliop, + void **fsdata, get_block_t *get_block, loff_t *bytes) { struct inode *inode =3D mapping->host; unsigned int blocksize =3D i_blocksize(inode); unsigned int zerofrom; int err; =20 - err =3D cont_expand_zero(file, mapping, pos, bytes); + err =3D cont_expand_zero(iocb, mapping, pos, bytes); if (err) return err; =20 diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 60a621b00c65..02468c848cce 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1864,10 +1864,12 @@ static int ceph_netfs_check_write_begin(struct file= *file, loff_t pos, unsigned * We are only allowed to write into/dirty the page if the page is * clean, or already dirty within the same snap context. */ -static int ceph_write_begin(struct file *file, struct address_space *mappi= ng, +static int ceph_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { + struct file *file =3D iocb->ki_filp; struct inode *inode =3D file_inode(file); struct ceph_inode_info *ci =3D ceph_inode(inode); int r; @@ -1885,10 +1887,12 @@ static int ceph_write_begin(struct file *file, stru= ct address_space *mapping, * we don't do anything in here that simple_write_end doesn't do * except adjust dirty page accounting */ -static int ceph_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, +static int ceph_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, + unsigned len, unsigned copied, struct folio *folio, void *fsdata) { + struct file *file =3D iocb->ki_filp; struct inode *inode =3D file_inode(file); struct ceph_client *cl =3D ceph_inode_to_client(inode); bool check_cap =3D false; diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 60f0ac8744b5..2c2b12fedeae 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -228,7 +228,7 @@ static int fill_zeros_to_end_of_page(struct folio *foli= o, unsigned int to) =20 /** * ecryptfs_write_begin - * @file: The eCryptfs file + * @iocb: I/O control block for the eCryptfs file * @mapping: The eCryptfs object * @pos: The file offset at which to start writing * @len: Length of the write @@ -239,7 +239,7 @@ static int fill_zeros_to_end_of_page(struct folio *foli= o, unsigned int to) * * Returns zero on success; non-zero otherwise */ -static int ecryptfs_write_begin(struct file *file, +static int ecryptfs_write_begin(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) @@ -322,7 +322,7 @@ static int ecryptfs_write_begin(struct file *file, * Note, this will increase i_size. */ if (index !=3D 0) { if (prev_page_end_size > i_size_read(mapping->host)) { - rc =3D ecryptfs_truncate(file->f_path.dentry, + rc =3D ecryptfs_truncate(iocb->ki_filp->f_path.dentry, prev_page_end_size); if (rc) { printk(KERN_ERR "%s: Error on attempt to " @@ -429,7 +429,7 @@ int ecryptfs_write_inode_size_to_metadata(struct inode = *ecryptfs_inode) =20 /** * ecryptfs_write_end - * @file: The eCryptfs file object + * @iocb: I/O control block for the eCryptfs file * @mapping: The eCryptfs object * @pos: The file position * @len: The length of the data (unused) @@ -437,7 +437,7 @@ int ecryptfs_write_inode_size_to_metadata(struct inode = *ecryptfs_inode) * @folio: The eCryptfs folio * @fsdata: The fsdata (unused) */ -static int ecryptfs_write_end(struct file *file, +static int ecryptfs_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 841a5b18e3df..70f53edd0a10 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -532,11 +532,10 @@ int exfat_file_fsync(struct file *filp, loff_t start,= loff_t end, int datasync) return blkdev_issue_flush(inode->i_sb->s_bdev); } =20 -static int exfat_extend_valid_size(struct file *file, loff_t new_valid_siz= e) +static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_s= ize) { int err; loff_t pos; - struct inode *inode =3D file_inode(file); struct exfat_inode_info *ei =3D EXFAT_I(inode); struct address_space *mapping =3D inode->i_mapping; const struct address_space_operations *ops =3D mapping->a_ops; @@ -551,14 +550,14 @@ static int exfat_extend_valid_size(struct file *file,= loff_t new_valid_size) if (pos + len > new_valid_size) len =3D new_valid_size - pos; =20 - err =3D ops->write_begin(file, mapping, pos, len, &folio, NULL); + err =3D ops->write_begin(NULL, mapping, pos, len, &folio, NULL); if (err) goto out; =20 off =3D offset_in_folio(folio, pos); folio_zero_new_buffers(folio, off, off + len); =20 - err =3D ops->write_end(file, mapping, pos, len, len, folio, NULL); + err =3D ops->write_end(NULL, mapping, pos, len, len, folio, NULL); if (err < 0) goto out; pos +=3D len; @@ -604,7 +603,7 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb= , struct iov_iter *iter) } =20 if (pos > valid_size) { - ret =3D exfat_extend_valid_size(file, pos); + ret =3D exfat_extend_valid_size(inode, pos); if (ret < 0 && ret !=3D -ENOSPC) { exfat_err(inode->i_sb, "write: fail to zero from %llu to %llu(%zd)", @@ -665,7 +664,7 @@ static vm_fault_t exfat_page_mkwrite(struct vm_fault *v= mf) start + vma->vm_end - vma->vm_start); =20 if (ei->valid_size < end) { - err =3D exfat_extend_valid_size(file, end); + err =3D exfat_extend_valid_size(inode, end); if (err < 0) { inode_unlock(inode); return vmf_fs_error(err); diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index b22c02d6000f..c10844e1e16c 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -446,9 +446,10 @@ static void exfat_write_failed(struct address_space *m= apping, loff_t to) } } =20 -static int exfat_write_begin(struct file *file, struct address_space *mapp= ing, - loff_t pos, unsigned int len, - struct folio **foliop, void **fsdata) +static int exfat_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned int len, + struct folio **foliop, void **fsdata) { int ret; =20 @@ -463,15 +464,16 @@ static int exfat_write_begin(struct file *file, struc= t address_space *mapping, return ret; } =20 -static int exfat_write_end(struct file *file, struct address_space *mappin= g, - loff_t pos, unsigned int len, unsigned int copied, - struct folio *folio, void *fsdata) +static int exfat_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned int len, unsigned int copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; struct exfat_inode_info *ei =3D EXFAT_I(inode); int err; =20 - err =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + err =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); if (err < len) exfat_write_failed(mapping, pos+len); =20 diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 30f8201c155f..d35ca26eee3c 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -915,7 +915,7 @@ static void ext2_readahead(struct readahead_control *ra= c) } =20 static int -ext2_write_begin(struct file *file, struct address_space *mapping, +ext2_write_begin(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { int ret; @@ -926,13 +926,14 @@ ext2_write_begin(struct file *file, struct address_sp= ace *mapping, return ret; } =20 -static int ext2_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int ext2_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { int ret; =20 - ret =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + ret =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); if (ret < len) ext2_write_failed(mapping, pos + len); return ret; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e6aa7ca6d842..9a16efd072bb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1252,7 +1252,8 @@ int ext4_block_write_begin(handle_t *handle, struct f= olio *folio, * and the ext4_write_end(). So doing the jbd2_journal_start at the start= of * ext4_write_begin() is the right place. */ -static int ext4_write_begin(struct file *file, struct address_space *mappi= ng, +static int ext4_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -1400,12 +1401,12 @@ static int write_end_fn(handle_t *handle, struct in= ode *inode, =20 /* * We need to pick up the new inode size which generic_commit_write gave us - * `file' can be NULL - eg, when called from page_symlink(). + * `iocb` can be NULL - eg, when called from page_symlink(). * * ext4 never places buffers on inode->i_mapping->i_private_list. metadata * buffers are managed internally. */ -static int ext4_write_end(struct file *file, +static int ext4_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) @@ -1510,7 +1511,7 @@ static void ext4_journalled_zero_new_buffers(handle_t= *handle, } while (bh !=3D head); } =20 -static int ext4_journalled_write_end(struct file *file, +static int ext4_journalled_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) @@ -3036,7 +3037,8 @@ static int ext4_nonda_switch(struct super_block *sb) return 0; } =20 -static int ext4_da_write_begin(struct file *file, struct address_space *ma= pping, +static int ext4_da_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -3054,7 +3056,7 @@ static int ext4_da_write_begin(struct file *file, str= uct address_space *mapping, =20 if (ext4_nonda_switch(inode->i_sb) || ext4_verity_in_progress(inode)) { *fsdata =3D (void *)FALL_BACK_TO_NONDELALLOC; - return ext4_write_begin(file, mapping, pos, + return ext4_write_begin(iocb, mapping, pos, len, foliop, fsdata); } *fsdata =3D (void *)0; @@ -3195,7 +3197,7 @@ static int ext4_da_do_write_end(struct address_space = *mapping, return copied; } =20 -static int ext4_da_write_end(struct file *file, +static int ext4_da_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) @@ -3204,7 +3206,7 @@ static int ext4_da_write_end(struct file *file, int write_mode =3D (int)(unsigned long)fsdata; =20 if (write_mode =3D=3D FALL_BACK_TO_NONDELALLOC) - return ext4_write_end(file, mapping, pos, + return ext4_write_end(iocb, mapping, pos, len, copied, folio, fsdata); =20 trace_ext4_da_write_end(inode, pos, len, copied); diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 31e892842625..711ad80b38d0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3519,8 +3519,10 @@ static int prepare_atomic_write_begin(struct f2fs_sb= _info *sbi, return 0; } =20 -static int f2fs_write_begin(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, struct folio **foliop, void **fsdata) +static int f2fs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, struct folio **foliop, + void **fsdata) { struct inode *inode =3D mapping->host; struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); @@ -3656,7 +3658,7 @@ static int f2fs_write_begin(struct file *file, struct= address_space *mapping, return err; } =20 -static int f2fs_write_end(struct file *file, +static int f2fs_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 3852bb66358c..9648ed097816 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -219,13 +219,14 @@ static void fat_write_failed(struct address_space *ma= pping, loff_t to) } } =20 -static int fat_write_begin(struct file *file, struct address_space *mappin= g, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int fat_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int err; =20 - err =3D cont_write_begin(file, mapping, pos, len, + err =3D cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, fat_get_block, &MSDOS_I(mapping->host)->mmu_private); if (err < 0) @@ -233,13 +234,14 @@ static int fat_write_begin(struct file *file, struct = address_space *mapping, return err; } =20 -static int fat_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int fat_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; int err; - err =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + err =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); if (err < len) fat_write_failed(mapping, pos + len); if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) { diff --git a/fs/fuse/file.c b/fs/fuse/file.c index f102afc03359..21c6f8654bfe 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2213,10 +2213,13 @@ static int fuse_writepages(struct address_space *ma= pping, * It's worthy to make sure that space is reserved on disk for the write, * but how to implement it without killing performance need more thinking. */ -static int fuse_write_begin(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, struct folio **foliop, void **fsdata) +static int fuse_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, struct folio **foliop, + void **fsdata) { pgoff_t index =3D pos >> PAGE_SHIFT; + struct file *file =3D iocb->ki_filp; struct fuse_conn *fc =3D get_fuse_conn(file_inode(file)); struct folio *folio; loff_t fsize; @@ -2256,9 +2259,10 @@ static int fuse_write_begin(struct file *file, struc= t address_space *mapping, return err; } =20 -static int fuse_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int fuse_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D folio->mapping->host; =20 diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h index a0c7cb0f79fc..c3fd3172fdd6 100644 --- a/fs/hfs/hfs_fs.h +++ b/fs/hfs/hfs_fs.h @@ -201,7 +201,7 @@ extern int hfs_get_block(struct inode *, sector_t, stru= ct buffer_head *, int); extern const struct address_space_operations hfs_aops; extern const struct address_space_operations hfs_btree_aops; =20 -int hfs_write_begin(struct file *file, struct address_space *mapping, +int hfs_write_begin(const struct kiocb *iocb, struct address_space *mappin= g, loff_t pos, unsigned len, struct folio **foliop, void **fsdata); extern struct inode *hfs_new_inode(struct inode *, const struct qstr *, um= ode_t); extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be= 32 *, __be32 *); diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index a81ce7a740b9..096f338134f9 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -44,12 +44,12 @@ static void hfs_write_failed(struct address_space *mapp= ing, loff_t to) } } =20 -int hfs_write_begin(struct file *file, struct address_space *mapping, +int hfs_write_begin(const struct kiocb *iocb, struct address_space *mappin= g, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { int ret; =20 - ret =3D cont_write_begin(file, mapping, pos, len, foliop, fsdata, + ret =3D cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, hfs_get_block, &HFS_I(mapping->host)->phys_size); if (unlikely(ret)) diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h index 2f089bff0095..3d5c65aef3b2 100644 --- a/fs/hfsplus/hfsplus_fs.h +++ b/fs/hfsplus/hfsplus_fs.h @@ -473,8 +473,10 @@ extern const struct address_space_operations hfsplus_a= ops; extern const struct address_space_operations hfsplus_btree_aops; extern const struct dentry_operations hfsplus_dentry_operations; =20 -int hfsplus_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, struct folio **foliop, void **fsdata); +int hfsplus_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, struct folio **foliop, + void **fsdata); struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir, umode_t mode); void hfsplus_delete_inode(struct inode *inode); diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index f331e9574217..97d75bb2c388 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -38,12 +38,14 @@ static void hfsplus_write_failed(struct address_space *= mapping, loff_t to) } } =20 -int hfsplus_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, struct folio **foliop, void **fsdata) +int hfsplus_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, + unsigned len, struct folio **foliop, + void **fsdata) { int ret; =20 - ret =3D cont_write_begin(file, mapping, pos, len, foliop, fsdata, + ret =3D cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, hfsplus_get_block, &HFSPLUS_I(mapping->host)->phys_size); if (unlikely(ret)) diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index 702c41317589..6c2cf0cdf3d6 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c @@ -445,7 +445,8 @@ static int hostfs_read_folio(struct file *file, struct = folio *folio) return ret; } =20 -static int hostfs_write_begin(struct file *file, struct address_space *map= ping, +static int hostfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -458,7 +459,8 @@ static int hostfs_write_begin(struct file *file, struct= address_space *mapping, return 0; } =20 -static int hostfs_write_end(struct file *file, struct address_space *mappi= ng, +static int hostfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { @@ -468,7 +470,7 @@ static int hostfs_write_end(struct file *file, struct a= ddress_space *mapping, int err; =20 buffer =3D kmap_local_folio(folio, from); - err =3D write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer, copied); + err =3D write_file(FILE_HOSTFS_I(iocb->ki_filp)->fd, &pos, buffer, copied= ); kunmap_local(buffer); =20 if (!folio_test_uptodate(folio) && err =3D=3D folio_size(folio)) diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 449a3fc1b8d9..7b95a3d2e2a6 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c @@ -188,13 +188,14 @@ static void hpfs_write_failed(struct address_space *m= apping, loff_t to) hpfs_unlock(inode->i_sb); } =20 -static int hpfs_write_begin(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int hpfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 - ret =3D cont_write_begin(file, mapping, pos, len, foliop, fsdata, + ret =3D cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, hpfs_get_block, &hpfs_i(mapping->host)->mmu_private); if (unlikely(ret)) @@ -203,13 +204,14 @@ static int hpfs_write_begin(struct file *file, struct= address_space *mapping, return ret; } =20 -static int hpfs_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int hpfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; int err; - err =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + err =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); if (err < len) hpfs_write_failed(mapping, pos + len); if (!(err < 0)) { diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index e4de5425838d..541aae502d4d 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -311,7 +311,7 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, = struct iov_iter *to) return retval; } =20 -static int hugetlbfs_write_begin(struct file *file, +static int hugetlbfs_write_begin(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) @@ -319,9 +319,10 @@ static int hugetlbfs_write_begin(struct file *file, return -EINVAL; } =20 -static int hugetlbfs_write_end(struct file *file, struct address_space *ma= pping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int hugetlbfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { BUG(); return -EINVAL; diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index 13c18ccc13b0..adec3af9bf8d 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c @@ -21,12 +21,14 @@ #include #include "nodelist.h" =20 -static int jffs2_write_end(struct file *filp, struct address_space *mappin= g, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata); -static int jffs2_write_begin(struct file *filp, struct address_space *mapp= ing, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata); +static int jffs2_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata); +static int jffs2_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata); static int jffs2_read_folio(struct file *filp, struct folio *folio); =20 int jffs2_fsync(struct file *filp, loff_t start, loff_t end, int datasync) @@ -121,9 +123,10 @@ static int jffs2_read_folio(struct file *file, struct = folio *folio) return ret; } =20 -static int jffs2_write_begin(struct file *filp, struct address_space *mapp= ing, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int jffs2_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { struct folio *folio; struct inode *inode =3D mapping->host; @@ -235,9 +238,10 @@ static int jffs2_write_begin(struct file *filp, struct= address_space *mapping, return ret; } =20 -static int jffs2_write_end(struct file *filp, struct address_space *mappin= g, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int jffs2_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { /* Actually commit the write from the page cache page we're looking at. * For now, we write the full page out each time. It sucks, but it's simp= le diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c index 60fc92dee24d..083e7fa54709 100644 --- a/fs/jfs/inode.c +++ b/fs/jfs/inode.c @@ -290,9 +290,10 @@ static void jfs_write_failed(struct address_space *map= ping, loff_t to) } } =20 -static int jfs_write_begin(struct file *file, struct address_space *mappin= g, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int jfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 @@ -303,13 +304,14 @@ static int jfs_write_begin(struct file *file, struct = address_space *mapping, return ret; } =20 -static int jfs_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, struct folio *folio, - void *fsdata) +static int jfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { int ret; =20 - ret =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + ret =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); if (ret < len) jfs_write_failed(mapping, pos + len); return ret; diff --git a/fs/libfs.c b/fs/libfs.c index f99ecc300647..52196566ccbc 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -910,7 +910,7 @@ static int simple_read_folio(struct file *file, struct = folio *folio) return 0; } =20 -int simple_write_begin(struct file *file, struct address_space *mapping, +int simple_write_begin(const struct kiocb *iocb, struct address_space *map= ping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -935,7 +935,7 @@ EXPORT_SYMBOL(simple_write_begin); =20 /** * simple_write_end - .write_end helper for non-block-device FSes - * @file: See .write_end of address_space_operations + * @iocb: kernel I/O control block * @mapping: " * @pos: " * @len: " @@ -956,9 +956,10 @@ EXPORT_SYMBOL(simple_write_begin); * * Use *ONLY* with simple_read_folio() */ -static int simple_write_end(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int simple_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D folio->mapping->host; loff_t last_pos =3D pos + copied; diff --git a/fs/minix/inode.c b/fs/minix/inode.c index f007e389d5d2..df9d11479caf 100644 --- a/fs/minix/inode.c +++ b/fs/minix/inode.c @@ -442,9 +442,10 @@ static void minix_write_failed(struct address_space *m= apping, loff_t to) } } =20 -static int minix_write_begin(struct file *file, struct address_space *mapp= ing, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int minix_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 033feeab8c34..2bd557ca1af9 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -342,12 +342,14 @@ static bool nfs_want_read_modify_write(struct file *f= ile, struct folio *folio, * If the writer ends up delaying the write, the writer needs to * increment the page use counts until he is done with the page. */ -static int nfs_write_begin(struct file *file, struct address_space *mappin= g, +static int nfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { fgf_t fgp =3D FGP_WRITEBEGIN; struct folio *folio; + struct file *file =3D iocb->ki_filp; int once_thru =3D 0; int ret; =20 @@ -377,10 +379,12 @@ static int nfs_write_begin(struct file *file, struct = address_space *mapping, return ret; } =20 -static int nfs_write_end(struct file *file, struct address_space *mapping, +static int nfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { + struct file *file =3D iocb->ki_filp; struct nfs_open_context *ctx =3D nfs_file_open_context(file); unsigned offset =3D offset_in_folio(folio, pos); int status; diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 6613b8fcceb0..c2ccafdf4a19 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -218,7 +218,8 @@ void nilfs_write_failed(struct address_space *mapping, = loff_t to) } } =20 -static int nilfs_write_begin(struct file *file, struct address_space *mapp= ing, +static int nilfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) =20 @@ -237,7 +238,8 @@ static int nilfs_write_begin(struct file *file, struct = address_space *mapping, return err; } =20 -static int nilfs_write_end(struct file *file, struct address_space *mappin= g, +static int nilfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { @@ -248,7 +250,7 @@ static int nilfs_write_end(struct file *file, struct ad= dress_space *mapping, =20 nr_dirty =3D nilfs_page_count_clean_buffers(folio, start, start + copied); - copied =3D generic_write_end(file, mapping, pos, len, copied, folio, + copied =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); nilfs_set_file_dirty(inode, nr_dirty); err =3D nilfs_transaction_commit(inode->i_sb); diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 1e99a35691cd..1590c2a3c48f 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -154,13 +154,13 @@ static int ntfs_extend_initialized_size(struct file *= file, if (pos + len > new_valid) len =3D new_valid - pos; =20 - err =3D ntfs_write_begin(file, mapping, pos, len, &folio, NULL); + err =3D ntfs_write_begin(NULL, mapping, pos, len, &folio, NULL); if (err) goto out; =20 folio_zero_range(folio, zerofrom, folio_size(folio) - zerofrom); =20 - err =3D ntfs_write_end(file, mapping, pos, len, len, folio, NULL); + err =3D ntfs_write_end(NULL, mapping, pos, len, len, folio, NULL); if (err < 0) goto out; pos +=3D len; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 0f0d27d4644a..dad088e64b3c 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -912,7 +912,7 @@ static int ntfs_get_block_write_begin(struct inode *ino= de, sector_t vbn, bh_result, create, GET_BLOCK_WRITE_BEGIN); } =20 -int ntfs_write_begin(struct file *file, struct address_space *mapping, +int ntfs_write_begin(const struct kiocb *iocb, struct address_space *mappi= ng, loff_t pos, u32 len, struct folio **foliop, void **fsdata) { int err; @@ -957,7 +957,8 @@ int ntfs_write_begin(struct file *file, struct address_= space *mapping, /* * ntfs_write_end - Address_space_operations::write_end. */ -int ntfs_write_end(struct file *file, struct address_space *mapping, loff_= t pos, +int ntfs_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, u32 len, u32 copied, struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; @@ -989,7 +990,7 @@ int ntfs_write_end(struct file *file, struct address_sp= ace *mapping, loff_t pos, folio_unlock(folio); folio_put(folio); } else { - err =3D generic_write_end(file, mapping, pos, len, copied, folio, + err =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); } =20 diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 36b8052660d5..921257773eec 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -702,10 +702,12 @@ struct inode *ntfs_iget5(struct super_block *sb, cons= t struct MFT_REF *ref, int ntfs_set_size(struct inode *inode, u64 new_size); int ntfs_get_block(struct inode *inode, sector_t vbn, struct buffer_head *bh_result, int create); -int ntfs_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, u32 len, struct folio **foliop, void **fsdata); -int ntfs_write_end(struct file *file, struct address_space *mapping, loff_= t pos, - u32 len, u32 copied, struct folio *folio, void *fsdata); +int ntfs_write_begin(const struct kiocb *iocb, struct address_space *mappi= ng, + loff_t pos, u32 len, struct folio **foliop, + void **fsdata); +int ntfs_write_end(const struct kiocb *iocb, struct address_space *mapping, + loff_t pos, u32 len, u32 copied, struct folio *folio, + void *fsdata); int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc); int ntfs_sync_inode(struct inode *inode); int inode_read_data(struct inode *inode, void *data, size_t bytes); diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 40b6bce12951..2203438738f6 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -1856,7 +1856,8 @@ int ocfs2_write_begin_nolock(struct address_space *ma= pping, return ret; } =20 -static int ocfs2_write_begin(struct file *file, struct address_space *mapp= ing, +static int ocfs2_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -2047,7 +2048,8 @@ int ocfs2_write_end_nolock(struct address_space *mapp= ing, loff_t pos, return copied; } =20 -static int ocfs2_write_end(struct file *file, struct address_space *mappin= g, +static int ocfs2_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { diff --git a/fs/omfs/file.c b/fs/omfs/file.c index 98358d405b6a..8d70f816b0c9 100644 --- a/fs/omfs/file.c +++ b/fs/omfs/file.c @@ -310,9 +310,10 @@ static void omfs_write_failed(struct address_space *ma= pping, loff_t to) } } =20 -static int omfs_write_begin(struct file *file, struct address_space *mappi= ng, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int omfs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c index 08a6f372a352..a7ab63776735 100644 --- a/fs/orangefs/inode.c +++ b/fs/orangefs/inode.c @@ -285,9 +285,10 @@ static int orangefs_read_folio(struct file *file, stru= ct folio *folio) return ret; } =20 -static int orangefs_write_begin(struct file *file, - struct address_space *mapping, loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int orangefs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, + unsigned len, struct folio **foliop, + void **fsdata) { struct orangefs_write_range *wr; struct folio *folio; @@ -340,9 +341,10 @@ static int orangefs_write_begin(struct file *file, return 0; } =20 -static int orangefs_write_end(struct file *file, struct address_space *map= ping, - loff_t pos, unsigned len, unsigned copied, struct folio *folio, - void *fsdata) +static int orangefs_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D folio->mapping->host; loff_t last_pos =3D pos + copied; @@ -372,7 +374,7 @@ static int orangefs_write_end(struct file *file, struct= address_space *mapping, folio_unlock(folio); folio_put(folio); =20 - mark_inode_dirty_sync(file_inode(file)); + mark_inode_dirty_sync(file_inode(iocb->ki_filp)); return copied; } =20 diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index bf311c38d9a8..89e95d8be66c 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -404,7 +404,8 @@ static int allocate_budget(struct ubifs_info *c, struct= folio *folio, * there is a plenty of flash space and the budget will be acquired quickl= y, * without forcing write-back. The slow path does not make this assumption. */ -static int ubifs_write_begin(struct file *file, struct address_space *mapp= ing, +static int ubifs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { @@ -514,7 +515,7 @@ static void cancel_budget(struct ubifs_info *c, struct = folio *folio, } } =20 -static int ubifs_write_end(struct file *file, struct address_space *mappin= g, +static int ubifs_write_end(struct kiocb *iocb, struct address_space *mappi= ng, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 4386dd845e40..356b75676fa9 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -244,10 +244,12 @@ static void udf_readahead(struct readahead_control *r= ac) mpage_readahead(rac, udf_get_block); } =20 -static int udf_write_begin(struct file *file, struct address_space *mappin= g, +static int udf_write_begin(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata) { + struct file *file =3D iocb->ki_filp; struct udf_inode_info *iinfo =3D UDF_I(file_inode(file)); struct folio *folio; int ret; @@ -271,15 +273,16 @@ static int udf_write_begin(struct file *file, struct = address_space *mapping, return 0; } =20 -static int udf_write_end(struct file *file, struct address_space *mapping, +static int udf_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata) { - struct inode *inode =3D file_inode(file); + struct inode *inode =3D file_inode(iocb->ki_filp); loff_t last_pos; =20 if (UDF_I(inode)->i_alloc_type !=3D ICBTAG_FLAG_AD_IN_ICB) - return generic_write_end(file, mapping, pos, len, copied, folio, + return generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); last_pos =3D pos + copied; if (last_pos > inode->i_size) diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c index 7dc38fdef2ea..8361c00e8fa6 100644 --- a/fs/ufs/inode.c +++ b/fs/ufs/inode.c @@ -474,9 +474,10 @@ static void ufs_write_failed(struct address_space *map= ping, loff_t to) } } =20 -static int ufs_write_begin(struct file *file, struct address_space *mappin= g, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +static int ufs_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { int ret; =20 @@ -487,13 +488,14 @@ static int ufs_write_begin(struct file *file, struct = address_space *mapping, return ret; } =20 -static int ufs_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +static int ufs_write_end(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { int ret; =20 - ret =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); + ret =3D generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata); if (ret < len) ufs_write_failed(mapping, pos + len); return ret; diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c index b492794f8e9a..af01e3beaa42 100644 --- a/fs/vboxsf/file.c +++ b/fs/vboxsf/file.c @@ -300,12 +300,13 @@ static int vboxsf_writepages(struct address_space *ma= pping, return error; } =20 -static int vboxsf_write_end(struct file *file, struct address_space *mappi= ng, +static int vboxsf_write_end(const struct kiocb *iocb, + struct address_space *mapping, loff_t pos, unsigned int len, unsigned int copied, struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; - struct vboxsf_handle *sf_handle =3D file->private_data; + struct vboxsf_handle *sf_handle =3D iocb->ki_filp->private_data; size_t from =3D offset_in_folio(folio, pos); u32 nwritten =3D len; u8 *buf; diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 178eb90e9cf3..b16b88bfbc3e 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -263,11 +263,11 @@ int block_write_begin(struct address_space *mapping, = loff_t pos, unsigned len, int __block_write_begin(struct folio *folio, loff_t pos, unsigned len, get_block_t *get_block); int block_write_end(loff_t pos, unsigned len, unsigned copied, struct foli= o *); -int generic_write_end(struct file *, struct address_space *, +int generic_write_end(const struct kiocb *, struct address_space *, loff_t, unsigned len, unsigned copied, struct folio *, void *); void folio_zero_new_buffers(struct folio *folio, size_t from, size_t to); -int cont_write_begin(struct file *, struct address_space *, loff_t, +int cont_write_begin(const struct kiocb *, struct address_space *, loff_t, unsigned, struct folio **, void **, get_block_t *, loff_t *); int generic_cont_expand_simple(struct inode *inode, loff_t size); diff --git a/include/linux/fs.h b/include/linux/fs.h index 09e3e80b0528..df8c503100c4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -444,10 +444,10 @@ struct address_space_operations { =20 void (*readahead)(struct readahead_control *); =20 - int (*write_begin)(struct file *, struct address_space *mapping, + int (*write_begin)(const struct kiocb *, struct address_space *mapping, loff_t pos, unsigned len, struct folio **foliop, void **fsdata); - int (*write_end)(struct file *, struct address_space *mapping, + int (*write_end)(const struct kiocb *, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct folio *folio, void *fsdata); =20 @@ -3598,9 +3598,10 @@ extern void simple_recursive_removal(struct dentry *, extern int noop_fsync(struct file *, loff_t, loff_t, int); extern ssize_t noop_direct_IO(struct kiocb *iocb, struct iov_iter *iter); extern int simple_empty(struct dentry *); -extern int simple_write_begin(struct file *file, struct address_space *map= ping, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata); +extern int simple_write_begin(const struct kiocb *iocb, + struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata); extern const struct address_space_operations ram_aops; extern int always_delete_dentry(const struct dentry *); extern struct inode *alloc_anon_inode(struct super_block *); diff --git a/mm/filemap.c b/mm/filemap.c index bada249b9fb7..ba089d75fc86 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4109,7 +4109,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, str= uct iov_iter *i) break; } =20 - status =3D a_ops->write_begin(file, mapping, pos, bytes, + status =3D a_ops->write_begin(iocb, mapping, pos, bytes, &folio, &fsdata); if (unlikely(status < 0)) break; @@ -4130,7 +4130,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, str= uct iov_iter *i) copied =3D copy_folio_from_iter_atomic(folio, offset, bytes, i); flush_dcache_folio(folio); =20 - status =3D a_ops->write_end(file, mapping, pos, bytes, copied, + status =3D a_ops->write_end(iocb, mapping, pos, bytes, copied, folio, fsdata); if (unlikely(status !=3D copied)) { iov_iter_revert(i, copied - max(status, 0L)); diff --git a/mm/shmem.c b/mm/shmem.c index 0c5fb4ffa03a..2229425e1b29 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3266,9 +3266,9 @@ static const struct inode_operations shmem_symlink_in= ode_operations; static const struct inode_operations shmem_short_symlink_operations; =20 static int -shmem_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, - struct folio **foliop, void **fsdata) +shmem_write_begin(const struct kiocb *iocb, struct address_space *mapping, + loff_t pos, unsigned len, + struct folio **foliop, void **fsdata) { struct inode *inode =3D mapping->host; struct shmem_inode_info *info =3D SHMEM_I(inode); @@ -3300,9 +3300,9 @@ shmem_write_begin(struct file *file, struct address_s= pace *mapping, } =20 static int -shmem_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct folio *folio, void *fsdata) +shmem_write_end(const struct kiocb *iocb, struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct folio *folio, void *fsdata) { struct inode *inode =3D mapping->host; =20 --=20 2.34.1 From nobody Tue Oct 7 10:32:54 2025 Received: from mx10.didiglobal.com (mx10.didiglobal.com [111.202.70.125]) by smtp.subspace.kernel.org (Postfix) with SMTP id C53AE2D6616; Thu, 10 Jul 2025 10:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.70.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142488; cv=none; b=CwnaX9PP9LuIDxdQHM659USWMOV9GVIS9XzM10R6bVp9fxjMmH0jVWrFkvBWBXxN2gXoK86D7HYh7NUEREJlmLMuP1jzA68GHZOQLicvAbVUoCHH9L5+Ilmbj7nyTdaqHoHiO3swg1mqd4dzMozc2vhTZNqAEwqzdXtxFpjJ7BU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142488; c=relaxed/simple; bh=e+n/6AlPUc3DbRhJD+hzg5MV5KYpldOkq0RvjNrxVUY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version; b=ZiPIupBcdc9dW1/f1u+DgvPrV33GjjEY3SNlwib2S1yOhFIc95VK4tJPWRO3rKWJjDktwKPfhvCHOt0wNu3pEoN4/k/+PY0eWrhxUQFWMZ8+B/l2C1PZibolzJsd2su7kKsA4bCWUBvBSsqiQ6kvI5UXwrEZaR33WMfbc+a7rT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com; spf=pass smtp.mailfrom=didiglobal.com; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b=d0xbnjYw; arc=none smtp.client-ip=111.202.70.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b="d0xbnjYw" Received: from mail.didiglobal.com (unknown [10.79.71.38]) by mx10.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id 0FA4D18387BC5E; Thu, 10 Jul 2025 18:13:29 +0800 (CST) Received: from BJ03-ACTMBX-08.didichuxing.com (10.79.71.35) by BJ03-ACTMBX-02.didichuxing.com (10.79.71.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:13 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-08.didichuxing.com (10.79.71.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:12 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e]) by BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e%7]) with mapi id 15.02.1748.010; Thu, 10 Jul 2025 18:14:12 +0800 X-MD-Sfrom: chentaotao@didiglobal.com X-MD-SrcIP: 10.79.71.38 From: =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= To: "tytso@mit.edu" , "hch@infradead.org" , "adilger.kernel@dilger.ca" , "willy@infradead.org" , "brauner@kernel.org" , "jani.nikula@linux.intel.com" , "rodrigo.vivi@intel.com" , "tursulin@ursulin.net" , "airlied@gmail.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-block@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "chentao325@qq.com" , "frank.li@vivo.com" , =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= Subject: [PATCH v5 4/5] mm/pagemap: add write_begin_get_folio() helper function Thread-Topic: [PATCH v5 4/5] mm/pagemap: add write_begin_get_folio() helper function Thread-Index: AQHb8YNhNDn+fEJVz0y29k3GEMiAYg== Date: Thu, 10 Jul 2025 10:14:12 +0000 Message-ID: <20250710101404.362146-5-chentaotao@didiglobal.com> In-Reply-To: <20250710101404.362146-1-chentaotao@didiglobal.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=didiglobal.com; s=2025; t=1752142431; bh=e+n/6AlPUc3DbRhJD+hzg5MV5KYpldOkq0RvjNrxVUY=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=d0xbnjYwkUwSNQGtY0jrMsDrePpkcnpXrxO+wIbgEaLulQs8BdiUykm3SLjqEELeb EMU81Lts5cS8gI5uG+fU7WeoedfsduBXpJscvPkIzAK5uWgpx7kqom43oSIJyMzH7n ZcbyIi6HdG3CzUJhB3nHvUmqFc/07rS9XFLbMAP8= Content-Type: text/plain; charset="utf-8" From: Taotao Chen Add write_begin_get_folio() to simplify the common folio lookup logic used by filesystem ->write_begin() implementations. This helper wraps __filemap_get_folio() with common flags such as FGP_WRITEBEGIN, conditional FGP_DONTCACHE, and set folio order based on the write length. Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen --- include/linux/pagemap.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index e63fbfbd5b0f..ce2bcdcadb73 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -750,6 +750,33 @@ struct folio *__filemap_get_folio(struct address_space= *mapping, pgoff_t index, struct page *pagecache_get_page(struct address_space *mapping, pgoff_t ind= ex, fgf_t fgp_flags, gfp_t gfp); =20 +/** + * write_begin_get_folio - Get folio for write_begin with flags. + * @iocb: The kiocb passed from write_begin (may be NULL). + * @mapping: The address space to search. + * @index: The page cache index. + * @len: Length of data being written. + * + * This is a helper for filesystem write_begin() implementations. + * It wraps __filemap_get_folio(), setting appropriate flags in + * the write begin context. + * + * Return: A folio or an ERR_PTR. + */ +static inline struct folio *write_begin_get_folio(const struct kiocb *iocb, + struct address_space *mapping, pgoff_t index, size_t len) +{ + fgf_t fgp_flags =3D FGP_WRITEBEGIN; + + fgp_flags |=3D fgf_set_order(len); + + if (iocb && iocb->ki_flags & IOCB_DONTCACHE) + fgp_flags |=3D FGP_DONTCACHE; + + return __filemap_get_folio(mapping, index, fgp_flags, + mapping_gfp_mask(mapping)); +} + /** * filemap_get_folio - Find and get a folio. * @mapping: The address_space to search. --=20 2.34.1 From nobody Tue Oct 7 10:32:54 2025 Received: from mx9.didiglobal.com (mx9.didiglobal.com [111.202.70.124]) by smtp.subspace.kernel.org (Postfix) with SMTP id E80122D8378; Thu, 10 Jul 2025 10:14:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.70.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142466; cv=none; b=KNKmGVMYzdgrir8Mnv1KD8AEzv3rlSPiYHgQ5oPxmSB+wXG6HViMP0XqWIixm9IqTq1atop4RJkE4ssYMAsK203NeOneN803j73d6CmiLHxWO/BSGEXlQ2F+6KLz/pRhWDIfNj1HsdXJay6kVNaQ4jN0/wlPdnXiTJoCcdLmSoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142466; c=relaxed/simple; bh=7NwIqzCgC1RdJfhixz5bD3co5fgHiYbQk2Lmr3rknQE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version; b=trplseVP+4c2XgJlZQJ4wEgJ1uayZ9ckB8A3BPAAHb7bvStB+bo3CM4Ubs8kE8jzeLPe4ZoExPPkUfQZfA/A+/+oQPVGwAzR5W8602pOapEEk0ZE6B+4/p0Xz+cJrL8LKhZmbHeT9XfFZWMyoGsr+lR3LLphjL7qLYER52uUrYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com; spf=pass smtp.mailfrom=didiglobal.com; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b=pUO++xb0; arc=none smtp.client-ip=111.202.70.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b="pUO++xb0" Received: from mail.didiglobal.com (unknown [10.79.65.20]) by mx9.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id 91DAD181988061; Thu, 10 Jul 2025 18:14:10 +0800 (CST) Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ02-ACTMBX-02.didichuxing.com (10.79.65.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:14 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:13 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e]) by BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e%7]) with mapi id 15.02.1748.010; Thu, 10 Jul 2025 18:14:13 +0800 X-MD-Sfrom: chentaotao@didiglobal.com X-MD-SrcIP: 10.79.65.20 From: =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= To: "tytso@mit.edu" , "hch@infradead.org" , "adilger.kernel@dilger.ca" , "willy@infradead.org" , "brauner@kernel.org" , "jani.nikula@linux.intel.com" , "rodrigo.vivi@intel.com" , "tursulin@ursulin.net" , "airlied@gmail.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-block@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "chentao325@qq.com" , "frank.li@vivo.com" , =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= Subject: [PATCH v5 5/5] ext4: support uncached buffered I/O Thread-Topic: [PATCH v5 5/5] ext4: support uncached buffered I/O Thread-Index: AQHb8YNidCjBjxjXN0upWQdveJF71w== Date: Thu, 10 Jul 2025 10:14:13 +0000 Message-ID: <20250710101404.362146-6-chentaotao@didiglobal.com> In-Reply-To: <20250710101404.362146-1-chentaotao@didiglobal.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=didiglobal.com; s=2025; t=1752142451; bh=7NwIqzCgC1RdJfhixz5bD3co5fgHiYbQk2Lmr3rknQE=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=pUO++xb079uJeMYeGE+v0JZeksYTppApb64G7oWIMCNd4WAin9dCgJa67poFEuvXH jNGaueB8IKTYZa6cCoO/9grensZNyjvYFeZHqt6z0wHjB66bHK2K8javVpACzqDmKe l3ZaFPY0UWUmbq8VfqXMmkYvLrKD3VzvNYAwScIQ= Content-Type: text/plain; charset="utf-8" From: Taotao Chen Set FOP_DONTCACHE in ext4_file_operations to declare support for uncached buffered I/O. To handle this flag, update ext4_write_begin() and ext4_da_write_begin() to use write_begin_get_folio(), which encapsulates FGP_DONTCACHE logic based on iocb->ki_flags. Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen --- fs/ext4/file.c | 3 ++- fs/ext4/inode.c | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 21df81347147..274b41a476c8 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -977,7 +977,8 @@ const struct file_operations ext4_file_operations =3D { .splice_write =3D iter_file_splice_write, .fallocate =3D ext4_fallocate, .fop_flags =3D FOP_MMAP_SYNC | FOP_BUFFER_RASYNC | - FOP_DIO_PARALLEL_WRITE, + FOP_DIO_PARALLEL_WRITE | + FOP_DONTCACHE, }; =20 const struct inode_operations ext4_file_inode_operations =3D { diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9a16efd072bb..5c7024051f1e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1264,7 +1264,6 @@ static int ext4_write_begin(const struct kiocb *iocb, struct folio *folio; pgoff_t index; unsigned from, to; - fgf_t fgp =3D FGP_WRITEBEGIN; =20 ret =3D ext4_emergency_state(inode->i_sb); if (unlikely(ret)) @@ -1288,16 +1287,14 @@ static int ext4_write_begin(const struct kiocb *ioc= b, } =20 /* - * __filemap_get_folio() can take a long time if the + * write_begin_get_folio() can take a long time if the * system is thrashing due to memory pressure, or if the folio * is being written back. So grab it first before we start * the transaction handle. This also allows us to allocate * the folio (if needed) without using GFP_NOFS. */ retry_grab: - fgp |=3D fgf_set_order(len); - folio =3D __filemap_get_folio(mapping, index, fgp, - mapping_gfp_mask(mapping)); + folio =3D write_begin_get_folio(iocb, mapping, index, len); if (IS_ERR(folio)) return PTR_ERR(folio); =20 @@ -3046,7 +3043,6 @@ static int ext4_da_write_begin(const struct kiocb *io= cb, struct folio *folio; pgoff_t index; struct inode *inode =3D mapping->host; - fgf_t fgp =3D FGP_WRITEBEGIN; =20 ret =3D ext4_emergency_state(inode->i_sb); if (unlikely(ret)) @@ -3072,9 +3068,7 @@ static int ext4_da_write_begin(const struct kiocb *io= cb, } =20 retry: - fgp |=3D fgf_set_order(len); - folio =3D __filemap_get_folio(mapping, index, fgp, - mapping_gfp_mask(mapping)); + folio =3D write_begin_get_folio(iocb, mapping, index, len); if (IS_ERR(folio)) return PTR_ERR(folio); =20 --=20 2.34.1