Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'ubifs-for-linus-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs

Pull UBI and UBIFS updates from Richard Weinberger:
"UBI:
- Add Zhihao Cheng as reviewer
- Attach via device tree
- Add NVMEM layer
- Various fastmap related fixes

UBIFS:
- Add Zhihao Cheng as reviewer
- Convert to folios
- Various fixes (memory leaks in error paths, function prototypes)"

* tag 'ubifs-for-linus-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs: (34 commits)
mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
mtd: ubi: provide NVMEM layer over UBI volumes
mtd: ubi: populate ubi volume fwnode
mtd: ubi: introduce pre-removal notification for UBI volumes
mtd: ubi: attach from device tree
mtd: ubi: block: use notifier to create ubiblock from parameter
dt-bindings: mtd: ubi-volume: allow UBI volumes to provide NVMEM
dt-bindings: mtd: add basic bindings for UBI
ubifs: Queue up space reservation tasks if retrying many times
ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path
ubifs: dbg_check_idx_size: Fix kmemleak if loading znode failed
ubi: Correct the number of PEBs after a volume resize failure
ubi: fix slab-out-of-bounds in ubi_eba_get_ldesc+0xfb/0x130
ubi: correct the calculation of fastmap size
ubifs: Remove unreachable code in dbg_check_ltab_lnum
ubifs: fix function pointer cast warnings
ubifs: fix sort function prototype
ubi: Check for too small LEB size in VTBL code
MAINTAINERS: Add Zhihao Cheng as UBI/UBIFS reviewer
ubifs: Convert populate_page() to take a folio
...

+1067 -427
+75
Documentation/devicetree/bindings/mtd/partitions/linux,ubi.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mtd/partitions/linux,ubi.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Unsorted Block Images 8 + 9 + description: | 10 + UBI ("Unsorted Block Images") is a volume management system for raw 11 + flash devices which manages multiple logical volumes on a single 12 + physical flash device and spreads the I/O load (i.e wear-leveling) 13 + across the whole flash chip. 14 + 15 + maintainers: 16 + - Daniel Golle <daniel@makrotopia.org> 17 + 18 + allOf: 19 + - $ref: partition.yaml# 20 + 21 + properties: 22 + compatible: 23 + const: linux,ubi 24 + 25 + volumes: 26 + type: object 27 + description: UBI Volumes 28 + 29 + patternProperties: 30 + "^ubi-volume-.*$": 31 + $ref: /schemas/mtd/partitions/ubi-volume.yaml# 32 + 33 + unevaluatedProperties: false 34 + 35 + required: 36 + - compatible 37 + 38 + unevaluatedProperties: false 39 + 40 + examples: 41 + - | 42 + partitions { 43 + compatible = "fixed-partitions"; 44 + #address-cells = <1>; 45 + #size-cells = <1>; 46 + 47 + partition@0 { 48 + reg = <0x0 0x100000>; 49 + label = "bootloader"; 50 + read-only; 51 + }; 52 + 53 + partition@100000 { 54 + reg = <0x100000 0x1ff00000>; 55 + label = "ubi"; 56 + compatible = "linux,ubi"; 57 + 58 + volumes { 59 + ubi-volume-caldata { 60 + volid = <2>; 61 + volname = "rf"; 62 + 63 + nvmem-layout { 64 + compatible = "fixed-layout"; 65 + #address-cells = <1>; 66 + #size-cells = <1>; 67 + 68 + eeprom@0 { 69 + reg = <0x0 0x1000>; 70 + }; 71 + }; 72 + }; 73 + }; 74 + }; 75 + };
+40
Documentation/devicetree/bindings/mtd/partitions/ubi-volume.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mtd/partitions/ubi-volume.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: UBI volume 8 + 9 + description: | 10 + This binding describes a single UBI volume. Volumes can be matches either 11 + by their ID or their name, or both. 12 + 13 + maintainers: 14 + - Daniel Golle <daniel@makrotopia.org> 15 + 16 + properties: 17 + volid: 18 + $ref: /schemas/types.yaml#/definitions/uint32 19 + description: 20 + Match UBI volume ID 21 + 22 + volname: 23 + $ref: /schemas/types.yaml#/definitions/string 24 + description: 25 + Match UBI volume ID 26 + 27 + nvmem-layout: 28 + $ref: /schemas/nvmem/layouts/nvmem-layout.yaml# 29 + description: 30 + This container may reference an NVMEM layout parser. 31 + 32 + anyOf: 33 + - required: 34 + - volid 35 + 36 + - required: 37 + - volname 38 + 39 + # This is a generic file other binding inherit from and extend 40 + additionalProperties: true
+10
Documentation/mm/page_cache.rst
··· 3 3 ========== 4 4 Page Cache 5 5 ========== 6 + 7 + The page cache is the primary way that the user and the rest of the kernel 8 + interact with filesystems. It can be bypassed (e.g. with O_DIRECT), 9 + but normal reads, writes and mmaps go through the page cache. 10 + 11 + Folios 12 + ====== 13 + 14 + The folio is the unit of memory management within the page cache. 15 + Operations
+2
MAINTAINERS
··· 22573 22573 22574 22574 UBI FILE SYSTEM (UBIFS) 22575 22575 M: Richard Weinberger <richard@nod.at> 22576 + R: Zhihao Cheng <chengzhihao1@huawei.com> 22576 22577 L: linux-mtd@lists.infradead.org 22577 22578 S: Supported 22578 22579 W: http://www.linux-mtd.infradead.org/doc/ubifs.html ··· 22719 22718 22720 22719 UNSORTED BLOCK IMAGES (UBI) 22721 22720 M: Richard Weinberger <richard@nod.at> 22721 + R: Zhihao Cheng <chengzhihao1@huawei.com> 22722 22722 L: linux-mtd@lists.infradead.org 22723 22723 S: Supported 22724 22724 W: http://www.linux-mtd.infradead.org/
+13
drivers/mtd/ubi/Kconfig
··· 113 113 testing purposes. 114 114 115 115 If in doubt, say "N". 116 + 117 + config MTD_UBI_NVMEM 118 + tristate "UBI virtual NVMEM" 119 + default n 120 + depends on NVMEM 121 + help 122 + This option enabled an additional driver exposing UBI volumes as NVMEM 123 + providers, intended for platforms where UBI is part of the firmware 124 + specification and used to store also e.g. MAC addresses or board- 125 + specific Wi-Fi calibration data. 126 + 127 + If in doubt, say "N". 128 + 116 129 endif # MTD_UBI
+1
drivers/mtd/ubi/Makefile
··· 7 7 ubi-$(CONFIG_MTD_UBI_BLOCK) += block.o 8 8 9 9 obj-$(CONFIG_MTD_UBI_GLUEBI) += gluebi.o 10 + obj-$(CONFIG_MTD_UBI_NVMEM) += nvmem.o
+68 -68
drivers/mtd/ubi/block.c
··· 65 65 }; 66 66 67 67 /* Numbers of elements set in the @ubiblock_param array */ 68 - static int ubiblock_devs __initdata; 68 + static int ubiblock_devs; 69 69 70 70 /* MTD devices specification parameters */ 71 - static struct ubiblock_param ubiblock_param[UBIBLOCK_MAX_DEVICES] __initdata; 71 + static struct ubiblock_param ubiblock_param[UBIBLOCK_MAX_DEVICES]; 72 72 73 73 struct ubiblock { 74 74 struct ubi_volume_desc *desc; ··· 536 536 return 0; 537 537 } 538 538 539 + static bool 540 + match_volume_desc(struct ubi_volume_info *vi, const char *name, int ubi_num, int vol_id) 541 + { 542 + int err, len, cur_ubi_num, cur_vol_id; 543 + 544 + if (ubi_num == -1) { 545 + /* No ubi num, name must be a vol device path */ 546 + err = ubi_get_num_by_path(name, &cur_ubi_num, &cur_vol_id); 547 + if (err || vi->ubi_num != cur_ubi_num || vi->vol_id != cur_vol_id) 548 + return false; 549 + 550 + return true; 551 + } 552 + 553 + if (vol_id == -1) { 554 + /* Got ubi_num, but no vol_id, name must be volume name */ 555 + if (vi->ubi_num != ubi_num) 556 + return false; 557 + 558 + len = strnlen(name, UBI_VOL_NAME_MAX + 1); 559 + if (len < 1 || vi->name_len != len) 560 + return false; 561 + 562 + if (strcmp(name, vi->name)) 563 + return false; 564 + 565 + return true; 566 + } 567 + 568 + if (vi->ubi_num != ubi_num) 569 + return false; 570 + 571 + if (vi->vol_id != vol_id) 572 + return false; 573 + 574 + return true; 575 + } 576 + 577 + static void 578 + ubiblock_create_from_param(struct ubi_volume_info *vi) 579 + { 580 + int i, ret = 0; 581 + struct ubiblock_param *p; 582 + 583 + /* 584 + * Iterate over ubiblock cmdline parameters. If a parameter matches the 585 + * newly added volume create the ubiblock device for it. 586 + */ 587 + for (i = 0; i < ubiblock_devs; i++) { 588 + p = &ubiblock_param[i]; 589 + 590 + if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id)) 591 + continue; 592 + 593 + ret = ubiblock_create(vi); 594 + if (ret) { 595 + pr_err( 596 + "UBI: block: can't add '%s' volume on ubi%d_%d, err=%d\n", 597 + vi->name, p->ubi_num, p->vol_id, ret); 598 + } 599 + break; 600 + } 601 + } 602 + 539 603 static int ubiblock_notify(struct notifier_block *nb, 540 604 unsigned long notification_type, void *ns_ptr) 541 605 { ··· 607 543 608 544 switch (notification_type) { 609 545 case UBI_VOLUME_ADDED: 610 - /* 611 - * We want to enforce explicit block device creation for 612 - * volumes, so when a volume is added we do nothing. 613 - */ 546 + ubiblock_create_from_param(&nt->vi); 614 547 break; 615 548 case UBI_VOLUME_REMOVED: 616 549 ubiblock_remove(&nt->vi); ··· 632 571 static struct notifier_block ubiblock_notifier = { 633 572 .notifier_call = ubiblock_notify, 634 573 }; 635 - 636 - static struct ubi_volume_desc * __init 637 - open_volume_desc(const char *name, int ubi_num, int vol_id) 638 - { 639 - if (ubi_num == -1) 640 - /* No ubi num, name must be a vol device path */ 641 - return ubi_open_volume_path(name, UBI_READONLY); 642 - else if (vol_id == -1) 643 - /* No vol_id, must be vol_name */ 644 - return ubi_open_volume_nm(ubi_num, name, UBI_READONLY); 645 - else 646 - return ubi_open_volume(ubi_num, vol_id, UBI_READONLY); 647 - } 648 - 649 - static void __init ubiblock_create_from_param(void) 650 - { 651 - int i, ret = 0; 652 - struct ubiblock_param *p; 653 - struct ubi_volume_desc *desc; 654 - struct ubi_volume_info vi; 655 - 656 - /* 657 - * If there is an error creating one of the ubiblocks, continue on to 658 - * create the following ubiblocks. This helps in a circumstance where 659 - * the kernel command-line specifies multiple block devices and some 660 - * may be broken, but we still want the working ones to come up. 661 - */ 662 - for (i = 0; i < ubiblock_devs; i++) { 663 - p = &ubiblock_param[i]; 664 - 665 - desc = open_volume_desc(p->name, p->ubi_num, p->vol_id); 666 - if (IS_ERR(desc)) { 667 - pr_err( 668 - "UBI: block: can't open volume on ubi%d_%d, err=%ld\n", 669 - p->ubi_num, p->vol_id, PTR_ERR(desc)); 670 - continue; 671 - } 672 - 673 - ubi_get_volume_info(desc, &vi); 674 - ubi_close_volume(desc); 675 - 676 - ret = ubiblock_create(&vi); 677 - if (ret) { 678 - pr_err( 679 - "UBI: block: can't add '%s' volume on ubi%d_%d, err=%d\n", 680 - vi.name, p->ubi_num, p->vol_id, ret); 681 - continue; 682 - } 683 - } 684 - } 685 574 686 575 static void ubiblock_remove_all(void) 687 576 { ··· 658 647 if (ubiblock_major < 0) 659 648 return ubiblock_major; 660 649 661 - /* 662 - * Attach block devices from 'block=' module param. 663 - * Even if one block device in the param list fails to come up, 664 - * still allow the module to load and leave any others up. 665 - */ 666 - ubiblock_create_from_param(); 667 - 668 - /* 669 - * Block devices are only created upon user requests, so we ignore 670 - * existing volumes. 671 - */ 672 - ret = ubi_register_volume_notifier(&ubiblock_notifier, 1); 650 + ret = ubi_register_volume_notifier(&ubiblock_notifier, 0); 673 651 if (ret) 674 652 goto err_unreg; 675 653 return 0;
+117 -51
drivers/mtd/ubi/build.c
··· 27 27 #include <linux/log2.h> 28 28 #include <linux/kthread.h> 29 29 #include <linux/kernel.h> 30 + #include <linux/of.h> 30 31 #include <linux/slab.h> 31 32 #include <linux/major.h> 32 33 #include "ubi.h" ··· 93 92 /* Serializes UBI devices creations and removals */ 94 93 DEFINE_MUTEX(ubi_devices_mutex); 95 94 96 - /* Protects @ubi_devices and @ubi->ref_count */ 95 + /* Protects @ubi_devices, @ubi->ref_count and @ubi->is_dead */ 97 96 static DEFINE_SPINLOCK(ubi_devices_lock); 98 97 99 98 /* "Show" method for files in '/<sysfs>/class/ubi/' */ ··· 261 260 262 261 spin_lock(&ubi_devices_lock); 263 262 ubi = ubi_devices[ubi_num]; 263 + if (ubi && ubi->is_dead) 264 + ubi = NULL; 265 + 264 266 if (ubi) { 265 267 ubi_assert(ubi->ref_count >= 0); 266 268 ubi->ref_count += 1; ··· 301 297 spin_lock(&ubi_devices_lock); 302 298 for (i = 0; i < UBI_MAX_DEVICES; i++) { 303 299 ubi = ubi_devices[i]; 304 - if (ubi && MAJOR(ubi->cdev.dev) == major) { 300 + if (ubi && !ubi->is_dead && MAJOR(ubi->cdev.dev) == major) { 305 301 ubi_assert(ubi->ref_count >= 0); 306 302 ubi->ref_count += 1; 307 303 get_device(&ubi->dev); ··· 330 326 for (i = 0; i < UBI_MAX_DEVICES; i++) { 331 327 struct ubi_device *ubi = ubi_devices[i]; 332 328 333 - if (ubi && MAJOR(ubi->cdev.dev) == major) { 329 + if (ubi && !ubi->is_dead && MAJOR(ubi->cdev.dev) == major) { 334 330 ubi_num = ubi->ubi_num; 335 331 break; 336 332 } ··· 517 513 int i; 518 514 519 515 for (i = from; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 520 - if (!ubi->volumes[i]) 516 + if (!ubi->volumes[i] || ubi->volumes[i]->is_dead) 521 517 continue; 522 518 ubi_eba_replace_table(ubi->volumes[i], NULL); 523 519 ubi_fastmap_destroy_checkmap(ubi->volumes[i]); ··· 1102 1098 return -EINVAL; 1103 1099 1104 1100 spin_lock(&ubi_devices_lock); 1105 - put_device(&ubi->dev); 1106 1101 ubi->ref_count -= 1; 1107 1102 if (ubi->ref_count) { 1108 1103 if (!anyway) { ··· 1112 1109 ubi_err(ubi, "%s reference count %d, destroy anyway", 1113 1110 ubi->ubi_name, ubi->ref_count); 1114 1111 } 1112 + ubi->is_dead = true; 1113 + spin_unlock(&ubi_devices_lock); 1114 + 1115 + ubi_notify_all(ubi, UBI_VOLUME_SHUTDOWN, NULL); 1116 + 1117 + spin_lock(&ubi_devices_lock); 1118 + put_device(&ubi->dev); 1115 1119 ubi_devices[ubi_num] = NULL; 1116 1120 spin_unlock(&ubi_devices_lock); 1117 1121 ··· 1229 1219 return mtd; 1230 1220 } 1231 1221 1232 - static int __init ubi_init(void) 1222 + static void ubi_notify_add(struct mtd_info *mtd) 1223 + { 1224 + struct device_node *np = mtd_get_of_node(mtd); 1225 + int err; 1226 + 1227 + if (!of_device_is_compatible(np, "linux,ubi")) 1228 + return; 1229 + 1230 + /* 1231 + * we are already holding &mtd_table_mutex, but still need 1232 + * to bump refcount 1233 + */ 1234 + err = __get_mtd_device(mtd); 1235 + if (err) 1236 + return; 1237 + 1238 + /* called while holding mtd_table_mutex */ 1239 + mutex_lock_nested(&ubi_devices_mutex, SINGLE_DEPTH_NESTING); 1240 + err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0, false, false); 1241 + mutex_unlock(&ubi_devices_mutex); 1242 + if (err < 0) 1243 + __put_mtd_device(mtd); 1244 + } 1245 + 1246 + static void ubi_notify_remove(struct mtd_info *mtd) 1247 + { 1248 + /* do nothing for now */ 1249 + } 1250 + 1251 + static struct mtd_notifier ubi_mtd_notifier = { 1252 + .add = ubi_notify_add, 1253 + .remove = ubi_notify_remove, 1254 + }; 1255 + 1256 + static int __init ubi_init_attach(void) 1233 1257 { 1234 1258 int err, i, k; 1235 - 1236 - /* Ensure that EC and VID headers have correct size */ 1237 - BUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64); 1238 - BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); 1239 - 1240 - if (mtd_devs > UBI_MAX_DEVICES) { 1241 - pr_err("UBI error: too many MTD devices, maximum is %d\n", 1242 - UBI_MAX_DEVICES); 1243 - return -EINVAL; 1244 - } 1245 - 1246 - /* Create base sysfs directory and sysfs files */ 1247 - err = class_register(&ubi_class); 1248 - if (err < 0) 1249 - return err; 1250 - 1251 - err = misc_register(&ubi_ctrl_cdev); 1252 - if (err) { 1253 - pr_err("UBI error: cannot register device\n"); 1254 - goto out; 1255 - } 1256 - 1257 - ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", 1258 - sizeof(struct ubi_wl_entry), 1259 - 0, 0, NULL); 1260 - if (!ubi_wl_entry_slab) { 1261 - err = -ENOMEM; 1262 - goto out_dev_unreg; 1263 - } 1264 - 1265 - err = ubi_debugfs_init(); 1266 - if (err) 1267 - goto out_slab; 1268 - 1269 1259 1270 1260 /* Attach MTD devices */ 1271 1261 for (i = 0; i < mtd_devs; i++) { ··· 1314 1304 } 1315 1305 } 1316 1306 1317 - err = ubiblock_init(); 1318 - if (err) { 1319 - pr_err("UBI error: block: cannot initialize, error %d\n", err); 1320 - 1321 - /* See comment above re-ubi_is_module(). */ 1322 - if (ubi_is_module()) 1323 - goto out_detach; 1324 - } 1325 - 1326 1307 return 0; 1327 1308 1328 1309 out_detach: ··· 1323 1322 ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); 1324 1323 mutex_unlock(&ubi_devices_mutex); 1325 1324 } 1326 - ubi_debugfs_exit(); 1325 + return err; 1326 + } 1327 + #ifndef CONFIG_MTD_UBI_MODULE 1328 + late_initcall(ubi_init_attach); 1329 + #endif 1330 + 1331 + static int __init ubi_init(void) 1332 + { 1333 + int err; 1334 + 1335 + /* Ensure that EC and VID headers have correct size */ 1336 + BUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64); 1337 + BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); 1338 + 1339 + if (mtd_devs > UBI_MAX_DEVICES) { 1340 + pr_err("UBI error: too many MTD devices, maximum is %d\n", 1341 + UBI_MAX_DEVICES); 1342 + return -EINVAL; 1343 + } 1344 + 1345 + /* Create base sysfs directory and sysfs files */ 1346 + err = class_register(&ubi_class); 1347 + if (err < 0) 1348 + return err; 1349 + 1350 + err = misc_register(&ubi_ctrl_cdev); 1351 + if (err) { 1352 + pr_err("UBI error: cannot register device\n"); 1353 + goto out; 1354 + } 1355 + 1356 + ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", 1357 + sizeof(struct ubi_wl_entry), 1358 + 0, 0, NULL); 1359 + if (!ubi_wl_entry_slab) { 1360 + err = -ENOMEM; 1361 + goto out_dev_unreg; 1362 + } 1363 + 1364 + err = ubi_debugfs_init(); 1365 + if (err) 1366 + goto out_slab; 1367 + 1368 + err = ubiblock_init(); 1369 + if (err) { 1370 + pr_err("UBI error: block: cannot initialize, error %d\n", err); 1371 + 1372 + /* See comment above re-ubi_is_module(). */ 1373 + if (ubi_is_module()) 1374 + goto out_slab; 1375 + } 1376 + 1377 + register_mtd_user(&ubi_mtd_notifier); 1378 + 1379 + if (ubi_is_module()) { 1380 + err = ubi_init_attach(); 1381 + if (err) 1382 + goto out_mtd_notifier; 1383 + } 1384 + 1385 + return 0; 1386 + 1387 + out_mtd_notifier: 1388 + unregister_mtd_user(&ubi_mtd_notifier); 1327 1389 out_slab: 1328 1390 kmem_cache_destroy(ubi_wl_entry_slab); 1329 1391 out_dev_unreg: ··· 1396 1332 pr_err("UBI error: cannot initialize UBI, error %d\n", err); 1397 1333 return err; 1398 1334 } 1399 - late_initcall(ubi_init); 1335 + device_initcall(ubi_init); 1336 + 1400 1337 1401 1338 static void __exit ubi_exit(void) 1402 1339 { 1403 1340 int i; 1404 1341 1405 1342 ubiblock_exit(); 1343 + unregister_mtd_user(&ubi_mtd_notifier); 1406 1344 1407 1345 for (i = 0; i < UBI_MAX_DEVICES; i++) 1408 1346 if (ubi_devices[i]) {
+7
drivers/mtd/ubi/eba.c
··· 1456 1456 } 1457 1457 1458 1458 ubi_assert(vol->eba_tbl->entries[lnum].pnum == from); 1459 + 1460 + /** 1461 + * The volumes_lock lock is needed here to prevent the expired old eba_tbl 1462 + * being updated when the eba_tbl is copied in the ubi_resize_volume() process. 1463 + */ 1464 + spin_lock(&ubi->volumes_lock); 1459 1465 vol->eba_tbl->entries[lnum].pnum = to; 1466 + spin_unlock(&ubi->volumes_lock); 1460 1467 1461 1468 out_unlock_buf: 1462 1469 mutex_unlock(&ubi->buf_mutex);
+4 -3
drivers/mtd/ubi/fastmap.c
··· 85 85 sizeof(struct ubi_fm_scan_pool) + 86 86 sizeof(struct ubi_fm_scan_pool) + 87 87 (ubi->peb_count * sizeof(struct ubi_fm_ec)) + 88 - (sizeof(struct ubi_fm_eba) + 89 - (ubi->peb_count * sizeof(__be32))) + 90 - sizeof(struct ubi_fm_volhdr) * UBI_MAX_VOLUMES; 88 + ((sizeof(struct ubi_fm_eba) + 89 + sizeof(struct ubi_fm_volhdr)) * 90 + (UBI_MAX_VOLUMES + UBI_INT_VOL_COUNT)) + 91 + (ubi->peb_count * sizeof(__be32)); 91 92 return roundup(size, ubi->leb_size); 92 93 } 93 94
+38 -18
drivers/mtd/ubi/kapi.c
··· 152 152 153 153 spin_lock(&ubi->volumes_lock); 154 154 vol = ubi->volumes[vol_id]; 155 - if (!vol) 155 + if (!vol || vol->is_dead) 156 156 goto out_unlock; 157 157 158 158 err = -EBUSY; ··· 280 280 EXPORT_SYMBOL_GPL(ubi_open_volume_nm); 281 281 282 282 /** 283 + * ubi_get_num_by_path - get UBI device and volume number from device path 284 + * @pathname: volume character device node path 285 + * @ubi_num: pointer to UBI device number to be set 286 + * @vol_id: pointer to UBI volume ID to be set 287 + * 288 + * Returns 0 on success and sets ubi_num and vol_id, returns error otherwise. 289 + */ 290 + int ubi_get_num_by_path(const char *pathname, int *ubi_num, int *vol_id) 291 + { 292 + int error; 293 + struct path path; 294 + struct kstat stat; 295 + 296 + error = kern_path(pathname, LOOKUP_FOLLOW, &path); 297 + if (error) 298 + return error; 299 + 300 + error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); 301 + path_put(&path); 302 + if (error) 303 + return error; 304 + 305 + if (!S_ISCHR(stat.mode)) 306 + return -EINVAL; 307 + 308 + *ubi_num = ubi_major2num(MAJOR(stat.rdev)); 309 + *vol_id = MINOR(stat.rdev) - 1; 310 + 311 + if (*vol_id < 0 || *ubi_num < 0) 312 + return -ENODEV; 313 + 314 + return 0; 315 + } 316 + 317 + /** 283 318 * ubi_open_volume_path - open UBI volume by its character device node path. 284 319 * @pathname: volume character device node path 285 320 * @mode: open mode ··· 325 290 struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) 326 291 { 327 292 int error, ubi_num, vol_id; 328 - struct path path; 329 - struct kstat stat; 330 293 331 294 dbg_gen("open volume %s, mode %d", pathname, mode); 332 295 333 296 if (!pathname || !*pathname) 334 297 return ERR_PTR(-EINVAL); 335 298 336 - error = kern_path(pathname, LOOKUP_FOLLOW, &path); 299 + error = ubi_get_num_by_path(pathname, &ubi_num, &vol_id); 337 300 if (error) 338 301 return ERR_PTR(error); 339 302 340 - error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); 341 - path_put(&path); 342 - if (error) 343 - return ERR_PTR(error); 344 - 345 - if (!S_ISCHR(stat.mode)) 346 - return ERR_PTR(-EINVAL); 347 - 348 - ubi_num = ubi_major2num(MAJOR(stat.rdev)); 349 - vol_id = MINOR(stat.rdev) - 1; 350 - 351 - if (vol_id >= 0 && ubi_num >= 0) 352 - return ubi_open_volume(ubi_num, vol_id, mode); 353 - return ERR_PTR(-ENODEV); 303 + return ubi_open_volume(ubi_num, vol_id, mode); 354 304 } 355 305 EXPORT_SYMBOL_GPL(ubi_open_volume_path); 356 306
+191
drivers/mtd/ubi/nvmem.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Copyright (c) 2023 Daniel Golle <daniel@makrotopia.org> 4 + */ 5 + 6 + /* UBI NVMEM provider */ 7 + #include "ubi.h" 8 + #include <linux/nvmem-provider.h> 9 + #include <asm/div64.h> 10 + 11 + /* List of all NVMEM devices */ 12 + static LIST_HEAD(nvmem_devices); 13 + static DEFINE_MUTEX(devices_mutex); 14 + 15 + struct ubi_nvmem { 16 + struct nvmem_device *nvmem; 17 + int ubi_num; 18 + int vol_id; 19 + int usable_leb_size; 20 + struct list_head list; 21 + }; 22 + 23 + static int ubi_nvmem_reg_read(void *priv, unsigned int from, 24 + void *val, size_t bytes) 25 + { 26 + size_t to_read, bytes_left = bytes; 27 + struct ubi_nvmem *unv = priv; 28 + struct ubi_volume_desc *desc; 29 + uint32_t offs; 30 + uint64_t lnum = from; 31 + int err = 0; 32 + 33 + desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY); 34 + if (IS_ERR(desc)) 35 + return PTR_ERR(desc); 36 + 37 + offs = do_div(lnum, unv->usable_leb_size); 38 + while (bytes_left) { 39 + to_read = unv->usable_leb_size - offs; 40 + 41 + if (to_read > bytes_left) 42 + to_read = bytes_left; 43 + 44 + err = ubi_read(desc, lnum, val, offs, to_read); 45 + if (err) 46 + break; 47 + 48 + lnum += 1; 49 + offs = 0; 50 + bytes_left -= to_read; 51 + val += to_read; 52 + } 53 + ubi_close_volume(desc); 54 + 55 + if (err) 56 + return err; 57 + 58 + return bytes_left == 0 ? 0 : -EIO; 59 + } 60 + 61 + static int ubi_nvmem_add(struct ubi_volume_info *vi) 62 + { 63 + struct device_node *np = dev_of_node(vi->dev); 64 + struct nvmem_config config = {}; 65 + struct ubi_nvmem *unv; 66 + int ret; 67 + 68 + if (!np) 69 + return 0; 70 + 71 + if (!of_get_child_by_name(np, "nvmem-layout")) 72 + return 0; 73 + 74 + if (WARN_ON_ONCE(vi->usable_leb_size <= 0) || 75 + WARN_ON_ONCE(vi->size <= 0)) 76 + return -EINVAL; 77 + 78 + unv = kzalloc(sizeof(struct ubi_nvmem), GFP_KERNEL); 79 + if (!unv) 80 + return -ENOMEM; 81 + 82 + config.id = NVMEM_DEVID_NONE; 83 + config.dev = vi->dev; 84 + config.name = dev_name(vi->dev); 85 + config.owner = THIS_MODULE; 86 + config.priv = unv; 87 + config.reg_read = ubi_nvmem_reg_read; 88 + config.size = vi->usable_leb_size * vi->size; 89 + config.word_size = 1; 90 + config.stride = 1; 91 + config.read_only = true; 92 + config.root_only = true; 93 + config.ignore_wp = true; 94 + config.of_node = np; 95 + 96 + unv->ubi_num = vi->ubi_num; 97 + unv->vol_id = vi->vol_id; 98 + unv->usable_leb_size = vi->usable_leb_size; 99 + unv->nvmem = nvmem_register(&config); 100 + if (IS_ERR(unv->nvmem)) { 101 + ret = dev_err_probe(vi->dev, PTR_ERR(unv->nvmem), 102 + "Failed to register NVMEM device\n"); 103 + kfree(unv); 104 + return ret; 105 + } 106 + 107 + mutex_lock(&devices_mutex); 108 + list_add_tail(&unv->list, &nvmem_devices); 109 + mutex_unlock(&devices_mutex); 110 + 111 + return 0; 112 + } 113 + 114 + static void ubi_nvmem_remove(struct ubi_volume_info *vi) 115 + { 116 + struct ubi_nvmem *unv_c, *unv = NULL; 117 + 118 + mutex_lock(&devices_mutex); 119 + list_for_each_entry(unv_c, &nvmem_devices, list) 120 + if (unv_c->ubi_num == vi->ubi_num && unv_c->vol_id == vi->vol_id) { 121 + unv = unv_c; 122 + break; 123 + } 124 + 125 + if (!unv) { 126 + mutex_unlock(&devices_mutex); 127 + return; 128 + } 129 + 130 + list_del(&unv->list); 131 + mutex_unlock(&devices_mutex); 132 + nvmem_unregister(unv->nvmem); 133 + kfree(unv); 134 + } 135 + 136 + /** 137 + * nvmem_notify - UBI notification handler. 138 + * @nb: registered notifier block 139 + * @l: notification type 140 + * @ns_ptr: pointer to the &struct ubi_notification object 141 + */ 142 + static int nvmem_notify(struct notifier_block *nb, unsigned long l, 143 + void *ns_ptr) 144 + { 145 + struct ubi_notification *nt = ns_ptr; 146 + 147 + switch (l) { 148 + case UBI_VOLUME_RESIZED: 149 + ubi_nvmem_remove(&nt->vi); 150 + fallthrough; 151 + case UBI_VOLUME_ADDED: 152 + ubi_nvmem_add(&nt->vi); 153 + break; 154 + case UBI_VOLUME_SHUTDOWN: 155 + ubi_nvmem_remove(&nt->vi); 156 + break; 157 + default: 158 + break; 159 + } 160 + return NOTIFY_OK; 161 + } 162 + 163 + static struct notifier_block nvmem_notifier = { 164 + .notifier_call = nvmem_notify, 165 + }; 166 + 167 + static int __init ubi_nvmem_init(void) 168 + { 169 + return ubi_register_volume_notifier(&nvmem_notifier, 0); 170 + } 171 + 172 + static void __exit ubi_nvmem_exit(void) 173 + { 174 + struct ubi_nvmem *unv, *tmp; 175 + 176 + mutex_lock(&devices_mutex); 177 + list_for_each_entry_safe(unv, tmp, &nvmem_devices, list) { 178 + nvmem_unregister(unv->nvmem); 179 + list_del(&unv->list); 180 + kfree(unv); 181 + } 182 + mutex_unlock(&devices_mutex); 183 + 184 + ubi_unregister_volume_notifier(&nvmem_notifier); 185 + } 186 + 187 + module_init(ubi_nvmem_init); 188 + module_exit(ubi_nvmem_exit); 189 + MODULE_DESCRIPTION("NVMEM layer over UBI volumes"); 190 + MODULE_AUTHOR("Daniel Golle"); 191 + MODULE_LICENSE("GPL");
+3
drivers/mtd/ubi/ubi.h
··· 337 337 int writers; 338 338 int exclusive; 339 339 int metaonly; 340 + bool is_dead; 340 341 341 342 int reserved_pebs; 342 343 int vol_type; ··· 562 561 spinlock_t volumes_lock; 563 562 int ref_count; 564 563 int image_seq; 564 + bool is_dead; 565 565 566 566 int rsvd_pebs; 567 567 int avail_pebs; ··· 957 955 void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di); 958 956 void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol, 959 957 struct ubi_volume_info *vi); 958 + int ubi_get_num_by_path(const char *pathname, int *ubi_num, int *vol_id); 960 959 /* scan.c */ 961 960 int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb, 962 961 int pnum, const struct ubi_vid_hdr *vid_hdr);
+62 -13
drivers/mtd/ubi/vmt.c
··· 59 59 struct ubi_device *ubi = vol->ubi; 60 60 61 61 spin_lock(&ubi->volumes_lock); 62 - if (!ubi->volumes[vol->vol_id]) { 62 + if (!ubi->volumes[vol->vol_id] || ubi->volumes[vol->vol_id]->is_dead) { 63 63 spin_unlock(&ubi->volumes_lock); 64 64 return -ENODEV; 65 65 } ··· 122 122 ubi_eba_replace_table(vol, NULL); 123 123 ubi_fastmap_destroy_checkmap(vol); 124 124 kfree(vol); 125 + } 126 + 127 + static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol) 128 + { 129 + struct fwnode_handle *fw_vols, *fw_vol; 130 + const char *volname; 131 + u32 volid; 132 + 133 + fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes"); 134 + if (!fw_vols) 135 + return NULL; 136 + 137 + fwnode_for_each_child_node(fw_vols, fw_vol) { 138 + if (!fwnode_property_read_string(fw_vol, "volname", &volname) && 139 + strncmp(volname, vol->name, vol->name_len)) 140 + continue; 141 + 142 + if (!fwnode_property_read_u32(fw_vol, "volid", &volid) && 143 + vol->vol_id != volid) 144 + continue; 145 + 146 + return fw_vol; 147 + } 148 + 149 + return NULL; 125 150 } 126 151 127 152 /** ··· 214 189 215 190 /* Ensure that the name is unique */ 216 191 for (i = 0; i < ubi->vtbl_slots; i++) 217 - if (ubi->volumes[i] && 192 + if (ubi->volumes[i] && !ubi->volumes[i]->is_dead && 218 193 ubi->volumes[i]->name_len == req->name_len && 219 194 !strcmp(ubi->volumes[i]->name, req->name)) { 220 195 ubi_err(ubi, "volume \"%s\" exists (ID %d)", ··· 248 223 vol->name_len = req->name_len; 249 224 memcpy(vol->name, req->name, vol->name_len); 250 225 vol->ubi = ubi; 226 + device_set_node(&vol->dev, find_volume_fwnode(vol)); 251 227 252 228 /* 253 229 * Finish all pending erases because there may be some LEBs belonging ··· 378 352 err = -EBUSY; 379 353 goto out_unlock; 380 354 } 355 + 356 + /* 357 + * Mark volume as dead at this point to prevent that anyone 358 + * can take a reference to the volume from now on. 359 + * This is necessary as we have to release the spinlock before 360 + * calling ubi_volume_notify. 361 + */ 362 + vol->is_dead = true; 363 + spin_unlock(&ubi->volumes_lock); 364 + 365 + ubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN); 366 + 367 + spin_lock(&ubi->volumes_lock); 381 368 ubi->volumes[vol_id] = NULL; 382 369 spin_unlock(&ubi->volumes_lock); 383 370 ··· 447 408 struct ubi_device *ubi = vol->ubi; 448 409 struct ubi_vtbl_record vtbl_rec; 449 410 struct ubi_eba_table *new_eba_tbl = NULL; 411 + struct ubi_eba_table *old_eba_tbl = NULL; 450 412 int vol_id = vol->vol_id; 451 413 452 414 if (ubi->ro_mode) ··· 493 453 err = -ENOSPC; 494 454 goto out_free; 495 455 } 456 + 496 457 ubi->avail_pebs -= pebs; 497 458 ubi->rsvd_pebs += pebs; 498 459 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs); 499 - ubi_eba_replace_table(vol, new_eba_tbl); 460 + old_eba_tbl = vol->eba_tbl; 461 + vol->eba_tbl = new_eba_tbl; 462 + vol->reserved_pebs = reserved_pebs; 500 463 spin_unlock(&ubi->volumes_lock); 501 464 } 502 465 ··· 514 471 ubi->avail_pebs -= pebs; 515 472 ubi_update_reserved(ubi); 516 473 ubi_eba_copy_table(vol, new_eba_tbl, reserved_pebs); 517 - ubi_eba_replace_table(vol, new_eba_tbl); 474 + old_eba_tbl = vol->eba_tbl; 475 + vol->eba_tbl = new_eba_tbl; 476 + vol->reserved_pebs = reserved_pebs; 518 477 spin_unlock(&ubi->volumes_lock); 519 478 } 520 479 ··· 538 493 if (err) 539 494 goto out_acc; 540 495 541 - vol->reserved_pebs = reserved_pebs; 542 496 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { 543 497 vol->used_ebs = reserved_pebs; 544 498 vol->last_eb_bytes = vol->usable_leb_size; ··· 545 501 (long long)vol->used_ebs * vol->usable_leb_size; 546 502 } 547 503 504 + /* destroy old table */ 505 + ubi_eba_destroy_table(old_eba_tbl); 548 506 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); 549 507 self_check_volumes(ubi); 550 508 return err; 551 509 552 510 out_acc: 553 - if (pebs > 0) { 554 - spin_lock(&ubi->volumes_lock); 555 - ubi->rsvd_pebs -= pebs; 556 - ubi->avail_pebs += pebs; 557 - spin_unlock(&ubi->volumes_lock); 558 - } 559 - return err; 560 - 511 + spin_lock(&ubi->volumes_lock); 512 + vol->reserved_pebs = reserved_pebs - pebs; 513 + ubi->rsvd_pebs -= pebs; 514 + ubi->avail_pebs += pebs; 515 + if (pebs > 0) 516 + ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs); 517 + else 518 + ubi_eba_copy_table(vol, old_eba_tbl, reserved_pebs); 519 + vol->eba_tbl = old_eba_tbl; 520 + spin_unlock(&ubi->volumes_lock); 561 521 out_free: 562 522 ubi_eba_destroy_table(new_eba_tbl); 563 523 return err; ··· 640 592 vol->dev.class = &ubi_class; 641 593 vol->dev.groups = volume_dev_groups; 642 594 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); 595 + device_set_node(&vol->dev, find_volume_fwnode(vol)); 643 596 err = device_register(&vol->dev); 644 597 if (err) { 645 598 cdev_del(&vol->cdev);
+6
drivers/mtd/ubi/vtbl.c
··· 791 791 * The number of supported volumes is limited by the eraseblock size 792 792 * and by the UBI_MAX_VOLUMES constant. 793 793 */ 794 + 795 + if (ubi->leb_size < UBI_VTBL_RECORD_SIZE) { 796 + ubi_err(ubi, "LEB size too small for a volume record"); 797 + return -EINVAL; 798 + } 799 + 794 800 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE; 795 801 if (ubi->vtbl_slots > UBI_MAX_VOLUMES) 796 802 ubi->vtbl_slots = UBI_MAX_VOLUMES;
+7 -2
fs/ubifs/debug.c
··· 1742 1742 err = dbg_walk_index(c, NULL, add_size, &calc); 1743 1743 if (err) { 1744 1744 ubifs_err(c, "error %d while walking the index", err); 1745 - return err; 1745 + goto out_err; 1746 1746 } 1747 1747 1748 1748 if (calc != idx_size) { 1749 1749 ubifs_err(c, "index size check failed: calculated size is %lld, should be %lld", 1750 1750 calc, idx_size); 1751 1751 dump_stack(); 1752 - return -EINVAL; 1752 + err = -EINVAL; 1753 + goto out_err; 1753 1754 } 1754 1755 1755 1756 return 0; 1757 + 1758 + out_err: 1759 + ubifs_destroy_tnc_tree(c); 1760 + return err; 1756 1761 } 1757 1762 1758 1763 /**
+2
fs/ubifs/dir.c
··· 1133 1133 dir_ui->ui_size = dir->i_size; 1134 1134 mutex_unlock(&dir_ui->ui_mutex); 1135 1135 out_inode: 1136 + /* Free inode->i_link before inode is marked as bad. */ 1137 + fscrypt_free_inode(inode); 1136 1138 make_bad_inode(inode); 1137 1139 iput(inode); 1138 1140 out_fname:
+221 -222
fs/ubifs/file.c
··· 96 96 return -EINVAL; 97 97 } 98 98 99 - static int do_readpage(struct page *page) 99 + static int do_readpage(struct folio *folio) 100 100 { 101 101 void *addr; 102 102 int err = 0, i; 103 103 unsigned int block, beyond; 104 - struct ubifs_data_node *dn; 105 - struct inode *inode = page->mapping->host; 104 + struct ubifs_data_node *dn = NULL; 105 + struct inode *inode = folio->mapping->host; 106 106 struct ubifs_info *c = inode->i_sb->s_fs_info; 107 107 loff_t i_size = i_size_read(inode); 108 108 109 109 dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx", 110 - inode->i_ino, page->index, i_size, page->flags); 111 - ubifs_assert(c, !PageChecked(page)); 112 - ubifs_assert(c, !PagePrivate(page)); 110 + inode->i_ino, folio->index, i_size, folio->flags); 111 + ubifs_assert(c, !folio_test_checked(folio)); 112 + ubifs_assert(c, !folio->private); 113 113 114 - addr = kmap(page); 114 + addr = kmap_local_folio(folio, 0); 115 115 116 - block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; 116 + block = folio->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; 117 117 beyond = (i_size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; 118 118 if (block >= beyond) { 119 119 /* Reading beyond inode */ 120 - SetPageChecked(page); 121 - memset(addr, 0, PAGE_SIZE); 120 + folio_set_checked(folio); 121 + addr = folio_zero_tail(folio, 0, addr); 122 122 goto out; 123 123 } 124 124 125 125 dn = kmalloc(UBIFS_MAX_DATA_NODE_SZ, GFP_NOFS); 126 126 if (!dn) { 127 127 err = -ENOMEM; 128 - goto error; 128 + goto out; 129 129 } 130 130 131 131 i = 0; ··· 150 150 memset(addr + ilen, 0, dlen - ilen); 151 151 } 152 152 } 153 - if (++i >= UBIFS_BLOCKS_PER_PAGE) 153 + if (++i >= (UBIFS_BLOCKS_PER_PAGE << folio_order(folio))) 154 154 break; 155 155 block += 1; 156 156 addr += UBIFS_BLOCK_SIZE; 157 + if (folio_test_highmem(folio) && (offset_in_page(addr) == 0)) { 158 + kunmap_local(addr - UBIFS_BLOCK_SIZE); 159 + addr = kmap_local_folio(folio, i * UBIFS_BLOCK_SIZE); 160 + } 157 161 } 162 + 158 163 if (err) { 159 164 struct ubifs_info *c = inode->i_sb->s_fs_info; 160 165 if (err == -ENOENT) { 161 166 /* Not found, so it must be a hole */ 162 - SetPageChecked(page); 167 + folio_set_checked(folio); 163 168 dbg_gen("hole"); 164 - goto out_free; 169 + err = 0; 170 + } else { 171 + ubifs_err(c, "cannot read page %lu of inode %lu, error %d", 172 + folio->index, inode->i_ino, err); 165 173 } 166 - ubifs_err(c, "cannot read page %lu of inode %lu, error %d", 167 - page->index, inode->i_ino, err); 168 - goto error; 169 174 } 170 175 171 - out_free: 172 - kfree(dn); 173 176 out: 174 - SetPageUptodate(page); 175 - ClearPageError(page); 176 - flush_dcache_page(page); 177 - kunmap(page); 178 - return 0; 179 - 180 - error: 181 177 kfree(dn); 182 - ClearPageUptodate(page); 183 - SetPageError(page); 184 - flush_dcache_page(page); 185 - kunmap(page); 178 + if (!err) 179 + folio_mark_uptodate(folio); 180 + flush_dcache_folio(folio); 181 + kunmap_local(addr); 186 182 return err; 187 183 } 188 184 ··· 218 222 pgoff_t index = pos >> PAGE_SHIFT; 219 223 struct ubifs_budget_req req = { .new_page = 1 }; 220 224 int err, appending = !!(pos + len > inode->i_size); 221 - struct page *page; 225 + struct folio *folio; 222 226 223 227 dbg_gen("ino %lu, pos %llu, len %u, i_size %lld", 224 228 inode->i_ino, pos, len, inode->i_size); 225 229 226 230 /* 227 - * At the slow path we have to budget before locking the page, because 228 - * budgeting may force write-back, which would wait on locked pages and 229 - * deadlock if we had the page locked. At this point we do not know 230 - * anything about the page, so assume that this is a new page which is 231 + * At the slow path we have to budget before locking the folio, because 232 + * budgeting may force write-back, which would wait on locked folios and 233 + * deadlock if we had the folio locked. At this point we do not know 234 + * anything about the folio, so assume that this is a new folio which is 231 235 * written to a hole. This corresponds to largest budget. Later the 232 236 * budget will be amended if this is not true. 233 237 */ ··· 239 243 if (unlikely(err)) 240 244 return err; 241 245 242 - page = grab_cache_page_write_begin(mapping, index); 243 - if (unlikely(!page)) { 246 + folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, 247 + mapping_gfp_mask(mapping)); 248 + if (IS_ERR(folio)) { 244 249 ubifs_release_budget(c, &req); 245 - return -ENOMEM; 250 + return PTR_ERR(folio); 246 251 } 247 252 248 - if (!PageUptodate(page)) { 249 - if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE) 250 - SetPageChecked(page); 253 + if (!folio_test_uptodate(folio)) { 254 + if (pos == folio_pos(folio) && len >= folio_size(folio)) 255 + folio_set_checked(folio); 251 256 else { 252 - err = do_readpage(page); 257 + err = do_readpage(folio); 253 258 if (err) { 254 - unlock_page(page); 255 - put_page(page); 259 + folio_unlock(folio); 260 + folio_put(folio); 256 261 ubifs_release_budget(c, &req); 257 262 return err; 258 263 } 259 264 } 260 - 261 - SetPageUptodate(page); 262 - ClearPageError(page); 263 265 } 264 266 265 - if (PagePrivate(page)) 267 + if (folio->private) 266 268 /* 267 - * The page is dirty, which means it was budgeted twice: 269 + * The folio is dirty, which means it was budgeted twice: 268 270 * o first time the budget was allocated by the task which 269 - * made the page dirty and set the PG_private flag; 271 + * made the folio dirty and set the private field; 270 272 * o and then we budgeted for it for the second time at the 271 273 * very beginning of this function. 272 274 * 273 - * So what we have to do is to release the page budget we 275 + * So what we have to do is to release the folio budget we 274 276 * allocated. 275 277 */ 276 278 release_new_page_budget(c); 277 - else if (!PageChecked(page)) 279 + else if (!folio_test_checked(folio)) 278 280 /* 279 - * We are changing a page which already exists on the media. 280 - * This means that changing the page does not make the amount 281 + * We are changing a folio which already exists on the media. 282 + * This means that changing the folio does not make the amount 281 283 * of indexing information larger, and this part of the budget 282 284 * which we have already acquired may be released. 283 285 */ ··· 298 304 ubifs_release_dirty_inode_budget(c, ui); 299 305 } 300 306 301 - *pagep = page; 307 + *pagep = &folio->page; 302 308 return 0; 303 309 } 304 310 305 311 /** 306 312 * allocate_budget - allocate budget for 'ubifs_write_begin()'. 307 313 * @c: UBIFS file-system description object 308 - * @page: page to allocate budget for 314 + * @folio: folio to allocate budget for 309 315 * @ui: UBIFS inode object the page belongs to 310 316 * @appending: non-zero if the page is appended 311 317 * ··· 316 322 * 317 323 * Returns: %0 in case of success and %-ENOSPC in case of failure. 318 324 */ 319 - static int allocate_budget(struct ubifs_info *c, struct page *page, 325 + static int allocate_budget(struct ubifs_info *c, struct folio *folio, 320 326 struct ubifs_inode *ui, int appending) 321 327 { 322 328 struct ubifs_budget_req req = { .fast = 1 }; 323 329 324 - if (PagePrivate(page)) { 330 + if (folio->private) { 325 331 if (!appending) 326 332 /* 327 - * The page is dirty and we are not appending, which 333 + * The folio is dirty and we are not appending, which 328 334 * means no budget is needed at all. 329 335 */ 330 336 return 0; ··· 348 354 */ 349 355 req.dirtied_ino = 1; 350 356 } else { 351 - if (PageChecked(page)) 357 + if (folio_test_checked(folio)) 352 358 /* 353 359 * The page corresponds to a hole and does not 354 360 * exist on the media. So changing it makes 355 - * make the amount of indexing information 361 + * the amount of indexing information 356 362 * larger, and we have to budget for a new 357 363 * page. 358 364 */ ··· 422 428 pgoff_t index = pos >> PAGE_SHIFT; 423 429 int err, appending = !!(pos + len > inode->i_size); 424 430 int skipped_read = 0; 425 - struct page *page; 431 + struct folio *folio; 426 432 427 433 ubifs_assert(c, ubifs_inode(inode)->ui_size == inode->i_size); 428 434 ubifs_assert(c, !c->ro_media && !c->ro_mount); ··· 431 437 return -EROFS; 432 438 433 439 /* Try out the fast-path part first */ 434 - page = grab_cache_page_write_begin(mapping, index); 435 - if (unlikely(!page)) 436 - return -ENOMEM; 440 + folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, 441 + mapping_gfp_mask(mapping)); 442 + if (IS_ERR(folio)) 443 + return PTR_ERR(folio); 437 444 438 - if (!PageUptodate(page)) { 445 + if (!folio_test_uptodate(folio)) { 439 446 /* The page is not loaded from the flash */ 440 - if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE) { 447 + if (pos == folio_pos(folio) && len >= folio_size(folio)) { 441 448 /* 442 449 * We change whole page so no need to load it. But we 443 450 * do not know whether this page exists on the media or ··· 448 453 * media. Thus, we are setting the @PG_checked flag 449 454 * here. 450 455 */ 451 - SetPageChecked(page); 456 + folio_set_checked(folio); 452 457 skipped_read = 1; 453 458 } else { 454 - err = do_readpage(page); 459 + err = do_readpage(folio); 455 460 if (err) { 456 - unlock_page(page); 457 - put_page(page); 461 + folio_unlock(folio); 462 + folio_put(folio); 458 463 return err; 459 464 } 460 465 } 461 - 462 - SetPageUptodate(page); 463 - ClearPageError(page); 464 466 } 465 467 466 - err = allocate_budget(c, page, ui, appending); 468 + err = allocate_budget(c, folio, ui, appending); 467 469 if (unlikely(err)) { 468 470 ubifs_assert(c, err == -ENOSPC); 469 471 /* 470 472 * If we skipped reading the page because we were going to 471 473 * write all of it, then it is not up to date. 472 474 */ 473 - if (skipped_read) { 474 - ClearPageChecked(page); 475 - ClearPageUptodate(page); 476 - } 475 + if (skipped_read) 476 + folio_clear_checked(folio); 477 477 /* 478 478 * Budgeting failed which means it would have to force 479 479 * write-back but didn't, because we set the @fast flag in the ··· 480 490 ubifs_assert(c, mutex_is_locked(&ui->ui_mutex)); 481 491 mutex_unlock(&ui->ui_mutex); 482 492 } 483 - unlock_page(page); 484 - put_page(page); 493 + folio_unlock(folio); 494 + folio_put(folio); 485 495 486 496 return write_begin_slow(mapping, pos, len, pagep); 487 497 } ··· 492 502 * with @ui->ui_mutex locked if we are appending pages, and unlocked 493 503 * otherwise. This is an optimization (slightly hacky though). 494 504 */ 495 - *pagep = page; 505 + *pagep = &folio->page; 496 506 return 0; 497 - 498 507 } 499 508 500 509 /** 501 510 * cancel_budget - cancel budget. 502 511 * @c: UBIFS file-system description object 503 - * @page: page to cancel budget for 512 + * @folio: folio to cancel budget for 504 513 * @ui: UBIFS inode object the page belongs to 505 514 * @appending: non-zero if the page is appended 506 515 * 507 516 * This is a helper function for a page write operation. It unlocks the 508 517 * @ui->ui_mutex in case of appending. 509 518 */ 510 - static void cancel_budget(struct ubifs_info *c, struct page *page, 519 + static void cancel_budget(struct ubifs_info *c, struct folio *folio, 511 520 struct ubifs_inode *ui, int appending) 512 521 { 513 522 if (appending) { ··· 514 525 ubifs_release_dirty_inode_budget(c, ui); 515 526 mutex_unlock(&ui->ui_mutex); 516 527 } 517 - if (!PagePrivate(page)) { 518 - if (PageChecked(page)) 528 + if (!folio->private) { 529 + if (folio_test_checked(folio)) 519 530 release_new_page_budget(c); 520 531 else 521 532 release_existing_page_budget(c); ··· 526 537 loff_t pos, unsigned len, unsigned copied, 527 538 struct page *page, void *fsdata) 528 539 { 540 + struct folio *folio = page_folio(page); 529 541 struct inode *inode = mapping->host; 530 542 struct ubifs_inode *ui = ubifs_inode(inode); 531 543 struct ubifs_info *c = inode->i_sb->s_fs_info; ··· 534 544 int appending = !!(end_pos > inode->i_size); 535 545 536 546 dbg_gen("ino %lu, pos %llu, pg %lu, len %u, copied %d, i_size %lld", 537 - inode->i_ino, pos, page->index, len, copied, inode->i_size); 547 + inode->i_ino, pos, folio->index, len, copied, inode->i_size); 538 548 539 - if (unlikely(copied < len && len == PAGE_SIZE)) { 549 + if (unlikely(copied < len && !folio_test_uptodate(folio))) { 540 550 /* 541 - * VFS copied less data to the page that it intended and 551 + * VFS copied less data to the folio than it intended and 542 552 * declared in its '->write_begin()' call via the @len 543 - * argument. If the page was not up-to-date, and @len was 544 - * @PAGE_SIZE, the 'ubifs_write_begin()' function did 553 + * argument. If the folio was not up-to-date, 554 + * the 'ubifs_write_begin()' function did 545 555 * not load it from the media (for optimization reasons). This 546 - * means that part of the page contains garbage. So read the 547 - * page now. 556 + * means that part of the folio contains garbage. So read the 557 + * folio now. 548 558 */ 549 559 dbg_gen("copied %d instead of %d, read page and repeat", 550 560 copied, len); 551 - cancel_budget(c, page, ui, appending); 552 - ClearPageChecked(page); 561 + cancel_budget(c, folio, ui, appending); 562 + folio_clear_checked(folio); 553 563 554 564 /* 555 565 * Return 0 to force VFS to repeat the whole operation, or the 556 566 * error code if 'do_readpage()' fails. 557 567 */ 558 - copied = do_readpage(page); 568 + copied = do_readpage(folio); 559 569 goto out; 560 570 } 561 571 562 - if (!PagePrivate(page)) { 563 - attach_page_private(page, (void *)1); 572 + if (len == folio_size(folio)) 573 + folio_mark_uptodate(folio); 574 + 575 + if (!folio->private) { 576 + folio_attach_private(folio, (void *)1); 564 577 atomic_long_inc(&c->dirty_pg_cnt); 565 - __set_page_dirty_nobuffers(page); 578 + filemap_dirty_folio(mapping, folio); 566 579 } 567 580 568 581 if (appending) { 569 582 i_size_write(inode, end_pos); 570 583 ui->ui_size = end_pos; 571 584 /* 572 - * Note, we do not set @I_DIRTY_PAGES (which means that the 573 - * inode has dirty pages), this has been done in 574 - * '__set_page_dirty_nobuffers()'. 585 + * We do not set @I_DIRTY_PAGES (which means that 586 + * the inode has dirty pages), this was done in 587 + * filemap_dirty_folio(). 575 588 */ 576 589 __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 577 590 ubifs_assert(c, mutex_is_locked(&ui->ui_mutex)); ··· 582 589 } 583 590 584 591 out: 585 - unlock_page(page); 586 - put_page(page); 592 + folio_unlock(folio); 593 + folio_put(folio); 587 594 return copied; 588 595 } 589 596 590 597 /** 591 598 * populate_page - copy data nodes into a page for bulk-read. 592 599 * @c: UBIFS file-system description object 593 - * @page: page 600 + * @folio: folio 594 601 * @bu: bulk-read information 595 602 * @n: next zbranch slot 596 603 * 597 604 * Returns: %0 on success and a negative error code on failure. 598 605 */ 599 - static int populate_page(struct ubifs_info *c, struct page *page, 606 + static int populate_page(struct ubifs_info *c, struct folio *folio, 600 607 struct bu_info *bu, int *n) 601 608 { 602 609 int i = 0, nn = *n, offs = bu->zbranch[0].offs, hole = 0, read = 0; 603 - struct inode *inode = page->mapping->host; 610 + struct inode *inode = folio->mapping->host; 604 611 loff_t i_size = i_size_read(inode); 605 612 unsigned int page_block; 606 613 void *addr, *zaddr; 607 614 pgoff_t end_index; 608 615 609 616 dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx", 610 - inode->i_ino, page->index, i_size, page->flags); 617 + inode->i_ino, folio->index, i_size, folio->flags); 611 618 612 - addr = zaddr = kmap(page); 619 + addr = zaddr = kmap_local_folio(folio, 0); 613 620 614 621 end_index = (i_size - 1) >> PAGE_SHIFT; 615 - if (!i_size || page->index > end_index) { 622 + if (!i_size || folio->index > end_index) { 616 623 hole = 1; 617 - memset(addr, 0, PAGE_SIZE); 624 + addr = folio_zero_tail(folio, 0, addr); 618 625 goto out_hole; 619 626 } 620 627 621 - page_block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; 628 + page_block = folio->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; 622 629 while (1) { 623 630 int err, len, out_len, dlen; 624 631 ··· 667 674 break; 668 675 addr += UBIFS_BLOCK_SIZE; 669 676 page_block += 1; 677 + if (folio_test_highmem(folio) && (offset_in_page(addr) == 0)) { 678 + kunmap_local(addr - UBIFS_BLOCK_SIZE); 679 + addr = kmap_local_folio(folio, i * UBIFS_BLOCK_SIZE); 680 + } 670 681 } 671 682 672 - if (end_index == page->index) { 683 + if (end_index == folio->index) { 673 684 int len = i_size & (PAGE_SIZE - 1); 674 685 675 686 if (len && len < read) ··· 682 685 683 686 out_hole: 684 687 if (hole) { 685 - SetPageChecked(page); 688 + folio_set_checked(folio); 686 689 dbg_gen("hole"); 687 690 } 688 691 689 - SetPageUptodate(page); 690 - ClearPageError(page); 691 - flush_dcache_page(page); 692 - kunmap(page); 692 + folio_mark_uptodate(folio); 693 + flush_dcache_folio(folio); 694 + kunmap_local(addr); 693 695 *n = nn; 694 696 return 0; 695 697 696 698 out_err: 697 - ClearPageUptodate(page); 698 - SetPageError(page); 699 - flush_dcache_page(page); 700 - kunmap(page); 699 + flush_dcache_folio(folio); 700 + kunmap_local(addr); 701 701 ubifs_err(c, "bad data node (block %u, inode %lu)", 702 702 page_block, inode->i_ino); 703 703 return -EINVAL; ··· 704 710 * ubifs_do_bulk_read - do bulk-read. 705 711 * @c: UBIFS file-system description object 706 712 * @bu: bulk-read information 707 - * @page1: first page to read 713 + * @folio1: first folio to read 708 714 * 709 715 * Returns: %1 if the bulk-read is done, otherwise %0 is returned. 710 716 */ 711 717 static int ubifs_do_bulk_read(struct ubifs_info *c, struct bu_info *bu, 712 - struct page *page1) 718 + struct folio *folio1) 713 719 { 714 - pgoff_t offset = page1->index, end_index; 715 - struct address_space *mapping = page1->mapping; 720 + pgoff_t offset = folio1->index, end_index; 721 + struct address_space *mapping = folio1->mapping; 716 722 struct inode *inode = mapping->host; 717 723 struct ubifs_inode *ui = ubifs_inode(inode); 718 724 int err, page_idx, page_cnt, ret = 0, n = 0; ··· 762 768 goto out_warn; 763 769 } 764 770 765 - err = populate_page(c, page1, bu, &n); 771 + err = populate_page(c, folio1, bu, &n); 766 772 if (err) 767 773 goto out_warn; 768 774 769 - unlock_page(page1); 775 + folio_unlock(folio1); 770 776 ret = 1; 771 777 772 778 isize = i_size_read(inode); ··· 776 782 777 783 for (page_idx = 1; page_idx < page_cnt; page_idx++) { 778 784 pgoff_t page_offset = offset + page_idx; 779 - struct page *page; 785 + struct folio *folio; 780 786 781 787 if (page_offset > end_index) 782 788 break; 783 - page = pagecache_get_page(mapping, page_offset, 789 + folio = __filemap_get_folio(mapping, page_offset, 784 790 FGP_LOCK|FGP_ACCESSED|FGP_CREAT|FGP_NOWAIT, 785 791 ra_gfp_mask); 786 - if (!page) 792 + if (IS_ERR(folio)) 787 793 break; 788 - if (!PageUptodate(page)) 789 - err = populate_page(c, page, bu, &n); 790 - unlock_page(page); 791 - put_page(page); 794 + if (!folio_test_uptodate(folio)) 795 + err = populate_page(c, folio, bu, &n); 796 + folio_unlock(folio); 797 + folio_put(folio); 792 798 if (err) 793 799 break; 794 800 } ··· 811 817 812 818 /** 813 819 * ubifs_bulk_read - determine whether to bulk-read and, if so, do it. 814 - * @page: page from which to start bulk-read. 820 + * @folio: folio from which to start bulk-read. 815 821 * 816 822 * Some flash media are capable of reading sequentially at faster rates. UBIFS 817 823 * bulk-read facility is designed to take advantage of that, by reading in one ··· 820 826 * 821 827 * Returns: %1 if a bulk-read is done and %0 otherwise. 822 828 */ 823 - static int ubifs_bulk_read(struct page *page) 829 + static int ubifs_bulk_read(struct folio *folio) 824 830 { 825 - struct inode *inode = page->mapping->host; 831 + struct inode *inode = folio->mapping->host; 826 832 struct ubifs_info *c = inode->i_sb->s_fs_info; 827 833 struct ubifs_inode *ui = ubifs_inode(inode); 828 - pgoff_t index = page->index, last_page_read = ui->last_page_read; 834 + pgoff_t index = folio->index, last_page_read = ui->last_page_read; 829 835 struct bu_info *bu; 830 836 int err = 0, allocated = 0; 831 837 ··· 873 879 874 880 bu->buf_len = c->max_bu_buf_len; 875 881 data_key_init(c, &bu->key, inode->i_ino, 876 - page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT); 877 - err = ubifs_do_bulk_read(c, bu, page); 882 + folio->index << UBIFS_BLOCKS_PER_PAGE_SHIFT); 883 + err = ubifs_do_bulk_read(c, bu, folio); 878 884 879 885 if (!allocated) 880 886 mutex_unlock(&c->bu_mutex); ··· 888 894 889 895 static int ubifs_read_folio(struct file *file, struct folio *folio) 890 896 { 891 - struct page *page = &folio->page; 892 - 893 - if (ubifs_bulk_read(page)) 897 + if (ubifs_bulk_read(folio)) 894 898 return 0; 895 - do_readpage(page); 899 + do_readpage(folio); 896 900 folio_unlock(folio); 897 901 return 0; 898 902 } 899 903 900 - static int do_writepage(struct page *page, int len) 904 + static int do_writepage(struct folio *folio, size_t len) 901 905 { 902 - int err = 0, i, blen; 906 + int err = 0, blen; 903 907 unsigned int block; 904 908 void *addr; 909 + size_t offset = 0; 905 910 union ubifs_key key; 906 - struct inode *inode = page->mapping->host; 911 + struct inode *inode = folio->mapping->host; 907 912 struct ubifs_info *c = inode->i_sb->s_fs_info; 908 913 909 914 #ifdef UBIFS_DEBUG 910 915 struct ubifs_inode *ui = ubifs_inode(inode); 911 916 spin_lock(&ui->ui_lock); 912 - ubifs_assert(c, page->index <= ui->synced_i_size >> PAGE_SHIFT); 917 + ubifs_assert(c, folio->index <= ui->synced_i_size >> PAGE_SHIFT); 913 918 spin_unlock(&ui->ui_lock); 914 919 #endif 915 920 916 - /* Update radix tree tags */ 917 - set_page_writeback(page); 921 + folio_start_writeback(folio); 918 922 919 - addr = kmap(page); 920 - block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; 921 - i = 0; 922 - while (len) { 923 - blen = min_t(int, len, UBIFS_BLOCK_SIZE); 923 + addr = kmap_local_folio(folio, offset); 924 + block = folio->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; 925 + for (;;) { 926 + blen = min_t(size_t, len, UBIFS_BLOCK_SIZE); 924 927 data_key_init(c, &key, inode->i_ino, block); 925 928 err = ubifs_jnl_write_data(c, inode, &key, addr, blen); 926 929 if (err) 927 930 break; 928 - if (++i >= UBIFS_BLOCKS_PER_PAGE) 931 + len -= blen; 932 + if (!len) 929 933 break; 930 934 block += 1; 931 935 addr += blen; 932 - len -= blen; 936 + if (folio_test_highmem(folio) && !offset_in_page(addr)) { 937 + kunmap_local(addr - blen); 938 + offset += PAGE_SIZE; 939 + addr = kmap_local_folio(folio, offset); 940 + } 933 941 } 942 + kunmap_local(addr); 934 943 if (err) { 935 - SetPageError(page); 936 - ubifs_err(c, "cannot write page %lu of inode %lu, error %d", 937 - page->index, inode->i_ino, err); 944 + mapping_set_error(folio->mapping, err); 945 + ubifs_err(c, "cannot write folio %lu of inode %lu, error %d", 946 + folio->index, inode->i_ino, err); 938 947 ubifs_ro_mode(c, err); 939 948 } 940 949 941 - ubifs_assert(c, PagePrivate(page)); 942 - if (PageChecked(page)) 950 + ubifs_assert(c, folio->private != NULL); 951 + if (folio_test_checked(folio)) 943 952 release_new_page_budget(c); 944 953 else 945 954 release_existing_page_budget(c); 946 955 947 956 atomic_long_dec(&c->dirty_pg_cnt); 948 - detach_page_private(page); 949 - ClearPageChecked(page); 957 + folio_detach_private(folio); 958 + folio_clear_checked(folio); 950 959 951 - kunmap(page); 952 - unlock_page(page); 953 - end_page_writeback(page); 960 + folio_unlock(folio); 961 + folio_end_writeback(folio); 954 962 return err; 955 963 } 956 964 ··· 1002 1006 * on the page lock and it would not write the truncated inode node to the 1003 1007 * journal before we have finished. 1004 1008 */ 1005 - static int ubifs_writepage(struct page *page, struct writeback_control *wbc) 1009 + static int ubifs_writepage(struct folio *folio, struct writeback_control *wbc, 1010 + void *data) 1006 1011 { 1007 - struct inode *inode = page->mapping->host; 1012 + struct inode *inode = folio->mapping->host; 1008 1013 struct ubifs_info *c = inode->i_sb->s_fs_info; 1009 1014 struct ubifs_inode *ui = ubifs_inode(inode); 1010 1015 loff_t i_size = i_size_read(inode), synced_i_size; 1011 - pgoff_t end_index = i_size >> PAGE_SHIFT; 1012 - int err, len = i_size & (PAGE_SIZE - 1); 1013 - void *kaddr; 1016 + int err, len = folio_size(folio); 1014 1017 1015 1018 dbg_gen("ino %lu, pg %lu, pg flags %#lx", 1016 - inode->i_ino, page->index, page->flags); 1017 - ubifs_assert(c, PagePrivate(page)); 1019 + inode->i_ino, folio->index, folio->flags); 1020 + ubifs_assert(c, folio->private != NULL); 1018 1021 1019 - /* Is the page fully outside @i_size? (truncate in progress) */ 1020 - if (page->index > end_index || (page->index == end_index && !len)) { 1022 + /* Is the folio fully outside @i_size? (truncate in progress) */ 1023 + if (folio_pos(folio) >= i_size) { 1021 1024 err = 0; 1022 1025 goto out_unlock; 1023 1026 } ··· 1025 1030 synced_i_size = ui->synced_i_size; 1026 1031 spin_unlock(&ui->ui_lock); 1027 1032 1028 - /* Is the page fully inside @i_size? */ 1029 - if (page->index < end_index) { 1030 - if (page->index >= synced_i_size >> PAGE_SHIFT) { 1033 + /* Is the folio fully inside i_size? */ 1034 + if (folio_pos(folio) + len <= i_size) { 1035 + if (folio_pos(folio) >= synced_i_size) { 1031 1036 err = inode->i_sb->s_op->write_inode(inode, NULL); 1032 1037 if (err) 1033 1038 goto out_redirty; ··· 1040 1045 * with this. 1041 1046 */ 1042 1047 } 1043 - return do_writepage(page, PAGE_SIZE); 1048 + return do_writepage(folio, len); 1044 1049 } 1045 1050 1046 1051 /* 1047 - * The page straddles @i_size. It must be zeroed out on each and every 1052 + * The folio straddles @i_size. It must be zeroed out on each and every 1048 1053 * writepage invocation because it may be mmapped. "A file is mapped 1049 1054 * in multiples of the page size. For a file that is not a multiple of 1050 1055 * the page size, the remaining memory is zeroed when mapped, and 1051 1056 * writes to that region are not written out to the file." 1052 1057 */ 1053 - kaddr = kmap_atomic(page); 1054 - memset(kaddr + len, 0, PAGE_SIZE - len); 1055 - flush_dcache_page(page); 1056 - kunmap_atomic(kaddr); 1058 + len = i_size - folio_pos(folio); 1059 + folio_zero_segment(folio, len, folio_size(folio)); 1057 1060 1058 1061 if (i_size > synced_i_size) { 1059 1062 err = inode->i_sb->s_op->write_inode(inode, NULL); ··· 1059 1066 goto out_redirty; 1060 1067 } 1061 1068 1062 - return do_writepage(page, len); 1069 + return do_writepage(folio, len); 1063 1070 out_redirty: 1064 1071 /* 1065 - * redirty_page_for_writepage() won't call ubifs_dirty_inode() because 1072 + * folio_redirty_for_writepage() won't call ubifs_dirty_inode() because 1066 1073 * it passes I_DIRTY_PAGES flag while calling __mark_inode_dirty(), so 1067 1074 * there is no need to do space budget for dirty inode. 1068 1075 */ 1069 - redirty_page_for_writepage(wbc, page); 1076 + folio_redirty_for_writepage(wbc, folio); 1070 1077 out_unlock: 1071 - unlock_page(page); 1078 + folio_unlock(folio); 1072 1079 return err; 1080 + } 1081 + 1082 + static int ubifs_writepages(struct address_space *mapping, 1083 + struct writeback_control *wbc) 1084 + { 1085 + return write_cache_pages(mapping, wbc, ubifs_writepage, NULL); 1073 1086 } 1074 1087 1075 1088 /** ··· 1154 1155 1155 1156 if (offset) { 1156 1157 pgoff_t index = new_size >> PAGE_SHIFT; 1157 - struct page *page; 1158 + struct folio *folio; 1158 1159 1159 - page = find_lock_page(inode->i_mapping, index); 1160 - if (page) { 1161 - if (PageDirty(page)) { 1160 + folio = filemap_lock_folio(inode->i_mapping, index); 1161 + if (!IS_ERR(folio)) { 1162 + if (folio_test_dirty(folio)) { 1162 1163 /* 1163 1164 * 'ubifs_jnl_truncate()' will try to truncate 1164 1165 * the last data node, but it contains ··· 1167 1168 * 'ubifs_jnl_truncate()' will see an already 1168 1169 * truncated (and up to date) data node. 1169 1170 */ 1170 - ubifs_assert(c, PagePrivate(page)); 1171 + ubifs_assert(c, folio->private != NULL); 1171 1172 1172 - clear_page_dirty_for_io(page); 1173 + folio_clear_dirty_for_io(folio); 1173 1174 if (UBIFS_BLOCKS_PER_PAGE_SHIFT) 1174 - offset = new_size & 1175 - (PAGE_SIZE - 1); 1176 - err = do_writepage(page, offset); 1177 - put_page(page); 1175 + offset = offset_in_folio(folio, 1176 + new_size); 1177 + err = do_writepage(folio, offset); 1178 + folio_put(folio); 1178 1179 if (err) 1179 1180 goto out_budg; 1180 1181 /* ··· 1187 1188 * to 'ubifs_jnl_truncate()' to save it from 1188 1189 * having to read it. 1189 1190 */ 1190 - unlock_page(page); 1191 - put_page(page); 1191 + folio_unlock(folio); 1192 + folio_put(folio); 1192 1193 } 1193 1194 } 1194 1195 } ··· 1511 1512 */ 1512 1513 static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf) 1513 1514 { 1514 - struct page *page = vmf->page; 1515 + struct folio *folio = page_folio(vmf->page); 1515 1516 struct inode *inode = file_inode(vmf->vma->vm_file); 1516 1517 struct ubifs_info *c = inode->i_sb->s_fs_info; 1517 1518 struct timespec64 now = current_time(inode); 1518 1519 struct ubifs_budget_req req = { .new_page = 1 }; 1519 1520 int err, update_time; 1520 1521 1521 - dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, page->index, 1522 + dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, folio->index, 1522 1523 i_size_read(inode)); 1523 1524 ubifs_assert(c, !c->ro_media && !c->ro_mount); 1524 1525 ··· 1526 1527 return VM_FAULT_SIGBUS; /* -EROFS */ 1527 1528 1528 1529 /* 1529 - * We have not locked @page so far so we may budget for changing the 1530 - * page. Note, we cannot do this after we locked the page, because 1530 + * We have not locked @folio so far so we may budget for changing the 1531 + * folio. Note, we cannot do this after we locked the folio, because 1531 1532 * budgeting may cause write-back which would cause deadlock. 1532 1533 * 1533 - * At the moment we do not know whether the page is dirty or not, so we 1534 - * assume that it is not and budget for a new page. We could look at 1534 + * At the moment we do not know whether the folio is dirty or not, so we 1535 + * assume that it is not and budget for a new folio. We could look at 1535 1536 * the @PG_private flag and figure this out, but we may race with write 1536 - * back and the page state may change by the time we lock it, so this 1537 + * back and the folio state may change by the time we lock it, so this 1537 1538 * would need additional care. We do not bother with this at the 1538 1539 * moment, although it might be good idea to do. Instead, we allocate 1539 - * budget for a new page and amend it later on if the page was in fact 1540 + * budget for a new folio and amend it later on if the folio was in fact 1540 1541 * dirty. 1541 1542 * 1542 1543 * The budgeting-related logic of this function is similar to what we ··· 1559 1560 return VM_FAULT_SIGBUS; 1560 1561 } 1561 1562 1562 - lock_page(page); 1563 - if (unlikely(page->mapping != inode->i_mapping || 1564 - page_offset(page) > i_size_read(inode))) { 1565 - /* Page got truncated out from underneath us */ 1563 + folio_lock(folio); 1564 + if (unlikely(folio->mapping != inode->i_mapping || 1565 + folio_pos(folio) >= i_size_read(inode))) { 1566 + /* Folio got truncated out from underneath us */ 1566 1567 goto sigbus; 1567 1568 } 1568 1569 1569 - if (PagePrivate(page)) 1570 + if (folio->private) 1570 1571 release_new_page_budget(c); 1571 1572 else { 1572 - if (!PageChecked(page)) 1573 + if (!folio_test_checked(folio)) 1573 1574 ubifs_convert_page_budget(c); 1574 - attach_page_private(page, (void *)1); 1575 + folio_attach_private(folio, (void *)1); 1575 1576 atomic_long_inc(&c->dirty_pg_cnt); 1576 - __set_page_dirty_nobuffers(page); 1577 + filemap_dirty_folio(folio->mapping, folio); 1577 1578 } 1578 1579 1579 1580 if (update_time) { ··· 1589 1590 ubifs_release_dirty_inode_budget(c, ui); 1590 1591 } 1591 1592 1592 - wait_for_stable_page(page); 1593 + folio_wait_stable(folio); 1593 1594 return VM_FAULT_LOCKED; 1594 1595 1595 1596 sigbus: 1596 - unlock_page(page); 1597 + folio_unlock(folio); 1597 1598 ubifs_release_budget(c, &req); 1598 1599 return VM_FAULT_SIGBUS; 1599 1600 } ··· 1647 1648 1648 1649 const struct address_space_operations ubifs_file_address_operations = { 1649 1650 .read_folio = ubifs_read_folio, 1650 - .writepage = ubifs_writepage, 1651 + .writepages = ubifs_writepages, 1651 1652 .write_begin = ubifs_write_begin, 1652 1653 .write_end = ubifs_write_end, 1653 1654 .invalidate_folio = ubifs_invalidate_folio,
+16 -16
fs/ubifs/find.c
··· 82 82 */ 83 83 static int scan_for_dirty_cb(struct ubifs_info *c, 84 84 const struct ubifs_lprops *lprops, int in_tree, 85 - struct scan_data *data) 85 + void *arg) 86 86 { 87 + struct scan_data *data = arg; 87 88 int ret = LPT_SCAN_CONTINUE; 88 89 89 90 /* Exclude LEBs that are currently in use */ ··· 167 166 data.pick_free = pick_free; 168 167 data.lnum = -1; 169 168 data.exclude_index = exclude_index; 170 - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, 171 - (ubifs_lpt_scan_callback)scan_for_dirty_cb, 169 + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_for_dirty_cb, 172 170 &data); 173 171 if (err) 174 172 return ERR_PTR(err); ··· 349 349 */ 350 350 static int scan_for_free_cb(struct ubifs_info *c, 351 351 const struct ubifs_lprops *lprops, int in_tree, 352 - struct scan_data *data) 352 + void *arg) 353 353 { 354 + struct scan_data *data = arg; 354 355 int ret = LPT_SCAN_CONTINUE; 355 356 356 357 /* Exclude LEBs that are currently in use */ ··· 447 446 data.pick_free = pick_free; 448 447 data.lnum = -1; 449 448 err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, 450 - (ubifs_lpt_scan_callback)scan_for_free_cb, 449 + scan_for_free_cb, 451 450 &data); 452 451 if (err) 453 452 return ERR_PTR(err); ··· 590 589 */ 591 590 static int scan_for_idx_cb(struct ubifs_info *c, 592 591 const struct ubifs_lprops *lprops, int in_tree, 593 - struct scan_data *data) 592 + void *arg) 594 593 { 594 + struct scan_data *data = arg; 595 595 int ret = LPT_SCAN_CONTINUE; 596 596 597 597 /* Exclude LEBs that are currently in use */ ··· 627 625 int err; 628 626 629 627 data.lnum = -1; 630 - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, 631 - (ubifs_lpt_scan_callback)scan_for_idx_cb, 628 + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_for_idx_cb, 632 629 &data); 633 630 if (err) 634 631 return ERR_PTR(err); ··· 727 726 return err; 728 727 } 729 728 730 - static int cmp_dirty_idx(const struct ubifs_lprops **a, 731 - const struct ubifs_lprops **b) 729 + static int cmp_dirty_idx(const void *a, const void *b) 732 730 { 733 - const struct ubifs_lprops *lpa = *a; 734 - const struct ubifs_lprops *lpb = *b; 731 + const struct ubifs_lprops *lpa = *(const struct ubifs_lprops **)a; 732 + const struct ubifs_lprops *lpb = *(const struct ubifs_lprops **)b; 735 733 736 734 return lpa->dirty + lpa->free - lpb->dirty - lpb->free; 737 735 } ··· 754 754 sizeof(void *) * c->dirty_idx.cnt); 755 755 /* Sort it so that the dirtiest is now at the end */ 756 756 sort(c->dirty_idx.arr, c->dirty_idx.cnt, sizeof(void *), 757 - (int (*)(const void *, const void *))cmp_dirty_idx, NULL); 757 + cmp_dirty_idx, NULL); 758 758 dbg_find("found %d dirty index LEBs", c->dirty_idx.cnt); 759 759 if (c->dirty_idx.cnt) 760 760 dbg_find("dirtiest index LEB is %d with dirty %d and free %d", ··· 782 782 */ 783 783 static int scan_dirty_idx_cb(struct ubifs_info *c, 784 784 const struct ubifs_lprops *lprops, int in_tree, 785 - struct scan_data *data) 785 + void *arg) 786 786 { 787 + struct scan_data *data = arg; 787 788 int ret = LPT_SCAN_CONTINUE; 788 789 789 790 /* Exclude LEBs that are currently in use */ ··· 843 842 if (c->pnodes_have >= c->pnode_cnt) 844 843 /* All pnodes are in memory, so skip scan */ 845 844 return -ENOSPC; 846 - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, 847 - (ubifs_lpt_scan_callback)scan_dirty_idx_cb, 845 + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_dirty_idx_cb, 848 846 &data); 849 847 if (err) 850 848 return err;
+149 -22
fs/ubifs/journal.c
··· 293 293 } 294 294 295 295 /** 296 + * __queue_and_wait - queue a task and wait until the task is waked up. 297 + * @c: UBIFS file-system description object 298 + * 299 + * This function adds current task in queue and waits until the task is waked 300 + * up. This function should be called with @c->reserve_space_wq locked. 301 + */ 302 + static void __queue_and_wait(struct ubifs_info *c) 303 + { 304 + DEFINE_WAIT(wait); 305 + 306 + __add_wait_queue_entry_tail_exclusive(&c->reserve_space_wq, &wait); 307 + set_current_state(TASK_UNINTERRUPTIBLE); 308 + spin_unlock(&c->reserve_space_wq.lock); 309 + 310 + schedule(); 311 + finish_wait(&c->reserve_space_wq, &wait); 312 + } 313 + 314 + /** 315 + * wait_for_reservation - try queuing current task to wait until waked up. 316 + * @c: UBIFS file-system description object 317 + * 318 + * This function queues current task to wait until waked up, if queuing is 319 + * started(@c->need_wait_space is not %0). Returns %true if current task is 320 + * added in queue, otherwise %false is returned. 321 + */ 322 + static bool wait_for_reservation(struct ubifs_info *c) 323 + { 324 + if (likely(atomic_read(&c->need_wait_space) == 0)) 325 + /* Quick path to check whether queuing is started. */ 326 + return false; 327 + 328 + spin_lock(&c->reserve_space_wq.lock); 329 + if (atomic_read(&c->need_wait_space) == 0) { 330 + /* Queuing is not started, don't queue current task. */ 331 + spin_unlock(&c->reserve_space_wq.lock); 332 + return false; 333 + } 334 + 335 + __queue_and_wait(c); 336 + return true; 337 + } 338 + 339 + /** 340 + * wake_up_reservation - wake up first task in queue or stop queuing. 341 + * @c: UBIFS file-system description object 342 + * 343 + * This function wakes up the first task in queue if it exists, or stops 344 + * queuing if no tasks in queue. 345 + */ 346 + static void wake_up_reservation(struct ubifs_info *c) 347 + { 348 + spin_lock(&c->reserve_space_wq.lock); 349 + if (waitqueue_active(&c->reserve_space_wq)) 350 + wake_up_locked(&c->reserve_space_wq); 351 + else 352 + /* 353 + * Compared with wait_for_reservation(), set @c->need_wait_space 354 + * under the protection of wait queue lock, which can avoid that 355 + * @c->need_wait_space is set to 0 after new task queued. 356 + */ 357 + atomic_set(&c->need_wait_space, 0); 358 + spin_unlock(&c->reserve_space_wq.lock); 359 + } 360 + 361 + /** 362 + * wake_up_reservation - add current task in queue or start queuing. 363 + * @c: UBIFS file-system description object 364 + * 365 + * This function starts queuing if queuing is not started, otherwise adds 366 + * current task in queue. 367 + */ 368 + static void add_or_start_queue(struct ubifs_info *c) 369 + { 370 + spin_lock(&c->reserve_space_wq.lock); 371 + if (atomic_cmpxchg(&c->need_wait_space, 0, 1) == 0) { 372 + /* Starts queuing, task can go on directly. */ 373 + spin_unlock(&c->reserve_space_wq.lock); 374 + return; 375 + } 376 + 377 + /* 378 + * There are at least two tasks have retried more than 32 times 379 + * at certain point, first task has started queuing, just queue 380 + * the left tasks. 381 + */ 382 + __queue_and_wait(c); 383 + } 384 + 385 + /** 296 386 * make_reservation - reserve journal space. 297 387 * @c: UBIFS file-system description object 298 388 * @jhead: journal head ··· 401 311 static int make_reservation(struct ubifs_info *c, int jhead, int len) 402 312 { 403 313 int err, cmt_retries = 0, nospc_retries = 0; 314 + bool blocked = wait_for_reservation(c); 404 315 405 316 again: 406 317 down_read(&c->commit_sem); 407 318 err = reserve_space(c, jhead, len); 408 - if (!err) 319 + if (!err) { 409 320 /* c->commit_sem will get released via finish_reservation(). */ 410 - return 0; 321 + goto out_wake_up; 322 + } 411 323 up_read(&c->commit_sem); 412 324 413 325 if (err == -ENOSPC) { 414 326 /* 415 327 * GC could not make any progress. We should try to commit 416 - * once because it could make some dirty space and GC would 417 - * make progress, so make the error -EAGAIN so that the below 328 + * because it could make some dirty space and GC would make 329 + * progress, so make the error -EAGAIN so that the below 418 330 * will commit and re-try. 419 331 */ 420 - if (nospc_retries++ < 2) { 421 - dbg_jnl("no space, retry"); 422 - err = -EAGAIN; 423 - } 424 - 425 - /* 426 - * This means that the budgeting is incorrect. We always have 427 - * to be able to write to the media, because all operations are 428 - * budgeted. Deletions are not budgeted, though, but we reserve 429 - * an extra LEB for them. 430 - */ 332 + nospc_retries++; 333 + dbg_jnl("no space, retry"); 334 + err = -EAGAIN; 431 335 } 432 336 433 337 if (err != -EAGAIN) ··· 433 349 */ 434 350 if (cmt_retries > 128) { 435 351 /* 436 - * This should not happen unless the journal size limitations 437 - * are too tough. 352 + * This should not happen unless: 353 + * 1. The journal size limitations are too tough. 354 + * 2. The budgeting is incorrect. We always have to be able to 355 + * write to the media, because all operations are budgeted. 356 + * Deletions are not budgeted, though, but we reserve an 357 + * extra LEB for them. 438 358 */ 439 - ubifs_err(c, "stuck in space allocation"); 359 + ubifs_err(c, "stuck in space allocation, nospc_retries %d", 360 + nospc_retries); 440 361 err = -ENOSPC; 441 362 goto out; 442 - } else if (cmt_retries > 32) 443 - ubifs_warn(c, "too many space allocation re-tries (%d)", 444 - cmt_retries); 363 + } else if (cmt_retries > 32) { 364 + /* 365 + * It's almost impossible to happen, unless there are many tasks 366 + * making reservation concurrently and someone task has retried 367 + * gc + commit for many times, generated available space during 368 + * this period are grabbed by other tasks. 369 + * But if it happens, start queuing up all tasks that will make 370 + * space reservation, then there is only one task making space 371 + * reservation at any time, and it can always make success under 372 + * the premise of correct budgeting. 373 + */ 374 + ubifs_warn(c, "too many space allocation cmt_retries (%d) " 375 + "nospc_retries (%d), start queuing tasks", 376 + cmt_retries, nospc_retries); 377 + 378 + if (!blocked) { 379 + blocked = true; 380 + add_or_start_queue(c); 381 + } 382 + } 445 383 446 384 dbg_jnl("-EAGAIN, commit and retry (retried %d times)", 447 385 cmt_retries); ··· 471 365 472 366 err = ubifs_run_commit(c); 473 367 if (err) 474 - return err; 368 + goto out_wake_up; 475 369 goto again; 476 370 477 371 out: ··· 485 379 ubifs_dump_lprops(c); 486 380 cmt_retries = dbg_check_lprops(c); 487 381 up_write(&c->commit_sem); 382 + } 383 + out_wake_up: 384 + if (blocked) { 385 + /* 386 + * Only tasks that have ever started queuing or ever been queued 387 + * can wake up other queued tasks, which can make sure that 388 + * there is only one task waked up to make space reservation. 389 + * For example: 390 + * task A task B task C 391 + * make_reservation make_reservation 392 + * reserve_space // 0 393 + * wake_up_reservation 394 + * atomic_cmpxchg // 0, start queuing 395 + * reserve_space 396 + * wait_for_reservation 397 + * __queue_and_wait 398 + * add_wait_queue 399 + * if (blocked) // false 400 + * // So that task C won't be waked up to race with task B 401 + */ 402 + wake_up_reservation(c); 488 403 } 489 404 return err; 490 405 }
+3 -3
fs/ubifs/lprops.c
··· 1014 1014 */ 1015 1015 static int scan_check_cb(struct ubifs_info *c, 1016 1016 const struct ubifs_lprops *lp, int in_tree, 1017 - struct ubifs_lp_stats *lst) 1017 + void *arg) 1018 1018 { 1019 + struct ubifs_lp_stats *lst = arg; 1019 1020 struct ubifs_scan_leb *sleb; 1020 1021 struct ubifs_scan_node *snod; 1021 1022 int cat, lnum = lp->lnum, is_idx = 0, used = 0, free, dirty, ret; ··· 1270 1269 1271 1270 memset(&lst, 0, sizeof(struct ubifs_lp_stats)); 1272 1271 err = ubifs_lpt_scan_nolock(c, c->main_first, c->leb_cnt - 1, 1273 - (ubifs_lpt_scan_callback)scan_check_cb, 1274 - &lst); 1272 + scan_check_cb, &lst); 1275 1273 if (err && err != -ENOSPC) 1276 1274 goto out; 1277 1275
-1
fs/ubifs/lpt_commit.c
··· 1646 1646 len -= node_len; 1647 1647 } 1648 1648 1649 - err = 0; 1650 1649 out: 1651 1650 vfree(buf); 1652 1651 return err;
+2
fs/ubifs/super.c
··· 2151 2151 mutex_init(&c->bu_mutex); 2152 2152 mutex_init(&c->write_reserve_mutex); 2153 2153 init_waitqueue_head(&c->cmt_wq); 2154 + init_waitqueue_head(&c->reserve_space_wq); 2155 + atomic_set(&c->need_wait_space, 0); 2154 2156 c->buds = RB_ROOT; 2155 2157 c->old_idx = RB_ROOT; 2156 2158 c->size_tree = RB_ROOT;
+1 -8
fs/ubifs/tnc.c
··· 3116 3116 void ubifs_tnc_close(struct ubifs_info *c) 3117 3117 { 3118 3118 tnc_destroy_cnext(c); 3119 - if (c->zroot.znode) { 3120 - long n, freed; 3121 - 3122 - n = atomic_long_read(&c->clean_zn_cnt); 3123 - freed = ubifs_destroy_tnc_subtree(c, c->zroot.znode); 3124 - ubifs_assert(c, freed == n); 3125 - atomic_long_sub(n, &ubifs_clean_zn_cnt); 3126 - } 3119 + ubifs_destroy_tnc_tree(c); 3127 3120 kfree(c->gap_lebs); 3128 3121 kfree(c->ilebs); 3129 3122 destroy_old_idx(c);
+22
fs/ubifs/tnc_misc.c
··· 251 251 } 252 252 253 253 /** 254 + * ubifs_destroy_tnc_tree - destroy all znodes connected to the TNC tree. 255 + * @c: UBIFS file-system description object 256 + * 257 + * This function destroys the whole TNC tree and updates clean global znode 258 + * count. 259 + */ 260 + void ubifs_destroy_tnc_tree(struct ubifs_info *c) 261 + { 262 + long n, freed; 263 + 264 + if (!c->zroot.znode) 265 + return; 266 + 267 + n = atomic_long_read(&c->clean_zn_cnt); 268 + freed = ubifs_destroy_tnc_subtree(c, c->zroot.znode); 269 + ubifs_assert(c, freed == n); 270 + atomic_long_sub(n, &ubifs_clean_zn_cnt); 271 + 272 + c->zroot.znode = NULL; 273 + } 274 + 275 + /** 254 276 * read_znode - read an indexing node from flash and fill znode. 255 277 * @c: UBIFS file-system description object 256 278 * @zzbr: the zbranch describing the node to read
+5
fs/ubifs/ubifs.h
··· 1047 1047 * @bg_bud_bytes: number of bud bytes when background commit is initiated 1048 1048 * @old_buds: buds to be released after commit ends 1049 1049 * @max_bud_cnt: maximum number of buds 1050 + * @need_wait_space: Non %0 means space reservation tasks need to wait in queue 1051 + * @reserve_space_wq: wait queue to sleep on if @need_wait_space is not %0 1050 1052 * 1051 1053 * @commit_sem: synchronizes committer with other processes 1052 1054 * @cmt_state: commit state ··· 1307 1305 long long bg_bud_bytes; 1308 1306 struct list_head old_buds; 1309 1307 int max_bud_cnt; 1308 + atomic_t need_wait_space; 1309 + wait_queue_head_t reserve_space_wq; 1310 1310 1311 1311 struct rw_semaphore commit_sem; 1312 1312 int cmt_state; ··· 1907 1903 struct ubifs_znode *znode); 1908 1904 long ubifs_destroy_tnc_subtree(const struct ubifs_info *c, 1909 1905 struct ubifs_znode *zr); 1906 + void ubifs_destroy_tnc_tree(struct ubifs_info *c); 1910 1907 struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c, 1911 1908 struct ubifs_zbranch *zbr, 1912 1909 struct ubifs_znode *parent, int iip);
+2
include/linux/mtd/ubi.h
··· 192 192 * or a volume was removed) 193 193 * @UBI_VOLUME_RESIZED: a volume has been re-sized 194 194 * @UBI_VOLUME_RENAMED: a volume has been re-named 195 + * @UBI_VOLUME_SHUTDOWN: a volume is going to removed, shutdown users 195 196 * @UBI_VOLUME_UPDATED: data has been written to a volume 196 197 * 197 198 * These constants define which type of event has happened when a volume ··· 203 202 UBI_VOLUME_REMOVED, 204 203 UBI_VOLUME_RESIZED, 205 204 UBI_VOLUME_RENAMED, 205 + UBI_VOLUME_SHUTDOWN, 206 206 UBI_VOLUME_UPDATED, 207 207 }; 208 208