cregit-Linux how code gets into the kernel

Release 4.10 fs/gfs2/super.c

Directory: fs/gfs2
/*
 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
 * Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License version 2.
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/bio.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
#include <linux/statfs.h>
#include <linux/seq_file.h>
#include <linux/mount.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/gfs2_ondisk.h>
#include <linux/crc32.h>
#include <linux/time.h>
#include <linux/wait.h>
#include <linux/writeback.h>
#include <linux/backing-dev.h>
#include <linux/kernel.h>

#include "gfs2.h"
#include "incore.h"
#include "bmap.h"
#include "dir.h"
#include "glock.h"
#include "glops.h"
#include "inode.h"
#include "log.h"
#include "meta_io.h"
#include "quota.h"
#include "recovery.h"
#include "rgrp.h"
#include "super.h"
#include "trans.h"
#include "util.h"
#include "sys.h"
#include "xattr.h"


#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)

enum {
	
Opt_lockproto,
	
Opt_locktable,
	
Opt_hostdata,
	
Opt_spectator,
	
Opt_ignore_local_fs,
	
Opt_localflocks,
	
Opt_localcaching,
	
Opt_debug,
	
Opt_nodebug,
	
Opt_upgrade,
	
Opt_acl,
	
Opt_noacl,
	
Opt_quota_off,
	
Opt_quota_account,
	
Opt_quota_on,
	
Opt_quota,
	
Opt_noquota,
	
Opt_suiddir,
	
Opt_nosuiddir,
	
Opt_data_writeback,
	
Opt_data_ordered,
	
Opt_meta,
	
Opt_discard,
	
Opt_nodiscard,
	
Opt_commit,
	
Opt_err_withdraw,
	
Opt_err_panic,
	
Opt_statfs_quantum,
	
Opt_statfs_percent,
	
Opt_quota_quantum,
	
Opt_barrier,
	
Opt_nobarrier,
	
Opt_rgrplvb,
	
Opt_norgrplvb,
	
Opt_loccookie,
	
Opt_noloccookie,
	
Opt_error,
};


static const match_table_t tokens = {
	{Opt_lockproto, "lockproto=%s"},
	{Opt_locktable, "locktable=%s"},
	{Opt_hostdata, "hostdata=%s"},
	{Opt_spectator, "spectator"},
	{Opt_spectator, "norecovery"},
	{Opt_ignore_local_fs, "ignore_local_fs"},
	{Opt_localflocks, "localflocks"},
	{Opt_localcaching, "localcaching"},
	{Opt_debug, "debug"},
	{Opt_nodebug, "nodebug"},
	{Opt_upgrade, "upgrade"},
	{Opt_acl, "acl"},
	{Opt_noacl, "noacl"},
	{Opt_quota_off, "quota=off"},
	{Opt_quota_account, "quota=account"},
	{Opt_quota_on, "quota=on"},
	{Opt_quota, "quota"},
	{Opt_noquota, "noquota"},
	{Opt_suiddir, "suiddir"},
	{Opt_nosuiddir, "nosuiddir"},
	{Opt_data_writeback, "data=writeback"},
	{Opt_data_ordered, "data=ordered"},
	{Opt_meta, "meta"},
	{Opt_discard, "discard"},
	{Opt_nodiscard, "nodiscard"},
	{Opt_commit, "commit=%d"},
	{Opt_err_withdraw, "errors=withdraw"},
	{Opt_err_panic, "errors=panic"},
	{Opt_statfs_quantum, "statfs_quantum=%d"},
	{Opt_statfs_percent, "statfs_percent=%d"},
	{Opt_quota_quantum, "quota_quantum=%d"},
	{Opt_barrier, "barrier"},
	{Opt_nobarrier, "nobarrier"},
	{Opt_rgrplvb, "rgrplvb"},
	{Opt_norgrplvb, "norgrplvb"},
	{Opt_loccookie, "loccookie"},
	{Opt_noloccookie, "noloccookie"},
	{Opt_error, NULL}
};

/**
 * gfs2_mount_args - Parse mount options
 * @args: The structure into which the parsed options will be written
 * @options: The options to parse
 *
 * Return: errno
 */


int gfs2_mount_args(struct gfs2_args *args, char *options) { char *o; int token; substring_t tmp[MAX_OPT_ARGS]; int rv; /* Split the options into tokens with the "," character and process them */ while (1) { o = strsep(&options, ","); if (o == NULL) break; if (*o == '\0') continue; token = match_token(o, tokens, tmp); switch (token) { case Opt_lockproto: match_strlcpy(args->ar_lockproto, &tmp[0], GFS2_LOCKNAME_LEN); break; case Opt_locktable: match_strlcpy(args->ar_locktable, &tmp[0], GFS2_LOCKNAME_LEN); break; case Opt_hostdata: match_strlcpy(args->ar_hostdata, &tmp[0], GFS2_LOCKNAME_LEN); break; case Opt_spectator: args->ar_spectator = 1; break; case Opt_ignore_local_fs: /* Retained for backwards compat only */ break; case Opt_localflocks: args->ar_localflocks = 1; break; case Opt_localcaching: /* Retained for backwards compat only */ break; case Opt_debug: if (args->ar_errors == GFS2_ERRORS_PANIC) { pr_warn("-o debug and -o errors=panic are mutually exclusive\n"); return -EINVAL; } args->ar_debug = 1; break; case Opt_nodebug: args->ar_debug = 0; break; case Opt_upgrade: /* Retained for backwards compat only */ break; case Opt_acl: args->ar_posix_acl = 1; break; case Opt_noacl: args->ar_posix_acl = 0; break; case Opt_quota_off: case Opt_noquota: args->ar_quota = GFS2_QUOTA_OFF; break; case Opt_quota_account: args->ar_quota = GFS2_QUOTA_ACCOUNT; break; case Opt_quota_on: case Opt_quota: args->ar_quota = GFS2_QUOTA_ON; break; case Opt_suiddir: args->ar_suiddir = 1; break; case Opt_nosuiddir: args->ar_suiddir = 0; break; case Opt_data_writeback: args->ar_data = GFS2_DATA_WRITEBACK; break; case Opt_data_ordered: args->ar_data = GFS2_DATA_ORDERED; break; case Opt_meta: args->ar_meta = 1; break; case Opt_discard: args->ar_discard = 1; break; case Opt_nodiscard: args->ar_discard = 0; break; case Opt_commit: rv = match_int(&tmp[0], &args->ar_commit); if (rv || args->ar_commit <= 0) { pr_warn("commit mount option requires a positive numeric argument\n"); return rv ? rv : -EINVAL; } break; case Opt_statfs_quantum: rv = match_int(&tmp[0], &args->ar_statfs_quantum); if (rv || args->ar_statfs_quantum < 0) { pr_warn("statfs_quantum mount option requires a non-negative numeric argument\n"); return rv ? rv : -EINVAL; } break; case Opt_quota_quantum: rv = match_int(&tmp[0], &args->ar_quota_quantum); if (rv || args->ar_quota_quantum <= 0) { pr_warn("quota_quantum mount option requires a positive numeric argument\n"); return rv ? rv : -EINVAL; } break; case Opt_statfs_percent: rv = match_int(&tmp[0], &args->ar_statfs_percent); if (rv || args->ar_statfs_percent < 0 || args->ar_statfs_percent > 100) { pr_warn("statfs_percent mount option requires a numeric argument between 0 and 100\n"); return rv ? rv : -EINVAL; } break; case Opt_err_withdraw: args->ar_errors = GFS2_ERRORS_WITHDRAW; break; case Opt_err_panic: if (args->ar_debug) { pr_warn("-o debug and -o errors=panic are mutually exclusive\n"); return -EINVAL; } args->ar_errors = GFS2_ERRORS_PANIC; break; case Opt_barrier: args->ar_nobarrier = 0; break; case Opt_nobarrier: args->ar_nobarrier = 1; break; case Opt_rgrplvb: args->ar_rgrplvb = 1; break; case Opt_norgrplvb: args->ar_rgrplvb = 0; break; case Opt_loccookie: args->ar_loccookie = 1; break; case Opt_noloccookie: args->ar_loccookie = 0; break; case Opt_error: default: pr_warn("invalid mount option: %s\n", o); return -EINVAL; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse37659.03%541.67%
benjamin marzinskibenjamin marzinski17627.63%325.00%
robert s. petersonrobert s. peterson528.16%18.33%
christoph hellwigchristoph hellwig203.14%18.33%
fabian frederickfabian frederick71.10%18.33%
joe perchesjoe perches60.94%18.33%
Total637100.00%12100.00%

/** * gfs2_jindex_free - Clear all the journal index information * @sdp: The GFS2 superblock * */
void gfs2_jindex_free(struct gfs2_sbd *sdp) { struct list_head list; struct gfs2_jdesc *jd; spin_lock(&sdp->sd_jindex_spin); list_add(&list, &sdp->sd_jindex_list); list_del_init(&sdp->sd_jindex_list); sdp->sd_journals = 0; spin_unlock(&sdp->sd_jindex_spin); while (!list_empty(&list)) { jd = list_entry(list.next, struct gfs2_jdesc, jd_list); gfs2_free_journal_extents(jd); list_del(&jd->jd_list); iput(jd->jd_inode); kfree(jd); } }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse8980.91%266.67%
david teiglanddavid teigland2119.09%133.33%
Total110100.00%3100.00%


static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid) { struct gfs2_jdesc *jd; int found = 0; list_for_each_entry(jd, head, jd_list) { if (jd->jd_jid == jid) { found = 1; break; } } if (!found) jd = NULL; return jd; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse64100.00%1100.00%
Total64100.00%1100.00%


struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid) { struct gfs2_jdesc *jd; spin_lock(&sdp->sd_jindex_spin); jd = jdesc_find_i(&sdp->sd_jindex_list, jid); spin_unlock(&sdp->sd_jindex_spin); return jd; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse52100.00%1100.00%
Total52100.00%1100.00%


int gfs2_jdesc_check(struct gfs2_jdesc *jd) { struct gfs2_inode *ip = GFS2_I(jd->jd_inode); struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); u64 size = i_size_read(jd->jd_inode); if (gfs2_check_internal_file_size(jd->jd_inode, 8 << 20, BIT(30))) return -EIO; jd->jd_blocks = size >> sdp->sd_sb.sb_bsize_shift; if (gfs2_write_alloc_required(ip, 0, size)) { gfs2_consist_inode(ip); return -EIO; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse9592.23%250.00%
robert s. petersonrobert s. peterson54.85%125.00%
fabian frederickfabian frederick32.91%125.00%
Total103100.00%4100.00%


static int init_threads(struct gfs2_sbd *sdp) { struct task_struct *p; int error = 0; p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); if (IS_ERR(p)) { error = PTR_ERR(p); fs_err(sdp, "can't start logd thread: %d\n", error); return error; } sdp->sd_logd_process = p; p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); if (IS_ERR(p)) { error = PTR_ERR(p); fs_err(sdp, "can't start quotad thread: %d\n", error); goto fail; } sdp->sd_quotad_process = p; return 0; fail: kthread_stop(sdp->sd_logd_process); return error; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse126100.00%1100.00%
Total126100.00%1100.00%

/** * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one * @sdp: the filesystem * * Returns: errno */
int gfs2_make_fs_rw(struct gfs2_sbd *sdp) { struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); struct gfs2_glock *j_gl = ip->i_gl; struct gfs2_holder freeze_gh; struct gfs2_log_header_host head; int error; error = init_threads(sdp); if (error) return error; error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 0, &freeze_gh); if (error) goto fail_threads; j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); error = gfs2_find_jhead(sdp->sd_jdesc, &head); if (error) goto fail; if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { gfs2_consist(sdp); error = -EIO; goto fail; } /* Initialize some head of the log stuff */ sdp->sd_log_sequence = head.lh_sequence + 1; gfs2_log_pointers_init(sdp, head.lh_blkno); error = gfs2_quota_init(sdp); if (error) goto fail; set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); gfs2_glock_dq_uninit(&freeze_gh); return 0; fail: freeze_gh.gh_flags |= GL_NOCACHE; gfs2_glock_dq_uninit(&freeze_gh); fail_threads: kthread_stop(sdp->sd_quotad_process); kthread_stop(sdp->sd_logd_process); return error; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse21797.31%250.00%
benjamin marzinskibenjamin marzinski62.69%250.00%
Total223100.00%4100.00%


void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf) { const struct gfs2_statfs_change *str = buf; sc->sc_total = be64_to_cpu(str->sc_total); sc->sc_free = be64_to_cpu(str->sc_free); sc->sc_dinodes = be64_to_cpu(str->sc_dinodes); }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse56100.00%1100.00%
Total56100.00%1100.00%


static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf) { struct gfs2_statfs_change *str = buf; str->sc_total = cpu_to_be64(sc->sc_total); str->sc_free = cpu_to_be64(sc->sc_free); str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse56100.00%1100.00%
Total56100.00%1100.00%


int gfs2_statfs_init(struct gfs2_sbd *sdp) { struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; struct buffer_head *m_bh, *l_bh; struct gfs2_holder gh; int error; error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, &gh); if (error) return error; error = gfs2_meta_inode_buffer(m_ip, &m_bh); if (error) goto out; if (sdp->sd_args.ar_spectator) { spin_lock(&sdp->sd_statfs_spin); gfs2_statfs_change_in(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); spin_unlock(&sdp->sd_statfs_spin); } else { error = gfs2_meta_inode_buffer(l_ip, &l_bh); if (error) goto out_m_bh; spin_lock(&sdp->sd_statfs_spin); gfs2_statfs_change_in(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); gfs2_statfs_change_in(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode)); spin_unlock(&sdp->sd_statfs_spin); brelse(l_bh); } out_m_bh: brelse(m_bh); out: gfs2_glock_dq_uninit(&gh); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse239100.00%1100.00%
Total239100.00%1100.00%


void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free, s64 dinodes) { struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; struct buffer_head *l_bh; s64 x, y; int need_sync = 0; int error; error = gfs2_meta_inode_buffer(l_ip, &l_bh); if (error) return; gfs2_trans_add_meta(l_ip->i_gl, l_bh); spin_lock(&sdp->sd_statfs_spin); l_sc->sc_total += total; l_sc->sc_free += free; l_sc->sc_dinodes += dinodes; gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode)); if (sdp->sd_args.ar_statfs_percent) { x = 100 * l_sc->sc_free; y = m_sc->sc_free * sdp->sd_args.ar_statfs_percent; if (x >= y || x <= -y) need_sync = 1; } spin_unlock(&sdp->sd_statfs_spin); brelse(l_bh); if (need_sync) gfs2_wake_up_statfs(sdp); }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse12662.69%250.00%
benjamin marzinskibenjamin marzinski7537.31%250.00%
Total201100.00%4100.00%


void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh, struct buffer_head *l_bh) { struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; gfs2_trans_add_meta(l_ip->i_gl, l_bh); gfs2_trans_add_meta(m_ip->i_gl, m_bh); spin_lock(&sdp->sd_statfs_spin); m_sc->sc_total += l_sc->sc_total; m_sc->sc_free += l_sc->sc_free; m_sc->sc_dinodes += l_sc->sc_dinodes; memset(l_sc, 0, sizeof(struct gfs2_statfs_change)); memset(l_bh->b_data + sizeof(struct gfs2_dinode), 0, sizeof(struct gfs2_statfs_change)); gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); spin_unlock(&sdp->sd_statfs_spin); }

Contributors

PersonTokensPropCommitsCommitProp
benjamin marzinskibenjamin marzinski15389.47%133.33%
robert s. petersonrobert s. peterson179.94%133.33%
steven whitehousesteven whitehouse10.58%133.33%
Total171100.00%3100.00%


int gfs2_statfs_sync(struct super_block *sb, int type) { struct gfs2_sbd *sdp = sb->s_fs_info; struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; struct gfs2_holder gh; struct buffer_head *m_bh, *l_bh; int error; sb_start_write(sb); error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, &gh); if (error) goto out; error = gfs2_meta_inode_buffer(m_ip, &m_bh); if (error) goto out_unlock; spin_lock(&sdp->sd_statfs_spin); gfs2_statfs_change_in(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) { spin_unlock(&sdp->sd_statfs_spin); goto out_bh; } spin_unlock(&sdp->sd_statfs_spin); error = gfs2_meta_inode_buffer(l_ip, &l_bh); if (error) goto out_bh; error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); if (error) goto out_bh2; update_statfs(sdp, m_bh, l_bh); sdp->sd_statfs_force_sync = 0; gfs2_trans_end(sdp); out_bh2: brelse(l_bh); out_bh: brelse(m_bh); out_unlock: gfs2_glock_dq_uninit(&gh); out: sb_end_write(sb); return error; }

Contributors

PersonTokensPropCommitsCommitProp
steven whitehousesteven whitehouse25190.94%240.00%
benjamin marzinskibenjamin marzinski259.06%360.00%
Total276100.00%5100.00%

struct lfcc { struct list_head list; struct gfs2_holder gh; }; /** * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all * journals are clean * @sdp: the file system * @state: the state to put the transaction lock into * @t_gh: the hold on the transaction lock * * Returns: errno */
static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *freeze_gh) { struct gfs2_inode *ip; struct gfs2_jdesc *jd; struct lfcc *lfcc; LIST_HEAD(list); struct gfs2_log_header_host lh; int error; list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL); if (!lfcc) { error = -ENOMEM; goto out; } ip = GFS2_I(jd->jd_inode); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh); if (error) { kfree(lfcc)