Changes in 4.19.99 Revert "efi: Fix debugobjects warning on 'efi_rts_work'" xfs: Sanity check flags of Q_XQUOTARM call i2c: stm32f7: rework slave_id allocation i2c: i2c-stm32f7: fix 10-bits check in slave free id search loop mfd: intel-lpss: Add default I2C device properties for Gemini Lake SUNRPC: Fix svcauth_gss_proxy_init() powerpc/pseries: Enable support for ibm,drc-info property powerpc/archrandom: fix arch_get_random_seed_int() tipc: update mon's self addr when node addr generated tipc: fix wrong timeout input for tipc_wait_for_cond() mt7601u: fix bbp version check in mt7601u_wait_bbp_ready crypto: sun4i-ss - fix big endian issues perf map: No need to adjust the long name of modules soc: aspeed: Fix snoop_file_poll()'s return type watchdog: sprd: Fix the incorrect pointer getting from driver data ipmi: Fix memory leak in __ipmi_bmc_register drm/sti: do not remove the drm_bridge that was never added ARM: dts: at91: nattis: set the PRLUD and HIPOW signals low ARM: dts: at91: nattis: make the SD-card slot work ixgbe: don't clear IPsec sa counters on HW clearing drm/virtio: fix bounds check in virtio_gpu_cmd_get_capset() iio: fix position relative kernel version apparmor: Fix network performance issue in aa_label_sk_perm ALSA: hda: fix unused variable warning apparmor: don't try to replace stale label in ptrace access check ARM: qcom_defconfig: Enable MAILBOX firmware: coreboot: Let OF core populate platform device PCI: iproc: Remove PAXC slot check to allow VF support bridge: br_arp_nd_proxy: set icmp6_router if neigh has NTF_ROUTER drm/hisilicon: hibmc: Don't overwrite fb helper surface depth signal/ia64: Use the generic force_sigsegv in setup_frame signal/ia64: Use the force_sig(SIGSEGV,...) in ia64_rt_sigreturn ASoC: wm9712: fix unused variable warning mailbox: mediatek: Add check for possible failure of kzalloc IB/rxe: replace kvfree with vfree IB/hfi1: Add mtu check for operational data VLs genirq/debugfs: Reinstate full OF path for domain name usb: dwc3: add EXTCON dependency for qcom usb: gadget: fsl_udc_core: check allocation return value and cleanup on failure cfg80211: regulatory: make initialization more robust mei: replace POLL* with EPOLL* for write queues. drm/msm: fix unsigned comparison with less than zero of: Fix property name in of_node_get_device_type ALSA: usb-audio: update quirk for B&W PX to remove microphone iwlwifi: nvm: get num of hw addresses from firmware staging: comedi: ni_mio_common: protect register write overflow netfilter: nft_osf: usage from output path is not valid pwm: lpss: Release runtime-pm reference from the driver's remove callback powerpc/pseries/memory-hotplug: Fix return value type of find_aa_index rtlwifi: rtl8821ae: replace _rtl8821ae_mrate_idx_to_arfr_id with generic version RDMA/bnxt_re: Add missing spin lock initialization netfilter: nf_flow_table: do not remove offload when other netns's interface is down powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() tipc: eliminate message disordering during binding table update net: socionext: Add dummy PHY register read in phy_write() drm/sun4i: hdmi: Fix double flag assignation net: hns3: add error handler for hns3_nic_init_vector_data() mlxsw: reg: QEEC: Add minimum shaper fields mlxsw: spectrum: Set minimum shaper on MC TCs NTB: ntb_hw_idt: replace IS_ERR_OR_NULL with regular NULL checks ASoC: wm97xx: fix uninitialized regmap pointer problem ARM: dts: bcm283x: Correct mailbox register sizes pcrypt: use format specifier in kobject_add ASoC: sun8i-codec: add missing route for ADC pinctrl: meson-gxl: remove invalid GPIOX tsin_a pins bus: ti-sysc: Add mcasp optional clocks flag exportfs: fix 'passing zero to ERR_PTR()' warning drm: rcar-du: Fix the return value in case of error in 'rcar_du_crtc_set_crc_source()' drm: rcar-du: Fix vblank initialization net: always initialize pagedlen drm/dp_mst: Skip validating ports during destruction, just ref arm64: dts: meson-gx: Add hdmi_5v regulator as hdmi tx supply arm64: dts: renesas: r8a7795-es1: Add missing power domains to IPMMU nodes net: phy: Fix not to call phy_resume() if PHY is not attached IB/hfi1: Correctly process FECN and BECN in packets OPP: Fix missing debugfs supply directory for OPPs IB/rxe: Fix incorrect cache cleanup in error flow mailbox: ti-msgmgr: Off by one in ti_msgmgr_of_xlate() staging: bcm2835-camera: Abort probe if there is no camera staging: bcm2835-camera: fix module autoloading switchtec: Remove immediate status check after submitting MRPC command ipv6: add missing tx timestamping on IPPROTO_RAW pinctrl: sh-pfc: r8a7740: Add missing REF125CK pin to gether_gmii group pinctrl: sh-pfc: r8a7740: Add missing LCD0 marks to lcd0_data24_1 group pinctrl: sh-pfc: r8a7791: Remove bogus ctrl marks from qspi_data4_b group pinctrl: sh-pfc: r8a7791: Remove bogus marks from vin1_b_data18 group pinctrl: sh-pfc: sh73a0: Add missing TO pin to tpu4_to3 group pinctrl: sh-pfc: r8a7794: Remove bogus IPSR9 field pinctrl: sh-pfc: r8a77970: Add missing MOD_SEL0 field pinctrl: sh-pfc: r8a77980: Add missing MOD_SEL0 field pinctrl: sh-pfc: sh7734: Add missing IPSR11 field pinctrl: sh-pfc: r8a77995: Remove bogus SEL_PWM[0-3]_3 configurations pinctrl: sh-pfc: sh7269: Add missing PCIOR0 field pinctrl: sh-pfc: sh7734: Remove bogus IPSR10 value net: hns3: fix error handling int the hns3_get_vector_ring_chain vxlan: changelink: Fix handling of default remotes Input: nomadik-ske-keypad - fix a loop timeout test fork,memcg: fix crash in free_thread_stack on memcg charge fail clk: highbank: fix refcount leak in hb_clk_init() clk: qoriq: fix refcount leak in clockgen_init() clk: ti: fix refcount leak in ti_dt_clocks_register() clk: socfpga: fix refcount leak clk: samsung: exynos4: fix refcount leak in exynos4_get_xom() clk: imx6q: fix refcount leak in imx6q_clocks_init() clk: imx6sx: fix refcount leak in imx6sx_clocks_init() clk: imx7d: fix refcount leak in imx7d_clocks_init() clk: vf610: fix refcount leak in vf610_clocks_init() clk: armada-370: fix refcount leak in a370_clk_init() clk: kirkwood: fix refcount leak in kirkwood_clk_init() clk: armada-xp: fix refcount leak in axp_clk_init() clk: mv98dx3236: fix refcount leak in mv98dx3236_clk_init() clk: dove: fix refcount leak in dove_clk_init() MIPS: BCM63XX: drop unused and broken DSP platform device arm64: defconfig: Re-enable bcm2835-thermal driver remoteproc: qcom: q6v5-mss: Add missing clocks for MSM8996 remoteproc: qcom: q6v5-mss: Add missing regulator for MSM8996 drm: Fix error handling in drm_legacy_addctx ARM: dts: r8a7743: Remove generic compatible string from iic3 drm/etnaviv: fix some off by one bugs drm/fb-helper: generic: Fix setup error path fork, memcg: fix cached_stacks case IB/usnic: Fix out of bounds index check in query pkey RDMA/ocrdma: Fix out of bounds index check in query pkey RDMA/qedr: Fix out of bounds index check in query pkey drm/shmob: Fix return value check in shmob_drm_probe arm64: dts: apq8016-sbc: Increase load on l11 for SDCARD spi: cadence: Correct initialisation of runtime PM RDMA/iw_cxgb4: Fix the unchecked ep dereference net: phy: micrel: set soft_reset callback to genphy_soft_reset for KSZ9031 memory: tegra: Don't invoke Tegra30+ specific memory timing setup on Tegra20 drm/etnaviv: NULL vs IS_ERR() buf in etnaviv_core_dump() media: s5p-jpeg: Correct step and max values for V4L2_CID_JPEG_RESTART_INTERVAL kbuild: mark prepare0 as PHONY to fix external module build crypto: brcm - Fix some set-but-not-used warning crypto: tgr192 - fix unaligned memory access ASoC: imx-sgtl5000: put of nodes if finding codec fails IB/iser: Pass the correct number of entries for dma mapped SGL net: hns3: fix wrong combined count returned by ethtool -l media: tw9910: Unregister subdevice with v4l2-async IB/mlx5: Don't override existing ip_protocol rtc: cmos: ignore bogus century byte spi/topcliff_pch: Fix potential NULL dereference on allocation error net: hns3: fix bug of ethtool_ops.get_channels for VF ARM: dts: sun8i-a23-a33: Move NAND controller device node to sort by address clk: sunxi-ng: sun8i-a23: Enable PLL-MIPI LDOs when ungating it iwlwifi: mvm: avoid possible access out of array. net/mlx5: Take lock with IRQs disabled to avoid deadlock ip_tunnel: Fix route fl4 init in ip_md_tunnel_xmit arm64: dts: allwinner: h6: Move GIC device node fix base address ordering iwlwifi: mvm: fix A-MPDU reference assignment bus: ti-sysc: Fix timer handling with drop pm_runtime_irq_safe() tty: ipwireless: Fix potential NULL pointer dereference driver: uio: fix possible memory leak in __uio_register_device driver: uio: fix possible use-after-free in __uio_register_device crypto: crypto4xx - Fix wrong ppc4xx_trng_probe()/ppc4xx_trng_remove() arguments driver core: Fix DL_FLAG_AUTOREMOVE_SUPPLIER device link flag handling driver core: Avoid careless re-use of existing device links driver core: Do not resume suppliers under device_links_write_lock() driver core: Fix handling of runtime PM flags in device_link_add() driver core: Do not call rpm_put_suppliers() in pm_runtime_drop_link() ARM: dts: lpc32xx: add required clocks property to keypad device node ARM: dts: lpc32xx: reparent keypad controller to SIC1 ARM: dts: lpc32xx: fix ARM PrimeCell LCD controller variant ARM: dts: lpc32xx: fix ARM PrimeCell LCD controller clocks property ARM: dts: lpc32xx: phy3250: fix SD card regulator voltage drm/xen-front: Fix mmap attributes for display buffers iwlwifi: mvm: fix RSS config command staging: most: cdev: add missing check for cdev_add failure clk: ingenic: jz4740: Fix gating of UDC clock rtc: ds1672: fix unintended sign extension thermal: mediatek: fix register index error arm64: dts: msm8916: remove bogus argument to the cpu clock ath10k: fix dma unmap direction for management frames net: phy: fixed_phy: Fix fixed_phy not checking GPIO rtc: ds1307: rx8130: Fix alarm handling net/smc: original socket family in inet_sock_diag rtc: 88pm860x: fix unintended sign extension rtc: 88pm80x: fix unintended sign extension rtc: pm8xxx: fix unintended sign extension fbdev: chipsfb: remove set but not used variable 'size' iw_cxgb4: use tos when importing the endpoint iw_cxgb4: use tos when finding ipv6 routes ipmi: kcs_bmc: handle devm_kasprintf() failure case xsk: add missing smp_rmb() in xsk_mmap drm/etnaviv: potential NULL dereference ntb_hw_switchtec: debug print 64bit aligned crosslink BAR Numbers ntb_hw_switchtec: NT req id mapping table register entry number should be 512 pinctrl: sh-pfc: emev2: Add missing pinmux functions pinctrl: sh-pfc: r8a7791: Fix scifb2_data_c pin group pinctrl: sh-pfc: r8a7792: Fix vin1_data18_b pin group pinctrl: sh-pfc: sh73a0: Fix fsic_spdif pin groups RDMA/mlx5: Fix memory leak in case we fail to add an IB device driver core: Fix possible supplier PM-usage counter imbalance PCI: endpoint: functions: Use memcpy_fromio()/memcpy_toio() usb: phy: twl6030-usb: fix possible use-after-free on remove block: don't use bio->bi_vcnt to figure out segment number keys: Timestamp new keys net: dsa: b53: Fix default VLAN ID net: dsa: b53: Properly account for VLAN filtering net: dsa: b53: Do not program CPU port's PVID mt76: usb: fix possible memory leak in mt76u_buf_free media: sh: migor: Include missing dma-mapping header vfio_pci: Enable memory accesses before calling pci_map_rom hwmon: (pmbus/tps53679) Fix driver info initialization in probe routine mdio_bus: Fix PTR_ERR() usage after initialization to constant KVM: PPC: Release all hardware TCE tables attached to a group staging: r8822be: check kzalloc return or bail dmaengine: mv_xor: Use correct device for DMA API cdc-wdm: pass return value of recover_from_urb_loss brcmfmac: create debugfs files for bus-specific layer regulator: pv88060: Fix array out-of-bounds access regulator: pv88080: Fix array out-of-bounds access regulator: pv88090: Fix array out-of-bounds access net: dsa: qca8k: Enable delay for RGMII_ID mode net/mlx5: Delete unused FPGA QPN variable drm/nouveau/bios/ramcfg: fix missing parentheses when calculating RON drm/nouveau/pmu: don't print reply values if exec is false drm/nouveau: fix missing break in switch statement driver core: Fix PM-runtime for links added during consumer probe ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of() net: dsa: fix unintended change of bridge interface STP state fs/nfs: Fix nfs_parse_devname to not modify it's argument staging: rtlwifi: Use proper enum for return in halmac_parse_psd_data_88xx powerpc/64s: Fix logic when handling unknown CPU features NFS: Fix a soft lockup in the delegation recovery code perf: Copy parent's address filter offsets on clone perf, pt, coresight: Fix address filters for vmas with non-zero offset clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable clocksource/drivers/exynos_mct: Fix error path in timer resources initialization platform/x86: wmi: fix potential null pointer dereference NFS/pnfs: Bulk destroy of layouts needs to be safe w.r.t. umount mmc: sdhci-brcmstb: handle mmc_of_parse() errors during probe iommu: Fix IOMMU debugfs fallout ARM: 8847/1: pm: fix HYP/SVC mode mismatch when MCPM is used ARM: 8848/1: virt: Align GIC version check with arm64 counterpart ARM: 8849/1: NOMMU: Fix encodings for PMSAv8's PRBAR4/PRLAR4 regulator: wm831x-dcdc: Fix list of wm831x_dcdc_ilim from mA to uA ath10k: Fix length of wmi tlv command for protected mgmt frames netfilter: nft_set_hash: fix lookups with fixed size hash on big endian netfilter: nft_set_hash: bogus element self comparison from deactivation path net: sched: act_csum: Fix csum calc for tagged packets hwrng: bcm2835 - fix probe as platform device iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() NFS: Add missing encode / decode sequence_maxsz to v4.2 operations NFSv4/flexfiles: Fix invalid deref in FF_LAYOUT_DEVID_NODE() net: aquantia: fixed instack structure overflow powerpc/mm: Check secondary hash page table media: dvb/earth-pt1: fix wrong initialization for demod blocks rbd: clear ->xferred on error from rbd_obj_issue_copyup() PCI: Fix "try" semantics of bus and slot reset nios2: ksyms: Add missing symbol exports x86/mm: Remove unused variable 'cpu' scsi: megaraid_sas: reduce module load time nfp: fix simple vNIC mailbox length drivers/rapidio/rio_cm.c: fix potential oops in riocm_ch_listen() xen, cpu_hotplug: Prevent an out of bounds access net/mlx5: Fix multiple updates of steering rules in parallel net/mlx5e: IPoIB, Fix RX checksum statistics update net: sh_eth: fix a missing check of of_get_phy_mode regulator: lp87565: Fix missing register for LP87565_BUCK_0 soc: amlogic: gx-socinfo: Add mask for each SoC packages media: ivtv: update *pos correctly in ivtv_read_pos() media: cx18: update *pos correctly in cx18_read_pos() media: wl128x: Fix an error code in fm_download_firmware() media: cx23885: check allocation return regulator: tps65086: Fix tps65086_ldoa1_ranges for selector 0xB crypto: ccree - reduce kernel stack usage with clang jfs: fix bogus variable self-initialization tipc: tipc clang warning m68k: mac: Fix VIA timer counter accesses ARM: dts: sun8i: a33: Reintroduce default pinctrl muxing arm64: dts: allwinner: a64: Add missing PIO clocks ARM: dts: sun9i: optimus: Fix fixed-regulators net: phy: don't clear BMCR in genphy_soft_reset ARM: OMAP2+: Fix potentially uninitialized return value for _setup_reset() net: dsa: Avoid null pointer when failing to connect to PHY soc: qcom: cmd-db: Fix an error code in cmd_db_dev_probe() media: davinci-isif: avoid uninitialized variable use media: tw5864: Fix possible NULL pointer dereference in tw5864_handle_frame spi: tegra114: clear packed bit for unpacked mode spi: tegra114: fix for unpacked mode transfers spi: tegra114: terminate dma and reset on transfer timeout spi: tegra114: flush fifos spi: tegra114: configure dma burst size to fifo trig level bus: ti-sysc: Fix sysc_unprepare() when no clocks have been allocated soc/fsl/qe: Fix an error code in qe_pin_request() spi: bcm2835aux: fix driver to not allow 65535 (=-1) cs-gpios drm/fb-helper: generic: Call drm_client_add() after setup is done arm64/vdso: don't leak kernel addresses rtc: Fix timestamp value for RTC_TIMESTAMP_BEGIN_1900 rtc: mt6397: Don't call irq_dispose_mapping. ehea: Fix a copy-paste err in ehea_init_port_res bpf: Add missed newline in verifier verbose log drm/vmwgfx: Remove set but not used variable 'restart' scsi: qla2xxx: Unregister chrdev if module initialization fails of: use correct function prototype for of_overlay_fdt_apply() net/sched: cbs: fix port_rate miscalculation clk: qcom: Skip halt checks on gcc_pcie_0_pipe_clk for 8998 ACPI: button: reinitialize button state upon resume firmware: arm_scmi: fix of_node leak in scmi_mailbox_check rxrpc: Fix detection of out of order acks scsi: target/core: Fix a race condition in the LUN lookup code brcmfmac: fix leak of mypkt on error return path ARM: pxa: ssp: Fix "WARNING: invalid free of devm_ allocated data" PCI: rockchip: Fix rockchip_pcie_ep_assert_intx() bitwise operations net: hns3: fix for vport->bw_limit overflow problem hwmon: (w83627hf) Use request_muxed_region for Super-IO accesses perf/core: Fix the address filtering fix staging: android: vsoc: fix copy_from_user overrun PCI: dwc: Fix dw_pcie_ep_find_capability() to return correct capability offset soc: amlogic: meson-gx-pwrc-vpu: Fix power on/off register bitmask platform/x86: alienware-wmi: fix kfree on potentially uninitialized pointer tipc: set sysctl_tipc_rmem and named_timeout right range usb: typec: tcpm: Notify the tcpc to start connection-detection for SRPs selftests/ipc: Fix msgque compiler warnings net: hns3: fix loop condition of hns3_get_tx_timeo_queue_info() powerpc: vdso: Make vdso32 installation conditional in vdso_install ARM: dts: ls1021: Fix SGMII PCS link remaining down after PHY disconnect media: ov2659: fix unbalanced mutex_lock/unlock 6lowpan: Off by one handling ->nexthdr dmaengine: axi-dmac: Don't check the number of frames for alignment ALSA: usb-audio: Handle the error from snd_usb_mixer_apply_create_quirk() afs: Fix AFS file locking to allow fine grained locks afs: Further fix file locking NFS: Don't interrupt file writeout due to fatal errors coresight: catu: fix clang build warning s390/kexec_file: Fix potential segment overlap in ELF loader irqchip/gic-v3-its: fix some definitions of inner cacheability attributes scsi: qla2xxx: Fix a format specifier scsi: qla2xxx: Fix error handling in qlt_alloc_qfull_cmd() scsi: qla2xxx: Avoid that qlt_send_resp_ctio() corrupts memory KVM: PPC: Book3S HV: Fix lockdep warning when entering the guest netfilter: nft_flow_offload: add entry to flowtable after confirmation PCI: iproc: Enable iProc config read for PAXBv2 ARM: dts: logicpd-som-lv: Fix MMC1 card detect packet: in recvmsg msg_name return at least sizeof sockaddr_ll ASoC: fix valid stream condition usb: gadget: fsl: fix link error against usb-gadget module dwc2: gadget: Fix completed transfer size calculation in DDMA IB/mlx5: Add missing XRC options to QP optional params mask RDMA/rxe: Consider skb reserve space based on netdev of GID iommu/vt-d: Make kernel parameter igfx_off work with vIOMMU net: ena: fix swapped parameters when calling ena_com_indirect_table_fill_entry net: ena: fix: Free napi resources when ena_up() fails net: ena: fix incorrect test of supported hash function net: ena: fix ena_com_fill_hash_function() implementation dmaengine: tegra210-adma: restore channel status watchdog: rtd119x_wdt: Fix remove function mmc: core: fix possible use after free of host lightnvm: pblk: fix lock order in pblk_rb_tear_down_check ath10k: Fix encoding for protected management frames afs: Fix the afs.cell and afs.volume xattr handlers vfio/mdev: Avoid release parent reference during error path vfio/mdev: Follow correct remove sequence vfio/mdev: Fix aborting mdev child device removal if one fails l2tp: Fix possible NULL pointer dereference ALSA: aica: Fix a long-time build breakage media: omap_vout: potential buffer overflow in vidioc_dqbuf() media: davinci/vpbe: array underflow in vpbe_enum_outputs() platform/x86: alienware-wmi: printing the wrong error code crypto: caam - fix caam_dump_sg that iterates through scatterlist netfilter: ebtables: CONFIG_COMPAT: reject trailing data after last rule pwm: meson: Consider 128 a valid pre-divider pwm: meson: Don't disable PWM when setting duty repeatedly ARM: riscpc: fix lack of keyboard interrupts after irq conversion nfp: bpf: fix static check error through tightening shift amount adjustment kdb: do a sanity check on the cpu in kdb_per_cpu() netfilter: nf_tables: correct NFT_LOGLEVEL_MAX value backlight: lm3630a: Return 0 on success in update_status functions thermal: rcar_gen3_thermal: fix interrupt type thermal: cpu_cooling: Actually trace CPU load in thermal_power_cpu_get_power EDAC/mc: Fix edac_mc_find() in case no device is found afs: Fix key leak in afs_release() and afs_evict_inode() afs: Don't invalidate callback if AFS_VNODE_DIR_VALID not set afs: Fix lock-wait/callback-break double locking afs: Fix double inc of vnode->cb_break ARM: dts: sun8i-h3: Fix wifi in Beelink X2 DT clk: meson: gxbb: no spread spectrum on mpll0 clk: meson: axg: spread spectrum is on mpll2 dmaengine: tegra210-adma: Fix crash during probe arm64: dts: meson: libretech-cc: set eMMC as removable RDMA/qedr: Fix incorrect device rate. spi: spi-fsl-spi: call spi_finalize_current_message() at the end crypto: ccp - fix AES CFB error exposed by new test vectors crypto: ccp - Fix 3DES complaint from ccp-crypto module serial: stm32: fix word length configuration serial: stm32: fix rx error handling serial: stm32: fix rx data length when parity enabled serial: stm32: fix transmit_chars when tx is stopped serial: stm32: Add support of TC bit status check serial: stm32: fix wakeup source initialization misc: sgi-xp: Properly initialize buf in xpc_get_rsvd_page_pa iommu: Add missing new line for dma type iommu: Use right function to get group for device signal/bpfilter: Fix bpfilter_kernl to use send_sig not force_sig signal/cifs: Fix cifs_put_tcp_session to call send_sig instead of force_sig inet: frags: call inet_frags_fini() after unregister_pernet_subsys() net: hns3: fix a memory leak issue for hclge_map_unmap_ring_to_vf_vector crypto: talitos - fix AEAD processing. netvsc: unshare skb in VF rx handler net: core: support XDP generic on stacked devices. RDMA/uverbs: check for allocation failure in uapi_add_elm() net: don't clear sock->sk early to avoid trouble in strparser phy: qcom-qusb2: fix missing assignment of ret when calling clk_prepare_enable cpufreq: brcmstb-avs-cpufreq: Fix initial command check cpufreq: brcmstb-avs-cpufreq: Fix types for voltage/frequency clk: sunxi-ng: sun50i-h6-r: Fix incorrect W1 clock gate register media: vivid: fix incorrect assignment operation when setting video mode crypto: inside-secure - fix zeroing of the request in ahash_exit_inv crypto: inside-secure - fix queued len computation arm64: dts: renesas: ebisu: Remove renesas, no-ether-link property mpls: fix warning with multi-label encap serial: stm32: fix a recursive locking in stm32_config_rs485 arm64: dts: meson-gxm-khadas-vim2: fix gpio-keys-polled node arm64: dts: meson-gxm-khadas-vim2: fix Bluetooth support iommu/vt-d: Duplicate iommu_resv_region objects per device list phy: usb: phy-brcm-usb: Remove sysfs attributes upon driver removal firmware: arm_scmi: fix bitfield definitions for SENSOR_DESC attributes firmware: arm_scmi: update rate_discrete in clock_describe_rates_get ntb_hw_switchtec: potential shift wrapping bug in switchtec_ntb_init_sndev() ASoC: meson: axg-tdmin: right_j is not supported ASoC: meson: axg-tdmout: right_j is not supported qed: iWARP - Use READ_ONCE and smp_store_release to access ep->state qed: iWARP - fix uninitialized callback powerpc/cacheinfo: add cacheinfo_teardown, cacheinfo_rebuild powerpc/pseries/mobility: rebuild cacheinfo hierarchy post-migration bpf: fix the check that forwarding is enabled in bpf_ipv6_fib_lookup IB/hfi1: Handle port down properly in pio drm/msm/mdp5: Fix mdp5_cfg_init error return net: netem: fix backlog accounting for corrupted GSO frames net/udp_gso: Allow TX timestamp with UDP GSO net/af_iucv: build proper skbs for HiperTransport net/af_iucv: always register net_device notifier ASoC: ti: davinci-mcasp: Fix slot mask settings when using multiple AXRs rtc: pcf8563: Fix interrupt trigger method rtc: pcf8563: Clear event flags and disable interrupts before requesting irq ARM: dts: iwg20d-q7-common: Fix SDHI1 VccQ regularor net/sched: cbs: Fix error path of cbs_module_init arm64: dts: allwinner: h6: Pine H64: Add interrupt line for RTC drm/msm/a3xx: remove TPL1 regs from snapshot ip6_fib: Don't discard nodes with valid routing information in fib6_locate_1() perf/ioctl: Add check for the sample_period value dmaengine: hsu: Revert "set HSU_CH_MTSR to memory width" clk: qcom: Fix -Wunused-const-variable nvmem: imx-ocotp: Ensure WAIT bits are preserved when setting timing nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm tools: bpftool: use correct argument in cgroup errors backlight: pwm_bl: Fix heuristic to determine number of brightness levels fork,memcg: alloc_thread_stack_node needs to set tsk->stack bnxt_en: Fix ethtool selftest crash under error conditions. bnxt_en: Suppress error messages when querying DSCP DCB capabilities. iommu/amd: Make iommu_disable safer mfd: intel-lpss: Release IDA resources rxrpc: Fix uninitialized error code in rxrpc_send_data_packet() xprtrdma: Fix use-after-free in rpcrdma_post_recvs um: Fix IRQ controller regression on console read PM: ACPI/PCI: Resume all devices during hibernation ACPI: PM: Simplify and fix PM domain hibernation callbacks ACPI: PM: Introduce "poweroff" callbacks for ACPI PM domain and LPSS fsi/core: Fix error paths on CFAM init devres: allow const resource arguments fsi: sbefifo: Don't fail operations when in SBE IPL state RDMA/hns: Fixs hw access invalid dma memory error PCI: mobiveil: Remove the flag MSI_FLAG_MULTI_PCI_MSI PCI: mobiveil: Fix devfn check in mobiveil_pcie_valid_device() PCI: mobiveil: Fix the valid check for inbound and outbound windows ceph: fix "ceph.dir.rctime" vxattr value net: pasemi: fix an use-after-free in pasemi_mac_phy_init() net/tls: fix socket wmem accounting on fallback with netem x86/pgtable/32: Fix LOWMEM_PAGES constant xdp: fix possible cq entry leak ARM: stm32: use "depends on" instead of "if" after prompt scsi: libfc: fix null pointer dereference on a null lport xfrm interface: ifname may be wrong in logs drm/panel: make drm_panel.h self-contained clk: sunxi-ng: v3s: add the missing PLL_DDR1 PM: sleep: Fix possible overflow in pm_system_cancel_wakeup() libertas_tf: Use correct channel range in lbtf_geo_init qed: reduce maximum stack frame size usb: host: xhci-hub: fix extra endianness conversion media: rcar-vin: Clean up correct notifier in error path mic: avoid statically declaring a 'struct device'. x86/kgbd: Use NMI_VECTOR not APIC_DM_NMI crypto: ccp - Reduce maximum stack usage ALSA: aoa: onyx: always initialize register read value arm64: dts: renesas: r8a77995: Fix register range of display node tipc: reduce risk of wakeup queue starvation ARM: dts: stm32: add missing vdda-supply to adc on stm32h743i-eval net/mlx5: Fix mlx5_ifc_query_lag_out_bits cifs: fix rmmod regression in cifs.ko caused by force_sig changes iio: tsl2772: Use devm_add_action_or_reset for tsl2772_chip_off net: fix bpf_xdp_adjust_head regression for generic-XDP spi: bcm-qspi: Fix BSPI QUAD and DUAL mode support when using flex mode cxgb4: smt: Add lock for atomic_dec_and_test crypto: caam - free resources in case caam_rng registration failed ext4: set error return correctly when ext4_htree_store_dirent fails RDMA/hns: Bugfix for slab-out-of-bounds when unloading hip08 driver RDMA/hns: bugfix for slab-out-of-bounds when loading hip08 driver ASoC: es8328: Fix copy-paste error in es8328_right_line_controls ASoC: cs4349: Use PM ops 'cs4349_runtime_pm' ASoC: wm8737: Fix copy-paste error in wm8737_snd_controls net/rds: Add a few missing rds_stat_names entries tools: bpftool: fix arguments for p_err() in do_event_pipe() tools: bpftool: fix format strings and arguments for jsonw_printf() drm: rcar-du: lvds: Fix bridge_to_rcar_lvds bnxt_en: Fix handling FRAG_ERR when NVM_INSTALL_UPDATE cmd fails signal: Allow cifs and drbd to receive their terminating signals powerpc/64s/radix: Fix memory hot-unplug page table split ASoC: sun4i-i2s: RX and TX counter registers are swapped dmaengine: dw: platform: Switch to acpi_dma_controller_register() rtc: rv3029: revert error handling patch to rv3029_eeprom_write() mac80211: minstrel_ht: fix per-group max throughput rate initialization i40e: reduce stack usage in i40e_set_fc media: atmel: atmel-isi: fix timeout value for stop streaming ARM: 8896/1: VDSO: Don't leak kernel addresses rtc: pcf2127: bugfix: read rtc disables watchdog mips: avoid explicit UB in assignment of mips_io_port_base media: em28xx: Fix exception handling in em28xx_alloc_urbs() iommu/mediatek: Fix iova_to_phys PA start for 4GB mode ahci: Do not export local variable ahci_em_messages rxrpc: Fix lack of conn cleanup when local endpoint is cleaned up [ver #2] Partially revert "kfifo: fix kfifo_alloc() and kfifo_init()" hwmon: (lm75) Fix write operations for negative temperatures net/sched: cbs: Set default link speed to 10 Mbps in cbs_set_port_rate power: supply: Init device wakeup after device_add() x86, perf: Fix the dependency of the x86 insn decoder selftest staging: greybus: light: fix a couple double frees irqdomain: Add the missing assignment of domain->fwnode for named fwnode bcma: fix incorrect update of BCMA_CORE_PCI_MDIO_DATA usb: typec: tps6598x: Fix build error without CONFIG_REGMAP_I2C bcache: Fix an error code in bch_dump_read() iio: dac: ad5380: fix incorrect assignment to val netfilter: ctnetlink: honor IPS_OFFLOAD flag ath9k: dynack: fix possible deadlock in ath_dynack_node_{de}init wcn36xx: use dynamic allocation for large variables tty: serial: fsl_lpuart: Use appropriate lpuart32_* I/O funcs ARM: dts: aspeed-g5: Fixe gpio-ranges upper limit xsk: avoid store-tearing when assigning queues xsk: avoid store-tearing when assigning umem led: triggers: Fix dereferencing of null pointer net: sonic: return NETDEV_TX_OK if failed to map buffer net: hns3: fix error VF index when setting VLAN offload rtlwifi: Fix file release memory leak ARM: dts: logicpd-som-lv: Fix i2c2 and i2c3 Pin mux f2fs: fix wrong error injection path in inc_valid_block_count() f2fs: fix error path of f2fs_convert_inline_page() scsi: fnic: fix msix interrupt allocation Btrfs: fix hang when loading existing inode cache off disk Btrfs: fix inode cache waiters hanging on failure to start caching thread Btrfs: fix inode cache waiters hanging on path allocation failure btrfs: use correct count in btrfs_file_write_iter() ixgbe: sync the first fragment unconditionally hwmon: (shtc1) fix shtc1 and shtw1 id mask net: sonic: replace dev_kfree_skb in sonic_send_packet pinctrl: iproc-gpio: Fix incorrect pinconf configurations gpio/aspeed: Fix incorrect number of banks ath10k: adjust skb length in ath10k_sdio_mbox_rx_packet RDMA/cma: Fix false error message net/rds: Fix 'ib_evt_handler_call' element in 'rds_ib_stat_names' um: Fix off by one error in IRQ enumeration bnxt_en: Increase timeout for HWRM_DBG_COREDUMP_XX commands f2fs: fix to avoid accessing uninitialized field of inode page in is_alive() mailbox: qcom-apcs: fix max_register value clk: actions: Fix factor clk struct member access powerpc/mm/mce: Keep irqs disabled during lockless page table walk bpf: fix BTF limits crypto: hisilicon - Matching the dma address for dma_pool_free() iommu/amd: Wait for completion of IOTLB flush in attach_device net: aquantia: Fix aq_vec_isr_legacy() return value cxgb4: Signedness bug in init_one() net: hisilicon: Fix signedness bug in hix5hd2_dev_probe() net: broadcom/bcmsysport: Fix signedness in bcm_sysport_probe() net: netsec: Fix signedness bug in netsec_probe() net: socionext: Fix a signedness bug in ave_probe() net: stmmac: dwmac-meson8b: Fix signedness bug in probe net: axienet: fix a signedness bug in probe of: mdio: Fix a signedness bug in of_phy_get_and_connect() net: nixge: Fix a signedness bug in nixge_probe() net: ethernet: stmmac: Fix signedness bug in ipq806x_gmac_of_parse() net: sched: cbs: Avoid division by zero when calculating the port rate nvme: retain split access workaround for capability reads net: stmmac: gmac4+: Not all Unicast addresses may be available rxrpc: Fix trace-after-put looking at the put connection record mac80211: accept deauth frames in IBSS mode llc: fix another potential sk_buff leak in llc_ui_sendmsg() llc: fix sk_buff refcounting in llc_conn_state_process() ip6erspan: remove the incorrect mtu limit for ip6erspan net: stmmac: fix length of PTP clock's name string net: stmmac: fix disabling flexible PPS output sctp: add chunks to sk_backlog when the newsk sk_socket is not set s390/qeth: Fix error handling during VNICC initialization s390/qeth: Fix initialization of vnicc cmd masks during set online act_mirred: Fix mirred_init_module error handling net: avoid possible false sharing in sk_leave_memory_pressure() net: add {READ|WRITE}_ONCE() annotations on ->rskq_accept_head tcp: annotate lockless access to tcp_memory_pressure net/smc: receive returns without data net/smc: receive pending data after RCV_SHUTDOWN drm/msm/dsi: Implement reset correctly vhost/test: stop device before reset dmaengine: imx-sdma: fix size check for sdma script_number firmware: dmi: Fix unlikely out-of-bounds read in save_mem_devices arm64: hibernate: check pgd table allocation net: netem: fix error path for corrupted GSO frames net: netem: correct the parent's backlog when corrupted packet was dropped xsk: Fix registration of Rx-only sockets bpf, offload: Unlock on error in bpf_offload_dev_create() afs: Fix missing timeout reset net: qca_spi: Move reset_count to struct qcaspi hv_netvsc: Fix offset usage in netvsc_send_table() hv_netvsc: Fix send_table offset in case of a host bug afs: Fix large file support drm: panel-lvds: Potential Oops in probe error handling hwrng: omap3-rom - Fix missing clock by probing with device tree dpaa_eth: perform DMA unmapping before read dpaa_eth: avoid timestamp read on error paths MIPS: Loongson: Fix return value of loongson_hwmon_init hv_netvsc: flag software created hash value net: neigh: use long type to store jiffies delta packet: fix data-race in fanout_flow_is_huge() i2c: stm32f7: report dma error during probe mmc: sdio: fix wl1251 vendor id mmc: core: fix wl1251 sdio quirks affs: fix a memory leak in affs_remount afs: Remove set but not used variables 'before', 'after' dmaengine: ti: edma: fix missed failure handling drm/radeon: fix bad DMA from INTERRUPT_CNTL2 arm64: dts: juno: Fix UART frequency samples/bpf: Fix broken xdp_rxq_info due to map order assumptions usb: dwc3: Allow building USB_DWC3_QCOM without EXTCON IB/iser: Fix dma_nents type definition serial: stm32: fix clearing interrupt error flags arm64: dts: meson-gxm-khadas-vim2: fix uart_A bluetooth node m68k: Call timer_interrupt() with interrupts disabled Linux 4.19.99 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ieabeab79ea5c8cb4b6b1552702fa5d6100cea5db
2047 lines
50 KiB
C
2047 lines
50 KiB
C
// SPDX-License-Identifier: LGPL-2.1
|
|
/*
|
|
* Copyright (c) 2012 Taobao.
|
|
* Written by Tao Ma <boyu.mt@taobao.com>
|
|
*/
|
|
|
|
#include <linux/iomap.h>
|
|
#include <linux/fiemap.h>
|
|
#include <linux/iversion.h>
|
|
|
|
#include "ext4_jbd2.h"
|
|
#include "ext4.h"
|
|
#include "xattr.h"
|
|
#include "truncate.h"
|
|
#include <trace/events/android_fs.h>
|
|
|
|
#define EXT4_XATTR_SYSTEM_DATA "data"
|
|
#define EXT4_MIN_INLINE_DATA_SIZE ((sizeof(__le32) * EXT4_N_BLOCKS))
|
|
#define EXT4_INLINE_DOTDOT_OFFSET 2
|
|
#define EXT4_INLINE_DOTDOT_SIZE 4
|
|
|
|
static int ext4_get_inline_size(struct inode *inode)
|
|
{
|
|
if (EXT4_I(inode)->i_inline_off)
|
|
return EXT4_I(inode)->i_inline_size;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int get_max_inline_xattr_value_size(struct inode *inode,
|
|
struct ext4_iloc *iloc)
|
|
{
|
|
struct ext4_xattr_ibody_header *header;
|
|
struct ext4_xattr_entry *entry;
|
|
struct ext4_inode *raw_inode;
|
|
int free, min_offs;
|
|
|
|
min_offs = EXT4_SB(inode->i_sb)->s_inode_size -
|
|
EXT4_GOOD_OLD_INODE_SIZE -
|
|
EXT4_I(inode)->i_extra_isize -
|
|
sizeof(struct ext4_xattr_ibody_header);
|
|
|
|
/*
|
|
* We need to subtract another sizeof(__u32) since an in-inode xattr
|
|
* needs an empty 4 bytes to indicate the gap between the xattr entry
|
|
* and the name/value pair.
|
|
*/
|
|
if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
|
|
return EXT4_XATTR_SIZE(min_offs -
|
|
EXT4_XATTR_LEN(strlen(EXT4_XATTR_SYSTEM_DATA)) -
|
|
EXT4_XATTR_ROUND - sizeof(__u32));
|
|
|
|
raw_inode = ext4_raw_inode(iloc);
|
|
header = IHDR(inode, raw_inode);
|
|
entry = IFIRST(header);
|
|
|
|
/* Compute min_offs. */
|
|
for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
|
|
if (!entry->e_value_inum && entry->e_value_size) {
|
|
size_t offs = le16_to_cpu(entry->e_value_offs);
|
|
if (offs < min_offs)
|
|
min_offs = offs;
|
|
}
|
|
}
|
|
free = min_offs -
|
|
((void *)entry - (void *)IFIRST(header)) - sizeof(__u32);
|
|
|
|
if (EXT4_I(inode)->i_inline_off) {
|
|
entry = (struct ext4_xattr_entry *)
|
|
((void *)raw_inode + EXT4_I(inode)->i_inline_off);
|
|
|
|
free += EXT4_XATTR_SIZE(le32_to_cpu(entry->e_value_size));
|
|
goto out;
|
|
}
|
|
|
|
free -= EXT4_XATTR_LEN(strlen(EXT4_XATTR_SYSTEM_DATA));
|
|
|
|
if (free > EXT4_XATTR_ROUND)
|
|
free = EXT4_XATTR_SIZE(free - EXT4_XATTR_ROUND);
|
|
else
|
|
free = 0;
|
|
|
|
out:
|
|
return free;
|
|
}
|
|
|
|
/*
|
|
* Get the maximum size we now can store in an inode.
|
|
* If we can't find the space for a xattr entry, don't use the space
|
|
* of the extents since we have no space to indicate the inline data.
|
|
*/
|
|
int ext4_get_max_inline_size(struct inode *inode)
|
|
{
|
|
int error, max_inline_size;
|
|
struct ext4_iloc iloc;
|
|
|
|
if (EXT4_I(inode)->i_extra_isize == 0)
|
|
return 0;
|
|
|
|
error = ext4_get_inode_loc(inode, &iloc);
|
|
if (error) {
|
|
ext4_error_inode(inode, __func__, __LINE__, 0,
|
|
"can't get inode location %lu",
|
|
inode->i_ino);
|
|
return 0;
|
|
}
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
max_inline_size = get_max_inline_xattr_value_size(inode, &iloc);
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
|
|
brelse(iloc.bh);
|
|
|
|
if (!max_inline_size)
|
|
return 0;
|
|
|
|
return max_inline_size + EXT4_MIN_INLINE_DATA_SIZE;
|
|
}
|
|
|
|
/*
|
|
* this function does not take xattr_sem, which is OK because it is
|
|
* currently only used in a code path coming form ext4_iget, before
|
|
* the new inode has been unlocked
|
|
*/
|
|
int ext4_find_inline_data_nolock(struct inode *inode)
|
|
{
|
|
struct ext4_xattr_ibody_find is = {
|
|
.s = { .not_found = -ENODATA, },
|
|
};
|
|
struct ext4_xattr_info i = {
|
|
.name_index = EXT4_XATTR_INDEX_SYSTEM,
|
|
.name = EXT4_XATTR_SYSTEM_DATA,
|
|
};
|
|
int error;
|
|
|
|
if (EXT4_I(inode)->i_extra_isize == 0)
|
|
return 0;
|
|
|
|
error = ext4_get_inode_loc(inode, &is.iloc);
|
|
if (error)
|
|
return error;
|
|
|
|
error = ext4_xattr_ibody_find(inode, &i, &is);
|
|
if (error)
|
|
goto out;
|
|
|
|
if (!is.s.not_found) {
|
|
if (is.s.here->e_value_inum) {
|
|
EXT4_ERROR_INODE(inode, "inline data xattr refers "
|
|
"to an external xattr inode");
|
|
error = -EFSCORRUPTED;
|
|
goto out;
|
|
}
|
|
EXT4_I(inode)->i_inline_off = (u16)((void *)is.s.here -
|
|
(void *)ext4_raw_inode(&is.iloc));
|
|
EXT4_I(inode)->i_inline_size = EXT4_MIN_INLINE_DATA_SIZE +
|
|
le32_to_cpu(is.s.here->e_value_size);
|
|
ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
}
|
|
out:
|
|
brelse(is.iloc.bh);
|
|
return error;
|
|
}
|
|
|
|
static int ext4_read_inline_data(struct inode *inode, void *buffer,
|
|
unsigned int len,
|
|
struct ext4_iloc *iloc)
|
|
{
|
|
struct ext4_xattr_entry *entry;
|
|
struct ext4_xattr_ibody_header *header;
|
|
int cp_len = 0;
|
|
struct ext4_inode *raw_inode;
|
|
|
|
if (!len)
|
|
return 0;
|
|
|
|
BUG_ON(len > EXT4_I(inode)->i_inline_size);
|
|
|
|
cp_len = len < EXT4_MIN_INLINE_DATA_SIZE ?
|
|
len : EXT4_MIN_INLINE_DATA_SIZE;
|
|
|
|
raw_inode = ext4_raw_inode(iloc);
|
|
memcpy(buffer, (void *)(raw_inode->i_block), cp_len);
|
|
|
|
len -= cp_len;
|
|
buffer += cp_len;
|
|
|
|
if (!len)
|
|
goto out;
|
|
|
|
header = IHDR(inode, raw_inode);
|
|
entry = (struct ext4_xattr_entry *)((void *)raw_inode +
|
|
EXT4_I(inode)->i_inline_off);
|
|
len = min_t(unsigned int, len,
|
|
(unsigned int)le32_to_cpu(entry->e_value_size));
|
|
|
|
memcpy(buffer,
|
|
(void *)IFIRST(header) + le16_to_cpu(entry->e_value_offs), len);
|
|
cp_len += len;
|
|
|
|
out:
|
|
return cp_len;
|
|
}
|
|
|
|
/*
|
|
* write the buffer to the inline inode.
|
|
* If 'create' is set, we don't need to do the extra copy in the xattr
|
|
* value since it is already handled by ext4_xattr_ibody_inline_set.
|
|
* That saves us one memcpy.
|
|
*/
|
|
static void ext4_write_inline_data(struct inode *inode, struct ext4_iloc *iloc,
|
|
void *buffer, loff_t pos, unsigned int len)
|
|
{
|
|
struct ext4_xattr_entry *entry;
|
|
struct ext4_xattr_ibody_header *header;
|
|
struct ext4_inode *raw_inode;
|
|
int cp_len = 0;
|
|
|
|
if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
|
|
return;
|
|
|
|
BUG_ON(!EXT4_I(inode)->i_inline_off);
|
|
BUG_ON(pos + len > EXT4_I(inode)->i_inline_size);
|
|
|
|
raw_inode = ext4_raw_inode(iloc);
|
|
buffer += pos;
|
|
|
|
if (pos < EXT4_MIN_INLINE_DATA_SIZE) {
|
|
cp_len = pos + len > EXT4_MIN_INLINE_DATA_SIZE ?
|
|
EXT4_MIN_INLINE_DATA_SIZE - pos : len;
|
|
memcpy((void *)raw_inode->i_block + pos, buffer, cp_len);
|
|
|
|
len -= cp_len;
|
|
buffer += cp_len;
|
|
pos += cp_len;
|
|
}
|
|
|
|
if (!len)
|
|
return;
|
|
|
|
pos -= EXT4_MIN_INLINE_DATA_SIZE;
|
|
header = IHDR(inode, raw_inode);
|
|
entry = (struct ext4_xattr_entry *)((void *)raw_inode +
|
|
EXT4_I(inode)->i_inline_off);
|
|
|
|
memcpy((void *)IFIRST(header) + le16_to_cpu(entry->e_value_offs) + pos,
|
|
buffer, len);
|
|
}
|
|
|
|
static int ext4_create_inline_data(handle_t *handle,
|
|
struct inode *inode, unsigned len)
|
|
{
|
|
int error;
|
|
void *value = NULL;
|
|
struct ext4_xattr_ibody_find is = {
|
|
.s = { .not_found = -ENODATA, },
|
|
};
|
|
struct ext4_xattr_info i = {
|
|
.name_index = EXT4_XATTR_INDEX_SYSTEM,
|
|
.name = EXT4_XATTR_SYSTEM_DATA,
|
|
};
|
|
|
|
error = ext4_get_inode_loc(inode, &is.iloc);
|
|
if (error)
|
|
return error;
|
|
|
|
BUFFER_TRACE(is.iloc.bh, "get_write_access");
|
|
error = ext4_journal_get_write_access(handle, is.iloc.bh);
|
|
if (error)
|
|
goto out;
|
|
|
|
if (len > EXT4_MIN_INLINE_DATA_SIZE) {
|
|
value = EXT4_ZERO_XATTR_VALUE;
|
|
len -= EXT4_MIN_INLINE_DATA_SIZE;
|
|
} else {
|
|
value = "";
|
|
len = 0;
|
|
}
|
|
|
|
/* Insert the the xttr entry. */
|
|
i.value = value;
|
|
i.value_len = len;
|
|
|
|
error = ext4_xattr_ibody_find(inode, &i, &is);
|
|
if (error)
|
|
goto out;
|
|
|
|
BUG_ON(!is.s.not_found);
|
|
|
|
error = ext4_xattr_ibody_inline_set(handle, inode, &i, &is);
|
|
if (error) {
|
|
if (error == -ENOSPC)
|
|
ext4_clear_inode_state(inode,
|
|
EXT4_STATE_MAY_INLINE_DATA);
|
|
goto out;
|
|
}
|
|
|
|
memset((void *)ext4_raw_inode(&is.iloc)->i_block,
|
|
0, EXT4_MIN_INLINE_DATA_SIZE);
|
|
|
|
EXT4_I(inode)->i_inline_off = (u16)((void *)is.s.here -
|
|
(void *)ext4_raw_inode(&is.iloc));
|
|
EXT4_I(inode)->i_inline_size = len + EXT4_MIN_INLINE_DATA_SIZE;
|
|
ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS);
|
|
ext4_set_inode_flag(inode, EXT4_INODE_INLINE_DATA);
|
|
get_bh(is.iloc.bh);
|
|
error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
|
|
|
|
out:
|
|
brelse(is.iloc.bh);
|
|
return error;
|
|
}
|
|
|
|
static int ext4_update_inline_data(handle_t *handle, struct inode *inode,
|
|
unsigned int len)
|
|
{
|
|
int error;
|
|
void *value = NULL;
|
|
struct ext4_xattr_ibody_find is = {
|
|
.s = { .not_found = -ENODATA, },
|
|
};
|
|
struct ext4_xattr_info i = {
|
|
.name_index = EXT4_XATTR_INDEX_SYSTEM,
|
|
.name = EXT4_XATTR_SYSTEM_DATA,
|
|
};
|
|
|
|
/* If the old space is ok, write the data directly. */
|
|
if (len <= EXT4_I(inode)->i_inline_size)
|
|
return 0;
|
|
|
|
error = ext4_get_inode_loc(inode, &is.iloc);
|
|
if (error)
|
|
return error;
|
|
|
|
error = ext4_xattr_ibody_find(inode, &i, &is);
|
|
if (error)
|
|
goto out;
|
|
|
|
BUG_ON(is.s.not_found);
|
|
|
|
len -= EXT4_MIN_INLINE_DATA_SIZE;
|
|
value = kzalloc(len, GFP_NOFS);
|
|
if (!value) {
|
|
error = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
error = ext4_xattr_ibody_get(inode, i.name_index, i.name,
|
|
value, len);
|
|
if (error == -ENODATA)
|
|
goto out;
|
|
|
|
BUFFER_TRACE(is.iloc.bh, "get_write_access");
|
|
error = ext4_journal_get_write_access(handle, is.iloc.bh);
|
|
if (error)
|
|
goto out;
|
|
|
|
/* Update the xttr entry. */
|
|
i.value = value;
|
|
i.value_len = len;
|
|
|
|
error = ext4_xattr_ibody_inline_set(handle, inode, &i, &is);
|
|
if (error)
|
|
goto out;
|
|
|
|
EXT4_I(inode)->i_inline_off = (u16)((void *)is.s.here -
|
|
(void *)ext4_raw_inode(&is.iloc));
|
|
EXT4_I(inode)->i_inline_size = EXT4_MIN_INLINE_DATA_SIZE +
|
|
le32_to_cpu(is.s.here->e_value_size);
|
|
ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
get_bh(is.iloc.bh);
|
|
error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
|
|
|
|
out:
|
|
kfree(value);
|
|
brelse(is.iloc.bh);
|
|
return error;
|
|
}
|
|
|
|
static int ext4_prepare_inline_data(handle_t *handle, struct inode *inode,
|
|
unsigned int len)
|
|
{
|
|
int ret, size, no_expand;
|
|
struct ext4_inode_info *ei = EXT4_I(inode);
|
|
|
|
if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
|
|
return -ENOSPC;
|
|
|
|
size = ext4_get_max_inline_size(inode);
|
|
if (size < len)
|
|
return -ENOSPC;
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
|
|
if (ei->i_inline_off)
|
|
ret = ext4_update_inline_data(handle, inode, len);
|
|
else
|
|
ret = ext4_create_inline_data(handle, inode, len);
|
|
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
return ret;
|
|
}
|
|
|
|
static int ext4_destroy_inline_data_nolock(handle_t *handle,
|
|
struct inode *inode)
|
|
{
|
|
struct ext4_inode_info *ei = EXT4_I(inode);
|
|
struct ext4_xattr_ibody_find is = {
|
|
.s = { .not_found = 0, },
|
|
};
|
|
struct ext4_xattr_info i = {
|
|
.name_index = EXT4_XATTR_INDEX_SYSTEM,
|
|
.name = EXT4_XATTR_SYSTEM_DATA,
|
|
.value = NULL,
|
|
.value_len = 0,
|
|
};
|
|
int error;
|
|
|
|
if (!ei->i_inline_off)
|
|
return 0;
|
|
|
|
error = ext4_get_inode_loc(inode, &is.iloc);
|
|
if (error)
|
|
return error;
|
|
|
|
error = ext4_xattr_ibody_find(inode, &i, &is);
|
|
if (error)
|
|
goto out;
|
|
|
|
BUFFER_TRACE(is.iloc.bh, "get_write_access");
|
|
error = ext4_journal_get_write_access(handle, is.iloc.bh);
|
|
if (error)
|
|
goto out;
|
|
|
|
error = ext4_xattr_ibody_inline_set(handle, inode, &i, &is);
|
|
if (error)
|
|
goto out;
|
|
|
|
memset((void *)ext4_raw_inode(&is.iloc)->i_block,
|
|
0, EXT4_MIN_INLINE_DATA_SIZE);
|
|
memset(ei->i_data, 0, EXT4_MIN_INLINE_DATA_SIZE);
|
|
|
|
if (ext4_has_feature_extents(inode->i_sb)) {
|
|
if (S_ISDIR(inode->i_mode) ||
|
|
S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) {
|
|
ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS);
|
|
ext4_ext_tree_init(handle, inode);
|
|
}
|
|
}
|
|
ext4_clear_inode_flag(inode, EXT4_INODE_INLINE_DATA);
|
|
|
|
get_bh(is.iloc.bh);
|
|
error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
|
|
|
|
EXT4_I(inode)->i_inline_off = 0;
|
|
EXT4_I(inode)->i_inline_size = 0;
|
|
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
out:
|
|
brelse(is.iloc.bh);
|
|
if (error == -ENODATA)
|
|
error = 0;
|
|
return error;
|
|
}
|
|
|
|
static int ext4_read_inline_page(struct inode *inode, struct page *page)
|
|
{
|
|
void *kaddr;
|
|
int ret = 0;
|
|
size_t len;
|
|
struct ext4_iloc iloc;
|
|
|
|
BUG_ON(!PageLocked(page));
|
|
BUG_ON(!ext4_has_inline_data(inode));
|
|
BUG_ON(page->index);
|
|
|
|
if (!EXT4_I(inode)->i_inline_off) {
|
|
ext4_warning(inode->i_sb, "inode %lu doesn't have inline data.",
|
|
inode->i_ino);
|
|
goto out;
|
|
}
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
goto out;
|
|
|
|
len = min_t(size_t, ext4_get_inline_size(inode), i_size_read(inode));
|
|
kaddr = kmap_atomic(page);
|
|
ret = ext4_read_inline_data(inode, kaddr, len, &iloc);
|
|
flush_dcache_page(page);
|
|
kunmap_atomic(kaddr);
|
|
zero_user_segment(page, len, PAGE_SIZE);
|
|
SetPageUptodate(page);
|
|
brelse(iloc.bh);
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
int ext4_readpage_inline(struct inode *inode, struct page *page)
|
|
{
|
|
int ret = 0;
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
return -EAGAIN;
|
|
}
|
|
|
|
if (trace_android_fs_dataread_start_enabled()) {
|
|
char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
|
|
|
|
path = android_fstrace_get_pathname(pathbuf,
|
|
MAX_TRACE_PATHBUF_LEN,
|
|
inode);
|
|
trace_android_fs_dataread_start(inode, page_offset(page),
|
|
PAGE_SIZE, current->pid,
|
|
path, current->comm);
|
|
}
|
|
|
|
/*
|
|
* Current inline data can only exist in the 1st page,
|
|
* So for all the other pages, just set them uptodate.
|
|
*/
|
|
if (!page->index)
|
|
ret = ext4_read_inline_page(inode, page);
|
|
else if (!PageUptodate(page)) {
|
|
zero_user_segment(page, 0, PAGE_SIZE);
|
|
SetPageUptodate(page);
|
|
}
|
|
|
|
trace_android_fs_dataread_end(inode, page_offset(page), PAGE_SIZE);
|
|
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
|
|
unlock_page(page);
|
|
return ret >= 0 ? 0 : ret;
|
|
}
|
|
|
|
static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
|
|
struct inode *inode,
|
|
unsigned flags)
|
|
{
|
|
int ret, needed_blocks, no_expand;
|
|
handle_t *handle = NULL;
|
|
int retries = 0, sem_held = 0;
|
|
struct page *page = NULL;
|
|
unsigned from, to;
|
|
struct ext4_iloc iloc;
|
|
|
|
if (!ext4_has_inline_data(inode)) {
|
|
/*
|
|
* clear the flag so that no new write
|
|
* will trap here again.
|
|
*/
|
|
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
return 0;
|
|
}
|
|
|
|
needed_blocks = ext4_writepage_trans_blocks(inode);
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
retry:
|
|
handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks);
|
|
if (IS_ERR(handle)) {
|
|
ret = PTR_ERR(handle);
|
|
handle = NULL;
|
|
goto out;
|
|
}
|
|
|
|
/* We cannot recurse into the filesystem as the transaction is already
|
|
* started */
|
|
flags |= AOP_FLAG_NOFS;
|
|
|
|
page = grab_cache_page_write_begin(mapping, 0, flags);
|
|
if (!page) {
|
|
ret = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
sem_held = 1;
|
|
/* If some one has already done this for us, just exit. */
|
|
if (!ext4_has_inline_data(inode)) {
|
|
ret = 0;
|
|
goto out;
|
|
}
|
|
|
|
from = 0;
|
|
to = ext4_get_inline_size(inode);
|
|
if (!PageUptodate(page)) {
|
|
ret = ext4_read_inline_page(inode, page);
|
|
if (ret < 0)
|
|
goto out;
|
|
}
|
|
|
|
ret = ext4_destroy_inline_data_nolock(handle, inode);
|
|
if (ret)
|
|
goto out;
|
|
|
|
if (ext4_should_dioread_nolock(inode)) {
|
|
ret = __block_write_begin(page, from, to,
|
|
ext4_get_block_unwritten);
|
|
} else
|
|
ret = __block_write_begin(page, from, to, ext4_get_block);
|
|
|
|
if (!ret && ext4_should_journal_data(inode)) {
|
|
ret = ext4_walk_page_buffers(handle, page_buffers(page),
|
|
from, to, NULL,
|
|
do_journal_get_write_access);
|
|
}
|
|
|
|
if (ret) {
|
|
unlock_page(page);
|
|
put_page(page);
|
|
page = NULL;
|
|
ext4_orphan_add(handle, inode);
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
sem_held = 0;
|
|
ext4_journal_stop(handle);
|
|
handle = NULL;
|
|
ext4_truncate_failed_write(inode);
|
|
/*
|
|
* If truncate failed early the inode might
|
|
* still be on the orphan list; we need to
|
|
* make sure the inode is removed from the
|
|
* orphan list in that case.
|
|
*/
|
|
if (inode->i_nlink)
|
|
ext4_orphan_del(NULL, inode);
|
|
}
|
|
|
|
if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
|
|
goto retry;
|
|
|
|
if (page)
|
|
block_commit_write(page, from, to);
|
|
out:
|
|
if (page) {
|
|
unlock_page(page);
|
|
put_page(page);
|
|
}
|
|
if (sem_held)
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
if (handle)
|
|
ext4_journal_stop(handle);
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Try to write data in the inode.
|
|
* If the inode has inline data, check whether the new write can be
|
|
* in the inode also. If not, create the page the handle, move the data
|
|
* to the page make it update and let the later codes create extent for it.
|
|
*/
|
|
int ext4_try_to_write_inline_data(struct address_space *mapping,
|
|
struct inode *inode,
|
|
loff_t pos, unsigned len,
|
|
unsigned flags,
|
|
struct page **pagep)
|
|
{
|
|
int ret;
|
|
handle_t *handle;
|
|
struct page *page;
|
|
struct ext4_iloc iloc;
|
|
|
|
if (pos + len > ext4_get_max_inline_size(inode))
|
|
goto convert;
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/*
|
|
* The possible write could happen in the inode,
|
|
* so try to reserve the space in inode first.
|
|
*/
|
|
handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
|
|
if (IS_ERR(handle)) {
|
|
ret = PTR_ERR(handle);
|
|
handle = NULL;
|
|
goto out;
|
|
}
|
|
|
|
ret = ext4_prepare_inline_data(handle, inode, pos + len);
|
|
if (ret && ret != -ENOSPC)
|
|
goto out;
|
|
|
|
/* We don't have space in inline inode, so convert it to extent. */
|
|
if (ret == -ENOSPC) {
|
|
ext4_journal_stop(handle);
|
|
brelse(iloc.bh);
|
|
goto convert;
|
|
}
|
|
|
|
ret = ext4_journal_get_write_access(handle, iloc.bh);
|
|
if (ret)
|
|
goto out;
|
|
|
|
flags |= AOP_FLAG_NOFS;
|
|
|
|
page = grab_cache_page_write_begin(mapping, 0, flags);
|
|
if (!page) {
|
|
ret = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
*pagep = page;
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
ret = 0;
|
|
unlock_page(page);
|
|
put_page(page);
|
|
goto out_up_read;
|
|
}
|
|
|
|
if (!PageUptodate(page)) {
|
|
ret = ext4_read_inline_page(inode, page);
|
|
if (ret < 0) {
|
|
unlock_page(page);
|
|
put_page(page);
|
|
goto out_up_read;
|
|
}
|
|
}
|
|
|
|
ret = 1;
|
|
handle = NULL;
|
|
out_up_read:
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
out:
|
|
if (handle && (ret != 1))
|
|
ext4_journal_stop(handle);
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
convert:
|
|
return ext4_convert_inline_data_to_extent(mapping,
|
|
inode, flags);
|
|
}
|
|
|
|
int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
|
|
unsigned copied, struct page *page)
|
|
{
|
|
int ret, no_expand;
|
|
void *kaddr;
|
|
struct ext4_iloc iloc;
|
|
|
|
if (unlikely(copied < len)) {
|
|
if (!PageUptodate(page)) {
|
|
copied = 0;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret) {
|
|
ext4_std_error(inode->i_sb, ret);
|
|
copied = 0;
|
|
goto out;
|
|
}
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
BUG_ON(!ext4_has_inline_data(inode));
|
|
|
|
kaddr = kmap_atomic(page);
|
|
ext4_write_inline_data(inode, &iloc, kaddr, pos, len);
|
|
kunmap_atomic(kaddr);
|
|
SetPageUptodate(page);
|
|
/* clear page dirty so that writepages wouldn't work for us. */
|
|
ClearPageDirty(page);
|
|
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
brelse(iloc.bh);
|
|
mark_inode_dirty(inode);
|
|
out:
|
|
return copied;
|
|
}
|
|
|
|
struct buffer_head *
|
|
ext4_journalled_write_inline_data(struct inode *inode,
|
|
unsigned len,
|
|
struct page *page)
|
|
{
|
|
int ret, no_expand;
|
|
void *kaddr;
|
|
struct ext4_iloc iloc;
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret) {
|
|
ext4_std_error(inode->i_sb, ret);
|
|
return NULL;
|
|
}
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
kaddr = kmap_atomic(page);
|
|
ext4_write_inline_data(inode, &iloc, kaddr, 0, len);
|
|
kunmap_atomic(kaddr);
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
|
|
return iloc.bh;
|
|
}
|
|
|
|
/*
|
|
* Try to make the page cache and handle ready for the inline data case.
|
|
* We can call this function in 2 cases:
|
|
* 1. The inode is created and the first write exceeds inline size. We can
|
|
* clear the inode state safely.
|
|
* 2. The inode has inline data, then we need to read the data, make it
|
|
* update and dirty so that ext4_da_writepages can handle it. We don't
|
|
* need to start the journal since the file's metatdata isn't changed now.
|
|
*/
|
|
static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
|
|
struct inode *inode,
|
|
unsigned flags,
|
|
void **fsdata)
|
|
{
|
|
int ret = 0, inline_size;
|
|
struct page *page;
|
|
|
|
page = grab_cache_page_write_begin(mapping, 0, flags);
|
|
if (!page)
|
|
return -ENOMEM;
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
goto out;
|
|
}
|
|
|
|
inline_size = ext4_get_inline_size(inode);
|
|
|
|
if (!PageUptodate(page)) {
|
|
ret = ext4_read_inline_page(inode, page);
|
|
if (ret < 0)
|
|
goto out;
|
|
}
|
|
|
|
ret = __block_write_begin(page, 0, inline_size,
|
|
ext4_da_get_block_prep);
|
|
if (ret) {
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
unlock_page(page);
|
|
put_page(page);
|
|
ext4_truncate_failed_write(inode);
|
|
return ret;
|
|
}
|
|
|
|
SetPageDirty(page);
|
|
SetPageUptodate(page);
|
|
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
*fsdata = (void *)CONVERT_INLINE_DATA;
|
|
|
|
out:
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
if (page) {
|
|
unlock_page(page);
|
|
put_page(page);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Prepare the write for the inline data.
|
|
* If the the data can be written into the inode, we just read
|
|
* the page and make it uptodate, and start the journal.
|
|
* Otherwise read the page, makes it dirty so that it can be
|
|
* handle in writepages(the i_disksize update is left to the
|
|
* normal ext4_da_write_end).
|
|
*/
|
|
int ext4_da_write_inline_data_begin(struct address_space *mapping,
|
|
struct inode *inode,
|
|
loff_t pos, unsigned len,
|
|
unsigned flags,
|
|
struct page **pagep,
|
|
void **fsdata)
|
|
{
|
|
int ret, inline_size;
|
|
handle_t *handle;
|
|
struct page *page;
|
|
struct ext4_iloc iloc;
|
|
int retries = 0;
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
retry_journal:
|
|
handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
|
|
if (IS_ERR(handle)) {
|
|
ret = PTR_ERR(handle);
|
|
goto out;
|
|
}
|
|
|
|
inline_size = ext4_get_max_inline_size(inode);
|
|
|
|
ret = -ENOSPC;
|
|
if (inline_size >= pos + len) {
|
|
ret = ext4_prepare_inline_data(handle, inode, pos + len);
|
|
if (ret && ret != -ENOSPC)
|
|
goto out_journal;
|
|
}
|
|
|
|
/*
|
|
* We cannot recurse into the filesystem as the transaction
|
|
* is already started.
|
|
*/
|
|
flags |= AOP_FLAG_NOFS;
|
|
|
|
if (ret == -ENOSPC) {
|
|
ext4_journal_stop(handle);
|
|
ret = ext4_da_convert_inline_data_to_extent(mapping,
|
|
inode,
|
|
flags,
|
|
fsdata);
|
|
if (ret == -ENOSPC &&
|
|
ext4_should_retry_alloc(inode->i_sb, &retries))
|
|
goto retry_journal;
|
|
goto out;
|
|
}
|
|
|
|
page = grab_cache_page_write_begin(mapping, 0, flags);
|
|
if (!page) {
|
|
ret = -ENOMEM;
|
|
goto out_journal;
|
|
}
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
ret = 0;
|
|
goto out_release_page;
|
|
}
|
|
|
|
if (!PageUptodate(page)) {
|
|
ret = ext4_read_inline_page(inode, page);
|
|
if (ret < 0)
|
|
goto out_release_page;
|
|
}
|
|
ret = ext4_journal_get_write_access(handle, iloc.bh);
|
|
if (ret)
|
|
goto out_release_page;
|
|
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
*pagep = page;
|
|
brelse(iloc.bh);
|
|
return 1;
|
|
out_release_page:
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
unlock_page(page);
|
|
put_page(page);
|
|
out_journal:
|
|
ext4_journal_stop(handle);
|
|
out:
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
|
|
unsigned len, unsigned copied,
|
|
struct page *page)
|
|
{
|
|
int ret;
|
|
|
|
ret = ext4_write_inline_data_end(inode, pos, len, copied, page);
|
|
if (ret < 0) {
|
|
unlock_page(page);
|
|
put_page(page);
|
|
return ret;
|
|
}
|
|
copied = ret;
|
|
|
|
/*
|
|
* No need to use i_size_read() here, the i_size
|
|
* cannot change under us because we hold i_mutex.
|
|
*
|
|
* But it's important to update i_size while still holding page lock:
|
|
* page writeout could otherwise come in and zero beyond i_size.
|
|
*/
|
|
if (pos+copied > inode->i_size)
|
|
i_size_write(inode, pos+copied);
|
|
unlock_page(page);
|
|
put_page(page);
|
|
|
|
/*
|
|
* Don't mark the inode dirty under page lock. First, it unnecessarily
|
|
* makes the holding time of page lock longer. Second, it forces lock
|
|
* ordering of page lock and transaction start for journaling
|
|
* filesystems.
|
|
*/
|
|
mark_inode_dirty(inode);
|
|
|
|
return copied;
|
|
}
|
|
|
|
#ifdef INLINE_DIR_DEBUG
|
|
void ext4_show_inline_dir(struct inode *dir, struct buffer_head *bh,
|
|
void *inline_start, int inline_size)
|
|
{
|
|
int offset;
|
|
unsigned short de_len;
|
|
struct ext4_dir_entry_2 *de = inline_start;
|
|
void *dlimit = inline_start + inline_size;
|
|
|
|
trace_printk("inode %lu\n", dir->i_ino);
|
|
offset = 0;
|
|
while ((void *)de < dlimit) {
|
|
de_len = ext4_rec_len_from_disk(de->rec_len, inline_size);
|
|
trace_printk("de: off %u rlen %u name %.*s nlen %u ino %u\n",
|
|
offset, de_len, de->name_len, de->name,
|
|
de->name_len, le32_to_cpu(de->inode));
|
|
if (ext4_check_dir_entry(dir, NULL, de, bh,
|
|
inline_start, inline_size, offset))
|
|
BUG();
|
|
|
|
offset += de_len;
|
|
de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
|
|
}
|
|
}
|
|
#else
|
|
#define ext4_show_inline_dir(dir, bh, inline_start, inline_size)
|
|
#endif
|
|
|
|
/*
|
|
* Add a new entry into a inline dir.
|
|
* It will return -ENOSPC if no space is available, and -EIO
|
|
* and -EEXIST if directory entry already exists.
|
|
*/
|
|
static int ext4_add_dirent_to_inline(handle_t *handle,
|
|
struct ext4_filename *fname,
|
|
struct inode *dir,
|
|
struct inode *inode,
|
|
struct ext4_iloc *iloc,
|
|
void *inline_start, int inline_size)
|
|
{
|
|
int err;
|
|
struct ext4_dir_entry_2 *de;
|
|
|
|
err = ext4_find_dest_de(dir, inode, iloc->bh, inline_start,
|
|
inline_size, fname, &de);
|
|
if (err)
|
|
return err;
|
|
|
|
BUFFER_TRACE(iloc->bh, "get_write_access");
|
|
err = ext4_journal_get_write_access(handle, iloc->bh);
|
|
if (err)
|
|
return err;
|
|
ext4_insert_dentry(inode, de, inline_size, fname);
|
|
|
|
ext4_show_inline_dir(dir, iloc->bh, inline_start, inline_size);
|
|
|
|
/*
|
|
* XXX shouldn't update any times until successful
|
|
* completion of syscall, but too many callers depend
|
|
* on this.
|
|
*
|
|
* XXX similarly, too many callers depend on
|
|
* ext4_new_inode() setting the times, but error
|
|
* recovery deletes the inode, so the worst that can
|
|
* happen is that the times are slightly out of date
|
|
* and/or different from the directory change time.
|
|
*/
|
|
dir->i_mtime = dir->i_ctime = current_time(dir);
|
|
ext4_update_dx_flag(dir);
|
|
inode_inc_iversion(dir);
|
|
return 1;
|
|
}
|
|
|
|
static void *ext4_get_inline_xattr_pos(struct inode *inode,
|
|
struct ext4_iloc *iloc)
|
|
{
|
|
struct ext4_xattr_entry *entry;
|
|
struct ext4_xattr_ibody_header *header;
|
|
|
|
BUG_ON(!EXT4_I(inode)->i_inline_off);
|
|
|
|
header = IHDR(inode, ext4_raw_inode(iloc));
|
|
entry = (struct ext4_xattr_entry *)((void *)ext4_raw_inode(iloc) +
|
|
EXT4_I(inode)->i_inline_off);
|
|
|
|
return (void *)IFIRST(header) + le16_to_cpu(entry->e_value_offs);
|
|
}
|
|
|
|
/* Set the final de to cover the whole block. */
|
|
static void ext4_update_final_de(void *de_buf, int old_size, int new_size)
|
|
{
|
|
struct ext4_dir_entry_2 *de, *prev_de;
|
|
void *limit;
|
|
int de_len;
|
|
|
|
de = (struct ext4_dir_entry_2 *)de_buf;
|
|
if (old_size) {
|
|
limit = de_buf + old_size;
|
|
do {
|
|
prev_de = de;
|
|
de_len = ext4_rec_len_from_disk(de->rec_len, old_size);
|
|
de_buf += de_len;
|
|
de = (struct ext4_dir_entry_2 *)de_buf;
|
|
} while (de_buf < limit);
|
|
|
|
prev_de->rec_len = ext4_rec_len_to_disk(de_len + new_size -
|
|
old_size, new_size);
|
|
} else {
|
|
/* this is just created, so create an empty entry. */
|
|
de->inode = 0;
|
|
de->rec_len = ext4_rec_len_to_disk(new_size, new_size);
|
|
}
|
|
}
|
|
|
|
static int ext4_update_inline_dir(handle_t *handle, struct inode *dir,
|
|
struct ext4_iloc *iloc)
|
|
{
|
|
int ret;
|
|
int old_size = EXT4_I(dir)->i_inline_size - EXT4_MIN_INLINE_DATA_SIZE;
|
|
int new_size = get_max_inline_xattr_value_size(dir, iloc);
|
|
|
|
if (new_size - old_size <= EXT4_DIR_REC_LEN(1))
|
|
return -ENOSPC;
|
|
|
|
ret = ext4_update_inline_data(handle, dir,
|
|
new_size + EXT4_MIN_INLINE_DATA_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ext4_update_final_de(ext4_get_inline_xattr_pos(dir, iloc), old_size,
|
|
EXT4_I(dir)->i_inline_size -
|
|
EXT4_MIN_INLINE_DATA_SIZE);
|
|
dir->i_size = EXT4_I(dir)->i_disksize = EXT4_I(dir)->i_inline_size;
|
|
return 0;
|
|
}
|
|
|
|
static void ext4_restore_inline_data(handle_t *handle, struct inode *inode,
|
|
struct ext4_iloc *iloc,
|
|
void *buf, int inline_size)
|
|
{
|
|
ext4_create_inline_data(handle, inode, inline_size);
|
|
ext4_write_inline_data(inode, iloc, buf, 0, inline_size);
|
|
ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
}
|
|
|
|
static int ext4_finish_convert_inline_dir(handle_t *handle,
|
|
struct inode *inode,
|
|
struct buffer_head *dir_block,
|
|
void *buf,
|
|
int inline_size)
|
|
{
|
|
int err, csum_size = 0, header_size = 0;
|
|
struct ext4_dir_entry_2 *de;
|
|
struct ext4_dir_entry_tail *t;
|
|
void *target = dir_block->b_data;
|
|
|
|
/*
|
|
* First create "." and ".." and then copy the dir information
|
|
* back to the block.
|
|
*/
|
|
de = (struct ext4_dir_entry_2 *)target;
|
|
de = ext4_init_dot_dotdot(inode, de,
|
|
inode->i_sb->s_blocksize, csum_size,
|
|
le32_to_cpu(((struct ext4_dir_entry_2 *)buf)->inode), 1);
|
|
header_size = (void *)de - target;
|
|
|
|
memcpy((void *)de, buf + EXT4_INLINE_DOTDOT_SIZE,
|
|
inline_size - EXT4_INLINE_DOTDOT_SIZE);
|
|
|
|
if (ext4_has_metadata_csum(inode->i_sb))
|
|
csum_size = sizeof(struct ext4_dir_entry_tail);
|
|
|
|
inode->i_size = inode->i_sb->s_blocksize;
|
|
i_size_write(inode, inode->i_sb->s_blocksize);
|
|
EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
|
|
ext4_update_final_de(dir_block->b_data,
|
|
inline_size - EXT4_INLINE_DOTDOT_SIZE + header_size,
|
|
inode->i_sb->s_blocksize - csum_size);
|
|
|
|
if (csum_size) {
|
|
t = EXT4_DIRENT_TAIL(dir_block->b_data,
|
|
inode->i_sb->s_blocksize);
|
|
initialize_dirent_tail(t, inode->i_sb->s_blocksize);
|
|
}
|
|
set_buffer_uptodate(dir_block);
|
|
err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
|
|
if (err)
|
|
return err;
|
|
set_buffer_verified(dir_block);
|
|
return ext4_mark_inode_dirty(handle, inode);
|
|
}
|
|
|
|
static int ext4_convert_inline_data_nolock(handle_t *handle,
|
|
struct inode *inode,
|
|
struct ext4_iloc *iloc)
|
|
{
|
|
int error;
|
|
void *buf = NULL;
|
|
struct buffer_head *data_bh = NULL;
|
|
struct ext4_map_blocks map;
|
|
int inline_size;
|
|
|
|
inline_size = ext4_get_inline_size(inode);
|
|
buf = kmalloc(inline_size, GFP_NOFS);
|
|
if (!buf) {
|
|
error = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
error = ext4_read_inline_data(inode, buf, inline_size, iloc);
|
|
if (error < 0)
|
|
goto out;
|
|
|
|
/*
|
|
* Make sure the inline directory entries pass checks before we try to
|
|
* convert them, so that we avoid touching stuff that needs fsck.
|
|
*/
|
|
if (S_ISDIR(inode->i_mode)) {
|
|
error = ext4_check_all_de(inode, iloc->bh,
|
|
buf + EXT4_INLINE_DOTDOT_SIZE,
|
|
inline_size - EXT4_INLINE_DOTDOT_SIZE);
|
|
if (error)
|
|
goto out;
|
|
}
|
|
|
|
error = ext4_destroy_inline_data_nolock(handle, inode);
|
|
if (error)
|
|
goto out;
|
|
|
|
map.m_lblk = 0;
|
|
map.m_len = 1;
|
|
map.m_flags = 0;
|
|
error = ext4_map_blocks(handle, inode, &map, EXT4_GET_BLOCKS_CREATE);
|
|
if (error < 0)
|
|
goto out_restore;
|
|
if (!(map.m_flags & EXT4_MAP_MAPPED)) {
|
|
error = -EIO;
|
|
goto out_restore;
|
|
}
|
|
|
|
data_bh = sb_getblk(inode->i_sb, map.m_pblk);
|
|
if (!data_bh) {
|
|
error = -ENOMEM;
|
|
goto out_restore;
|
|
}
|
|
|
|
lock_buffer(data_bh);
|
|
error = ext4_journal_get_create_access(handle, data_bh);
|
|
if (error) {
|
|
unlock_buffer(data_bh);
|
|
error = -EIO;
|
|
goto out_restore;
|
|
}
|
|
memset(data_bh->b_data, 0, inode->i_sb->s_blocksize);
|
|
|
|
if (!S_ISDIR(inode->i_mode)) {
|
|
memcpy(data_bh->b_data, buf, inline_size);
|
|
set_buffer_uptodate(data_bh);
|
|
error = ext4_handle_dirty_metadata(handle,
|
|
inode, data_bh);
|
|
} else {
|
|
error = ext4_finish_convert_inline_dir(handle, inode, data_bh,
|
|
buf, inline_size);
|
|
}
|
|
|
|
unlock_buffer(data_bh);
|
|
out_restore:
|
|
if (error)
|
|
ext4_restore_inline_data(handle, inode, iloc, buf, inline_size);
|
|
|
|
out:
|
|
brelse(data_bh);
|
|
kfree(buf);
|
|
return error;
|
|
}
|
|
|
|
/*
|
|
* Try to add the new entry to the inline data.
|
|
* If succeeds, return 0. If not, extended the inline dir and copied data to
|
|
* the new created block.
|
|
*/
|
|
int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
|
|
struct inode *dir, struct inode *inode)
|
|
{
|
|
int ret, inline_size, no_expand;
|
|
void *inline_start;
|
|
struct ext4_iloc iloc;
|
|
|
|
ret = ext4_get_inode_loc(dir, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ext4_write_lock_xattr(dir, &no_expand);
|
|
if (!ext4_has_inline_data(dir))
|
|
goto out;
|
|
|
|
inline_start = (void *)ext4_raw_inode(&iloc)->i_block +
|
|
EXT4_INLINE_DOTDOT_SIZE;
|
|
inline_size = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DOTDOT_SIZE;
|
|
|
|
ret = ext4_add_dirent_to_inline(handle, fname, dir, inode, &iloc,
|
|
inline_start, inline_size);
|
|
if (ret != -ENOSPC)
|
|
goto out;
|
|
|
|
/* check whether it can be inserted to inline xattr space. */
|
|
inline_size = EXT4_I(dir)->i_inline_size -
|
|
EXT4_MIN_INLINE_DATA_SIZE;
|
|
if (!inline_size) {
|
|
/* Try to use the xattr space.*/
|
|
ret = ext4_update_inline_dir(handle, dir, &iloc);
|
|
if (ret && ret != -ENOSPC)
|
|
goto out;
|
|
|
|
inline_size = EXT4_I(dir)->i_inline_size -
|
|
EXT4_MIN_INLINE_DATA_SIZE;
|
|
}
|
|
|
|
if (inline_size) {
|
|
inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
|
|
|
|
ret = ext4_add_dirent_to_inline(handle, fname, dir,
|
|
inode, &iloc, inline_start,
|
|
inline_size);
|
|
|
|
if (ret != -ENOSPC)
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* The inline space is filled up, so create a new block for it.
|
|
* As the extent tree will be created, we have to save the inline
|
|
* dir first.
|
|
*/
|
|
ret = ext4_convert_inline_data_nolock(handle, dir, &iloc);
|
|
|
|
out:
|
|
ext4_write_unlock_xattr(dir, &no_expand);
|
|
ext4_mark_inode_dirty(handle, dir);
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* This function fills a red-black tree with information from an
|
|
* inlined dir. It returns the number directory entries loaded
|
|
* into the tree. If there is an error it is returned in err.
|
|
*/
|
|
int htree_inlinedir_to_tree(struct file *dir_file,
|
|
struct inode *dir, ext4_lblk_t block,
|
|
struct dx_hash_info *hinfo,
|
|
__u32 start_hash, __u32 start_minor_hash,
|
|
int *has_inline_data)
|
|
{
|
|
int err = 0, count = 0;
|
|
unsigned int parent_ino;
|
|
int pos;
|
|
struct ext4_dir_entry_2 *de;
|
|
struct inode *inode = file_inode(dir_file);
|
|
int ret, inline_size = 0;
|
|
struct ext4_iloc iloc;
|
|
void *dir_buf = NULL;
|
|
struct ext4_dir_entry_2 fake;
|
|
struct fscrypt_str tmp_str;
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
*has_inline_data = 0;
|
|
goto out;
|
|
}
|
|
|
|
inline_size = ext4_get_inline_size(inode);
|
|
dir_buf = kmalloc(inline_size, GFP_NOFS);
|
|
if (!dir_buf) {
|
|
ret = -ENOMEM;
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
goto out;
|
|
}
|
|
|
|
ret = ext4_read_inline_data(inode, dir_buf, inline_size, &iloc);
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
pos = 0;
|
|
parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
|
|
while (pos < inline_size) {
|
|
/*
|
|
* As inlined dir doesn't store any information about '.' and
|
|
* only the inode number of '..' is stored, we have to handle
|
|
* them differently.
|
|
*/
|
|
if (pos == 0) {
|
|
fake.inode = cpu_to_le32(inode->i_ino);
|
|
fake.name_len = 1;
|
|
strcpy(fake.name, ".");
|
|
fake.rec_len = ext4_rec_len_to_disk(
|
|
EXT4_DIR_REC_LEN(fake.name_len),
|
|
inline_size);
|
|
ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
|
|
de = &fake;
|
|
pos = EXT4_INLINE_DOTDOT_OFFSET;
|
|
} else if (pos == EXT4_INLINE_DOTDOT_OFFSET) {
|
|
fake.inode = cpu_to_le32(parent_ino);
|
|
fake.name_len = 2;
|
|
strcpy(fake.name, "..");
|
|
fake.rec_len = ext4_rec_len_to_disk(
|
|
EXT4_DIR_REC_LEN(fake.name_len),
|
|
inline_size);
|
|
ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
|
|
de = &fake;
|
|
pos = EXT4_INLINE_DOTDOT_SIZE;
|
|
} else {
|
|
de = (struct ext4_dir_entry_2 *)(dir_buf + pos);
|
|
pos += ext4_rec_len_from_disk(de->rec_len, inline_size);
|
|
if (ext4_check_dir_entry(inode, dir_file, de,
|
|
iloc.bh, dir_buf,
|
|
inline_size, pos)) {
|
|
ret = count;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
ext4fs_dirhash(dir, de->name, de->name_len, hinfo);
|
|
if ((hinfo->hash < start_hash) ||
|
|
((hinfo->hash == start_hash) &&
|
|
(hinfo->minor_hash < start_minor_hash)))
|
|
continue;
|
|
if (de->inode == 0)
|
|
continue;
|
|
tmp_str.name = de->name;
|
|
tmp_str.len = de->name_len;
|
|
err = ext4_htree_store_dirent(dir_file, hinfo->hash,
|
|
hinfo->minor_hash, de, &tmp_str);
|
|
if (err) {
|
|
ret = err;
|
|
goto out;
|
|
}
|
|
count++;
|
|
}
|
|
ret = count;
|
|
out:
|
|
kfree(dir_buf);
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* So this function is called when the volume is mkfsed with
|
|
* dir_index disabled. In order to keep f_pos persistent
|
|
* after we convert from an inlined dir to a blocked based,
|
|
* we just pretend that we are a normal dir and return the
|
|
* offset as if '.' and '..' really take place.
|
|
*
|
|
*/
|
|
int ext4_read_inline_dir(struct file *file,
|
|
struct dir_context *ctx,
|
|
int *has_inline_data)
|
|
{
|
|
unsigned int offset, parent_ino;
|
|
int i;
|
|
struct ext4_dir_entry_2 *de;
|
|
struct super_block *sb;
|
|
struct inode *inode = file_inode(file);
|
|
int ret, inline_size = 0;
|
|
struct ext4_iloc iloc;
|
|
void *dir_buf = NULL;
|
|
int dotdot_offset, dotdot_size, extra_offset, extra_size;
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
*has_inline_data = 0;
|
|
goto out;
|
|
}
|
|
|
|
inline_size = ext4_get_inline_size(inode);
|
|
dir_buf = kmalloc(inline_size, GFP_NOFS);
|
|
if (!dir_buf) {
|
|
ret = -ENOMEM;
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
goto out;
|
|
}
|
|
|
|
ret = ext4_read_inline_data(inode, dir_buf, inline_size, &iloc);
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
ret = 0;
|
|
sb = inode->i_sb;
|
|
parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
|
|
offset = ctx->pos;
|
|
|
|
/*
|
|
* dotdot_offset and dotdot_size is the real offset and
|
|
* size for ".." and "." if the dir is block based while
|
|
* the real size for them are only EXT4_INLINE_DOTDOT_SIZE.
|
|
* So we will use extra_offset and extra_size to indicate them
|
|
* during the inline dir iteration.
|
|
*/
|
|
dotdot_offset = EXT4_DIR_REC_LEN(1);
|
|
dotdot_size = dotdot_offset + EXT4_DIR_REC_LEN(2);
|
|
extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE;
|
|
extra_size = extra_offset + inline_size;
|
|
|
|
/*
|
|
* If the version has changed since the last call to
|
|
* readdir(2), then we might be pointing to an invalid
|
|
* dirent right now. Scan from the start of the inline
|
|
* dir to make sure.
|
|
*/
|
|
if (!inode_eq_iversion(inode, file->f_version)) {
|
|
for (i = 0; i < extra_size && i < offset;) {
|
|
/*
|
|
* "." is with offset 0 and
|
|
* ".." is dotdot_offset.
|
|
*/
|
|
if (!i) {
|
|
i = dotdot_offset;
|
|
continue;
|
|
} else if (i == dotdot_offset) {
|
|
i = dotdot_size;
|
|
continue;
|
|
}
|
|
/* for other entry, the real offset in
|
|
* the buf has to be tuned accordingly.
|
|
*/
|
|
de = (struct ext4_dir_entry_2 *)
|
|
(dir_buf + i - extra_offset);
|
|
/* It's too expensive to do a full
|
|
* dirent test each time round this
|
|
* loop, but we do have to test at
|
|
* least that it is non-zero. A
|
|
* failure will be detected in the
|
|
* dirent test below. */
|
|
if (ext4_rec_len_from_disk(de->rec_len, extra_size)
|
|
< EXT4_DIR_REC_LEN(1))
|
|
break;
|
|
i += ext4_rec_len_from_disk(de->rec_len,
|
|
extra_size);
|
|
}
|
|
offset = i;
|
|
ctx->pos = offset;
|
|
file->f_version = inode_query_iversion(inode);
|
|
}
|
|
|
|
while (ctx->pos < extra_size) {
|
|
if (ctx->pos == 0) {
|
|
if (!dir_emit(ctx, ".", 1, inode->i_ino, DT_DIR))
|
|
goto out;
|
|
ctx->pos = dotdot_offset;
|
|
continue;
|
|
}
|
|
|
|
if (ctx->pos == dotdot_offset) {
|
|
if (!dir_emit(ctx, "..", 2, parent_ino, DT_DIR))
|
|
goto out;
|
|
ctx->pos = dotdot_size;
|
|
continue;
|
|
}
|
|
|
|
de = (struct ext4_dir_entry_2 *)
|
|
(dir_buf + ctx->pos - extra_offset);
|
|
if (ext4_check_dir_entry(inode, file, de, iloc.bh, dir_buf,
|
|
extra_size, ctx->pos))
|
|
goto out;
|
|
if (le32_to_cpu(de->inode)) {
|
|
if (!dir_emit(ctx, de->name, de->name_len,
|
|
le32_to_cpu(de->inode),
|
|
get_dtype(sb, de->file_type)))
|
|
goto out;
|
|
}
|
|
ctx->pos += ext4_rec_len_from_disk(de->rec_len, extra_size);
|
|
}
|
|
out:
|
|
kfree(dir_buf);
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
|
|
struct ext4_dir_entry_2 **parent_de,
|
|
int *retval)
|
|
{
|
|
struct ext4_iloc iloc;
|
|
|
|
*retval = ext4_get_inode_loc(inode, &iloc);
|
|
if (*retval)
|
|
return NULL;
|
|
|
|
*parent_de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
|
|
|
|
return iloc.bh;
|
|
}
|
|
|
|
/*
|
|
* Try to create the inline data for the new dir.
|
|
* If it succeeds, return 0, otherwise return the error.
|
|
* In case of ENOSPC, the caller should create the normal disk layout dir.
|
|
*/
|
|
int ext4_try_create_inline_dir(handle_t *handle, struct inode *parent,
|
|
struct inode *inode)
|
|
{
|
|
int ret, inline_size = EXT4_MIN_INLINE_DATA_SIZE;
|
|
struct ext4_iloc iloc;
|
|
struct ext4_dir_entry_2 *de;
|
|
|
|
ret = ext4_get_inode_loc(inode, &iloc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = ext4_prepare_inline_data(handle, inode, inline_size);
|
|
if (ret)
|
|
goto out;
|
|
|
|
/*
|
|
* For inline dir, we only save the inode information for the ".."
|
|
* and create a fake dentry to cover the left space.
|
|
*/
|
|
de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
|
|
de->inode = cpu_to_le32(parent->i_ino);
|
|
de = (struct ext4_dir_entry_2 *)((void *)de + EXT4_INLINE_DOTDOT_SIZE);
|
|
de->inode = 0;
|
|
de->rec_len = ext4_rec_len_to_disk(
|
|
inline_size - EXT4_INLINE_DOTDOT_SIZE,
|
|
inline_size);
|
|
set_nlink(inode, 2);
|
|
inode->i_size = EXT4_I(inode)->i_disksize = inline_size;
|
|
out:
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
struct buffer_head *ext4_find_inline_entry(struct inode *dir,
|
|
struct ext4_filename *fname,
|
|
struct ext4_dir_entry_2 **res_dir,
|
|
int *has_inline_data)
|
|
{
|
|
int ret;
|
|
struct ext4_iloc iloc;
|
|
void *inline_start;
|
|
int inline_size;
|
|
|
|
if (ext4_get_inode_loc(dir, &iloc))
|
|
return NULL;
|
|
|
|
down_read(&EXT4_I(dir)->xattr_sem);
|
|
if (!ext4_has_inline_data(dir)) {
|
|
*has_inline_data = 0;
|
|
goto out;
|
|
}
|
|
|
|
inline_start = (void *)ext4_raw_inode(&iloc)->i_block +
|
|
EXT4_INLINE_DOTDOT_SIZE;
|
|
inline_size = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DOTDOT_SIZE;
|
|
ret = ext4_search_dir(iloc.bh, inline_start, inline_size,
|
|
dir, fname, 0, res_dir);
|
|
if (ret == 1)
|
|
goto out_find;
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
if (ext4_get_inline_size(dir) == EXT4_MIN_INLINE_DATA_SIZE)
|
|
goto out;
|
|
|
|
inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
|
|
inline_size = ext4_get_inline_size(dir) - EXT4_MIN_INLINE_DATA_SIZE;
|
|
|
|
ret = ext4_search_dir(iloc.bh, inline_start, inline_size,
|
|
dir, fname, 0, res_dir);
|
|
if (ret == 1)
|
|
goto out_find;
|
|
|
|
out:
|
|
brelse(iloc.bh);
|
|
iloc.bh = NULL;
|
|
out_find:
|
|
up_read(&EXT4_I(dir)->xattr_sem);
|
|
return iloc.bh;
|
|
}
|
|
|
|
int ext4_delete_inline_entry(handle_t *handle,
|
|
struct inode *dir,
|
|
struct ext4_dir_entry_2 *de_del,
|
|
struct buffer_head *bh,
|
|
int *has_inline_data)
|
|
{
|
|
int err, inline_size, no_expand;
|
|
struct ext4_iloc iloc;
|
|
void *inline_start;
|
|
|
|
err = ext4_get_inode_loc(dir, &iloc);
|
|
if (err)
|
|
return err;
|
|
|
|
ext4_write_lock_xattr(dir, &no_expand);
|
|
if (!ext4_has_inline_data(dir)) {
|
|
*has_inline_data = 0;
|
|
goto out;
|
|
}
|
|
|
|
if ((void *)de_del - ((void *)ext4_raw_inode(&iloc)->i_block) <
|
|
EXT4_MIN_INLINE_DATA_SIZE) {
|
|
inline_start = (void *)ext4_raw_inode(&iloc)->i_block +
|
|
EXT4_INLINE_DOTDOT_SIZE;
|
|
inline_size = EXT4_MIN_INLINE_DATA_SIZE -
|
|
EXT4_INLINE_DOTDOT_SIZE;
|
|
} else {
|
|
inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
|
|
inline_size = ext4_get_inline_size(dir) -
|
|
EXT4_MIN_INLINE_DATA_SIZE;
|
|
}
|
|
|
|
BUFFER_TRACE(bh, "get_write_access");
|
|
err = ext4_journal_get_write_access(handle, bh);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = ext4_generic_delete_entry(handle, dir, de_del, bh,
|
|
inline_start, inline_size, 0);
|
|
if (err)
|
|
goto out;
|
|
|
|
ext4_show_inline_dir(dir, iloc.bh, inline_start, inline_size);
|
|
out:
|
|
ext4_write_unlock_xattr(dir, &no_expand);
|
|
if (likely(err == 0))
|
|
err = ext4_mark_inode_dirty(handle, dir);
|
|
brelse(iloc.bh);
|
|
if (err != -ENOENT)
|
|
ext4_std_error(dir->i_sb, err);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Get the inline dentry at offset.
|
|
*/
|
|
static inline struct ext4_dir_entry_2 *
|
|
ext4_get_inline_entry(struct inode *inode,
|
|
struct ext4_iloc *iloc,
|
|
unsigned int offset,
|
|
void **inline_start,
|
|
int *inline_size)
|
|
{
|
|
void *inline_pos;
|
|
|
|
BUG_ON(offset > ext4_get_inline_size(inode));
|
|
|
|
if (offset < EXT4_MIN_INLINE_DATA_SIZE) {
|
|
inline_pos = (void *)ext4_raw_inode(iloc)->i_block;
|
|
*inline_size = EXT4_MIN_INLINE_DATA_SIZE;
|
|
} else {
|
|
inline_pos = ext4_get_inline_xattr_pos(inode, iloc);
|
|
offset -= EXT4_MIN_INLINE_DATA_SIZE;
|
|
*inline_size = ext4_get_inline_size(inode) -
|
|
EXT4_MIN_INLINE_DATA_SIZE;
|
|
}
|
|
|
|
if (inline_start)
|
|
*inline_start = inline_pos;
|
|
return (struct ext4_dir_entry_2 *)(inline_pos + offset);
|
|
}
|
|
|
|
bool empty_inline_dir(struct inode *dir, int *has_inline_data)
|
|
{
|
|
int err, inline_size;
|
|
struct ext4_iloc iloc;
|
|
size_t inline_len;
|
|
void *inline_pos;
|
|
unsigned int offset;
|
|
struct ext4_dir_entry_2 *de;
|
|
bool ret = true;
|
|
|
|
err = ext4_get_inode_loc(dir, &iloc);
|
|
if (err) {
|
|
EXT4_ERROR_INODE(dir, "error %d getting inode %lu block",
|
|
err, dir->i_ino);
|
|
return true;
|
|
}
|
|
|
|
down_read(&EXT4_I(dir)->xattr_sem);
|
|
if (!ext4_has_inline_data(dir)) {
|
|
*has_inline_data = 0;
|
|
goto out;
|
|
}
|
|
|
|
de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
|
|
if (!le32_to_cpu(de->inode)) {
|
|
ext4_warning(dir->i_sb,
|
|
"bad inline directory (dir #%lu) - no `..'",
|
|
dir->i_ino);
|
|
ret = true;
|
|
goto out;
|
|
}
|
|
|
|
inline_len = ext4_get_inline_size(dir);
|
|
offset = EXT4_INLINE_DOTDOT_SIZE;
|
|
while (offset < inline_len) {
|
|
de = ext4_get_inline_entry(dir, &iloc, offset,
|
|
&inline_pos, &inline_size);
|
|
if (ext4_check_dir_entry(dir, NULL, de,
|
|
iloc.bh, inline_pos,
|
|
inline_size, offset)) {
|
|
ext4_warning(dir->i_sb,
|
|
"bad inline directory (dir #%lu) - "
|
|
"inode %u, rec_len %u, name_len %d"
|
|
"inline size %d",
|
|
dir->i_ino, le32_to_cpu(de->inode),
|
|
le16_to_cpu(de->rec_len), de->name_len,
|
|
inline_size);
|
|
ret = true;
|
|
goto out;
|
|
}
|
|
if (le32_to_cpu(de->inode)) {
|
|
ret = false;
|
|
goto out;
|
|
}
|
|
offset += ext4_rec_len_from_disk(de->rec_len, inline_size);
|
|
}
|
|
|
|
out:
|
|
up_read(&EXT4_I(dir)->xattr_sem);
|
|
brelse(iloc.bh);
|
|
return ret;
|
|
}
|
|
|
|
int ext4_destroy_inline_data(handle_t *handle, struct inode *inode)
|
|
{
|
|
int ret, no_expand;
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
ret = ext4_destroy_inline_data_nolock(handle, inode);
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap)
|
|
{
|
|
__u64 addr;
|
|
int error = -EAGAIN;
|
|
struct ext4_iloc iloc;
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode))
|
|
goto out;
|
|
|
|
error = ext4_get_inode_loc(inode, &iloc);
|
|
if (error)
|
|
goto out;
|
|
|
|
addr = (__u64)iloc.bh->b_blocknr << inode->i_sb->s_blocksize_bits;
|
|
addr += (char *)ext4_raw_inode(&iloc) - iloc.bh->b_data;
|
|
addr += offsetof(struct ext4_inode, i_block);
|
|
|
|
brelse(iloc.bh);
|
|
|
|
iomap->addr = addr;
|
|
iomap->offset = 0;
|
|
iomap->length = min_t(loff_t, ext4_get_inline_size(inode),
|
|
i_size_read(inode));
|
|
iomap->type = IOMAP_INLINE;
|
|
iomap->flags = 0;
|
|
|
|
out:
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
return error;
|
|
}
|
|
|
|
int ext4_inline_data_fiemap(struct inode *inode,
|
|
struct fiemap_extent_info *fieinfo,
|
|
int *has_inline, __u64 start, __u64 len)
|
|
{
|
|
__u64 physical = 0;
|
|
__u64 inline_len;
|
|
__u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
|
|
FIEMAP_EXTENT_LAST;
|
|
int error = 0;
|
|
struct ext4_iloc iloc;
|
|
|
|
down_read(&EXT4_I(inode)->xattr_sem);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
*has_inline = 0;
|
|
goto out;
|
|
}
|
|
inline_len = min_t(size_t, ext4_get_inline_size(inode),
|
|
i_size_read(inode));
|
|
if (start >= inline_len)
|
|
goto out;
|
|
if (start + len < inline_len)
|
|
inline_len = start + len;
|
|
inline_len -= start;
|
|
|
|
error = ext4_get_inode_loc(inode, &iloc);
|
|
if (error)
|
|
goto out;
|
|
|
|
physical = (__u64)iloc.bh->b_blocknr << inode->i_sb->s_blocksize_bits;
|
|
physical += (char *)ext4_raw_inode(&iloc) - iloc.bh->b_data;
|
|
physical += offsetof(struct ext4_inode, i_block);
|
|
|
|
brelse(iloc.bh);
|
|
out:
|
|
up_read(&EXT4_I(inode)->xattr_sem);
|
|
if (physical)
|
|
error = fiemap_fill_next_extent(fieinfo, start, physical,
|
|
inline_len, flags);
|
|
return (error < 0 ? error : 0);
|
|
}
|
|
|
|
int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
|
|
{
|
|
handle_t *handle;
|
|
int inline_size, value_len, needed_blocks, no_expand, err = 0;
|
|
size_t i_size;
|
|
void *value = NULL;
|
|
struct ext4_xattr_ibody_find is = {
|
|
.s = { .not_found = -ENODATA, },
|
|
};
|
|
struct ext4_xattr_info i = {
|
|
.name_index = EXT4_XATTR_INDEX_SYSTEM,
|
|
.name = EXT4_XATTR_SYSTEM_DATA,
|
|
};
|
|
|
|
|
|
needed_blocks = ext4_writepage_trans_blocks(inode);
|
|
handle = ext4_journal_start(inode, EXT4_HT_INODE, needed_blocks);
|
|
if (IS_ERR(handle))
|
|
return PTR_ERR(handle);
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
if (!ext4_has_inline_data(inode)) {
|
|
*has_inline = 0;
|
|
ext4_journal_stop(handle);
|
|
return 0;
|
|
}
|
|
|
|
if ((err = ext4_orphan_add(handle, inode)) != 0)
|
|
goto out;
|
|
|
|
if ((err = ext4_get_inode_loc(inode, &is.iloc)) != 0)
|
|
goto out;
|
|
|
|
down_write(&EXT4_I(inode)->i_data_sem);
|
|
i_size = inode->i_size;
|
|
inline_size = ext4_get_inline_size(inode);
|
|
EXT4_I(inode)->i_disksize = i_size;
|
|
|
|
if (i_size < inline_size) {
|
|
/* Clear the content in the xattr space. */
|
|
if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) {
|
|
if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0)
|
|
goto out_error;
|
|
|
|
BUG_ON(is.s.not_found);
|
|
|
|
value_len = le32_to_cpu(is.s.here->e_value_size);
|
|
value = kmalloc(value_len, GFP_NOFS);
|
|
if (!value) {
|
|
err = -ENOMEM;
|
|
goto out_error;
|
|
}
|
|
|
|
err = ext4_xattr_ibody_get(inode, i.name_index,
|
|
i.name, value, value_len);
|
|
if (err <= 0)
|
|
goto out_error;
|
|
|
|
i.value = value;
|
|
i.value_len = i_size > EXT4_MIN_INLINE_DATA_SIZE ?
|
|
i_size - EXT4_MIN_INLINE_DATA_SIZE : 0;
|
|
err = ext4_xattr_ibody_inline_set(handle, inode,
|
|
&i, &is);
|
|
if (err)
|
|
goto out_error;
|
|
}
|
|
|
|
/* Clear the content within i_blocks. */
|
|
if (i_size < EXT4_MIN_INLINE_DATA_SIZE) {
|
|
void *p = (void *) ext4_raw_inode(&is.iloc)->i_block;
|
|
memset(p + i_size, 0,
|
|
EXT4_MIN_INLINE_DATA_SIZE - i_size);
|
|
}
|
|
|
|
EXT4_I(inode)->i_inline_size = i_size <
|
|
EXT4_MIN_INLINE_DATA_SIZE ?
|
|
EXT4_MIN_INLINE_DATA_SIZE : i_size;
|
|
}
|
|
|
|
out_error:
|
|
up_write(&EXT4_I(inode)->i_data_sem);
|
|
out:
|
|
brelse(is.iloc.bh);
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
kfree(value);
|
|
if (inode->i_nlink)
|
|
ext4_orphan_del(handle, inode);
|
|
|
|
if (err == 0) {
|
|
inode->i_mtime = inode->i_ctime = current_time(inode);
|
|
err = ext4_mark_inode_dirty(handle, inode);
|
|
if (IS_SYNC(inode))
|
|
ext4_handle_sync(handle);
|
|
}
|
|
ext4_journal_stop(handle);
|
|
return err;
|
|
}
|
|
|
|
int ext4_convert_inline_data(struct inode *inode)
|
|
{
|
|
int error, needed_blocks, no_expand;
|
|
handle_t *handle;
|
|
struct ext4_iloc iloc;
|
|
|
|
if (!ext4_has_inline_data(inode)) {
|
|
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
|
|
return 0;
|
|
}
|
|
|
|
needed_blocks = ext4_writepage_trans_blocks(inode);
|
|
|
|
iloc.bh = NULL;
|
|
error = ext4_get_inode_loc(inode, &iloc);
|
|
if (error)
|
|
return error;
|
|
|
|
handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks);
|
|
if (IS_ERR(handle)) {
|
|
error = PTR_ERR(handle);
|
|
goto out_free;
|
|
}
|
|
|
|
ext4_write_lock_xattr(inode, &no_expand);
|
|
if (ext4_has_inline_data(inode))
|
|
error = ext4_convert_inline_data_nolock(handle, inode, &iloc);
|
|
ext4_write_unlock_xattr(inode, &no_expand);
|
|
ext4_journal_stop(handle);
|
|
out_free:
|
|
brelse(iloc.bh);
|
|
return error;
|
|
}
|