Changes in 5.15.46
binfmt_flat: do not stop relocating GOT entries prematurely on riscv
parisc/stifb: Implement fb_is_primary_device()
parisc/stifb: Keep track of hardware path of graphics card
RISC-V: Mark IORESOURCE_EXCLUSIVE for reserved mem instead of IORESOURCE_BUSY
riscv: Initialize thread pointer before calling C functions
riscv: Fix irq_work when SMP is disabled
riscv: Wire up memfd_secret in UAPI header
riscv: Move alternative length validation into subsection
ALSA: hda/realtek - Add new type for ALC245
ALSA: hda/realtek: Enable 4-speaker output for Dell XPS 15 9520 laptop
ALSA: hda/realtek - Fix microphone noise on ASUS TUF B550M-PLUS
ALSA: usb-audio: Cancel pending work at closing a MIDI substream
USB: serial: pl2303: fix type detection for odd device
USB: serial: option: add Quectel BG95 modem
USB: new quirk for Dell Gen 2 devices
usb: isp1760: Fix out-of-bounds array access
usb: dwc3: gadget: Move null pinter check to proper place
usb: core: hcd: Add support for deferring roothub registration
fs/ntfs3: Update valid size if -EIOCBQUEUED
fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated space)
fs/ntfs3: Keep preallocated only if option prealloc enabled
fs/ntfs3: Check new size for limits
fs/ntfs3: In function ntfs_set_acl_ex do not change inode->i_mode if called from function ntfs_init_acl
fs/ntfs3: Fix some memory leaks in an error handling path of 'log_replay()'
fs/ntfs3: Update i_ctime when xattr is added
fs/ntfs3: Restore ntfs_xattr_get_acl and ntfs_xattr_set_acl functions
cifs: fix potential double free during failed mount
cifs: when extending a file with falloc we should make files not-sparse
xhci: Allow host runtime PM as default for Intel Alder Lake N xHCI
platform/x86: intel-hid: fix _DSM function index handling
x86/MCE/AMD: Fix memory leak when threshold_create_bank() fails
perf/x86/intel: Fix event constraints for ICL
x86/kexec: fix memory leak of elf header buffer
x86/sgx: Set active memcg prior to shmem allocation
ptrace/um: Replace PT_DTRACE with TIF_SINGLESTEP
ptrace/xtensa: Replace PT_SINGLESTEP with TIF_SINGLESTEP
ptrace: Reimplement PTRACE_KILL by always sending SIGKILL
btrfs: add "0x" prefix for unsupported optional features
btrfs: return correct error number for __extent_writepage_io()
btrfs: repair super block num_devices automatically
btrfs: fix the error handling for submit_extent_page() for btrfs_do_readpage()
iommu/vt-d: Add RPLS to quirk list to skip TE disabling
drm/vmwgfx: validate the screen formats
drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes
selftests/bpf: Fix vfs_link kprobe definition
selftests/bpf: Fix parsing of prog types in UAPI hdr for bpftool sync
mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue
b43legacy: Fix assigning negative value to unsigned variable
b43: Fix assigning negative value to unsigned variable
ipw2x00: Fix potential NULL dereference in libipw_xmit()
ipv6: fix locking issues with loops over idev->addr_list
fbcon: Consistently protect deferred_takeover with console_lock()
x86/platform/uv: Update TSC sync state for UV5
ACPICA: Avoid cache flush inside virtual machines
mac80211: minstrel_ht: fix where rate stats are stored (fixes debugfs output)
drm/komeda: return early if drm_universal_plane_init() fails.
drm/amd/display: Disabling Z10 on DCN31
rcu-tasks: Fix race in schedule and flush work
rcu: Make TASKS_RUDE_RCU select IRQ_WORK
sfc: ef10: Fix assigning negative value to unsigned variable
ALSA: jack: Access input_dev under mutex
rtw88: 8821c: fix debugfs rssi value
spi: spi-rspi: Remove setting {src,dst}_{addr,addr_width} based on DMA direction
tools/power turbostat: fix ICX DRAM power numbers
scsi: lpfc: Move cfg_log_verbose check before calling lpfc_dmp_dbg()
scsi: lpfc: Fix SCSI I/O completion and abort handler deadlock
scsi: lpfc: Fix call trace observed during I/O with CMF enabled
cpuidle: PSCI: Improve support for suspend-to-RAM for PSCI OSI mode
drm/amd/pm: fix double free in si_parse_power_table()
ASoC: rsnd: care default case on rsnd_ssiu_busif_err_status_clear()
ASoC: rsnd: care return value from rsnd_node_fixed_index()
ath9k: fix QCA9561 PA bias level
media: venus: hfi: avoid null dereference in deinit
media: pci: cx23885: Fix the error handling in cx23885_initdev()
media: cx25821: Fix the warning when removing the module
md/bitmap: don't set sb values if can't pass sanity check
mmc: jz4740: Apply DMA engine limits to maximum segment size
drivers: mmc: sdhci_am654: Add the quirk to set TESTCD bit
scsi: megaraid: Fix error check return value of register_chrdev()
drm/amdgpu/sdma: Fix incorrect calculations of the wptr of the doorbells
scsi: ufs: Use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()
scsi: lpfc: Fix resource leak in lpfc_sli4_send_seq_to_ulp()
ath11k: disable spectral scan during spectral deinit
ASoC: Intel: bytcr_rt5640: Add quirk for the HP Pro Tablet 408
drm/plane: Move range check for format_count earlier
drm/amd/pm: fix the compile warning
ath10k: skip ath10k_halt during suspend for driver state RESTARTING
arm64: compat: Do not treat syscall number as ESR_ELx for a bad syscall
drm: msm: fix error check return value of irq_of_parse_and_map()
scsi: target: tcmu: Fix possible data corruption
ipv6: Don't send rs packets to the interface of ARPHRD_TUNNEL
net/mlx5: fs, delete the FTE when there are no rules attached to it
ASoC: dapm: Don't fold register value changes into notifications
mlxsw: spectrum_dcb: Do not warn about priority changes
mlxsw: Treat LLDP packets as control
drm/amdgpu/psp: move PSP memory alloc from hw_init to sw_init
drm/amdgpu/ucode: Remove firmware load type check in amdgpu_ucode_free_bo
regulator: mt6315: Enforce regulator-compatible, not name
HID: bigben: fix slab-out-of-bounds Write in bigben_probe
of: Support more than one crash kernel regions for kexec -s
ASoC: tscs454: Add endianness flag in snd_soc_component_driver
scsi: lpfc: Alter FPIN stat accounting logic
net: remove two BUG() from skb_checksum_help()
s390/preempt: disable __preempt_count_add() optimization for PROFILE_ALL_BRANCHES
perf/amd/ibs: Cascade pmu init functions' return value
sched/core: Avoid obvious double update_rq_clock warning
spi: stm32-qspi: Fix wait_cmd timeout in APM mode
dma-debug: change allocation mode from GFP_NOWAIT to GFP_ATIOMIC
ACPI: PM: Block ASUS B1400CEAE from suspend to idle by default
ipmi:ssif: Check for NULL msg when handling events and messages
ipmi: Fix pr_fmt to avoid compilation issues
rtlwifi: Use pr_warn instead of WARN_ONCE
mt76: mt7921: accept rx frames with non-standard VHT MCS10-11
mt76: fix encap offload ethernet type check
media: rga: fix possible memory leak in rga_probe
media: coda: limit frame interval enumeration to supported encoder frame sizes
media: hantro: HEVC: unconditionnaly set pps_{cb/cr}_qp_offset values
media: ccs-core.c: fix failure to call clk_disable_unprepare
media: imon: reorganize serialization
media: cec-adap.c: fix is_configuring state
usbnet: Run unregister_netdev() before unbind() again
openrisc: start CPU timer early in boot
nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags
ASoC: rt5645: Fix errorenous cleanup order
nbd: Fix hung on disconnect request if socket is closed before
drm/amd/pm: update smartshift powerboost calc for smu12
drm/amd/pm: update smartshift powerboost calc for smu13
net: phy: micrel: Allow probing without .driver_data
media: exynos4-is: Fix compile warning
media: hantro: Stop using H.264 parameter pic_num
ASoC: max98357a: remove dependency on GPIOLIB
ASoC: rt1015p: remove dependency on GPIOLIB
ACPI: CPPC: Assume no transition latency if no PCCT
nvme: set non-mdts limits in nvme_scan_work
can: mcp251xfd: silence clang's -Wunaligned-access warning
x86/microcode: Add explicit CPU vendor dependency
net: ipa: ignore endianness if there is no header
m68k: atari: Make Atari ROM port I/O write macros return void
rxrpc: Return an error to sendmsg if call failed
rxrpc, afs: Fix selection of abort codes
afs: Adjust ACK interpretation to try and cope with NAT
eth: tg3: silence the GCC 12 array-bounds warning
char: tpm: cr50_i2c: Suppress duplicated error message in .remove()
selftests/bpf: fix btf_dump/btf_dump due to recent clang change
gfs2: use i_lock spin_lock for inode qadata
scsi: target: tcmu: Avoid holding XArray lock when calling lock_page
IB/rdmavt: add missing locks in rvt_ruc_loopback
ARM: dts: ox820: align interrupt controller node name with dtschema
ARM: dts: socfpga: align interrupt controller node name with dtschema
ARM: dts: s5pv210: align DMA channels with dtschema
arm64: dts: qcom: msm8994: Fix the cont_splash_mem address
arm64: dts: qcom: msm8994: Fix BLSP[12]_DMA channels count
PM / devfreq: rk3399_dmc: Disable edev on remove()
crypto: ccree - use fine grained DMA mapping dir
soc: ti: ti_sci_pm_domains: Check for null return of devm_kcalloc
fs: jfs: fix possible NULL pointer dereference in dbFree()
arm64: dts: qcom: sdm845-xiaomi-beryllium: fix typo in panel's vddio-supply property
ALSA: usb-audio: Add quirk bits for enabling/disabling generic implicit fb
ALSA: usb-audio: Move generic implicit fb quirk entries into quirks.c
ARM: OMAP1: clock: Fix UART rate reporting algorithm
powerpc/fadump: Fix fadump to work with a different endian capture kernel
fat: add ratelimit to fat*_ent_bread()
pinctrl: renesas: rzn1: Fix possible null-ptr-deref in sh_pfc_map_resources()
ARM: versatile: Add missing of_node_put in dcscb_init
ARM: dts: exynos: add atmel,24c128 fallback to Samsung EEPROM
ARM: hisi: Add missing of_node_put after of_find_compatible_node
cpufreq: Avoid unnecessary frequency updates due to mismatch
powerpc/rtas: Keep MSR[RI] set when calling RTAS
PCI: Avoid pci_dev_lock() AB/BA deadlock with sriov_numvfs_store()
KVM: PPC: Book3S HV Nested: L2 LPCR should inherit L1 LPES setting
alpha: fix alloc_zeroed_user_highpage_movable()
tracing: incorrect isolate_mote_t cast in mm_vmscan_lru_isolate
powerpc/powernv/vas: Assign real address to rx_fifo in vas_rx_win_attr
powerpc/xics: fix refcount leak in icp_opal_init()
powerpc/powernv: fix missing of_node_put in uv_init()
macintosh/via-pmu: Fix build failure when CONFIG_INPUT is disabled
powerpc/iommu: Add missing of_node_put in iommu_init_early_dart
smb3: check for null tcon
RDMA/hfi1: Prevent panic when SDMA is disabled
Input: gpio-keys - cancel delayed work only in case of GPIO
drm: fix EDID struct for old ARM OABI format
drm/bridge_connector: enable HPD by default if supported
dt-bindings: display: sitronix, st7735r: Fix backlight in example
drm/vmwgfx: Fix an invalid read
ath11k: acquire ab->base_lock in unassign when finding the peer by addr
drm: bridge: it66121: Fix the register page length
ath9k: fix ar9003_get_eepmisc
drm/edid: fix invalid EDID extension block filtering
drm/bridge: adv7511: clean up CEC adapter when probe fails
drm: bridge: icn6211: Fix register layout
drm: bridge: icn6211: Fix HFP_HSW_HBP_HI and HFP_MIN handling
mtd: spinand: gigadevice: fix Quad IO for GD5F1GQ5UExxG
spi: qcom-qspi: Add minItems to interconnect-names
ASoC: mediatek: Fix error handling in mt8173_max98090_dev_probe
ASoC: mediatek: Fix missing of_node_put in mt2701_wm8960_machine_probe
x86/delay: Fix the wrong asm constraint in delay_loop()
drm/vc4: hvs: Fix frame count register readout
drm/mediatek: Fix mtk_cec_mask()
drm/vc4: hvs: Reset muxes at probe time
drm/vc4: txp: Don't set TXP_VSTART_AT_EOF
drm/vc4: txp: Force alpha to be 0xff if it's disabled
libbpf: Don't error out on CO-RE relos for overriden weak subprogs
x86/PCI: Fix ALi M1487 (IBC) PIRQ router link value interpretation
mptcp: reset the packet scheduler on PRIO change
nl80211: show SSID for P2P_GO interfaces
drm/komeda: Fix an undefined behavior bug in komeda_plane_add()
drm: mali-dp: potential dereference of null pointer
spi: spi-ti-qspi: Fix return value handling of wait_for_completion_timeout
scftorture: Fix distribution of short handler delays
net: dsa: mt7530: 1G can also support 1000BASE-X link mode
ixp4xx_eth: fix error check return value of platform_get_irq()
NFC: NULL out the dev->rfkill to prevent UAF
efi: Add missing prototype for efi_capsule_setup_info
device property: Check fwnode->secondary when finding properties
device property: Allow error pointer to be passed to fwnode APIs
target: remove an incorrect unmap zeroes data deduction
drbd: fix duplicate array initializer
EDAC/dmc520: Don't print an error for each unconfigured interrupt line
mtd: rawnand: denali: Use managed device resources
HID: hid-led: fix maximum brightness for Dream Cheeky
HID: elan: Fix potential double free in elan_input_configured
drm/bridge: Fix error handling in analogix_dp_probe
regulator: da9121: Fix uninit-value in da9121_assign_chip_model()
drm/mediatek: dpi: Use mt8183 output formats for mt8192
signal: Deliver SIGTRAP on perf event asynchronously if blocked
sched/fair: Fix cfs_rq_clock_pelt() for throttled cfs_rq
sched/psi: report zeroes for CPU full at the system level
spi: img-spfi: Fix pm_runtime_get_sync() error checking
cpufreq: Fix possible race in cpufreq online error path
printk: use atomic updates for klogd work
printk: add missing memory barrier to wake_up_klogd()
printk: wake waiters for safe and NMI contexts
ath9k_htc: fix potential out of bounds access with invalid rxstatus->rs_keyix
media: i2c: max9286: Use dev_err_probe() helper
media: i2c: max9286: Use "maxim,gpio-poc" property
media: i2c: max9286: fix kernel oops when removing module
media: hantro: Empty encoder capture buffers by default
drm/panel: simple: Add missing bus flags for Innolux G070Y2-L01
ALSA: pcm: Check for null pointer of pointer substream before dereferencing it
mtdblock: warn if opened on NAND
inotify: show inotify mask flags in proc fdinfo
fsnotify: fix wrong lockdep annotations
spi: rockchip: Stop spi slave dma receiver when cs inactive
spi: rockchip: Preset cs-high and clk polarity in setup progress
spi: rockchip: fix missing error on unsupported SPI_CS_HIGH
of: overlay: do not break notify on NOTIFY_{OK|STOP}
selftests/damon: add damon to selftests root Makefile
drm/msm/dp: Modify prototype of encoder based API
drm/msm/hdmi: switch to drm_bridge_connector
drm/msm/dpu: adjust display_v_end for eDP and DP
scsi: iscsi: Fix harmless double shift bug
scsi: ufs: qcom: Fix ufs_qcom_resume()
scsi: ufs: core: Exclude UECxx from SFR dump list
drm/v3d: Fix null pointer dereference of pointer perfmon
selftests/resctrl: Fix null pointer dereference on open failed
libbpf: Fix logic for finding matching program for CO-RE relocation
mtd: spi-nor: core: Check written SR value in spi_nor_write_16bit_sr_and_check()
x86/pm: Fix false positive kmemleak report in msr_build_context()
mtd: rawnand: cadence: fix possible null-ptr-deref in cadence_nand_dt_probe()
mtd: rawnand: intel: fix possible null-ptr-deref in ebu_nand_probe()
x86/speculation: Add missing prototype for unpriv_ebpf_notify()
ASoC: rk3328: fix disabling mclk on pclk probe failure
perf tools: Add missing headers needed by util/data.h
drm/msm/disp/dpu1: set vbif hw config to NULL to avoid use after memory free during pm runtime resume
drm/msm/dp: stop event kernel thread when DP unbind
drm/msm/dp: fix error check return value of irq_of_parse_and_map()
drm/msm/dp: reset DP controller before transmit phy test pattern
drm/msm/dp: do not stop transmitting phy test pattern during DP phy compliance test
drm/msm/dsi: fix error checks and return values for DSI xmit functions
drm/msm/hdmi: check return value after calling platform_get_resource_byname()
drm/msm/hdmi: fix error check return value of irq_of_parse_and_map()
drm/msm: add missing include to msm_drv.c
drm/panel: panel-simple: Fix proper bpc for AM-1280800N3TZQW-T00H
kunit: fix debugfs code to use enum kunit_status, not bool
drm/rockchip: vop: fix possible null-ptr-deref in vop_bind()
spi: cadence-quadspi: fix Direct Access Mode disable for SoCFPGA
perf tools: Use Python devtools for version autodetection rather than runtime
virtio_blk: fix the discard_granularity and discard_alignment queue limits
nl80211: don't hold RTNL in color change request
x86: Fix return value of __setup handlers
irqchip/exiu: Fix acknowledgment of edge triggered interrupts
irqchip/aspeed-i2c-ic: Fix irq_of_parse_and_map() return value
irqchip/aspeed-scu-ic: Fix irq_of_parse_and_map() return value
x86/mm: Cleanup the control_va_addr_alignment() __setup handler
arm64: fix types in copy_highpage()
regulator: core: Fix enable_count imbalance with EXCLUSIVE_GET
drm/msm/dsi: fix address for second DSI PHY on SDM660
drm/msm/dp: fix event thread stuck in wait_event after kthread_stop()
drm/msm/mdp5: Return error code in mdp5_pipe_release when deadlock is detected
drm/msm/mdp5: Return error code in mdp5_mixer_release when deadlock is detected
drm/msm: return an error pointer in msm_gem_prime_get_sg_table()
media: uvcvideo: Fix missing check to determine if element is found in list
arm64: stackleak: fix current_top_of_stack()
iomap: iomap_write_failed fix
spi: spi-fsl-qspi: check return value after calling platform_get_resource_byname()
Revert "cpufreq: Fix possible race in cpufreq online error path"
regulator: qcom_smd: Fix up PM8950 regulator configuration
samples: bpf: Don't fail for a missing VMLINUX_BTF when VMLINUX_H is provided
perf/amd/ibs: Use interrupt regs ip for stack unwinding
ath11k: Don't check arvif->is_started before sending management frames
wilc1000: fix crash observed in AP mode with cfg80211_register_netdevice()
HID: amd_sfh: Modify the bus name
HID: amd_sfh: Modify the hid name
ASoC: fsl: Use dev_err_probe() helper
ASoC: fsl: Fix refcount leak in imx_sgtl5000_probe
ASoC: imx-hdmi: Fix refcount leak in imx_hdmi_probe
ASoC: mxs-saif: Fix refcount leak in mxs_saif_probe
regulator: pfuze100: Fix refcount leak in pfuze_parse_regulators_dt
dma-direct: factor out a helper for DMA_ATTR_NO_KERNEL_MAPPING allocations
dma-direct: don't fail on highmem CMA pages in dma_direct_alloc_pages
ASoC: samsung: Use dev_err_probe() helper
ASoC: samsung: Fix refcount leak in aries_audio_probe
block: Fix the bio.bi_opf comment
kselftest/cgroup: fix test_stress.sh to use OUTPUT dir
scripts/faddr2line: Fix overlapping text section failures
media: aspeed: Fix an error handling path in aspeed_video_probe()
media: exynos4-is: Fix PM disable depth imbalance in fimc_is_probe
mt76: mt7921: Fix the error handling path of mt7921_pci_probe()
mt76: do not attempt to reorder received 802.3 packets without agg session
media: st-delta: Fix PM disable depth imbalance in delta_probe
media: atmel: atmel-isc: Fix PM disable depth imbalance in atmel_isc_probe
media: i2c: rdacm2x: properly set subdev entity function
media: exynos4-is: Change clk_disable to clk_disable_unprepare
media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init
media: vsp1: Fix offset calculation for plane cropping
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: hantro: HEVC: Fix tile info buffer value computation
Bluetooth: fix dangling sco_conn and use-after-free in sco_sock_timeout
Bluetooth: use hdev lock in activate_scan for hci_is_adv_monitoring
Bluetooth: use hdev lock for accept_list and reject_list in conn req
nvme: set dma alignment to dword
m68k: math-emu: Fix dependencies of math emulation support
sctp: read sk->sk_bound_dev_if once in sctp_rcv()
net: hinic: add missing destroy_workqueue in hinic_pf_to_mgmt_init
ASoC: ti: j721e-evm: Fix refcount leak in j721e_soc_probe_*
kselftest/arm64: bti: force static linking
media: ov7670: remove ov7670_power_off from ov7670_remove
media: i2c: ov5648: fix wrong pointer passed to IS_ERR() and PTR_ERR()
media: staging: media: rkvdec: Make use of the helper function devm_platform_ioremap_resource()
media: rkvdec: h264: Fix dpb_valid implementation
media: rkvdec: h264: Fix bit depth wrap in pps packet
regulator: scmi: Fix refcount leak in scmi_regulator_probe
ext4: reject the 'commit' option on ext2 filesystems
drm/msm/a6xx: Fix refcount leak in a6xx_gpu_init
drm: msm: fix possible memory leak in mdp5_crtc_cursor_set()
x86/sev: Annotate stack change in the #VC handler
drm/msm: don't free the IRQ if it was not requested
selftests/bpf: Add missed ima_setup.sh in Makefile
drm/msm/dpu: handle pm_runtime_get_sync() errors in bind path
drm/i915: Fix CFI violation with show_dynamic_id()
thermal/drivers/bcm2711: Don't clamp temperature at zero
thermal/drivers/broadcom: Fix potential NULL dereference in sr_thermal_probe
thermal/core: Fix memory leak in __thermal_cooling_device_register()
thermal/drivers/imx_sc_thermal: Fix refcount leak in imx_sc_thermal_probe
bfq: Relax waker detection for shared queues
bfq: Allow current waker to defend against a tentative one
ASoC: wm2000: fix missing clk_disable_unprepare() on error in wm2000_anc_transition()
PM: domains: Fix initialization of genpd's next_wakeup
net: macb: Fix PTP one step sync support
NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx
ASoC: max98090: Move check for invalid values before casting in max98090_put_enab_tlv()
net: stmmac: selftests: Use kcalloc() instead of kzalloc()
net: stmmac: fix out-of-bounds access in a selftest
hv_netvsc: Fix potential dereference of NULL pointer
hwmon: (pmbus) Check PEC support before reading other registers
rxrpc: Fix listen() setting the bar too high for the prealloc rings
rxrpc: Don't try to resend the request if we're receiving the reply
rxrpc: Fix overlapping ACK accounting
rxrpc: Don't let ack.previousPacket regress
rxrpc: Fix decision on when to generate an IDLE ACK
net: huawei: hinic: Use devm_kcalloc() instead of devm_kzalloc()
hinic: Avoid some over memory allocation
net: dsa: restrict SMSC_LAN9303_I2C kconfig
net/smc: postpone sk_refcnt increment in connect()
dma-direct: factor out dma_set_{de,en}crypted helpers
dma-direct: don't call dma_set_decrypted for remapped allocations
dma-direct: always leak memory that can't be re-encrypted
dma-direct: don't over-decrypt memory
arm64: dts: rockchip: Move drive-impedance-ohm to emmc phy on rk3399
arm64: dts: mt8192: Fix nor_flash status disable typo
PCI/ACPI: Allow D3 only if Root Port can signal and wake from D3
memory: samsung: exynos5422-dmc: Avoid some over memory allocation
ARM: dts: BCM5301X: update CRU block description
ARM: dts: BCM5301X: Update pin controller node name
ARM: dts: suniv: F1C100: fix watchdog compatible
soc: qcom: smp2p: Fix missing of_node_put() in smp2p_parse_ipc
soc: qcom: smsm: Fix missing of_node_put() in smsm_parse_ipc
PCI: cadence: Fix find_first_zero_bit() limit
PCI: rockchip: Fix find_first_zero_bit() limit
PCI: mediatek: Fix refcount leak in mtk_pcie_subsys_powerup()
PCI: dwc: Fix setting error return on MSI DMA mapping failure
ARM: dts: ci4x10: Adapt to changes in imx6qdl.dtsi regarding fec clocks
soc: qcom: llcc: Add MODULE_DEVICE_TABLE()
KVM: nVMX: Leave most VM-Exit info fields unmodified on failed VM-Entry
KVM: nVMX: Clear IDT vectoring on nested VM-Exit for double/triple fault
crypto: qat - set CIPHER capability for QAT GEN2
crypto: qat - set COMPRESSION capability for QAT GEN2
crypto: qat - set CIPHER capability for DH895XCC
crypto: qat - set COMPRESSION capability for DH895XCC
platform/chrome: cros_ec: fix error handling in cros_ec_register()
ARM: dts: imx6dl-colibri: Fix I2C pinmuxing
platform/chrome: Re-introduce cros_ec_cmd_xfer and use it for ioctls
can: xilinx_can: mark bit timing constants as const
ARM: dts: stm32: Fix PHY post-reset delay on Avenger96
ARM: dts: bcm2835-rpi-zero-w: Fix GPIO line name for Wifi/BT
ARM: dts: bcm2837-rpi-cm3-io3: Fix GPIO line names for SMPS I2C
ARM: dts: bcm2837-rpi-3-b-plus: Fix GPIO line name of power LED
ARM: dts: bcm2835-rpi-b: Fix GPIO line names
misc: ocxl: fix possible double free in ocxl_file_register_afu
crypto: marvell/cesa - ECB does not IV
gpiolib: of: Introduce hook for missing gpio-ranges
pinctrl: bcm2835: implement hook for missing gpio-ranges
arm: mediatek: select arch timer for mt7629
pinctrl/rockchip: support deferring other gpio params
pinctrl: mediatek: mt8195: enable driver on mtk platforms
arm64: dts: qcom: qrb5165-rb5: Fix can-clock node name
Drivers: hv: vmbus: Fix handling of messages with transaction ID of zero
powerpc/fadump: fix PT_LOAD segment for boot memory area
mfd: ipaq-micro: Fix error check return value of platform_get_irq()
scsi: fcoe: Fix Wstringop-overflow warnings in fcoe_wwn_from_mac()
soc: bcm: Check for NULL return of devm_kzalloc()
arm64: dts: ti: k3-am64-mcu: remove incorrect UART base clock rates
ASoC: sh: rz-ssi: Check return value of pm_runtime_resume_and_get()
ASoC: sh: rz-ssi: Propagate error codes returned from platform_get_irq_byname()
ASoC: sh: rz-ssi: Release the DMA channels in rz_ssi_probe() error path
firmware: arm_scmi: Fix list protocols enumeration in the base protocol
nvdimm: Fix firmware activation deadlock scenarios
nvdimm: Allow overwrite in the presence of disabled dimms
pinctrl: mvebu: Fix irq_of_parse_and_map() return value
drivers/base/node.c: fix compaction sysfs file leak
dax: fix cache flush on PMD-mapped pages
drivers/base/memory: fix an unlikely reference counting issue in __add_memory_block()
firmware: arm_ffa: Fix uuid parameter to ffa_partition_probe
firmware: arm_ffa: Remove incorrect assignment of driver_data
list: introduce list_is_head() helper and re-use it in list.h
list: fix a data-race around ep->rdllist
drm/msm/dpu: fix error check return value of irq_of_parse_and_map()
powerpc/8xx: export 'cpm_setbrg' for modules
pinctrl: renesas: r8a779a0: Fix GPIO function on I2C-capable pins
pinctrl: renesas: core: Fix possible null-ptr-deref in sh_pfc_map_resources()
powerpc/idle: Fix return value of __setup() handler
powerpc/4xx/cpm: Fix return value of __setup() handler
RDMA/hns: Add the detection for CMDQ status in the device initialization process
arm64: dts: marvell: espressobin-ultra: fix SPI-NOR config
arm64: dts: marvell: espressobin-ultra: enable front USB3 port
ASoC: atmel-pdmic: Remove endianness flag on pdmic component
ASoC: atmel-classd: Remove endianness flag on class d component
proc: fix dentry/inode overinstantiating under /proc/${pid}/net
ipc/mqueue: use get_tree_nodev() in mqueue_get_tree()
PCI: imx6: Fix PERST# start-up sequence
tty: fix deadlock caused by calling printk() under tty_port->lock
crypto: sun8i-ss - rework handling of IV
crypto: sun8i-ss - handle zero sized sg
crypto: cryptd - Protect per-CPU resource by disabling BH.
ARM: dts: at91: sama7g5: remove interrupt-parent from gic node
hugetlbfs: fix hugetlbfs_statfs() locking
Input: sparcspkr - fix refcount leak in bbc_beep_probe
PCI/AER: Clear MULTI_ERR_COR/UNCOR_RCV bits
PCI: microchip: Fix potential race in interrupt handling
hwrng: omap3-rom - fix using wrong clk_disable() in omap_rom_rng_runtime_resume()
powerpc/64: Only WARN if __pa()/__va() called with bad addresses
powerpc/perf: Fix the threshold compare group constraint for power10
powerpc/perf: Fix the threshold compare group constraint for power9
macintosh: via-pmu and via-cuda need RTC_LIB
powerpc/xive: Add some error handling code to 'xive_spapr_init()'
powerpc/xive: Fix refcount leak in xive_spapr_init
powerpc/fsl_rio: Fix refcount leak in fsl_rio_setup
mfd: davinci_voicecodec: Fix possible null-ptr-deref davinci_vc_probe()
nfsd: destroy percpu stats counters after reply cache shutdown
mailbox: forward the hrtimer if not queued and under a lock
RDMA/hfi1: Prevent use of lock before it is initialized
KVM: LAPIC: Drop pending LAPIC timer injection when canceling the timer
Input: stmfts - do not leave device disabled in stmfts_input_open
OPP: call of_node_put() on error path in _bandwidth_supported()
f2fs: support fault injection for dquot_initialize()
f2fs: fix to do sanity check on inline_dots inode
f2fs: fix dereference of stale list iterator after loop body
iommu/amd: Enable swiotlb in all cases
iommu/mediatek: Fix 2 HW sharing pgtable issue
iommu/mediatek: Add list_del in mtk_iommu_remove
iommu/mediatek: Remove clk_disable in mtk_iommu_remove
iommu/mediatek: Add mutex for m4u_group and m4u_dom in data
i2c: at91: use dma safe buffers
cpufreq: mediatek: Use module_init and add module_exit
cpufreq: mediatek: Unregister platform device on exit
iommu/arm-smmu-v3-sva: Fix mm use-after-free
MIPS: Loongson: Use hwmon_device_register_with_groups() to register hwmon
iommu/mediatek: Fix NULL pointer dereference when printing dev_name
i2c: at91: Initialize dma_buf in at91_twi_xfer()
dmaengine: idxd: Fix the error handling path in idxd_cdev_register()
NFS: Do not report EINTR/ERESTARTSYS as mapping errors
NFS: fsync() should report filesystem errors over EINTR/ERESTARTSYS
NFS: Don't report ENOSPC write errors twice
NFS: Do not report flush errors in nfs_write_end()
NFS: Don't report errors from nfs_pageio_complete() more than once
NFSv4/pNFS: Do not fail I/O when we fail to allocate the pNFS layout
NFS: Further fixes to the writeback error handling
video: fbdev: clcdfb: Fix refcount leak in clcdfb_of_vram_setup
dmaengine: stm32-mdma: remove GISR1 register
dmaengine: stm32-mdma: fix chan initialization in stm32_mdma_irq_handler()
iommu/amd: Increase timeout waiting for GA log enablement
i2c: npcm: Fix timeout calculation
i2c: npcm: Correct register access width
i2c: npcm: Handle spurious interrupts
i2c: rcar: fix PM ref counts in probe error paths
perf build: Fix btf__load_from_kernel_by_id() feature check
perf c2c: Use stdio interface if slang is not supported
perf jevents: Fix event syntax error caused by ExtSel
video: fbdev: vesafb: Fix a use-after-free due early fb_info cleanup
NFS: Always initialise fattr->label in nfs_fattr_alloc()
NFS: Create a new nfs_alloc_fattr_with_label() function
NFS: Convert GFP_NOFS to GFP_KERNEL
NFSv4.1 mark qualified async operations as MOVEABLE tasks
f2fs: fix to avoid f2fs_bug_on() in dec_valid_node_count()
f2fs: fix to do sanity check on block address in f2fs_do_zero_range()
f2fs: fix to clear dirty inode in f2fs_evict_inode()
f2fs: fix deadloop in foreground GC
f2fs: don't need inode lock for system hidden quota
f2fs: fix to do sanity check on total_data_blocks
f2fs: don't use casefolded comparison for "." and ".."
f2fs: fix fallocate to use file_modified to update permissions consistently
f2fs: fix to do sanity check for inline inode
objtool: Fix objtool regression on x32 systems
objtool: Fix symbol creation
wifi: mac80211: fix use-after-free in chanctx code
iwlwifi: mvm: fix assert 1F04 upon reconfig
fs-writeback: writeback_sb_inodes:Recalculate 'wrote' according skipped pages
efi: Do not import certificates from UEFI Secure Boot for T2 Macs
bfq: Avoid false marking of bic as stably merged
bfq: Avoid merging queues with different parents
bfq: Split shared queues on move between cgroups
bfq: Update cgroup information before merging bio
bfq: Drop pointless unlock-lock pair
bfq: Remove pointless bfq_init_rq() calls
bfq: Track whether bfq_group is still online
bfq: Get rid of __bio_blkcg() usage
bfq: Make sure bfqg for which we are queueing requests is online
ext4: mark group as trimmed only if it was fully scanned
ext4: fix use-after-free in ext4_rename_dir_prepare
ext4: fix race condition between ext4_write and ext4_convert_inline_data
ext4: fix warning in ext4_handle_inode_extension
ext4: fix bug_on in ext4_writepages
ext4: filter out EXT4_FC_REPLAY from on-disk superblock field s_state
ext4: fix bug_on in __es_tree_search
ext4: verify dir block before splitting it
ext4: avoid cycles in directory h-tree
ACPI: property: Release subnode properties with data nodes
tty: goldfish: Introduce gf_ioread32()/gf_iowrite32()
tracing: Fix potential double free in create_var_ref()
tracing: Initialize integer variable to prevent garbage return value
drm/amdgpu: add beige goby PCI ID
PCI/PM: Fix bridge_d3_blacklist[] Elo i2 overwrite of Gigabyte X299
PCI: qcom: Fix runtime PM imbalance on probe errors
PCI: qcom: Fix unbalanced PHY init on probe errors
staging: r8188eu: prevent ->Ssid overflow in rtw_wx_set_scan()
mm, compaction: fast_find_migrateblock() should return pfn in the target zone
s390/perf: obtain sie_block from the right address
s390/stp: clock_delta should be signed
dlm: fix plock invalid read
dlm: uninitialized variable on error in dlm_listen_for_all()
dlm: fix missing lkb refcount handling
ocfs2: dlmfs: fix error handling of user_dlm_destroy_lock
scsi: dc395x: Fix a missing check on list iterator
scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
landlock: Add clang-format exceptions
landlock: Format with clang-format
selftests/landlock: Add clang-format exceptions
selftests/landlock: Normalize array assignment
selftests/landlock: Format with clang-format
samples/landlock: Add clang-format exceptions
samples/landlock: Format with clang-format
landlock: Fix landlock_add_rule(2) documentation
selftests/landlock: Make tests build with old libc
selftests/landlock: Extend tests for minimal valid attribute size
selftests/landlock: Add tests for unknown access rights
selftests/landlock: Extend access right tests to directories
selftests/landlock: Fully test file rename with "remove" access
selftests/landlock: Add tests for O_PATH
landlock: Change landlock_add_rule(2) argument check ordering
landlock: Change landlock_restrict_self(2) check ordering
selftests/landlock: Test landlock_create_ruleset(2) argument check ordering
landlock: Define access_mask_t to enforce a consistent access mask size
landlock: Reduce the maximum number of layers to 16
landlock: Create find_rule() from unmask_layers()
landlock: Fix same-layer rule unions
drm/amdgpu/cs: make commands with 0 chunks illegal behaviour.
drm/nouveau/subdev/bus: Ratelimit logging for fault errors
drm/etnaviv: check for reaped mapping in etnaviv_iommu_unmap_gem
drm/nouveau/clk: Fix an incorrect NULL check on list iterator
drm/nouveau/kms/nv50-: atom: fix an incorrect NULL check on list iterator
drm/bridge: analogix_dp: Grab runtime PM reference for DP-AUX
drm/i915/dsi: fix VBT send packet port selection for ICL+
md: fix an incorrect NULL check in does_sb_need_changing
md: fix an incorrect NULL check in md_reload_sb
mtd: cfi_cmdset_0002: Move and rename chip_check/chip_ready/chip_good_for_write
mtd: cfi_cmdset_0002: Use chip_ready() for write on S29GL064N
media: coda: Fix reported H264 profile
media: coda: Add more H264 levels for CODA960
ima: remove the IMA_TEMPLATE Kconfig option
Kconfig: Add option for asm goto w/ tied outputs to workaround clang-13 bug
RDMA/hfi1: Fix potential integer multiplication overflow errors
mmc: core: Allows to override the timeout value for ioctl() path
csky: patch_text: Fixup last cpu should be master
irqchip/armada-370-xp: Do not touch Performance Counter Overflow on A375, A38x, A39x
irqchip: irq-xtensa-mx: fix initial IRQ affinity
thermal: devfreq_cooling: use local ops instead of global ops
cfg80211: declare MODULE_FIRMWARE for regulatory.db
mac80211: upgrade passive scan to active scan on DFS channels after beacon rx
um: Use asm-generic/dma-mapping.h
um: chan_user: Fix winch_tramp() return value
um: Fix out-of-bounds read in LDT setup
kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add]
ftrace: Clean up hash direct_functions on register failures
ksmbd: fix outstanding credits related bugs
iommu/msm: Fix an incorrect NULL check on list iterator
iommu/dma: Fix iova map result check bug
Revert "mm/cma.c: remove redundant cma_mutex lock"
mm/page_alloc: always attempt to allocate at least one page during bulk allocation
nodemask.h: fix compilation error with GCC12
hugetlb: fix huge_pmd_unshare address update
mm/memremap: fix missing call to untrack_pfn() in pagemap_range()
xtensa/simdisk: fix proc_read_simdisk()
rtl818x: Prevent using not initialized queues
ASoC: rt5514: Fix event generation for "DSP Voice Wake Up" control
carl9170: tx: fix an incorrect use of list iterator
stm: ltdc: fix two incorrect NULL checks on list iterator
bcache: improve multithreaded bch_btree_check()
bcache: improve multithreaded bch_sectors_dirty_init()
bcache: remove incremental dirty sector counting for bch_sectors_dirty_init()
bcache: avoid journal no-space deadlock by reserving 1 journal bucket
serial: pch: don't overwrite xmit->buf[0] by x_char
tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator
gma500: fix an incorrect NULL check on list iterator
arm64: dts: qcom: ipq8074: fix the sleep clock frequency
arm64: tegra: Add missing DFLL reset on Tegra210
clk: tegra: Add missing reset deassertion
phy: qcom-qmp: fix struct clk leak on probe errors
ARM: dts: s5pv210: Remove spi-cs-high on panel in Aries
ARM: pxa: maybe fix gpio lookup tables
SMB3: EBADF/EIO errors in rename/open caused by race condition in smb2_compound_op
docs/conf.py: Cope with removal of language=None in Sphinx 5.0.0
dt-bindings: gpio: altera: correct interrupt-cells
vdpasim: allow to enable a vq repeatedly
blk-iolatency: Fix inflight count imbalances and IO hangs on offline
coresight: core: Fix coresight device probe failure issue
phy: qcom-qmp: fix reset-controller leak on probe errors
net: ipa: fix page free in ipa_endpoint_trans_release()
net: ipa: fix page free in ipa_endpoint_replenish_one()
kseltest/cgroup: Make test_stress.sh work if run interactively
list: test: Add a test for list_is_head()
Revert "random: use static branch for crng_ready()"
staging: r8188eu: delete rtw_wx_read/write32()
RDMA/hns: Remove the num_cqc_timer variable
RDMA/rxe: Generate a completion for unsupported/invalid opcode
MIPS: IP27: Remove incorrect `cpu_has_fpu' override
MIPS: IP30: Remove incorrect `cpu_has_fpu' override
ext4: only allow test_dummy_encryption when supported
interconnect: qcom: sc7180: Drop IP0 interconnects
interconnect: qcom: icc-rpmh: Add BCMs to commit list in pre_aggregate
fs: add two trivial lookup helpers
exportfs: support idmapped mounts
fs/ntfs3: Fix invalid free in log_replay
md: Don't set mddev private to NULL in raid0 pers->free
md: fix double free of io_acct_set bioset
md: bcache: check the return value of kzalloc() in detached_dev_do_request()
pinctrl/rockchip: support setting input-enable param
block: fix bio_clone_blkg_association() to associate with proper blkcg_gq
Linux 5.15.46
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I7b65df29c22a01b81a94cd844867a18e73098a15
2474 lines
68 KiB
C
2474 lines
68 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* linux/fs/nfs/inode.c
|
|
*
|
|
* Copyright (C) 1992 Rick Sladkey
|
|
*
|
|
* nfs inode and superblock handling functions
|
|
*
|
|
* Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
|
|
* experimental NFS changes. Modularisation taken straight from SYS5 fs.
|
|
*
|
|
* Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
|
|
* J.S.Peatfield@damtp.cam.ac.uk
|
|
*
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/time.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/string.h>
|
|
#include <linux/stat.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/unistd.h>
|
|
#include <linux/sunrpc/clnt.h>
|
|
#include <linux/sunrpc/stats.h>
|
|
#include <linux/sunrpc/metrics.h>
|
|
#include <linux/nfs_fs.h>
|
|
#include <linux/nfs_mount.h>
|
|
#include <linux/nfs4_mount.h>
|
|
#include <linux/lockd/bind.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/vfs.h>
|
|
#include <linux/inet.h>
|
|
#include <linux/nfs_xdr.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/iversion.h>
|
|
|
|
#include "nfs4_fs.h"
|
|
#include "callback.h"
|
|
#include "delegation.h"
|
|
#include "iostat.h"
|
|
#include "internal.h"
|
|
#include "fscache.h"
|
|
#include "pnfs.h"
|
|
#include "nfs.h"
|
|
#include "netns.h"
|
|
#include "sysfs.h"
|
|
|
|
#include "nfstrace.h"
|
|
|
|
#define NFSDBG_FACILITY NFSDBG_VFS
|
|
|
|
#define NFS_64_BIT_INODE_NUMBERS_ENABLED 1
|
|
|
|
/* Default is to see 64-bit inode numbers */
|
|
static bool enable_ino64 = NFS_64_BIT_INODE_NUMBERS_ENABLED;
|
|
|
|
static int nfs_update_inode(struct inode *, struct nfs_fattr *);
|
|
|
|
static struct kmem_cache * nfs_inode_cachep;
|
|
|
|
static inline unsigned long
|
|
nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
|
|
{
|
|
return nfs_fileid_to_ino_t(fattr->fileid);
|
|
}
|
|
|
|
static int nfs_wait_killable(int mode)
|
|
{
|
|
freezable_schedule_unsafe();
|
|
if (signal_pending_state(mode, current))
|
|
return -ERESTARTSYS;
|
|
return 0;
|
|
}
|
|
|
|
int nfs_wait_bit_killable(struct wait_bit_key *key, int mode)
|
|
{
|
|
return nfs_wait_killable(mode);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
|
|
|
|
/**
|
|
* nfs_compat_user_ino64 - returns the user-visible inode number
|
|
* @fileid: 64-bit fileid
|
|
*
|
|
* This function returns a 32-bit inode number if the boot parameter
|
|
* nfs.enable_ino64 is zero.
|
|
*/
|
|
u64 nfs_compat_user_ino64(u64 fileid)
|
|
{
|
|
#ifdef CONFIG_COMPAT
|
|
compat_ulong_t ino;
|
|
#else
|
|
unsigned long ino;
|
|
#endif
|
|
|
|
if (enable_ino64)
|
|
return fileid;
|
|
ino = fileid;
|
|
if (sizeof(ino) < sizeof(fileid))
|
|
ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8;
|
|
return ino;
|
|
}
|
|
|
|
int nfs_drop_inode(struct inode *inode)
|
|
{
|
|
return NFS_STALE(inode) || generic_drop_inode(inode);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_drop_inode);
|
|
|
|
void nfs_clear_inode(struct inode *inode)
|
|
{
|
|
/*
|
|
* The following should never happen...
|
|
*/
|
|
WARN_ON_ONCE(nfs_have_writebacks(inode));
|
|
WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files));
|
|
nfs_zap_acl_cache(inode);
|
|
nfs_access_zap_cache(inode);
|
|
nfs_fscache_clear_inode(inode);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_clear_inode);
|
|
|
|
void nfs_evict_inode(struct inode *inode)
|
|
{
|
|
truncate_inode_pages_final(&inode->i_data);
|
|
clear_inode(inode);
|
|
nfs_clear_inode(inode);
|
|
}
|
|
|
|
int nfs_sync_inode(struct inode *inode)
|
|
{
|
|
inode_dio_wait(inode);
|
|
return nfs_wb_all(inode);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_sync_inode);
|
|
|
|
/**
|
|
* nfs_sync_mapping - helper to flush all mmapped dirty data to disk
|
|
* @mapping: pointer to struct address_space
|
|
*/
|
|
int nfs_sync_mapping(struct address_space *mapping)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (mapping->nrpages != 0) {
|
|
unmap_mapping_range(mapping, 0, 0, 0);
|
|
ret = nfs_wb_all(mapping->host);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static int nfs_attribute_timeout(struct inode *inode)
|
|
{
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
|
|
}
|
|
|
|
static bool nfs_check_cache_flags_invalid(struct inode *inode,
|
|
unsigned long flags)
|
|
{
|
|
unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
|
|
|
|
return (cache_validity & flags) != 0;
|
|
}
|
|
|
|
bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags)
|
|
{
|
|
if (nfs_check_cache_flags_invalid(inode, flags))
|
|
return true;
|
|
return nfs_attribute_cache_expired(inode);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_check_cache_invalid);
|
|
|
|
#ifdef CONFIG_NFS_V4_2
|
|
static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
|
|
{
|
|
return nfsi->xattr_cache != NULL;
|
|
}
|
|
#else
|
|
static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
|
|
{
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
bool have_delegation = NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
|
|
|
|
if (have_delegation) {
|
|
if (!(flags & NFS_INO_REVAL_FORCED))
|
|
flags &= ~(NFS_INO_INVALID_MODE |
|
|
NFS_INO_INVALID_OTHER |
|
|
NFS_INO_INVALID_XATTR);
|
|
flags &= ~(NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE);
|
|
} else if (flags & NFS_INO_REVAL_PAGECACHE)
|
|
flags |= NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE;
|
|
|
|
if (!nfs_has_xattr_cache(nfsi))
|
|
flags &= ~NFS_INO_INVALID_XATTR;
|
|
if (flags & NFS_INO_INVALID_DATA)
|
|
nfs_fscache_invalidate(inode);
|
|
flags &= ~(NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED);
|
|
|
|
nfsi->cache_validity |= flags;
|
|
|
|
if (inode->i_mapping->nrpages == 0)
|
|
nfsi->cache_validity &= ~(NFS_INO_INVALID_DATA |
|
|
NFS_INO_DATA_INVAL_DEFER);
|
|
else if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
|
|
nfsi->cache_validity &= ~NFS_INO_DATA_INVAL_DEFER;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_set_cache_invalid);
|
|
|
|
/*
|
|
* Invalidate the local caches
|
|
*/
|
|
static void nfs_zap_caches_locked(struct inode *inode)
|
|
{
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
int mode = inode->i_mode;
|
|
|
|
nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
|
|
|
|
nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
|
|
nfsi->attrtimeo_timestamp = jiffies;
|
|
|
|
if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
|
|
| NFS_INO_INVALID_DATA
|
|
| NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL
|
|
| NFS_INO_INVALID_XATTR
|
|
| NFS_INO_REVAL_PAGECACHE);
|
|
} else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
|
|
| NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL
|
|
| NFS_INO_INVALID_XATTR
|
|
| NFS_INO_REVAL_PAGECACHE);
|
|
nfs_zap_label_cache_locked(nfsi);
|
|
}
|
|
|
|
void nfs_zap_caches(struct inode *inode)
|
|
{
|
|
spin_lock(&inode->i_lock);
|
|
nfs_zap_caches_locked(inode);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
|
|
void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
|
|
{
|
|
if (mapping->nrpages != 0) {
|
|
spin_lock(&inode->i_lock);
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
}
|
|
|
|
void nfs_zap_acl_cache(struct inode *inode)
|
|
{
|
|
void (*clear_acl_cache)(struct inode *);
|
|
|
|
clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache;
|
|
if (clear_acl_cache != NULL)
|
|
clear_acl_cache(inode);
|
|
spin_lock(&inode->i_lock);
|
|
NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ACL;
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_zap_acl_cache);
|
|
|
|
void nfs_invalidate_atime(struct inode *inode)
|
|
{
|
|
spin_lock(&inode->i_lock);
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_invalidate_atime);
|
|
|
|
/*
|
|
* Invalidate, but do not unhash, the inode.
|
|
* NB: must be called with inode->i_lock held!
|
|
*/
|
|
static void nfs_set_inode_stale_locked(struct inode *inode)
|
|
{
|
|
set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
|
|
nfs_zap_caches_locked(inode);
|
|
trace_nfs_set_inode_stale(inode);
|
|
}
|
|
|
|
void nfs_set_inode_stale(struct inode *inode)
|
|
{
|
|
spin_lock(&inode->i_lock);
|
|
nfs_set_inode_stale_locked(inode);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
|
|
struct nfs_find_desc {
|
|
struct nfs_fh *fh;
|
|
struct nfs_fattr *fattr;
|
|
};
|
|
|
|
/*
|
|
* In NFSv3 we can have 64bit inode numbers. In order to support
|
|
* this, and re-exported directories (also seen in NFSv2)
|
|
* we are forced to allow 2 different inodes to have the same
|
|
* i_ino.
|
|
*/
|
|
static int
|
|
nfs_find_actor(struct inode *inode, void *opaque)
|
|
{
|
|
struct nfs_find_desc *desc = (struct nfs_find_desc *)opaque;
|
|
struct nfs_fh *fh = desc->fh;
|
|
struct nfs_fattr *fattr = desc->fattr;
|
|
|
|
if (NFS_FILEID(inode) != fattr->fileid)
|
|
return 0;
|
|
if (inode_wrong_type(inode, fattr->mode))
|
|
return 0;
|
|
if (nfs_compare_fh(NFS_FH(inode), fh))
|
|
return 0;
|
|
if (is_bad_inode(inode) || NFS_STALE(inode))
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
static int
|
|
nfs_init_locked(struct inode *inode, void *opaque)
|
|
{
|
|
struct nfs_find_desc *desc = (struct nfs_find_desc *)opaque;
|
|
struct nfs_fattr *fattr = desc->fattr;
|
|
|
|
set_nfs_fileid(inode, fattr->fileid);
|
|
inode->i_mode = fattr->mode;
|
|
nfs_copy_fh(NFS_FH(inode), desc->fh);
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_NFS_V4_SECURITY_LABEL
|
|
static void nfs_clear_label_invalid(struct inode *inode)
|
|
{
|
|
spin_lock(&inode->i_lock);
|
|
NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_LABEL;
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
|
|
void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
|
|
struct nfs4_label *label)
|
|
{
|
|
int error;
|
|
|
|
if (label == NULL)
|
|
return;
|
|
|
|
if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) {
|
|
error = security_inode_notifysecctx(inode, label->label,
|
|
label->len);
|
|
if (error)
|
|
printk(KERN_ERR "%s() %s %d "
|
|
"security_inode_notifysecctx() %d\n",
|
|
__func__,
|
|
(char *)label->label,
|
|
label->len, error);
|
|
nfs_clear_label_invalid(inode);
|
|
}
|
|
}
|
|
|
|
struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags)
|
|
{
|
|
struct nfs4_label *label = NULL;
|
|
int minor_version = server->nfs_client->cl_minorversion;
|
|
|
|
if (minor_version < 2)
|
|
return label;
|
|
|
|
if (!(server->caps & NFS_CAP_SECURITY_LABEL))
|
|
return label;
|
|
|
|
label = kzalloc(sizeof(struct nfs4_label), flags);
|
|
if (label == NULL)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
label->label = kzalloc(NFS4_MAXLABELLEN, flags);
|
|
if (label->label == NULL) {
|
|
kfree(label);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
label->len = NFS4_MAXLABELLEN;
|
|
|
|
return label;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs4_label_alloc);
|
|
#else
|
|
void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
|
|
struct nfs4_label *label)
|
|
{
|
|
}
|
|
#endif
|
|
EXPORT_SYMBOL_GPL(nfs_setsecurity);
|
|
|
|
/* Search for inode identified by fh, fileid and i_mode in inode cache. */
|
|
struct inode *
|
|
nfs_ilookup(struct super_block *sb, struct nfs_fattr *fattr, struct nfs_fh *fh)
|
|
{
|
|
struct nfs_find_desc desc = {
|
|
.fh = fh,
|
|
.fattr = fattr,
|
|
};
|
|
struct inode *inode;
|
|
unsigned long hash;
|
|
|
|
if (!(fattr->valid & NFS_ATTR_FATTR_FILEID) ||
|
|
!(fattr->valid & NFS_ATTR_FATTR_TYPE))
|
|
return NULL;
|
|
|
|
hash = nfs_fattr_to_ino_t(fattr);
|
|
inode = ilookup5(sb, hash, nfs_find_actor, &desc);
|
|
|
|
dprintk("%s: returning %p\n", __func__, inode);
|
|
return inode;
|
|
}
|
|
|
|
/*
|
|
* This is our front-end to iget that looks up inodes by file handle
|
|
* instead of inode number.
|
|
*/
|
|
struct inode *
|
|
nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, struct nfs4_label *label)
|
|
{
|
|
struct nfs_find_desc desc = {
|
|
.fh = fh,
|
|
.fattr = fattr
|
|
};
|
|
struct inode *inode = ERR_PTR(-ENOENT);
|
|
u64 fattr_supported = NFS_SB(sb)->fattr_valid;
|
|
unsigned long hash;
|
|
|
|
nfs_attr_check_mountpoint(sb, fattr);
|
|
|
|
if (nfs_attr_use_mounted_on_fileid(fattr))
|
|
fattr->fileid = fattr->mounted_on_fileid;
|
|
else if ((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0)
|
|
goto out_no_inode;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0)
|
|
goto out_no_inode;
|
|
|
|
hash = nfs_fattr_to_ino_t(fattr);
|
|
|
|
inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
|
|
if (inode == NULL) {
|
|
inode = ERR_PTR(-ENOMEM);
|
|
goto out_no_inode;
|
|
}
|
|
|
|
if (inode->i_state & I_NEW) {
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
unsigned long now = jiffies;
|
|
|
|
/* We set i_ino for the few things that still rely on it,
|
|
* such as stat(2) */
|
|
inode->i_ino = hash;
|
|
|
|
/* We can't support update_atime(), since the server will reset it */
|
|
inode->i_flags |= S_NOATIME|S_NOCMTIME;
|
|
inode->i_mode = fattr->mode;
|
|
nfsi->cache_validity = 0;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0
|
|
&& (fattr_supported & NFS_ATTR_FATTR_MODE))
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_MODE);
|
|
/* Why so? Because we want revalidate for devices/FIFOs, and
|
|
* that's precisely what we have in nfs_file_inode_operations.
|
|
*/
|
|
inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops;
|
|
if (S_ISREG(inode->i_mode)) {
|
|
inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops;
|
|
inode->i_data.a_ops = &nfs_file_aops;
|
|
} else if (S_ISDIR(inode->i_mode)) {
|
|
inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
|
|
inode->i_fop = &nfs_dir_operations;
|
|
inode->i_data.a_ops = &nfs_dir_aops;
|
|
/* Deal with crossing mountpoints */
|
|
if (fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT ||
|
|
fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
|
|
if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
|
|
inode->i_op = &nfs_referral_inode_operations;
|
|
else
|
|
inode->i_op = &nfs_mountpoint_inode_operations;
|
|
inode->i_fop = NULL;
|
|
inode->i_flags |= S_AUTOMOUNT;
|
|
}
|
|
} else if (S_ISLNK(inode->i_mode)) {
|
|
inode->i_op = &nfs_symlink_inode_operations;
|
|
inode_nohighmem(inode);
|
|
} else
|
|
init_special_inode(inode, inode->i_mode, fattr->rdev);
|
|
|
|
memset(&inode->i_atime, 0, sizeof(inode->i_atime));
|
|
memset(&inode->i_mtime, 0, sizeof(inode->i_mtime));
|
|
memset(&inode->i_ctime, 0, sizeof(inode->i_ctime));
|
|
inode_set_iversion_raw(inode, 0);
|
|
inode->i_size = 0;
|
|
clear_nlink(inode);
|
|
inode->i_uid = make_kuid(&init_user_ns, -2);
|
|
inode->i_gid = make_kgid(&init_user_ns, -2);
|
|
inode->i_blocks = 0;
|
|
memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
|
|
nfsi->write_io = 0;
|
|
nfsi->read_io = 0;
|
|
|
|
nfsi->read_cache_jiffies = fattr->time_start;
|
|
nfsi->attr_gencount = fattr->gencount;
|
|
if (fattr->valid & NFS_ATTR_FATTR_ATIME)
|
|
inode->i_atime = fattr->atime;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_ATIME)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
|
|
if (fattr->valid & NFS_ATTR_FATTR_MTIME)
|
|
inode->i_mtime = fattr->mtime;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_MTIME)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
|
|
if (fattr->valid & NFS_ATTR_FATTR_CTIME)
|
|
inode->i_ctime = fattr->ctime;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_CTIME)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME);
|
|
if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
|
|
inode_set_iversion_raw(inode, fattr->change_attr);
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE);
|
|
if (fattr->valid & NFS_ATTR_FATTR_SIZE)
|
|
inode->i_size = nfs_size_to_loff_t(fattr->size);
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_SIZE);
|
|
if (fattr->valid & NFS_ATTR_FATTR_NLINK)
|
|
set_nlink(inode, fattr->nlink);
|
|
else if (fattr_supported & NFS_ATTR_FATTR_NLINK)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_NLINK);
|
|
if (fattr->valid & NFS_ATTR_FATTR_OWNER)
|
|
inode->i_uid = fattr->uid;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_OWNER)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
|
|
if (fattr->valid & NFS_ATTR_FATTR_GROUP)
|
|
inode->i_gid = fattr->gid;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_GROUP)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
|
|
if (nfs_server_capable(inode, NFS_CAP_XATTR))
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR);
|
|
if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
|
|
inode->i_blocks = fattr->du.nfs2.blocks;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_BLOCKS_USED &&
|
|
fattr->size != 0)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_BLOCKS);
|
|
if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
|
|
/*
|
|
* report the blocks in 512byte units
|
|
*/
|
|
inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
|
|
} else if (fattr_supported & NFS_ATTR_FATTR_SPACE_USED &&
|
|
fattr->size != 0)
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_BLOCKS);
|
|
|
|
nfs_setsecurity(inode, fattr, label);
|
|
|
|
nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
|
|
nfsi->attrtimeo_timestamp = now;
|
|
nfsi->access_cache = RB_ROOT;
|
|
|
|
nfs_fscache_init_inode(inode);
|
|
|
|
unlock_new_inode(inode);
|
|
} else {
|
|
int err = nfs_refresh_inode(inode, fattr);
|
|
if (err < 0) {
|
|
iput(inode);
|
|
inode = ERR_PTR(err);
|
|
goto out_no_inode;
|
|
}
|
|
}
|
|
dprintk("NFS: nfs_fhget(%s/%Lu fh_crc=0x%08x ct=%d)\n",
|
|
inode->i_sb->s_id,
|
|
(unsigned long long)NFS_FILEID(inode),
|
|
nfs_display_fhandle_hash(fh),
|
|
atomic_read(&inode->i_count));
|
|
|
|
out:
|
|
return inode;
|
|
|
|
out_no_inode:
|
|
dprintk("nfs_fhget: iget failed with error %ld\n", PTR_ERR(inode));
|
|
goto out;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_fhget);
|
|
|
|
#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE|ATTR_OPEN)
|
|
|
|
int
|
|
nfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
|
struct iattr *attr)
|
|
{
|
|
struct inode *inode = d_inode(dentry);
|
|
struct nfs_fattr *fattr;
|
|
int error = 0;
|
|
|
|
nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
|
|
|
|
/* skip mode change if it's just for clearing setuid/setgid */
|
|
if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
|
|
attr->ia_valid &= ~ATTR_MODE;
|
|
|
|
if (attr->ia_valid & ATTR_SIZE) {
|
|
BUG_ON(!S_ISREG(inode->i_mode));
|
|
|
|
error = inode_newsize_ok(inode, attr->ia_size);
|
|
if (error)
|
|
return error;
|
|
|
|
if (attr->ia_size == i_size_read(inode))
|
|
attr->ia_valid &= ~ATTR_SIZE;
|
|
}
|
|
|
|
/* Optimization: if the end result is no change, don't RPC */
|
|
if (((attr->ia_valid & NFS_VALID_ATTRS) & ~(ATTR_FILE|ATTR_OPEN)) == 0)
|
|
return 0;
|
|
|
|
trace_nfs_setattr_enter(inode);
|
|
|
|
/* Write all dirty data */
|
|
if (S_ISREG(inode->i_mode))
|
|
nfs_sync_inode(inode);
|
|
|
|
fattr = nfs_alloc_fattr();
|
|
if (fattr == NULL) {
|
|
error = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
|
|
if (error == 0)
|
|
error = nfs_refresh_inode(inode, fattr);
|
|
nfs_free_fattr(fattr);
|
|
out:
|
|
trace_nfs_setattr_exit(inode, error);
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_setattr);
|
|
|
|
/**
|
|
* nfs_vmtruncate - unmap mappings "freed" by truncate() syscall
|
|
* @inode: inode of the file used
|
|
* @offset: file offset to start truncating
|
|
*
|
|
* This is a copy of the common vmtruncate, but with the locking
|
|
* corrected to take into account the fact that NFS requires
|
|
* inode->i_size to be updated under the inode->i_lock.
|
|
* Note: must be called with inode->i_lock held!
|
|
*/
|
|
static int nfs_vmtruncate(struct inode * inode, loff_t offset)
|
|
{
|
|
int err;
|
|
|
|
err = inode_newsize_ok(inode, offset);
|
|
if (err)
|
|
goto out;
|
|
|
|
i_size_write(inode, offset);
|
|
/* Optimisation */
|
|
if (offset == 0)
|
|
NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_DATA |
|
|
NFS_INO_DATA_INVAL_DEFER);
|
|
NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE;
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
truncate_pagecache(inode, offset);
|
|
spin_lock(&inode->i_lock);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* nfs_setattr_update_inode - Update inode metadata after a setattr call.
|
|
* @inode: pointer to struct inode
|
|
* @attr: pointer to struct iattr
|
|
* @fattr: pointer to struct nfs_fattr
|
|
*
|
|
* Note: we do this in the *proc.c in order to ensure that
|
|
* it works for things like exclusive creates too.
|
|
*/
|
|
void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
|
|
struct nfs_fattr *fattr)
|
|
{
|
|
/* Barrier: bump the attribute generation count. */
|
|
nfs_fattr_set_barrier(fattr);
|
|
|
|
spin_lock(&inode->i_lock);
|
|
NFS_I(inode)->attr_gencount = fattr->gencount;
|
|
if ((attr->ia_valid & ATTR_SIZE) != 0) {
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME |
|
|
NFS_INO_INVALID_BLOCKS);
|
|
nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
|
|
nfs_vmtruncate(inode, attr->ia_size);
|
|
}
|
|
if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) {
|
|
NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_CTIME;
|
|
if ((attr->ia_valid & ATTR_KILL_SUID) != 0 &&
|
|
inode->i_mode & S_ISUID)
|
|
inode->i_mode &= ~S_ISUID;
|
|
if ((attr->ia_valid & ATTR_KILL_SGID) != 0 &&
|
|
(inode->i_mode & (S_ISGID | S_IXGRP)) ==
|
|
(S_ISGID | S_IXGRP))
|
|
inode->i_mode &= ~S_ISGID;
|
|
if ((attr->ia_valid & ATTR_MODE) != 0) {
|
|
int mode = attr->ia_mode & S_IALLUGO;
|
|
mode |= inode->i_mode & ~S_IALLUGO;
|
|
inode->i_mode = mode;
|
|
}
|
|
if ((attr->ia_valid & ATTR_UID) != 0)
|
|
inode->i_uid = attr->ia_uid;
|
|
if ((attr->ia_valid & ATTR_GID) != 0)
|
|
inode->i_gid = attr->ia_gid;
|
|
if (fattr->valid & NFS_ATTR_FATTR_CTIME)
|
|
inode->i_ctime = fattr->ctime;
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
|
|
| NFS_INO_INVALID_CTIME);
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL);
|
|
}
|
|
if (attr->ia_valid & (ATTR_ATIME_SET|ATTR_ATIME)) {
|
|
NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_ATIME
|
|
| NFS_INO_INVALID_CTIME);
|
|
if (fattr->valid & NFS_ATTR_FATTR_ATIME)
|
|
inode->i_atime = fattr->atime;
|
|
else if (attr->ia_valid & ATTR_ATIME_SET)
|
|
inode->i_atime = attr->ia_atime;
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_CTIME)
|
|
inode->i_ctime = fattr->ctime;
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
|
|
| NFS_INO_INVALID_CTIME);
|
|
}
|
|
if (attr->ia_valid & (ATTR_MTIME_SET|ATTR_MTIME)) {
|
|
NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_MTIME
|
|
| NFS_INO_INVALID_CTIME);
|
|
if (fattr->valid & NFS_ATTR_FATTR_MTIME)
|
|
inode->i_mtime = fattr->mtime;
|
|
else if (attr->ia_valid & ATTR_MTIME_SET)
|
|
inode->i_mtime = attr->ia_mtime;
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_CTIME)
|
|
inode->i_ctime = fattr->ctime;
|
|
else
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
|
|
| NFS_INO_INVALID_CTIME);
|
|
}
|
|
if (fattr->valid)
|
|
nfs_update_inode(inode, fattr);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
|
|
|
|
static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
|
|
{
|
|
struct dentry *parent;
|
|
|
|
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
|
|
return;
|
|
parent = dget_parent(dentry);
|
|
nfs_force_use_readdirplus(d_inode(parent));
|
|
dput(parent);
|
|
}
|
|
|
|
static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
|
|
{
|
|
struct dentry *parent;
|
|
|
|
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
|
|
return;
|
|
parent = dget_parent(dentry);
|
|
nfs_advise_use_readdirplus(d_inode(parent));
|
|
dput(parent);
|
|
}
|
|
|
|
static u32 nfs_get_valid_attrmask(struct inode *inode)
|
|
{
|
|
unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
|
|
u32 reply_mask = STATX_INO | STATX_TYPE;
|
|
|
|
if (!(cache_validity & NFS_INO_INVALID_ATIME))
|
|
reply_mask |= STATX_ATIME;
|
|
if (!(cache_validity & NFS_INO_INVALID_CTIME))
|
|
reply_mask |= STATX_CTIME;
|
|
if (!(cache_validity & NFS_INO_INVALID_MTIME))
|
|
reply_mask |= STATX_MTIME;
|
|
if (!(cache_validity & NFS_INO_INVALID_SIZE))
|
|
reply_mask |= STATX_SIZE;
|
|
if (!(cache_validity & NFS_INO_INVALID_NLINK))
|
|
reply_mask |= STATX_NLINK;
|
|
if (!(cache_validity & NFS_INO_INVALID_MODE))
|
|
reply_mask |= STATX_MODE;
|
|
if (!(cache_validity & NFS_INO_INVALID_OTHER))
|
|
reply_mask |= STATX_UID | STATX_GID;
|
|
if (!(cache_validity & NFS_INO_INVALID_BLOCKS))
|
|
reply_mask |= STATX_BLOCKS;
|
|
return reply_mask;
|
|
}
|
|
|
|
int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|
struct kstat *stat, u32 request_mask, unsigned int query_flags)
|
|
{
|
|
struct inode *inode = d_inode(path->dentry);
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
unsigned long cache_validity;
|
|
int err = 0;
|
|
bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
|
|
bool do_update = false;
|
|
|
|
trace_nfs_getattr_enter(inode);
|
|
|
|
request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID |
|
|
STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME |
|
|
STATX_INO | STATX_SIZE | STATX_BLOCKS;
|
|
|
|
if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
|
|
nfs_readdirplus_parent_cache_hit(path->dentry);
|
|
goto out_no_revalidate;
|
|
}
|
|
|
|
/* Flush out writes to the server in order to update c/mtime. */
|
|
if ((request_mask & (STATX_CTIME | STATX_MTIME)) &&
|
|
S_ISREG(inode->i_mode))
|
|
filemap_write_and_wait(inode->i_mapping);
|
|
|
|
/*
|
|
* We may force a getattr if the user cares about atime.
|
|
*
|
|
* Note that we only have to check the vfsmount flags here:
|
|
* - NFS always sets S_NOATIME by so checking it would give a
|
|
* bogus result
|
|
* - NFS never sets SB_NOATIME or SB_NODIRATIME so there is
|
|
* no point in checking those.
|
|
*/
|
|
if ((path->mnt->mnt_flags & MNT_NOATIME) ||
|
|
((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
|
|
request_mask &= ~STATX_ATIME;
|
|
|
|
/* Is the user requesting attributes that might need revalidation? */
|
|
if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
|
|
STATX_MTIME|STATX_UID|STATX_GID|
|
|
STATX_SIZE|STATX_BLOCKS)))
|
|
goto out_no_revalidate;
|
|
|
|
/* Check whether the cached attributes are stale */
|
|
do_update |= force_sync || nfs_attribute_cache_expired(inode);
|
|
cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
|
|
do_update |= cache_validity & NFS_INO_INVALID_CHANGE;
|
|
if (request_mask & STATX_ATIME)
|
|
do_update |= cache_validity & NFS_INO_INVALID_ATIME;
|
|
if (request_mask & STATX_CTIME)
|
|
do_update |= cache_validity & NFS_INO_INVALID_CTIME;
|
|
if (request_mask & STATX_MTIME)
|
|
do_update |= cache_validity & NFS_INO_INVALID_MTIME;
|
|
if (request_mask & STATX_SIZE)
|
|
do_update |= cache_validity & NFS_INO_INVALID_SIZE;
|
|
if (request_mask & STATX_NLINK)
|
|
do_update |= cache_validity & NFS_INO_INVALID_NLINK;
|
|
if (request_mask & STATX_MODE)
|
|
do_update |= cache_validity & NFS_INO_INVALID_MODE;
|
|
if (request_mask & (STATX_UID | STATX_GID))
|
|
do_update |= cache_validity & NFS_INO_INVALID_OTHER;
|
|
if (request_mask & STATX_BLOCKS)
|
|
do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
|
|
|
|
if (do_update) {
|
|
/* Update the attribute cache */
|
|
if (!(server->flags & NFS_MOUNT_NOAC))
|
|
nfs_readdirplus_parent_cache_miss(path->dentry);
|
|
else
|
|
nfs_readdirplus_parent_cache_hit(path->dentry);
|
|
err = __nfs_revalidate_inode(server, inode);
|
|
if (err)
|
|
goto out;
|
|
} else
|
|
nfs_readdirplus_parent_cache_hit(path->dentry);
|
|
out_no_revalidate:
|
|
/* Only return attributes that were revalidated. */
|
|
stat->result_mask = nfs_get_valid_attrmask(inode) | request_mask;
|
|
|
|
generic_fillattr(&init_user_ns, inode, stat);
|
|
stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
|
|
if (S_ISDIR(inode->i_mode))
|
|
stat->blksize = NFS_SERVER(inode)->dtsize;
|
|
out:
|
|
trace_nfs_getattr_exit(inode, err);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_getattr);
|
|
|
|
static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
|
|
{
|
|
refcount_set(&l_ctx->count, 1);
|
|
l_ctx->lockowner = current->files;
|
|
INIT_LIST_HEAD(&l_ctx->list);
|
|
atomic_set(&l_ctx->io_count, 0);
|
|
}
|
|
|
|
static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
|
|
{
|
|
struct nfs_lock_context *pos;
|
|
|
|
list_for_each_entry_rcu(pos, &ctx->lock_context.list, list) {
|
|
if (pos->lockowner != current->files)
|
|
continue;
|
|
if (refcount_inc_not_zero(&pos->count))
|
|
return pos;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
|
|
{
|
|
struct nfs_lock_context *res, *new = NULL;
|
|
struct inode *inode = d_inode(ctx->dentry);
|
|
|
|
rcu_read_lock();
|
|
res = __nfs_find_lock_context(ctx);
|
|
rcu_read_unlock();
|
|
if (res == NULL) {
|
|
new = kmalloc(sizeof(*new), GFP_KERNEL);
|
|
if (new == NULL)
|
|
return ERR_PTR(-ENOMEM);
|
|
nfs_init_lock_context(new);
|
|
spin_lock(&inode->i_lock);
|
|
res = __nfs_find_lock_context(ctx);
|
|
if (res == NULL) {
|
|
new->open_context = get_nfs_open_context(ctx);
|
|
if (new->open_context) {
|
|
list_add_tail_rcu(&new->list,
|
|
&ctx->lock_context.list);
|
|
res = new;
|
|
new = NULL;
|
|
} else
|
|
res = ERR_PTR(-EBADF);
|
|
}
|
|
spin_unlock(&inode->i_lock);
|
|
kfree(new);
|
|
}
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_get_lock_context);
|
|
|
|
void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
|
|
{
|
|
struct nfs_open_context *ctx = l_ctx->open_context;
|
|
struct inode *inode = d_inode(ctx->dentry);
|
|
|
|
if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock))
|
|
return;
|
|
list_del_rcu(&l_ctx->list);
|
|
spin_unlock(&inode->i_lock);
|
|
put_nfs_open_context(ctx);
|
|
kfree_rcu(l_ctx, rcu_head);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_put_lock_context);
|
|
|
|
/**
|
|
* nfs_close_context - Common close_context() routine NFSv2/v3
|
|
* @ctx: pointer to context
|
|
* @is_sync: is this a synchronous close
|
|
*
|
|
* Ensure that the attributes are up to date if we're mounted
|
|
* with close-to-open semantics and we have cached data that will
|
|
* need to be revalidated on open.
|
|
*/
|
|
void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
|
|
{
|
|
struct nfs_inode *nfsi;
|
|
struct inode *inode;
|
|
|
|
if (!(ctx->mode & FMODE_WRITE))
|
|
return;
|
|
if (!is_sync)
|
|
return;
|
|
inode = d_inode(ctx->dentry);
|
|
if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
|
|
return;
|
|
nfsi = NFS_I(inode);
|
|
if (inode->i_mapping->nrpages == 0)
|
|
return;
|
|
if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
|
|
return;
|
|
if (!list_empty(&nfsi->open_files))
|
|
return;
|
|
if (NFS_SERVER(inode)->flags & NFS_MOUNT_NOCTO)
|
|
return;
|
|
nfs_revalidate_inode(inode,
|
|
NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_close_context);
|
|
|
|
struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
|
|
fmode_t f_mode,
|
|
struct file *filp)
|
|
{
|
|
struct nfs_open_context *ctx;
|
|
|
|
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
|
|
if (!ctx)
|
|
return ERR_PTR(-ENOMEM);
|
|
nfs_sb_active(dentry->d_sb);
|
|
ctx->dentry = dget(dentry);
|
|
if (filp)
|
|
ctx->cred = get_cred(filp->f_cred);
|
|
else
|
|
ctx->cred = get_current_cred();
|
|
ctx->ll_cred = NULL;
|
|
ctx->state = NULL;
|
|
ctx->mode = f_mode;
|
|
ctx->flags = 0;
|
|
ctx->error = 0;
|
|
ctx->flock_owner = (fl_owner_t)filp;
|
|
nfs_init_lock_context(&ctx->lock_context);
|
|
ctx->lock_context.open_context = ctx;
|
|
INIT_LIST_HEAD(&ctx->list);
|
|
ctx->mdsthreshold = NULL;
|
|
return ctx;
|
|
}
|
|
EXPORT_SYMBOL_GPL(alloc_nfs_open_context);
|
|
|
|
struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
|
|
{
|
|
if (ctx != NULL && refcount_inc_not_zero(&ctx->lock_context.count))
|
|
return ctx;
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(get_nfs_open_context);
|
|
|
|
static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
|
|
{
|
|
struct inode *inode = d_inode(ctx->dentry);
|
|
struct super_block *sb = ctx->dentry->d_sb;
|
|
|
|
if (!refcount_dec_and_test(&ctx->lock_context.count))
|
|
return;
|
|
if (!list_empty(&ctx->list)) {
|
|
spin_lock(&inode->i_lock);
|
|
list_del_rcu(&ctx->list);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
if (inode != NULL)
|
|
NFS_PROTO(inode)->close_context(ctx, is_sync);
|
|
put_cred(ctx->cred);
|
|
dput(ctx->dentry);
|
|
nfs_sb_deactive(sb);
|
|
put_rpccred(ctx->ll_cred);
|
|
kfree(ctx->mdsthreshold);
|
|
kfree_rcu(ctx, rcu_head);
|
|
}
|
|
|
|
void put_nfs_open_context(struct nfs_open_context *ctx)
|
|
{
|
|
__put_nfs_open_context(ctx, 0);
|
|
}
|
|
EXPORT_SYMBOL_GPL(put_nfs_open_context);
|
|
|
|
static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
|
|
{
|
|
__put_nfs_open_context(ctx, 1);
|
|
}
|
|
|
|
/*
|
|
* Ensure that mmap has a recent RPC credential for use when writing out
|
|
* shared pages
|
|
*/
|
|
void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
|
|
{
|
|
struct inode *inode = d_inode(ctx->dentry);
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
spin_lock(&inode->i_lock);
|
|
if (list_empty(&nfsi->open_files) &&
|
|
(nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA |
|
|
NFS_INO_REVAL_FORCED);
|
|
list_add_tail_rcu(&ctx->list, &nfsi->open_files);
|
|
spin_unlock(&inode->i_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_inode_attach_open_context);
|
|
|
|
void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
|
|
{
|
|
filp->private_data = get_nfs_open_context(ctx);
|
|
set_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
|
|
if (list_empty(&ctx->list))
|
|
nfs_inode_attach_open_context(ctx);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_file_set_open_context);
|
|
|
|
/*
|
|
* Given an inode, search for an open context with the desired characteristics
|
|
*/
|
|
struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode)
|
|
{
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
struct nfs_open_context *pos, *ctx = NULL;
|
|
|
|
rcu_read_lock();
|
|
list_for_each_entry_rcu(pos, &nfsi->open_files, list) {
|
|
if (cred != NULL && cred_fscmp(pos->cred, cred) != 0)
|
|
continue;
|
|
if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
|
|
continue;
|
|
if (!test_bit(NFS_CONTEXT_FILE_OPEN, &pos->flags))
|
|
continue;
|
|
ctx = get_nfs_open_context(pos);
|
|
if (ctx)
|
|
break;
|
|
}
|
|
rcu_read_unlock();
|
|
return ctx;
|
|
}
|
|
|
|
void nfs_file_clear_open_context(struct file *filp)
|
|
{
|
|
struct nfs_open_context *ctx = nfs_file_open_context(filp);
|
|
|
|
if (ctx) {
|
|
struct inode *inode = d_inode(ctx->dentry);
|
|
|
|
clear_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
|
|
/*
|
|
* We fatal error on write before. Try to writeback
|
|
* every page again.
|
|
*/
|
|
if (ctx->error < 0)
|
|
invalidate_inode_pages2(inode->i_mapping);
|
|
filp->private_data = NULL;
|
|
put_nfs_open_context_sync(ctx);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* These allocate and release file read/write context information.
|
|
*/
|
|
int nfs_open(struct inode *inode, struct file *filp)
|
|
{
|
|
struct nfs_open_context *ctx;
|
|
|
|
ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp);
|
|
if (IS_ERR(ctx))
|
|
return PTR_ERR(ctx);
|
|
nfs_file_set_open_context(filp, ctx);
|
|
put_nfs_open_context(ctx);
|
|
nfs_fscache_open_file(inode, filp);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* This function is called whenever some part of NFS notices that
|
|
* the cached attributes have to be refreshed.
|
|
*/
|
|
int
|
|
__nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
|
|
{
|
|
int status = -ESTALE;
|
|
struct nfs4_label *label = NULL;
|
|
struct nfs_fattr *fattr = NULL;
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
dfprintk(PAGECACHE, "NFS: revalidating (%s/%Lu)\n",
|
|
inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode));
|
|
|
|
trace_nfs_revalidate_inode_enter(inode);
|
|
|
|
if (is_bad_inode(inode))
|
|
goto out;
|
|
if (NFS_STALE(inode))
|
|
goto out;
|
|
|
|
/* pNFS: Attributes aren't updated until we layoutcommit */
|
|
if (S_ISREG(inode->i_mode)) {
|
|
status = pnfs_sync_inode(inode, false);
|
|
if (status)
|
|
goto out;
|
|
}
|
|
|
|
status = -ENOMEM;
|
|
fattr = nfs_alloc_fattr();
|
|
if (fattr == NULL)
|
|
goto out;
|
|
|
|
nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
|
|
|
|
label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
|
|
if (IS_ERR(label)) {
|
|
status = PTR_ERR(label);
|
|
goto out;
|
|
}
|
|
|
|
status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr,
|
|
label, inode);
|
|
if (status != 0) {
|
|
dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) getattr failed, error=%d\n",
|
|
inode->i_sb->s_id,
|
|
(unsigned long long)NFS_FILEID(inode), status);
|
|
switch (status) {
|
|
case -ETIMEDOUT:
|
|
/* A soft timeout occurred. Use cached information? */
|
|
if (server->flags & NFS_MOUNT_SOFTREVAL)
|
|
status = 0;
|
|
break;
|
|
case -ESTALE:
|
|
if (!S_ISDIR(inode->i_mode))
|
|
nfs_set_inode_stale(inode);
|
|
else
|
|
nfs_zap_caches(inode);
|
|
}
|
|
goto err_out;
|
|
}
|
|
|
|
status = nfs_refresh_inode(inode, fattr);
|
|
if (status) {
|
|
dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) refresh failed, error=%d\n",
|
|
inode->i_sb->s_id,
|
|
(unsigned long long)NFS_FILEID(inode), status);
|
|
goto err_out;
|
|
}
|
|
|
|
if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
|
|
nfs_zap_acl_cache(inode);
|
|
|
|
nfs_setsecurity(inode, fattr, label);
|
|
|
|
dfprintk(PAGECACHE, "NFS: (%s/%Lu) revalidation complete\n",
|
|
inode->i_sb->s_id,
|
|
(unsigned long long)NFS_FILEID(inode));
|
|
|
|
err_out:
|
|
nfs4_label_free(label);
|
|
out:
|
|
nfs_free_fattr(fattr);
|
|
trace_nfs_revalidate_inode_exit(inode, status);
|
|
return status;
|
|
}
|
|
|
|
int nfs_attribute_cache_expired(struct inode *inode)
|
|
{
|
|
if (nfs_have_delegated_attributes(inode))
|
|
return 0;
|
|
return nfs_attribute_timeout(inode);
|
|
}
|
|
|
|
/**
|
|
* nfs_revalidate_inode - Revalidate the inode attributes
|
|
* @inode: pointer to inode struct
|
|
* @flags: cache flags to check
|
|
*
|
|
* Updates inode attribute information by retrieving the data from the server.
|
|
*/
|
|
int nfs_revalidate_inode(struct inode *inode, unsigned long flags)
|
|
{
|
|
if (!nfs_check_cache_invalid(inode, flags))
|
|
return NFS_STALE(inode) ? -ESTALE : 0;
|
|
return __nfs_revalidate_inode(NFS_SERVER(inode), inode);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_revalidate_inode);
|
|
|
|
static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
|
|
{
|
|
int ret;
|
|
|
|
if (mapping->nrpages != 0) {
|
|
if (S_ISREG(inode->i_mode)) {
|
|
ret = nfs_sync_mapping(mapping);
|
|
if (ret < 0)
|
|
return ret;
|
|
}
|
|
ret = invalidate_inode_pages2(mapping);
|
|
if (ret < 0)
|
|
return ret;
|
|
}
|
|
nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
|
|
nfs_fscache_wait_on_invalidate(inode);
|
|
|
|
dfprintk(PAGECACHE, "NFS: (%s/%Lu) data cache invalidated\n",
|
|
inode->i_sb->s_id,
|
|
(unsigned long long)NFS_FILEID(inode));
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* nfs_clear_invalid_mapping - Conditionally clear a mapping
|
|
* @mapping: pointer to mapping
|
|
*
|
|
* If the NFS_INO_INVALID_DATA inode flag is set, clear the mapping.
|
|
*/
|
|
int nfs_clear_invalid_mapping(struct address_space *mapping)
|
|
{
|
|
struct inode *inode = mapping->host;
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
unsigned long *bitlock = &nfsi->flags;
|
|
int ret = 0;
|
|
|
|
/*
|
|
* We must clear NFS_INO_INVALID_DATA first to ensure that
|
|
* invalidations that come in while we're shooting down the mappings
|
|
* are respected. But, that leaves a race window where one revalidator
|
|
* can clear the flag, and then another checks it before the mapping
|
|
* gets invalidated. Fix that by serializing access to this part of
|
|
* the function.
|
|
*
|
|
* At the same time, we need to allow other tasks to see whether we
|
|
* might be in the middle of invalidating the pages, so we only set
|
|
* the bit lock here if it looks like we're going to be doing that.
|
|
*/
|
|
for (;;) {
|
|
ret = wait_on_bit_action(bitlock, NFS_INO_INVALIDATING,
|
|
nfs_wait_bit_killable, TASK_KILLABLE);
|
|
if (ret)
|
|
goto out;
|
|
spin_lock(&inode->i_lock);
|
|
if (test_bit(NFS_INO_INVALIDATING, bitlock)) {
|
|
spin_unlock(&inode->i_lock);
|
|
continue;
|
|
}
|
|
if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
|
|
break;
|
|
spin_unlock(&inode->i_lock);
|
|
goto out;
|
|
}
|
|
|
|
set_bit(NFS_INO_INVALIDATING, bitlock);
|
|
smp_wmb();
|
|
nfsi->cache_validity &=
|
|
~(NFS_INO_INVALID_DATA | NFS_INO_DATA_INVAL_DEFER);
|
|
spin_unlock(&inode->i_lock);
|
|
trace_nfs_invalidate_mapping_enter(inode);
|
|
ret = nfs_invalidate_mapping(inode, mapping);
|
|
trace_nfs_invalidate_mapping_exit(inode, ret);
|
|
|
|
clear_bit_unlock(NFS_INO_INVALIDATING, bitlock);
|
|
smp_mb__after_atomic();
|
|
wake_up_bit(bitlock, NFS_INO_INVALIDATING);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
bool nfs_mapping_need_revalidate_inode(struct inode *inode)
|
|
{
|
|
return nfs_check_cache_invalid(inode, NFS_INO_INVALID_CHANGE) ||
|
|
NFS_STALE(inode);
|
|
}
|
|
|
|
int nfs_revalidate_mapping_rcu(struct inode *inode)
|
|
{
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
unsigned long *bitlock = &nfsi->flags;
|
|
int ret = 0;
|
|
|
|
if (IS_SWAPFILE(inode))
|
|
goto out;
|
|
if (nfs_mapping_need_revalidate_inode(inode)) {
|
|
ret = -ECHILD;
|
|
goto out;
|
|
}
|
|
spin_lock(&inode->i_lock);
|
|
if (test_bit(NFS_INO_INVALIDATING, bitlock) ||
|
|
(nfsi->cache_validity & NFS_INO_INVALID_DATA))
|
|
ret = -ECHILD;
|
|
spin_unlock(&inode->i_lock);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* nfs_revalidate_mapping - Revalidate the pagecache
|
|
* @inode: pointer to host inode
|
|
* @mapping: pointer to mapping
|
|
*/
|
|
int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
|
|
{
|
|
/* swapfiles are not supposed to be shared. */
|
|
if (IS_SWAPFILE(inode))
|
|
return 0;
|
|
|
|
if (nfs_mapping_need_revalidate_inode(inode)) {
|
|
int ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
|
|
if (ret < 0)
|
|
return ret;
|
|
}
|
|
|
|
return nfs_clear_invalid_mapping(mapping);
|
|
}
|
|
|
|
static bool nfs_file_has_writers(struct nfs_inode *nfsi)
|
|
{
|
|
struct inode *inode = &nfsi->vfs_inode;
|
|
|
|
if (!S_ISREG(inode->i_mode))
|
|
return false;
|
|
if (list_empty(&nfsi->open_files))
|
|
return false;
|
|
return inode_is_open_for_write(inode);
|
|
}
|
|
|
|
static bool nfs_file_has_buffered_writers(struct nfs_inode *nfsi)
|
|
{
|
|
return nfs_file_has_writers(nfsi) && nfs_file_io_is_buffered(nfsi);
|
|
}
|
|
|
|
static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
struct timespec64 ts;
|
|
|
|
if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE)
|
|
&& (fattr->valid & NFS_ATTR_FATTR_CHANGE)
|
|
&& inode_eq_iversion_raw(inode, fattr->pre_change_attr)) {
|
|
inode_set_iversion_raw(inode, fattr->change_attr);
|
|
if (S_ISDIR(inode->i_mode))
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
|
|
else if (nfs_server_capable(inode, NFS_CAP_XATTR))
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR);
|
|
}
|
|
/* If we have atomic WCC data, we may update some attributes */
|
|
ts = inode->i_ctime;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME)
|
|
&& (fattr->valid & NFS_ATTR_FATTR_CTIME)
|
|
&& timespec64_equal(&ts, &fattr->pre_ctime)) {
|
|
inode->i_ctime = fattr->ctime;
|
|
}
|
|
|
|
ts = inode->i_mtime;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
|
|
&& (fattr->valid & NFS_ATTR_FATTR_MTIME)
|
|
&& timespec64_equal(&ts, &fattr->pre_mtime)) {
|
|
inode->i_mtime = fattr->mtime;
|
|
if (S_ISDIR(inode->i_mode))
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
|
|
}
|
|
if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
|
|
&& (fattr->valid & NFS_ATTR_FATTR_SIZE)
|
|
&& i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
|
|
&& !nfs_have_writebacks(inode)) {
|
|
i_size_write(inode, nfs_size_to_loff_t(fattr->size));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* nfs_check_inode_attributes - verify consistency of the inode attribute cache
|
|
* @inode: pointer to inode
|
|
* @fattr: updated attributes
|
|
*
|
|
* Verifies the attribute cache. If we have just changed the attributes,
|
|
* so that fattr carries weak cache consistency data, then it may
|
|
* also update the ctime/mtime/change_attribute.
|
|
*/
|
|
static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
loff_t cur_size, new_isize;
|
|
unsigned long invalid = 0;
|
|
struct timespec64 ts;
|
|
|
|
if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
|
|
return 0;
|
|
|
|
if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
|
|
/* Only a mounted-on-fileid? Just exit */
|
|
if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
|
|
return 0;
|
|
/* Has the inode gone and changed behind our back? */
|
|
} else if (nfsi->fileid != fattr->fileid) {
|
|
/* Is this perhaps the mounted-on fileid? */
|
|
if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) &&
|
|
nfsi->fileid == fattr->mounted_on_fileid)
|
|
return 0;
|
|
return -ESTALE;
|
|
}
|
|
if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode))
|
|
return -ESTALE;
|
|
|
|
|
|
if (!nfs_file_has_buffered_writers(nfsi)) {
|
|
/* Verify a few of the more important attributes */
|
|
if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && !inode_eq_iversion_raw(inode, fattr->change_attr))
|
|
invalid |= NFS_INO_INVALID_CHANGE;
|
|
|
|
ts = inode->i_mtime;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec64_equal(&ts, &fattr->mtime))
|
|
invalid |= NFS_INO_INVALID_MTIME;
|
|
|
|
ts = inode->i_ctime;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && !timespec64_equal(&ts, &fattr->ctime))
|
|
invalid |= NFS_INO_INVALID_CTIME;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
|
|
cur_size = i_size_read(inode);
|
|
new_isize = nfs_size_to_loff_t(fattr->size);
|
|
if (cur_size != new_isize)
|
|
invalid |= NFS_INO_INVALID_SIZE;
|
|
}
|
|
}
|
|
|
|
/* Have any file permissions changed? */
|
|
if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
|
|
invalid |= NFS_INO_INVALID_MODE;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
|
|
invalid |= NFS_INO_INVALID_OTHER;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
|
|
invalid |= NFS_INO_INVALID_OTHER;
|
|
|
|
/* Has the link count changed? */
|
|
if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
|
|
invalid |= NFS_INO_INVALID_NLINK;
|
|
|
|
ts = inode->i_atime;
|
|
if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec64_equal(&ts, &fattr->atime))
|
|
invalid |= NFS_INO_INVALID_ATIME;
|
|
|
|
if (invalid != 0)
|
|
nfs_set_cache_invalid(inode, invalid);
|
|
|
|
nfsi->read_cache_jiffies = fattr->time_start;
|
|
return 0;
|
|
}
|
|
|
|
static atomic_long_t nfs_attr_generation_counter;
|
|
|
|
static unsigned long nfs_read_attr_generation_counter(void)
|
|
{
|
|
return atomic_long_read(&nfs_attr_generation_counter);
|
|
}
|
|
|
|
unsigned long nfs_inc_attr_generation_counter(void)
|
|
{
|
|
return atomic_long_inc_return(&nfs_attr_generation_counter);
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_inc_attr_generation_counter);
|
|
|
|
void nfs_fattr_init(struct nfs_fattr *fattr)
|
|
{
|
|
fattr->valid = 0;
|
|
fattr->time_start = jiffies;
|
|
fattr->gencount = nfs_inc_attr_generation_counter();
|
|
fattr->owner_name = NULL;
|
|
fattr->group_name = NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_fattr_init);
|
|
|
|
/**
|
|
* nfs_fattr_set_barrier
|
|
* @fattr: attributes
|
|
*
|
|
* Used to set a barrier after an attribute was updated. This
|
|
* barrier ensures that older attributes from RPC calls that may
|
|
* have raced with our update cannot clobber these new values.
|
|
* Note that you are still responsible for ensuring that other
|
|
* operations which change the attribute on the server do not
|
|
* collide.
|
|
*/
|
|
void nfs_fattr_set_barrier(struct nfs_fattr *fattr)
|
|
{
|
|
fattr->gencount = nfs_inc_attr_generation_counter();
|
|
}
|
|
|
|
struct nfs_fattr *nfs_alloc_fattr(void)
|
|
{
|
|
struct nfs_fattr *fattr;
|
|
|
|
fattr = kmalloc(sizeof(*fattr), GFP_KERNEL);
|
|
if (fattr != NULL) {
|
|
nfs_fattr_init(fattr);
|
|
fattr->label = NULL;
|
|
}
|
|
return fattr;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_alloc_fattr);
|
|
|
|
struct nfs_fattr *nfs_alloc_fattr_with_label(struct nfs_server *server)
|
|
{
|
|
struct nfs_fattr *fattr = nfs_alloc_fattr();
|
|
|
|
if (!fattr)
|
|
return NULL;
|
|
|
|
fattr->label = nfs4_label_alloc(server, GFP_KERNEL);
|
|
if (IS_ERR(fattr->label)) {
|
|
kfree(fattr);
|
|
return NULL;
|
|
}
|
|
|
|
return fattr;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_alloc_fattr_with_label);
|
|
|
|
struct nfs_fh *nfs_alloc_fhandle(void)
|
|
{
|
|
struct nfs_fh *fh;
|
|
|
|
fh = kmalloc(sizeof(struct nfs_fh), GFP_KERNEL);
|
|
if (fh != NULL)
|
|
fh->size = 0;
|
|
return fh;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_alloc_fhandle);
|
|
|
|
#ifdef NFS_DEBUG
|
|
/*
|
|
* _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
|
|
* in the same way that wireshark does
|
|
*
|
|
* @fh: file handle
|
|
*
|
|
* For debugging only.
|
|
*/
|
|
u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
|
|
{
|
|
/* wireshark uses 32-bit AUTODIN crc and does a bitwise
|
|
* not on the result */
|
|
return nfs_fhandle_hash(fh);
|
|
}
|
|
EXPORT_SYMBOL_GPL(_nfs_display_fhandle_hash);
|
|
|
|
/*
|
|
* _nfs_display_fhandle - display an NFS file handle on the console
|
|
*
|
|
* @fh: file handle to display
|
|
* @caption: display caption
|
|
*
|
|
* For debugging only.
|
|
*/
|
|
void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
|
|
{
|
|
unsigned short i;
|
|
|
|
if (fh == NULL || fh->size == 0) {
|
|
printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh);
|
|
return;
|
|
}
|
|
|
|
printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
|
|
caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
|
|
for (i = 0; i < fh->size; i += 16) {
|
|
__be32 *pos = (__be32 *)&fh->data[i];
|
|
|
|
switch ((fh->size - i - 1) >> 2) {
|
|
case 0:
|
|
printk(KERN_DEFAULT " %08x\n",
|
|
be32_to_cpup(pos));
|
|
break;
|
|
case 1:
|
|
printk(KERN_DEFAULT " %08x %08x\n",
|
|
be32_to_cpup(pos), be32_to_cpup(pos + 1));
|
|
break;
|
|
case 2:
|
|
printk(KERN_DEFAULT " %08x %08x %08x\n",
|
|
be32_to_cpup(pos), be32_to_cpup(pos + 1),
|
|
be32_to_cpup(pos + 2));
|
|
break;
|
|
default:
|
|
printk(KERN_DEFAULT " %08x %08x %08x %08x\n",
|
|
be32_to_cpup(pos), be32_to_cpup(pos + 1),
|
|
be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
|
|
}
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(_nfs_display_fhandle);
|
|
#endif
|
|
|
|
/**
|
|
* nfs_inode_attrs_cmp_generic - compare attributes
|
|
* @fattr: attributes
|
|
* @inode: pointer to inode
|
|
*
|
|
* Attempt to divine whether or not an RPC call reply carrying stale
|
|
* attributes got scheduled after another call carrying updated ones.
|
|
* Note also the check for wraparound of 'attr_gencount'
|
|
*
|
|
* The function returns '1' if it thinks the attributes in @fattr are
|
|
* more recent than the ones cached in @inode. Otherwise it returns
|
|
* the value '0'.
|
|
*/
|
|
static int nfs_inode_attrs_cmp_generic(const struct nfs_fattr *fattr,
|
|
const struct inode *inode)
|
|
{
|
|
unsigned long attr_gencount = NFS_I(inode)->attr_gencount;
|
|
|
|
return (long)(fattr->gencount - attr_gencount) > 0 ||
|
|
(long)(attr_gencount - nfs_read_attr_generation_counter()) > 0;
|
|
}
|
|
|
|
/**
|
|
* nfs_inode_attrs_cmp_monotonic - compare attributes
|
|
* @fattr: attributes
|
|
* @inode: pointer to inode
|
|
*
|
|
* Attempt to divine whether or not an RPC call reply carrying stale
|
|
* attributes got scheduled after another call carrying updated ones.
|
|
*
|
|
* We assume that the server observes monotonic semantics for
|
|
* the change attribute, so a larger value means that the attributes in
|
|
* @fattr are more recent, in which case the function returns the
|
|
* value '1'.
|
|
* A return value of '0' indicates no measurable change
|
|
* A return value of '-1' means that the attributes in @inode are
|
|
* more recent.
|
|
*/
|
|
static int nfs_inode_attrs_cmp_monotonic(const struct nfs_fattr *fattr,
|
|
const struct inode *inode)
|
|
{
|
|
s64 diff = fattr->change_attr - inode_peek_iversion_raw(inode);
|
|
if (diff > 0)
|
|
return 1;
|
|
return diff == 0 ? 0 : -1;
|
|
}
|
|
|
|
/**
|
|
* nfs_inode_attrs_cmp_strict_monotonic - compare attributes
|
|
* @fattr: attributes
|
|
* @inode: pointer to inode
|
|
*
|
|
* Attempt to divine whether or not an RPC call reply carrying stale
|
|
* attributes got scheduled after another call carrying updated ones.
|
|
*
|
|
* We assume that the server observes strictly monotonic semantics for
|
|
* the change attribute, so a larger value means that the attributes in
|
|
* @fattr are more recent, in which case the function returns the
|
|
* value '1'.
|
|
* A return value of '-1' means that the attributes in @inode are
|
|
* more recent or unchanged.
|
|
*/
|
|
static int nfs_inode_attrs_cmp_strict_monotonic(const struct nfs_fattr *fattr,
|
|
const struct inode *inode)
|
|
{
|
|
return nfs_inode_attrs_cmp_monotonic(fattr, inode) > 0 ? 1 : -1;
|
|
}
|
|
|
|
/**
|
|
* nfs_inode_attrs_cmp - compare attributes
|
|
* @fattr: attributes
|
|
* @inode: pointer to inode
|
|
*
|
|
* This function returns '1' if it thinks the attributes in @fattr are
|
|
* more recent than the ones cached in @inode. It returns '-1' if
|
|
* the attributes in @inode are more recent than the ones in @fattr,
|
|
* and it returns 0 if not sure.
|
|
*/
|
|
static int nfs_inode_attrs_cmp(const struct nfs_fattr *fattr,
|
|
const struct inode *inode)
|
|
{
|
|
if (nfs_inode_attrs_cmp_generic(fattr, inode) > 0)
|
|
return 1;
|
|
switch (NFS_SERVER(inode)->change_attr_type) {
|
|
case NFS4_CHANGE_TYPE_IS_UNDEFINED:
|
|
break;
|
|
case NFS4_CHANGE_TYPE_IS_TIME_METADATA:
|
|
if (!(fattr->valid & NFS_ATTR_FATTR_CHANGE))
|
|
break;
|
|
return nfs_inode_attrs_cmp_monotonic(fattr, inode);
|
|
default:
|
|
if (!(fattr->valid & NFS_ATTR_FATTR_CHANGE))
|
|
break;
|
|
return nfs_inode_attrs_cmp_strict_monotonic(fattr, inode);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* nfs_inode_finish_partial_attr_update - complete a previous inode update
|
|
* @fattr: attributes
|
|
* @inode: pointer to inode
|
|
*
|
|
* Returns '1' if the last attribute update left the inode cached
|
|
* attributes in a partially unrevalidated state, and @fattr
|
|
* matches the change attribute of that partial update.
|
|
* Otherwise returns '0'.
|
|
*/
|
|
static int nfs_inode_finish_partial_attr_update(const struct nfs_fattr *fattr,
|
|
const struct inode *inode)
|
|
{
|
|
const unsigned long check_valid =
|
|
NFS_INO_INVALID_ATIME | NFS_INO_INVALID_CTIME |
|
|
NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE |
|
|
NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_OTHER |
|
|
NFS_INO_INVALID_NLINK;
|
|
unsigned long cache_validity = NFS_I(inode)->cache_validity;
|
|
enum nfs4_change_attr_type ctype = NFS_SERVER(inode)->change_attr_type;
|
|
|
|
if (ctype != NFS4_CHANGE_TYPE_IS_UNDEFINED &&
|
|
!(cache_validity & NFS_INO_INVALID_CHANGE) &&
|
|
(cache_validity & check_valid) != 0 &&
|
|
(fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 &&
|
|
nfs_inode_attrs_cmp_monotonic(fattr, inode) == 0)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
static int nfs_refresh_inode_locked(struct inode *inode,
|
|
struct nfs_fattr *fattr)
|
|
{
|
|
int attr_cmp = nfs_inode_attrs_cmp(fattr, inode);
|
|
int ret = 0;
|
|
|
|
trace_nfs_refresh_inode_enter(inode);
|
|
|
|
if (attr_cmp > 0 || nfs_inode_finish_partial_attr_update(fattr, inode))
|
|
ret = nfs_update_inode(inode, fattr);
|
|
else if (attr_cmp == 0)
|
|
ret = nfs_check_inode_attributes(inode, fattr);
|
|
|
|
trace_nfs_refresh_inode_exit(inode, ret);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* nfs_refresh_inode - try to update the inode attribute cache
|
|
* @inode: pointer to inode
|
|
* @fattr: updated attributes
|
|
*
|
|
* Check that an RPC call that returned attributes has not overlapped with
|
|
* other recent updates of the inode metadata, then decide whether it is
|
|
* safe to do a full update of the inode attributes, or whether just to
|
|
* call nfs_check_inode_attributes.
|
|
*/
|
|
int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
int status;
|
|
|
|
if ((fattr->valid & NFS_ATTR_FATTR) == 0)
|
|
return 0;
|
|
spin_lock(&inode->i_lock);
|
|
status = nfs_refresh_inode_locked(inode, fattr);
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
return status;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_refresh_inode);
|
|
|
|
static int nfs_post_op_update_inode_locked(struct inode *inode,
|
|
struct nfs_fattr *fattr, unsigned int invalid)
|
|
{
|
|
if (S_ISDIR(inode->i_mode))
|
|
invalid |= NFS_INO_INVALID_DATA;
|
|
nfs_set_cache_invalid(inode, invalid);
|
|
if ((fattr->valid & NFS_ATTR_FATTR) == 0)
|
|
return 0;
|
|
return nfs_refresh_inode_locked(inode, fattr);
|
|
}
|
|
|
|
/**
|
|
* nfs_post_op_update_inode - try to update the inode attribute cache
|
|
* @inode: pointer to inode
|
|
* @fattr: updated attributes
|
|
*
|
|
* After an operation that has changed the inode metadata, mark the
|
|
* attribute cache as being invalid, then try to update it.
|
|
*
|
|
* NB: if the server didn't return any post op attributes, this
|
|
* function will force the retrieval of attributes before the next
|
|
* NFS request. Thus it should be used only for operations that
|
|
* are expected to change one or more attributes, to avoid
|
|
* unnecessary NFS requests and trips through nfs_update_inode().
|
|
*/
|
|
int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
int status;
|
|
|
|
spin_lock(&inode->i_lock);
|
|
nfs_fattr_set_barrier(fattr);
|
|
status = nfs_post_op_update_inode_locked(inode, fattr,
|
|
NFS_INO_INVALID_CHANGE
|
|
| NFS_INO_INVALID_CTIME
|
|
| NFS_INO_REVAL_FORCED);
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
return status;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_post_op_update_inode);
|
|
|
|
/**
|
|
* nfs_post_op_update_inode_force_wcc_locked - update the inode attribute cache
|
|
* @inode: pointer to inode
|
|
* @fattr: updated attributes
|
|
*
|
|
* After an operation that has changed the inode metadata, mark the
|
|
* attribute cache as being invalid, then try to update it. Fake up
|
|
* weak cache consistency data, if none exist.
|
|
*
|
|
* This function is mainly designed to be used by the ->write_done() functions.
|
|
*/
|
|
int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
int attr_cmp = nfs_inode_attrs_cmp(fattr, inode);
|
|
int status;
|
|
|
|
/* Don't do a WCC update if these attributes are already stale */
|
|
if (attr_cmp < 0)
|
|
return 0;
|
|
if ((fattr->valid & NFS_ATTR_FATTR) == 0 || !attr_cmp) {
|
|
fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE
|
|
| NFS_ATTR_FATTR_PRESIZE
|
|
| NFS_ATTR_FATTR_PREMTIME
|
|
| NFS_ATTR_FATTR_PRECTIME);
|
|
goto out_noforce;
|
|
}
|
|
if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 &&
|
|
(fattr->valid & NFS_ATTR_FATTR_PRECHANGE) == 0) {
|
|
fattr->pre_change_attr = inode_peek_iversion_raw(inode);
|
|
fattr->valid |= NFS_ATTR_FATTR_PRECHANGE;
|
|
}
|
|
if ((fattr->valid & NFS_ATTR_FATTR_CTIME) != 0 &&
|
|
(fattr->valid & NFS_ATTR_FATTR_PRECTIME) == 0) {
|
|
fattr->pre_ctime = inode->i_ctime;
|
|
fattr->valid |= NFS_ATTR_FATTR_PRECTIME;
|
|
}
|
|
if ((fattr->valid & NFS_ATTR_FATTR_MTIME) != 0 &&
|
|
(fattr->valid & NFS_ATTR_FATTR_PREMTIME) == 0) {
|
|
fattr->pre_mtime = inode->i_mtime;
|
|
fattr->valid |= NFS_ATTR_FATTR_PREMTIME;
|
|
}
|
|
if ((fattr->valid & NFS_ATTR_FATTR_SIZE) != 0 &&
|
|
(fattr->valid & NFS_ATTR_FATTR_PRESIZE) == 0) {
|
|
fattr->pre_size = i_size_read(inode);
|
|
fattr->valid |= NFS_ATTR_FATTR_PRESIZE;
|
|
}
|
|
out_noforce:
|
|
status = nfs_post_op_update_inode_locked(inode, fattr,
|
|
NFS_INO_INVALID_CHANGE
|
|
| NFS_INO_INVALID_CTIME
|
|
| NFS_INO_INVALID_MTIME
|
|
| NFS_INO_INVALID_BLOCKS);
|
|
return status;
|
|
}
|
|
|
|
/**
|
|
* nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
|
|
* @inode: pointer to inode
|
|
* @fattr: updated attributes
|
|
*
|
|
* After an operation that has changed the inode metadata, mark the
|
|
* attribute cache as being invalid, then try to update it. Fake up
|
|
* weak cache consistency data, if none exist.
|
|
*
|
|
* This function is mainly designed to be used by the ->write_done() functions.
|
|
*/
|
|
int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
int status;
|
|
|
|
spin_lock(&inode->i_lock);
|
|
nfs_fattr_set_barrier(fattr);
|
|
status = nfs_post_op_update_inode_force_wcc_locked(inode, fattr);
|
|
spin_unlock(&inode->i_lock);
|
|
return status;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc);
|
|
|
|
|
|
/*
|
|
* Many nfs protocol calls return the new file attributes after
|
|
* an operation. Here we update the inode to reflect the state
|
|
* of the server's inode.
|
|
*
|
|
* This is a bit tricky because we have to make sure all dirty pages
|
|
* have been sent off to the server before calling invalidate_inode_pages.
|
|
* To make sure no other process adds more write requests while we try
|
|
* our best to flush them, we make them sleep during the attribute refresh.
|
|
*
|
|
* A very similar scenario holds for the dir cache.
|
|
*/
|
|
static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
|
|
{
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
loff_t cur_isize, new_isize;
|
|
u64 fattr_supported = server->fattr_valid;
|
|
unsigned long invalid = 0;
|
|
unsigned long now = jiffies;
|
|
unsigned long save_cache_validity;
|
|
bool have_writers = nfs_file_has_buffered_writers(nfsi);
|
|
bool cache_revalidated = true;
|
|
bool attr_changed = false;
|
|
bool have_delegation;
|
|
|
|
dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
|
|
__func__, inode->i_sb->s_id, inode->i_ino,
|
|
nfs_display_fhandle_hash(NFS_FH(inode)),
|
|
atomic_read(&inode->i_count), fattr->valid);
|
|
|
|
if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
|
|
/* Only a mounted-on-fileid? Just exit */
|
|
if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
|
|
return 0;
|
|
/* Has the inode gone and changed behind our back? */
|
|
} else if (nfsi->fileid != fattr->fileid) {
|
|
/* Is this perhaps the mounted-on fileid? */
|
|
if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) &&
|
|
nfsi->fileid == fattr->mounted_on_fileid)
|
|
return 0;
|
|
printk(KERN_ERR "NFS: server %s error: fileid changed\n"
|
|
"fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
|
|
NFS_SERVER(inode)->nfs_client->cl_hostname,
|
|
inode->i_sb->s_id, (long long)nfsi->fileid,
|
|
(long long)fattr->fileid);
|
|
goto out_err;
|
|
}
|
|
|
|
/*
|
|
* Make sure the inode's type hasn't changed.
|
|
*/
|
|
if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode)) {
|
|
/*
|
|
* Big trouble! The inode has become a different object.
|
|
*/
|
|
printk(KERN_DEBUG "NFS: %s: inode %lu mode changed, %07o to %07o\n",
|
|
__func__, inode->i_ino, inode->i_mode, fattr->mode);
|
|
goto out_err;
|
|
}
|
|
|
|
/* Update the fsid? */
|
|
if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
|
|
!nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
|
|
!IS_AUTOMOUNT(inode))
|
|
server->fsid = fattr->fsid;
|
|
|
|
/* Save the delegation state before clearing cache_validity */
|
|
have_delegation = nfs_have_delegated_attributes(inode);
|
|
|
|
/*
|
|
* Update the read time so we don't revalidate too often.
|
|
*/
|
|
nfsi->read_cache_jiffies = fattr->time_start;
|
|
|
|
save_cache_validity = nfsi->cache_validity;
|
|
nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
|
|
| NFS_INO_INVALID_ATIME
|
|
| NFS_INO_REVAL_FORCED
|
|
| NFS_INO_INVALID_BLOCKS);
|
|
|
|
/* Do atomic weak cache consistency updates */
|
|
nfs_wcc_update_inode(inode, fattr);
|
|
|
|
if (pnfs_layoutcommit_outstanding(inode)) {
|
|
nfsi->cache_validity |=
|
|
save_cache_validity &
|
|
(NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME |
|
|
NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE |
|
|
NFS_INO_INVALID_BLOCKS);
|
|
cache_revalidated = false;
|
|
}
|
|
|
|
/* More cache consistency checks */
|
|
if (fattr->valid & NFS_ATTR_FATTR_CHANGE) {
|
|
if (!inode_eq_iversion_raw(inode, fattr->change_attr)) {
|
|
/* Could it be a race with writeback? */
|
|
if (!(have_writers || have_delegation)) {
|
|
invalid |= NFS_INO_INVALID_DATA
|
|
| NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL
|
|
| NFS_INO_INVALID_XATTR;
|
|
/* Force revalidate of all attributes */
|
|
save_cache_validity |= NFS_INO_INVALID_CTIME
|
|
| NFS_INO_INVALID_MTIME
|
|
| NFS_INO_INVALID_SIZE
|
|
| NFS_INO_INVALID_BLOCKS
|
|
| NFS_INO_INVALID_NLINK
|
|
| NFS_INO_INVALID_MODE
|
|
| NFS_INO_INVALID_OTHER;
|
|
if (S_ISDIR(inode->i_mode))
|
|
nfs_force_lookup_revalidate(inode);
|
|
attr_changed = true;
|
|
dprintk("NFS: change_attr change on server for file %s/%ld\n",
|
|
inode->i_sb->s_id,
|
|
inode->i_ino);
|
|
} else if (!have_delegation)
|
|
nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER;
|
|
inode_set_iversion_raw(inode, fattr->change_attr);
|
|
}
|
|
} else {
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_CHANGE;
|
|
if (!have_delegation ||
|
|
(nfsi->cache_validity & NFS_INO_INVALID_CHANGE) != 0)
|
|
cache_revalidated = false;
|
|
}
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_MTIME)
|
|
inode->i_mtime = fattr->mtime;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_MTIME)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_MTIME;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_CTIME)
|
|
inode->i_ctime = fattr->ctime;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_CTIME)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_CTIME;
|
|
|
|
/* Check if our cached file size is stale */
|
|
if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
|
|
new_isize = nfs_size_to_loff_t(fattr->size);
|
|
cur_isize = i_size_read(inode);
|
|
if (new_isize != cur_isize && !have_delegation) {
|
|
/* Do we perhaps have any outstanding writes, or has
|
|
* the file grown beyond our last write? */
|
|
if (!nfs_have_writebacks(inode) || new_isize > cur_isize) {
|
|
i_size_write(inode, new_isize);
|
|
if (!have_writers)
|
|
invalid |= NFS_INO_INVALID_DATA;
|
|
}
|
|
dprintk("NFS: isize change on server for file %s/%ld "
|
|
"(%Ld to %Ld)\n",
|
|
inode->i_sb->s_id,
|
|
inode->i_ino,
|
|
(long long)cur_isize,
|
|
(long long)new_isize);
|
|
}
|
|
if (new_isize == 0 &&
|
|
!(fattr->valid & (NFS_ATTR_FATTR_SPACE_USED |
|
|
NFS_ATTR_FATTR_BLOCKS_USED))) {
|
|
fattr->du.nfs3.used = 0;
|
|
fattr->valid |= NFS_ATTR_FATTR_SPACE_USED;
|
|
}
|
|
} else
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_SIZE;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_ATIME)
|
|
inode->i_atime = fattr->atime;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_ATIME)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_ATIME;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_MODE) {
|
|
if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
|
|
umode_t newmode = inode->i_mode & S_IFMT;
|
|
newmode |= fattr->mode & S_IALLUGO;
|
|
inode->i_mode = newmode;
|
|
invalid |= NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL;
|
|
}
|
|
} else if (fattr_supported & NFS_ATTR_FATTR_MODE)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_MODE;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
|
|
if (!uid_eq(inode->i_uid, fattr->uid)) {
|
|
invalid |= NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL;
|
|
inode->i_uid = fattr->uid;
|
|
}
|
|
} else if (fattr_supported & NFS_ATTR_FATTR_OWNER)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_OTHER;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
|
|
if (!gid_eq(inode->i_gid, fattr->gid)) {
|
|
invalid |= NFS_INO_INVALID_ACCESS
|
|
| NFS_INO_INVALID_ACL;
|
|
inode->i_gid = fattr->gid;
|
|
}
|
|
} else if (fattr_supported & NFS_ATTR_FATTR_GROUP)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_OTHER;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
|
|
if (inode->i_nlink != fattr->nlink) {
|
|
if (S_ISDIR(inode->i_mode))
|
|
invalid |= NFS_INO_INVALID_DATA;
|
|
set_nlink(inode, fattr->nlink);
|
|
}
|
|
} else if (fattr_supported & NFS_ATTR_FATTR_NLINK)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_NLINK;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
|
|
/*
|
|
* report the blocks in 512byte units
|
|
*/
|
|
inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
|
|
} else if (fattr_supported & NFS_ATTR_FATTR_SPACE_USED)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_BLOCKS;
|
|
|
|
if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
|
|
inode->i_blocks = fattr->du.nfs2.blocks;
|
|
else if (fattr_supported & NFS_ATTR_FATTR_BLOCKS_USED)
|
|
nfsi->cache_validity |=
|
|
save_cache_validity & NFS_INO_INVALID_BLOCKS;
|
|
|
|
/* Update attrtimeo value if we're out of the unstable period */
|
|
if (attr_changed) {
|
|
nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
|
|
nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
|
|
nfsi->attrtimeo_timestamp = now;
|
|
/* Set barrier to be more recent than all outstanding updates */
|
|
nfsi->attr_gencount = nfs_inc_attr_generation_counter();
|
|
} else {
|
|
if (cache_revalidated) {
|
|
if (!time_in_range_open(now, nfsi->attrtimeo_timestamp,
|
|
nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
|
|
nfsi->attrtimeo <<= 1;
|
|
if (nfsi->attrtimeo > NFS_MAXATTRTIMEO(inode))
|
|
nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
|
|
}
|
|
nfsi->attrtimeo_timestamp = now;
|
|
}
|
|
/* Set the barrier to be more recent than this fattr */
|
|
if ((long)(fattr->gencount - nfsi->attr_gencount) > 0)
|
|
nfsi->attr_gencount = fattr->gencount;
|
|
}
|
|
|
|
/* Don't invalidate the data if we were to blame */
|
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
|
|
|| S_ISLNK(inode->i_mode)))
|
|
invalid &= ~NFS_INO_INVALID_DATA;
|
|
nfs_set_cache_invalid(inode, invalid);
|
|
|
|
return 0;
|
|
out_err:
|
|
/*
|
|
* No need to worry about unhashing the dentry, as the
|
|
* lookup validation will know that the inode is bad.
|
|
* (But we fall through to invalidate the caches.)
|
|
*/
|
|
nfs_set_inode_stale_locked(inode);
|
|
return -ESTALE;
|
|
}
|
|
|
|
struct inode *nfs_alloc_inode(struct super_block *sb)
|
|
{
|
|
struct nfs_inode *nfsi;
|
|
nfsi = kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL);
|
|
if (!nfsi)
|
|
return NULL;
|
|
nfsi->flags = 0UL;
|
|
nfsi->cache_validity = 0UL;
|
|
#if IS_ENABLED(CONFIG_NFS_V4)
|
|
nfsi->nfs4_acl = NULL;
|
|
#endif /* CONFIG_NFS_V4 */
|
|
#ifdef CONFIG_NFS_V4_2
|
|
nfsi->xattr_cache = NULL;
|
|
#endif
|
|
return &nfsi->vfs_inode;
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_alloc_inode);
|
|
|
|
void nfs_free_inode(struct inode *inode)
|
|
{
|
|
kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
|
|
}
|
|
EXPORT_SYMBOL_GPL(nfs_free_inode);
|
|
|
|
static inline void nfs4_init_once(struct nfs_inode *nfsi)
|
|
{
|
|
#if IS_ENABLED(CONFIG_NFS_V4)
|
|
INIT_LIST_HEAD(&nfsi->open_states);
|
|
nfsi->delegation = NULL;
|
|
init_rwsem(&nfsi->rwsem);
|
|
nfsi->layout = NULL;
|
|
#endif
|
|
}
|
|
|
|
static void init_once(void *foo)
|
|
{
|
|
struct nfs_inode *nfsi = (struct nfs_inode *) foo;
|
|
|
|
inode_init_once(&nfsi->vfs_inode);
|
|
INIT_LIST_HEAD(&nfsi->open_files);
|
|
INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
|
|
INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
|
|
INIT_LIST_HEAD(&nfsi->commit_info.list);
|
|
atomic_long_set(&nfsi->nrequests, 0);
|
|
atomic_long_set(&nfsi->commit_info.ncommit, 0);
|
|
atomic_set(&nfsi->commit_info.rpcs_out, 0);
|
|
init_rwsem(&nfsi->rmdir_sem);
|
|
mutex_init(&nfsi->commit_mutex);
|
|
nfs4_init_once(nfsi);
|
|
nfsi->cache_change_attribute = 0;
|
|
}
|
|
|
|
static int __init nfs_init_inodecache(void)
|
|
{
|
|
nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
|
|
sizeof(struct nfs_inode),
|
|
0, (SLAB_RECLAIM_ACCOUNT|
|
|
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
|
init_once);
|
|
if (nfs_inode_cachep == NULL)
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void nfs_destroy_inodecache(void)
|
|
{
|
|
/*
|
|
* Make sure all delayed rcu free inodes are flushed before we
|
|
* destroy cache.
|
|
*/
|
|
rcu_barrier();
|
|
kmem_cache_destroy(nfs_inode_cachep);
|
|
}
|
|
|
|
struct workqueue_struct *nfsiod_workqueue;
|
|
EXPORT_SYMBOL_GPL(nfsiod_workqueue);
|
|
|
|
/*
|
|
* start up the nfsiod workqueue
|
|
*/
|
|
static int nfsiod_start(void)
|
|
{
|
|
struct workqueue_struct *wq;
|
|
dprintk("RPC: creating workqueue nfsiod\n");
|
|
wq = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM | WQ_UNBOUND, 0);
|
|
if (wq == NULL)
|
|
return -ENOMEM;
|
|
nfsiod_workqueue = wq;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Destroy the nfsiod workqueue
|
|
*/
|
|
static void nfsiod_stop(void)
|
|
{
|
|
struct workqueue_struct *wq;
|
|
|
|
wq = nfsiod_workqueue;
|
|
if (wq == NULL)
|
|
return;
|
|
nfsiod_workqueue = NULL;
|
|
destroy_workqueue(wq);
|
|
}
|
|
|
|
unsigned int nfs_net_id;
|
|
EXPORT_SYMBOL_GPL(nfs_net_id);
|
|
|
|
static int nfs_net_init(struct net *net)
|
|
{
|
|
nfs_clients_init(net);
|
|
return nfs_fs_proc_net_init(net);
|
|
}
|
|
|
|
static void nfs_net_exit(struct net *net)
|
|
{
|
|
nfs_fs_proc_net_exit(net);
|
|
nfs_clients_exit(net);
|
|
}
|
|
|
|
static struct pernet_operations nfs_net_ops = {
|
|
.init = nfs_net_init,
|
|
.exit = nfs_net_exit,
|
|
.id = &nfs_net_id,
|
|
.size = sizeof(struct nfs_net),
|
|
};
|
|
|
|
/*
|
|
* Initialize NFS
|
|
*/
|
|
static int __init init_nfs_fs(void)
|
|
{
|
|
int err;
|
|
|
|
err = nfs_sysfs_init();
|
|
if (err < 0)
|
|
goto out10;
|
|
|
|
err = register_pernet_subsys(&nfs_net_ops);
|
|
if (err < 0)
|
|
goto out9;
|
|
|
|
err = nfs_fscache_register();
|
|
if (err < 0)
|
|
goto out8;
|
|
|
|
err = nfsiod_start();
|
|
if (err)
|
|
goto out7;
|
|
|
|
err = nfs_fs_proc_init();
|
|
if (err)
|
|
goto out6;
|
|
|
|
err = nfs_init_nfspagecache();
|
|
if (err)
|
|
goto out5;
|
|
|
|
err = nfs_init_inodecache();
|
|
if (err)
|
|
goto out4;
|
|
|
|
err = nfs_init_readpagecache();
|
|
if (err)
|
|
goto out3;
|
|
|
|
err = nfs_init_writepagecache();
|
|
if (err)
|
|
goto out2;
|
|
|
|
err = nfs_init_directcache();
|
|
if (err)
|
|
goto out1;
|
|
|
|
rpc_proc_register(&init_net, &nfs_rpcstat);
|
|
|
|
err = register_nfs_fs();
|
|
if (err)
|
|
goto out0;
|
|
|
|
return 0;
|
|
out0:
|
|
rpc_proc_unregister(&init_net, "nfs");
|
|
nfs_destroy_directcache();
|
|
out1:
|
|
nfs_destroy_writepagecache();
|
|
out2:
|
|
nfs_destroy_readpagecache();
|
|
out3:
|
|
nfs_destroy_inodecache();
|
|
out4:
|
|
nfs_destroy_nfspagecache();
|
|
out5:
|
|
nfs_fs_proc_exit();
|
|
out6:
|
|
nfsiod_stop();
|
|
out7:
|
|
nfs_fscache_unregister();
|
|
out8:
|
|
unregister_pernet_subsys(&nfs_net_ops);
|
|
out9:
|
|
nfs_sysfs_exit();
|
|
out10:
|
|
return err;
|
|
}
|
|
|
|
static void __exit exit_nfs_fs(void)
|
|
{
|
|
nfs_destroy_directcache();
|
|
nfs_destroy_writepagecache();
|
|
nfs_destroy_readpagecache();
|
|
nfs_destroy_inodecache();
|
|
nfs_destroy_nfspagecache();
|
|
nfs_fscache_unregister();
|
|
unregister_pernet_subsys(&nfs_net_ops);
|
|
rpc_proc_unregister(&init_net, "nfs");
|
|
unregister_nfs_fs();
|
|
nfs_fs_proc_exit();
|
|
nfsiod_stop();
|
|
nfs_sysfs_exit();
|
|
}
|
|
|
|
/* Not quite true; I just maintain it */
|
|
MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
|
|
module_param(enable_ino64, bool, 0644);
|
|
|
|
module_init(init_nfs_fs)
|
|
module_exit(exit_nfs_fs)
|