29949ccfbb
https://source.android.com/docs/security/bulletin/2023-08-01 CVE-2023-21264 CVE-2020-29374 * tag 'ASB-2023-08-05_11-5.4' of https://android.googlesource.com/kernel/common: UPSTREAM: media: dvb-core: Fix kernel WARNING for blocking operation in wait_event*() ANDROID: ABI: Update allowed list for QCOM UPSTREAM: usb: gadget: udc: renesas_usb3: Fix use after free bug in renesas_usb3_remove due to race condition UPSTREAM: x86/mm: Avoid using set_pgd() outside of real PGD pages UPSTREAM: net/sched: flower: fix possible OOB write in fl_set_geneve_opt() Linux 5.4.249 xfs: verify buffer contents when we skip log replay mm: make wait_on_page_writeback() wait for multiple pending writebacks mm: fix VM_BUG_ON(PageTail) and BUG_ON(PageWriteback) i2c: imx-lpi2c: fix type char overflow issue when calculating the clock cycle x86/apic: Fix kernel panic when booting with intremap=off and x2apic_phys drm/radeon: fix race condition UAF in radeon_gem_set_domain_ioctl drm/exynos: fix race condition UAF in exynos_g2d_exec_ioctl drm/exynos: vidi: fix a wrong error return ARM: dts: Fix erroneous ADS touchscreen polarities ASoC: nau8824: Add quirk to active-high jack-detect s390/cio: unregister device when the only path is gone usb: gadget: udc: fix NULL dereference in remove() nfcsim.c: Fix error checking for debugfs_create_dir media: cec: core: don't set last_initiator if tx in progress arm64: Add missing Set/Way CMO encodings HID: wacom: Add error check to wacom_parse_and_register() scsi: target: iscsi: Prevent login threads from racing between each other sch_netem: acquire qdisc lock in netem_change() Revert "net: phy: dp83867: perform soft reset and retain established link" netfilter: nfnetlink_osf: fix module autoload netfilter: nf_tables: disallow element updates of bound anonymous sets be2net: Extend xmit workaround to BE3 chip net: dsa: mt7530: fix trapping frames on non-MT7621 SoC MT7530 switch ipvs: align inner_mac_header for encapsulation mmc: usdhi60rol0: fix deferred probing mmc: sh_mmcif: fix deferred probing mmc: sdhci-acpi: fix deferred probing mmc: omap_hsmmc: fix deferred probing mmc: omap: fix deferred probing mmc: mvsdio: fix deferred probing mmc: mvsdio: convert to devm_platform_ioremap_resource mmc: mtk-sd: fix deferred probing net: qca_spi: Avoid high load if QCA7000 is not available xfrm: Linearize the skb after offloading if needed. ieee802154: hwsim: Fix possible memory leaks rcu: Upgrade rcu_swap_protected() to rcu_replace_pointer() x86/mm: Avoid using set_pgd() outside of real PGD pages cifs: Fix potential deadlock when updating vol in cifs_reconnect() cifs: Merge is_path_valid() into get_normalized_path() cifs: Introduce helpers for finding TCP connection cifs: Get rid of kstrdup_const()'d paths cifs: Clean up DFS referral cache nilfs2: prevent general protection fault in nilfs_clear_dirty_page() writeback: fix dereferencing NULL mapping->host on writeback_page_template ip_tunnels: allow VXLAN/GENEVE to inherit TOS/TTL from VLAN mmc: meson-gx: remove redundant mmc_request_done() call from irq context cgroup: Do not corrupt task iteration when rebinding subsystem PCI: hv: Fix a race condition bug in hv_pci_query_relations() Drivers: hv: vmbus: Fix vmbus_wait_for_unload() to scan present CPUs nilfs2: fix buffer corruption due to concurrent device reads media: dvb-core: Fix use-after-free due to race at dvb_register_device() media: dvbdev: fix error logic at dvb_register_device() media: dvbdev: Fix memleak in dvb_register_device tick/common: Align tick period during sched_timer setup x86/purgatory: remove PGO flags tracing: Add tracing_reset_all_online_cpus_unlocked() function epoll: ep_autoremove_wake_function should use list_del_init_careful list: add "list_del_init_careful()" to go with "list_empty_careful()" mm: rewrite wait_on_page_bit_common() logic nilfs2: reject devices with insufficient block count Revert "neighbour: Replace zero-length array with flexible-array member" Revert "neighbour: fix unaligned access to pneigh_entry" Revert "tcp: deny tcp_disconnect() when threads are waiting" Linux 5.4.248 mmc: block: ensure error propagation for non-blk drm/nouveau/kms: Fix NULL pointer dereference in nouveau_connector_detect_depth neighbour: delete neigh_lookup_nodev as not used net: Remove unused inline function dst_hold_and_use() neighbour: Remove unused inline function neigh_key_eq16() afs: Fix vlserver probe RTT handling selftests/ptp: Fix timestamp printf format for PTP_SYS_OFFSET net: tipc: resize nlattr array to correct size net: lapbether: only support ethernet devices net/sched: cls_api: Fix lockup on flushing explicitly created chain drm/nouveau: add nv_encoder pointer check for NULL drm/nouveau/kms: Don't change EDID when it hasn't actually changed drm/nouveau/dp: check for NULL nv_connector->native_mode igb: fix nvm.ops.read() error handling sctp: fix an error code in sctp_sf_eat_auth() ipvlan: fix bound dev checking for IPv6 l3s mode IB/isert: Fix incorrect release of isert connection IB/isert: Fix possible list corruption in CMA handler IB/isert: Fix dead lock in ib_isert IB/uverbs: Fix to consider event queue closing also upon non-blocking mode iavf: remove mask from iavf_irq_enable_queues() RDMA/rxe: Fix the use-before-initialization error of resp_pkts RDMA/rxe: Removed unused name from rxe_task struct RDMA/rxe: Remove the unused variable obj net/sched: cls_u32: Fix reference counter leak leading to overflow ping6: Fix send to link-local addresses with VRF. netfilter: nfnetlink: skip error delivery on batch in case of ENOMEM spi: fsl-dspi: avoid SCK glitches with continuous transfers spi: spi-fsl-dspi: Remove unused chip->void_write_data usb: dwc3: gadget: Reset num TRBs before giving back the request serial: lantiq: add missing interrupt ack USB: serial: option: add Quectel EM061KGL series Remove DECnet support from kernel ALSA: hda/realtek: Add a quirk for Compaq N14JP6 net: usb: qmi_wwan: add support for Compal RXM-G1 RDMA/uverbs: Restrict usage of privileged QKEYs nouveau: fix client work fence deletion race powerpc/purgatory: remove PGO flags kexec: support purgatories with .text.hot sections nilfs2: fix possible out-of-bounds segment allocation in resize ioctl nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key() nios2: dts: Fix tse_mac "max-frame-size" property ocfs2: check new file size on fallocate call ocfs2: fix use-after-free when unmounting read-only filesystem drm:amd:amdgpu: Fix missing buffer object unlock in failure path xen/blkfront: Only check REQ_FUA for writes mips: Move initrd_start check after initrd address sanitisation. MIPS: Alchemy: fix dbdma2 parisc: Flush gatt writes and adjust gatt mask in parisc_agp_mask_memory() parisc: Improve cache flushing for PCXL in arch_sync_dma_for_cpu() btrfs: handle memory allocation failure in btrfs_csum_one_bio power: supply: Fix logic checking if system is running from battery irqchip/meson-gpio: Mark OF related data as maybe unused regulator: Fix error checking for debugfs_create_dir platform/x86: asus-wmi: Ignore WMI events with codes 0x7B, 0xC0 power: supply: Ratelimit no data debug output ARM: dts: vexpress: add missing cache properties power: supply: bq27xxx: Use mod_delayed_work() instead of cancel() + schedule() power: supply: sc27xx: Fix external_power_changed race power: supply: ab8500: Fix external_power_changed race s390/dasd: Use correct lock while counting channel queue length dasd: refactor dasd_ioctl_information KEYS: asymmetric: Copy sig and digest in public_key_verify_signature() test_firmware: fix a memory leak with reqs buffer Revert "firmware: arm_sdei: Fix sleep from invalid context BUG" Revert "PM: domains: Fix up terminology with parent/child" Revert "PM: domains: Restore comment indentation for generic_pm_domain.child_links" Revert "scripts/gdb: bail early if there are no generic PD" Revert "uapi/linux/const.h: prefer ISO-friendly __typeof__" Revert "netfilter: nf_tables: don't write table validation state without mutex" Linux 5.4.247 Revert "staging: rtl8192e: Replace macro RTL_PCI_DEVICE with PCI_DEVICE" mtd: spinand: macronix: Add support for MX35LFxGE4AD btrfs: unset reloc control if transaction commit fails in prepare_to_relocate() btrfs: check return value of btrfs_commit_transaction in relocation rbd: get snapshot context after exclusive lock is ensured to be held drm/atomic: Don't pollute crtc_state->mode_blob with error pointers cifs: handle empty list of targets in cifs_reconnect() cifs: get rid of unused parameter in reconn_setup_dfs_targets() ext4: only check dquot_initialize_needed() when debugging eeprom: at24: also select REGMAP i2c: sprd: Delete i2c adapter in .remove's error path bonding (gcc13): synchronize bond_{a,t}lb_xmit() types usb: usbfs: Use consistent mmap functions usb: usbfs: Enforce page requirements for mmap pinctrl: meson-axg: add missing GPIOA_18 gpio group rbd: move RBD_OBJ_FLAG_COPYUP_ENABLED flag setting Bluetooth: Fix use-after-free in hci_remove_ltk/hci_remove_irk ceph: fix use-after-free bug for inodes when flushing capsnaps can: j1939: avoid possible use-after-free when j1939_can_rx_register fails can: j1939: change j1939_netdev_lock type to mutex can: j1939: j1939_sk_send_loop_abort(): improved error queue handling in J1939 Socket drm/amdgpu: fix xclk freq on CHIP_STONEY ALSA: hda/realtek: Add Lenovo P3 Tower platform ALSA: hda/realtek: Add a quirk for HP Slim Desktop S01 Input: psmouse - fix OOB access in Elantech protocol Input: xpad - delete a Razer DeathAdder mouse VID/PID entry batman-adv: Broken sync while rescheduling delayed work bnxt_en: Query default VLAN before VNIC setup on a VF lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release() net: sched: fix possible refcount leak in tc_chain_tmplt_add() net: sched: move rtm_tca_policy declaration to include file rfs: annotate lockless accesses to RFS sock flow table rfs: annotate lockless accesses to sk->sk_rxhash netfilter: ipset: Add schedule point in call_ad(). netfilter: conntrack: fix NULL pointer dereference in nf_confirm_cthelper Bluetooth: L2CAP: Add missing checks for invalid DCID Bluetooth: Fix l2cap_disconnect_req deadlock net: dsa: lan9303: allow vid != 0 in port_fdb_{add|del} methods neighbour: fix unaligned access to pneigh_entry neighbour: Replace zero-length array with flexible-array member spi: qup: Request DMA before enabling clocks i40e: fix build warnings in i40e_alloc.h i40iw: fix build warning in i40iw_manage_apbvt() block/blk-iocost (gcc13): keep large values in a new enum blk-iocost: avoid 64-bit division in ioc_timer_fn Linux 5.4.246 drm/edid: fix objtool warning in drm_cvt_modes() wifi: rtlwifi: 8192de: correct checking of IQK reload drm/edid: Fix uninitialized variable in drm_cvt_modes() RDMA/bnxt_re: Remove the qp from list only if the qp destroy succeeds RDMA/bnxt_re: Remove set but not used variable 'dev_attr' scsi: dpt_i2o: Do not process completions with invalid addresses scsi: dpt_i2o: Remove broken pass-through ioctl (I2OUSERCMD) regmap: Account for register length when chunking test_firmware: fix the memory leak of the allocated firmware buffer fbcon: Fix null-ptr-deref in soft_cursor ext4: add lockdep annotations for i_data_sem for ea_inode's ext4: disallow ea_inodes with extended attributes ext4: set lockdep subclass for the ea_inode in ext4_xattr_inode_cache_find() ext4: add EA_INODE checking to ext4_iget() tracing/probe: trace_probe_primary_from_call(): checked list_first_entry selinux: don't use make's grouped targets feature yet tty: serial: fsl_lpuart: use UARTCTRL_TXINV to send break instead of UARTCTRL_SBK mmc: vub300: fix invalid response handling wifi: rtlwifi: remove always-true condition pointed out by GCC 12 lib/dynamic_debug.c: use address-of operator on section symbols treewide: Remove uninitialized_var() usage kernel/extable.c: use address-of operator on section symbols eth: sun: cassini: remove dead code gcc-12: disable '-Wdangling-pointer' warning for now ACPI: thermal: drop an always true check x86/boot: Wrap literal addresses in absolute_pointer() flow_dissector: work around stack frame size warning ata: libata-scsi: Use correct device no in ata_find_dev() scsi: stex: Fix gcc 13 warnings misc: fastrpc: reject new invocations during device removal misc: fastrpc: return -EPIPE to invocations on device removal usb: gadget: f_fs: Add unbind event before functionfs_unbind net: usb: qmi_wwan: Set DTR quirk for BroadMobi BM818 iio: dac: build ad5758 driver when AD5758 is selected iio: dac: mcp4725: Fix i2c_master_send() return value handling iio: light: vcnl4035: fixed chip ID check HID: wacom: avoid integer overflow in wacom_intuos_inout() HID: google: add jewel USB id iio: adc: mxs-lradc: fix the order of two cleanup operations mailbox: mailbox-test: fix a locking issue in mbox_test_message_write() atm: hide unused procfs functions ALSA: oss: avoid missing-prototype warnings netfilter: conntrack: define variables exp_nat_nla_policy and any_addr with CONFIG_NF_NAT wifi: b43: fix incorrect __packed annotation scsi: core: Decrease scsi_device's iorequest_cnt if dispatch failed arm64/mm: mark private VM_FAULT_X defines as vm_fault_t ARM: dts: stm32: add pin map for CAN controller on stm32f7 wifi: rtl8xxxu: fix authentication timeout due to incorrect RCR value media: dvb-core: Fix use-after-free due to race condition at dvb_ca_en50221 media: dvb-core: Fix kernel WARNING for blocking operation in wait_event*() media: dvb-core: Fix use-after-free due on race condition at dvb_net media: mn88443x: fix !CONFIG_OF error by drop of_match_ptr from ID table media: ttusb-dec: fix memory leak in ttusb_dec_exit_dvb() media: dvb_ca_en50221: fix a size write bug media: netup_unidvb: fix irq init by register it at the end of probe media: dvb-usb: dw2102: fix uninit-value in su3000_read_mac_address media: dvb-usb: digitv: fix null-ptr-deref in digitv_i2c_xfer() media: dvb-usb-v2: rtl28xxu: fix null-ptr-deref in rtl28xxu_i2c_xfer media: dvb-usb-v2: ce6230: fix null-ptr-deref in ce6230_i2c_master_xfer() media: dvb-usb-v2: ec168: fix null-ptr-deref in ec168_i2c_xfer() media: dvb-usb: az6027: fix three null-ptr-deref in az6027_i2c_xfer() media: dvb_demux: fix a bug for the continuity counter ASoC: ssm2602: Add workaround for playback distortions xfrm: Check if_id in inbound policy/secpath match ASoC: dwc: limit the number of overrun messages nbd: Fix debugfs_create_dir error checking fbdev: stifb: Fix info entry in sti_struct on error path fbdev: modedb: Add 1920x1080 at 60 Hz video mode media: rcar-vin: Select correct interrupt mode for V4L2_FIELD_ALTERNATE ARM: 9295/1: unwind:fix unwind abort for uleb128 case mailbox: mailbox-test: Fix potential double-free in mbox_test_message_write() watchdog: menz069_wdt: fix watchdog initialisation mtd: rawnand: marvell: don't set the NAND frequency select mtd: rawnand: marvell: ensure timing values are written net: dsa: mv88e6xxx: Increase wait after reset deactivation net/sched: flower: fix possible OOB write in fl_set_geneve_opt() udp6: Fix race condition in udp6_sendmsg & connect net/netlink: fix NETLINK_LIST_MEMBERSHIPS length report ocfs2/dlm: move BITS_TO_BYTES() to bitops.h for wider use net: sched: fix NULL pointer dereference in mq_attach net/sched: Prohibit regrafting ingress or clsact Qdiscs net/sched: Reserve TC_H_INGRESS (TC_H_CLSACT) for ingress (clsact) Qdiscs net/sched: sch_clsact: Only create under TC_H_CLSACT net/sched: sch_ingress: Only create under TC_H_INGRESS tcp: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state if user_mss set tcp: deny tcp_disconnect() when threads are waiting af_packet: do not use READ_ONCE() in packet_bind() mtd: rawnand: ingenic: fix empty stub helper definitions amd-xgbe: fix the false linkup in xgbe_phy_status af_packet: Fix data-races of pkt_sk(sk)->num. netrom: fix info-leak in nr_write_internal() net/mlx5: fw_tracer, Fix event handling dmaengine: pl330: rename _start to prevent build error iommu/amd: Don't block updates to GATag if guest mode is on iommu/rockchip: Fix unwind goto issue RDMA/bnxt_re: Fix return value of bnxt_re_process_raw_qp_pkt_rx RDMA/bnxt_re: Refactor queue pair creation code RDMA/bnxt_re: Enable SRIOV VF support on Broadcom's 57500 adapter series RDMA/efa: Fix unsupported page sizes in device Linux 5.4.245 netfilter: ctnetlink: Support offloaded conntrack entry deletion ipv{4,6}/raw: fix output xfrm lookup wrt protocol binder: fix UAF caused by faulty buffer cleanup bluetooth: Add cmd validity checks at the start of hci_sock_ioctl() io_uring: have io_kill_timeout() honor the request references io_uring: don't drop completion lock before timer is fully initialized io_uring: always grab lock in io_cancel_async_work() cdc_ncm: Fix the build warning net/mlx5: Devcom, serialize devcom registration net/mlx5: devcom only supports 2 ports fs: fix undefined behavior in bit shift for SB_NOUSER power: supply: bq24190: Call power_supply_changed() after updating input current power: supply: core: Refactor power_supply_set_input_current_limit_from_supplier() power: supply: bq27xxx: After charger plug in/out wait 0.5s for things to stabilize net: cdc_ncm: Deal with too low values of dwNtbOutMaxSize cdc_ncm: Implement the 32-bit version of NCM Transfer Block Linux 5.4.244 3c589_cs: Fix an error handling path in tc589_probe() net/mlx5: Devcom, fix error flow in mlx5_devcom_register_device net/mlx5: Fix error message when failing to allocate device memory forcedeth: Fix an error handling path in nv_probe() ASoC: Intel: Skylake: Fix declaration of enum skl_ch_cfg x86/show_trace_log_lvl: Ensure stack pointer is aligned, again xen/pvcalls-back: fix double frees with pvcalls_new_active_socket() coresight: Fix signedness bug in tmc_etr_buf_insert_barrier_packet() power: supply: sbs-charger: Fix INHIBITED bit for Status reg power: supply: bq27xxx: Fix poll_interval handling and races on remove power: supply: bq27xxx: Fix I2C IRQ race on remove power: supply: bq27xxx: Fix bq27xxx_battery_update() race condition power: supply: leds: Fix blink to LED on transition ipv6: Fix out-of-bounds access in ipv6_find_tlv() bpf: Fix mask generation for 32-bit narrow loads of 64-bit fields selftests: fib_tests: mute cleanup error message net: fix skb leak in __skb_tstamp_tx() media: radio-shark: Add endpoint checks USB: sisusbvga: Add endpoint checks USB: core: Add routines for endpoint checks in old drivers udplite: Fix NULL pointer dereference in __sk_mem_raise_allocated(). net: fix stack overflow when LRO is disabled for virtual interfaces fbdev: udlfb: Fix endpoint check debugobjects: Don't wake up kswapd from fill_pool() x86/topology: Fix erroneous smp_num_siblings on Intel Hybrid platforms parisc: Fix flush_dcache_page() for usage from irq context selftests/memfd: Fix unknown type name build failure x86/mm: Avoid incomplete Global INVLPG flushes btrfs: use nofs when cleaning up aborted transactions gpio: mockup: Fix mode of debugfs files parisc: Allow to reboot machine after system halt parisc: Handle kgdb breakpoints only in kernel context m68k: Move signal frame following exception on 68020/030 ALSA: hda/realtek: Enable headset onLenovo M70/M90 ALSA: hda/ca0132: add quirk for EVGA X299 DARK mt76: mt7615: Fix build with older compilers spi: fsl-cpm: Use 16 bit mode for large transfers with even size spi: fsl-spi: Re-organise transfer bits_per_word adaptation watchdog: sp5100_tco: Immediately trigger upon starting. s390/qdio: fix do_sqbs() inline assembly constraint s390/qdio: get rid of register asm vc_screen: reload load of struct vc_data pointer in vcs_write() to avoid UAF vc_screen: rewrite vcs_size to accept vc, not inode usb: gadget: u_ether: Fix host MAC address case usb: gadget: u_ether: Convert prints to device prints lib/string_helpers: Introduce string_upper() and string_lower() helpers HID: wacom: add three styli to wacom_intuos_get_tool_type HID: wacom: Add new Intuos Pro Small (PTH-460) device IDs HID: wacom: Force pen out of prox if no events have been received in a while netfilter: nf_tables: hold mutex on netns pre_exit path netfilter: nf_tables: validate NFTA_SET_ELEM_OBJREF based on NFT_SET_OBJECT flag netfilter: nf_tables: stricter validation of element data netfilter: nf_tables: allow up to 64 bytes in the set element data area netfilter: nf_tables: add nft_setelem_parse_key() netfilter: nf_tables: validate registers coming from userspace. netfilter: nftables: statify nft_parse_register() netfilter: nftables: add nft_parse_register_store() and use it netfilter: nftables: add nft_parse_register_load() and use it nilfs2: fix use-after-free bug of nilfs_root in nilfs_evict_inode() powerpc/64s/radix: Fix soft dirty tracking tpm/tpm_tis: Disable interrupts for more Lenovo devices ceph: force updating the msg pointer in non-split case serial: Add support for Advantech PCI-1611U card statfs: enforce statfs[64] structure initialization KVM: x86: do not report a vCPU as preempted outside instruction boundaries can: kvaser_pciefd: Disable interrupts in probe error path can: kvaser_pciefd: Do not send EFLUSH command on TFD interrupt can: kvaser_pciefd: Clear listen-only bit if not explicitly requested can: kvaser_pciefd: Empty SRB buffer in probe can: kvaser_pciefd: Call request_irq() before enabling interrupts can: kvaser_pciefd: Set CAN_STATE_STOPPED in kvaser_pciefd_stop() can: j1939: recvmsg(): allow MSG_CMSG_COMPAT flag ALSA: hda/realtek: Add quirk for 2nd ASUS GU603 ALSA: hda/realtek: Add a quirk for HP EliteDesk 805 ALSA: hda: Add NVIDIA codec IDs a3 through a7 to patch table ALSA: hda: Fix Oops by 9.1 surround channel names usb: typec: altmodes/displayport: fix pin_assignment_show usb: dwc3: debugfs: Resume dwc3 before accessing registers USB: UHCI: adjust zhaoxin UHCI controllers OverCurrent bit value usb-storage: fix deadlock when a scsi command timeouts more than once USB: usbtmc: Fix direction for 0-length ioctl control messages vlan: fix a potential uninit-value in vlan_dev_hard_start_xmit() igb: fix bit_shift to be in [1..8] range cassini: Fix a memory leak in the error handling path of cas_init_one() wifi: iwlwifi: mvm: don't trust firmware n_channels net: bcmgenet: Restore phy_stop() depending upon suspend/close net: bcmgenet: Remove phy_stop() from bcmgenet_netif_stop() net: nsh: Use correct mac_offset to unwind gso skb in nsh_gso_segment() drm/exynos: fix g2d_open/close helper function definitions media: netup_unidvb: fix use-after-free at del_timer() net: hns3: fix reset delay time to avoid configuration timeout net: hns3: fix sending pfc frames after reset issue erspan: get the proto with the md version for collect_md ip_gre, ip6_gre: Fix race condition on o_seqno in collect_md mode ip6_gre: Make o_seqno start from 0 in native mode ip6_gre: Fix skb_under_panic in __gre6_xmit() serial: arc_uart: fix of_iomap leak in `arc_serial_probe` vsock: avoid to close connected socket after the timeout ALSA: firewire-digi00x: prevent potential use after free net: fec: Better handle pm_runtime_get() failing in .remove() af_key: Reject optional tunnel/BEET mode templates in outbound policies cpupower: Make TSC read per CPU for Mperf monitor ASoC: fsl_micfil: register platform component before registering cpu dai btrfs: fix space cache inconsistency after error loading it from disk btrfs: replace calls to btrfs_find_free_ino with btrfs_find_free_objectid mfd: dln2: Fix memory leak in dln2_probe() phy: st: miphy28lp: use _poll_timeout functions for waits Input: xpad - add constants for GIP interface numbers iommu/arm-smmu-v3: Acknowledge pri/event queue overflow if any clk: tegra20: fix gcc-7 constant overflow warning RDMA/core: Fix multiple -Warray-bounds warnings recordmcount: Fix memory leaks in the uwrite function sched: Fix KCSAN noinstr violation mcb-pci: Reallocate memory region to avoid memory overlapping serial: 8250: Reinit port->pm on port specific driver unbind usb: typec: tcpm: fix multiple times discover svids error HID: wacom: generic: Set battery quirk only when we see battery data spi: spi-imx: fix MX51_ECSPI_* macros when cs > 3 HID: logitech-hidpp: Reconcile USB and Unifying serials HID: logitech-hidpp: Don't use the USB serial for USB devices staging: rtl8192e: Replace macro RTL_PCI_DEVICE with PCI_DEVICE Bluetooth: L2CAP: fix "bad unlock balance" in l2cap_disconnect_rsp wifi: iwlwifi: dvm: Fix memcpy: detected field-spanning write backtrace wifi: iwlwifi: pcie: Fix integer overflow in iwl_write_to_user_buf wifi: iwlwifi: pcie: fix possible NULL pointer dereference samples/bpf: Fix fout leak in hbm's run_bpf_prog f2fs: fix to drop all dirty pages during umount() if cp_error is set ext4: Fix best extent lstart adjustment logic in ext4_mb_new_inode_pa() ext4: set goal start correctly in ext4_mb_normalize_request gfs2: Fix inode height consistency check scsi: message: mptlan: Fix use after free bug in mptlan_remove() due to race condition lib: cpu_rmap: Avoid use after free on rmap->obj array entries scsi: target: iscsit: Free cmds before session free net: Catch invalid index in XPS mapping net: pasemi: Fix return type of pasemi_mac_start_tx() scsi: lpfc: Prevent lpfc_debugfs_lockstat_write() buffer overflow ext2: Check block size validity during mount wifi: brcmfmac: cfg80211: Pass the PMK in binary instead of hex ACPICA: ACPICA: check null return of ACPI_ALLOCATE_ZEROED in acpi_db_display_objects ACPICA: Avoid undefined behavior: applying zero offset to null pointer drm/tegra: Avoid potential 32-bit integer overflow ACPI: EC: Fix oops when removing custom query handlers firmware: arm_sdei: Fix sleep from invalid context BUG memstick: r592: Fix UAF bug in r592_remove due to race condition regmap: cache: Return error in cache sync operations for REGCACHE_NONE drm/amd/display: Use DC_LOG_DC in the trasform pixel function fs: hfsplus: remove WARN_ON() from hfsplus_cat_{read,write}_inode() af_unix: Fix data races around sk->sk_shutdown. af_unix: Fix a data race of sk->sk_receive_queue->qlen. net: datagram: fix data-races in datagram_poll() ipvlan:Fix out-of-bounds caused by unclear skb->cb net: add vlan_get_protocol_and_depth() helper net: tap: check vlan with eth_type_vlan() method net: annotate sk->sk_err write from do_recvmmsg() netlink: annotate accesses to nlk->cb_running netfilter: conntrack: fix possible bug_on with enable_hooks=1 net: Fix load-tearing on sk->sk_stamp in sock_recv_cmsgs(). linux/dim: Do nothing if no time delta between samples ARM: 9296/1: HP Jornada 7XX: fix kernel-doc warnings drm/mipi-dsi: Set the fwnode for mipi_dsi_device driver core: add a helper to setup both the of_node and fwnode of a device Linux 5.4.243 drm/amd/display: Fix hang when skipping modeset mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock drm/exynos: move to use request_irq by IRQF_NO_AUTOEN flag drm/msm/adreno: Fix null ptr access in adreno_gpu_cleanup() firmware: raspberrypi: fix possible memory leak in rpi_firmware_probe() drm/msm: Fix double pm_runtime_disable() call PM: domains: Restore comment indentation for generic_pm_domain.child_links printk: declare printk_deferred_{enter,safe}() in include/linux/printk.h PCI: pciehp: Fix AB-BA deadlock between reset_lock and device_lock PCI: pciehp: Use down_read/write_nested(reset_lock) to fix lockdep errors drbd: correctly submit flush bio on barrier serial: 8250: Fix serial8250_tx_empty() race with DMA Tx tty: Prevent writing chars during tcsetattr TCSADRAIN/FLUSH ext4: fix invalid free tracking in ext4_xattr_move_to_block() ext4: remove a BUG_ON in ext4_mb_release_group_pa() ext4: bail out of ext4_xattr_ibody_get() fails for any reason ext4: add bounds checking in get_max_inline_xattr_value_size() ext4: fix deadlock when converting an inline directory in nojournal mode ext4: improve error recovery code paths in __ext4_remount() ext4: fix data races when using cached status extents ext4: avoid a potential slab-out-of-bounds in ext4_group_desc_csum ext4: fix WARNING in mb_find_extent HID: wacom: insert timestamp to packed Bluetooth (BT) events HID: wacom: Set a default resolution for older tablets drm/amdgpu: disable sdma ecc irq only when sdma RAS is enabled in suspend drm/amdgpu/gfx: disable gfx9 cp_ecc_error_irq only when enabling legacy gfx ras drm/amdgpu: fix an amdgpu_irq_put() issue in gmc_v9_0_hw_fini() drm/panel: otm8009a: Set backlight parent to panel device f2fs: fix potential corruption when moving a directory ARM: dts: s5pv210: correct MIPI CSIS clock name ARM: dts: exynos: fix WM8960 clock name in Itop Elite remoteproc: st: Call of_node_put() on iteration error remoteproc: stm32: Call of_node_put() on iteration error sh: nmi_debug: fix return value of __setup handler sh: init: use OF_EARLY_FLATTREE for early init sh: math-emu: fix macro redefined warning inotify: Avoid reporting event with invalid wd platform/x86: touchscreen_dmi: Add info for the Dexp Ursus KX210i cifs: fix pcchunk length type in smb2_copychunk_range btrfs: print-tree: parent bytenr must be aligned to sector size btrfs: don't free qgroup space unless specified btrfs: fix btrfs_prev_leaf() to not return the same key twice perf symbols: Fix return incorrect build_id size in elf_read_build_id() perf map: Delete two variable initialisations before null pointer checks in sort__sym_from_cmp() perf vendor events power9: Remove UTF-8 characters from JSON files virtio_net: suppress cpu stall when free_unused_bufs virtio_net: split free_unused_bufs() net: dsa: mt7530: fix corrupt frames using trgmii on 40 MHz XTAL MT7621 ALSA: caiaq: input: Add error handling for unsupported input methods in `snd_usb_caiaq_input_init` drm/amdgpu: add a missing lock for AMDGPU_SCHED af_packet: Don't send zero-byte data in packet_sendmsg_spkt(). ionic: remove noise from ethtool rxnfc error msg rxrpc: Fix hard call timeout units net/sched: act_mirred: Add carrier check writeback: fix call of incorrect macro net: dsa: mv88e6xxx: add mv88e6321 rsvd2cpu sit: update dev->needed_headroom in ipip6_tunnel_bind_dev() net/sched: cls_api: remove block_cb from driver_list before freeing net/ncsi: clear Tx enable mode when handling a Config required AEN relayfs: fix out-of-bounds access in relay_file_read kernel/relay.c: fix read_pos error when multiple readers crypto: safexcel - Cleanup ring IRQ workqueues on load failure crypto: inside-secure - irq balance dm verity: fix error handling for check_at_most_once on FEC dm verity: skip redundant verity_handle_err() on I/O errors mailbox: zynqmp: Fix counts of child nodes mailbox: zynq: Switch to flexible array to simplify code tick/nohz: Fix cpu_is_hotpluggable() by checking with nohz subsystem nohz: Add TICK_DEP_BIT_RCU netfilter: nf_tables: deactivate anonymous set from preparation phase debugobject: Ensure pool refill (again) perf intel-pt: Fix CYC timestamps after standalone CBR perf auxtrace: Fix address filter entire kernel size dm ioctl: fix nested locking in table_clear() to remove deadlock concern dm flakey: fix a crash with invalid table line dm integrity: call kmem_cache_destroy() in dm_integrity_init() error path dm clone: call kmem_cache_destroy() in dm_clone_init() error path s390/dasd: fix hanging blockdevice after request requeue btrfs: scrub: reject unsupported scrub flags scripts/gdb: fix lx-timerlist for Python3 clk: rockchip: rk3399: allow clk_cifout to force clk_cifout_src to reparent wifi: rtl8xxxu: RTL8192EU always needs full init mailbox: zynqmp: Fix typo in IPI documentation mailbox: zynqmp: Fix IPI isr handling md/raid10: fix null-ptr-deref in raid10_sync_request nilfs2: fix infinite loop in nilfs_mdt_get_block() nilfs2: do not write dirty data after degenerating to read-only parisc: Fix argument pointer in real64_call_asm() afs: Fix updating of i_size with dv jump from server dmaengine: at_xdmac: do not enable all cyclic channels dmaengine: dw-edma: Fix to enable to issue dma request on DMA processing dmaengine: dw-edma: Fix to change for continuous transfer phy: tegra: xusb: Add missing tegra_xusb_port_unregister for usb2_port and ulpi_port pwm: mtk-disp: Disable shadow registers before setting backlight values pwm: mtk-disp: Adjust the clocks to avoid them mismatch pwm: mtk-disp: Don't check the return code of pwmchip_remove() dmaengine: mv_xor_v2: Fix an error code. leds: TI_LMU_COMMON: select REGMAP instead of depending on it ext4: fix use-after-free read in ext4_find_extent for bigalloc + inline openrisc: Properly store r31 to pt_regs on unhandled exceptions clocksource/drivers/davinci: Fix memory leak in davinci_timer_register when init fails clocksource: davinci: axe a pointless __GFP_NOFAIL clocksource/drivers/davinci: Avoid trailing '\n' hidden in pr_fmt() RDMA/mlx5: Use correct device num_ports when modify DC SUNRPC: remove the maximum number of retries in call_bind_status Input: raspberrypi-ts - fix refcount leak in rpi_ts_probe input: raspberrypi-ts: Release firmware handle when not needed firmware: raspberrypi: Introduce devm_rpi_firmware_get() firmware: raspberrypi: Keep count of all consumers NFSv4.1: Always send a RECLAIM_COMPLETE after establishing lease IB/hfi1: Fix SDMA mmu_rb_node not being evicted in LRU order RDMA/siw: Remove namespace check from siw_netdev_event() clk: add missing of_node_put() in "assigned-clocks" property parsing power: supply: generic-adc-battery: fix unit scaling rtc: meson-vrtc: Use ktime_get_real_ts64() to get the current time RDMA/mlx4: Prevent shift wrapping in set_user_sq_size() rtc: omap: include header for omap_rtc_power_off_program prototype RDMA/rdmavt: Delete unnecessary NULL check RDMA/siw: Fix potential page_array out of range access perf/core: Fix hardlockup failure caused by perf throttle powerpc/rtas: use memmove for potentially overlapping buffer copy macintosh: via-pmu-led: requires ATA to be set powerpc/sysdev/tsi108: fix resource printk format warnings powerpc/wii: fix resource printk format warnings powerpc/mpc512x: fix resource printk format warning macintosh/windfarm_smu_sat: Add missing of_node_put() spmi: Add a check for remove callback when removing a SPMI driver staging: rtl8192e: Fix W_DISABLE# does not work after stop/start serial: 8250: Add missing wakeup event reporting tty: serial: fsl_lpuart: adjust buffer length to the intended size firmware: stratix10-svc: Fix an NULL vs IS_ERR() bug in probe usb: mtu3: fix kernel panic at qmu transfer done irq handler usb: chipidea: fix missing goto in `ci_hdrc_probe` sh: sq: Fix incorrect element size for allocating bitmap buffer uapi/linux/const.h: prefer ISO-friendly __typeof__ spi: cadence-quadspi: fix suspend-resume implementations mtd: spi-nor: cadence-quadspi: Handle probe deferral while requesting DMA channel mtd: spi-nor: cadence-quadspi: Don't initialize rx_dma_complete on failure mtd: spi-nor: cadence-quadspi: Provide a way to disable DAC mode mtd: spi-nor: cadence-quadspi: Make driver independent of flash geometry scripts/gdb: bail early if there are no generic PD PM: domains: Fix up terminology with parent/child scripts/gdb: bail early if there are no clocks ia64: salinfo: placate defined-but-not-used warning ia64: mm/contig: fix section mismatch warning/error of: Fix modalias string generation vmci_host: fix a race condition in vmci_host_poll() causing GPF spi: fsl-spi: Fix CPM/QE mode Litte Endian spi: qup: Don't skip cleanup in remove's error path linux/vt_buffer.h: allow either builtin or modular for macros ASoC: es8316: Handle optional IRQ assignment ASoC: es8316: Use IRQF_NO_AUTOEN when requesting the IRQ genirq: Add IRQF_NO_AUTOEN for request_irq/nmi() PCI: imx6: Install the fault handler only on compatible match usb: gadget: udc: renesas_usb3: Fix use after free bug in renesas_usb3_remove due to race condition iio: light: max44009: add missing OF device matching fpga: bridge: fix kernel-doc parameter description usb: host: xhci-rcar: remove leftover quirk handling pstore: Revert pmsg_lock back to a normal mutex tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp. net: amd: Fix link leak when verifying config failed netlink: Use copy_to_user() for optval in netlink_getsockopt(). Revert "Bluetooth: btsdio: fix use after free bug in btsdio_remove due to unfinished work" ipv4: Fix potential uninit variable access bug in __ip_make_skb() netfilter: nf_tables: don't write table validation state without mutex bpf: Don't EFAULT for getsockopt with optval=NULL ixgbe: Enable setting RSS table to default values ixgbe: Allow flow hash to be set via ethtool wifi: iwlwifi: mvm: check firmware response size wifi: iwlwifi: make the loop for card preparation effective md/raid10: fix memleak of md thread md: update the optimal I/O size on reshape md/raid10: fix memleak for 'conf->bio_split' md/raid10: fix leak of 'r10bio->remaining' for recovery bpf, sockmap: Revert buggy deadlock fix in the sockhash and sockmap nvme-fcloop: fix "inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage" nvme: fix async event trace event nvme: handle the persistent internal error AER bpf, sockmap: fix deadlocks in the sockhash and sockmap scsi: lpfc: Fix ioremap issues in lpfc_sli4_pci_mem_setup() crypto: drbg - Only fail when jent is unavailable in FIPS mode crypto: drbg - make drbg_prepare_hrng() handle jent instantiation errors bpftool: Fix bug for long instructions in program CFG dumps wifi: rtlwifi: fix incorrect error codes in rtl_debugfs_set_write_reg() wifi: rtlwifi: fix incorrect error codes in rtl_debugfs_set_write_rfreg() rtlwifi: Replace RT_TRACE with rtl_dbg rtlwifi: Start changing RT_TRACE into rtl_dbg f2fs: handle dqget error in f2fs_transfer_project_quota() scsi: megaraid: Fix mega_cmd_done() CMDID_INT_CMDS scsi: target: iscsit: Fix TAS handling during conn cleanup net/packet: convert po->auxdata to an atomic flag net/packet: convert po->origdev to an atomic flag net/packet: annotate accesses to po->xmit vlan: partially enable SIOCSHWTSTAMP in container scm: fix MSG_CTRUNC setting condition for SO_PASSSEC wifi: rtw88: mac: Return the original error from rtw_mac_power_switch() wifi: rtw88: mac: Return the original error from rtw_pwr_seq_parser() tools: bpftool: Remove invalid \' json escape wifi: ath6kl: reduce WARN to dev_dbg() in callback wifi: ath5k: fix an off by one check in ath5k_eeprom_read_freq_list() wifi: ath9k: hif_usb: fix memory leak of remain_skbs wifi: ath6kl: minor fix for allocation size tick/common: Align tick period with the HZ tick. tick: Get rid of tick_period tick/sched: Optimize tick_do_update_jiffies64() further tick/sched: Reduce seqcount held scope in tick_do_update_jiffies64() tick/sched: Use tick_next_period for lockless quick check timekeeping: Split jiffies seqlock debugobject: Prevent init race with static objects arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step x86/ioapic: Don't return 0 from arch_dynirq_lower_bound() regulator: stm32-pwr: fix of_iomap leak media: rc: gpio-ir-recv: Fix support for wake-up media: rcar_fdp1: Fix refcount leak in probe and remove function media: rcar_fdp1: Fix the correct variable assignments media: rcar_fdp1: Make use of the helper function devm_platform_ioremap_resource() media: rcar_fdp1: fix pm_runtime_get_sync() usage count media: rcar_fdp1: simplify error check logic at fdp_open() media: saa7134: fix use after free bug in saa7134_finidev due to race condition media: dm1105: Fix use after free bug in dm1105_remove due to race condition x86/apic: Fix atomic update of offset in reserve_eilvt_offset() regulator: core: Avoid lockdep reports when resolving supplies regulator: core: Consistently set mutex_owner when using ww_mutex_lock_slow() drm/lima/lima_drv: Add missing unwind goto in lima_pdev_probe() mmc: sdhci-of-esdhc: fix quirk to ignore command inhibit for data drm/msm/adreno: drop bogus pm_runtime_set_active() drm/msm/adreno: Defer enabling runpm until hw_init() drm/msm: fix unbalanced pm_runtime_enable in adreno_gpu_{init, cleanup} firmware: qcom_scm: Clear download bit during reboot media: av7110: prevent underflow in write_ts_to_decoder() media: uapi: add MEDIA_BUS_FMT_METADATA_FIXED media bus format. media: bdisp: Add missing check for create_workqueue ARM: dts: qcom: ipq8064: Fix the PCI I/O port range ARM: dts: qcom: ipq8064: reduce pci IO size to 64K ARM: dts: qcom: ipq4019: Fix the PCI I/O port range EDAC/skx: Fix overflows on the DRAM row address mapping arrays arm64: dts: renesas: r8a774c0: Remove bogus voltages from OPP table arm64: dts: renesas: r8a77990: Remove bogus voltages from OPP table drm/probe-helper: Cancel previous job before starting new one drm/vgem: add missing mutex_destroy drm/rockchip: Drop unbalanced obj unref erofs: fix potential overflow calculating xattr_isize erofs: stop parsing non-compact HEAD index if clusterofs is invalid tpm, tpm_tis: Do not skip reset of original interrupt vector selinux: ensure av_permissions.h is built when needed selinux: fix Makefile dependencies of flask.h ubifs: Free memory for tmpfile name ubi: Fix return value overwrite issue in try_write_vid_and_data() ubifs: Fix memleak when insert_old_idx() failed Revert "ubifs: dirty_cow_znode: Fix memleak in error handling path" i2c: omap: Fix standard mode false ACK readings KVM: nVMX: Emulate NOPs in L2, and PAUSE if it's not intercepted reiserfs: Add security prefix to xattr name in reiserfs_security_write() ring-buffer: Sync IRQ works before buffer destruction pwm: meson: Fix g12a ao clk81 name pwm: meson: Fix axg ao mux parents kheaders: Use array declaration instead of char ipmi: fix SSIF not responding under certain cond. ipmi:ssif: Add send_retries increment MIPS: fw: Allow firmware to pass a empty env xhci: fix debugfs register accesses while suspended debugfs: regset32: Add Runtime PM support staging: iio: resolver: ads1210: fix config mode perf sched: Cast PTHREAD_STACK_MIN to int as it may turn into sysconf(__SC_THREAD_STACK_MIN_VALUE) USB: dwc3: fix runtime pm imbalance on unbind USB: dwc3: fix runtime pm imbalance on probe errors asm-generic/io.h: suppress endianness warnings for readq() and writeq() ASoC: Intel: bytcr_rt5640: Add quirk for the Acer Iconia One 7 B1-750 iio: adc: palmas_gpadc: fix NULL dereference on rmmod USB: serial: option: add UNISOC vendor and TOZED LT70C product bluetooth: Perform careful capability checks in hci_sock_ioctl() drm/fb-helper: set x/yres_virtual in drm_fb_helper_check_var wifi: brcmfmac: slab-out-of-bounds read in brcmf_get_assoc_ies() counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Conflicts: drivers/firmware/qcom_scm.c drivers/md/dm-verity-target.c drivers/usb/dwc3/core.c drivers/usb/dwc3/debugfs.c drivers/usb/gadget/function/f_fs.c Change-Id: Iedad1fcca99a9b739e08ea6d60988800b3a7aefa
1705 lines
42 KiB
C
1705 lines
42 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* fs/f2fs/checkpoint.c
|
|
*
|
|
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
|
|
* http://www.samsung.com/
|
|
*/
|
|
#include <linux/fs.h>
|
|
#include <linux/bio.h>
|
|
#include <linux/mpage.h>
|
|
#include <linux/writeback.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/f2fs_fs.h>
|
|
#include <linux/pagevec.h>
|
|
#include <linux/swap.h>
|
|
|
|
#include "f2fs.h"
|
|
#include "node.h"
|
|
#include "segment.h"
|
|
#include "trace.h"
|
|
#include <trace/events/f2fs.h>
|
|
|
|
static struct kmem_cache *ino_entry_slab;
|
|
struct kmem_cache *f2fs_inode_entry_slab;
|
|
|
|
void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io)
|
|
{
|
|
f2fs_build_fault_attr(sbi, 0, 0);
|
|
set_ckpt_flags(sbi, CP_ERROR_FLAG);
|
|
if (!end_io)
|
|
f2fs_flush_merged_writes(sbi);
|
|
}
|
|
|
|
/*
|
|
* We guarantee no failure on the returned page.
|
|
*/
|
|
struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
|
|
{
|
|
struct address_space *mapping = META_MAPPING(sbi);
|
|
struct page *page = NULL;
|
|
repeat:
|
|
page = f2fs_grab_cache_page(mapping, index, false);
|
|
if (!page) {
|
|
cond_resched();
|
|
goto repeat;
|
|
}
|
|
f2fs_wait_on_page_writeback(page, META, true, true);
|
|
if (!PageUptodate(page))
|
|
SetPageUptodate(page);
|
|
return page;
|
|
}
|
|
|
|
static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
|
|
bool is_meta)
|
|
{
|
|
struct address_space *mapping = META_MAPPING(sbi);
|
|
struct page *page;
|
|
struct f2fs_io_info fio = {
|
|
.sbi = sbi,
|
|
.type = META,
|
|
.op = REQ_OP_READ,
|
|
.op_flags = REQ_META | REQ_PRIO,
|
|
.old_blkaddr = index,
|
|
.new_blkaddr = index,
|
|
.encrypted_page = NULL,
|
|
.is_por = !is_meta,
|
|
};
|
|
int err;
|
|
|
|
if (unlikely(!is_meta))
|
|
fio.op_flags &= ~REQ_META;
|
|
repeat:
|
|
page = f2fs_grab_cache_page(mapping, index, false);
|
|
if (!page) {
|
|
cond_resched();
|
|
goto repeat;
|
|
}
|
|
if (PageUptodate(page))
|
|
goto out;
|
|
|
|
fio.page = page;
|
|
|
|
err = f2fs_submit_page_bio(&fio);
|
|
if (err) {
|
|
f2fs_put_page(page, 1);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
f2fs_update_iostat(sbi, FS_META_READ_IO, F2FS_BLKSIZE);
|
|
|
|
lock_page(page);
|
|
if (unlikely(page->mapping != mapping)) {
|
|
f2fs_put_page(page, 1);
|
|
goto repeat;
|
|
}
|
|
|
|
if (unlikely(!PageUptodate(page))) {
|
|
f2fs_put_page(page, 1);
|
|
return ERR_PTR(-EIO);
|
|
}
|
|
out:
|
|
return page;
|
|
}
|
|
|
|
struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
|
|
{
|
|
return __get_meta_page(sbi, index, true);
|
|
}
|
|
|
|
struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index)
|
|
{
|
|
struct page *page;
|
|
int count = 0;
|
|
|
|
retry:
|
|
page = __get_meta_page(sbi, index, true);
|
|
if (IS_ERR(page)) {
|
|
if (PTR_ERR(page) == -EIO &&
|
|
++count <= DEFAULT_RETRY_IO_COUNT)
|
|
goto retry;
|
|
f2fs_stop_checkpoint(sbi, false);
|
|
}
|
|
return page;
|
|
}
|
|
|
|
/* for POR only */
|
|
struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index)
|
|
{
|
|
return __get_meta_page(sbi, index, false);
|
|
}
|
|
|
|
static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
|
|
int type)
|
|
{
|
|
struct seg_entry *se;
|
|
unsigned int segno, offset;
|
|
bool exist;
|
|
|
|
if (type == DATA_GENERIC)
|
|
return true;
|
|
|
|
segno = GET_SEGNO(sbi, blkaddr);
|
|
offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
|
|
se = get_seg_entry(sbi, segno);
|
|
|
|
exist = f2fs_test_bit(offset, se->cur_valid_map);
|
|
if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) {
|
|
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
|
|
blkaddr, exist);
|
|
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
|
return exist;
|
|
}
|
|
|
|
if (!exist && type == DATA_GENERIC_ENHANCE) {
|
|
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
|
|
blkaddr, exist);
|
|
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
|
dump_stack();
|
|
}
|
|
return exist;
|
|
}
|
|
|
|
bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
|
|
block_t blkaddr, int type)
|
|
{
|
|
switch (type) {
|
|
case META_NAT:
|
|
break;
|
|
case META_SIT:
|
|
if (unlikely(blkaddr >= SIT_BLK_CNT(sbi)))
|
|
return false;
|
|
break;
|
|
case META_SSA:
|
|
if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) ||
|
|
blkaddr < SM_I(sbi)->ssa_blkaddr))
|
|
return false;
|
|
break;
|
|
case META_CP:
|
|
if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr ||
|
|
blkaddr < __start_cp_addr(sbi)))
|
|
return false;
|
|
break;
|
|
case META_POR:
|
|
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
|
|
blkaddr < MAIN_BLKADDR(sbi)))
|
|
return false;
|
|
break;
|
|
case DATA_GENERIC:
|
|
case DATA_GENERIC_ENHANCE:
|
|
case DATA_GENERIC_ENHANCE_READ:
|
|
case DATA_GENERIC_ENHANCE_UPDATE:
|
|
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
|
|
blkaddr < MAIN_BLKADDR(sbi))) {
|
|
f2fs_warn(sbi, "access invalid blkaddr:%u",
|
|
blkaddr);
|
|
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
|
dump_stack();
|
|
return false;
|
|
} else {
|
|
return __is_bitmap_valid(sbi, blkaddr, type);
|
|
}
|
|
break;
|
|
case META_GENERIC:
|
|
if (unlikely(blkaddr < SEG0_BLKADDR(sbi) ||
|
|
blkaddr >= MAIN_BLKADDR(sbi)))
|
|
return false;
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Readahead CP/NAT/SIT/SSA/POR pages
|
|
*/
|
|
int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
|
|
int type, bool sync)
|
|
{
|
|
struct page *page;
|
|
block_t blkno = start;
|
|
struct f2fs_io_info fio = {
|
|
.sbi = sbi,
|
|
.type = META,
|
|
.op = REQ_OP_READ,
|
|
.op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
|
|
.encrypted_page = NULL,
|
|
.in_list = false,
|
|
.is_por = (type == META_POR),
|
|
};
|
|
struct blk_plug plug;
|
|
int err;
|
|
|
|
if (unlikely(type == META_POR))
|
|
fio.op_flags &= ~REQ_META;
|
|
|
|
blk_start_plug(&plug);
|
|
for (; nrpages-- > 0; blkno++) {
|
|
|
|
if (!f2fs_is_valid_blkaddr(sbi, blkno, type))
|
|
goto out;
|
|
|
|
switch (type) {
|
|
case META_NAT:
|
|
if (unlikely(blkno >=
|
|
NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid)))
|
|
blkno = 0;
|
|
/* get nat block addr */
|
|
fio.new_blkaddr = current_nat_addr(sbi,
|
|
blkno * NAT_ENTRY_PER_BLOCK);
|
|
break;
|
|
case META_SIT:
|
|
if (unlikely(blkno >= TOTAL_SEGS(sbi)))
|
|
goto out;
|
|
/* get sit block addr */
|
|
fio.new_blkaddr = current_sit_addr(sbi,
|
|
blkno * SIT_ENTRY_PER_BLOCK);
|
|
break;
|
|
case META_SSA:
|
|
case META_CP:
|
|
case META_POR:
|
|
fio.new_blkaddr = blkno;
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
|
|
page = f2fs_grab_cache_page(META_MAPPING(sbi),
|
|
fio.new_blkaddr, false);
|
|
if (!page)
|
|
continue;
|
|
if (PageUptodate(page)) {
|
|
f2fs_put_page(page, 1);
|
|
continue;
|
|
}
|
|
|
|
fio.page = page;
|
|
err = f2fs_submit_page_bio(&fio);
|
|
f2fs_put_page(page, err ? 1 : 0);
|
|
|
|
if (!err)
|
|
f2fs_update_iostat(sbi, FS_META_READ_IO, F2FS_BLKSIZE);
|
|
}
|
|
out:
|
|
blk_finish_plug(&plug);
|
|
return blkno - start;
|
|
}
|
|
|
|
void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index)
|
|
{
|
|
struct page *page;
|
|
bool readahead = false;
|
|
|
|
page = find_get_page(META_MAPPING(sbi), index);
|
|
if (!page || !PageUptodate(page))
|
|
readahead = true;
|
|
f2fs_put_page(page, 0);
|
|
|
|
if (readahead)
|
|
f2fs_ra_meta_pages(sbi, index, BIO_MAX_PAGES, META_POR, true);
|
|
}
|
|
|
|
static int __f2fs_write_meta_page(struct page *page,
|
|
struct writeback_control *wbc,
|
|
enum iostat_type io_type)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_P_SB(page);
|
|
|
|
trace_f2fs_writepage(page, META);
|
|
|
|
if (unlikely(f2fs_cp_error(sbi))) {
|
|
if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) {
|
|
ClearPageUptodate(page);
|
|
dec_page_count(sbi, F2FS_DIRTY_META);
|
|
unlock_page(page);
|
|
return 0;
|
|
}
|
|
goto redirty_out;
|
|
}
|
|
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
|
|
goto redirty_out;
|
|
if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0))
|
|
goto redirty_out;
|
|
|
|
f2fs_do_write_meta_page(sbi, page, io_type);
|
|
dec_page_count(sbi, F2FS_DIRTY_META);
|
|
|
|
if (wbc->for_reclaim)
|
|
f2fs_submit_merged_write_cond(sbi, NULL, page, 0, META);
|
|
|
|
unlock_page(page);
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
f2fs_submit_merged_write(sbi, META);
|
|
|
|
return 0;
|
|
|
|
redirty_out:
|
|
redirty_page_for_writepage(wbc, page);
|
|
return AOP_WRITEPAGE_ACTIVATE;
|
|
}
|
|
|
|
static int f2fs_write_meta_page(struct page *page,
|
|
struct writeback_control *wbc)
|
|
{
|
|
return __f2fs_write_meta_page(page, wbc, FS_META_IO);
|
|
}
|
|
|
|
static int f2fs_write_meta_pages(struct address_space *mapping,
|
|
struct writeback_control *wbc)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
|
|
long diff, written;
|
|
|
|
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
|
|
goto skip_write;
|
|
|
|
/* collect a number of dirty meta pages and write together */
|
|
if (wbc->sync_mode != WB_SYNC_ALL &&
|
|
get_pages(sbi, F2FS_DIRTY_META) <
|
|
nr_pages_to_skip(sbi, META))
|
|
goto skip_write;
|
|
|
|
/* if locked failed, cp will flush dirty pages instead */
|
|
if (!down_write_trylock(&sbi->cp_global_sem))
|
|
goto skip_write;
|
|
|
|
trace_f2fs_writepages(mapping->host, wbc, META);
|
|
diff = nr_pages_to_write(sbi, META, wbc);
|
|
written = f2fs_sync_meta_pages(sbi, META, wbc->nr_to_write, FS_META_IO);
|
|
up_write(&sbi->cp_global_sem);
|
|
wbc->nr_to_write = max((long)0, wbc->nr_to_write - written - diff);
|
|
return 0;
|
|
|
|
skip_write:
|
|
wbc->pages_skipped += get_pages(sbi, F2FS_DIRTY_META);
|
|
trace_f2fs_writepages(mapping->host, wbc, META);
|
|
return 0;
|
|
}
|
|
|
|
long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
|
|
long nr_to_write, enum iostat_type io_type)
|
|
{
|
|
struct address_space *mapping = META_MAPPING(sbi);
|
|
pgoff_t index = 0, prev = ULONG_MAX;
|
|
struct pagevec pvec;
|
|
long nwritten = 0;
|
|
int nr_pages;
|
|
struct writeback_control wbc = {
|
|
.for_reclaim = 0,
|
|
};
|
|
struct blk_plug plug;
|
|
|
|
pagevec_init(&pvec);
|
|
|
|
blk_start_plug(&plug);
|
|
|
|
while ((nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
|
|
PAGECACHE_TAG_DIRTY))) {
|
|
int i;
|
|
|
|
for (i = 0; i < nr_pages; i++) {
|
|
struct page *page = pvec.pages[i];
|
|
|
|
if (prev == ULONG_MAX)
|
|
prev = page->index - 1;
|
|
if (nr_to_write != LONG_MAX && page->index != prev + 1) {
|
|
pagevec_release(&pvec);
|
|
goto stop;
|
|
}
|
|
|
|
lock_page(page);
|
|
|
|
if (unlikely(page->mapping != mapping)) {
|
|
continue_unlock:
|
|
unlock_page(page);
|
|
continue;
|
|
}
|
|
if (!PageDirty(page)) {
|
|
/* someone wrote it for us */
|
|
goto continue_unlock;
|
|
}
|
|
|
|
f2fs_wait_on_page_writeback(page, META, true, true);
|
|
|
|
if (!clear_page_dirty_for_io(page))
|
|
goto continue_unlock;
|
|
|
|
if (__f2fs_write_meta_page(page, &wbc, io_type)) {
|
|
unlock_page(page);
|
|
break;
|
|
}
|
|
nwritten++;
|
|
prev = page->index;
|
|
if (unlikely(nwritten >= nr_to_write))
|
|
break;
|
|
}
|
|
pagevec_release(&pvec);
|
|
cond_resched();
|
|
}
|
|
stop:
|
|
if (nwritten)
|
|
f2fs_submit_merged_write(sbi, type);
|
|
|
|
blk_finish_plug(&plug);
|
|
|
|
return nwritten;
|
|
}
|
|
|
|
static int f2fs_set_meta_page_dirty(struct page *page)
|
|
{
|
|
trace_f2fs_set_page_dirty(page, META);
|
|
|
|
if (!PageUptodate(page))
|
|
SetPageUptodate(page);
|
|
if (!PageDirty(page)) {
|
|
__set_page_dirty_nobuffers(page);
|
|
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
|
|
f2fs_set_page_private(page, 0);
|
|
f2fs_trace_pid(page);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
const struct address_space_operations f2fs_meta_aops = {
|
|
.writepage = f2fs_write_meta_page,
|
|
.writepages = f2fs_write_meta_pages,
|
|
.set_page_dirty = f2fs_set_meta_page_dirty,
|
|
.invalidatepage = f2fs_invalidate_page,
|
|
.releasepage = f2fs_release_page,
|
|
#ifdef CONFIG_MIGRATION
|
|
.migratepage = f2fs_migrate_page,
|
|
#endif
|
|
};
|
|
|
|
static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino,
|
|
unsigned int devidx, int type)
|
|
{
|
|
struct inode_management *im = &sbi->im[type];
|
|
struct ino_entry *e, *tmp;
|
|
|
|
tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS);
|
|
|
|
radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
|
|
|
|
spin_lock(&im->ino_lock);
|
|
e = radix_tree_lookup(&im->ino_root, ino);
|
|
if (!e) {
|
|
e = tmp;
|
|
if (unlikely(radix_tree_insert(&im->ino_root, ino, e)))
|
|
f2fs_bug_on(sbi, 1);
|
|
|
|
memset(e, 0, sizeof(struct ino_entry));
|
|
e->ino = ino;
|
|
|
|
list_add_tail(&e->list, &im->ino_list);
|
|
if (type != ORPHAN_INO)
|
|
im->ino_num++;
|
|
}
|
|
|
|
if (type == FLUSH_INO)
|
|
f2fs_set_bit(devidx, (char *)&e->dirty_device);
|
|
|
|
spin_unlock(&im->ino_lock);
|
|
radix_tree_preload_end();
|
|
|
|
if (e != tmp)
|
|
kmem_cache_free(ino_entry_slab, tmp);
|
|
}
|
|
|
|
static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
|
|
{
|
|
struct inode_management *im = &sbi->im[type];
|
|
struct ino_entry *e;
|
|
|
|
spin_lock(&im->ino_lock);
|
|
e = radix_tree_lookup(&im->ino_root, ino);
|
|
if (e) {
|
|
list_del(&e->list);
|
|
radix_tree_delete(&im->ino_root, ino);
|
|
im->ino_num--;
|
|
spin_unlock(&im->ino_lock);
|
|
kmem_cache_free(ino_entry_slab, e);
|
|
return;
|
|
}
|
|
spin_unlock(&im->ino_lock);
|
|
}
|
|
|
|
void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
|
|
{
|
|
/* add new dirty ino entry into list */
|
|
__add_ino_entry(sbi, ino, 0, type);
|
|
}
|
|
|
|
void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
|
|
{
|
|
/* remove dirty ino entry from list */
|
|
__remove_ino_entry(sbi, ino, type);
|
|
}
|
|
|
|
/* mode should be APPEND_INO or UPDATE_INO */
|
|
bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
|
|
{
|
|
struct inode_management *im = &sbi->im[mode];
|
|
struct ino_entry *e;
|
|
|
|
spin_lock(&im->ino_lock);
|
|
e = radix_tree_lookup(&im->ino_root, ino);
|
|
spin_unlock(&im->ino_lock);
|
|
return e ? true : false;
|
|
}
|
|
|
|
void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
|
|
{
|
|
struct ino_entry *e, *tmp;
|
|
int i;
|
|
|
|
for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
|
|
struct inode_management *im = &sbi->im[i];
|
|
|
|
spin_lock(&im->ino_lock);
|
|
list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
|
|
list_del(&e->list);
|
|
radix_tree_delete(&im->ino_root, e->ino);
|
|
kmem_cache_free(ino_entry_slab, e);
|
|
im->ino_num--;
|
|
}
|
|
spin_unlock(&im->ino_lock);
|
|
}
|
|
}
|
|
|
|
void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
|
|
unsigned int devidx, int type)
|
|
{
|
|
__add_ino_entry(sbi, ino, devidx, type);
|
|
}
|
|
|
|
bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
|
|
unsigned int devidx, int type)
|
|
{
|
|
struct inode_management *im = &sbi->im[type];
|
|
struct ino_entry *e;
|
|
bool is_dirty = false;
|
|
|
|
spin_lock(&im->ino_lock);
|
|
e = radix_tree_lookup(&im->ino_root, ino);
|
|
if (e && f2fs_test_bit(devidx, (char *)&e->dirty_device))
|
|
is_dirty = true;
|
|
spin_unlock(&im->ino_lock);
|
|
return is_dirty;
|
|
}
|
|
|
|
int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
|
|
{
|
|
struct inode_management *im = &sbi->im[ORPHAN_INO];
|
|
int err = 0;
|
|
|
|
spin_lock(&im->ino_lock);
|
|
|
|
if (time_to_inject(sbi, FAULT_ORPHAN)) {
|
|
spin_unlock(&im->ino_lock);
|
|
f2fs_show_injection_info(sbi, FAULT_ORPHAN);
|
|
return -ENOSPC;
|
|
}
|
|
|
|
if (unlikely(im->ino_num >= sbi->max_orphans))
|
|
err = -ENOSPC;
|
|
else
|
|
im->ino_num++;
|
|
spin_unlock(&im->ino_lock);
|
|
|
|
return err;
|
|
}
|
|
|
|
void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi)
|
|
{
|
|
struct inode_management *im = &sbi->im[ORPHAN_INO];
|
|
|
|
spin_lock(&im->ino_lock);
|
|
f2fs_bug_on(sbi, im->ino_num == 0);
|
|
im->ino_num--;
|
|
spin_unlock(&im->ino_lock);
|
|
}
|
|
|
|
void f2fs_add_orphan_inode(struct inode *inode)
|
|
{
|
|
/* add new orphan ino entry into list */
|
|
__add_ino_entry(F2FS_I_SB(inode), inode->i_ino, 0, ORPHAN_INO);
|
|
f2fs_update_inode_page(inode);
|
|
}
|
|
|
|
void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
|
|
{
|
|
/* remove orphan entry from orphan list */
|
|
__remove_ino_entry(sbi, ino, ORPHAN_INO);
|
|
}
|
|
|
|
static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
|
|
{
|
|
struct inode *inode;
|
|
struct node_info ni;
|
|
int err;
|
|
|
|
inode = f2fs_iget_retry(sbi->sb, ino);
|
|
if (IS_ERR(inode)) {
|
|
/*
|
|
* there should be a bug that we can't find the entry
|
|
* to orphan inode.
|
|
*/
|
|
f2fs_bug_on(sbi, PTR_ERR(inode) == -ENOENT);
|
|
return PTR_ERR(inode);
|
|
}
|
|
|
|
err = dquot_initialize(inode);
|
|
if (err) {
|
|
iput(inode);
|
|
goto err_out;
|
|
}
|
|
|
|
clear_nlink(inode);
|
|
|
|
/* truncate all the data during iput */
|
|
iput(inode);
|
|
|
|
err = f2fs_get_node_info(sbi, ino, &ni);
|
|
if (err)
|
|
goto err_out;
|
|
|
|
/* ENOMEM was fully retried in f2fs_evict_inode. */
|
|
if (ni.blk_addr != NULL_ADDR) {
|
|
err = -EIO;
|
|
goto err_out;
|
|
}
|
|
return 0;
|
|
|
|
err_out:
|
|
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
|
f2fs_warn(sbi, "%s: orphan failed (ino=%x), run fsck to fix.",
|
|
__func__, ino);
|
|
return err;
|
|
}
|
|
|
|
int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
|
|
{
|
|
block_t start_blk, orphan_blocks, i, j;
|
|
unsigned int s_flags = sbi->sb->s_flags;
|
|
int err = 0;
|
|
#ifdef CONFIG_QUOTA
|
|
int quota_enabled;
|
|
#endif
|
|
|
|
if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
|
|
return 0;
|
|
|
|
if (bdev_read_only(sbi->sb->s_bdev)) {
|
|
f2fs_info(sbi, "write access unavailable, skipping orphan cleanup");
|
|
return 0;
|
|
}
|
|
|
|
if (s_flags & SB_RDONLY) {
|
|
f2fs_info(sbi, "orphan cleanup on readonly fs");
|
|
sbi->sb->s_flags &= ~SB_RDONLY;
|
|
}
|
|
|
|
#ifdef CONFIG_QUOTA
|
|
/* Needed for iput() to work correctly and not trash data */
|
|
sbi->sb->s_flags |= SB_ACTIVE;
|
|
|
|
/*
|
|
* Turn on quotas which were not enabled for read-only mounts if
|
|
* filesystem has quota feature, so that they are updated correctly.
|
|
*/
|
|
quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
|
|
#endif
|
|
|
|
start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
|
|
orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
|
|
|
|
f2fs_ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true);
|
|
|
|
for (i = 0; i < orphan_blocks; i++) {
|
|
struct page *page;
|
|
struct f2fs_orphan_block *orphan_blk;
|
|
|
|
page = f2fs_get_meta_page(sbi, start_blk + i);
|
|
if (IS_ERR(page)) {
|
|
err = PTR_ERR(page);
|
|
goto out;
|
|
}
|
|
|
|
orphan_blk = (struct f2fs_orphan_block *)page_address(page);
|
|
for (j = 0; j < le32_to_cpu(orphan_blk->entry_count); j++) {
|
|
nid_t ino = le32_to_cpu(orphan_blk->ino[j]);
|
|
err = recover_orphan_inode(sbi, ino);
|
|
if (err) {
|
|
f2fs_put_page(page, 1);
|
|
goto out;
|
|
}
|
|
}
|
|
f2fs_put_page(page, 1);
|
|
}
|
|
/* clear Orphan Flag */
|
|
clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
|
|
out:
|
|
set_sbi_flag(sbi, SBI_IS_RECOVERED);
|
|
|
|
#ifdef CONFIG_QUOTA
|
|
/* Turn quotas off */
|
|
if (quota_enabled)
|
|
f2fs_quota_off_umount(sbi->sb);
|
|
#endif
|
|
sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
|
|
|
|
return err;
|
|
}
|
|
|
|
static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
|
|
{
|
|
struct list_head *head;
|
|
struct f2fs_orphan_block *orphan_blk = NULL;
|
|
unsigned int nentries = 0;
|
|
unsigned short index = 1;
|
|
unsigned short orphan_blocks;
|
|
struct page *page = NULL;
|
|
struct ino_entry *orphan = NULL;
|
|
struct inode_management *im = &sbi->im[ORPHAN_INO];
|
|
|
|
orphan_blocks = GET_ORPHAN_BLOCKS(im->ino_num);
|
|
|
|
/*
|
|
* we don't need to do spin_lock(&im->ino_lock) here, since all the
|
|
* orphan inode operations are covered under f2fs_lock_op().
|
|
* And, spin_lock should be avoided due to page operations below.
|
|
*/
|
|
head = &im->ino_list;
|
|
|
|
/* loop for each orphan inode entry and write them in Jornal block */
|
|
list_for_each_entry(orphan, head, list) {
|
|
if (!page) {
|
|
page = f2fs_grab_meta_page(sbi, start_blk++);
|
|
orphan_blk =
|
|
(struct f2fs_orphan_block *)page_address(page);
|
|
memset(orphan_blk, 0, sizeof(*orphan_blk));
|
|
}
|
|
|
|
orphan_blk->ino[nentries++] = cpu_to_le32(orphan->ino);
|
|
|
|
if (nentries == F2FS_ORPHANS_PER_BLOCK) {
|
|
/*
|
|
* an orphan block is full of 1020 entries,
|
|
* then we need to flush current orphan blocks
|
|
* and bring another one in memory
|
|
*/
|
|
orphan_blk->blk_addr = cpu_to_le16(index);
|
|
orphan_blk->blk_count = cpu_to_le16(orphan_blocks);
|
|
orphan_blk->entry_count = cpu_to_le32(nentries);
|
|
set_page_dirty(page);
|
|
f2fs_put_page(page, 1);
|
|
index++;
|
|
nentries = 0;
|
|
page = NULL;
|
|
}
|
|
}
|
|
|
|
if (page) {
|
|
orphan_blk->blk_addr = cpu_to_le16(index);
|
|
orphan_blk->blk_count = cpu_to_le16(orphan_blocks);
|
|
orphan_blk->entry_count = cpu_to_le32(nentries);
|
|
set_page_dirty(page);
|
|
f2fs_put_page(page, 1);
|
|
}
|
|
}
|
|
|
|
static __u32 f2fs_checkpoint_chksum(struct f2fs_sb_info *sbi,
|
|
struct f2fs_checkpoint *ckpt)
|
|
{
|
|
unsigned int chksum_ofs = le32_to_cpu(ckpt->checksum_offset);
|
|
__u32 chksum;
|
|
|
|
chksum = f2fs_crc32(sbi, ckpt, chksum_ofs);
|
|
if (chksum_ofs < CP_CHKSUM_OFFSET) {
|
|
chksum_ofs += sizeof(chksum);
|
|
chksum = f2fs_chksum(sbi, chksum, (__u8 *)ckpt + chksum_ofs,
|
|
F2FS_BLKSIZE - chksum_ofs);
|
|
}
|
|
return chksum;
|
|
}
|
|
|
|
static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
|
|
struct f2fs_checkpoint **cp_block, struct page **cp_page,
|
|
unsigned long long *version)
|
|
{
|
|
size_t crc_offset = 0;
|
|
__u32 crc;
|
|
|
|
*cp_page = f2fs_get_meta_page(sbi, cp_addr);
|
|
if (IS_ERR(*cp_page))
|
|
return PTR_ERR(*cp_page);
|
|
|
|
*cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
|
|
|
|
crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
|
|
if (crc_offset < CP_MIN_CHKSUM_OFFSET ||
|
|
crc_offset > CP_CHKSUM_OFFSET) {
|
|
f2fs_put_page(*cp_page, 1);
|
|
f2fs_warn(sbi, "invalid crc_offset: %zu", crc_offset);
|
|
return -EINVAL;
|
|
}
|
|
|
|
crc = f2fs_checkpoint_chksum(sbi, *cp_block);
|
|
if (crc != cur_cp_crc(*cp_block)) {
|
|
f2fs_put_page(*cp_page, 1);
|
|
f2fs_warn(sbi, "invalid crc value");
|
|
return -EINVAL;
|
|
}
|
|
|
|
*version = cur_cp_version(*cp_block);
|
|
return 0;
|
|
}
|
|
|
|
static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
|
|
block_t cp_addr, unsigned long long *version)
|
|
{
|
|
struct page *cp_page_1 = NULL, *cp_page_2 = NULL;
|
|
struct f2fs_checkpoint *cp_block = NULL;
|
|
unsigned long long cur_version = 0, pre_version = 0;
|
|
unsigned int cp_blocks;
|
|
int err;
|
|
|
|
err = get_checkpoint_version(sbi, cp_addr, &cp_block,
|
|
&cp_page_1, version);
|
|
if (err)
|
|
return NULL;
|
|
|
|
cp_blocks = le32_to_cpu(cp_block->cp_pack_total_block_count);
|
|
|
|
if (cp_blocks > sbi->blocks_per_seg || cp_blocks <= F2FS_CP_PACKS) {
|
|
f2fs_warn(sbi, "invalid cp_pack_total_block_count:%u",
|
|
le32_to_cpu(cp_block->cp_pack_total_block_count));
|
|
goto invalid_cp;
|
|
}
|
|
pre_version = *version;
|
|
|
|
cp_addr += cp_blocks - 1;
|
|
err = get_checkpoint_version(sbi, cp_addr, &cp_block,
|
|
&cp_page_2, version);
|
|
if (err)
|
|
goto invalid_cp;
|
|
cur_version = *version;
|
|
|
|
if (cur_version == pre_version) {
|
|
*version = cur_version;
|
|
f2fs_put_page(cp_page_2, 1);
|
|
return cp_page_1;
|
|
}
|
|
f2fs_put_page(cp_page_2, 1);
|
|
invalid_cp:
|
|
f2fs_put_page(cp_page_1, 1);
|
|
return NULL;
|
|
}
|
|
|
|
int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
|
{
|
|
struct f2fs_checkpoint *cp_block;
|
|
struct f2fs_super_block *fsb = sbi->raw_super;
|
|
struct page *cp1, *cp2, *cur_page;
|
|
unsigned long blk_size = sbi->blocksize;
|
|
unsigned long long cp1_version = 0, cp2_version = 0;
|
|
unsigned long long cp_start_blk_no;
|
|
unsigned int cp_blks = 1 + __cp_payload(sbi);
|
|
block_t cp_blk_no;
|
|
int i;
|
|
int err;
|
|
|
|
sbi->ckpt = f2fs_kvzalloc(sbi, array_size(blk_size, cp_blks),
|
|
GFP_KERNEL);
|
|
if (!sbi->ckpt)
|
|
return -ENOMEM;
|
|
/*
|
|
* Finding out valid cp block involves read both
|
|
* sets( cp pack 1 and cp pack 2)
|
|
*/
|
|
cp_start_blk_no = le32_to_cpu(fsb->cp_blkaddr);
|
|
cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version);
|
|
|
|
/* The second checkpoint pack should start at the next segment */
|
|
cp_start_blk_no += ((unsigned long long)1) <<
|
|
le32_to_cpu(fsb->log_blocks_per_seg);
|
|
cp2 = validate_checkpoint(sbi, cp_start_blk_no, &cp2_version);
|
|
|
|
if (cp1 && cp2) {
|
|
if (ver_after(cp2_version, cp1_version))
|
|
cur_page = cp2;
|
|
else
|
|
cur_page = cp1;
|
|
} else if (cp1) {
|
|
cur_page = cp1;
|
|
} else if (cp2) {
|
|
cur_page = cp2;
|
|
} else {
|
|
err = -EFSCORRUPTED;
|
|
goto fail_no_cp;
|
|
}
|
|
|
|
cp_block = (struct f2fs_checkpoint *)page_address(cur_page);
|
|
memcpy(sbi->ckpt, cp_block, blk_size);
|
|
|
|
if (cur_page == cp1)
|
|
sbi->cur_cp_pack = 1;
|
|
else
|
|
sbi->cur_cp_pack = 2;
|
|
|
|
/* Sanity checking of checkpoint */
|
|
if (f2fs_sanity_check_ckpt(sbi)) {
|
|
err = -EFSCORRUPTED;
|
|
goto free_fail_no_cp;
|
|
}
|
|
|
|
if (cp_blks <= 1)
|
|
goto done;
|
|
|
|
cp_blk_no = le32_to_cpu(fsb->cp_blkaddr);
|
|
if (cur_page == cp2)
|
|
cp_blk_no += 1 << le32_to_cpu(fsb->log_blocks_per_seg);
|
|
|
|
for (i = 1; i < cp_blks; i++) {
|
|
void *sit_bitmap_ptr;
|
|
unsigned char *ckpt = (unsigned char *)sbi->ckpt;
|
|
|
|
cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i);
|
|
if (IS_ERR(cur_page)) {
|
|
err = PTR_ERR(cur_page);
|
|
goto free_fail_no_cp;
|
|
}
|
|
sit_bitmap_ptr = page_address(cur_page);
|
|
memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size);
|
|
f2fs_put_page(cur_page, 1);
|
|
}
|
|
done:
|
|
f2fs_put_page(cp1, 1);
|
|
f2fs_put_page(cp2, 1);
|
|
return 0;
|
|
|
|
free_fail_no_cp:
|
|
f2fs_put_page(cp1, 1);
|
|
f2fs_put_page(cp2, 1);
|
|
fail_no_cp:
|
|
kvfree(sbi->ckpt);
|
|
return err;
|
|
}
|
|
|
|
static void __add_dirty_inode(struct inode *inode, enum inode_type type)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
|
int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE;
|
|
|
|
if (is_inode_flag_set(inode, flag))
|
|
return;
|
|
|
|
set_inode_flag(inode, flag);
|
|
if (!f2fs_is_volatile_file(inode))
|
|
list_add_tail(&F2FS_I(inode)->dirty_list,
|
|
&sbi->inode_list[type]);
|
|
stat_inc_dirty_inode(sbi, type);
|
|
}
|
|
|
|
static void __remove_dirty_inode(struct inode *inode, enum inode_type type)
|
|
{
|
|
int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE;
|
|
|
|
if (get_dirty_pages(inode) || !is_inode_flag_set(inode, flag))
|
|
return;
|
|
|
|
list_del_init(&F2FS_I(inode)->dirty_list);
|
|
clear_inode_flag(inode, flag);
|
|
stat_dec_dirty_inode(F2FS_I_SB(inode), type);
|
|
}
|
|
|
|
void f2fs_update_dirty_page(struct inode *inode, struct page *page)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
|
enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
|
|
|
|
if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
|
|
!S_ISLNK(inode->i_mode))
|
|
return;
|
|
|
|
spin_lock(&sbi->inode_lock[type]);
|
|
if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH))
|
|
__add_dirty_inode(inode, type);
|
|
inode_inc_dirty_pages(inode);
|
|
spin_unlock(&sbi->inode_lock[type]);
|
|
|
|
f2fs_set_page_private(page, 0);
|
|
f2fs_trace_pid(page);
|
|
}
|
|
|
|
void f2fs_remove_dirty_inode(struct inode *inode)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
|
enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
|
|
|
|
if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
|
|
!S_ISLNK(inode->i_mode))
|
|
return;
|
|
|
|
if (type == FILE_INODE && !test_opt(sbi, DATA_FLUSH))
|
|
return;
|
|
|
|
spin_lock(&sbi->inode_lock[type]);
|
|
__remove_dirty_inode(inode, type);
|
|
spin_unlock(&sbi->inode_lock[type]);
|
|
}
|
|
|
|
int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type)
|
|
{
|
|
struct list_head *head;
|
|
struct inode *inode;
|
|
struct f2fs_inode_info *fi;
|
|
bool is_dir = (type == DIR_INODE);
|
|
unsigned long ino = 0;
|
|
|
|
trace_f2fs_sync_dirty_inodes_enter(sbi->sb, is_dir,
|
|
get_pages(sbi, is_dir ?
|
|
F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA));
|
|
retry:
|
|
if (unlikely(f2fs_cp_error(sbi))) {
|
|
trace_f2fs_sync_dirty_inodes_exit(sbi->sb, is_dir,
|
|
get_pages(sbi, is_dir ?
|
|
F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA));
|
|
return -EIO;
|
|
}
|
|
|
|
spin_lock(&sbi->inode_lock[type]);
|
|
|
|
head = &sbi->inode_list[type];
|
|
if (list_empty(head)) {
|
|
spin_unlock(&sbi->inode_lock[type]);
|
|
trace_f2fs_sync_dirty_inodes_exit(sbi->sb, is_dir,
|
|
get_pages(sbi, is_dir ?
|
|
F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA));
|
|
return 0;
|
|
}
|
|
fi = list_first_entry(head, struct f2fs_inode_info, dirty_list);
|
|
inode = igrab(&fi->vfs_inode);
|
|
spin_unlock(&sbi->inode_lock[type]);
|
|
if (inode) {
|
|
unsigned long cur_ino = inode->i_ino;
|
|
|
|
F2FS_I(inode)->cp_task = current;
|
|
|
|
filemap_fdatawrite(inode->i_mapping);
|
|
|
|
F2FS_I(inode)->cp_task = NULL;
|
|
|
|
iput(inode);
|
|
/* We need to give cpu to another writers. */
|
|
if (ino == cur_ino)
|
|
cond_resched();
|
|
else
|
|
ino = cur_ino;
|
|
} else {
|
|
/*
|
|
* We should submit bio, since it exists several
|
|
* wribacking dentry pages in the freeing inode.
|
|
*/
|
|
f2fs_submit_merged_write(sbi, DATA);
|
|
cond_resched();
|
|
}
|
|
goto retry;
|
|
}
|
|
|
|
int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
|
|
{
|
|
struct list_head *head = &sbi->inode_list[DIRTY_META];
|
|
struct inode *inode;
|
|
struct f2fs_inode_info *fi;
|
|
s64 total = get_pages(sbi, F2FS_DIRTY_IMETA);
|
|
|
|
while (total--) {
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
|
|
spin_lock(&sbi->inode_lock[DIRTY_META]);
|
|
if (list_empty(head)) {
|
|
spin_unlock(&sbi->inode_lock[DIRTY_META]);
|
|
return 0;
|
|
}
|
|
fi = list_first_entry(head, struct f2fs_inode_info,
|
|
gdirty_list);
|
|
inode = igrab(&fi->vfs_inode);
|
|
spin_unlock(&sbi->inode_lock[DIRTY_META]);
|
|
if (inode) {
|
|
sync_inode_metadata(inode, 0);
|
|
|
|
/* it's on eviction */
|
|
if (is_inode_flag_set(inode, FI_DIRTY_INODE))
|
|
f2fs_update_inode_page(inode);
|
|
iput(inode);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void __prepare_cp_block(struct f2fs_sb_info *sbi)
|
|
{
|
|
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
|
struct f2fs_nm_info *nm_i = NM_I(sbi);
|
|
nid_t last_nid = nm_i->next_scan_nid;
|
|
|
|
next_free_nid(sbi, &last_nid);
|
|
ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
|
|
ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
|
|
ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
|
|
ckpt->next_free_nid = cpu_to_le32(last_nid);
|
|
}
|
|
|
|
static bool __need_flush_quota(struct f2fs_sb_info *sbi)
|
|
{
|
|
bool ret = false;
|
|
|
|
if (!is_journalled_quota(sbi))
|
|
return false;
|
|
|
|
if (!down_write_trylock(&sbi->quota_sem))
|
|
return true;
|
|
if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) {
|
|
ret = false;
|
|
} else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) {
|
|
ret = false;
|
|
} else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH)) {
|
|
clear_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
|
|
ret = true;
|
|
} else if (get_pages(sbi, F2FS_DIRTY_QDATA)) {
|
|
ret = true;
|
|
}
|
|
up_write(&sbi->quota_sem);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Freeze all the FS-operations for checkpoint.
|
|
*/
|
|
static int block_operations(struct f2fs_sb_info *sbi)
|
|
{
|
|
struct writeback_control wbc = {
|
|
.sync_mode = WB_SYNC_ALL,
|
|
.nr_to_write = LONG_MAX,
|
|
.for_reclaim = 0,
|
|
};
|
|
int err = 0, cnt = 0;
|
|
|
|
/*
|
|
* Let's flush inline_data in dirty node pages.
|
|
*/
|
|
f2fs_flush_inline_data(sbi);
|
|
|
|
retry_flush_quotas:
|
|
f2fs_lock_all(sbi);
|
|
if (__need_flush_quota(sbi)) {
|
|
int locked;
|
|
|
|
if (++cnt > DEFAULT_RETRY_QUOTA_FLUSH_COUNT) {
|
|
set_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
|
|
set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
|
|
goto retry_flush_dents;
|
|
}
|
|
f2fs_unlock_all(sbi);
|
|
|
|
/* only failed during mount/umount/freeze/quotactl */
|
|
locked = down_read_trylock(&sbi->sb->s_umount);
|
|
f2fs_quota_sync(sbi->sb, -1);
|
|
if (locked)
|
|
up_read(&sbi->sb->s_umount);
|
|
cond_resched();
|
|
goto retry_flush_quotas;
|
|
}
|
|
|
|
retry_flush_dents:
|
|
/* write all the dirty dentry pages */
|
|
if (get_pages(sbi, F2FS_DIRTY_DENTS)) {
|
|
f2fs_unlock_all(sbi);
|
|
err = f2fs_sync_dirty_inodes(sbi, DIR_INODE);
|
|
if (err)
|
|
return err;
|
|
cond_resched();
|
|
goto retry_flush_quotas;
|
|
}
|
|
|
|
/*
|
|
* POR: we should ensure that there are no dirty node pages
|
|
* until finishing nat/sit flush. inode->i_blocks can be updated.
|
|
*/
|
|
down_write(&sbi->node_change);
|
|
|
|
if (get_pages(sbi, F2FS_DIRTY_IMETA)) {
|
|
up_write(&sbi->node_change);
|
|
f2fs_unlock_all(sbi);
|
|
err = f2fs_sync_inode_meta(sbi);
|
|
if (err)
|
|
return err;
|
|
cond_resched();
|
|
goto retry_flush_quotas;
|
|
}
|
|
|
|
retry_flush_nodes:
|
|
down_write(&sbi->node_write);
|
|
|
|
if (get_pages(sbi, F2FS_DIRTY_NODES)) {
|
|
up_write(&sbi->node_write);
|
|
atomic_inc(&sbi->wb_sync_req[NODE]);
|
|
err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
|
|
atomic_dec(&sbi->wb_sync_req[NODE]);
|
|
if (err) {
|
|
up_write(&sbi->node_change);
|
|
f2fs_unlock_all(sbi);
|
|
return err;
|
|
}
|
|
cond_resched();
|
|
goto retry_flush_nodes;
|
|
}
|
|
|
|
/*
|
|
* sbi->node_change is used only for AIO write_begin path which produces
|
|
* dirty node blocks and some checkpoint values by block allocation.
|
|
*/
|
|
__prepare_cp_block(sbi);
|
|
up_write(&sbi->node_change);
|
|
return err;
|
|
}
|
|
|
|
static void unblock_operations(struct f2fs_sb_info *sbi)
|
|
{
|
|
up_write(&sbi->node_write);
|
|
f2fs_unlock_all(sbi);
|
|
}
|
|
|
|
void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
|
|
{
|
|
DEFINE_WAIT(wait);
|
|
|
|
for (;;) {
|
|
if (!get_pages(sbi, type))
|
|
break;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi) &&
|
|
!is_sbi_flag_set(sbi, SBI_IS_CLOSE)))
|
|
break;
|
|
|
|
if (type == F2FS_DIRTY_META)
|
|
f2fs_sync_meta_pages(sbi, META, LONG_MAX,
|
|
FS_CP_META_IO);
|
|
else if (type == F2FS_WB_CP_DATA)
|
|
f2fs_submit_merged_write(sbi, DATA);
|
|
|
|
prepare_to_wait(&sbi->cp_wait, &wait, TASK_UNINTERRUPTIBLE);
|
|
io_schedule_timeout(DEFAULT_IO_TIMEOUT);
|
|
}
|
|
finish_wait(&sbi->cp_wait, &wait);
|
|
}
|
|
|
|
static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|
{
|
|
unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num;
|
|
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&sbi->cp_lock, flags);
|
|
|
|
if ((cpc->reason & CP_UMOUNT) &&
|
|
le32_to_cpu(ckpt->cp_pack_total_block_count) >
|
|
sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
|
|
disable_nat_bits(sbi, false);
|
|
|
|
if (cpc->reason & CP_TRIMMED)
|
|
__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
|
|
|
|
if (cpc->reason & CP_UMOUNT)
|
|
__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
|
|
|
|
if (cpc->reason & CP_FASTBOOT)
|
|
__set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
|
|
|
|
if (orphan_num)
|
|
__set_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
|
|
|
|
if (is_sbi_flag_set(sbi, SBI_NEED_FSCK))
|
|
__set_ckpt_flags(ckpt, CP_FSCK_FLAG);
|
|
|
|
if (is_sbi_flag_set(sbi, SBI_IS_RESIZEFS))
|
|
__set_ckpt_flags(ckpt, CP_RESIZEFS_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_RESIZEFS_FLAG);
|
|
|
|
if (is_sbi_flag_set(sbi, SBI_CP_DISABLED))
|
|
__set_ckpt_flags(ckpt, CP_DISABLED_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_DISABLED_FLAG);
|
|
|
|
if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK))
|
|
__set_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
|
|
|
|
if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH))
|
|
__set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
|
|
|
|
if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR))
|
|
__set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
|
|
|
|
/* set this flag to activate crc|cp_ver for recovery */
|
|
__set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG);
|
|
__clear_ckpt_flags(ckpt, CP_NOCRC_RECOVERY_FLAG);
|
|
|
|
spin_unlock_irqrestore(&sbi->cp_lock, flags);
|
|
}
|
|
|
|
static void commit_checkpoint(struct f2fs_sb_info *sbi,
|
|
void *src, block_t blk_addr)
|
|
{
|
|
struct writeback_control wbc = {
|
|
.for_reclaim = 0,
|
|
};
|
|
|
|
/*
|
|
* pagevec_lookup_tag and lock_page again will take
|
|
* some extra time. Therefore, f2fs_update_meta_pages and
|
|
* f2fs_sync_meta_pages are combined in this function.
|
|
*/
|
|
struct page *page = f2fs_grab_meta_page(sbi, blk_addr);
|
|
int err;
|
|
|
|
f2fs_wait_on_page_writeback(page, META, true, true);
|
|
|
|
memcpy(page_address(page), src, PAGE_SIZE);
|
|
|
|
set_page_dirty(page);
|
|
if (unlikely(!clear_page_dirty_for_io(page)))
|
|
f2fs_bug_on(sbi, 1);
|
|
|
|
/* writeout cp pack 2 page */
|
|
err = __f2fs_write_meta_page(page, &wbc, FS_CP_META_IO);
|
|
if (unlikely(err && f2fs_cp_error(sbi))) {
|
|
f2fs_put_page(page, 1);
|
|
return;
|
|
}
|
|
|
|
f2fs_bug_on(sbi, err);
|
|
f2fs_put_page(page, 0);
|
|
|
|
/* submit checkpoint (with barrier if NOBARRIER is not set) */
|
|
f2fs_submit_merged_write(sbi, META_FLUSH);
|
|
}
|
|
|
|
static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|
{
|
|
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
|
struct f2fs_nm_info *nm_i = NM_I(sbi);
|
|
unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num, flags;
|
|
block_t start_blk;
|
|
unsigned int data_sum_blocks, orphan_blocks;
|
|
__u32 crc32 = 0;
|
|
int i;
|
|
int cp_payload_blks = __cp_payload(sbi);
|
|
struct super_block *sb = sbi->sb;
|
|
struct curseg_info *seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
|
|
u64 kbytes_written;
|
|
int err;
|
|
|
|
/* Flush all the NAT/SIT pages */
|
|
f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO);
|
|
|
|
/* start to update checkpoint, cp ver is already updated previously */
|
|
ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi, true));
|
|
ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
|
|
for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
|
|
ckpt->cur_node_segno[i] =
|
|
cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
|
|
ckpt->cur_node_blkoff[i] =
|
|
cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
|
|
ckpt->alloc_type[i + CURSEG_HOT_NODE] =
|
|
curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
|
|
}
|
|
for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
|
|
ckpt->cur_data_segno[i] =
|
|
cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
|
|
ckpt->cur_data_blkoff[i] =
|
|
cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
|
|
ckpt->alloc_type[i + CURSEG_HOT_DATA] =
|
|
curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
|
|
}
|
|
|
|
/* 2 cp + n data seg summary + orphan inode blocks */
|
|
data_sum_blocks = f2fs_npages_for_summary_flush(sbi, false);
|
|
spin_lock_irqsave(&sbi->cp_lock, flags);
|
|
if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
|
|
__set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
|
|
else
|
|
__clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
|
|
spin_unlock_irqrestore(&sbi->cp_lock, flags);
|
|
|
|
orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num);
|
|
ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks +
|
|
orphan_blocks);
|
|
|
|
if (__remain_node_summaries(cpc->reason))
|
|
ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS+
|
|
cp_payload_blks + data_sum_blocks +
|
|
orphan_blocks + NR_CURSEG_NODE_TYPE);
|
|
else
|
|
ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS +
|
|
cp_payload_blks + data_sum_blocks +
|
|
orphan_blocks);
|
|
|
|
/* update ckpt flag for checkpoint */
|
|
update_ckpt_flags(sbi, cpc);
|
|
|
|
/* update SIT/NAT bitmap */
|
|
get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP));
|
|
get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP));
|
|
|
|
crc32 = f2fs_checkpoint_chksum(sbi, ckpt);
|
|
*((__le32 *)((unsigned char *)ckpt +
|
|
le32_to_cpu(ckpt->checksum_offset)))
|
|
= cpu_to_le32(crc32);
|
|
|
|
start_blk = __start_cp_next_addr(sbi);
|
|
|
|
/* write nat bits */
|
|
if (enabled_nat_bits(sbi, cpc)) {
|
|
__u64 cp_ver = cur_cp_version(ckpt);
|
|
block_t blk;
|
|
|
|
cp_ver |= ((__u64)crc32 << 32);
|
|
*(__le64 *)nm_i->nat_bits = cpu_to_le64(cp_ver);
|
|
|
|
blk = start_blk + sbi->blocks_per_seg - nm_i->nat_bits_blocks;
|
|
for (i = 0; i < nm_i->nat_bits_blocks; i++)
|
|
f2fs_update_meta_page(sbi, nm_i->nat_bits +
|
|
(i << F2FS_BLKSIZE_BITS), blk + i);
|
|
}
|
|
|
|
/* write out checkpoint buffer at block 0 */
|
|
f2fs_update_meta_page(sbi, ckpt, start_blk++);
|
|
|
|
for (i = 1; i < 1 + cp_payload_blks; i++)
|
|
f2fs_update_meta_page(sbi, (char *)ckpt + i * F2FS_BLKSIZE,
|
|
start_blk++);
|
|
|
|
if (orphan_num) {
|
|
write_orphan_inodes(sbi, start_blk);
|
|
start_blk += orphan_blocks;
|
|
}
|
|
|
|
f2fs_write_data_summaries(sbi, start_blk);
|
|
start_blk += data_sum_blocks;
|
|
|
|
/* Record write statistics in the hot node summary */
|
|
kbytes_written = sbi->kbytes_written;
|
|
if (sb->s_bdev->bd_part)
|
|
kbytes_written += BD_PART_WRITTEN(sbi);
|
|
|
|
seg_i->journal->info.kbytes_written = cpu_to_le64(kbytes_written);
|
|
|
|
if (__remain_node_summaries(cpc->reason)) {
|
|
f2fs_write_node_summaries(sbi, start_blk);
|
|
start_blk += NR_CURSEG_NODE_TYPE;
|
|
}
|
|
|
|
/* update user_block_counts */
|
|
sbi->last_valid_block_count = sbi->total_valid_block_count;
|
|
percpu_counter_set(&sbi->alloc_valid_block_count, 0);
|
|
|
|
/* Here, we have one bio having CP pack except cp pack 2 page */
|
|
f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO);
|
|
/* Wait for all dirty meta pages to be submitted for IO */
|
|
f2fs_wait_on_all_pages(sbi, F2FS_DIRTY_META);
|
|
|
|
/* wait for previous submitted meta pages writeback */
|
|
f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
|
|
|
|
/* flush all device cache */
|
|
err = f2fs_flush_device_cache(sbi);
|
|
if (err)
|
|
return err;
|
|
|
|
/* barrier and flush checkpoint cp pack 2 page if it can */
|
|
commit_checkpoint(sbi, ckpt, start_blk);
|
|
f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
|
|
|
|
/*
|
|
* invalidate intermediate page cache borrowed from meta inode which are
|
|
* used for migration of encrypted or verity inode's blocks.
|
|
*/
|
|
if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))
|
|
invalidate_mapping_pages(META_MAPPING(sbi),
|
|
MAIN_BLKADDR(sbi), MAX_BLKADDR(sbi) - 1);
|
|
|
|
f2fs_release_ino_entry(sbi, false);
|
|
|
|
f2fs_reset_fsync_node_info(sbi);
|
|
|
|
clear_sbi_flag(sbi, SBI_IS_DIRTY);
|
|
clear_sbi_flag(sbi, SBI_NEED_CP);
|
|
clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
|
|
|
|
spin_lock(&sbi->stat_lock);
|
|
sbi->unusable_block_count = 0;
|
|
spin_unlock(&sbi->stat_lock);
|
|
|
|
__set_cp_next_pack(sbi);
|
|
|
|
/*
|
|
* redirty superblock if metadata like node page or inode cache is
|
|
* updated during writing checkpoint.
|
|
*/
|
|
if (get_pages(sbi, F2FS_DIRTY_NODES) ||
|
|
get_pages(sbi, F2FS_DIRTY_IMETA))
|
|
set_sbi_flag(sbi, SBI_IS_DIRTY);
|
|
|
|
f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_DENTS));
|
|
|
|
return unlikely(f2fs_cp_error(sbi)) ? -EIO : 0;
|
|
}
|
|
|
|
int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|
{
|
|
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
|
unsigned long long ckpt_ver;
|
|
int err = 0;
|
|
|
|
if (f2fs_readonly(sbi->sb) || f2fs_hw_is_readonly(sbi))
|
|
return -EROFS;
|
|
|
|
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
|
if (cpc->reason != CP_PAUSE)
|
|
return 0;
|
|
f2fs_warn(sbi, "Start checkpoint disabled!");
|
|
}
|
|
if (cpc->reason != CP_RESIZE)
|
|
down_write(&sbi->cp_global_sem);
|
|
|
|
if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
|
|
((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
|
|
((cpc->reason & CP_DISCARD) && !sbi->discard_blks)))
|
|
goto out;
|
|
if (unlikely(f2fs_cp_error(sbi))) {
|
|
err = -EIO;
|
|
goto out;
|
|
}
|
|
|
|
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops");
|
|
|
|
err = block_operations(sbi);
|
|
if (err)
|
|
goto out;
|
|
|
|
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops");
|
|
|
|
f2fs_flush_merged_writes(sbi);
|
|
|
|
/* this is the case of multiple fstrims without any changes */
|
|
if (cpc->reason & CP_DISCARD) {
|
|
if (!f2fs_exist_trim_candidates(sbi, cpc)) {
|
|
unblock_operations(sbi);
|
|
goto out;
|
|
}
|
|
|
|
if (NM_I(sbi)->nat_cnt[DIRTY_NAT] == 0 &&
|
|
SIT_I(sbi)->dirty_sentries == 0 &&
|
|
prefree_segments(sbi) == 0) {
|
|
f2fs_flush_sit_entries(sbi, cpc);
|
|
f2fs_clear_prefree_segments(sbi, cpc);
|
|
unblock_operations(sbi);
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* update checkpoint pack index
|
|
* Increase the version number so that
|
|
* SIT entries and seg summaries are written at correct place
|
|
*/
|
|
ckpt_ver = cur_cp_version(ckpt);
|
|
ckpt->checkpoint_ver = cpu_to_le64(++ckpt_ver);
|
|
|
|
/* write cached NAT/SIT entries to NAT/SIT area */
|
|
err = f2fs_flush_nat_entries(sbi, cpc);
|
|
if (err)
|
|
goto stop;
|
|
|
|
f2fs_flush_sit_entries(sbi, cpc);
|
|
|
|
err = do_checkpoint(sbi, cpc);
|
|
if (err)
|
|
f2fs_release_discard_addrs(sbi);
|
|
else
|
|
f2fs_clear_prefree_segments(sbi, cpc);
|
|
stop:
|
|
unblock_operations(sbi);
|
|
stat_inc_cp_count(sbi->stat_info);
|
|
|
|
if (cpc->reason & CP_RECOVERY)
|
|
f2fs_notice(sbi, "checkpoint: version = %llx", ckpt_ver);
|
|
|
|
/* update CP_TIME to trigger checkpoint periodically */
|
|
f2fs_update_time(sbi, CP_TIME);
|
|
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint");
|
|
out:
|
|
if (cpc->reason != CP_RESIZE)
|
|
up_write(&sbi->cp_global_sem);
|
|
return err;
|
|
}
|
|
|
|
void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_INO_ENTRY; i++) {
|
|
struct inode_management *im = &sbi->im[i];
|
|
|
|
INIT_RADIX_TREE(&im->ino_root, GFP_ATOMIC);
|
|
spin_lock_init(&im->ino_lock);
|
|
INIT_LIST_HEAD(&im->ino_list);
|
|
im->ino_num = 0;
|
|
}
|
|
|
|
sbi->max_orphans = (sbi->blocks_per_seg - F2FS_CP_PACKS -
|
|
NR_CURSEG_TYPE - __cp_payload(sbi)) *
|
|
F2FS_ORPHANS_PER_BLOCK;
|
|
}
|
|
|
|
int __init f2fs_create_checkpoint_caches(void)
|
|
{
|
|
ino_entry_slab = f2fs_kmem_cache_create("f2fs_ino_entry",
|
|
sizeof(struct ino_entry));
|
|
if (!ino_entry_slab)
|
|
return -ENOMEM;
|
|
f2fs_inode_entry_slab = f2fs_kmem_cache_create("f2fs_inode_entry",
|
|
sizeof(struct inode_entry));
|
|
if (!f2fs_inode_entry_slab) {
|
|
kmem_cache_destroy(ino_entry_slab);
|
|
return -ENOMEM;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void f2fs_destroy_checkpoint_caches(void)
|
|
{
|
|
kmem_cache_destroy(ino_entry_slab);
|
|
kmem_cache_destroy(f2fs_inode_entry_slab);
|
|
}
|