linux/fs/gfs2/incore.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
   3 * Copyright (C) 2004-2008 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#ifndef __INCORE_DOT_H__
  11#define __INCORE_DOT_H__
  12
  13#include <linux/fs.h>
  14#include <linux/kobject.h>
  15#include <linux/workqueue.h>
  16#include <linux/dlm.h>
  17#include <linux/buffer_head.h>
  18#include <linux/rcupdate.h>
  19#include <linux/rculist_bl.h>
  20#include <linux/completion.h>
  21#include <linux/rbtree.h>
  22#include <linux/ktime.h>
  23#include <linux/percpu.h>
  24#include <linux/lockref.h>
  25#include <linux/rhashtable.h>
  26#include <linux/mutex.h>
  27
  28#define DIO_WAIT        0x00000010
  29#define DIO_METADATA    0x00000020
  30
  31struct gfs2_log_operations;
  32struct gfs2_bufdata;
  33struct gfs2_holder;
  34struct gfs2_glock;
  35struct gfs2_quota_data;
  36struct gfs2_trans;
  37struct gfs2_jdesc;
  38struct gfs2_sbd;
  39struct lm_lockops;
  40
  41typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret);
  42
  43struct gfs2_log_header_host {
  44        u64 lh_sequence;        /* Sequence number of this transaction */
  45        u32 lh_flags;           /* GFS2_LOG_HEAD_... */
  46        u32 lh_tail;            /* Block number of log tail */
  47        u32 lh_blkno;
  48
  49        s64 lh_local_total;
  50        s64 lh_local_free;
  51        s64 lh_local_dinodes;
  52};
  53
  54/*
  55 * Structure of operations that are associated with each
  56 * type of element in the log.
  57 */
  58
  59struct gfs2_log_operations {
  60        void (*lo_before_commit) (struct gfs2_sbd *sdp, struct gfs2_trans *tr);
  61        void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_trans *tr);
  62        void (*lo_before_scan) (struct gfs2_jdesc *jd,
  63                                struct gfs2_log_header_host *head, int pass);
  64        int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start,
  65                                 struct gfs2_log_descriptor *ld, __be64 *ptr,
  66                                 int pass);
  67        void (*lo_after_scan) (struct gfs2_jdesc *jd, int error, int pass);
  68        const char *lo_name;
  69};
  70
  71#define GBF_FULL 1
  72
  73/**
  74 * Clone bitmaps (bi_clone):
  75 *
  76 * - When a block is freed, we remember the previous state of the block in the
  77 *   clone bitmap, and only mark the block as free in the real bitmap.
  78 *
  79 * - When looking for a block to allocate, we check for a free block in the
  80 *   clone bitmap, and if no clone bitmap exists, in the real bitmap.
  81 *
  82 * - For allocating a block, we mark it as allocated in the real bitmap, and if
  83 *   a clone bitmap exists, also in the clone bitmap.
  84 *
  85 * - At the end of a log_flush, we copy the real bitmap into the clone bitmap
  86 *   to make the clone bitmap reflect the current allocation state.
  87 *   (Alternatively, we could remove the clone bitmap.)
  88 *
  89 * The clone bitmaps are in-core only, and is never written to disk.
  90 *
  91 * These steps ensure that blocks which have been freed in a transaction cannot
  92 * be reallocated in that same transaction.
  93 */
  94struct gfs2_bitmap {
  95        struct buffer_head *bi_bh;
  96        char *bi_clone;
  97        unsigned long bi_flags;
  98        u32 bi_offset;
  99        u32 bi_start;
 100        u32 bi_bytes;
 101        u32 bi_blocks;
 102};
 103
 104struct gfs2_rgrpd {
 105        struct rb_node rd_node;         /* Link with superblock */
 106        struct gfs2_glock *rd_gl;       /* Glock for this rgrp */
 107        u64 rd_addr;                    /* grp block disk address */
 108        u64 rd_data0;                   /* first data location */
 109        u32 rd_length;                  /* length of rgrp header in fs blocks */
 110        u32 rd_data;                    /* num of data blocks in rgrp */
 111        u32 rd_bitbytes;                /* number of bytes in data bitmaps */
 112        u32 rd_free;
 113        u32 rd_requested;               /* number of blocks in rd_rstree */
 114        u32 rd_reserved;                /* number of reserved blocks */
 115        u32 rd_free_clone;
 116        u32 rd_dinodes;
 117        u64 rd_igeneration;
 118        struct gfs2_bitmap *rd_bits;
 119        struct gfs2_sbd *rd_sbd;
 120        struct gfs2_rgrp_lvb *rd_rgl;
 121        u32 rd_last_alloc;
 122        u32 rd_flags;
 123        u32 rd_extfail_pt;              /* extent failure point */
 124#define GFS2_RDF_CHECK          0x10000000 /* check for unlinked inodes */
 125#define GFS2_RDF_UPTODATE       0x20000000 /* rg is up to date */
 126#define GFS2_RDF_ERROR          0x40000000 /* error in rg */
 127#define GFS2_RDF_PREFERRED      0x80000000 /* This rgrp is preferred */
 128#define GFS2_RDF_MASK           0xf0000000 /* mask for internal flags */
 129        spinlock_t rd_rsspin;           /* protects reservation related vars */
 130        struct mutex rd_mutex;
 131        struct rb_root rd_rstree;       /* multi-block reservation tree */
 132};
 133
 134enum gfs2_state_bits {
 135        BH_Pinned = BH_PrivateStart,
 136        BH_Escaped = BH_PrivateStart + 1,
 137};
 138
 139BUFFER_FNS(Pinned, pinned)
 140TAS_BUFFER_FNS(Pinned, pinned)
 141BUFFER_FNS(Escaped, escaped)
 142TAS_BUFFER_FNS(Escaped, escaped)
 143
 144struct gfs2_bufdata {
 145        struct buffer_head *bd_bh;
 146        struct gfs2_glock *bd_gl;
 147        u64 bd_blkno;
 148
 149        struct list_head bd_list;
 150
 151        struct gfs2_trans *bd_tr;
 152        struct list_head bd_ail_st_list;
 153        struct list_head bd_ail_gl_list;
 154};
 155
 156/*
 157 * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a
 158 * prefix of lock_dlm_ gets awkward.
 159 */
 160
 161#define GDLM_STRNAME_BYTES      25
 162#define GDLM_LVB_SIZE           32
 163
 164/*
 165 * ls_recover_flags:
 166 *
 167 * DFL_BLOCK_LOCKS: dlm is in recovery and will grant locks that had been
 168 * held by failed nodes whose journals need recovery.  Those locks should
 169 * only be used for journal recovery until the journal recovery is done.
 170 * This is set by the dlm recover_prep callback and cleared by the
 171 * gfs2_control thread when journal recovery is complete.  To avoid
 172 * races between recover_prep setting and gfs2_control clearing, recover_spin
 173 * is held while changing this bit and reading/writing recover_block
 174 * and recover_start.
 175 *
 176 * DFL_NO_DLM_OPS: dlm lockspace ops/callbacks are not being used.
 177 *
 178 * DFL_FIRST_MOUNT: this node is the first to mount this fs and is doing
 179 * recovery of all journals before allowing other nodes to mount the fs.
 180 * This is cleared when FIRST_MOUNT_DONE is set.
 181 *
 182 * DFL_FIRST_MOUNT_DONE: this node was the first mounter, and has finished
 183 * recovery of all journals, and now allows other nodes to mount the fs.
 184 *
 185 * DFL_MOUNT_DONE: gdlm_mount has completed successfully and cleared
 186 * BLOCK_LOCKS for the first time.  The gfs2_control thread should now
 187 * control clearing BLOCK_LOCKS for further recoveries.
 188 *
 189 * DFL_UNMOUNT: gdlm_unmount sets to keep sdp off gfs2_control_wq.
 190 *
 191 * DFL_DLM_RECOVERY: set while dlm is in recovery, between recover_prep()
 192 * and recover_done(), i.e. set while recover_block == recover_start.
 193 */
 194
 195enum {
 196        DFL_BLOCK_LOCKS         = 0,
 197        DFL_NO_DLM_OPS          = 1,
 198        DFL_FIRST_MOUNT         = 2,
 199        DFL_FIRST_MOUNT_DONE    = 3,
 200        DFL_MOUNT_DONE          = 4,
 201        DFL_UNMOUNT             = 5,
 202        DFL_DLM_RECOVERY        = 6,
 203};
 204
 205/*
 206 * We are using struct lm_lockname as an rhashtable key.  Avoid holes within
 207 * the struct; padding at the end is fine.
 208 */
 209struct lm_lockname {
 210        u64 ln_number;
 211        struct gfs2_sbd *ln_sbd;
 212        unsigned int ln_type;
 213};
 214
 215#define lm_name_equal(name1, name2) \
 216        (((name1)->ln_number == (name2)->ln_number) &&  \
 217         ((name1)->ln_type == (name2)->ln_type) &&      \
 218         ((name1)->ln_sbd == (name2)->ln_sbd))
 219
 220
 221struct gfs2_glock_operations {
 222        int (*go_sync) (struct gfs2_glock *gl);
 223        int (*go_xmote_bh)(struct gfs2_glock *gl);
 224        void (*go_inval) (struct gfs2_glock *gl, int flags);
 225        int (*go_demote_ok) (const struct gfs2_glock *gl);
 226        int (*go_lock) (struct gfs2_holder *gh);
 227        void (*go_dump)(struct seq_file *seq, struct gfs2_glock *gl,
 228                        const char *fs_id_buf);
 229        void (*go_callback)(struct gfs2_glock *gl, bool remote);
 230        void (*go_free)(struct gfs2_glock *gl);
 231        const int go_subclass;
 232        const int go_type;
 233        const unsigned long go_flags;
 234#define GLOF_ASPACE 1 /* address space attached */
 235#define GLOF_LVB    2 /* Lock Value Block attached */
 236#define GLOF_LRU    4 /* LRU managed */
 237#define GLOF_NONDISK   8 /* not I/O related */
 238};
 239
 240enum {
 241        GFS2_LKS_SRTT = 0,      /* Non blocking smoothed round trip time */
 242        GFS2_LKS_SRTTVAR = 1,   /* Non blocking smoothed variance */
 243        GFS2_LKS_SRTTB = 2,     /* Blocking smoothed round trip time */
 244        GFS2_LKS_SRTTVARB = 3,  /* Blocking smoothed variance */
 245        GFS2_LKS_SIRT = 4,      /* Smoothed Inter-request time */
 246        GFS2_LKS_SIRTVAR = 5,   /* Smoothed Inter-request variance */
 247        GFS2_LKS_DCOUNT = 6,    /* Count of dlm requests */
 248        GFS2_LKS_QCOUNT = 7,    /* Count of gfs2_holder queues */
 249        GFS2_NR_LKSTATS
 250};
 251
 252struct gfs2_lkstats {
 253        u64 stats[GFS2_NR_LKSTATS];
 254};
 255
 256enum {
 257        /* States */
 258        HIF_HOLDER              = 6,  /* Set for gh that "holds" the glock */
 259        HIF_FIRST               = 7,
 260        HIF_WAIT                = 10,
 261};
 262
 263struct gfs2_holder {
 264        struct list_head gh_list;
 265
 266        struct gfs2_glock *gh_gl;
 267        struct pid *gh_owner_pid;
 268        u16 gh_flags;
 269        u16 gh_state;
 270
 271        int gh_error;
 272        unsigned long gh_iflags; /* HIF_... */
 273        unsigned long gh_ip;
 274};
 275
 276/* Number of quota types we support */
 277#define GFS2_MAXQUOTAS 2
 278
 279struct gfs2_qadata { /* quota allocation data */
 280        /* Quota stuff */
 281        struct gfs2_quota_data *qa_qd[2 * GFS2_MAXQUOTAS];
 282        struct gfs2_holder qa_qd_ghs[2 * GFS2_MAXQUOTAS];
 283        unsigned int qa_qd_num;
 284        int qa_ref;
 285};
 286
 287/* Resource group multi-block reservation, in order of appearance:
 288
 289   Step 1. Function prepares to write, allocates a mb, sets the size hint.
 290   Step 2. User calls inplace_reserve to target an rgrp, sets the rgrp info
 291   Step 3. Function get_local_rgrp locks the rgrp, determines which bits to use
 292   Step 4. Bits are assigned from the rgrp based on either the reservation
 293           or wherever it can.
 294*/
 295
 296struct gfs2_blkreserv {
 297        struct rb_node rs_node;       /* node within rd_rstree */
 298        struct gfs2_rgrpd *rs_rgd;
 299        u64 rs_start;
 300        u32 rs_requested;
 301        u32 rs_reserved;              /* number of reserved blocks */
 302};
 303
 304/*
 305 * Allocation parameters
 306 * @target: The number of blocks we'd ideally like to allocate
 307 * @aflags: The flags (e.g. Orlov flag)
 308 *
 309 * The intent is to gradually expand this structure over time in
 310 * order to give more information, e.g. alignment, min extent size
 311 * to the allocation code.
 312 */
 313struct gfs2_alloc_parms {
 314        u64 target;
 315        u32 min_target;
 316        u32 aflags;
 317        u64 allowed;
 318};
 319
 320enum {
 321        GLF_LOCK                        = 1,
 322        GLF_DEMOTE                      = 3,
 323        GLF_PENDING_DEMOTE              = 4,
 324        GLF_DEMOTE_IN_PROGRESS          = 5,
 325        GLF_DIRTY                       = 6,
 326        GLF_LFLUSH                      = 7,
 327        GLF_INVALIDATE_IN_PROGRESS      = 8,
 328        GLF_REPLY_PENDING               = 9,
 329        GLF_INITIAL                     = 10,
 330        GLF_FROZEN                      = 11,
 331        GLF_LRU                         = 13,
 332        GLF_OBJECT                      = 14, /* Used only for tracing */
 333        GLF_BLOCKING                    = 15,
 334        GLF_PENDING_DELETE              = 17,
 335        GLF_FREEING                     = 18, /* Wait for glock to be freed */
 336};
 337
 338struct gfs2_glock {
 339        unsigned long gl_flags;         /* GLF_... */
 340        struct lm_lockname gl_name;
 341
 342        struct lockref gl_lockref;
 343
 344        /* State fields protected by gl_lockref.lock */
 345        unsigned int gl_state:2,        /* Current state */
 346                     gl_target:2,       /* Target state */
 347                     gl_demote_state:2, /* State requested by remote node */
 348                     gl_req:2,          /* State in last dlm request */
 349                     gl_reply:8;        /* Last reply from the dlm */
 350
 351        unsigned long gl_demote_time; /* time of first demote request */
 352        long gl_hold_time;
 353        struct list_head gl_holders;
 354
 355        const struct gfs2_glock_operations *gl_ops;
 356        ktime_t gl_dstamp;
 357        struct gfs2_lkstats gl_stats;
 358        struct dlm_lksb gl_lksb;
 359        unsigned long gl_tchange;
 360        void *gl_object;
 361
 362        struct list_head gl_lru;
 363        struct list_head gl_ail_list;
 364        atomic_t gl_ail_count;
 365        atomic_t gl_revokes;
 366        struct delayed_work gl_work;
 367        /* For iopen glocks only */
 368        struct {
 369                struct delayed_work gl_delete;
 370                u64 gl_no_formal_ino;
 371        };
 372        struct rcu_head gl_rcu;
 373        struct rhash_head gl_node;
 374};
 375
 376#define GFS2_MIN_LVB_SIZE 32    /* Min size of LVB that gfs2 supports */
 377
 378enum {
 379        GIF_INVALID             = 0,
 380        GIF_QD_LOCKED           = 1,
 381        GIF_ALLOC_FAILED        = 2,
 382        GIF_SW_PAGED            = 3,
 383        GIF_ORDERED             = 4,
 384        GIF_FREE_VFS_INODE      = 5,
 385        GIF_GLOP_PENDING        = 6,
 386        GIF_DEFERRED_DELETE     = 7,
 387};
 388
 389struct gfs2_inode {
 390        struct inode i_inode;
 391        u64 i_no_addr;
 392        u64 i_no_formal_ino;
 393        u64 i_generation;
 394        u64 i_eattr;
 395        unsigned long i_flags;          /* GIF_... */
 396        struct gfs2_glock *i_gl; /* Move into i_gh? */
 397        struct gfs2_holder i_iopen_gh;
 398        struct gfs2_holder i_gh; /* for prepare/commit_write only */
 399        struct gfs2_qadata *i_qadata; /* quota allocation data */
 400        struct gfs2_holder i_rgd_gh;
 401        struct gfs2_blkreserv i_res; /* rgrp multi-block reservation */
 402        u64 i_goal;     /* goal block for allocations */
 403        atomic_t i_sizehint;  /* hint of the write size */
 404        struct rw_semaphore i_rw_mutex;
 405        struct list_head i_ordered;
 406        struct list_head i_trunc_list;
 407        __be64 *i_hash_cache;
 408        u32 i_entries;
 409        u32 i_diskflags;
 410        u8 i_height;
 411        u8 i_depth;
 412        u16 i_rahead;
 413};
 414
 415/*
 416 * Since i_inode is the first element of struct gfs2_inode,
 417 * this is effectively a cast.
 418 */
 419static inline struct gfs2_inode *GFS2_I(struct inode *inode)
 420{
 421        return container_of(inode, struct gfs2_inode, i_inode);
 422}
 423
 424static inline struct gfs2_sbd *GFS2_SB(const struct inode *inode)
 425{
 426        return inode->i_sb->s_fs_info;
 427}
 428
 429struct gfs2_file {
 430        struct mutex f_fl_mutex;
 431        struct gfs2_holder f_fl_gh;
 432};
 433
 434struct gfs2_revoke_replay {
 435        struct list_head rr_list;
 436        u64 rr_blkno;
 437        unsigned int rr_where;
 438};
 439
 440enum {
 441        QDF_CHANGE              = 1,
 442        QDF_LOCKED              = 2,
 443        QDF_REFRESH             = 3,
 444        QDF_QMSG_QUIET          = 4,
 445};
 446
 447struct gfs2_quota_data {
 448        struct hlist_bl_node qd_hlist;
 449        struct list_head qd_list;
 450        struct kqid qd_id;
 451        struct gfs2_sbd *qd_sbd;
 452        struct lockref qd_lockref;
 453        struct list_head qd_lru;
 454        unsigned qd_hash;
 455
 456        unsigned long qd_flags;         /* QDF_... */
 457
 458        s64 qd_change;
 459        s64 qd_change_sync;
 460
 461        unsigned int qd_slot;
 462        unsigned int qd_slot_count;
 463
 464        struct buffer_head *qd_bh;
 465        struct gfs2_quota_change *qd_bh_qc;
 466        unsigned int qd_bh_count;
 467
 468        struct gfs2_glock *qd_gl;
 469        struct gfs2_quota_lvb qd_qb;
 470
 471        u64 qd_sync_gen;
 472        unsigned long qd_last_warn;
 473        struct rcu_head qd_rcu;
 474};
 475
 476enum {
 477        TR_TOUCHED = 1,
 478        TR_ATTACHED = 2,
 479        TR_ONSTACK = 3,
 480};
 481
 482struct gfs2_trans {
 483        unsigned long tr_ip;
 484
 485        unsigned int tr_blocks;
 486        unsigned int tr_revokes;
 487        unsigned int tr_reserved;
 488        unsigned long tr_flags;
 489
 490        unsigned int tr_num_buf_new;
 491        unsigned int tr_num_databuf_new;
 492        unsigned int tr_num_buf_rm;
 493        unsigned int tr_num_databuf_rm;
 494        unsigned int tr_num_revoke;
 495
 496        struct list_head tr_list;
 497        struct list_head tr_databuf;
 498        struct list_head tr_buf;
 499
 500        unsigned int tr_first;
 501        struct list_head tr_ail1_list;
 502        struct list_head tr_ail2_list;
 503};
 504
 505struct gfs2_journal_extent {
 506        struct list_head list;
 507
 508        unsigned int lblock; /* First logical block */
 509        u64 dblock; /* First disk block */
 510        u64 blocks;
 511};
 512
 513struct gfs2_jdesc {
 514        struct list_head jd_list;
 515        struct list_head extent_list;
 516        unsigned int nr_extents;
 517        struct work_struct jd_work;
 518        struct inode *jd_inode;
 519        struct bio *jd_log_bio;
 520        unsigned long jd_flags;
 521#define JDF_RECOVERY 1
 522        unsigned int jd_jid;
 523        u32 jd_blocks;
 524        int jd_recover_error;
 525        /* Replay stuff */
 526
 527        unsigned int jd_found_blocks;
 528        unsigned int jd_found_revokes;
 529        unsigned int jd_replayed_blocks;
 530
 531        struct list_head jd_revoke_list;
 532        unsigned int jd_replay_tail;
 533
 534        u64 jd_no_addr;
 535};
 536
 537struct gfs2_statfs_change_host {
 538        s64 sc_total;
 539        s64 sc_free;
 540        s64 sc_dinodes;
 541};
 542
 543#define GFS2_QUOTA_DEFAULT      GFS2_QUOTA_OFF
 544#define GFS2_QUOTA_OFF          0
 545#define GFS2_QUOTA_ACCOUNT      1
 546#define GFS2_QUOTA_ON           2
 547
 548#define GFS2_DATA_DEFAULT       GFS2_DATA_ORDERED
 549#define GFS2_DATA_WRITEBACK     1
 550#define GFS2_DATA_ORDERED       2
 551
 552#define GFS2_ERRORS_DEFAULT     GFS2_ERRORS_WITHDRAW
 553#define GFS2_ERRORS_WITHDRAW    0
 554#define GFS2_ERRORS_CONTINUE    1 /* place holder for future feature */
 555#define GFS2_ERRORS_RO          2 /* place holder for future feature */
 556#define GFS2_ERRORS_PANIC       3
 557
 558struct gfs2_args {
 559        char ar_lockproto[GFS2_LOCKNAME_LEN];   /* Name of the Lock Protocol */
 560        char ar_locktable[GFS2_LOCKNAME_LEN];   /* Name of the Lock Table */
 561        char ar_hostdata[GFS2_LOCKNAME_LEN];    /* Host specific data */
 562        unsigned int ar_spectator:1;            /* Don't get a journal */
 563        unsigned int ar_localflocks:1;          /* Let the VFS do flock|fcntl */
 564        unsigned int ar_debug:1;                /* Oops on errors */
 565        unsigned int ar_posix_acl:1;            /* Enable posix acls */
 566        unsigned int ar_quota:2;                /* off/account/on */
 567        unsigned int ar_suiddir:1;              /* suiddir support */
 568        unsigned int ar_data:2;                 /* ordered/writeback */
 569        unsigned int ar_meta:1;                 /* mount metafs */
 570        unsigned int ar_discard:1;              /* discard requests */
 571        unsigned int ar_errors:2;               /* errors=withdraw | panic */
 572        unsigned int ar_nobarrier:1;            /* do not send barriers */
 573        unsigned int ar_rgrplvb:1;              /* use lvbs for rgrp info */
 574        unsigned int ar_loccookie:1;            /* use location based readdir
 575                                                   cookies */
 576        s32 ar_commit;                          /* Commit interval */
 577        s32 ar_statfs_quantum;                  /* The fast statfs interval */
 578        s32 ar_quota_quantum;                   /* The quota interval */
 579        s32 ar_statfs_percent;                  /* The % change to force sync */
 580};
 581
 582struct gfs2_tune {
 583        spinlock_t gt_spin;
 584
 585        unsigned int gt_logd_secs;
 586
 587        unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */
 588        unsigned int gt_quota_scale_num; /* Numerator */
 589        unsigned int gt_quota_scale_den; /* Denominator */
 590        unsigned int gt_quota_quantum; /* Secs between syncs to quota file */
 591        unsigned int gt_new_files_jdata;
 592        unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */
 593        unsigned int gt_complain_secs;
 594        unsigned int gt_statfs_quantum;
 595        unsigned int gt_statfs_slow;
 596};
 597
 598enum {
 599        SDF_JOURNAL_CHECKED     = 0,
 600        SDF_JOURNAL_LIVE        = 1,
 601        SDF_WITHDRAWN           = 2,
 602        SDF_NOBARRIERS          = 3,
 603        SDF_NORECOVERY          = 4,
 604        SDF_DEMOTE              = 5,
 605        SDF_NOJOURNALID         = 6,
 606        SDF_RORECOVERY          = 7, /* read only recovery */
 607        SDF_SKIP_DLM_UNLOCK     = 8,
 608        SDF_FORCE_AIL_FLUSH     = 9,
 609        SDF_FS_FROZEN           = 10,
 610        SDF_WITHDRAWING         = 11, /* Will withdraw eventually */
 611        SDF_WITHDRAW_IN_PROG    = 12, /* Withdraw is in progress */
 612        SDF_REMOTE_WITHDRAW     = 13, /* Performing remote recovery */
 613        SDF_WITHDRAW_RECOVERY   = 14, /* Wait for journal recovery when we are
 614                                         withdrawing */
 615};
 616
 617enum gfs2_freeze_state {
 618        SFS_UNFROZEN            = 0,
 619        SFS_STARTING_FREEZE     = 1,
 620        SFS_FROZEN              = 2,
 621};
 622
 623#define GFS2_FSNAME_LEN         256
 624
 625struct gfs2_inum_host {
 626        u64 no_formal_ino;
 627        u64 no_addr;
 628};
 629
 630struct gfs2_sb_host {
 631        u32 sb_magic;
 632        u32 sb_type;
 633
 634        u32 sb_fs_format;
 635        u32 sb_multihost_format;
 636        u32 sb_bsize;
 637        u32 sb_bsize_shift;
 638
 639        struct gfs2_inum_host sb_master_dir;
 640        struct gfs2_inum_host sb_root_dir;
 641
 642        char sb_lockproto[GFS2_LOCKNAME_LEN];
 643        char sb_locktable[GFS2_LOCKNAME_LEN];
 644};
 645
 646/*
 647 * lm_mount() return values
 648 *
 649 * ls_jid - the journal ID this node should use
 650 * ls_first - this node is the first to mount the file system
 651 * ls_lockspace - lock module's context for this file system
 652 * ls_ops - lock module's functions
 653 */
 654
 655struct lm_lockstruct {
 656        int ls_jid;
 657        unsigned int ls_first;
 658        const struct lm_lockops *ls_ops;
 659        dlm_lockspace_t *ls_dlm;
 660
 661        int ls_recover_jid_done;   /* These two are deprecated, */
 662        int ls_recover_jid_status; /* used previously by gfs_controld */
 663
 664        struct dlm_lksb ls_mounted_lksb; /* mounted_lock */
 665        struct dlm_lksb ls_control_lksb; /* control_lock */
 666        char ls_control_lvb[GDLM_LVB_SIZE]; /* control_lock lvb */
 667        struct completion ls_sync_wait; /* {control,mounted}_{lock,unlock} */
 668        char *ls_lvb_bits;
 669
 670        spinlock_t ls_recover_spin; /* protects following fields */
 671        unsigned long ls_recover_flags; /* DFL_ */
 672        uint32_t ls_recover_mount; /* gen in first recover_done cb */
 673        uint32_t ls_recover_start; /* gen in last recover_done cb */
 674        uint32_t ls_recover_block; /* copy recover_start in last recover_prep */
 675        uint32_t ls_recover_size; /* size of recover_submit, recover_result */
 676        uint32_t *ls_recover_submit; /* gen in last recover_slot cb per jid */
 677        uint32_t *ls_recover_result; /* result of last jid recovery */
 678};
 679
 680struct gfs2_pcpu_lkstats {
 681        /* One struct for each glock type */
 682        struct gfs2_lkstats lkstats[10];
 683};
 684
 685/* List of local (per node) statfs inodes */
 686struct lcl_statfs_inode {
 687        struct list_head si_list;
 688        struct inode *si_sc_inode;
 689        unsigned int si_jid; /* journal id this statfs inode corresponds to */
 690};
 691
 692struct gfs2_sbd {
 693        struct super_block *sd_vfs;
 694        struct gfs2_pcpu_lkstats __percpu *sd_lkstats;
 695        struct kobject sd_kobj;
 696        struct completion sd_kobj_unregister;
 697        unsigned long sd_flags; /* SDF_... */
 698        struct gfs2_sb_host sd_sb;
 699
 700        /* Constants computed on mount */
 701
 702        u32 sd_fsb2bb;
 703        u32 sd_fsb2bb_shift;
 704        u32 sd_diptrs;  /* Number of pointers in a dinode */
 705        u32 sd_inptrs;  /* Number of pointers in a indirect block */
 706        u32 sd_ldptrs;  /* Number of pointers in a log descriptor block */
 707        u32 sd_jbsize;  /* Size of a journaled data block */
 708        u32 sd_hash_bsize;      /* sizeof(exhash block) */
 709        u32 sd_hash_bsize_shift;
 710        u32 sd_hash_ptrs;       /* Number of pointers in a hash block */
 711        u32 sd_qc_per_block;
 712        u32 sd_blocks_per_bitmap;
 713        u32 sd_max_dirres;      /* Max blocks needed to add a directory entry */
 714        u32 sd_max_height;      /* Max height of a file's metadata tree */
 715        u64 sd_heightsize[GFS2_MAX_META_HEIGHT + 1];
 716        u32 sd_max_dents_per_leaf; /* Max number of dirents in a leaf block */
 717
 718        struct gfs2_args sd_args;       /* Mount arguments */
 719        struct gfs2_tune sd_tune;       /* Filesystem tuning structure */
 720
 721        /* Lock Stuff */
 722
 723        struct lm_lockstruct sd_lockstruct;
 724        struct gfs2_holder sd_live_gh;
 725        struct gfs2_glock *sd_rename_gl;
 726        struct gfs2_glock *sd_freeze_gl;
 727        struct work_struct sd_freeze_work;
 728        wait_queue_head_t sd_glock_wait;
 729        wait_queue_head_t sd_async_glock_wait;
 730        atomic_t sd_glock_disposal;
 731        struct completion sd_locking_init;
 732        struct completion sd_wdack;
 733        struct delayed_work sd_control_work;
 734
 735        /* Inode Stuff */
 736
 737        struct dentry *sd_master_dir;
 738        struct dentry *sd_root_dir;
 739
 740        struct inode *sd_jindex;
 741        struct inode *sd_statfs_inode;
 742        struct inode *sd_sc_inode;
 743        struct list_head sd_sc_inodes_list;
 744        struct inode *sd_qc_inode;
 745        struct inode *sd_rindex;
 746        struct inode *sd_quota_inode;
 747
 748        /* StatFS stuff */
 749
 750        spinlock_t sd_statfs_spin;
 751        struct gfs2_statfs_change_host sd_statfs_master;
 752        struct gfs2_statfs_change_host sd_statfs_local;
 753        int sd_statfs_force_sync;
 754
 755        /* Resource group stuff */
 756
 757        int sd_rindex_uptodate;
 758        spinlock_t sd_rindex_spin;
 759        struct rb_root sd_rindex_tree;
 760        unsigned int sd_rgrps;
 761        unsigned int sd_max_rg_data;
 762
 763        /* Journal index stuff */
 764
 765        struct list_head sd_jindex_list;
 766        spinlock_t sd_jindex_spin;
 767        struct mutex sd_jindex_mutex;
 768        unsigned int sd_journals;
 769
 770        struct gfs2_jdesc *sd_jdesc;
 771        struct gfs2_holder sd_journal_gh;
 772        struct gfs2_holder sd_jinode_gh;
 773        struct gfs2_glock *sd_jinode_gl;
 774
 775        struct gfs2_holder sd_sc_gh;
 776        struct gfs2_holder sd_qc_gh;
 777
 778        struct completion sd_journal_ready;
 779
 780        /* Daemon stuff */
 781
 782        struct task_struct *sd_logd_process;
 783        struct task_struct *sd_quotad_process;
 784
 785        /* Quota stuff */
 786
 787        struct list_head sd_quota_list;
 788        atomic_t sd_quota_count;
 789        struct mutex sd_quota_mutex;
 790        struct mutex sd_quota_sync_mutex;
 791        wait_queue_head_t sd_quota_wait;
 792        struct list_head sd_trunc_list;
 793        spinlock_t sd_trunc_lock;
 794
 795        unsigned int sd_quota_slots;
 796        unsigned long *sd_quota_bitmap;
 797        spinlock_t sd_bitmap_lock;
 798
 799        u64 sd_quota_sync_gen;
 800
 801        /* Log stuff */
 802
 803        struct address_space sd_aspace;
 804
 805        spinlock_t sd_log_lock;
 806
 807        struct gfs2_trans *sd_log_tr;
 808        unsigned int sd_log_blks_reserved;
 809
 810        atomic_t sd_log_pinned;
 811        unsigned int sd_log_num_revoke;
 812
 813        struct list_head sd_log_revokes;
 814        struct list_head sd_log_ordered;
 815        spinlock_t sd_ordered_lock;
 816
 817        atomic_t sd_log_thresh1;
 818        atomic_t sd_log_thresh2;
 819        atomic_t sd_log_blks_free;
 820        atomic_t sd_log_blks_needed;
 821        atomic_t sd_log_revokes_available;
 822        wait_queue_head_t sd_log_waitq;
 823        wait_queue_head_t sd_logd_waitq;
 824
 825        u64 sd_log_sequence;
 826        int sd_log_idle;
 827
 828        struct rw_semaphore sd_log_flush_lock;
 829        atomic_t sd_log_in_flight;
 830        wait_queue_head_t sd_log_flush_wait;
 831        int sd_log_error; /* First log error */
 832        wait_queue_head_t sd_withdraw_wait;
 833
 834        unsigned int sd_log_tail;
 835        unsigned int sd_log_flush_tail;
 836        unsigned int sd_log_head;
 837        unsigned int sd_log_flush_head;
 838
 839        spinlock_t sd_ail_lock;
 840        struct list_head sd_ail1_list;
 841        struct list_head sd_ail2_list;
 842
 843        /* For quiescing the filesystem */
 844        struct gfs2_holder sd_freeze_gh;
 845        atomic_t sd_freeze_state;
 846        struct mutex sd_freeze_mutex;
 847
 848        char sd_fsname[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2];
 849        char sd_table_name[GFS2_FSNAME_LEN];
 850        char sd_proto_name[GFS2_FSNAME_LEN];
 851
 852        /* Debugging crud */
 853
 854        unsigned long sd_last_warning;
 855        struct dentry *debugfs_dir;    /* debugfs directory */
 856        unsigned long sd_glock_dqs_held;
 857};
 858
 859static inline void gfs2_glstats_inc(struct gfs2_glock *gl, int which)
 860{
 861        gl->gl_stats.stats[which]++;
 862}
 863
 864static inline void gfs2_sbstats_inc(const struct gfs2_glock *gl, int which)
 865{
 866        const struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
 867        preempt_disable();
 868        this_cpu_ptr(sdp->sd_lkstats)->lkstats[gl->gl_name.ln_type].stats[which]++;
 869        preempt_enable();
 870}
 871
 872extern struct gfs2_rgrpd *gfs2_glock2rgrp(struct gfs2_glock *gl);
 873
 874static inline unsigned gfs2_max_stuffed_size(const struct gfs2_inode *ip)
 875{
 876        return GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
 877}
 878
 879#endif /* __INCORE_DOT_H__ */
 880
 881