Files
kernel_google_msm-4.9/fs/block_dev.c
lucaswei 3745a45546 Merge android-4.9-q (4.9.241) into android-msm-pixel-4.9-rvc-lts
Merge 4.9.241 into android-4.9-q
Linux 4.9.241
  * usb: gadget: f_ncm: allow using NCM in SuperSpeed Plus gadgets.
      drivers/usb/gadget/function/f_ncm.c
  * eeprom: at25: set minimum read/write access stride to 1
      drivers/misc/eeprom/at25.c
  * USB: cdc-wdm: Make wdm_flush() interruptible and add wdm_fsync().
      drivers/usb/class/cdc-wdm.c
  * usb: cdc-acm: add quirk to blacklist ETAS ES58X devices
      drivers/usb/class/cdc-acm.c
  * net: korina: cast KSEG0 address to pointer in kfree
      drivers/net/ethernet/korina.c
  * ath10k: check idx validity in __ath10k_htt_rx_ring_fill_n()
      drivers/net/wireless/ath/ath10k/htt_rx.c
  * usb: core: Solve race condition in anchor cleanup functions
      drivers/usb/core/urb.c
  * brcm80211: fix possible memleak in brcmf_proto_msgbuf_attach
      drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
  * reiserfs: Fix memory leak in reiserfs_parse_options()
      fs/reiserfs/super.c
  * ipvs: Fix uninit-value in do_ip_vs_set_ctl()
      net/netfilter/ipvs/ip_vs_ctl.c
  * tty: ipwireless: fix error handling
      drivers/tty/ipwireless/network.c
      drivers/tty/ipwireless/tty.c
  * Fix use after free in get_capset_info callback.
      drivers/gpu/drm/virtio/virtgpu_kms.c
      drivers/gpu/drm/virtio/virtgpu_vq.c
  * rtl8xxxu: prevent potential memory leak
      drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
  * brcmsmac: fix memory leak in wlc_phy_attach_lcnphy
      drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c
  * scsi: ibmvfc: Fix error return in ibmvfc_probe()
      drivers/scsi/ibmvscsi/ibmvfc.c
  * Bluetooth: Only mark socket zapped after unlocking
      net/bluetooth/l2cap_sock.c
  * usb: ohci: Default to per-port over-current protection
      drivers/usb/host/ohci-hcd.c
  * xfs: make sure the rt allocator doesn't run off the end
      fs/xfs/xfs_rtalloc.c
  * reiserfs: only call unlock_new_inode() if I_NEW
      fs/reiserfs/inode.c
  * misc: rtsx: Fix memory leak in rtsx_pci_probe
      drivers/mfd/rtsx_pcr.c
  * ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()
      drivers/net/wireless/ath/ath9k/hif_usb.c
  * USB: cdc-acm: handle broken union descriptors
      drivers/usb/class/cdc-acm.c
  * udf: Avoid accessing uninitialized data on failed inode read
      fs/udf/inode.c
  * udf: Limit sparing table size
      fs/udf/super.c
  * usb: gadget: function: printer: fix use-after-free in __lock_acquire
      drivers/usb/gadget/function/f_printer.c
  * misc: vop: add round_up(x,4) for vring_size to avoid kernel panic
      drivers/misc/mic/vop/vop_main.c
      drivers/misc/mic/vop/vop_vringh.c
      samples/mic/mpssd/mpssd.c
  * mic: vop: copy data to kernel space then write to io memory
      drivers/misc/mic/vop/vop_vringh.c
  * scsi: target: core: Add CONTROL field for trace events
      include/scsi/scsi_common.h
      include/trace/events/target.h
  * scsi: mvumi: Fix error return in mvumi_io_attach()
      drivers/scsi/mvumi.c
  * PM: hibernate: remove the bogus call to get_gendisk() in software_resume()
      kernel/power/hibernate.c
  * ntfs: add check for mft record size in superblock
      fs/ntfs/inode.c
  * fs: dlm: fix configfs memory leak
      fs/dlm/config.c
  * media: saa7134: avoid a shift overflow
      drivers/media/pci/saa7134/saa7134-tvaudio.c
  * mmc: sdio: Check for CISTPL_VERS_1 buffer size
      drivers/mmc/core/sdio_cis.c
  * media: uvcvideo: Ensure all probed info is returned to v4l2
      drivers/media/usb/uvc/uvc_v4l2.c
  * media: media/pci: prevent memory leak in bttv_probe
      drivers/media/pci/bt8xx/bttv-driver.c
  * media: bdisp: Fix runtime PM imbalance on error
      drivers/media/platform/sti/bdisp/bdisp-v4l2.c
  * media: platform: sti: hva: Fix runtime PM imbalance on error
      drivers/media/platform/sti/hva/hva-hw.c
  * media: platform: s3c-camif: Fix runtime PM imbalance on error
      drivers/media/platform/s3c-camif/camif-core.c
  * media: vsp1: Fix runtime PM imbalance on error
      drivers/media/platform/vsp1/vsp1_drv.c
  * media: exynos4-is: Fix a reference count leak
      drivers/media/platform/exynos4-is/mipi-csis.c
  * media: exynos4-is: Fix a reference count leak due to pm_runtime_get_sync
      drivers/media/platform/exynos4-is/media-dev.c
  * media: exynos4-is: Fix several reference count leaks due to pm_runtime_get_sync
      drivers/media/platform/exynos4-is/fimc-isp.c
      drivers/media/platform/exynos4-is/fimc-lite.c
  * media: ati_remote: sanity check for both endpoints
      drivers/media/rc/ati_remote.c
  * media: firewire: fix memory leak
      drivers/media/firewire/firedtv-fw.c
  * crypto: ccp - fix error handling
      drivers/crypto/ccp/ccp-ops.c
  * NTB: hw: amd: fix an issue about leak system resources
      drivers/ntb/hw/amd/ntb_hw_amd.c
  * nvmet: fix uninitialized work for zero kato
      drivers/nvme/target/core.c
  * powerpc/powernv/dump: Fix race while processing OPAL dump
      arch/powerpc/platforms/powernv/opal-dump.c
  * arm64: dts: zynqmp: Remove additional compatible string for i2c IPs
      arch/arm64/boot/dts/xilinx/zynqmp.dtsi
  * arm64: dts: qcom: msm8916: Fix MDP/DSI interrupts
      arch/arm64/boot/dts/qcom/msm8916.dtsi
  * memory: fsl-corenet-cf: Fix handling of platform_get_irq() error
      drivers/memory/fsl-corenet-cf.c
  * memory: omap-gpmc: Fix a couple off by ones
      drivers/memory/omap-gpmc.c
  * KVM: x86: emulating RDPID failure shall return #UD rather than #GP
      arch/x86/kvm/emulate.c
  * Input: sun4i-ps2 - fix handling of platform_get_irq() error
      drivers/input/serio/sun4i-ps2.c
  * Input: twl4030_keypad - fix handling of platform_get_irq() error
      drivers/input/keyboard/twl4030_keypad.c
  * Input: omap4-keypad - fix handling of platform_get_irq() error
      drivers/input/keyboard/omap4-keypad.c
  * Input: ep93xx_keypad - fix handling of platform_get_irq() error
      drivers/input/keyboard/ep93xx_keypad.c
  * Input: imx6ul_tsc - clean up some errors in imx6ul_tsc_resume()
      drivers/input/touchscreen/imx6ul_tsc.c
  * vfio/pci: Clear token on bypass registration failure
      drivers/vfio/pci/vfio_pci_intrs.c
  * clk: bcm2835: add missing release if devm_clk_hw_register fails
      drivers/clk/bcm/clk-bcm2835.c
  * clk: at91: clk-main: update key before writing AT91_CKGR_MOR
      drivers/clk/at91/clk-main.c
  * rapidio: fix the missed put_device() for rio_mport_add_riodev
      drivers/rapidio/devices/rio_mport_cdev.c
  * rapidio: fix error handling path
      drivers/rapidio/devices/rio_mport_cdev.c
  * lib/crc32.c: fix trivial typo in preprocessor condition
      lib/crc32.c
  * IB/rdmavt: Fix sizeof mismatch
      drivers/infiniband/sw/rdmavt/vt.c
  * cpufreq: powernv: Fix frame-size-overflow in powernv_cpufreq_reboot_notifier
      drivers/cpufreq/powernv-cpufreq.c
  * powerpc/perf/hv-gpci: Fix starting index value
      arch/powerpc/perf/hv-gpci-requests.h
  * powerpc/perf: Exclude pmc5/6 from the irrelevant PMU group constraints
      arch/powerpc/perf/isa207-common.c
  * overflow: Include header file with SIZE_MAX declaration
      include/linux/overflow.h
  * kdb: Fix pager search for multi-line strings
      kernel/debug/kdb/kdb_io.c
  * RDMA/hns: Set the unsupported wr opcode
      drivers/infiniband/hw/hns/hns_roce_hw_v1.c
  * perf intel-pt: Fix "context_switch event has no tid" error
      tools/perf/util/intel-pt.c
  * powerpc/tau: Disable TAU between measurements
      arch/powerpc/kernel/tau_6xx.c
      arch/powerpc/platforms/Kconfig
  * powerpc/tau: Remove duplicated set_thresholds() call
      arch/powerpc/kernel/tau_6xx.c
  * powerpc/tau: Use appropriate temperature sample interval
      arch/powerpc/include/asm/reg.h
      arch/powerpc/kernel/tau_6xx.c
  * RDMA/qedr: Fix use of uninitialized field
      drivers/infiniband/hw/qedr/main.c
  * ARM: 9007/1: l2c: fix prefetch bits init in L2X0_AUX_CTRL using DT values
      arch/arm/mm/cache-l2x0.c
  * mtd: mtdoops: Don't write panic data twice
      drivers/mtd/mtdoops.c
  * mtd: lpddr: fix excessive stack usage with clang
      drivers/mtd/lpddr/lpddr2_nvm.c
  * powerpc/icp-hv: Fix missing of_node_put() in success path
      arch/powerpc/sysdev/xics/icp-hv.c
  * powerpc/pseries: Fix missing of_node_put() in rng_init()
      arch/powerpc/platforms/pseries/rng.c
  * IB/mlx4: Adjust delayed work when a dup is observed
      drivers/infiniband/hw/mlx4/cm.c
  * IB/mlx4: Fix starvation in paravirt mux/demux
      drivers/infiniband/hw/mlx4/mad.c
      drivers/infiniband/hw/mlx4/mlx4_ib.h
  * net: korina: fix kfree of rx/tx descriptor array
      drivers/net/ethernet/korina.c
  * mwifiex: fix double free
      drivers/net/wireless/marvell/mwifiex/sdio.c
  * scsi: be2iscsi: Fix a theoretical leak in beiscsi_create_eqs()
      drivers/scsi/be2iscsi/be_main.c
  * nl80211: fix non-split wiphy information
      net/wireless/nl80211.c
  * usb: gadget: u_ether: enable qmult on SuperSpeed Plus as well
      drivers/usb/gadget/function/u_ether.c
  * usb: gadget: f_ncm: fix ncm_bitrate for SuperSpeed and above.
      drivers/usb/gadget/function/f_ncm.c
  * iwlwifi: mvm: split a print to avoid a WARNING in ROC
      drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
  * mfd: sm501: Fix leaks in probe()
      drivers/mfd/sm501.c
  * net: enic: Cure the enic api locking trainwreck
      drivers/net/ethernet/cisco/enic/enic.h
      drivers/net/ethernet/cisco/enic/enic_api.c
      drivers/net/ethernet/cisco/enic/enic_main.c
  * quota: clear padding in v2r1_mem2diskdqb()
      fs/quota/quota_v2.c
  * ALSA: seq: oss: Avoid mutex lock for a long-time ioctl
      sound/core/seq/oss/seq_oss.c
  * misc: mic: scif: Fix error handling path
      drivers/misc/mic/scif/scif_rma.c
  * ath6kl: wmi: prevent a shift wrapping bug in ath6kl_wmi_delete_pstream_cmd()
      drivers/net/wireless/ath/ath6kl/wmi.c
  * HID: roccat: add bounds checking in kone_sysfs_write_settings()
      drivers/hid/hid-roccat-kone.c
  * video: fbdev: sis: fix null ptr dereference
      drivers/video/fbdev/sis/init.c
  * video: fbdev: vga16fb: fix setting of pixclock because a pass-by-value error
      drivers/video/fbdev/vga16fb.c
  * drivers/virt/fsl_hypervisor: Fix error handling path
      drivers/virt/fsl_hypervisor.c
  * pty: do tty_flip_buffer_push without port->lock in pty_write
      drivers/tty/pty.c
  * tty: hvcs: Don't NULL tty->driver_data until hvcs_cleanup()
      drivers/tty/hvc/hvcs.c
  * tty: serial: earlycon dependency
      drivers/tty/serial/Kconfig
  * VMCI: check return value of get_user_pages_fast() for errors
      drivers/misc/vmw_vmci/vmci_queue_pair.c
  * backlight: sky81452-backlight: Fix refcount imbalance on error
      drivers/video/backlight/sky81452-backlight.c
  * scsi: csiostor: Fix wrong return value in csio_hw_prep_fw()
      drivers/scsi/csiostor/csio_hw.c
  * scsi: qla4xxx: Fix an error handling path in 'qla4xxx_get_host_stats()'
      drivers/scsi/qla4xxx/ql4_os.c
  * drm/gma500: fix error check
      drivers/gpu/drm/gma500/cdv_intel_dp.c
  * mwifiex: Do not use GFP_KERNEL in atomic context
      drivers/net/wireless/marvell/mwifiex/scan.c
  * ASoC: qcom: lpass-platform: fix memory leak
      sound/soc/qcom/lpass-platform.c
  * wcn36xx: Fix reported 802.11n rx_highest rate wcn3660/wcn3680
      drivers/net/wireless/ath/wcn36xx/main.c
  * ath9k: Fix potential out of bounds in ath9k_htc_txcompletion_cb()
      drivers/net/wireless/ath/ath9k/htc_hst.c
  * ath6kl: prevent potential array overflow in ath6kl_add_new_sta()
      drivers/net/wireless/ath/ath6kl/main.c
  * ath10k: provide survey info as accumulated data
      drivers/net/wireless/ath/ath10k/mac.c
  * regulator: resolve supply after creating regulator
      drivers/regulator/core.c
  * media: ti-vpe: Fix a missing check and reference count leak
      drivers/media/platform/ti-vpe/vpe.c
  * media: platform: fcp: Fix a reference count leak.
      drivers/media/platform/rcar-fcp.c
  * media: tc358743: initialize variable
      drivers/media/i2c/tc358743.c
  * crypto: omap-sham - fix digcnt register handling with export/import
      drivers/crypto/omap-sham.c
  * media: omap3isp: Fix memleak in isp_probe
      drivers/media/platform/omap3isp/isp.c
  * media: m5mols: Check function pointer in m5mols_sensor_power
      drivers/media/i2c/m5mols/m5mols_core.c
  * media: Revert "media: exynos4-is: Add missed check for pinctrl_lookup_state()"
      drivers/media/platform/exynos4-is/media-dev.c
  * crypto: ixp4xx - Fix the size used in a 'dma_free_coherent()' call
      drivers/crypto/ixp4xx_crypto.c
  * EDAC/i5100: Fix error handling order in i5100_init_one()
      drivers/edac/i5100_edac.c
  * crypto: algif_aead - Do not set MAY_BACKLOG on the async path
      crypto/algif_aead.c
  * ima: Don't ignore errors from crypto_shash_update()
      security/integrity/ima/ima_crypto.c
  * KVM: x86/mmu: Commit zap of remaining invalid pages when recovering lpages
      arch/x86/kvm/mmu.c
  * cifs: remove bogus debug code
      fs/cifs/asn1.c
  * icmp: randomize the global rate limiter
      Documentation/networking/ip-sysctl.txt
      net/ipv4/icmp.c
  * tcp: fix to update snd_wl1 in bulk receiver fast path
      net/ipv4/tcp_input.c
  * nfc: Ensure presence of NFC_ATTR_FIRMWARE_NAME attribute in nfc_genl_fw_download()
      net/nfc/netlink.c
  * net: hdlc_raw_eth: Clear the IFF_TX_SKB_SHARING flag after calling ether_setup
      drivers/net/wan/hdlc_raw_eth.c
  * net: hdlc: In hdlc_rcv, check to make sure dev is an HDLC device
      drivers/net/wan/hdlc.c
  * ALSA: bebob: potential info leak in hwdep_read()
      sound/firewire/bebob/bebob_hwdep.c
  * r8169: fix data corruption issue on RTL8402
      drivers/net/ethernet/realtek/r8169.c
  * net/ipv4: always honour route mtu during forwarding
      include/net/ip.h
  * tipc: fix the skb_unshare() in tipc_buf_append()
      net/tipc/msg.c
  * ibmveth: Identify ingress large send packets.
      drivers/net/ethernet/ibm/ibmveth.c
  * UPSTREAM: binder: fix UAF when releasing todo list
      drivers/android/binder.c
  * ANDROID: namespace'ify tcp_default_init_rwnd implementation
      include/net/netns/ipv4.h
      include/net/tcp.h
      net/ipv4/syncookies.c
      net/ipv4/sysctl_net_ipv4.c
      net/ipv4/tcp_input.c
      net/ipv4/tcp_ipv4.c
      net/ipv4/tcp_minisocks.c
      net/ipv4/tcp_output.c
      net/ipv6/syncookies.c
    Merge 4.9.240 into android-4.9-q
Linux 4.9.240
  * crypto: qat - check cipher length for aead AES-CBC-HMAC-SHA
      drivers/crypto/qat/qat_common/qat_algs.c
  * reiserfs: Fix oops during mount
      fs/reiserfs/xattr.c
  * reiserfs: Initialize inode keys properly
      fs/reiserfs/inode.c
  * USB: serial: ftdi_sio: add support for FreeCalypso JTAG+UART adapters
      drivers/usb/serial/ftdi_sio.c
      drivers/usb/serial/ftdi_sio_ids.h
  * USB: serial: pl2303: add device-id for HP GC device
      drivers/usb/serial/pl2303.c
      drivers/usb/serial/pl2303.h
  * staging: comedi: check validity of wMaxPacketSize of usb endpoints found
      drivers/staging/comedi/drivers/vmk80xx.c
  * USB: serial: option: Add Telit FT980-KS composition
      drivers/usb/serial/option.c
  * USB: serial: option: add Cellient MPL200 card
      drivers/usb/serial/option.c
  * media: usbtv: Fix refcounting mixup
      drivers/media/usb/usbtv/usbtv-core.c
  * Bluetooth: Disconnect if E0 is used for Level 4
      include/net/bluetooth/hci_core.h
      net/bluetooth/hci_conn.c
      net/bluetooth/hci_event.c
  * Bluetooth: Fix update of connection state in `hci_encrypt_cfm`
      include/net/bluetooth/hci_core.h
  * Bluetooth: Consolidate encryption handling in hci_encrypt_cfm
      include/net/bluetooth/hci_core.h
      net/bluetooth/hci_event.c
  * Bluetooth: fix kernel oops in store_pending_adv_report
      net/bluetooth/hci_event.c
  * Bluetooth: MGMT: Fix not checking if BT_HS is enabled
      net/bluetooth/mgmt.c
  * Bluetooth: L2CAP: Fix calling sk_filter on non-socket based channel
      include/net/bluetooth/l2cap.h
      net/bluetooth/l2cap_core.c
      net/bluetooth/l2cap_sock.c
  * Bluetooth: A2MP: Fix not initializing all members
      net/bluetooth/a2mp.c
    Merge 4.9.239 into android-4.9-q
Linux 4.9.239
  * net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
      drivers/net/usb/rtl8150.c
  * mm: khugepaged: recalculate min_free_kbytes after memory hotplug as expected by khugepaged
      include/linux/khugepaged.h
      mm/khugepaged.c
      mm/page_alloc.c
  * perf: Fix task_function_call() error handling
      kernel/events/core.c
  * rxrpc: Fix server keyring leak
      net/rxrpc/key.c
  * rxrpc: Fix some missing _bh annotations on locking conn->state_lock
      net/rxrpc/conn_event.c
  * rxrpc: Downgrade the BUG() for unsupported token type in rxrpc_read()
      net/rxrpc/key.c
  * rxrpc: Fix rxkad token xdr encoding
      net/rxrpc/key.c
  * mdio: fix mdio-thunder.c dependency & build error
      drivers/net/phy/Kconfig
  * bonding: set dev->needed_headroom in bond_setup_by_slave()
      drivers/net/bonding/bond_main.c
  * xfrm: Use correct address family in xfrm_state_find
      net/xfrm/xfrm_state.c
  * net: stmmac: removed enabling eee in EEE set callback
      drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
  * xfrm: clone whole liftime_cur structure in xfrm_do_migrate
      net/xfrm/xfrm_state.c
  * xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate
      include/net/xfrm.h
  * drm/amdgpu: prevent double kfree ttm->sg
      drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
  * openvswitch: handle DNAT tuple collision
      net/openvswitch/conntrack.c
  * net: team: fix memory leak in __team_options_register
      drivers/net/team/team.c
  * team: set dev->needed_headroom in team_setup_by_port()
      drivers/net/team/team.c
  * sctp: fix sctp_auth_init_hmacs() error path
      net/sctp/auth.c
  * mm/khugepaged: fix filemap page_to_pgoff(page) != offset
      mm/khugepaged.c
  * macsec: avoid use-after-free in macsec_handle_frame()
      drivers/net/macsec.c
  * ftrace: Move RCU is watching check after recursion check
      kernel/trace/ftrace.c
  * mtd: rawnand: sunxi: Fix the probe error path
      drivers/mtd/nand/sunxi_nand.c
  * perf top: Fix stdio interface input handling with glibc 2.28+
      tools/perf/builtin-top.c
  * driver core: Fix probe_count imbalance in really_probe()
      drivers/base/dd.c
  * platform/x86: thinkpad_acpi: re-initialize ACPI buffer size when reuse
      drivers/platform/x86/thinkpad_acpi.c
  * platform/x86: thinkpad_acpi: initialize tp_nvram_state variable
      drivers/platform/x86/thinkpad_acpi.c
  * usermodehelper: reset umask to default before executing user process
      kernel/kmod.c
  * net: wireless: nl80211: fix out-of-bounds access in nl80211_del_key()
      net/wireless/nl80211.c
  * fbcon: Fix global-out-of-bounds read in fbcon_get_font()
      drivers/video/console/fbcon.c
  * Revert "ravb: Fixed to be able to unload modules"
      drivers/net/ethernet/renesas/ravb_main.c
  * Fonts: Support FONT_EXTRA_WORDS macros for built-in fonts
      include/linux/font.h
      lib/fonts/font_10x18.c
      lib/fonts/font_6x10.c
      lib/fonts/font_6x11.c
      lib/fonts/font_7x14.c
      lib/fonts/font_8x16.c
      lib/fonts/font_8x8.c
      lib/fonts/font_acorn_8x8.c
      lib/fonts/font_mini_4x6.c
      lib/fonts/font_pearl_8x8.c
      lib/fonts/font_sun12x22.c
      lib/fonts/font_sun8x16.c
  * fbdev, newport_con: Move FONT_EXTRA_WORDS macros into linux/font.h
      drivers/video/console/fbcon.h
      drivers/video/console/fbcon_rotate.c
      drivers/video/console/newport_con.c
      drivers/video/console/tileblit.c
      include/linux/font.h
  * netfilter: ctnetlink: add a range check for l3/l4 protonum
      net/netfilter/nf_conntrack_netlink.c
  * ep_create_wakeup_source(): dentry name can change under you...
      fs/eventpoll.c
  * epoll: EPOLL_CTL_ADD: close the race in decision to take fast path
      fs/eventpoll.c
  * epoll: replace ->visited/visited_list with generation count
      fs/eventpoll.c
  * epoll: do not insert into poll queues until all sanity checks are done
      fs/eventpoll.c
  * net/packet: fix overflow in tpacket_rcv
      net/packet/af_packet.c
  * random32: Restore __latent_entropy attribute on net_rand_state
      lib/random32.c
  * i2c: cpm: Fix i2c_ram structure
      drivers/i2c/busses/i2c-cpm.c
  * iommu/exynos: add missing put_device() call in exynos_iommu_of_xlate()
      drivers/iommu/exynos-iommu.c
  * clk: samsung: exynos4: mark 'chipid' clock as CLK_IGNORE_UNUSED
      drivers/clk/samsung/clk-exynos4.c
  * nfs: Fix security label length not being reset
      fs/nfs/dir.c
  * mac80211: do not allow bigger VHT MPDUs than the hardware supports
      net/mac80211/vht.c
  * drivers/net/wan/hdlc: Set skb->protocol before transmitting
      drivers/net/wan/hdlc_cisco.c
      drivers/net/wan/hdlc_fr.c
      drivers/net/wan/hdlc_ppp.c
  * drivers/net/wan/lapbether: Make skb->protocol consistent with the header
      drivers/net/wan/lapbether.c
  * rndis_host: increase sleep time in the query-response loop
      drivers/net/usb/rndis_host.c
  * net: dec: de2104x: Increase receive ring size for Tulip
      drivers/net/ethernet/dec/tulip/de2104x.c
  * drm/amdgpu: restore proper ref count in amdgpu_display_crtc_set_config
      drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
  * Input: i8042 - add nopnp quirk for Acer Aspire 5 A515
      drivers/input/serio/i8042-x86ia64io.h
  * gpio: tc35894: fix up tc35894 interrupt configuration
      drivers/gpio/gpio-tc3589x.c
  * USB: gadget: f_ncm: Fix NDP16 datagram validation
      drivers/usb/gadget/function/f_ncm.c
  * vsock/virtio: stop workers during the .remove()
      net/vmw_vsock/virtio_transport.c
  * vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock
      net/vmw_vsock/virtio_transport.c
    Merge 4.9.238 into android-4.9-q
Linux 4.9.238
  * ata: sata_mv, avoid trigerrable BUG_ON
      drivers/ata/sata_mv.c
  * ata: make qc_prep return ata_completion_errors
      Documentation/DocBook/libata.tmpl
      drivers/ata/acard-ahci.c
      drivers/ata/libahci.c
      drivers/ata/libata-core.c
      drivers/ata/libata-sff.c
      drivers/ata/pata_macio.c
      drivers/ata/pata_pxa.c
      drivers/ata/pdc_adma.c
      drivers/ata/sata_fsl.c
      drivers/ata/sata_inic162x.c
      drivers/ata/sata_mv.c
      drivers/ata/sata_nv.c
      drivers/ata/sata_promise.c
      drivers/ata/sata_qstor.c
      drivers/ata/sata_rcar.c
      drivers/ata/sata_sil.c
      drivers/ata/sata_sil24.c
      drivers/ata/sata_sx4.c
      include/linux/libata.h
  * ata: define AC_ERR_OK
      include/linux/libata.h
  * lib/string.c: implement stpcpy
      lib/string.c
  * kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
      kernel/kprobes.c
  * MIPS: Add the missing 'CPU_1074K' into __get_cpu_type()
      arch/mips/include/asm/cpu-type.h
  * ALSA: asihpi: fix iounmap in error handler
      sound/pci/asihpi/hpioctl.c
  * batman-adv: mcast: fix duplicate mcast packets in BLA backbone from mesh
      net/batman-adv/bridge_loop_avoidance.c
      net/batman-adv/bridge_loop_avoidance.h
      net/batman-adv/soft-interface.c
  * batman-adv: Add missing include for in_interrupt()
      net/batman-adv/bridge_loop_avoidance.c
  * mac802154: tx: fix use-after-free
      net/mac802154/tx.c
  * batman-adv: mcast/TT: fix wrongly dropped or rerouted packets
      net/batman-adv/routing.c
  * atm: eni: fix the missed pci_disable_device() for eni_init_one()
      drivers/atm/eni.c
  * batman-adv: bla: fix type misuse for backbone_gw hash indexing
      net/batman-adv/bridge_loop_avoidance.c
  * mwifiex: Increase AES key storage size to 256 bits
      drivers/net/wireless/marvell/mwifiex/fw.h
      drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
  * clocksource/drivers/h8300_timer8: Fix wrong return value in h8300_8timer_init()
      drivers/clocksource/h8300_timer8.c
  * ieee802154/adf7242: check status of adf7242_read_reg
      drivers/net/ieee802154/adf7242.c
  * objtool: Fix noreturn detection for ignored functions
      tools/objtool/check.c
  * i2c: core: Call i2c_acpi_install_space_handler() before i2c_acpi_register_devices()
      drivers/i2c/i2c-core.c
  * s390/init: add missing __init annotations
      arch/s390/kernel/setup.c
  * vfio/pci: fix racy on error and request eventfd ctx
      drivers/vfio/pci/vfio_pci.c
  * selftests/x86/syscall_nt: Clear weird flags after each test
      tools/testing/selftests/x86/syscall_nt.c
  * cifs: Fix double add page to memcg when cifs_readpages
      fs/cifs/file.c
  * vfio/pci: Clear error and request eventfd ctx after releasing
      drivers/vfio/pci/vfio_pci.c
  * x86/speculation/mds: Mark mds_user_clear_cpu_buffers() __always_inline
      arch/x86/include/asm/nospec-branch.h
  * mtd: parser: cmdline: Support MTD names containing one or more colons
      drivers/mtd/cmdlinepart.c
  * ceph: fix potential race in ceph_check_caps
      fs/ceph/caps.c
  * mtd: rawnand: omap_elm: Fix runtime PM imbalance on error
      drivers/mtd/nand/omap_elm.c
  * perf kcore_copy: Fix module map when there are no modules loaded
      tools/perf/util/symbol-elf.c
  * perf util: Fix memory leak of prefix_if_not_in
      tools/perf/util/sort.c
  * vfio/pci: fix memory leaks of eventfd ctx
      drivers/vfio/pci/vfio_pci.c
  * btrfs: don't force read-only after error in drop snapshot
      fs/btrfs/extent-tree.c
  * printk: handle blank console arguments passed in.
      kernel/printk/printk.c
  * e1000: Do not perform reset in reset_task if we are already down
      drivers/net/ethernet/intel/e1000/e1000_main.c
  * USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
      drivers/usb/host/ehci-mv.c
  * fuse: don't check refcount after stealing page
      fs/fuse/dev.c
  * ALSA: hda: Fix potential race in unsol event handler
      sound/hda/hdac_bus.c
  * tty: serial: samsung: Correct clock selection logic
      drivers/tty/serial/samsung.c
  * USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()
      drivers/usb/host/ehci-mv.c
  * Bluetooth: Handle Inquiry Cancel error after Inquiry Complete
      net/bluetooth/hci_event.c
  * phy: samsung: s5pv210-usb2: Add delay after reset
      drivers/phy/phy-s5pv210-usb2.c
  * atm: fix a memory leak of vcc->user_back
      net/atm/lec.c
  * dt-bindings: sound: wm8994: Correct required supplies based on actual implementaion
      Documentation/devicetree/bindings/sound/wm8994.txt
  * drivers: char: tlclk.c: Avoid data race between init and interrupt handler
      drivers/char/tlclk.c
  * bdev: Reduce time holding bd_mutex in sync in blkdev_close()
      fs/block_dev.c
  * KVM: Remove CREATE_IRQCHIP/SET_PIT2 race
      arch/x86/kvm/x86.c
  * mm/mmap.c: initialize align_offset explicitly for vm_unmapped_area
      mm/mmap.c
  * mm/filemap.c: clear page error before actual read
      mm/filemap.c
  * ALSA: usb-audio: Fix case when USB MIDI interface has more than one extra endpoint descriptor
      sound/usb/midi.c
  * ubifs: Fix out-of-bounds memory access caused by abnormal value of node_len
      fs/ubifs/io.c
  * svcrdma: Fix leak of transport addresses
      net/sunrpc/xprtrdma/svc_rdma_backchannel.c
  * SUNRPC: Fix a potential buffer overflow in 'svc_print_xprts()'
      net/sunrpc/svc_xprt.c
  * tools: gpio-hammer: Avoid potential overflow in main
      tools/gpio/gpio-hammer.c
  * cpufreq: powernv: Fix frame-size-overflow in powernv_cpufreq_work_fn
      drivers/cpufreq/powernv-cpufreq.c
  * serial: 8250: 8250_omap: Terminate DMA before pushing data on RX timeout
      drivers/tty/serial/8250/8250_omap.c
  * serial: 8250_omap: Fix sleeping function called from invalid context during probe
      drivers/tty/serial/8250/8250_omap.c
  * serial: 8250_port: Don't service RX FIFO if throttled
      drivers/tty/serial/8250/8250_port.c
  * tracing: Use address-of operator on section symbols
      kernel/trace/trace.c
  * tpm: ibmvtpm: Wait for buffer to be set before proceeding
      drivers/char/tpm/tpm_ibmvtpm.c
      drivers/char/tpm/tpm_ibmvtpm.h
  * xfs: don't ever return a stale pointer from __xfs_dir3_free_read
      fs/xfs/libxfs/xfs_dir2_node.c
  * media: tda10071: fix unsigned sign extension overflow
      drivers/media/dvb-frontends/tda10071.c
  * Bluetooth: L2CAP: handle l2cap config request during open state
      net/bluetooth/l2cap_core.c
  * drm/amdgpu: increase atombios cmd timeout
      drivers/gpu/drm/amd/amdgpu/atom.c
  * timekeeping: Prevent 32bit truncation in scale64_check_overflow()
      kernel/time/timekeeping.c
  * Bluetooth: guard against controllers sending zero'd events
      net/bluetooth/hci_event.c
  * media: go7007: Fix URB type for interrupt handling
      drivers/media/usb/go7007/go7007-usb.c
  * dmaengine: tegra-apb: Prevent race conditions on channel's freeing
      drivers/dma/tegra20-apb-dma.c
  * bpf: Remove recursion prevention from rcu free callback
      kernel/bpf/hashtab.c
  * x86/pkeys: Add check for pkey "overflow"
      arch/x86/include/asm/pkeys.h
      arch/x86/kernel/fpu/xstate.c
  * KVM: x86: fix incorrect comparison in trace event
      arch/x86/kvm/mmutrace.h
  * RDMA/rxe: Fix configuration of atomic queue pair attributes
      drivers/infiniband/sw/rxe/rxe_qp.c
  * drm/omap: fix possible object reference leak
      drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c
  * scsi: lpfc: Fix coverity errors in fmdi attribute handling
      drivers/scsi/lpfc/lpfc_ct.c
      drivers/scsi/lpfc/lpfc_hw.h
  * scsi: lpfc: Fix RQ buffer leakage when no IOCBs available
      drivers/scsi/lpfc/lpfc_sli.c
  * selinux: sel_avc_get_stat_idx should increase position index
      security/selinux/selinuxfs.c
  * audit: CONFIG_CHANGE don't log internal bookkeeping as an event
      kernel/audit_watch.c
  * skbuff: fix a data race in skb_queue_len()
      include/linux/skbuff.h
      net/unix/af_unix.c
  * ALSA: hda: Clear RIRB status before reading WP
      sound/pci/hda/hda_controller.c
  * KVM: fix overflow of zero page refcount with ksm running
      virt/kvm/kvm_main.c
  * Bluetooth: prefetch channel before killing sock
      net/bluetooth/l2cap_sock.c
  * mm: pagewalk: fix termination condition in walk_pte_range()
      mm/pagewalk.c
  * Bluetooth: Fix refcount use-after-free issue
      net/bluetooth/l2cap_core.c
      net/bluetooth/l2cap_sock.c
  * ar5523: Add USB ID of SMCWUSBT-G2 wireless adapter
      drivers/net/wireless/ath/ar5523/ar5523.c
  * tracing: Set kernel_stack's caller size properly
      kernel/trace/trace_entries.h
  * dmaengine: zynqmp_dma: fix burst length configuration
      drivers/dma/xilinx/zynqmp_dma.c
  * ACPI: EC: Reference count query handlers under lock
      drivers/acpi/ec.c
  * media: ti-vpe: cal: Restrict DMA to avoid memory corruption
      drivers/media/platform/ti-vpe/cal.c
  * seqlock: Require WRITE_ONCE surrounding raw_seqcount_barrier
      include/linux/seqlock.h
  * rt_cpu_seq_next should increase position index
      net/ipv4/route.c
  * neigh_stat_seq_next() should increase position index
      net/core/neighbour.c
  * kernel/sys.c: avoid copying possible padding bytes in copy_to_user
      kernel/sys.c
  * CIFS: Properly process SMB3 lease breaks
      fs/cifs/cifsglob.h
      fs/cifs/file.c
      fs/cifs/misc.c
      fs/cifs/smb1ops.c
      fs/cifs/smb2misc.c
      fs/cifs/smb2ops.c
      fs/cifs/smb2pdu.h
  * debugfs: Fix !DEBUG_FS debugfs_create_automount
      include/linux/debugfs.h
  * RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()'
      drivers/infiniband/hw/cxgb4/cm.c
  * xfs: fix attr leaf header freemap.size underflow
      fs/xfs/libxfs/xfs_attr_leaf.c
  * RDMA/i40iw: Fix potential use after free
      drivers/infiniband/hw/i40iw/i40iw_cm.c
  * bcache: fix a lost wake-up problem caused by mca_cannibalize_lock
      drivers/md/bcache/bcache.h
      drivers/md/bcache/btree.c
      drivers/md/bcache/super.c
  * tracing: Adding NULL checks for trace_array descriptor pointer
      kernel/trace/trace.c
      kernel/trace/trace_events.c
  * mfd: mfd-core: Protect against NULL call-back function pointer
      drivers/mfd/mfd-core.c
  * mtd: cfi_cmdset_0002: don't free cfi->cfiq in error path of cfi_amdstd_setup()
      drivers/mtd/chips/cfi_cmdset_0002.c
  * clk/ti/adpll: allocate room for terminating null
      drivers/clk/ti/adpll.c
  * PM / devfreq: tegra30: Fix integer overflow on CPU's freq max out
      drivers/devfreq/tegra-devfreq.c
  * ALSA: usb-audio: Add delay quirk for H570e USB headsets
      sound/usb/quirks.c
  * ASoC: kirkwood: fix IRQ error handling
      sound/soc/kirkwood/kirkwood-dma.c
  * gma/gma500: fix a memory disclosure bug due to uninitialized bytes
      drivers/gpu/drm/gma500/cdv_intel_display.c
  * m68k: q40: Fix info-leak in rtc_ioctl
      arch/m68k/q40/config.c
  * scsi: aacraid: fix illegal IO beyond last LBA
      drivers/scsi/aacraid/aachba.c
  * serial: 8250: Avoid error message on reprobe
      drivers/tty/serial/8250/8250_core.c
  * net: add __must_check to skb_put_padto()
      include/linux/skbuff.h
  * net/hsr: Check skb_put_padto() return value
      net/hsr/hsr_device.c
  * net: phy: Avoid NPD upon phy_detach() when driver is unbound
      drivers/net/phy/phy_device.c
  * bnxt_en: Protect bnxt_set_eee() and bnxt_set_pauseparam() with mutex.
      drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
  * tipc: use skb_unshare() instead in tipc_buf_append()
      net/tipc/msg.c
  * ip: fix tos reflection in ack and reset packets
      net/ipv4/ip_output.c
  * hdlc_ppp: add range checks in ppp_cp_parse_cr()
      drivers/net/wan/hdlc_ppp.c
  * mtd: Fix comparison in map_word_andequal()
      include/linux/mtd/map.h
  * RDMA/ucma: ucma_context reference leak in error path
      drivers/infiniband/core/ucma.c
  * kprobes: fix kill kprobe which has been marked as gone
      kernel/kprobes.c
  * KVM: fix memory leak in kvm_io_bus_unregister_dev()
      virt/kvm/kvm_main.c
  * af_key: pfkey_dump needs parameter validation
      net/key/af_key.c

Change-Id: I3d2f58309021b7d544b64bab27bc9f6b2af211b1
Signed-off-by: lucaswei <lucaswei@google.com>
2020-11-26 18:08:27 +08:00

2034 lines
51 KiB
C

/*
* linux/fs/block_dev.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
* Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
*/
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fcntl.h>
#include <linux/slab.h>
#include <linux/kmod.h>
#include <linux/major.h>
#include <linux/device_cgroup.h>
#include <linux/highmem.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/module.h>
#include <linux/blkpg.h>
#include <linux/magic.h>
#include <linux/buffer_head.h>
#include <linux/swap.h>
#include <linux/pagevec.h>
#include <linux/writeback.h>
#include <linux/mpage.h>
#include <linux/mount.h>
#include <linux/uio.h>
#include <linux/namei.h>
#include <linux/log2.h>
#include <linux/cleancache.h>
#include <linux/dax.h>
#include <linux/badblocks.h>
#include <linux/falloc.h>
#include <asm/uaccess.h>
#include "internal.h"
struct bdev_inode {
struct block_device bdev;
struct inode vfs_inode;
};
static const struct address_space_operations def_blk_aops;
static inline struct bdev_inode *BDEV_I(struct inode *inode)
{
return container_of(inode, struct bdev_inode, vfs_inode);
}
struct block_device *I_BDEV(struct inode *inode)
{
return &BDEV_I(inode)->bdev;
}
EXPORT_SYMBOL(I_BDEV);
void __vfs_msg(struct super_block *sb, const char *prefix, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
printk_ratelimited("%sVFS (%s): %pV\n", prefix, sb->s_id, &vaf);
va_end(args);
}
static void bdev_write_inode(struct block_device *bdev)
{
struct inode *inode = bdev->bd_inode;
int ret;
spin_lock(&inode->i_lock);
while (inode->i_state & I_DIRTY) {
spin_unlock(&inode->i_lock);
ret = write_inode_now(inode, true);
if (ret) {
char name[BDEVNAME_SIZE];
pr_warn_ratelimited("VFS: Dirty inode writeback failed "
"for block device %s (err=%d).\n",
bdevname(bdev, name), ret);
}
spin_lock(&inode->i_lock);
}
spin_unlock(&inode->i_lock);
}
/* Kill _all_ buffers and pagecache , dirty or not.. */
void kill_bdev(struct block_device *bdev)
{
struct address_space *mapping = bdev->bd_inode->i_mapping;
if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
return;
invalidate_bh_lrus();
truncate_inode_pages(mapping, 0);
}
EXPORT_SYMBOL(kill_bdev);
/* Invalidate clean unused buffers and pagecache. */
void invalidate_bdev(struct block_device *bdev)
{
struct address_space *mapping = bdev->bd_inode->i_mapping;
if (mapping->nrpages) {
invalidate_bh_lrus();
lru_add_drain_all(); /* make sure all lru add caches are flushed */
invalidate_mapping_pages(mapping, 0, -1);
}
/* 99% of the time, we don't need to flush the cleancache on the bdev.
* But, for the strange corners, lets be cautious
*/
cleancache_invalidate_inode(mapping);
}
EXPORT_SYMBOL(invalidate_bdev);
static void set_init_blocksize(struct block_device *bdev)
{
unsigned bsize = bdev_logical_block_size(bdev);
loff_t size = i_size_read(bdev->bd_inode);
while (bsize < PAGE_SIZE) {
if (size & bsize)
break;
bsize <<= 1;
}
bdev->bd_block_size = bsize;
bdev->bd_inode->i_blkbits = blksize_bits(bsize);
}
int set_blocksize(struct block_device *bdev, int size)
{
/* Size must be a power of two, and between 512 and PAGE_SIZE */
if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size))
return -EINVAL;
/* Size cannot be smaller than the size supported by the device */
if (size < bdev_logical_block_size(bdev))
return -EINVAL;
/* Don't change the size if it is same as current */
if (bdev->bd_block_size != size) {
sync_blockdev(bdev);
bdev->bd_block_size = size;
bdev->bd_inode->i_blkbits = blksize_bits(size);
kill_bdev(bdev);
}
return 0;
}
EXPORT_SYMBOL(set_blocksize);
int sb_set_blocksize(struct super_block *sb, int size)
{
if (set_blocksize(sb->s_bdev, size))
return 0;
/* If we get here, we know size is power of two
* and it's value is between 512 and PAGE_SIZE */
sb->s_blocksize = size;
sb->s_blocksize_bits = blksize_bits(size);
return sb->s_blocksize;
}
EXPORT_SYMBOL(sb_set_blocksize);
int sb_min_blocksize(struct super_block *sb, int size)
{
int minsize = bdev_logical_block_size(sb->s_bdev);
if (size < minsize)
size = minsize;
return sb_set_blocksize(sb, size);
}
EXPORT_SYMBOL(sb_min_blocksize);
static int
blkdev_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh, int create)
{
bh->b_bdev = I_BDEV(inode);
bh->b_blocknr = iblock;
set_buffer_mapped(bh);
return 0;
}
static struct inode *bdev_file_inode(struct file *file)
{
return file->f_mapping->host;
}
static ssize_t
blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
{
struct file *file = iocb->ki_filp;
struct inode *inode = bdev_file_inode(file);
return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter,
blkdev_get_block, NULL, NULL,
DIO_SKIP_DIO_COUNT);
}
int __sync_blockdev(struct block_device *bdev, int wait)
{
if (!bdev)
return 0;
if (!wait)
return filemap_flush(bdev->bd_inode->i_mapping);
return filemap_write_and_wait(bdev->bd_inode->i_mapping);
}
/*
* Write out and wait upon all the dirty data associated with a block
* device via its mapping. Does not take the superblock lock.
*/
int sync_blockdev(struct block_device *bdev)
{
return __sync_blockdev(bdev, 1);
}
EXPORT_SYMBOL(sync_blockdev);
/*
* Write out and wait upon all dirty data associated with this
* device. Filesystem data as well as the underlying block
* device. Takes the superblock lock.
*/
int fsync_bdev(struct block_device *bdev)
{
struct super_block *sb = get_super(bdev);
if (sb) {
int res = sync_filesystem(sb);
drop_super(sb);
return res;
}
return sync_blockdev(bdev);
}
EXPORT_SYMBOL(fsync_bdev);
/**
* freeze_bdev -- lock a filesystem and force it into a consistent state
* @bdev: blockdevice to lock
*
* If a superblock is found on this device, we take the s_umount semaphore
* on it to make sure nobody unmounts until the snapshot creation is done.
* The reference counter (bd_fsfreeze_count) guarantees that only the last
* unfreeze process can unfreeze the frozen filesystem actually when multiple
* freeze requests arrive simultaneously. It counts up in freeze_bdev() and
* count down in thaw_bdev(). When it becomes 0, thaw_bdev() will unfreeze
* actually.
*/
struct super_block *freeze_bdev(struct block_device *bdev)
{
struct super_block *sb;
int error = 0;
mutex_lock(&bdev->bd_fsfreeze_mutex);
if (++bdev->bd_fsfreeze_count > 1) {
/*
* We don't even need to grab a reference - the first call
* to freeze_bdev grab an active reference and only the last
* thaw_bdev drops it.
*/
sb = get_super(bdev);
if (sb)
drop_super(sb);
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return sb;
}
sb = get_active_super(bdev);
if (!sb)
goto out;
if (sb->s_op->freeze_super)
error = sb->s_op->freeze_super(sb);
else
error = freeze_super(sb);
if (error) {
deactivate_super(sb);
bdev->bd_fsfreeze_count--;
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return ERR_PTR(error);
}
deactivate_super(sb);
out:
sync_blockdev(bdev);
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return sb; /* thaw_bdev releases s->s_umount */
}
EXPORT_SYMBOL(freeze_bdev);
/**
* thaw_bdev -- unlock filesystem
* @bdev: blockdevice to unlock
* @sb: associated superblock
*
* Unlocks the filesystem and marks it writeable again after freeze_bdev().
*/
int thaw_bdev(struct block_device *bdev, struct super_block *sb)
{
int error = -EINVAL;
mutex_lock(&bdev->bd_fsfreeze_mutex);
if (!bdev->bd_fsfreeze_count)
goto out;
error = 0;
if (--bdev->bd_fsfreeze_count > 0)
goto out;
if (!sb)
goto out;
if (sb->s_op->thaw_super)
error = sb->s_op->thaw_super(sb);
else
error = thaw_super(sb);
if (error)
bdev->bd_fsfreeze_count++;
out:
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return error;
}
EXPORT_SYMBOL(thaw_bdev);
static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
{
return block_write_full_page(page, blkdev_get_block, wbc);
}
static int blkdev_readpage(struct file * file, struct page * page)
{
return block_read_full_page(page, blkdev_get_block);
}
static int blkdev_readpages(struct file *file, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages)
{
return mpage_readpages(mapping, pages, nr_pages, blkdev_get_block);
}
static int blkdev_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{
return block_write_begin(mapping, pos, len, flags, pagep,
blkdev_get_block);
}
static int blkdev_write_end(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned copied,
struct page *page, void *fsdata)
{
int ret;
ret = block_write_end(file, mapping, pos, len, copied, page, fsdata);
unlock_page(page);
put_page(page);
return ret;
}
/*
* private llseek:
* for a block special file file_inode(file)->i_size is zero
* so we compute the size by hand (just as in block_read/write above)
*/
static loff_t block_llseek(struct file *file, loff_t offset, int whence)
{
struct inode *bd_inode = bdev_file_inode(file);
loff_t retval;
inode_lock(bd_inode);
retval = fixed_size_llseek(file, offset, whence, i_size_read(bd_inode));
inode_unlock(bd_inode);
return retval;
}
int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
{
struct inode *bd_inode = bdev_file_inode(filp);
struct block_device *bdev = I_BDEV(bd_inode);
int error;
error = filemap_write_and_wait_range(filp->f_mapping, start, end);
if (error)
return error;
/*
* There is no need to serialise calls to blkdev_issue_flush with
* i_mutex and doing so causes performance issues with concurrent
* O_SYNC writers to a block device.
*/
error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
if (error == -EOPNOTSUPP)
error = 0;
return error;
}
EXPORT_SYMBOL(blkdev_fsync);
/**
* bdev_read_page() - Start reading a page from a block device
* @bdev: The device to read the page from
* @sector: The offset on the device to read the page to (need not be aligned)
* @page: The page to read
*
* On entry, the page should be locked. It will be unlocked when the page
* has been read. If the block driver implements rw_page synchronously,
* that will be true on exit from this function, but it need not be.
*
* Errors returned by this function are usually "soft", eg out of memory, or
* queue full; callers should try a different route to read this page rather
* than propagate an error back up the stack.
*
* Return: negative errno if an error occurs, 0 if submission was successful.
*/
int bdev_read_page(struct block_device *bdev, sector_t sector,
struct page *page)
{
const struct block_device_operations *ops = bdev->bd_disk->fops;
int result = -EOPNOTSUPP;
if (!ops->rw_page || bdev_get_integrity(bdev))
return result;
result = blk_queue_enter(bdev->bd_queue, false);
if (result)
return result;
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, false);
blk_queue_exit(bdev->bd_queue);
return result;
}
EXPORT_SYMBOL_GPL(bdev_read_page);
/**
* bdev_write_page() - Start writing a page to a block device
* @bdev: The device to write the page to
* @sector: The offset on the device to write the page to (need not be aligned)
* @page: The page to write
* @wbc: The writeback_control for the write
*
* On entry, the page should be locked and not currently under writeback.
* On exit, if the write started successfully, the page will be unlocked and
* under writeback. If the write failed already (eg the driver failed to
* queue the page to the device), the page will still be locked. If the
* caller is a ->writepage implementation, it will need to unlock the page.
*
* Errors returned by this function are usually "soft", eg out of memory, or
* queue full; callers should try a different route to write this page rather
* than propagate an error back up the stack.
*
* Return: negative errno if an error occurs, 0 if submission was successful.
*/
int bdev_write_page(struct block_device *bdev, sector_t sector,
struct page *page, struct writeback_control *wbc)
{
int result;
const struct block_device_operations *ops = bdev->bd_disk->fops;
if (!ops->rw_page || bdev_get_integrity(bdev))
return -EOPNOTSUPP;
result = blk_queue_enter(bdev->bd_queue, false);
if (result)
return result;
set_page_writeback(page);
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, true);
if (result) {
end_page_writeback(page);
} else {
clean_page_buffers(page);
unlock_page(page);
}
blk_queue_exit(bdev->bd_queue);
return result;
}
EXPORT_SYMBOL_GPL(bdev_write_page);
/**
* bdev_direct_access() - Get the address for directly-accessibly memory
* @bdev: The device containing the memory
* @dax: control and output parameters for ->direct_access
*
* If a block device is made up of directly addressable memory, this function
* will tell the caller the PFN and the address of the memory. The address
* may be directly dereferenced within the kernel without the need to call
* ioremap(), kmap() or similar. The PFN is suitable for inserting into
* page tables.
*
* Return: negative errno if an error occurs, otherwise the number of bytes
* accessible at this address.
*/
long bdev_direct_access(struct block_device *bdev, struct blk_dax_ctl *dax)
{
sector_t sector = dax->sector;
long avail, size = dax->size;
const struct block_device_operations *ops = bdev->bd_disk->fops;
/*
* The device driver is allowed to sleep, in order to make the
* memory directly accessible.
*/
might_sleep();
if (size < 0)
return size;
if (!blk_queue_dax(bdev_get_queue(bdev)) || !ops->direct_access)
return -EOPNOTSUPP;
if ((sector + DIV_ROUND_UP(size, 512)) >
part_nr_sects_read(bdev->bd_part))
return -ERANGE;
sector += get_start_sect(bdev);
if (sector % (PAGE_SIZE / 512))
return -EINVAL;
avail = ops->direct_access(bdev, sector, &dax->addr, &dax->pfn, size);
if (!avail)
return -ERANGE;
if (avail > 0 && avail & ~PAGE_MASK)
return -ENXIO;
return min(avail, size);
}
EXPORT_SYMBOL_GPL(bdev_direct_access);
/**
* bdev_dax_supported() - Check if the device supports dax for filesystem
* @sb: The superblock of the device
* @blocksize: The block size of the device
*
* This is a library function for filesystems to check if the block device
* can be mounted with dax option.
*
* Return: negative errno if unsupported, 0 if supported.
*/
int bdev_dax_supported(struct super_block *sb, int blocksize)
{
struct blk_dax_ctl dax = {
.sector = 0,
.size = PAGE_SIZE,
};
int err;
if (blocksize != PAGE_SIZE) {
vfs_msg(sb, KERN_ERR, "error: unsupported blocksize for dax");
return -EINVAL;
}
err = bdev_direct_access(sb->s_bdev, &dax);
if (err < 0) {
switch (err) {
case -EOPNOTSUPP:
vfs_msg(sb, KERN_ERR,
"error: device does not support dax");
break;
case -EINVAL:
vfs_msg(sb, KERN_ERR,
"error: unaligned partition for dax");
break;
default:
vfs_msg(sb, KERN_ERR,
"error: dax access failed (%d)", err);
}
return err;
}
return 0;
}
EXPORT_SYMBOL_GPL(bdev_dax_supported);
/**
* bdev_dax_capable() - Return if the raw device is capable for dax
* @bdev: The device for raw block device access
*/
bool bdev_dax_capable(struct block_device *bdev)
{
struct blk_dax_ctl dax = {
.size = PAGE_SIZE,
};
if (!IS_ENABLED(CONFIG_FS_DAX))
return false;
dax.sector = 0;
if (bdev_direct_access(bdev, &dax) < 0)
return false;
dax.sector = bdev->bd_part->nr_sects - (PAGE_SIZE / 512);
if (bdev_direct_access(bdev, &dax) < 0)
return false;
return true;
}
/*
* pseudo-fs
*/
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock);
static struct kmem_cache * bdev_cachep __read_mostly;
static struct inode *bdev_alloc_inode(struct super_block *sb)
{
struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL);
if (!ei)
return NULL;
return &ei->vfs_inode;
}
static void bdev_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct bdev_inode *bdi = BDEV_I(inode);
kmem_cache_free(bdev_cachep, bdi);
}
static void bdev_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, bdev_i_callback);
}
static void init_once(void *foo)
{
struct bdev_inode *ei = (struct bdev_inode *) foo;
struct block_device *bdev = &ei->bdev;
memset(bdev, 0, sizeof(*bdev));
mutex_init(&bdev->bd_mutex);
INIT_LIST_HEAD(&bdev->bd_list);
#ifdef CONFIG_SYSFS
INIT_LIST_HEAD(&bdev->bd_holder_disks);
#endif
bdev->bd_bdi = &noop_backing_dev_info;
inode_init_once(&ei->vfs_inode);
/* Initialize mutex for freeze. */
mutex_init(&bdev->bd_fsfreeze_mutex);
}
static void bdev_evict_inode(struct inode *inode)
{
struct block_device *bdev = &BDEV_I(inode)->bdev;
truncate_inode_pages_final(&inode->i_data);
invalidate_inode_buffers(inode); /* is it needed here? */
clear_inode(inode);
spin_lock(&bdev_lock);
list_del_init(&bdev->bd_list);
spin_unlock(&bdev_lock);
/* Detach inode from wb early as bdi_put() may free bdi->wb */
inode_detach_wb(inode);
if (bdev->bd_bdi != &noop_backing_dev_info) {
bdi_put(bdev->bd_bdi);
bdev->bd_bdi = &noop_backing_dev_info;
}
}
static const struct super_operations bdev_sops = {
.statfs = simple_statfs,
.alloc_inode = bdev_alloc_inode,
.destroy_inode = bdev_destroy_inode,
.drop_inode = generic_delete_inode,
.evict_inode = bdev_evict_inode,
};
static struct dentry *bd_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
struct dentry *dent;
dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, BDEVFS_MAGIC);
if (!IS_ERR(dent))
dent->d_sb->s_iflags |= SB_I_CGROUPWB;
return dent;
}
static struct file_system_type bd_type = {
.name = "bdev",
.mount = bd_mount,
.kill_sb = kill_anon_super,
};
struct super_block *blockdev_superblock __read_mostly;
EXPORT_SYMBOL_GPL(blockdev_superblock);
void __init bdev_cache_init(void)
{
int err;
static struct vfsmount *bd_mnt;
bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD|SLAB_ACCOUNT|SLAB_PANIC),
init_once);
err = register_filesystem(&bd_type);
if (err)
panic("Cannot register bdev pseudo-fs");
bd_mnt = kern_mount(&bd_type);
if (IS_ERR(bd_mnt))
panic("Cannot create bdev pseudo-fs");
blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */
}
/*
* Most likely _very_ bad one - but then it's hardly critical for small
* /dev and can be fixed when somebody will need really large one.
* Keep in mind that it will be fed through icache hash function too.
*/
static inline unsigned long hash(dev_t dev)
{
return MAJOR(dev)+MINOR(dev);
}
static int bdev_test(struct inode *inode, void *data)
{
return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data;
}
static int bdev_set(struct inode *inode, void *data)
{
BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data;
return 0;
}
static LIST_HEAD(all_bdevs);
/*
* If there is a bdev inode for this device, unhash it so that it gets evicted
* as soon as last inode reference is dropped.
*/
void bdev_unhash_inode(dev_t dev)
{
struct inode *inode;
inode = ilookup5(blockdev_superblock, hash(dev), bdev_test, &dev);
if (inode) {
remove_inode_hash(inode);
iput(inode);
}
}
struct block_device *bdget(dev_t dev)
{
struct block_device *bdev;
struct inode *inode;
inode = iget5_locked(blockdev_superblock, hash(dev),
bdev_test, bdev_set, &dev);
if (!inode)
return NULL;
bdev = &BDEV_I(inode)->bdev;
if (inode->i_state & I_NEW) {
bdev->bd_contains = NULL;
bdev->bd_super = NULL;
bdev->bd_inode = inode;
bdev->bd_block_size = i_blocksize(inode);
bdev->bd_part_count = 0;
bdev->bd_invalidated = 0;
inode->i_mode = S_IFBLK;
inode->i_rdev = dev;
inode->i_bdev = bdev;
inode->i_data.a_ops = &def_blk_aops;
mapping_set_gfp_mask(&inode->i_data, GFP_USER);
spin_lock(&bdev_lock);
list_add(&bdev->bd_list, &all_bdevs);
spin_unlock(&bdev_lock);
unlock_new_inode(inode);
}
return bdev;
}
EXPORT_SYMBOL(bdget);
/**
* bdgrab -- Grab a reference to an already referenced block device
* @bdev: Block device to grab a reference to.
*/
struct block_device *bdgrab(struct block_device *bdev)
{
ihold(bdev->bd_inode);
return bdev;
}
EXPORT_SYMBOL(bdgrab);
long nr_blockdev_pages(void)
{
struct block_device *bdev;
long ret = 0;
spin_lock(&bdev_lock);
list_for_each_entry(bdev, &all_bdevs, bd_list) {
ret += bdev->bd_inode->i_mapping->nrpages;
}
spin_unlock(&bdev_lock);
return ret;
}
void bdput(struct block_device *bdev)
{
iput(bdev->bd_inode);
}
EXPORT_SYMBOL(bdput);
static struct block_device *bd_acquire(struct inode *inode)
{
struct block_device *bdev;
spin_lock(&bdev_lock);
bdev = inode->i_bdev;
if (bdev && !inode_unhashed(bdev->bd_inode)) {
bdgrab(bdev);
spin_unlock(&bdev_lock);
return bdev;
}
spin_unlock(&bdev_lock);
/*
* i_bdev references block device inode that was already shut down
* (corresponding device got removed). Remove the reference and look
* up block device inode again just in case new device got
* reestablished under the same device number.
*/
if (bdev)
bd_forget(inode);
bdev = bdget(inode->i_rdev);
if (bdev) {
spin_lock(&bdev_lock);
if (!inode->i_bdev) {
/*
* We take an additional reference to bd_inode,
* and it's released in clear_inode() of inode.
* So, we can access it via ->i_mapping always
* without igrab().
*/
bdgrab(bdev);
inode->i_bdev = bdev;
inode->i_mapping = bdev->bd_inode->i_mapping;
}
spin_unlock(&bdev_lock);
}
return bdev;
}
/* Call when you free inode */
void bd_forget(struct inode *inode)
{
struct block_device *bdev = NULL;
spin_lock(&bdev_lock);
if (!sb_is_blkdev_sb(inode->i_sb))
bdev = inode->i_bdev;
inode->i_bdev = NULL;
inode->i_mapping = &inode->i_data;
spin_unlock(&bdev_lock);
if (bdev)
bdput(bdev);
}
/**
* bd_may_claim - test whether a block device can be claimed
* @bdev: block device of interest
* @whole: whole block device containing @bdev, may equal @bdev
* @holder: holder trying to claim @bdev
*
* Test whether @bdev can be claimed by @holder.
*
* CONTEXT:
* spin_lock(&bdev_lock).
*
* RETURNS:
* %true if @bdev can be claimed, %false otherwise.
*/
static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
void *holder)
{
if (bdev->bd_holder == holder)
return true; /* already a holder */
else if (bdev->bd_holder != NULL)
return false; /* held by someone else */
else if (whole == bdev)
return true; /* is a whole device which isn't held */
else if (whole->bd_holder == bd_may_claim)
return true; /* is a partition of a device that is being partitioned */
else if (whole->bd_holder != NULL)
return false; /* is a partition of a held device */
else
return true; /* is a partition of an un-held device */
}
/**
* bd_prepare_to_claim - prepare to claim a block device
* @bdev: block device of interest
* @whole: the whole device containing @bdev, may equal @bdev
* @holder: holder trying to claim @bdev
*
* Prepare to claim @bdev. This function fails if @bdev is already
* claimed by another holder and waits if another claiming is in
* progress. This function doesn't actually claim. On successful
* return, the caller has ownership of bd_claiming and bd_holder[s].
*
* CONTEXT:
* spin_lock(&bdev_lock). Might release bdev_lock, sleep and regrab
* it multiple times.
*
* RETURNS:
* 0 if @bdev can be claimed, -EBUSY otherwise.
*/
static int bd_prepare_to_claim(struct block_device *bdev,
struct block_device *whole, void *holder)
{
retry:
/* if someone else claimed, fail */
if (!bd_may_claim(bdev, whole, holder))
return -EBUSY;
/* if claiming is already in progress, wait for it to finish */
if (whole->bd_claiming) {
wait_queue_head_t *wq = bit_waitqueue(&whole->bd_claiming, 0);
DEFINE_WAIT(wait);
prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
spin_unlock(&bdev_lock);
schedule();
finish_wait(wq, &wait);
spin_lock(&bdev_lock);
goto retry;
}
/* yay, all mine */
return 0;
}
/**
* bd_start_claiming - start claiming a block device
* @bdev: block device of interest
* @holder: holder trying to claim @bdev
*
* @bdev is about to be opened exclusively. Check @bdev can be opened
* exclusively and mark that an exclusive open is in progress. Each
* successful call to this function must be matched with a call to
* either bd_finish_claiming() or bd_abort_claiming() (which do not
* fail).
*
* This function is used to gain exclusive access to the block device
* without actually causing other exclusive open attempts to fail. It
* should be used when the open sequence itself requires exclusive
* access but may subsequently fail.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to the block device containing @bdev on success, ERR_PTR()
* value on failure.
*/
static struct block_device *bd_start_claiming(struct block_device *bdev,
void *holder)
{
struct gendisk *disk;
struct block_device *whole;
int partno, err;
might_sleep();
/*
* @bdev might not have been initialized properly yet, look up
* and grab the outer block device the hard way.
*/
disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk)
return ERR_PTR(-ENXIO);
/*
* Normally, @bdev should equal what's returned from bdget_disk()
* if partno is 0; however, some drivers (floppy) use multiple
* bdev's for the same physical device and @bdev may be one of the
* aliases. Keep @bdev if partno is 0. This means claimer
* tracking is broken for those devices but it has always been that
* way.
*/
if (partno)
whole = bdget_disk(disk, 0);
else
whole = bdgrab(bdev);
module_put(disk->fops->owner);
put_disk(disk);
if (!whole)
return ERR_PTR(-ENOMEM);
/* prepare to claim, if successful, mark claiming in progress */
spin_lock(&bdev_lock);
err = bd_prepare_to_claim(bdev, whole, holder);
if (err == 0) {
whole->bd_claiming = holder;
spin_unlock(&bdev_lock);
return whole;
} else {
spin_unlock(&bdev_lock);
bdput(whole);
return ERR_PTR(err);
}
}
#ifdef CONFIG_SYSFS
struct bd_holder_disk {
struct list_head list;
struct gendisk *disk;
int refcnt;
};
static struct bd_holder_disk *bd_find_holder_disk(struct block_device *bdev,
struct gendisk *disk)
{
struct bd_holder_disk *holder;
list_for_each_entry(holder, &bdev->bd_holder_disks, list)
if (holder->disk == disk)
return holder;
return NULL;
}
static int add_symlink(struct kobject *from, struct kobject *to)
{
return sysfs_create_link(from, to, kobject_name(to));
}
static void del_symlink(struct kobject *from, struct kobject *to)
{
sysfs_remove_link(from, kobject_name(to));
}
/**
* bd_link_disk_holder - create symlinks between holding disk and slave bdev
* @bdev: the claimed slave bdev
* @disk: the holding disk
*
* DON'T USE THIS UNLESS YOU'RE ALREADY USING IT.
*
* This functions creates the following sysfs symlinks.
*
* - from "slaves" directory of the holder @disk to the claimed @bdev
* - from "holders" directory of the @bdev to the holder @disk
*
* For example, if /dev/dm-0 maps to /dev/sda and disk for dm-0 is
* passed to bd_link_disk_holder(), then:
*
* /sys/block/dm-0/slaves/sda --> /sys/block/sda
* /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
*
* The caller must have claimed @bdev before calling this function and
* ensure that both @bdev and @disk are valid during the creation and
* lifetime of these symlinks.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
{
struct bd_holder_disk *holder;
int ret = 0;
mutex_lock(&bdev->bd_mutex);
WARN_ON_ONCE(!bdev->bd_holder);
/* FIXME: remove the following once add_disk() handles errors */
if (WARN_ON(!disk->slave_dir || !bdev->bd_part->holder_dir))
goto out_unlock;
holder = bd_find_holder_disk(bdev, disk);
if (holder) {
holder->refcnt++;
goto out_unlock;
}
holder = kzalloc(sizeof(*holder), GFP_KERNEL);
if (!holder) {
ret = -ENOMEM;
goto out_unlock;
}
INIT_LIST_HEAD(&holder->list);
holder->disk = disk;
holder->refcnt = 1;
ret = add_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
if (ret)
goto out_free;
ret = add_symlink(bdev->bd_part->holder_dir, &disk_to_dev(disk)->kobj);
if (ret)
goto out_del;
/*
* bdev could be deleted beneath us which would implicitly destroy
* the holder directory. Hold on to it.
*/
kobject_get(bdev->bd_part->holder_dir);
list_add(&holder->list, &bdev->bd_holder_disks);
goto out_unlock;
out_del:
del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
out_free:
kfree(holder);
out_unlock:
mutex_unlock(&bdev->bd_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(bd_link_disk_holder);
/**
* bd_unlink_disk_holder - destroy symlinks created by bd_link_disk_holder()
* @bdev: the calimed slave bdev
* @disk: the holding disk
*
* DON'T USE THIS UNLESS YOU'RE ALREADY USING IT.
*
* CONTEXT:
* Might sleep.
*/
void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
{
struct bd_holder_disk *holder;
mutex_lock(&bdev->bd_mutex);
holder = bd_find_holder_disk(bdev, disk);
if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
del_symlink(bdev->bd_part->holder_dir,
&disk_to_dev(disk)->kobj);
kobject_put(bdev->bd_part->holder_dir);
list_del_init(&holder->list);
kfree(holder);
}
mutex_unlock(&bdev->bd_mutex);
}
EXPORT_SYMBOL_GPL(bd_unlink_disk_holder);
#endif
/**
* flush_disk - invalidates all buffer-cache entries on a disk
*
* @bdev: struct block device to be flushed
* @kill_dirty: flag to guide handling of dirty inodes
*
* Invalidates all buffer-cache entries on a disk. It should be called
* when a disk has been changed -- either by a media change or online
* resize.
*/
static void flush_disk(struct block_device *bdev, bool kill_dirty)
{
if (__invalidate_device(bdev, kill_dirty)) {
printk(KERN_WARNING "VFS: busy inodes on changed media or "
"resized disk %s\n",
bdev->bd_disk ? bdev->bd_disk->disk_name : "");
}
if (!bdev->bd_disk)
return;
if (disk_part_scan_enabled(bdev->bd_disk))
bdev->bd_invalidated = 1;
}
/**
* check_disk_size_change - checks for disk size change and adjusts bdev size.
* @disk: struct gendisk to check
* @bdev: struct bdev to adjust.
*
* This routine checks to see if the bdev size does not match the disk size
* and adjusts it if it differs.
*/
void check_disk_size_change(struct gendisk *disk, struct block_device *bdev)
{
loff_t disk_size, bdev_size;
disk_size = (loff_t)get_capacity(disk) << 9;
bdev_size = i_size_read(bdev->bd_inode);
if (disk_size != bdev_size) {
printk(KERN_INFO
"%s: detected capacity change from %lld to %lld\n",
disk->disk_name, bdev_size, disk_size);
i_size_write(bdev->bd_inode, disk_size);
flush_disk(bdev, false);
}
}
EXPORT_SYMBOL(check_disk_size_change);
/**
* revalidate_disk - wrapper for lower-level driver's revalidate_disk call-back
* @disk: struct gendisk to be revalidated
*
* This routine is a wrapper for lower-level driver's revalidate_disk
* call-backs. It is used to do common pre and post operations needed
* for all revalidate_disk operations.
*/
int revalidate_disk(struct gendisk *disk)
{
struct block_device *bdev;
int ret = 0;
if (disk->fops->revalidate_disk)
ret = disk->fops->revalidate_disk(disk);
bdev = bdget_disk(disk, 0);
if (!bdev)
return ret;
mutex_lock(&bdev->bd_mutex);
check_disk_size_change(disk, bdev);
bdev->bd_invalidated = 0;
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
return ret;
}
EXPORT_SYMBOL(revalidate_disk);
/*
* This routine checks whether a removable media has been changed,
* and invalidates all buffer-cache-entries in that case. This
* is a relatively slow routine, so we have to try to minimize using
* it. Thus it is called only upon a 'mount' or 'open'. This
* is the best way of combining speed and utility, I think.
* People changing diskettes in the middle of an operation deserve
* to lose :-)
*/
int check_disk_change(struct block_device *bdev)
{
struct gendisk *disk = bdev->bd_disk;
const struct block_device_operations *bdops = disk->fops;
unsigned int events;
events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
DISK_EVENT_EJECT_REQUEST);
if (!(events & DISK_EVENT_MEDIA_CHANGE))
return 0;
flush_disk(bdev, true);
if (bdops->revalidate_disk)
bdops->revalidate_disk(bdev->bd_disk);
return 1;
}
EXPORT_SYMBOL(check_disk_change);
void bd_set_size(struct block_device *bdev, loff_t size)
{
inode_lock(bdev->bd_inode);
i_size_write(bdev->bd_inode, size);
inode_unlock(bdev->bd_inode);
}
EXPORT_SYMBOL(bd_set_size);
static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
/*
* bd_mutex locking:
*
* mutex_lock(part->bd_mutex)
* mutex_lock_nested(whole->bd_mutex, 1)
*/
static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
{
struct gendisk *disk;
struct module *owner;
int ret;
int partno;
int perm = 0;
if (mode & FMODE_READ)
perm |= MAY_READ;
if (mode & FMODE_WRITE)
perm |= MAY_WRITE;
/*
* hooks: /n/, see "layering violations".
*/
if (!for_part) {
ret = devcgroup_inode_permission(bdev->bd_inode, perm);
if (ret != 0)
return ret;
}
restart:
ret = -ENXIO;
disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk)
goto out;
owner = disk->fops->owner;
disk_block_events(disk);
mutex_lock_nested(&bdev->bd_mutex, for_part);
if (!bdev->bd_openers) {
bdev->bd_disk = disk;
bdev->bd_queue = disk->queue;
bdev->bd_contains = bdev;
if (!partno) {
ret = -ENXIO;
bdev->bd_part = disk_get_part(disk, partno);
if (!bdev->bd_part)
goto out_clear;
ret = 0;
if (disk->fops->open) {
ret = disk->fops->open(bdev, mode);
if (ret == -ERESTARTSYS) {
/* Lost a race with 'disk' being
* deleted, try again.
* See md.c
*/
disk_put_part(bdev->bd_part);
bdev->bd_part = NULL;
bdev->bd_disk = NULL;
bdev->bd_queue = NULL;
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
put_disk(disk);
module_put(owner);
goto restart;
}
}
if (!ret) {
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
set_init_blocksize(bdev);
}
/*
* If the device is invalidated, rescan partition
* if open succeeded or failed with -ENOMEDIUM.
* The latter is necessary to prevent ghost
* partitions on a removed medium.
*/
if (bdev->bd_invalidated) {
if (!ret)
rescan_partitions(disk, bdev);
else if (ret == -ENOMEDIUM)
invalidate_partitions(disk, bdev);
}
if (ret)
goto out_clear;
} else {
struct block_device *whole;
whole = bdget_disk(disk, 0);
ret = -ENOMEM;
if (!whole)
goto out_clear;
BUG_ON(for_part);
ret = __blkdev_get(whole, mode, 1);
if (ret) {
bdput(whole);
goto out_clear;
}
bdev->bd_contains = whole;
bdev->bd_part = disk_get_part(disk, partno);
if (!(disk->flags & GENHD_FL_UP) ||
!bdev->bd_part || !bdev->bd_part->nr_sects) {
ret = -ENXIO;
goto out_clear;
}
bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
set_init_blocksize(bdev);
}
if (bdev->bd_bdi == &noop_backing_dev_info)
bdev->bd_bdi = bdi_get(disk->queue->backing_dev_info);
} else {
if (bdev->bd_contains == bdev) {
ret = 0;
if (bdev->bd_disk->fops->open)
ret = bdev->bd_disk->fops->open(bdev, mode);
/* the same as first opener case, read comment there */
if (bdev->bd_invalidated) {
if (!ret)
rescan_partitions(bdev->bd_disk, bdev);
else if (ret == -ENOMEDIUM)
invalidate_partitions(bdev->bd_disk, bdev);
}
if (ret)
goto out_unlock_bdev;
}
/* only one opener holds refs to the module and disk */
put_disk(disk);
module_put(owner);
}
bdev->bd_openers++;
if (for_part)
bdev->bd_part_count++;
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
return 0;
out_clear:
disk_put_part(bdev->bd_part);
bdev->bd_disk = NULL;
bdev->bd_part = NULL;
bdev->bd_queue = NULL;
if (bdev != bdev->bd_contains)
__blkdev_put(bdev->bd_contains, mode, 1);
bdev->bd_contains = NULL;
out_unlock_bdev:
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
put_disk(disk);
module_put(owner);
out:
return ret;
}
/**
* blkdev_get - open a block device
* @bdev: block_device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open @bdev with @mode. If @mode includes %FMODE_EXCL, @bdev is
* open with exclusive access. Specifying %FMODE_EXCL with %NULL
* @holder is invalid. Exclusive opens may nest for the same @holder.
*
* On success, the reference count of @bdev is unchanged. On failure,
* @bdev is put.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
{
struct block_device *whole = NULL;
int res;
WARN_ON_ONCE((mode & FMODE_EXCL) && !holder);
if ((mode & FMODE_EXCL) && holder) {
whole = bd_start_claiming(bdev, holder);
if (IS_ERR(whole)) {
bdput(bdev);
return PTR_ERR(whole);
}
}
res = __blkdev_get(bdev, mode, 0);
if (whole) {
struct gendisk *disk = whole->bd_disk;
/* finish claiming */
mutex_lock(&bdev->bd_mutex);
spin_lock(&bdev_lock);
if (!res) {
BUG_ON(!bd_may_claim(bdev, whole, holder));
/*
* Note that for a whole device bd_holders
* will be incremented twice, and bd_holder
* will be set to bd_may_claim before being
* set to holder
*/
whole->bd_holders++;
whole->bd_holder = bd_may_claim;
bdev->bd_holders++;
bdev->bd_holder = holder;
}
/* tell others that we're done */
BUG_ON(whole->bd_claiming != holder);
whole->bd_claiming = NULL;
wake_up_bit(&whole->bd_claiming, 0);
spin_unlock(&bdev_lock);
/*
* Block event polling for write claims if requested. Any
* write holder makes the write_holder state stick until
* all are released. This is good enough and tracking
* individual writeable reference is too fragile given the
* way @mode is used in blkdev_get/put().
*/
if (!res && (mode & FMODE_WRITE) && !bdev->bd_write_holder &&
(disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE)) {
bdev->bd_write_holder = true;
disk_block_events(disk);
}
mutex_unlock(&bdev->bd_mutex);
bdput(whole);
}
if (res)
bdput(bdev);
return res;
}
EXPORT_SYMBOL(blkdev_get);
/**
* blkdev_get_by_path - open a block device by name
* @path: path to the block device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open the blockdevice described by the device file at @path. @mode
* and @holder are identical to blkdev_get().
*
* On success, the returned block_device has reference count of one.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to block_device on success, ERR_PTR(-errno) on failure.
*/
struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
void *holder)
{
struct block_device *bdev;
int err;
bdev = lookup_bdev(path);
if (IS_ERR(bdev))
return bdev;
err = blkdev_get(bdev, mode, holder);
if (err)
return ERR_PTR(err);
if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) {
blkdev_put(bdev, mode);
return ERR_PTR(-EACCES);
}
return bdev;
}
EXPORT_SYMBOL(blkdev_get_by_path);
/**
* blkdev_get_by_dev - open a block device by device number
* @dev: device number of block device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open the blockdevice described by device number @dev. @mode and
* @holder are identical to blkdev_get().
*
* Use it ONLY if you really do not have anything better - i.e. when
* you are behind a truly sucky interface and all you are given is a
* device number. _Never_ to be used for internal purposes. If you
* ever need it - reconsider your API.
*
* On success, the returned block_device has reference count of one.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to block_device on success, ERR_PTR(-errno) on failure.
*/
struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)
{
struct block_device *bdev;
int err;
bdev = bdget(dev);
if (!bdev)
return ERR_PTR(-ENOMEM);
err = blkdev_get(bdev, mode, holder);
if (err)
return ERR_PTR(err);
return bdev;
}
EXPORT_SYMBOL(blkdev_get_by_dev);
static int blkdev_open(struct inode * inode, struct file * filp)
{
struct block_device *bdev;
/*
* Preserve backwards compatibility and allow large file access
* even if userspace doesn't ask for it explicitly. Some mkfs
* binary needs it. We might want to drop this workaround
* during an unstable branch.
*/
filp->f_flags |= O_LARGEFILE;
if (filp->f_flags & O_NDELAY)
filp->f_mode |= FMODE_NDELAY;
if (filp->f_flags & O_EXCL)
filp->f_mode |= FMODE_EXCL;
if ((filp->f_flags & O_ACCMODE) == 3)
filp->f_mode |= FMODE_WRITE_IOCTL;
bdev = bd_acquire(inode);
if (bdev == NULL)
return -ENOMEM;
filp->f_mapping = bdev->bd_inode->i_mapping;
return blkdev_get(bdev, filp->f_mode, filp);
}
static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
{
struct gendisk *disk = bdev->bd_disk;
struct block_device *victim = NULL;
/*
* Sync early if it looks like we're the last one. If someone else
* opens the block device between now and the decrement of bd_openers
* then we did a sync that we didn't need to, but that's not the end
* of the world and we want to avoid long (could be several minute)
* syncs while holding the mutex.
*/
if (bdev->bd_openers == 1)
sync_blockdev(bdev);
mutex_lock_nested(&bdev->bd_mutex, for_part);
if (for_part)
bdev->bd_part_count--;
if (!--bdev->bd_openers) {
WARN_ON_ONCE(bdev->bd_holders);
sync_blockdev(bdev);
kill_bdev(bdev);
bdev_write_inode(bdev);
}
if (bdev->bd_contains == bdev) {
if (disk->fops->release)
disk->fops->release(disk, mode);
}
if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner;
disk_put_part(bdev->bd_part);
bdev->bd_part = NULL;
bdev->bd_disk = NULL;
if (bdev != bdev->bd_contains)
victim = bdev->bd_contains;
bdev->bd_contains = NULL;
put_disk(disk);
module_put(owner);
}
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
if (victim)
__blkdev_put(victim, mode, 1);
}
void blkdev_put(struct block_device *bdev, fmode_t mode)
{
mutex_lock(&bdev->bd_mutex);
if (mode & FMODE_EXCL) {
bool bdev_free;
/*
* Release a claim on the device. The holder fields
* are protected with bdev_lock. bd_mutex is to
* synchronize disk_holder unlinking.
*/
spin_lock(&bdev_lock);
WARN_ON_ONCE(--bdev->bd_holders < 0);
WARN_ON_ONCE(--bdev->bd_contains->bd_holders < 0);
/* bd_contains might point to self, check in a separate step */
if ((bdev_free = !bdev->bd_holders))
bdev->bd_holder = NULL;
if (!bdev->bd_contains->bd_holders)
bdev->bd_contains->bd_holder = NULL;
spin_unlock(&bdev_lock);
/*
* If this was the last claim, remove holder link and
* unblock evpoll if it was a write holder.
*/
if (bdev_free && bdev->bd_write_holder) {
disk_unblock_events(bdev->bd_disk);
bdev->bd_write_holder = false;
}
}
/*
* Trigger event checking and tell drivers to flush MEDIA_CHANGE
* event. This is to ensure detection of media removal commanded
* from userland - e.g. eject(1).
*/
disk_flush_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE);
mutex_unlock(&bdev->bd_mutex);
__blkdev_put(bdev, mode, 0);
}
EXPORT_SYMBOL(blkdev_put);
static int blkdev_close(struct inode * inode, struct file * filp)
{
struct block_device *bdev = I_BDEV(bdev_file_inode(filp));
blkdev_put(bdev, filp->f_mode);
return 0;
}
static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
{
struct block_device *bdev = I_BDEV(bdev_file_inode(file));
fmode_t mode = file->f_mode;
/*
* O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
* to updated it before every ioctl.
*/
if (file->f_flags & O_NDELAY)
mode |= FMODE_NDELAY;
else
mode &= ~FMODE_NDELAY;
return blkdev_ioctl(bdev, mode, cmd, arg);
}
/*
* Write data to the block device. Only intended for the block device itself
* and the raw driver which basically is a fake block device.
*
* Does not take i_mutex for the write and thus is not for general purpose
* use.
*/
ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct file *file = iocb->ki_filp;
struct inode *bd_inode = bdev_file_inode(file);
loff_t size = i_size_read(bd_inode);
struct blk_plug plug;
ssize_t ret;
if (bdev_read_only(I_BDEV(bd_inode)))
return -EPERM;
if (!iov_iter_count(from))
return 0;
if (iocb->ki_pos >= size)
return -ENOSPC;
iov_iter_truncate(from, size - iocb->ki_pos);
blk_start_plug(&plug);
ret = __generic_file_write_iter(iocb, from);
if (ret > 0)
ret = generic_write_sync(iocb, ret);
blk_finish_plug(&plug);
return ret;
}
EXPORT_SYMBOL_GPL(blkdev_write_iter);
ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct file *file = iocb->ki_filp;
struct inode *bd_inode = bdev_file_inode(file);
loff_t size = i_size_read(bd_inode);
loff_t pos = iocb->ki_pos;
if (pos >= size)
return 0;
size -= pos;
iov_iter_truncate(to, size);
return generic_file_read_iter(iocb, to);
}
EXPORT_SYMBOL_GPL(blkdev_read_iter);
/*
* Try to release a page associated with block device when the system
* is under memory pressure.
*/
static int blkdev_releasepage(struct page *page, gfp_t wait)
{
struct super_block *super = BDEV_I(page->mapping->host)->bdev.bd_super;
if (super && super->s_op->bdev_try_to_free_page)
return super->s_op->bdev_try_to_free_page(super, page, wait);
return try_to_free_buffers(page);
}
static int blkdev_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
if (dax_mapping(mapping)) {
struct block_device *bdev = I_BDEV(mapping->host);
return dax_writeback_mapping_range(mapping, bdev, wbc);
}
return generic_writepages(mapping, wbc);
}
static const struct address_space_operations def_blk_aops = {
.readpage = blkdev_readpage,
.readpages = blkdev_readpages,
.writepage = blkdev_writepage,
.write_begin = blkdev_write_begin,
.write_end = blkdev_write_end,
.writepages = blkdev_writepages,
.releasepage = blkdev_releasepage,
.direct_IO = blkdev_direct_IO,
.is_dirty_writeback = buffer_check_dirty_writeback,
};
#define BLKDEV_FALLOC_FL_SUPPORTED \
(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE)
static long blkdev_fallocate(struct file *file, int mode, loff_t start,
loff_t len)
{
struct block_device *bdev = I_BDEV(bdev_file_inode(file));
struct request_queue *q = bdev_get_queue(bdev);
struct address_space *mapping;
loff_t end = start + len - 1;
loff_t isize;
int error;
/* Fail if we don't recognize the flags. */
if (mode & ~BLKDEV_FALLOC_FL_SUPPORTED)
return -EOPNOTSUPP;
/* Don't go off the end of the device. */
isize = i_size_read(bdev->bd_inode);
if (start >= isize)
return -EINVAL;
if (end >= isize) {
if (mode & FALLOC_FL_KEEP_SIZE) {
len = isize - start;
end = start + len - 1;
} else
return -EINVAL;
}
/*
* Don't allow IO that isn't aligned to logical block size.
*/
if ((start | len) & (bdev_logical_block_size(bdev) - 1))
return -EINVAL;
/* Invalidate the page cache, including dirty pages. */
mapping = bdev->bd_inode->i_mapping;
truncate_inode_pages_range(mapping, start, end);
switch (mode) {
case FALLOC_FL_ZERO_RANGE:
case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE:
error = blkdev_issue_zeroout(bdev, start >> 9, len >> 9,
GFP_KERNEL, false);
break;
case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE:
/* Only punch if the device can do zeroing discard. */
if (!blk_queue_discard(q) || !q->limits.discard_zeroes_data)
return -EOPNOTSUPP;
error = blkdev_issue_discard(bdev, start >> 9, len >> 9,
GFP_KERNEL, 0);
break;
case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE:
if (!blk_queue_discard(q))
return -EOPNOTSUPP;
error = blkdev_issue_discard(bdev, start >> 9, len >> 9,
GFP_KERNEL, 0);
break;
default:
return -EOPNOTSUPP;
}
if (error)
return error;
/*
* Invalidate again; if someone wandered in and dirtied a page,
* the caller will be given -EBUSY. The third argument is
* inclusive, so the rounding here is safe.
*/
return invalidate_inode_pages2_range(mapping,
start >> PAGE_SHIFT,
end >> PAGE_SHIFT);
}
const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_close,
.llseek = block_llseek,
.read_iter = blkdev_read_iter,
.write_iter = blkdev_write_iter,
.mmap = generic_file_mmap,
.fsync = blkdev_fsync,
.unlocked_ioctl = block_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_blkdev_ioctl,
#endif
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
.fallocate = blkdev_fallocate,
};
int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
{
int res;
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
res = blkdev_ioctl(bdev, 0, cmd, arg);
set_fs(old_fs);
return res;
}
EXPORT_SYMBOL(ioctl_by_bdev);
/**
* lookup_bdev - lookup a struct block_device by name
* @pathname: special file representing the block device
*
* Get a reference to the blockdevice at @pathname in the current
* namespace if possible and return it. Return ERR_PTR(error)
* otherwise.
*/
struct block_device *lookup_bdev(const char *pathname)
{
struct block_device *bdev;
struct inode *inode;
struct path path;
int error;
if (!pathname || !*pathname)
return ERR_PTR(-EINVAL);
error = kern_path(pathname, LOOKUP_FOLLOW, &path);
if (error)
return ERR_PTR(error);
inode = d_backing_inode(path.dentry);
error = -ENOTBLK;
if (!S_ISBLK(inode->i_mode))
goto fail;
error = -EACCES;
if (!may_open_dev(&path))
goto fail;
error = -ENOMEM;
bdev = bd_acquire(inode);
if (!bdev)
goto fail;
out:
path_put(&path);
return bdev;
fail:
bdev = ERR_PTR(error);
goto out;
}
EXPORT_SYMBOL(lookup_bdev);
int __invalidate_device(struct block_device *bdev, bool kill_dirty)
{
struct super_block *sb = get_super(bdev);
int res = 0;
if (sb) {
/*
* no need to lock the super, get_super holds the
* read mutex so the filesystem cannot go away
* under us (->put_super runs with the write lock
* hold).
*/
shrink_dcache_sb(sb);
res = invalidate_inodes(sb, kill_dirty);
drop_super(sb);
}
invalidate_bdev(bdev);
return res;
}
EXPORT_SYMBOL(__invalidate_device);
void iterate_bdevs(void (*func)(struct block_device *, void *), void *arg)
{
struct inode *inode, *old_inode = NULL;
spin_lock(&blockdev_superblock->s_inode_list_lock);
list_for_each_entry(inode, &blockdev_superblock->s_inodes, i_sb_list) {
struct address_space *mapping = inode->i_mapping;
struct block_device *bdev;
spin_lock(&inode->i_lock);
if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW) ||
mapping->nrpages == 0) {
spin_unlock(&inode->i_lock);
continue;
}
__iget(inode);
spin_unlock(&inode->i_lock);
spin_unlock(&blockdev_superblock->s_inode_list_lock);
/*
* We hold a reference to 'inode' so it couldn't have been
* removed from s_inodes list while we dropped the
* s_inode_list_lock We cannot iput the inode now as we can
* be holding the last reference and we cannot iput it under
* s_inode_list_lock. So we keep the reference and iput it
* later.
*/
iput(old_inode);
old_inode = inode;
bdev = I_BDEV(inode);
mutex_lock(&bdev->bd_mutex);
if (bdev->bd_openers)
func(bdev, arg);
mutex_unlock(&bdev->bd_mutex);
spin_lock(&blockdev_superblock->s_inode_list_lock);
}
spin_unlock(&blockdev_superblock->s_inode_list_lock);
iput(old_inode);
}