Changes in 4.19.323 staging: iio: frequency: ad9833: Get frequency value statically staging: iio: frequency: ad9833: Load clock using clock framework staging: iio: frequency: ad9834: Validate frequency parameter value usbnet: ipheth: fix carrier detection in modes 1 and 4 net: ethernet: use ip_hdrlen() instead of bit shift net: phy: vitesse: repair vsc73xx autonegotiation scripts: kconfig: merge_config: config files: add a trailing newline arm64: dts: rockchip: override BIOS_DISABLE signal via GPIO hog on RK3399 Puma net/mlx5: Update the list of the PCI supported devices net: ftgmac100: Enable TX interrupt to avoid TX timeout net: dpaa: Pad packets to ETH_ZLEN soundwire: stream: Revert "soundwire: stream: fix programming slave ports for non-continous port maps" selftests/vm: remove call to ksft_set_plan() selftests/kcmp: remove call to ksft_set_plan() ASoC: allow module autoloading for table db1200_pids pinctrl: at91: make it work with current gpiolib microblaze: don't treat zero reserved memory regions as error net: ftgmac100: Ensure tx descriptor updates are visible wifi: iwlwifi: mvm: fix iwl_mvm_max_scan_ie_fw_cmd_room() wifi: iwlwifi: mvm: don't wait for tx queues if firmware is dead ASoC: tda7419: fix module autoloading spi: bcm63xx: Enable module autoloading x86/hyperv: Set X86_FEATURE_TSC_KNOWN_FREQ when Hyper-V provides frequency ocfs2: add bounds checking to ocfs2_xattr_find_entry() ocfs2: strict bound check before memcmp in ocfs2_xattr_find_entry() gpio: prevent potential speculation leaks in gpio_device_get_desc() USB: serial: pl2303: add device id for Macrosilicon MS3020 ACPI: PMIC: Remove unneeded check in tps68470_pmic_opregion_probe() wifi: ath9k: fix parameter check in ath9k_init_debug() wifi: ath9k: Remove error checks when creating debugfs entries netfilter: nf_tables: elements with timeout below CONFIG_HZ never expire wifi: cfg80211: fix UBSAN noise in cfg80211_wext_siwscan() wifi: cfg80211: fix two more possible UBSAN-detected off-by-one errors wifi: mac80211: use two-phase skb reclamation in ieee80211_do_stop() can: bcm: Clear bo->bcm_proc_read after remove_proc_entry(). Bluetooth: btusb: Fix not handling ZPL/short-transfer block, bfq: fix possible UAF for bfqq->bic with merge chain block, bfq: choose the last bfqq from merge chain in bfq_setup_cooperator() block, bfq: don't break merge chain in bfq_split_bfqq() spi: ppc4xx: handle irq_of_parse_and_map() errors spi: ppc4xx: Avoid returning 0 when failed to parse and map IRQ ARM: versatile: fix OF node leak in CPUs prepare reset: berlin: fix OF node leak in probe() error path clocksource/drivers/qcom: Add missing iounmap() on errors in msm_dt_timer_init() hwmon: (max16065) Fix overflows seen when writing limits mtd: slram: insert break after errors in parsing the map hwmon: (ntc_thermistor) fix module autoloading power: supply: max17042_battery: Fix SOC threshold calc w/ no current sense fbdev: hpfb: Fix an error handling path in hpfb_dio_probe() drm/stm: Fix an error handling path in stm_drm_platform_probe() drm/amd: fix typo drm/amdgpu: Replace one-element array with flexible-array member drm/amdgpu: properly handle vbios fake edid sizing drm/radeon: Replace one-element array with flexible-array member drm/radeon: properly handle vbios fake edid sizing drm/rockchip: vop: Allow 4096px width scaling drm/radeon/evergreen_cs: fix int overflow errors in cs track offsets jfs: fix out-of-bounds in dbNextAG() and diAlloc() drm/msm/a5xx: properly clear preemption records on resume drm/msm/a5xx: fix races in preemption evaluation stage ipmi: docs: don't advertise deprecated sysfs entries drm/msm: fix %s null argument error xen: use correct end address of kernel for conflict checking xen/swiotlb: simplify range_straddles_page_boundary() xen/swiotlb: add alignment check for dma buffers selftests/bpf: Fix error compiling test_lru_map.c xz: cleanup CRC32 edits from 2018 kthread: add kthread_work tracepoints kthread: fix task state in kthread worker if being frozen jbd2: introduce/export functions jbd2_journal_submit|finish_inode_data_buffers() ext4: clear EXT4_GROUP_INFO_WAS_TRIMMED_BIT even mount with discard smackfs: Use rcu_assign_pointer() to ensure safe assignment in smk_set_cipso ext4: avoid negative min_clusters in find_group_orlov() ext4: return error on ext4_find_inline_entry ext4: avoid OOB when system.data xattr changes underneath the filesystem nilfs2: fix potential null-ptr-deref in nilfs_btree_insert() nilfs2: determine empty node blocks as corrupted nilfs2: fix potential oob read in nilfs_btree_check_delete() perf sched timehist: Fix missing free of session in perf_sched__timehist() perf sched timehist: Fixed timestamp error when unable to confirm event sched_in time perf time-utils: Fix 32-bit nsec parsing clk: rockchip: Set parent rate for DCLK_VOP clock on RK3228 drivers: media: dvb-frontends/rtl2832: fix an out-of-bounds write error drivers: media: dvb-frontends/rtl2830: fix an out-of-bounds write error PCI: xilinx-nwl: Fix register misspelling RDMA/iwcm: Fix WARNING:at_kernel/workqueue.c:#check_flush_dependency pinctrl: single: fix missing error code in pcs_probe() clk: ti: dra7-atl: Fix leak of of_nodes pinctrl: mvebu: Fix devinit_dove_pinctrl_probe function RDMA/cxgb4: Added NULL check for lookup_atid ntb: intel: Fix the NULL vs IS_ERR() bug for debugfs_create_dir() nfsd: call cache_put if xdr_reserve_space returns NULL f2fs: enhance to update i_mode and acl atomically in f2fs_setattr() f2fs: fix typo f2fs: fix to update i_ctime in __f2fs_setxattr() f2fs: remove unneeded check condition in __f2fs_setxattr() f2fs: reduce expensive checkpoint trigger frequency coresight: tmc: sg: Do not leak sg_table netfilter: nf_reject_ipv6: fix nf_reject_ip6_tcphdr_put() net: seeq: Fix use after free vulnerability in ether3 Driver Due to Race Condition tcp: introduce tcp_skb_timestamp_us() helper tcp: check skb is non-NULL in tcp_rto_delta_us() net: qrtr: Update packets cloning when broadcasting netfilter: ctnetlink: compile ctnetlink_label_size with CONFIG_NF_CONNTRACK_EVENTS crypto: aead,cipher - zeroize key buffer after use Remove *.orig pattern from .gitignore soc: versatile: integrator: fix OF node leak in probe() error path USB: appledisplay: close race between probe and completion handler USB: misc: cypress_cy7c63: check for short transfer firmware_loader: Block path traversal tty: rp2: Fix reset with non forgiving PCIe host bridges drbd: Fix atomicity violation in drbd_uuid_set_bm() drbd: Add NULL check for net_conf to prevent dereference in state validation ACPI: sysfs: validate return type of _STR method f2fs: prevent possible int overflow in dir_block_index() f2fs: avoid potential int overflow in sanity_check_area_boundary() vfs: fix race between evice_inodes() and find_inode()&iput() fs: Fix file_set_fowner LSM hook inconsistencies nfs: fix memory leak in error path of nfs4_do_reclaim PCI: xilinx-nwl: Use irq_data_get_irq_chip_data() PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler soc: versatile: realview: fix memory leak during device remove soc: versatile: realview: fix soc_dev leak during device remove usb: yurex: Replace snprintf() with the safer scnprintf() variant USB: misc: yurex: fix race between read and write pps: remove usage of the deprecated ida_simple_xx() API pps: add an error check in parport_attach i2c: aspeed: Update the stop sw state when the bus recovery occurs i2c: isch: Add missed 'else' usb: yurex: Fix inconsistent locking bug in yurex_read() mailbox: rockchip: fix a typo in module autoloading mailbox: bcm2835: Fix timeout during suspend mode ceph: remove the incorrect Fw reference check when dirtying pages netfilter: uapi: NFTA_FLOWTABLE_HOOK is NLA_NESTED netfilter: nf_tables: prevent nf_skb_duplicated corruption r8152: Factor out OOB link list waits net: ethernet: lantiq_etop: fix memory disclosure net: avoid potential underflow in qdisc_pkt_len_init() with UFO net: add more sanity checks to qdisc_pkt_len_init() ipv4: ip_gre: Fix drops of small packets in ipgre_xmit sctp: set sk_state back to CLOSED if autobind fails in sctp_listen_start ALSA: hda/generic: Unconditionally prefer preferred_dacs pairs ALSA: hda/conexant: Fix conflicting quirk for System76 Pangolin f2fs: Require FMODE_WRITE for atomic write ioctls wifi: ath9k: fix possible integer overflow in ath9k_get_et_stats() wifi: ath9k_htc: Use __skb_set_length() for resetting urb before resubmit net: hisilicon: hip04: fix OF node leak in probe() net: hisilicon: hns_dsaf_mac: fix OF node leak in hns_mac_get_info() net: hisilicon: hns_mdio: fix OF node leak in probe() ACPICA: Fix memory leak if acpi_ps_get_next_namepath() fails ACPICA: Fix memory leak if acpi_ps_get_next_field() fails ACPI: EC: Do not release locks during operation region accesses ACPICA: check null return of ACPI_ALLOCATE_ZEROED() in acpi_db_convert_to_package() tipc: guard against string buffer overrun net: mvpp2: Increase size of queue_name buffer ipv4: Check !in_dev earlier for ioctl(SIOCSIFADDR). ipv4: Mask upper DSCP bits and ECN bits in NETLINK_FIB_LOOKUP family tcp: avoid reusing FIN_WAIT2 when trying to find port in connect() process ACPICA: iasl: handle empty connection_node wifi: mwifiex: Fix memcpy() field-spanning write warning in mwifiex_cmd_802_11_scan_ext() signal: Replace BUG_ON()s ALSA: asihpi: Fix potential OOB array access ALSA: hdsp: Break infinite MIDI input flush loop fbdev: pxafb: Fix possible use after free in pxafb_task() power: reset: brcmstb: Do not go into infinite loop if reset fails ata: sata_sil: Rename sil_blacklist to sil_quirks jfs: UBSAN: shift-out-of-bounds in dbFindBits jfs: Fix uaf in dbFreeBits jfs: check if leafidx greater than num leaves per dmap tree jfs: Fix uninit-value access of new_ea in ea_buffer drm/amd/display: Check stream before comparing them drm/amd/display: Fix index out of bounds in degamma hardware format translation drm/printer: Allow NULL data in devcoredump printer scsi: aacraid: Rearrange order of struct aac_srb_unit drm/radeon/r100: Handle unknown family in r100_cp_init_microcode() of/irq: Refer to actual buffer size in of_irq_parse_one() ext4: ext4_search_dir should return a proper error ext4: fix i_data_sem unlock order in ext4_ind_migrate() spi: s3c64xx: fix timeout counters in flush_fifo selftests: breakpoints: use remaining time to check if suspend succeed selftests: vDSO: fix vDSO symbols lookup for powerpc64 i2c: xiic: Wait for TX empty to avoid missed TX NAKs spi: bcm63xx: Fix module autoloading perf/core: Fix small negative period being ignored parisc: Fix itlb miss handler for 64-bit programs ALSA: core: add isascii() check to card ID generator ext4: no need to continue when the number of entries is 1 ext4: propagate errors from ext4_find_extent() in ext4_insert_range() ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space() ext4: aovid use-after-free in ext4_ext_insert_extent() ext4: fix double brelse() the buffer of the extents path ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit() parisc: Fix 64-bit userspace syscall path of/irq: Support #msi-cells=<0> in of_msi_get_domain jbd2: stop waiting for space when jbd2_cleanup_journal_tail() returns error ocfs2: fix the la space leak when unmounting an ocfs2 volume ocfs2: fix uninit-value in ocfs2_get_block() ocfs2: reserve space for inline xattr before attaching reflink tree ocfs2: cancel dqi_sync_work before freeing oinfo ocfs2: remove unreasonable unlock in ocfs2_read_blocks ocfs2: fix null-ptr-deref when journal load failed. ocfs2: fix possible null-ptr-deref in ocfs2_set_buffer_uptodate riscv: define ILLEGAL_POINTER_VALUE for 64bit aoe: fix the potential use-after-free problem in more places clk: rockchip: fix error for unknown clocks media: uapi/linux/cec.h: cec_msg_set_reply_to: zero flags media: venus: fix use after free bug in venus_remove due to race condition iio: magnetometer: ak8975: Fix reading for ak099xx sensors tomoyo: fallback to realpath if symlink's pathname does not exist Input: adp5589-keys - fix adp5589_gpio_get_value() btrfs: wait for fixup workers before stopping cleaner kthread during umount gpio: davinci: fix lazy disable ext4: avoid ext4_error()'s caused by ENOMEM in the truncate path ext4: fix slab-use-after-free in ext4_split_extent_at() ext4: update orig_path in ext4_find_extent() arm64: Add Cortex-715 CPU part definition arm64: cputype: Add Neoverse-N3 definitions arm64: errata: Expand speculative SSBS workaround once more uprobes: fix kernel info leak via "[uprobes]" vma nfsd: use ktime_get_seconds() for timestamps nfsd: fix delegation_blocked() to block correctly for at least 30 seconds rtc: at91sam9: drop platform_data support rtc: at91sam9: fix OF node leak in probe() error path ACPI: battery: Simplify battery hook locking ACPI: battery: Fix possible crash when unregistering a battery hook ext4: fix inode tree inconsistency caused by ENOMEM net: ethernet: cortina: Drop TSO support tracing: Remove precision vsnprintf() check from print event drm: Move drm_mode_setcrtc() local re-init to failure path drm/crtc: fix uninitialized variable use even harder virtio_console: fix misc probe bugs Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal bpf: Check percpu map value size first s390/facility: Disable compile time optimization for decompressor code s390/mm: Add cond_resched() to cmm_alloc/free_pages() ext4: nested locking for xattr inode s390/cpum_sf: Remove WARN_ON_ONCE statements ktest.pl: Avoid false positives with grub2 skip regex clk: bcm: bcm53573: fix OF node leak in init i2c: i801: Use a different adapter-name for IDF adapters PCI: Mark Creative Labs EMU20k2 INTx masking as broken media: videobuf2-core: clear memory related fields in __vb2_plane_dmabuf_put() usb: chipidea: udc: enable suspend interrupt after usb reset tools/iio: Add memory allocation failure check for trigger_name driver core: bus: Return -EIO instead of 0 when show/store invalid bus attribute fbdev: sisfb: Fix strbuf array overflow NFS: Remove print_overflow_msg() SUNRPC: Fix integer overflow in decode_rc_list() tcp: fix tcp_enter_recovery() to zero retrans_stamp when it's safe netfilter: br_netfilter: fix panic with metadata_dst skb Bluetooth: RFCOMM: FIX possible deadlock in rfcomm_sk_state_change gpio: aspeed: Add the flush write to ensure the write complete. clk: Add (devm_)clk_get_optional() functions clk: generalize devm_clk_get() a bit clk: Provide new devm_clk helpers for prepared and enabled clocks gpio: aspeed: Use devm_clk api to manage clock source igb: Do not bring the device up after non-fatal error net: ibm: emac: mal: fix wrong goto ppp: fix ppp_async_encode() illegal access net: ipv6: ensure we call ipv6_mc_down() at most once CDC-NCM: avoid overflow in sanity checking HID: plantronics: Workaround for an unexcepted opposite volume key Revert "usb: yurex: Replace snprintf() with the safer scnprintf() variant" usb: xhci: Fix problem with xhci resume from suspend usb: storage: ignore bogus device raised by JieLi BR21 USB sound chip net: Fix an unsafe loop on the list posix-clock: Fix missing timespec64 check in pc_clock_settime() arm64: probes: Remove broken LDR (literal) uprobe support arm64: probes: Fix simulate_ldr*_literal() PCI: Add function 0 DMA alias quirk for Glenfly Arise chip fat: fix uninitialized variable KVM: Fix a data race on last_boosted_vcpu in kvm_vcpu_on_spin() net: dsa: mv88e6xxx: Fix out-of-bound access s390/sclp_vt220: Convert newlines to CRLF instead of LFCR KVM: s390: Change virtual to physical address access in diag 0x258 handler x86/cpufeatures: Define X86_FEATURE_AMD_IBPB_RET drm/vmwgfx: Handle surface check failure correctly iio: dac: stm32-dac-core: add missing select REGMAP_MMIO in Kconfig iio: adc: ti-ads8688: add missing select IIO_(TRIGGERED_)BUFFER in Kconfig iio: hid-sensors: Fix an error handling path in _hid_sensor_set_report_latency() iio: light: opt3001: add missing full-scale range value Bluetooth: Remove debugfs directory on module init failure Bluetooth: btusb: Fix regression with fake CSR controllers 0a12:0001 xhci: Fix incorrect stream context type macro USB: serial: option: add support for Quectel EG916Q-GL USB: serial: option: add Telit FN920C04 MBIM compositions parport: Proper fix for array out-of-bounds access x86/apic: Always explicitly disarm TSC-deadline timer nilfs2: propagate directory read errors from nilfs_find_entry() clk: Fix pointer casting to prevent oops in devm_clk_release() clk: Fix slab-out-of-bounds error in devm_clk_release() RDMA/bnxt_re: Fix incorrect AVID type in WQE structure RDMA/cxgb4: Fix RDMA_CM_EVENT_UNREACHABLE error for iWARP RDMA/bnxt_re: Return more meaningful error drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation macsec: don't increment counters for an unrelated SA net: ethernet: aeroflex: fix potential memory leak in greth_start_xmit_gbit() net: systemport: fix potential memory leak in bcm_sysport_xmit() usb: typec: altmode should keep reference to parent Bluetooth: bnep: fix wild-memory-access in proto_unregister arm64:uprobe fix the uprobe SWBP_INSN in big-endian arm64: probes: Fix uprobes for big-endian kernels KVM: s390: gaccess: Refactor gpa and length calculation KVM: s390: gaccess: Refactor access address range check KVM: s390: gaccess: Cleanup access to guest pages KVM: s390: gaccess: Check if guest address is in memslot udf: fix uninit-value use in udf_get_fileshortad jfs: Fix sanity check in dbMount net/sun3_82586: fix potential memory leak in sun3_82586_send_packet() be2net: fix potential memory leak in be_xmit() net: usb: usbnet: fix name regression posix-clock: posix-clock: Fix unbalanced locking in pc_clock_settime() ALSA: hda/realtek: Update default depop procedure drm/amd: Guard against bad data for ATIF ACPI method ACPI: button: Add DMI quirk for Samsung Galaxy Book2 to fix initial lid detection issue nilfs2: fix kernel bug due to missing clearing of buffer delay flag hv_netvsc: Fix VF namespace also in synthetic NIC NETDEV_REGISTER event selinux: improve error checking in sel_write_load() arm64/uprobes: change the uprobe_opcode_t typedef to fix the sparse warning xfrm: validate new SA's prefixlen using SA family when sel.family is unset usb: dwc3: remove generic PHY calibrate() calls usb: dwc3: Add splitdisable quirk for Hisilicon Kirin Soc usb: dwc3: core: Stop processing of pending events if controller is halted cgroup: Fix potential overflow issue when checking max_depth wifi: mac80211: skip non-uploaded keys in ieee80211_iter_keys gtp: simplify error handling code in 'gtp_encap_enable()' gtp: allow -1 to be specified as file description from userspace net/sched: stop qdisc_tree_reduce_backlog on TC_H_ROOT bpf: Fix out-of-bounds write in trie_get_next_key() net: support ip generic csum processing in skb_csum_hwoffload_help net: skip offload for NETIF_F_IPV6_CSUM if ipv6 header contains extension netfilter: nft_payload: sanitize offset and length before calling skb_checksum() firmware: arm_sdei: Fix the input parameter of cpuhp_remove_state() net: amd: mvme147: Fix probe banner message misc: sgi-gru: Don't disable preemption in GRU driver usbip: tools: Fix detach_port() invalid port error path usb: phy: Fix API devm_usb_put_phy() can not release the phy xhci: Fix Link TRB DMA in command ring stopped completion event Revert "driver core: Fix uevent_show() vs driver detach race" wifi: mac80211: do not pass a stopped vif to the driver in .get_txpower wifi: ath10k: Fix memory leak in management tx wifi: iwlegacy: Clear stale interrupts before resuming device nilfs2: fix potential deadlock with newly created symlinks ocfs2: pass u64 to ocfs2_truncate_inline maybe overflow nilfs2: fix kernel bug due to missing clearing of checked flag mm: shmem: fix data-race in shmem_getattr() vt: prevent kernel-infoleak in con_font_get() Linux 4.19.323 Change-Id: I2348f834187153067ab46b3b48b8fe7da9cee1f1 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
697 lines
21 KiB
C
697 lines
21 KiB
C
// SPDX-License-Identifier: LGPL-2.1
|
|
/*
|
|
* Copyright (c) 2008,2009 NEC Software Tohoku, Ltd.
|
|
* Written by Takashi Sato <t-sato@yk.jp.nec.com>
|
|
* Akira Fujita <a-fujita@rs.jp.nec.com>
|
|
*/
|
|
|
|
#include <linux/fs.h>
|
|
#include <linux/quotaops.h>
|
|
#include <linux/slab.h>
|
|
#include "ext4_jbd2.h"
|
|
#include "ext4.h"
|
|
#include "ext4_extents.h"
|
|
|
|
/**
|
|
* get_ext_path - Find an extent path for designated logical block number.
|
|
*
|
|
* @inode: an inode which is searched
|
|
* @lblock: logical block number to find an extent path
|
|
* @path: pointer to an extent path pointer (for output)
|
|
*
|
|
* ext4_find_extent wrapper. Return 0 on success, or a negative error value
|
|
* on failure.
|
|
*/
|
|
static inline int
|
|
get_ext_path(struct inode *inode, ext4_lblk_t lblock,
|
|
struct ext4_ext_path **ppath)
|
|
{
|
|
struct ext4_ext_path *path;
|
|
|
|
path = ext4_find_extent(inode, lblock, ppath, EXT4_EX_NOCACHE);
|
|
if (IS_ERR(path))
|
|
return PTR_ERR(path);
|
|
if (path[ext_depth(inode)].p_ext == NULL) {
|
|
ext4_ext_drop_refs(path);
|
|
kfree(path);
|
|
*ppath = NULL;
|
|
return -ENODATA;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* ext4_double_down_write_data_sem - Acquire two inodes' write lock
|
|
* of i_data_sem
|
|
*
|
|
* Acquire write lock of i_data_sem of the two inodes
|
|
*/
|
|
void
|
|
ext4_double_down_write_data_sem(struct inode *first, struct inode *second)
|
|
{
|
|
if (first < second) {
|
|
down_write(&EXT4_I(first)->i_data_sem);
|
|
down_write_nested(&EXT4_I(second)->i_data_sem, I_DATA_SEM_OTHER);
|
|
} else {
|
|
down_write(&EXT4_I(second)->i_data_sem);
|
|
down_write_nested(&EXT4_I(first)->i_data_sem, I_DATA_SEM_OTHER);
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ext4_double_up_write_data_sem - Release two inodes' write lock of i_data_sem
|
|
*
|
|
* @orig_inode: original inode structure to be released its lock first
|
|
* @donor_inode: donor inode structure to be released its lock second
|
|
* Release write lock of i_data_sem of two inodes (orig and donor).
|
|
*/
|
|
void
|
|
ext4_double_up_write_data_sem(struct inode *orig_inode,
|
|
struct inode *donor_inode)
|
|
{
|
|
up_write(&EXT4_I(orig_inode)->i_data_sem);
|
|
up_write(&EXT4_I(donor_inode)->i_data_sem);
|
|
}
|
|
|
|
/**
|
|
* mext_check_coverage - Check that all extents in range has the same type
|
|
*
|
|
* @inode: inode in question
|
|
* @from: block offset of inode
|
|
* @count: block count to be checked
|
|
* @unwritten: extents expected to be unwritten
|
|
* @err: pointer to save error value
|
|
*
|
|
* Return 1 if all extents in range has expected type, and zero otherwise.
|
|
*/
|
|
static int
|
|
mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count,
|
|
int unwritten, int *err)
|
|
{
|
|
struct ext4_ext_path *path = NULL;
|
|
struct ext4_extent *ext;
|
|
int ret = 0;
|
|
ext4_lblk_t last = from + count;
|
|
while (from < last) {
|
|
*err = get_ext_path(inode, from, &path);
|
|
if (*err)
|
|
goto out;
|
|
ext = path[ext_depth(inode)].p_ext;
|
|
if (unwritten != ext4_ext_is_unwritten(ext))
|
|
goto out;
|
|
from += ext4_ext_get_actual_len(ext);
|
|
ext4_ext_drop_refs(path);
|
|
}
|
|
ret = 1;
|
|
out:
|
|
ext4_ext_drop_refs(path);
|
|
kfree(path);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* mext_page_double_lock - Grab and lock pages on both @inode1 and @inode2
|
|
*
|
|
* @inode1: the inode structure
|
|
* @inode2: the inode structure
|
|
* @index1: page index
|
|
* @index2: page index
|
|
* @page: result page vector
|
|
*
|
|
* Grab two locked pages for inode's by inode order
|
|
*/
|
|
static int
|
|
mext_page_double_lock(struct inode *inode1, struct inode *inode2,
|
|
pgoff_t index1, pgoff_t index2, struct page *page[2])
|
|
{
|
|
struct address_space *mapping[2];
|
|
unsigned fl = AOP_FLAG_NOFS;
|
|
|
|
BUG_ON(!inode1 || !inode2);
|
|
if (inode1 < inode2) {
|
|
mapping[0] = inode1->i_mapping;
|
|
mapping[1] = inode2->i_mapping;
|
|
} else {
|
|
swap(index1, index2);
|
|
mapping[0] = inode2->i_mapping;
|
|
mapping[1] = inode1->i_mapping;
|
|
}
|
|
|
|
page[0] = grab_cache_page_write_begin(mapping[0], index1, fl);
|
|
if (!page[0])
|
|
return -ENOMEM;
|
|
|
|
page[1] = grab_cache_page_write_begin(mapping[1], index2, fl);
|
|
if (!page[1]) {
|
|
unlock_page(page[0]);
|
|
put_page(page[0]);
|
|
return -ENOMEM;
|
|
}
|
|
/*
|
|
* grab_cache_page_write_begin() may not wait on page's writeback if
|
|
* BDI not demand that. But it is reasonable to be very conservative
|
|
* here and explicitly wait on page's writeback
|
|
*/
|
|
wait_on_page_writeback(page[0]);
|
|
wait_on_page_writeback(page[1]);
|
|
if (inode1 > inode2)
|
|
swap(page[0], page[1]);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Force page buffers uptodate w/o dropping page's lock */
|
|
static int
|
|
mext_page_mkuptodate(struct page *page, unsigned from, unsigned to)
|
|
{
|
|
struct inode *inode = page->mapping->host;
|
|
sector_t block;
|
|
struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
|
|
unsigned int blocksize, block_start, block_end;
|
|
int i, err, nr = 0, partial = 0;
|
|
BUG_ON(!PageLocked(page));
|
|
BUG_ON(PageWriteback(page));
|
|
|
|
if (PageUptodate(page))
|
|
return 0;
|
|
|
|
blocksize = i_blocksize(inode);
|
|
if (!page_has_buffers(page))
|
|
create_empty_buffers(page, blocksize, 0);
|
|
|
|
head = page_buffers(page);
|
|
block = (sector_t)page->index << (PAGE_SHIFT - inode->i_blkbits);
|
|
for (bh = head, block_start = 0; bh != head || !block_start;
|
|
block++, block_start = block_end, bh = bh->b_this_page) {
|
|
block_end = block_start + blocksize;
|
|
if (block_end <= from || block_start >= to) {
|
|
if (!buffer_uptodate(bh))
|
|
partial = 1;
|
|
continue;
|
|
}
|
|
if (buffer_uptodate(bh))
|
|
continue;
|
|
if (!buffer_mapped(bh)) {
|
|
err = ext4_get_block(inode, block, bh, 0);
|
|
if (err) {
|
|
SetPageError(page);
|
|
return err;
|
|
}
|
|
if (!buffer_mapped(bh)) {
|
|
zero_user(page, block_start, blocksize);
|
|
set_buffer_uptodate(bh);
|
|
continue;
|
|
}
|
|
}
|
|
BUG_ON(nr >= MAX_BUF_PER_PAGE);
|
|
arr[nr++] = bh;
|
|
}
|
|
/* No io required */
|
|
if (!nr)
|
|
goto out;
|
|
|
|
for (i = 0; i < nr; i++) {
|
|
bh = arr[i];
|
|
if (!bh_uptodate_or_lock(bh)) {
|
|
err = bh_submit_read(bh);
|
|
if (err)
|
|
return err;
|
|
}
|
|
}
|
|
out:
|
|
if (!partial)
|
|
SetPageUptodate(page);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* move_extent_per_page - Move extent data per page
|
|
*
|
|
* @o_filp: file structure of original file
|
|
* @donor_inode: donor inode
|
|
* @orig_page_offset: page index on original file
|
|
* @donor_page_offset: page index on donor file
|
|
* @data_offset_in_page: block index where data swapping starts
|
|
* @block_len_in_page: the number of blocks to be swapped
|
|
* @unwritten: orig extent is unwritten or not
|
|
* @err: pointer to save return value
|
|
*
|
|
* Save the data in original inode blocks and replace original inode extents
|
|
* with donor inode extents by calling ext4_swap_extents().
|
|
* Finally, write out the saved data in new original inode blocks. Return
|
|
* replaced block count.
|
|
*/
|
|
static int
|
|
move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
|
|
pgoff_t orig_page_offset, pgoff_t donor_page_offset,
|
|
int data_offset_in_page,
|
|
int block_len_in_page, int unwritten, int *err)
|
|
{
|
|
struct inode *orig_inode = file_inode(o_filp);
|
|
struct page *pagep[2] = {NULL, NULL};
|
|
handle_t *handle;
|
|
ext4_lblk_t orig_blk_offset, donor_blk_offset;
|
|
unsigned long blocksize = orig_inode->i_sb->s_blocksize;
|
|
unsigned int tmp_data_size, data_size, replaced_size;
|
|
int i, err2, jblocks, retries = 0;
|
|
int replaced_count = 0;
|
|
int from = data_offset_in_page << orig_inode->i_blkbits;
|
|
int blocks_per_page = PAGE_SIZE >> orig_inode->i_blkbits;
|
|
struct super_block *sb = orig_inode->i_sb;
|
|
struct buffer_head *bh = NULL;
|
|
|
|
/*
|
|
* It needs twice the amount of ordinary journal buffers because
|
|
* inode and donor_inode may change each different metadata blocks.
|
|
*/
|
|
again:
|
|
*err = 0;
|
|
jblocks = ext4_writepage_trans_blocks(orig_inode) * 2;
|
|
handle = ext4_journal_start(orig_inode, EXT4_HT_MOVE_EXTENTS, jblocks);
|
|
if (IS_ERR(handle)) {
|
|
*err = PTR_ERR(handle);
|
|
return 0;
|
|
}
|
|
|
|
orig_blk_offset = orig_page_offset * blocks_per_page +
|
|
data_offset_in_page;
|
|
|
|
donor_blk_offset = donor_page_offset * blocks_per_page +
|
|
data_offset_in_page;
|
|
|
|
/* Calculate data_size */
|
|
if ((orig_blk_offset + block_len_in_page - 1) ==
|
|
((orig_inode->i_size - 1) >> orig_inode->i_blkbits)) {
|
|
/* Replace the last block */
|
|
tmp_data_size = orig_inode->i_size & (blocksize - 1);
|
|
/*
|
|
* If data_size equal zero, it shows data_size is multiples of
|
|
* blocksize. So we set appropriate value.
|
|
*/
|
|
if (tmp_data_size == 0)
|
|
tmp_data_size = blocksize;
|
|
|
|
data_size = tmp_data_size +
|
|
((block_len_in_page - 1) << orig_inode->i_blkbits);
|
|
} else
|
|
data_size = block_len_in_page << orig_inode->i_blkbits;
|
|
|
|
replaced_size = data_size;
|
|
|
|
*err = mext_page_double_lock(orig_inode, donor_inode, orig_page_offset,
|
|
donor_page_offset, pagep);
|
|
if (unlikely(*err < 0))
|
|
goto stop_journal;
|
|
/*
|
|
* If orig extent was unwritten it can become initialized
|
|
* at any time after i_data_sem was dropped, in order to
|
|
* serialize with delalloc we have recheck extent while we
|
|
* hold page's lock, if it is still the case data copy is not
|
|
* necessary, just swap data blocks between orig and donor.
|
|
*/
|
|
if (unwritten) {
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
|
/* If any of extents in range became initialized we have to
|
|
* fallback to data copying */
|
|
unwritten = mext_check_coverage(orig_inode, orig_blk_offset,
|
|
block_len_in_page, 1, err);
|
|
if (*err)
|
|
goto drop_data_sem;
|
|
|
|
unwritten &= mext_check_coverage(donor_inode, donor_blk_offset,
|
|
block_len_in_page, 1, err);
|
|
if (*err)
|
|
goto drop_data_sem;
|
|
|
|
if (!unwritten) {
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
|
goto data_copy;
|
|
}
|
|
if ((page_has_private(pagep[0]) &&
|
|
!try_to_release_page(pagep[0], 0)) ||
|
|
(page_has_private(pagep[1]) &&
|
|
!try_to_release_page(pagep[1], 0))) {
|
|
*err = -EBUSY;
|
|
goto drop_data_sem;
|
|
}
|
|
replaced_count = ext4_swap_extents(handle, orig_inode,
|
|
donor_inode, orig_blk_offset,
|
|
donor_blk_offset,
|
|
block_len_in_page, 1, err);
|
|
drop_data_sem:
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
|
goto unlock_pages;
|
|
}
|
|
data_copy:
|
|
*err = mext_page_mkuptodate(pagep[0], from, from + replaced_size);
|
|
if (*err)
|
|
goto unlock_pages;
|
|
|
|
/* At this point all buffers in range are uptodate, old mapping layout
|
|
* is no longer required, try to drop it now. */
|
|
if ((page_has_private(pagep[0]) && !try_to_release_page(pagep[0], 0)) ||
|
|
(page_has_private(pagep[1]) && !try_to_release_page(pagep[1], 0))) {
|
|
*err = -EBUSY;
|
|
goto unlock_pages;
|
|
}
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
|
replaced_count = ext4_swap_extents(handle, orig_inode, donor_inode,
|
|
orig_blk_offset, donor_blk_offset,
|
|
block_len_in_page, 1, err);
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
|
if (*err) {
|
|
if (replaced_count) {
|
|
block_len_in_page = replaced_count;
|
|
replaced_size =
|
|
block_len_in_page << orig_inode->i_blkbits;
|
|
} else
|
|
goto unlock_pages;
|
|
}
|
|
/* Perform all necessary steps similar write_begin()/write_end()
|
|
* but keeping in mind that i_size will not change */
|
|
if (!page_has_buffers(pagep[0]))
|
|
create_empty_buffers(pagep[0], 1 << orig_inode->i_blkbits, 0);
|
|
bh = page_buffers(pagep[0]);
|
|
for (i = 0; i < data_offset_in_page; i++)
|
|
bh = bh->b_this_page;
|
|
for (i = 0; i < block_len_in_page; i++) {
|
|
*err = ext4_get_block(orig_inode, orig_blk_offset + i, bh, 0);
|
|
if (*err < 0)
|
|
break;
|
|
bh = bh->b_this_page;
|
|
}
|
|
if (!*err)
|
|
*err = block_commit_write(pagep[0], from, from + replaced_size);
|
|
|
|
if (unlikely(*err < 0))
|
|
goto repair_branches;
|
|
|
|
/* Even in case of data=writeback it is reasonable to pin
|
|
* inode to transaction, to prevent unexpected data loss */
|
|
*err = ext4_jbd2_inode_add_write(handle, orig_inode,
|
|
(loff_t)orig_page_offset << PAGE_SHIFT, replaced_size);
|
|
|
|
unlock_pages:
|
|
unlock_page(pagep[0]);
|
|
put_page(pagep[0]);
|
|
unlock_page(pagep[1]);
|
|
put_page(pagep[1]);
|
|
stop_journal:
|
|
ext4_journal_stop(handle);
|
|
if (*err == -ENOSPC &&
|
|
ext4_should_retry_alloc(sb, &retries))
|
|
goto again;
|
|
/* Buffer was busy because probably is pinned to journal transaction,
|
|
* force transaction commit may help to free it. */
|
|
if (*err == -EBUSY && retries++ < 4 && EXT4_SB(sb)->s_journal &&
|
|
jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal))
|
|
goto again;
|
|
return replaced_count;
|
|
|
|
repair_branches:
|
|
/*
|
|
* This should never ever happen!
|
|
* Extents are swapped already, but we are not able to copy data.
|
|
* Try to swap extents to it's original places
|
|
*/
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
|
replaced_count = ext4_swap_extents(handle, donor_inode, orig_inode,
|
|
orig_blk_offset, donor_blk_offset,
|
|
block_len_in_page, 0, &err2);
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
|
if (replaced_count != block_len_in_page) {
|
|
EXT4_ERROR_INODE_BLOCK(orig_inode, (sector_t)(orig_blk_offset),
|
|
"Unable to copy data block,"
|
|
" data will be lost.");
|
|
*err = -EIO;
|
|
}
|
|
replaced_count = 0;
|
|
goto unlock_pages;
|
|
}
|
|
|
|
/**
|
|
* mext_check_arguments - Check whether move extent can be done
|
|
*
|
|
* @orig_inode: original inode
|
|
* @donor_inode: donor inode
|
|
* @orig_start: logical start offset in block for orig
|
|
* @donor_start: logical start offset in block for donor
|
|
* @len: the number of blocks to be moved
|
|
*
|
|
* Check the arguments of ext4_move_extents() whether the files can be
|
|
* exchanged with each other.
|
|
* Return 0 on success, or a negative error value on failure.
|
|
*/
|
|
static int
|
|
mext_check_arguments(struct inode *orig_inode,
|
|
struct inode *donor_inode, __u64 orig_start,
|
|
__u64 donor_start, __u64 *len)
|
|
{
|
|
__u64 orig_eof, donor_eof;
|
|
unsigned int blkbits = orig_inode->i_blkbits;
|
|
unsigned int blocksize = 1 << blkbits;
|
|
|
|
orig_eof = (i_size_read(orig_inode) + blocksize - 1) >> blkbits;
|
|
donor_eof = (i_size_read(donor_inode) + blocksize - 1) >> blkbits;
|
|
|
|
|
|
if (donor_inode->i_mode & (S_ISUID|S_ISGID)) {
|
|
ext4_debug("ext4 move extent: suid or sgid is set"
|
|
" to donor file [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (IS_IMMUTABLE(donor_inode) || IS_APPEND(donor_inode))
|
|
return -EPERM;
|
|
|
|
/* Ext4 move extent does not support swapfile */
|
|
if (IS_SWAPFILE(orig_inode) || IS_SWAPFILE(donor_inode)) {
|
|
ext4_debug("ext4 move extent: The argument files should "
|
|
"not be swapfile [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EBUSY;
|
|
}
|
|
|
|
if (ext4_is_quota_file(orig_inode) && ext4_is_quota_file(donor_inode)) {
|
|
ext4_debug("ext4 move extent: The argument files should "
|
|
"not be quota files [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EBUSY;
|
|
}
|
|
|
|
/* Ext4 move extent supports only extent based file */
|
|
if (!(ext4_test_inode_flag(orig_inode, EXT4_INODE_EXTENTS))) {
|
|
ext4_debug("ext4 move extent: orig file is not extents "
|
|
"based file [ino:orig %lu]\n", orig_inode->i_ino);
|
|
return -EOPNOTSUPP;
|
|
} else if (!(ext4_test_inode_flag(donor_inode, EXT4_INODE_EXTENTS))) {
|
|
ext4_debug("ext4 move extent: donor file is not extents "
|
|
"based file [ino:donor %lu]\n", donor_inode->i_ino);
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
if ((!orig_inode->i_size) || (!donor_inode->i_size)) {
|
|
ext4_debug("ext4 move extent: File size is 0 byte\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Start offset should be same */
|
|
if ((orig_start & ~(PAGE_MASK >> orig_inode->i_blkbits)) !=
|
|
(donor_start & ~(PAGE_MASK >> orig_inode->i_blkbits))) {
|
|
ext4_debug("ext4 move extent: orig and donor's start "
|
|
"offsets are not aligned [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
|
|
if ((orig_start >= EXT_MAX_BLOCKS) ||
|
|
(donor_start >= EXT_MAX_BLOCKS) ||
|
|
(*len > EXT_MAX_BLOCKS) ||
|
|
(donor_start + *len >= EXT_MAX_BLOCKS) ||
|
|
(orig_start + *len >= EXT_MAX_BLOCKS)) {
|
|
ext4_debug("ext4 move extent: Can't handle over [%u] blocks "
|
|
"[ino:orig %lu, donor %lu]\n", EXT_MAX_BLOCKS,
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
if (orig_eof <= orig_start)
|
|
*len = 0;
|
|
else if (orig_eof < orig_start + *len - 1)
|
|
*len = orig_eof - orig_start;
|
|
if (donor_eof <= donor_start)
|
|
*len = 0;
|
|
else if (donor_eof < donor_start + *len - 1)
|
|
*len = donor_eof - donor_start;
|
|
if (!*len) {
|
|
ext4_debug("ext4 move extent: len should not be 0 "
|
|
"[ino:orig %lu, donor %lu]\n", orig_inode->i_ino,
|
|
donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* ext4_move_extents - Exchange the specified range of a file
|
|
*
|
|
* @o_filp: file structure of the original file
|
|
* @d_filp: file structure of the donor file
|
|
* @orig_blk: start offset in block for orig
|
|
* @donor_blk: start offset in block for donor
|
|
* @len: the number of blocks to be moved
|
|
* @moved_len: moved block length
|
|
*
|
|
* This function returns 0 and moved block length is set in moved_len
|
|
* if succeed, otherwise returns error value.
|
|
*
|
|
*/
|
|
int
|
|
ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
|
|
__u64 donor_blk, __u64 len, __u64 *moved_len)
|
|
{
|
|
struct inode *orig_inode = file_inode(o_filp);
|
|
struct inode *donor_inode = file_inode(d_filp);
|
|
struct ext4_ext_path *path = NULL;
|
|
int blocks_per_page = PAGE_SIZE >> orig_inode->i_blkbits;
|
|
ext4_lblk_t o_end, o_start = orig_blk;
|
|
ext4_lblk_t d_start = donor_blk;
|
|
int ret;
|
|
|
|
if (orig_inode->i_sb != donor_inode->i_sb) {
|
|
ext4_debug("ext4 move extent: The argument files "
|
|
"should be in same FS [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* orig and donor should be different inodes */
|
|
if (orig_inode == donor_inode) {
|
|
ext4_debug("ext4 move extent: The argument files should not "
|
|
"be same inode [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Regular file check */
|
|
if (!S_ISREG(orig_inode->i_mode) || !S_ISREG(donor_inode->i_mode)) {
|
|
ext4_debug("ext4 move extent: The argument files should be "
|
|
"regular file [ino:orig %lu, donor %lu]\n",
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* TODO: it's not obvious how to swap blocks for inodes with full
|
|
journaling enabled */
|
|
if (ext4_should_journal_data(orig_inode) ||
|
|
ext4_should_journal_data(donor_inode)) {
|
|
ext4_msg(orig_inode->i_sb, KERN_ERR,
|
|
"Online defrag not supported with data journaling");
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) {
|
|
ext4_msg(orig_inode->i_sb, KERN_ERR,
|
|
"Online defrag not supported for encrypted files");
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
/* Protect orig and donor inodes against a truncate */
|
|
lock_two_nondirectories(orig_inode, donor_inode);
|
|
|
|
/* Wait for all existing dio workers */
|
|
inode_dio_wait(orig_inode);
|
|
inode_dio_wait(donor_inode);
|
|
|
|
/* Protect extent tree against block allocations via delalloc */
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
|
/* Check the filesystem environment whether move_extent can be done */
|
|
ret = mext_check_arguments(orig_inode, donor_inode, orig_blk,
|
|
donor_blk, &len);
|
|
if (ret)
|
|
goto out;
|
|
o_end = o_start + len;
|
|
|
|
*moved_len = 0;
|
|
while (o_start < o_end) {
|
|
struct ext4_extent *ex;
|
|
ext4_lblk_t cur_blk, next_blk;
|
|
pgoff_t orig_page_index, donor_page_index;
|
|
int offset_in_page;
|
|
int unwritten, cur_len;
|
|
|
|
ret = get_ext_path(orig_inode, o_start, &path);
|
|
if (ret)
|
|
goto out;
|
|
ex = path[path->p_depth].p_ext;
|
|
next_blk = ext4_ext_next_allocated_block(path);
|
|
cur_blk = le32_to_cpu(ex->ee_block);
|
|
cur_len = ext4_ext_get_actual_len(ex);
|
|
/* Check hole before the start pos */
|
|
if (cur_blk + cur_len - 1 < o_start) {
|
|
if (next_blk == EXT_MAX_BLOCKS) {
|
|
o_start = o_end;
|
|
ret = -ENODATA;
|
|
goto out;
|
|
}
|
|
d_start += next_blk - o_start;
|
|
o_start = next_blk;
|
|
continue;
|
|
/* Check hole after the start pos */
|
|
} else if (cur_blk > o_start) {
|
|
/* Skip hole */
|
|
d_start += cur_blk - o_start;
|
|
o_start = cur_blk;
|
|
/* Extent inside requested range ?*/
|
|
if (cur_blk >= o_end)
|
|
goto out;
|
|
} else { /* in_range(o_start, o_blk, o_len) */
|
|
cur_len += cur_blk - o_start;
|
|
}
|
|
unwritten = ext4_ext_is_unwritten(ex);
|
|
if (o_end - o_start < cur_len)
|
|
cur_len = o_end - o_start;
|
|
|
|
orig_page_index = o_start >> (PAGE_SHIFT -
|
|
orig_inode->i_blkbits);
|
|
donor_page_index = d_start >> (PAGE_SHIFT -
|
|
donor_inode->i_blkbits);
|
|
offset_in_page = o_start % blocks_per_page;
|
|
if (cur_len > blocks_per_page- offset_in_page)
|
|
cur_len = blocks_per_page - offset_in_page;
|
|
/*
|
|
* Up semaphore to avoid following problems:
|
|
* a. transaction deadlock among ext4_journal_start,
|
|
* ->write_begin via pagefault, and jbd2_journal_commit
|
|
* b. racing with ->readpage, ->write_begin, and ext4_get_block
|
|
* in move_extent_per_page
|
|
*/
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
|
/* Swap original branches with new branches */
|
|
*moved_len += move_extent_per_page(o_filp, donor_inode,
|
|
orig_page_index, donor_page_index,
|
|
offset_in_page, cur_len,
|
|
unwritten, &ret);
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
|
if (ret < 0)
|
|
break;
|
|
o_start += cur_len;
|
|
d_start += cur_len;
|
|
}
|
|
|
|
out:
|
|
if (*moved_len) {
|
|
ext4_discard_preallocations(orig_inode);
|
|
ext4_discard_preallocations(donor_inode);
|
|
}
|
|
|
|
ext4_ext_drop_refs(path);
|
|
kfree(path);
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
|
unlock_two_nondirectories(orig_inode, donor_inode);
|
|
|
|
return ret;
|
|
}
|