Changes in 4.9.215 x86/vdso: Use RDPID in preference to LSL when available KVM: x86: emulate RDPID ALSA: hda: Use scnprintf() for printing texts for sysfs/procfs ecryptfs: fix a memory leak bug in parse_tag_1_packet() ecryptfs: fix a memory leak bug in ecryptfs_init_messaging() ALSA: usb-audio: Apply sample rate quirk for Audioengine D1 ext4: don't assume that mmp_nodename/bdevname have NUL ext4: fix checksum errors with indexed dirs ext4: improve explanation of a mount failure caused by a misconfigured kernel Btrfs: fix race between using extent maps and merging them btrfs: log message when rw remount is attempted with unclean tree-log perf/x86/amd: Add missing L2 misses event spec to AMD Family 17h's event map padata: Remove broken queue flushing s390/time: Fix clk type in get_tod_clock perf/x86/intel: Fix inaccurate period in context switch for auto-reload hwmon: (pmbus/ltc2978) Fix PMBus polling of MFR_COMMON definitions. jbd2: move the clearing of b_modified flag to the journal_unmap_buffer() jbd2: do not clear the BH_Mapped flag when forgetting a metadata buffer btrfs: print message when tree-log replay starts scsi: qla2xxx: fix a potential NULL pointer dereference Revert "KVM: VMX: Add non-canonical check on writes to RTIT address MSRs" drm/gma500: Fixup fbdev stolen size usage evaluation cpu/hotplug, stop_machine: Fix stop_machine vs hotplug order brcmfmac: Fix use after free in brcmf_sdio_readframes() gianfar: Fix TX timestamping with a stacked DSA driver pinctrl: sh-pfc: sh7264: Fix CAN function GPIOs pxa168fb: Fix the function used to release some memory in an error handling path media: i2c: mt9v032: fix enum mbus codes and frame sizes powerpc/powernv/iov: Ensure the pdn for VFs always contains a valid PE number gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_irq_map/unmap() media: sti: bdisp: fix a possible sleep-in-atomic-context bug in bdisp_device_run() pinctrl: baytrail: Do not clear IRQ flags on direct-irq enabled pins efi/x86: Map the entire EFI vendor string before copying it MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() sparc: Add .exit.data section. uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol() usb: gadget: udc: fix possible sleep-in-atomic-context bugs in gr_probe() jbd2: clear JBD2_ABORT flag before journal_reset to update log tail info when load journal x86/sysfb: Fix check for bad VRAM size tracing: Fix tracing_stat return values in error handling paths tracing: Fix very unlikely race of registering two stat tracers ext4, jbd2: ensure panic when aborting with zero errno kconfig: fix broken dependency in randconfig-generated .config clk: qcom: rcg2: Don't crash if our parent can't be found; return an error drm/amdgpu: remove 4 set but not used variable in amdgpu_atombios_get_connector_info_from_object_table regulator: rk808: Lower log level on optional GPIOs being not available net/wan/fsl_ucc_hdlc: reject muram offsets above 64K PCI/IOV: Fix memory leak in pci_iov_add_virtfn() NFC: port100: Convert cpu_to_le16(le16_to_cpu(E1) + E2) to use le16_add_cpu(). media: v4l2-device.h: Explicitly compare grp{id,mask} to zero in v4l2_device macros reiserfs: Fix spurious unlock in reiserfs_fill_super() error handling ALSA: usx2y: Adjust indentation in snd_usX2Y_hwdep_dsp_status b43legacy: Fix -Wcast-function-type ipw2x00: Fix -Wcast-function-type iwlegacy: Fix -Wcast-function-type rtlwifi: rtl_pci: Fix -Wcast-function-type orinoco: avoid assertion in case of NULL pointer ACPICA: Disassembler: create buffer fields in ACPI_PARSE_LOAD_PASS1 scsi: aic7xxx: Adjust indentation in ahc_find_syncrate drm/mediatek: handle events when enabling/disabling crtc ARM: dts: r8a7779: Add device node for ARM global timer x86/vdso: Provide missing include file PM / devfreq: rk3399_dmc: Add COMPILE_TEST and HAVE_ARM_SMCCC dependency pinctrl: sh-pfc: sh7269: Fix CAN function GPIOs RDMA/rxe: Fix error type of mmap_offset ALSA: sh: Fix compile warning wrt const tools lib api fs: Fix gcc9 stringop-truncation compilation error usbip: Fix unsafe unaligned pointer usage udf: Fix free space reporting for metadata and virtual partitions soc/tegra: fuse: Correct straps' address for older Tegra124 device trees rcu: Use WRITE_ONCE() for assignments to ->pprev for hlist_nulls Input: edt-ft5x06 - work around first register access error wan: ixp4xx_hss: fix compile-testing on 64-bit ASoC: atmel: fix build error with CONFIG_SND_ATMEL_SOC_DMA=m tty: synclinkmp: Adjust indentation in several functions tty: synclink_gt: Adjust indentation in several functions driver core: platform: Prevent resouce overflow from causing infinite loops driver core: Print device when resources present in really_probe() vme: bridges: reduce stack usage drm/nouveau/gr/gk20a,gm200-: add terminators to method lists read from fw drm/nouveau: Fix copy-paste error in nouveau_fence_wait_uevent_handler drm/vmwgfx: prevent memory leak in vmw_cmdbuf_res_add usb: musb: omap2430: Get rid of musb .set_vbus for omap2430 glue iommu/arm-smmu-v3: Use WRITE_ONCE() when changing validity of an STE scsi: iscsi: Don't destroy session if there are outstanding connections arm64: fix alternatives with LLVM's integrated assembler pwm: omap-dmtimer: Remove PWM chip in .remove before making it unfunctional cmd64x: potential buffer overflow in cmd64x_program_timings() ide: serverworks: potential overflow in svwks_set_pio_mode() remoteproc: Initialize rproc_class before use x86/decoder: Add TEST opcode to Group3-2 s390/ftrace: generate traced function stack frame driver core: platform: fix u32 greater or equal to zero comparison ALSA: hda - Add docking station support for Lenovo Thinkpad T420s powerpc/sriov: Remove VF eeh_dev state when disabling SR-IOV jbd2: switch to use jbd2_journal_abort() when failed to submit the commit record ARM: 8951/1: Fix Kexec compilation issue. hostap: Adjust indentation in prism2_hostapd_add_sta iwlegacy: ensure loop counter addr does not wrap and cause an infinite loop cifs: fix NULL dereference in match_prepath irqchip/gic-v3: Only provision redistributors that are enabled in ACPI drm/nouveau/disp/nv50-: prevent oops when no channel method map provided ftrace: fpid_next() should increase position index trigger_next should increase position index radeon: insert 10ms sleep in dce5_crtc_load_lut ocfs2: fix a NULL pointer dereference when call ocfs2_update_inode_fsync_trans() lib/scatterlist.c: adjust indentation in __sg_alloc_table reiserfs: prevent NULL pointer dereference in reiserfs_insert_item() bcache: explicity type cast in bset_bkey_last() irqchip/gic-v3-its: Reference to its_invall_cmd descriptor when building INVALL iwlwifi: mvm: Fix thermal zone registration microblaze: Prevent the overflow of the start brd: check and limit max_part par help_next should increase position index selinux: ensure we cleanup the internal AVC counters on error in avc_update() enic: prevent waking up stopped tx queues over watchdog reset net/sched: matchall: add missing validation of TCA_MATCHALL_FLAGS net/sched: flower: add missing validation of TCA_FLOWER_FLAGS floppy: check FDC index for errors before assigning it vt: selection, handle pending signals in paste_selection staging: android: ashmem: Disallow ashmem memory from being remapped staging: vt6656: fix sign of rx_dbm to bb_pre_ed_rssi. xhci: Force Maximum Packet size for Full-speed bulk devices to valid range. usb: uas: fix a plug & unplug racing USB: Fix novation SourceControl XL after suspend USB: hub: Don't record a connect-change event during reset-resume staging: rtl8188eu: Fix potential security hole staging: rtl8188eu: Fix potential overuse of kernel memory x86/mce/amd: Publish the bank pointer only after setup has succeeded x86/mce/amd: Fix kobject lifetime tty/serial: atmel: manage shutdown in case of RS485 or ISO7816 mode tty: serial: imx: setup the correct sg entry for tx dma Revert "ipc,sem: remove uneeded sem_undo_list lock usage in exit_sem()" xhci: apply XHCI_PME_STUCK_QUIRK to Intel Comet Lake platforms KVM: x86: don't notify userspace IOAPIC on edge-triggered interrupt EOI VT_RESIZEX: get rid of field-by-field copyin vt: vt_ioctl: fix race in VT_RESIZEX lib/stackdepot.c: fix global out-of-bounds in stack_slabs KVM: nVMX: Don't emulate instructions in guest mode netfilter: xt_bpf: add overflow checks ext4: fix a data race in EXT4_I(inode)->i_disksize ext4: add cond_resched() to __ext4_find_entry() ext4: fix mount failure with quota configured as module ext4: rename s_journal_flag_rwsem to s_writepages_rwsem ext4: fix race between writepages and enabling EXT4_EXTENTS_FL KVM: nVMX: Refactor IO bitmap checks into helper function KVM: nVMX: Check IO instruction VM-exit conditions KVM: apic: avoid calculating pending eoi from an uninitialized val Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents scsi: Revert "RDMA/isert: Fix a recently introduced regression related to logout" scsi: Revert "target: iscsi: Wait for all commands to finish before freeing a session" usb: gadget: composite: Fix bMaxPower for SuperSpeedPlus staging: greybus: use after free in gb_audio_manager_remove_all() ecryptfs: replace BUG_ON with error handling code ALSA: rawmidi: Avoid bit fields for state flags ALSA: seq: Avoid concurrent access to queue flags ALSA: seq: Fix concurrent access to queue current tick/time netfilter: xt_hashlimit: limit the max size of hashtable ata: ahci: Add shutdown to freeze hardware resources of ahci xen: Enable interrupts when calling _cond_resched() s390/mm: Explicitly compare PAGE_DEFAULT_KEY against zero in storage_key_init_range Linux 4.9.215 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I4c663321dde48cd2a324e59acb70c99f75f9344e
670 lines
19 KiB
C
670 lines
19 KiB
C
/*
|
|
* linux/fs/jbd2/checkpoint.c
|
|
*
|
|
* Written by Stephen C. Tweedie <sct@redhat.com>, 1999
|
|
*
|
|
* Copyright 1999 Red Hat Software --- All Rights Reserved
|
|
*
|
|
* This file is part of the Linux kernel and is made available under
|
|
* the terms of the GNU General Public License, version 2, or at your
|
|
* option, any later version, incorporated herein by reference.
|
|
*
|
|
* Checkpoint routines for the generic filesystem journaling code.
|
|
* Part of the ext2fs journaling system.
|
|
*
|
|
* Checkpointing is the process of ensuring that a section of the log is
|
|
* committed fully to disk, so that that portion of the log can be
|
|
* reused.
|
|
*/
|
|
|
|
#include <linux/time.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/jbd2.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/blkdev.h>
|
|
#include <trace/events/jbd2.h>
|
|
|
|
/*
|
|
* Unlink a buffer from a transaction checkpoint list.
|
|
*
|
|
* Called with j_list_lock held.
|
|
*/
|
|
static inline void __buffer_unlink_first(struct journal_head *jh)
|
|
{
|
|
transaction_t *transaction = jh->b_cp_transaction;
|
|
|
|
jh->b_cpnext->b_cpprev = jh->b_cpprev;
|
|
jh->b_cpprev->b_cpnext = jh->b_cpnext;
|
|
if (transaction->t_checkpoint_list == jh) {
|
|
transaction->t_checkpoint_list = jh->b_cpnext;
|
|
if (transaction->t_checkpoint_list == jh)
|
|
transaction->t_checkpoint_list = NULL;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Unlink a buffer from a transaction checkpoint(io) list.
|
|
*
|
|
* Called with j_list_lock held.
|
|
*/
|
|
static inline void __buffer_unlink(struct journal_head *jh)
|
|
{
|
|
transaction_t *transaction = jh->b_cp_transaction;
|
|
|
|
__buffer_unlink_first(jh);
|
|
if (transaction->t_checkpoint_io_list == jh) {
|
|
transaction->t_checkpoint_io_list = jh->b_cpnext;
|
|
if (transaction->t_checkpoint_io_list == jh)
|
|
transaction->t_checkpoint_io_list = NULL;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Move a buffer from the checkpoint list to the checkpoint io list
|
|
*
|
|
* Called with j_list_lock held
|
|
*/
|
|
static inline void __buffer_relink_io(struct journal_head *jh)
|
|
{
|
|
transaction_t *transaction = jh->b_cp_transaction;
|
|
|
|
__buffer_unlink_first(jh);
|
|
|
|
if (!transaction->t_checkpoint_io_list) {
|
|
jh->b_cpnext = jh->b_cpprev = jh;
|
|
} else {
|
|
jh->b_cpnext = transaction->t_checkpoint_io_list;
|
|
jh->b_cpprev = transaction->t_checkpoint_io_list->b_cpprev;
|
|
jh->b_cpprev->b_cpnext = jh;
|
|
jh->b_cpnext->b_cpprev = jh;
|
|
}
|
|
transaction->t_checkpoint_io_list = jh;
|
|
}
|
|
|
|
/*
|
|
* Try to release a checkpointed buffer from its transaction.
|
|
* Returns 1 if we released it and 2 if we also released the
|
|
* whole transaction.
|
|
*
|
|
* Requires j_list_lock
|
|
*/
|
|
static int __try_to_free_cp_buf(struct journal_head *jh)
|
|
{
|
|
int ret = 0;
|
|
struct buffer_head *bh = jh2bh(jh);
|
|
|
|
if (jh->b_transaction == NULL && !buffer_locked(bh) &&
|
|
!buffer_dirty(bh) && !buffer_write_io_error(bh)) {
|
|
JBUFFER_TRACE(jh, "remove from checkpoint list");
|
|
ret = __jbd2_journal_remove_checkpoint(jh) + 1;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* __jbd2_log_wait_for_space: wait until there is space in the journal.
|
|
*
|
|
* Called under j-state_lock *only*. It will be unlocked if we have to wait
|
|
* for a checkpoint to free up some space in the log.
|
|
*/
|
|
void __jbd2_log_wait_for_space(journal_t *journal)
|
|
{
|
|
int nblocks, space_left;
|
|
/* assert_spin_locked(&journal->j_state_lock); */
|
|
|
|
nblocks = jbd2_space_needed(journal);
|
|
while (jbd2_log_space_left(journal) < nblocks) {
|
|
write_unlock(&journal->j_state_lock);
|
|
mutex_lock(&journal->j_checkpoint_mutex);
|
|
|
|
/*
|
|
* Test again, another process may have checkpointed while we
|
|
* were waiting for the checkpoint lock. If there are no
|
|
* transactions ready to be checkpointed, try to recover
|
|
* journal space by calling cleanup_journal_tail(), and if
|
|
* that doesn't work, by waiting for the currently committing
|
|
* transaction to complete. If there is absolutely no way
|
|
* to make progress, this is either a BUG or corrupted
|
|
* filesystem, so abort the journal and leave a stack
|
|
* trace for forensic evidence.
|
|
*/
|
|
write_lock(&journal->j_state_lock);
|
|
if (journal->j_flags & JBD2_ABORT) {
|
|
mutex_unlock(&journal->j_checkpoint_mutex);
|
|
return;
|
|
}
|
|
spin_lock(&journal->j_list_lock);
|
|
nblocks = jbd2_space_needed(journal);
|
|
space_left = jbd2_log_space_left(journal);
|
|
if (space_left < nblocks) {
|
|
int chkpt = journal->j_checkpoint_transactions != NULL;
|
|
tid_t tid = 0;
|
|
|
|
if (journal->j_committing_transaction)
|
|
tid = journal->j_committing_transaction->t_tid;
|
|
spin_unlock(&journal->j_list_lock);
|
|
write_unlock(&journal->j_state_lock);
|
|
if (chkpt) {
|
|
jbd2_log_do_checkpoint(journal);
|
|
} else if (jbd2_cleanup_journal_tail(journal) == 0) {
|
|
/* We were able to recover space; yay! */
|
|
;
|
|
} else if (tid) {
|
|
/*
|
|
* jbd2_journal_commit_transaction() may want
|
|
* to take the checkpoint_mutex if JBD2_FLUSHED
|
|
* is set. So we need to temporarily drop it.
|
|
*/
|
|
mutex_unlock(&journal->j_checkpoint_mutex);
|
|
jbd2_log_wait_commit(journal, tid);
|
|
write_lock(&journal->j_state_lock);
|
|
continue;
|
|
} else {
|
|
printk(KERN_ERR "%s: needed %d blocks and "
|
|
"only had %d space available\n",
|
|
__func__, nblocks, space_left);
|
|
printk(KERN_ERR "%s: no way to get more "
|
|
"journal space in %s\n", __func__,
|
|
journal->j_devname);
|
|
WARN_ON(1);
|
|
jbd2_journal_abort(journal, -EIO);
|
|
}
|
|
write_lock(&journal->j_state_lock);
|
|
} else {
|
|
spin_unlock(&journal->j_list_lock);
|
|
}
|
|
mutex_unlock(&journal->j_checkpoint_mutex);
|
|
}
|
|
}
|
|
|
|
static void
|
|
__flush_batch(journal_t *journal, int *batch_count)
|
|
{
|
|
int i;
|
|
struct blk_plug plug;
|
|
|
|
blk_start_plug(&plug);
|
|
for (i = 0; i < *batch_count; i++)
|
|
write_dirty_buffer(journal->j_chkpt_bhs[i], WRITE_SYNC);
|
|
blk_finish_plug(&plug);
|
|
|
|
for (i = 0; i < *batch_count; i++) {
|
|
struct buffer_head *bh = journal->j_chkpt_bhs[i];
|
|
BUFFER_TRACE(bh, "brelse");
|
|
__brelse(bh);
|
|
}
|
|
*batch_count = 0;
|
|
}
|
|
|
|
/*
|
|
* Perform an actual checkpoint. We take the first transaction on the
|
|
* list of transactions to be checkpointed and send all its buffers
|
|
* to disk. We submit larger chunks of data at once.
|
|
*
|
|
* The journal should be locked before calling this function.
|
|
* Called with j_checkpoint_mutex held.
|
|
*/
|
|
int jbd2_log_do_checkpoint(journal_t *journal)
|
|
{
|
|
struct journal_head *jh;
|
|
struct buffer_head *bh;
|
|
transaction_t *transaction;
|
|
tid_t this_tid;
|
|
int result, batch_count = 0;
|
|
|
|
jbd_debug(1, "Start checkpoint\n");
|
|
|
|
/*
|
|
* First thing: if there are any transactions in the log which
|
|
* don't need checkpointing, just eliminate them from the
|
|
* journal straight away.
|
|
*/
|
|
result = jbd2_cleanup_journal_tail(journal);
|
|
trace_jbd2_checkpoint(journal, result);
|
|
jbd_debug(1, "cleanup_journal_tail returned %d\n", result);
|
|
if (result <= 0)
|
|
return result;
|
|
|
|
/*
|
|
* OK, we need to start writing disk blocks. Take one transaction
|
|
* and write it.
|
|
*/
|
|
result = 0;
|
|
spin_lock(&journal->j_list_lock);
|
|
if (!journal->j_checkpoint_transactions)
|
|
goto out;
|
|
transaction = journal->j_checkpoint_transactions;
|
|
if (transaction->t_chp_stats.cs_chp_time == 0)
|
|
transaction->t_chp_stats.cs_chp_time = jiffies;
|
|
this_tid = transaction->t_tid;
|
|
restart:
|
|
/*
|
|
* If someone cleaned up this transaction while we slept, we're
|
|
* done (maybe it's a new transaction, but it fell at the same
|
|
* address).
|
|
*/
|
|
if (journal->j_checkpoint_transactions != transaction ||
|
|
transaction->t_tid != this_tid)
|
|
goto out;
|
|
|
|
/* checkpoint all of the transaction's buffers */
|
|
while (transaction->t_checkpoint_list) {
|
|
jh = transaction->t_checkpoint_list;
|
|
bh = jh2bh(jh);
|
|
|
|
if (buffer_locked(bh)) {
|
|
get_bh(bh);
|
|
spin_unlock(&journal->j_list_lock);
|
|
wait_on_buffer(bh);
|
|
/* the journal_head may have gone by now */
|
|
BUFFER_TRACE(bh, "brelse");
|
|
__brelse(bh);
|
|
goto retry;
|
|
}
|
|
if (jh->b_transaction != NULL) {
|
|
transaction_t *t = jh->b_transaction;
|
|
tid_t tid = t->t_tid;
|
|
|
|
transaction->t_chp_stats.cs_forced_to_close++;
|
|
spin_unlock(&journal->j_list_lock);
|
|
if (unlikely(journal->j_flags & JBD2_UNMOUNT))
|
|
/*
|
|
* The journal thread is dead; so
|
|
* starting and waiting for a commit
|
|
* to finish will cause us to wait for
|
|
* a _very_ long time.
|
|
*/
|
|
printk(KERN_ERR
|
|
"JBD2: %s: Waiting for Godot: block %llu\n",
|
|
journal->j_devname, (unsigned long long) bh->b_blocknr);
|
|
|
|
jbd2_log_start_commit(journal, tid);
|
|
jbd2_log_wait_commit(journal, tid);
|
|
goto retry;
|
|
}
|
|
if (!buffer_dirty(bh)) {
|
|
if (unlikely(buffer_write_io_error(bh)) && !result)
|
|
result = -EIO;
|
|
BUFFER_TRACE(bh, "remove from checkpoint");
|
|
if (__jbd2_journal_remove_checkpoint(jh))
|
|
/* The transaction was released; we're done */
|
|
goto out;
|
|
continue;
|
|
}
|
|
/*
|
|
* Important: we are about to write the buffer, and
|
|
* possibly block, while still holding the journal
|
|
* lock. We cannot afford to let the transaction
|
|
* logic start messing around with this buffer before
|
|
* we write it to disk, as that would break
|
|
* recoverability.
|
|
*/
|
|
BUFFER_TRACE(bh, "queue");
|
|
get_bh(bh);
|
|
J_ASSERT_BH(bh, !buffer_jwrite(bh));
|
|
journal->j_chkpt_bhs[batch_count++] = bh;
|
|
__buffer_relink_io(jh);
|
|
transaction->t_chp_stats.cs_written++;
|
|
if ((batch_count == JBD2_NR_BATCH) ||
|
|
need_resched() ||
|
|
spin_needbreak(&journal->j_list_lock))
|
|
goto unlock_and_flush;
|
|
}
|
|
|
|
if (batch_count) {
|
|
unlock_and_flush:
|
|
spin_unlock(&journal->j_list_lock);
|
|
retry:
|
|
if (batch_count)
|
|
__flush_batch(journal, &batch_count);
|
|
spin_lock(&journal->j_list_lock);
|
|
goto restart;
|
|
}
|
|
|
|
/*
|
|
* Now we issued all of the transaction's buffers, let's deal
|
|
* with the buffers that are out for I/O.
|
|
*/
|
|
restart2:
|
|
/* Did somebody clean up the transaction in the meanwhile? */
|
|
if (journal->j_checkpoint_transactions != transaction ||
|
|
transaction->t_tid != this_tid)
|
|
goto out;
|
|
|
|
while (transaction->t_checkpoint_io_list) {
|
|
jh = transaction->t_checkpoint_io_list;
|
|
bh = jh2bh(jh);
|
|
if (buffer_locked(bh)) {
|
|
get_bh(bh);
|
|
spin_unlock(&journal->j_list_lock);
|
|
wait_on_buffer(bh);
|
|
/* the journal_head may have gone by now */
|
|
BUFFER_TRACE(bh, "brelse");
|
|
__brelse(bh);
|
|
spin_lock(&journal->j_list_lock);
|
|
goto restart2;
|
|
}
|
|
if (unlikely(buffer_write_io_error(bh)) && !result)
|
|
result = -EIO;
|
|
|
|
/*
|
|
* Now in whatever state the buffer currently is, we
|
|
* know that it has been written out and so we can
|
|
* drop it from the list
|
|
*/
|
|
if (__jbd2_journal_remove_checkpoint(jh))
|
|
break;
|
|
}
|
|
out:
|
|
spin_unlock(&journal->j_list_lock);
|
|
if (result < 0)
|
|
jbd2_journal_abort(journal, result);
|
|
else
|
|
result = jbd2_cleanup_journal_tail(journal);
|
|
|
|
return (result < 0) ? result : 0;
|
|
}
|
|
|
|
/*
|
|
* Check the list of checkpoint transactions for the journal to see if
|
|
* we have already got rid of any since the last update of the log tail
|
|
* in the journal superblock. If so, we can instantly roll the
|
|
* superblock forward to remove those transactions from the log.
|
|
*
|
|
* Return <0 on error, 0 on success, 1 if there was nothing to clean up.
|
|
*
|
|
* Called with the journal lock held.
|
|
*
|
|
* This is the only part of the journaling code which really needs to be
|
|
* aware of transaction aborts. Checkpointing involves writing to the
|
|
* main filesystem area rather than to the journal, so it can proceed
|
|
* even in abort state, but we must not update the super block if
|
|
* checkpointing may have failed. Otherwise, we would lose some metadata
|
|
* buffers which should be written-back to the filesystem.
|
|
*/
|
|
|
|
int jbd2_cleanup_journal_tail(journal_t *journal)
|
|
{
|
|
tid_t first_tid;
|
|
unsigned long blocknr;
|
|
|
|
if (is_journal_aborted(journal))
|
|
return -EIO;
|
|
|
|
if (!jbd2_journal_get_log_tail(journal, &first_tid, &blocknr))
|
|
return 1;
|
|
J_ASSERT(blocknr != 0);
|
|
|
|
/*
|
|
* We need to make sure that any blocks that were recently written out
|
|
* --- perhaps by jbd2_log_do_checkpoint() --- are flushed out before
|
|
* we drop the transactions from the journal. It's unlikely this will
|
|
* be necessary, especially with an appropriately sized journal, but we
|
|
* need this to guarantee correctness. Fortunately
|
|
* jbd2_cleanup_journal_tail() doesn't get called all that often.
|
|
*/
|
|
if (journal->j_flags & JBD2_BARRIER)
|
|
blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
|
|
|
|
return __jbd2_update_log_tail(journal, first_tid, blocknr);
|
|
}
|
|
|
|
|
|
/* Checkpoint list management */
|
|
|
|
/*
|
|
* journal_clean_one_cp_list
|
|
*
|
|
* Find all the written-back checkpoint buffers in the given list and
|
|
* release them. If 'destroy' is set, clean all buffers unconditionally.
|
|
*
|
|
* Called with j_list_lock held.
|
|
* Returns 1 if we freed the transaction, 0 otherwise.
|
|
*/
|
|
static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
|
|
{
|
|
struct journal_head *last_jh;
|
|
struct journal_head *next_jh = jh;
|
|
int ret;
|
|
|
|
if (!jh)
|
|
return 0;
|
|
|
|
last_jh = jh->b_cpprev;
|
|
do {
|
|
jh = next_jh;
|
|
next_jh = jh->b_cpnext;
|
|
if (!destroy)
|
|
ret = __try_to_free_cp_buf(jh);
|
|
else
|
|
ret = __jbd2_journal_remove_checkpoint(jh) + 1;
|
|
if (!ret)
|
|
return 0;
|
|
if (ret == 2)
|
|
return 1;
|
|
/*
|
|
* This function only frees up some memory
|
|
* if possible so we dont have an obligation
|
|
* to finish processing. Bail out if preemption
|
|
* requested:
|
|
*/
|
|
if (need_resched())
|
|
return 0;
|
|
} while (jh != last_jh);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* journal_clean_checkpoint_list
|
|
*
|
|
* Find all the written-back checkpoint buffers in the journal and release them.
|
|
* If 'destroy' is set, release all buffers unconditionally.
|
|
*
|
|
* Called with j_list_lock held.
|
|
*/
|
|
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
|
|
{
|
|
transaction_t *transaction, *last_transaction, *next_transaction;
|
|
int ret;
|
|
|
|
transaction = journal->j_checkpoint_transactions;
|
|
if (!transaction)
|
|
return;
|
|
|
|
last_transaction = transaction->t_cpprev;
|
|
next_transaction = transaction;
|
|
do {
|
|
transaction = next_transaction;
|
|
next_transaction = transaction->t_cpnext;
|
|
ret = journal_clean_one_cp_list(transaction->t_checkpoint_list,
|
|
destroy);
|
|
/*
|
|
* This function only frees up some memory if possible so we
|
|
* dont have an obligation to finish processing. Bail out if
|
|
* preemption requested:
|
|
*/
|
|
if (need_resched())
|
|
return;
|
|
if (ret)
|
|
continue;
|
|
/*
|
|
* It is essential that we are as careful as in the case of
|
|
* t_checkpoint_list with removing the buffer from the list as
|
|
* we can possibly see not yet submitted buffers on io_list
|
|
*/
|
|
ret = journal_clean_one_cp_list(transaction->
|
|
t_checkpoint_io_list, destroy);
|
|
if (need_resched())
|
|
return;
|
|
/*
|
|
* Stop scanning if we couldn't free the transaction. This
|
|
* avoids pointless scanning of transactions which still
|
|
* weren't checkpointed.
|
|
*/
|
|
if (!ret)
|
|
return;
|
|
} while (transaction != last_transaction);
|
|
}
|
|
|
|
/*
|
|
* Remove buffers from all checkpoint lists as journal is aborted and we just
|
|
* need to free memory
|
|
*/
|
|
void jbd2_journal_destroy_checkpoint(journal_t *journal)
|
|
{
|
|
/*
|
|
* We loop because __jbd2_journal_clean_checkpoint_list() may abort
|
|
* early due to a need of rescheduling.
|
|
*/
|
|
while (1) {
|
|
spin_lock(&journal->j_list_lock);
|
|
if (!journal->j_checkpoint_transactions) {
|
|
spin_unlock(&journal->j_list_lock);
|
|
break;
|
|
}
|
|
__jbd2_journal_clean_checkpoint_list(journal, true);
|
|
spin_unlock(&journal->j_list_lock);
|
|
cond_resched();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* journal_remove_checkpoint: called after a buffer has been committed
|
|
* to disk (either by being write-back flushed to disk, or being
|
|
* committed to the log).
|
|
*
|
|
* We cannot safely clean a transaction out of the log until all of the
|
|
* buffer updates committed in that transaction have safely been stored
|
|
* elsewhere on disk. To achieve this, all of the buffers in a
|
|
* transaction need to be maintained on the transaction's checkpoint
|
|
* lists until they have been rewritten, at which point this function is
|
|
* called to remove the buffer from the existing transaction's
|
|
* checkpoint lists.
|
|
*
|
|
* The function returns 1 if it frees the transaction, 0 otherwise.
|
|
* The function can free jh and bh.
|
|
*
|
|
* This function is called with j_list_lock held.
|
|
*/
|
|
int __jbd2_journal_remove_checkpoint(struct journal_head *jh)
|
|
{
|
|
struct transaction_chp_stats_s *stats;
|
|
transaction_t *transaction;
|
|
journal_t *journal;
|
|
int ret = 0;
|
|
|
|
JBUFFER_TRACE(jh, "entry");
|
|
|
|
if ((transaction = jh->b_cp_transaction) == NULL) {
|
|
JBUFFER_TRACE(jh, "not on transaction");
|
|
goto out;
|
|
}
|
|
journal = transaction->t_journal;
|
|
|
|
JBUFFER_TRACE(jh, "removing from transaction");
|
|
__buffer_unlink(jh);
|
|
jh->b_cp_transaction = NULL;
|
|
jbd2_journal_put_journal_head(jh);
|
|
|
|
if (transaction->t_checkpoint_list != NULL ||
|
|
transaction->t_checkpoint_io_list != NULL)
|
|
goto out;
|
|
|
|
/*
|
|
* There is one special case to worry about: if we have just pulled the
|
|
* buffer off a running or committing transaction's checkpoing list,
|
|
* then even if the checkpoint list is empty, the transaction obviously
|
|
* cannot be dropped!
|
|
*
|
|
* The locking here around t_state is a bit sleazy.
|
|
* See the comment at the end of jbd2_journal_commit_transaction().
|
|
*/
|
|
if (transaction->t_state != T_FINISHED)
|
|
goto out;
|
|
|
|
/* OK, that was the last buffer for the transaction: we can now
|
|
safely remove this transaction from the log */
|
|
stats = &transaction->t_chp_stats;
|
|
if (stats->cs_chp_time)
|
|
stats->cs_chp_time = jbd2_time_diff(stats->cs_chp_time,
|
|
jiffies);
|
|
trace_jbd2_checkpoint_stats(journal->j_fs_dev->bd_dev,
|
|
transaction->t_tid, stats);
|
|
|
|
__jbd2_journal_drop_transaction(journal, transaction);
|
|
jbd2_journal_free_transaction(transaction);
|
|
ret = 1;
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* journal_insert_checkpoint: put a committed buffer onto a checkpoint
|
|
* list so that we know when it is safe to clean the transaction out of
|
|
* the log.
|
|
*
|
|
* Called with the journal locked.
|
|
* Called with j_list_lock held.
|
|
*/
|
|
void __jbd2_journal_insert_checkpoint(struct journal_head *jh,
|
|
transaction_t *transaction)
|
|
{
|
|
JBUFFER_TRACE(jh, "entry");
|
|
J_ASSERT_JH(jh, buffer_dirty(jh2bh(jh)) || buffer_jbddirty(jh2bh(jh)));
|
|
J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
|
|
|
|
/* Get reference for checkpointing transaction */
|
|
jbd2_journal_grab_journal_head(jh2bh(jh));
|
|
jh->b_cp_transaction = transaction;
|
|
|
|
if (!transaction->t_checkpoint_list) {
|
|
jh->b_cpnext = jh->b_cpprev = jh;
|
|
} else {
|
|
jh->b_cpnext = transaction->t_checkpoint_list;
|
|
jh->b_cpprev = transaction->t_checkpoint_list->b_cpprev;
|
|
jh->b_cpprev->b_cpnext = jh;
|
|
jh->b_cpnext->b_cpprev = jh;
|
|
}
|
|
transaction->t_checkpoint_list = jh;
|
|
}
|
|
|
|
/*
|
|
* We've finished with this transaction structure: adios...
|
|
*
|
|
* The transaction must have no links except for the checkpoint by this
|
|
* point.
|
|
*
|
|
* Called with the journal locked.
|
|
* Called with j_list_lock held.
|
|
*/
|
|
|
|
void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transaction)
|
|
{
|
|
assert_spin_locked(&journal->j_list_lock);
|
|
if (transaction->t_cpnext) {
|
|
transaction->t_cpnext->t_cpprev = transaction->t_cpprev;
|
|
transaction->t_cpprev->t_cpnext = transaction->t_cpnext;
|
|
if (journal->j_checkpoint_transactions == transaction)
|
|
journal->j_checkpoint_transactions =
|
|
transaction->t_cpnext;
|
|
if (journal->j_checkpoint_transactions == transaction)
|
|
journal->j_checkpoint_transactions = NULL;
|
|
}
|
|
|
|
J_ASSERT(transaction->t_state == T_FINISHED);
|
|
J_ASSERT(transaction->t_buffers == NULL);
|
|
J_ASSERT(transaction->t_forget == NULL);
|
|
J_ASSERT(transaction->t_shadow_list == NULL);
|
|
J_ASSERT(transaction->t_checkpoint_list == NULL);
|
|
J_ASSERT(transaction->t_checkpoint_io_list == NULL);
|
|
J_ASSERT(atomic_read(&transaction->t_updates) == 0);
|
|
J_ASSERT(journal->j_committing_transaction != transaction);
|
|
J_ASSERT(journal->j_running_transaction != transaction);
|
|
|
|
trace_jbd2_drop_transaction(journal, transaction);
|
|
|
|
jbd_debug(1, "Dropping transaction %d, all done\n", transaction->t_tid);
|
|
}
|