incore.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. #ifndef __INCORE_DOT_H__
  10. #define __INCORE_DOT_H__
  11. #include <linux/fs.h>
  12. #define DIO_WAIT 0x00000010
  13. #define DIO_METADATA 0x00000020
  14. #define DIO_ALL 0x00000100
  15. struct gfs2_log_operations;
  16. struct gfs2_log_element;
  17. struct gfs2_holder;
  18. struct gfs2_glock;
  19. struct gfs2_quota_data;
  20. struct gfs2_trans;
  21. struct gfs2_ail;
  22. struct gfs2_jdesc;
  23. struct gfs2_sbd;
  24. typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret);
  25. /*
  26. * Structure of operations that are associated with each
  27. * type of element in the log.
  28. */
  29. struct gfs2_log_operations {
  30. void (*lo_add) (struct gfs2_sbd *sdp, struct gfs2_log_element *le);
  31. void (*lo_incore_commit) (struct gfs2_sbd *sdp, struct gfs2_trans *tr);
  32. void (*lo_before_commit) (struct gfs2_sbd *sdp);
  33. void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_ail *ai);
  34. void (*lo_before_scan) (struct gfs2_jdesc *jd,
  35. struct gfs2_log_header_host *head, int pass);
  36. int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start,
  37. struct gfs2_log_descriptor *ld, __be64 *ptr,
  38. int pass);
  39. void (*lo_after_scan) (struct gfs2_jdesc *jd, int error, int pass);
  40. const char *lo_name;
  41. };
  42. struct gfs2_log_element {
  43. struct list_head le_list;
  44. const struct gfs2_log_operations *le_ops;
  45. };
  46. struct gfs2_bitmap {
  47. struct buffer_head *bi_bh;
  48. char *bi_clone;
  49. u32 bi_offset;
  50. u32 bi_start;
  51. u32 bi_len;
  52. };
  53. struct gfs2_rgrpd {
  54. struct list_head rd_list; /* Link with superblock */
  55. struct list_head rd_list_mru;
  56. struct list_head rd_recent; /* Recently used rgrps */
  57. struct gfs2_glock *rd_gl; /* Glock for this rgrp */
  58. struct gfs2_rindex_host rd_ri;
  59. struct gfs2_rgrp_host rd_rg;
  60. u64 rd_rg_vn;
  61. struct gfs2_bitmap *rd_bits;
  62. unsigned int rd_bh_count;
  63. struct mutex rd_mutex;
  64. u32 rd_free_clone;
  65. struct gfs2_log_element rd_le;
  66. u32 rd_last_alloc_data;
  67. u32 rd_last_alloc_meta;
  68. struct gfs2_sbd *rd_sbd;
  69. };
  70. enum gfs2_state_bits {
  71. BH_Pinned = BH_PrivateStart,
  72. BH_Escaped = BH_PrivateStart + 1,
  73. };
  74. BUFFER_FNS(Pinned, pinned)
  75. TAS_BUFFER_FNS(Pinned, pinned)
  76. BUFFER_FNS(Escaped, escaped)
  77. TAS_BUFFER_FNS(Escaped, escaped)
  78. struct gfs2_bufdata {
  79. struct buffer_head *bd_bh;
  80. struct gfs2_glock *bd_gl;
  81. struct list_head bd_list_tr;
  82. struct gfs2_log_element bd_le;
  83. struct gfs2_ail *bd_ail;
  84. struct list_head bd_ail_st_list;
  85. struct list_head bd_ail_gl_list;
  86. };
  87. struct gfs2_glock_operations {
  88. void (*go_xmote_th) (struct gfs2_glock *gl, unsigned int state, int flags);
  89. void (*go_xmote_bh) (struct gfs2_glock *gl);
  90. void (*go_drop_th) (struct gfs2_glock *gl);
  91. void (*go_drop_bh) (struct gfs2_glock *gl);
  92. void (*go_sync) (struct gfs2_glock *gl);
  93. void (*go_inval) (struct gfs2_glock *gl, int flags);
  94. int (*go_demote_ok) (struct gfs2_glock *gl);
  95. int (*go_lock) (struct gfs2_holder *gh);
  96. void (*go_unlock) (struct gfs2_holder *gh);
  97. void (*go_callback) (struct gfs2_glock *gl, unsigned int state);
  98. void (*go_greedy) (struct gfs2_glock *gl);
  99. const int go_type;
  100. };
  101. enum {
  102. /* Actions */
  103. HIF_MUTEX = 0,
  104. HIF_PROMOTE = 1,
  105. HIF_DEMOTE = 2,
  106. HIF_GREEDY = 3,
  107. /* States */
  108. HIF_ALLOCED = 4,
  109. HIF_DEALLOC = 5,
  110. HIF_HOLDER = 6,
  111. HIF_FIRST = 7,
  112. HIF_ABORTED = 9,
  113. };
  114. struct gfs2_holder {
  115. struct list_head gh_list;
  116. struct gfs2_glock *gh_gl;
  117. struct task_struct *gh_owner;
  118. unsigned int gh_state;
  119. unsigned gh_flags;
  120. int gh_error;
  121. unsigned long gh_iflags;
  122. struct completion gh_wait;
  123. unsigned long gh_ip;
  124. };
  125. enum {
  126. GLF_LOCK = 1,
  127. GLF_STICKY = 2,
  128. GLF_PREFETCH = 3,
  129. GLF_DIRTY = 5,
  130. GLF_SKIP_WAITERS2 = 6,
  131. GLF_GREEDY = 7,
  132. };
  133. struct gfs2_glock {
  134. struct hlist_node gl_list;
  135. unsigned long gl_flags; /* GLF_... */
  136. struct lm_lockname gl_name;
  137. atomic_t gl_ref;
  138. spinlock_t gl_spin;
  139. unsigned int gl_state;
  140. unsigned int gl_hash;
  141. struct task_struct *gl_owner;
  142. unsigned long gl_ip;
  143. struct list_head gl_holders;
  144. struct list_head gl_waiters1; /* HIF_MUTEX */
  145. struct list_head gl_waiters2; /* HIF_DEMOTE, HIF_GREEDY */
  146. struct list_head gl_waiters3; /* HIF_PROMOTE */
  147. const struct gfs2_glock_operations *gl_ops;
  148. struct gfs2_holder *gl_req_gh;
  149. gfs2_glop_bh_t gl_req_bh;
  150. void *gl_lock;
  151. char *gl_lvb;
  152. atomic_t gl_lvb_count;
  153. u64 gl_vn;
  154. unsigned long gl_stamp;
  155. void *gl_object;
  156. struct list_head gl_reclaim;
  157. struct gfs2_sbd *gl_sbd;
  158. struct inode *gl_aspace;
  159. struct gfs2_log_element gl_le;
  160. struct list_head gl_ail_list;
  161. atomic_t gl_ail_count;
  162. };
  163. struct gfs2_alloc {
  164. /* Quota stuff */
  165. struct gfs2_quota_data *al_qd[2*MAXQUOTAS];
  166. struct gfs2_holder al_qd_ghs[2*MAXQUOTAS];
  167. unsigned int al_qd_num;
  168. u32 al_requested; /* Filled in by caller of gfs2_inplace_reserve() */
  169. u32 al_alloced; /* Filled in by gfs2_alloc_*() */
  170. /* Filled in by gfs2_inplace_reserve() */
  171. unsigned int al_line;
  172. char *al_file;
  173. struct gfs2_holder al_ri_gh;
  174. struct gfs2_holder al_rgd_gh;
  175. struct gfs2_rgrpd *al_rgd;
  176. };
  177. enum {
  178. GIF_INVALID = 0,
  179. GIF_QD_LOCKED = 1,
  180. GIF_PAGED = 2,
  181. GIF_SW_PAGED = 3,
  182. };
  183. struct gfs2_inode {
  184. struct inode i_inode;
  185. struct gfs2_inum_host i_num;
  186. unsigned long i_flags; /* GIF_... */
  187. struct gfs2_dinode_host i_di; /* To be replaced by ref to block */
  188. struct gfs2_glock *i_gl; /* Move into i_gh? */
  189. struct gfs2_holder i_iopen_gh;
  190. struct gfs2_holder i_gh; /* for prepare/commit_write only */
  191. struct gfs2_alloc i_alloc;
  192. u64 i_last_rg_alloc;
  193. spinlock_t i_spin;
  194. struct rw_semaphore i_rw_mutex;
  195. unsigned int i_greedy;
  196. unsigned long i_last_pfault;
  197. struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT];
  198. };
  199. /*
  200. * Since i_inode is the first element of struct gfs2_inode,
  201. * this is effectively a cast.
  202. */
  203. static inline struct gfs2_inode *GFS2_I(struct inode *inode)
  204. {
  205. return container_of(inode, struct gfs2_inode, i_inode);
  206. }
  207. /* To be removed? */
  208. static inline struct gfs2_sbd *GFS2_SB(struct inode *inode)
  209. {
  210. return inode->i_sb->s_fs_info;
  211. }
  212. enum {
  213. GFF_DID_DIRECT_ALLOC = 0,
  214. GFF_EXLOCK = 1,
  215. };
  216. struct gfs2_file {
  217. unsigned long f_flags; /* GFF_... */
  218. struct mutex f_fl_mutex;
  219. struct gfs2_holder f_fl_gh;
  220. };
  221. struct gfs2_revoke {
  222. struct gfs2_log_element rv_le;
  223. u64 rv_blkno;
  224. };
  225. struct gfs2_revoke_replay {
  226. struct list_head rr_list;
  227. u64 rr_blkno;
  228. unsigned int rr_where;
  229. };
  230. enum {
  231. QDF_USER = 0,
  232. QDF_CHANGE = 1,
  233. QDF_LOCKED = 2,
  234. };
  235. struct gfs2_quota_lvb {
  236. __be32 qb_magic;
  237. u32 __pad;
  238. __be64 qb_limit; /* Hard limit of # blocks to alloc */
  239. __be64 qb_warn; /* Warn user when alloc is above this # */
  240. __be64 qb_value; /* Current # blocks allocated */
  241. };
  242. struct gfs2_quota_data {
  243. struct list_head qd_list;
  244. unsigned int qd_count;
  245. u32 qd_id;
  246. unsigned long qd_flags; /* QDF_... */
  247. s64 qd_change;
  248. s64 qd_change_sync;
  249. unsigned int qd_slot;
  250. unsigned int qd_slot_count;
  251. struct buffer_head *qd_bh;
  252. struct gfs2_quota_change *qd_bh_qc;
  253. unsigned int qd_bh_count;
  254. struct gfs2_glock *qd_gl;
  255. struct gfs2_quota_lvb qd_qb;
  256. u64 qd_sync_gen;
  257. unsigned long qd_last_warn;
  258. unsigned long qd_last_touched;
  259. };
  260. struct gfs2_log_buf {
  261. struct list_head lb_list;
  262. struct buffer_head *lb_bh;
  263. struct buffer_head *lb_real;
  264. };
  265. struct gfs2_trans {
  266. unsigned long tr_ip;
  267. unsigned int tr_blocks;
  268. unsigned int tr_revokes;
  269. unsigned int tr_reserved;
  270. struct gfs2_holder tr_t_gh;
  271. int tr_touched;
  272. unsigned int tr_num_buf;
  273. unsigned int tr_num_buf_new;
  274. unsigned int tr_num_buf_rm;
  275. struct list_head tr_list_buf;
  276. unsigned int tr_num_revoke;
  277. unsigned int tr_num_revoke_rm;
  278. };
  279. struct gfs2_ail {
  280. struct list_head ai_list;
  281. unsigned int ai_first;
  282. struct list_head ai_ail1_list;
  283. struct list_head ai_ail2_list;
  284. u64 ai_sync_gen;
  285. };
  286. struct gfs2_jdesc {
  287. struct list_head jd_list;
  288. struct inode *jd_inode;
  289. unsigned int jd_jid;
  290. int jd_dirty;
  291. unsigned int jd_blocks;
  292. };
  293. #define GFS2_GLOCKD_DEFAULT 1
  294. #define GFS2_GLOCKD_MAX 16
  295. #define GFS2_QUOTA_DEFAULT GFS2_QUOTA_OFF
  296. #define GFS2_QUOTA_OFF 0
  297. #define GFS2_QUOTA_ACCOUNT 1
  298. #define GFS2_QUOTA_ON 2
  299. #define GFS2_DATA_DEFAULT GFS2_DATA_ORDERED
  300. #define GFS2_DATA_WRITEBACK 1
  301. #define GFS2_DATA_ORDERED 2
  302. struct gfs2_args {
  303. char ar_lockproto[GFS2_LOCKNAME_LEN]; /* Name of the Lock Protocol */
  304. char ar_locktable[GFS2_LOCKNAME_LEN]; /* Name of the Lock Table */
  305. char ar_hostdata[GFS2_LOCKNAME_LEN]; /* Host specific data */
  306. int ar_spectator; /* Don't get a journal because we're always RO */
  307. int ar_ignore_local_fs; /* Don't optimize even if local_fs is 1 */
  308. int ar_localflocks; /* Let the VFS do flock|fcntl locks for us */
  309. int ar_localcaching; /* Local-style caching (dangerous on multihost) */
  310. int ar_debug; /* Oops on errors instead of trying to be graceful */
  311. int ar_upgrade; /* Upgrade ondisk/multihost format */
  312. unsigned int ar_num_glockd; /* Number of glockd threads */
  313. int ar_posix_acl; /* Enable posix acls */
  314. int ar_quota; /* off/account/on */
  315. int ar_suiddir; /* suiddir support */
  316. int ar_data; /* ordered/writeback */
  317. };
  318. struct gfs2_tune {
  319. spinlock_t gt_spin;
  320. unsigned int gt_ilimit;
  321. unsigned int gt_ilimit_tries;
  322. unsigned int gt_ilimit_min;
  323. unsigned int gt_demote_secs; /* Cache retention for unheld glock */
  324. unsigned int gt_incore_log_blocks;
  325. unsigned int gt_log_flush_secs;
  326. unsigned int gt_jindex_refresh_secs; /* Check for new journal index */
  327. unsigned int gt_scand_secs;
  328. unsigned int gt_recoverd_secs;
  329. unsigned int gt_logd_secs;
  330. unsigned int gt_quotad_secs;
  331. unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */
  332. unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */
  333. unsigned int gt_quota_scale_num; /* Numerator */
  334. unsigned int gt_quota_scale_den; /* Denominator */
  335. unsigned int gt_quota_cache_secs;
  336. unsigned int gt_quota_quantum; /* Secs between syncs to quota file */
  337. unsigned int gt_atime_quantum; /* Min secs between atime updates */
  338. unsigned int gt_new_files_jdata;
  339. unsigned int gt_new_files_directio;
  340. unsigned int gt_max_atomic_write; /* Split big writes into this size */
  341. unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */
  342. unsigned int gt_lockdump_size;
  343. unsigned int gt_stall_secs; /* Detects trouble! */
  344. unsigned int gt_complain_secs;
  345. unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */
  346. unsigned int gt_entries_per_readdir;
  347. unsigned int gt_prefetch_secs; /* Usage window for prefetched glocks */
  348. unsigned int gt_greedy_default;
  349. unsigned int gt_greedy_quantum;
  350. unsigned int gt_greedy_max;
  351. unsigned int gt_statfs_quantum;
  352. unsigned int gt_statfs_slow;
  353. };
  354. enum {
  355. SDF_JOURNAL_CHECKED = 0,
  356. SDF_JOURNAL_LIVE = 1,
  357. SDF_SHUTDOWN = 2,
  358. SDF_NOATIME = 3,
  359. };
  360. #define GFS2_FSNAME_LEN 256
  361. struct gfs2_sbd {
  362. struct super_block *sd_vfs;
  363. struct super_block *sd_vfs_meta;
  364. struct kobject sd_kobj;
  365. unsigned long sd_flags; /* SDF_... */
  366. struct gfs2_sb_host sd_sb;
  367. /* Constants computed on mount */
  368. u32 sd_fsb2bb;
  369. u32 sd_fsb2bb_shift;
  370. u32 sd_diptrs; /* Number of pointers in a dinode */
  371. u32 sd_inptrs; /* Number of pointers in a indirect block */
  372. u32 sd_jbsize; /* Size of a journaled data block */
  373. u32 sd_hash_bsize; /* sizeof(exhash block) */
  374. u32 sd_hash_bsize_shift;
  375. u32 sd_hash_ptrs; /* Number of pointers in a hash block */
  376. u32 sd_qc_per_block;
  377. u32 sd_max_dirres; /* Max blocks needed to add a directory entry */
  378. u32 sd_max_height; /* Max height of a file's metadata tree */
  379. u64 sd_heightsize[GFS2_MAX_META_HEIGHT];
  380. u32 sd_max_jheight; /* Max height of journaled file's meta tree */
  381. u64 sd_jheightsize[GFS2_MAX_META_HEIGHT];
  382. struct gfs2_args sd_args; /* Mount arguments */
  383. struct gfs2_tune sd_tune; /* Filesystem tuning structure */
  384. /* Lock Stuff */
  385. struct lm_lockstruct sd_lockstruct;
  386. struct list_head sd_reclaim_list;
  387. spinlock_t sd_reclaim_lock;
  388. wait_queue_head_t sd_reclaim_wq;
  389. atomic_t sd_reclaim_count;
  390. struct gfs2_holder sd_live_gh;
  391. struct gfs2_glock *sd_rename_gl;
  392. struct gfs2_glock *sd_trans_gl;
  393. /* Inode Stuff */
  394. struct inode *sd_master_dir;
  395. struct inode *sd_jindex;
  396. struct inode *sd_inum_inode;
  397. struct inode *sd_statfs_inode;
  398. struct inode *sd_ir_inode;
  399. struct inode *sd_sc_inode;
  400. struct inode *sd_qc_inode;
  401. struct inode *sd_rindex;
  402. struct inode *sd_quota_inode;
  403. /* Inum stuff */
  404. struct mutex sd_inum_mutex;
  405. /* StatFS stuff */
  406. spinlock_t sd_statfs_spin;
  407. struct mutex sd_statfs_mutex;
  408. struct gfs2_statfs_change_host sd_statfs_master;
  409. struct gfs2_statfs_change_host sd_statfs_local;
  410. unsigned long sd_statfs_sync_time;
  411. /* Resource group stuff */
  412. u64 sd_rindex_vn;
  413. spinlock_t sd_rindex_spin;
  414. struct mutex sd_rindex_mutex;
  415. struct list_head sd_rindex_list;
  416. struct list_head sd_rindex_mru_list;
  417. struct list_head sd_rindex_recent_list;
  418. struct gfs2_rgrpd *sd_rindex_forward;
  419. unsigned int sd_rgrps;
  420. /* Journal index stuff */
  421. struct list_head sd_jindex_list;
  422. spinlock_t sd_jindex_spin;
  423. struct mutex sd_jindex_mutex;
  424. unsigned int sd_journals;
  425. unsigned long sd_jindex_refresh_time;
  426. struct gfs2_jdesc *sd_jdesc;
  427. struct gfs2_holder sd_journal_gh;
  428. struct gfs2_holder sd_jinode_gh;
  429. struct gfs2_holder sd_ir_gh;
  430. struct gfs2_holder sd_sc_gh;
  431. struct gfs2_holder sd_qc_gh;
  432. /* Daemon stuff */
  433. struct task_struct *sd_scand_process;
  434. struct task_struct *sd_recoverd_process;
  435. struct task_struct *sd_logd_process;
  436. struct task_struct *sd_quotad_process;
  437. struct task_struct *sd_glockd_process[GFS2_GLOCKD_MAX];
  438. unsigned int sd_glockd_num;
  439. /* Quota stuff */
  440. struct list_head sd_quota_list;
  441. atomic_t sd_quota_count;
  442. spinlock_t sd_quota_spin;
  443. struct mutex sd_quota_mutex;
  444. unsigned int sd_quota_slots;
  445. unsigned int sd_quota_chunks;
  446. unsigned char **sd_quota_bitmap;
  447. u64 sd_quota_sync_gen;
  448. unsigned long sd_quota_sync_time;
  449. /* Log stuff */
  450. spinlock_t sd_log_lock;
  451. unsigned int sd_log_blks_reserved;
  452. unsigned int sd_log_commited_buf;
  453. unsigned int sd_log_commited_revoke;
  454. unsigned int sd_log_num_gl;
  455. unsigned int sd_log_num_buf;
  456. unsigned int sd_log_num_revoke;
  457. unsigned int sd_log_num_rg;
  458. unsigned int sd_log_num_databuf;
  459. unsigned int sd_log_num_jdata;
  460. unsigned int sd_log_num_hdrs;
  461. struct list_head sd_log_le_gl;
  462. struct list_head sd_log_le_buf;
  463. struct list_head sd_log_le_revoke;
  464. struct list_head sd_log_le_rg;
  465. struct list_head sd_log_le_databuf;
  466. unsigned int sd_log_blks_free;
  467. struct mutex sd_log_reserve_mutex;
  468. u64 sd_log_sequence;
  469. unsigned int sd_log_head;
  470. unsigned int sd_log_tail;
  471. int sd_log_idle;
  472. unsigned long sd_log_flush_time;
  473. struct rw_semaphore sd_log_flush_lock;
  474. struct list_head sd_log_flush_list;
  475. unsigned int sd_log_flush_head;
  476. u64 sd_log_flush_wrapped;
  477. struct list_head sd_ail1_list;
  478. struct list_head sd_ail2_list;
  479. u64 sd_ail_sync_gen;
  480. /* Replay stuff */
  481. struct list_head sd_revoke_list;
  482. unsigned int sd_replay_tail;
  483. unsigned int sd_found_blocks;
  484. unsigned int sd_found_revokes;
  485. unsigned int sd_replayed_blocks;
  486. /* For quiescing the filesystem */
  487. struct gfs2_holder sd_freeze_gh;
  488. struct mutex sd_freeze_lock;
  489. unsigned int sd_freeze_count;
  490. /* Counters */
  491. atomic_t sd_glock_count;
  492. atomic_t sd_glock_held_count;
  493. atomic_t sd_inode_count;
  494. atomic_t sd_reclaimed;
  495. char sd_fsname[GFS2_FSNAME_LEN];
  496. char sd_table_name[GFS2_FSNAME_LEN];
  497. char sd_proto_name[GFS2_FSNAME_LEN];
  498. /* Debugging crud */
  499. unsigned long sd_last_warning;
  500. struct vfsmount *sd_gfs2mnt;
  501. };
  502. #endif /* __INCORE_DOT_H__ */