linux/fs/gfs2/util.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
   3 * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
   4 *
   5 * This copyrighted material is made available to anyone wishing to use,
   6 * modify, copy, or redistribute it subject to the terms and conditions
   7 * of the GNU General Public License version 2.
   8 */
   9
  10#include <linux/spinlock.h>
  11#include <linux/completion.h>
  12#include <linux/buffer_head.h>
  13#include <linux/crc32.h>
  14#include <linux/gfs2_ondisk.h>
  15#include <asm/uaccess.h>
  16
  17#include "gfs2.h"
  18#include "incore.h"
  19#include "glock.h"
  20#include "rgrp.h"
  21#include "util.h"
  22
  23struct kmem_cache *gfs2_glock_cachep __read_mostly;
  24struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly;
  25struct kmem_cache *gfs2_inode_cachep __read_mostly;
  26struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
  27struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
  28struct kmem_cache *gfs2_quotad_cachep __read_mostly;
  29struct kmem_cache *gfs2_qadata_cachep __read_mostly;
  30mempool_t *gfs2_page_pool __read_mostly;
  31
  32void gfs2_assert_i(struct gfs2_sbd *sdp)
  33{
  34        printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n",
  35               sdp->sd_fsname);
  36}
  37
  38int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
  39{
  40        struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  41        const struct lm_lockops *lm = ls->ls_ops;
  42        va_list args;
  43
  44        if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW &&
  45            test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  46                return 0;
  47
  48        va_start(args, fmt);
  49        vprintk(fmt, args);
  50        va_end(args);
  51
  52        if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) {
  53                fs_err(sdp, "about to withdraw this file system\n");
  54                BUG_ON(sdp->sd_args.ar_debug);
  55
  56                kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
  57
  58                if (!strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm"))
  59                        wait_for_completion(&sdp->sd_wdack);
  60
  61                if (lm->lm_unmount) {
  62                        fs_err(sdp, "telling LM to unmount\n");
  63                        lm->lm_unmount(sdp);
  64                }
  65                set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
  66                fs_err(sdp, "withdrawn\n");
  67                dump_stack();
  68        }
  69
  70        if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  71                panic("GFS2: fsid=%s: panic requested.\n", sdp->sd_fsname);
  72
  73        return -1;
  74}
  75
  76/**
  77 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  78 * Returns: -1 if this call withdrew the machine,
  79 *          -2 if it was already withdrawn
  80 */
  81
  82int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  83                           const char *function, char *file, unsigned int line)
  84{
  85        int me;
  86        me = gfs2_lm_withdraw(sdp,
  87                "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
  88                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
  89                sdp->sd_fsname, assertion,
  90                sdp->sd_fsname, function, file, line);
  91        dump_stack();
  92        return (me) ? -1 : -2;
  93}
  94
  95/**
  96 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  97 * Returns: -1 if we printed something
  98 *          -2 if we didn't
  99 */
 100
 101int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
 102                       const char *function, char *file, unsigned int line)
 103{
 104        if (time_before(jiffies,
 105                        sdp->sd_last_warning +
 106                        gfs2_tune_get(sdp, gt_complain_secs) * HZ))
 107                return -2;
 108
 109        if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
 110                printk(KERN_WARNING
 111                       "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
 112                       "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 113                       sdp->sd_fsname, assertion,
 114                       sdp->sd_fsname, function, file, line);
 115
 116        if (sdp->sd_args.ar_debug)
 117                BUG();
 118        else
 119                dump_stack();
 120
 121        if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
 122                panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
 123                      "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 124                      sdp->sd_fsname, assertion,
 125                      sdp->sd_fsname, function, file, line);
 126
 127        sdp->sd_last_warning = jiffies;
 128
 129        return -1;
 130}
 131
 132/**
 133 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
 134 * Returns: -1 if this call withdrew the machine,
 135 *          0 if it was already withdrawn
 136 */
 137
 138int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
 139                   char *file, unsigned int line)
 140{
 141        int rv;
 142        rv = gfs2_lm_withdraw(sdp,
 143                "GFS2: fsid=%s: fatal: filesystem consistency error\n"
 144                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 145                sdp->sd_fsname,
 146                sdp->sd_fsname, function, file, line);
 147        return rv;
 148}
 149
 150/**
 151 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
 152 * Returns: -1 if this call withdrew the machine,
 153 *          0 if it was already withdrawn
 154 */
 155
 156int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
 157                         const char *function, char *file, unsigned int line)
 158{
 159        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
 160        int rv;
 161        rv = gfs2_lm_withdraw(sdp,
 162                "GFS2: fsid=%s: fatal: filesystem consistency error\n"
 163                "GFS2: fsid=%s:   inode = %llu %llu\n"
 164                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 165                sdp->sd_fsname,
 166                sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
 167                (unsigned long long)ip->i_no_addr,
 168                sdp->sd_fsname, function, file, line);
 169        return rv;
 170}
 171
 172/**
 173 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
 174 * Returns: -1 if this call withdrew the machine,
 175 *          0 if it was already withdrawn
 176 */
 177
 178int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
 179                         const char *function, char *file, unsigned int line)
 180{
 181        struct gfs2_sbd *sdp = rgd->rd_sbd;
 182        int rv;
 183
 184        gfs2_rgrp_dump(NULL, rgd->rd_gl);
 185        rv = gfs2_lm_withdraw(sdp,
 186                "GFS2: fsid=%s: fatal: filesystem consistency error\n"
 187                "GFS2: fsid=%s:   RG = %llu\n"
 188                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 189                sdp->sd_fsname,
 190                sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
 191                sdp->sd_fsname, function, file, line);
 192        return rv;
 193}
 194
 195/**
 196 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
 197 * Returns: -1 if this call withdrew the machine,
 198 *          -2 if it was already withdrawn
 199 */
 200
 201int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
 202                       const char *type, const char *function, char *file,
 203                       unsigned int line)
 204{
 205        int me;
 206        me = gfs2_lm_withdraw(sdp,
 207                "GFS2: fsid=%s: fatal: invalid metadata block\n"
 208                "GFS2: fsid=%s:   bh = %llu (%s)\n"
 209                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 210                sdp->sd_fsname,
 211                sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
 212                sdp->sd_fsname, function, file, line);
 213        return (me) ? -1 : -2;
 214}
 215
 216/**
 217 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
 218 * Returns: -1 if this call withdrew the machine,
 219 *          -2 if it was already withdrawn
 220 */
 221
 222int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
 223                           u16 type, u16 t, const char *function,
 224                           char *file, unsigned int line)
 225{
 226        int me;
 227        me = gfs2_lm_withdraw(sdp,
 228                "GFS2: fsid=%s: fatal: invalid metadata block\n"
 229                "GFS2: fsid=%s:   bh = %llu (type: exp=%u, found=%u)\n"
 230                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 231                sdp->sd_fsname,
 232                sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
 233                sdp->sd_fsname, function, file, line);
 234        return (me) ? -1 : -2;
 235}
 236
 237/**
 238 * gfs2_io_error_i - Flag an I/O error and withdraw
 239 * Returns: -1 if this call withdrew the machine,
 240 *          0 if it was already withdrawn
 241 */
 242
 243int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
 244                    unsigned int line)
 245{
 246        int rv;
 247        rv = gfs2_lm_withdraw(sdp,
 248                "GFS2: fsid=%s: fatal: I/O error\n"
 249                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 250                sdp->sd_fsname,
 251                sdp->sd_fsname, function, file, line);
 252        return rv;
 253}
 254
 255/**
 256 * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
 257 * Returns: -1 if this call withdrew the machine,
 258 *          0 if it was already withdrawn
 259 */
 260
 261int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
 262                       const char *function, char *file, unsigned int line)
 263{
 264        int rv;
 265        rv = gfs2_lm_withdraw(sdp,
 266                "GFS2: fsid=%s: fatal: I/O error\n"
 267                "GFS2: fsid=%s:   block = %llu\n"
 268                "GFS2: fsid=%s:   function = %s, file = %s, line = %u\n",
 269                sdp->sd_fsname,
 270                sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
 271                sdp->sd_fsname, function, file, line);
 272        return rv;
 273}
 274