glops.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. #include <linux/spinlock.h>
  10. #include <linux/completion.h>
  11. #include <linux/buffer_head.h>
  12. #include <linux/gfs2_ondisk.h>
  13. #include <linux/bio.h>
  14. #include <linux/posix_acl.h>
  15. #include <linux/security.h>
  16. #include "gfs2.h"
  17. #include "incore.h"
  18. #include "bmap.h"
  19. #include "glock.h"
  20. #include "glops.h"
  21. #include "inode.h"
  22. #include "log.h"
  23. #include "meta_io.h"
  24. #include "recovery.h"
  25. #include "rgrp.h"
  26. #include "util.h"
  27. #include "trans.h"
  28. #include "dir.h"
  29. struct workqueue_struct *gfs2_freeze_wq;
  30. static void gfs2_ail_error(struct gfs2_glock *gl, const struct buffer_head *bh)
  31. {
  32. fs_err(gl->gl_name.ln_sbd,
  33. "AIL buffer %p: blocknr %llu state 0x%08lx mapping %p page "
  34. "state 0x%lx\n",
  35. bh, (unsigned long long)bh->b_blocknr, bh->b_state,
  36. bh->b_page->mapping, bh->b_page->flags);
  37. fs_err(gl->gl_name.ln_sbd, "AIL glock %u:%llu mapping %p\n",
  38. gl->gl_name.ln_type, gl->gl_name.ln_number,
  39. gfs2_glock2aspace(gl));
  40. gfs2_lm_withdraw(gl->gl_name.ln_sbd, "AIL error\n");
  41. }
  42. /**
  43. * __gfs2_ail_flush - remove all buffers for a given lock from the AIL
  44. * @gl: the glock
  45. * @fsync: set when called from fsync (not all buffers will be clean)
  46. *
  47. * None of the buffers should be dirty, locked, or pinned.
  48. */
  49. static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync,
  50. unsigned int nr_revokes)
  51. {
  52. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  53. struct list_head *head = &gl->gl_ail_list;
  54. struct gfs2_bufdata *bd, *tmp;
  55. struct buffer_head *bh;
  56. const unsigned long b_state = (1UL << BH_Dirty)|(1UL << BH_Pinned)|(1UL << BH_Lock);
  57. gfs2_log_lock(sdp);
  58. spin_lock(&sdp->sd_ail_lock);
  59. list_for_each_entry_safe_reverse(bd, tmp, head, bd_ail_gl_list) {
  60. if (nr_revokes == 0)
  61. break;
  62. bh = bd->bd_bh;
  63. if (bh->b_state & b_state) {
  64. if (fsync)
  65. continue;
  66. gfs2_ail_error(gl, bh);
  67. }
  68. gfs2_trans_add_revoke(sdp, bd);
  69. nr_revokes--;
  70. }
  71. GLOCK_BUG_ON(gl, !fsync && atomic_read(&gl->gl_ail_count));
  72. spin_unlock(&sdp->sd_ail_lock);
  73. gfs2_log_unlock(sdp);
  74. }
  75. static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
  76. {
  77. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  78. struct gfs2_trans tr;
  79. memset(&tr, 0, sizeof(tr));
  80. INIT_LIST_HEAD(&tr.tr_buf);
  81. INIT_LIST_HEAD(&tr.tr_databuf);
  82. tr.tr_revokes = atomic_read(&gl->gl_ail_count);
  83. if (!tr.tr_revokes)
  84. return;
  85. /* A shortened, inline version of gfs2_trans_begin()
  86. * tr->alloced is not set since the transaction structure is
  87. * on the stack */
  88. tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64));
  89. tr.tr_ip = _RET_IP_;
  90. if (gfs2_log_reserve(sdp, tr.tr_reserved) < 0)
  91. return;
  92. WARN_ON_ONCE(current->journal_info);
  93. current->journal_info = &tr;
  94. __gfs2_ail_flush(gl, 0, tr.tr_revokes);
  95. gfs2_trans_end(sdp);
  96. gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
  97. }
  98. void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
  99. {
  100. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  101. unsigned int revokes = atomic_read(&gl->gl_ail_count);
  102. unsigned int max_revokes = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / sizeof(u64);
  103. int ret;
  104. if (!revokes)
  105. return;
  106. while (revokes > max_revokes)
  107. max_revokes += (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / sizeof(u64);
  108. ret = gfs2_trans_begin(sdp, 0, max_revokes);
  109. if (ret)
  110. return;
  111. __gfs2_ail_flush(gl, fsync, max_revokes);
  112. gfs2_trans_end(sdp);
  113. gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
  114. }
  115. /**
  116. * rgrp_go_sync - sync out the metadata for this glock
  117. * @gl: the glock
  118. *
  119. * Called when demoting or unlocking an EX glock. We must flush
  120. * to disk all dirty buffers/pages relating to this glock, and must not
  121. * return to caller to demote/unlock the glock until I/O is complete.
  122. */
  123. static void rgrp_go_sync(struct gfs2_glock *gl)
  124. {
  125. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  126. struct address_space *mapping = &sdp->sd_aspace;
  127. struct gfs2_rgrpd *rgd;
  128. int error;
  129. spin_lock(&gl->gl_lockref.lock);
  130. rgd = gl->gl_object;
  131. if (rgd)
  132. gfs2_rgrp_brelse(rgd);
  133. spin_unlock(&gl->gl_lockref.lock);
  134. if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
  135. return;
  136. GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
  137. gfs2_log_flush(sdp, gl, NORMAL_FLUSH);
  138. filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  139. error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  140. mapping_set_error(mapping, error);
  141. gfs2_ail_empty_gl(gl);
  142. spin_lock(&gl->gl_lockref.lock);
  143. rgd = gl->gl_object;
  144. if (rgd)
  145. gfs2_free_clones(rgd);
  146. spin_unlock(&gl->gl_lockref.lock);
  147. }
  148. /**
  149. * rgrp_go_inval - invalidate the metadata for this glock
  150. * @gl: the glock
  151. * @flags:
  152. *
  153. * We never used LM_ST_DEFERRED with resource groups, so that we
  154. * should always see the metadata flag set here.
  155. *
  156. */
  157. static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
  158. {
  159. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  160. struct address_space *mapping = &sdp->sd_aspace;
  161. struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
  162. if (rgd)
  163. gfs2_rgrp_brelse(rgd);
  164. WARN_ON_ONCE(!(flags & DIO_METADATA));
  165. gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
  166. truncate_inode_pages_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  167. if (rgd)
  168. rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
  169. }
  170. static struct gfs2_inode *gfs2_glock2inode(struct gfs2_glock *gl)
  171. {
  172. struct gfs2_inode *ip;
  173. spin_lock(&gl->gl_lockref.lock);
  174. ip = gl->gl_object;
  175. if (ip)
  176. set_bit(GIF_GLOP_PENDING, &ip->i_flags);
  177. spin_unlock(&gl->gl_lockref.lock);
  178. return ip;
  179. }
  180. struct gfs2_rgrpd *gfs2_glock2rgrp(struct gfs2_glock *gl)
  181. {
  182. struct gfs2_rgrpd *rgd;
  183. spin_lock(&gl->gl_lockref.lock);
  184. rgd = gl->gl_object;
  185. spin_unlock(&gl->gl_lockref.lock);
  186. return rgd;
  187. }
  188. static void gfs2_clear_glop_pending(struct gfs2_inode *ip)
  189. {
  190. if (!ip)
  191. return;
  192. clear_bit_unlock(GIF_GLOP_PENDING, &ip->i_flags);
  193. wake_up_bit(&ip->i_flags, GIF_GLOP_PENDING);
  194. }
  195. /**
  196. * inode_go_sync - Sync the dirty data and/or metadata for an inode glock
  197. * @gl: the glock protecting the inode
  198. *
  199. */
  200. static void inode_go_sync(struct gfs2_glock *gl)
  201. {
  202. struct gfs2_inode *ip = gfs2_glock2inode(gl);
  203. int isreg = ip && S_ISREG(ip->i_inode.i_mode);
  204. struct address_space *metamapping = gfs2_glock2aspace(gl);
  205. int error;
  206. if (isreg) {
  207. if (test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
  208. unmap_shared_mapping_range(ip->i_inode.i_mapping, 0, 0);
  209. inode_dio_wait(&ip->i_inode);
  210. }
  211. if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
  212. goto out;
  213. GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
  214. gfs2_log_flush(gl->gl_name.ln_sbd, gl, NORMAL_FLUSH);
  215. filemap_fdatawrite(metamapping);
  216. if (isreg) {
  217. struct address_space *mapping = ip->i_inode.i_mapping;
  218. filemap_fdatawrite(mapping);
  219. error = filemap_fdatawait(mapping);
  220. mapping_set_error(mapping, error);
  221. }
  222. error = filemap_fdatawait(metamapping);
  223. mapping_set_error(metamapping, error);
  224. gfs2_ail_empty_gl(gl);
  225. /*
  226. * Writeback of the data mapping may cause the dirty flag to be set
  227. * so we have to clear it again here.
  228. */
  229. smp_mb__before_atomic();
  230. clear_bit(GLF_DIRTY, &gl->gl_flags);
  231. out:
  232. gfs2_clear_glop_pending(ip);
  233. }
  234. /**
  235. * inode_go_inval - prepare a inode glock to be released
  236. * @gl: the glock
  237. * @flags:
  238. *
  239. * Normally we invalidate everything, but if we are moving into
  240. * LM_ST_DEFERRED from LM_ST_SHARED or LM_ST_EXCLUSIVE then we
  241. * can keep hold of the metadata, since it won't have changed.
  242. *
  243. */
  244. static void inode_go_inval(struct gfs2_glock *gl, int flags)
  245. {
  246. struct gfs2_inode *ip = gfs2_glock2inode(gl);
  247. gfs2_assert_withdraw(gl->gl_name.ln_sbd, !atomic_read(&gl->gl_ail_count));
  248. if (flags & DIO_METADATA) {
  249. struct address_space *mapping = gfs2_glock2aspace(gl);
  250. truncate_inode_pages(mapping, 0);
  251. if (ip) {
  252. set_bit(GIF_INVALID, &ip->i_flags);
  253. forget_all_cached_acls(&ip->i_inode);
  254. security_inode_invalidate_secctx(&ip->i_inode);
  255. gfs2_dir_hash_inval(ip);
  256. }
  257. }
  258. if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
  259. gfs2_log_flush(gl->gl_name.ln_sbd, NULL, NORMAL_FLUSH);
  260. gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
  261. }
  262. if (ip && S_ISREG(ip->i_inode.i_mode))
  263. truncate_inode_pages(ip->i_inode.i_mapping, 0);
  264. gfs2_clear_glop_pending(ip);
  265. }
  266. /**
  267. * inode_go_demote_ok - Check to see if it's ok to unlock an inode glock
  268. * @gl: the glock
  269. *
  270. * Returns: 1 if it's ok
  271. */
  272. static int inode_go_demote_ok(const struct gfs2_glock *gl)
  273. {
  274. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  275. if (sdp->sd_jindex == gl->gl_object || sdp->sd_rindex == gl->gl_object)
  276. return 0;
  277. return 1;
  278. }
  279. /**
  280. * gfs2_set_nlink - Set the inode's link count based on on-disk info
  281. * @inode: The inode in question
  282. * @nlink: The link count
  283. *
  284. * If the link count has hit zero, it must never be raised, whatever the
  285. * on-disk inode might say. When new struct inodes are created the link
  286. * count is set to 1, so that we can safely use this test even when reading
  287. * in on disk information for the first time.
  288. */
  289. static void gfs2_set_nlink(struct inode *inode, u32 nlink)
  290. {
  291. /*
  292. * We will need to review setting the nlink count here in the
  293. * light of the forthcoming ro bind mount work. This is a reminder
  294. * to do that.
  295. */
  296. if ((inode->i_nlink != nlink) && (inode->i_nlink != 0)) {
  297. if (nlink == 0)
  298. clear_nlink(inode);
  299. else
  300. set_nlink(inode, nlink);
  301. }
  302. }
  303. static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
  304. {
  305. const struct gfs2_dinode *str = buf;
  306. struct timespec atime;
  307. u16 height, depth;
  308. if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
  309. goto corrupt;
  310. ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino);
  311. ip->i_inode.i_mode = be32_to_cpu(str->di_mode);
  312. ip->i_inode.i_rdev = 0;
  313. switch (ip->i_inode.i_mode & S_IFMT) {
  314. case S_IFBLK:
  315. case S_IFCHR:
  316. ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major),
  317. be32_to_cpu(str->di_minor));
  318. break;
  319. };
  320. i_uid_write(&ip->i_inode, be32_to_cpu(str->di_uid));
  321. i_gid_write(&ip->i_inode, be32_to_cpu(str->di_gid));
  322. gfs2_set_nlink(&ip->i_inode, be32_to_cpu(str->di_nlink));
  323. i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
  324. gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
  325. atime.tv_sec = be64_to_cpu(str->di_atime);
  326. atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
  327. if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0)
  328. ip->i_inode.i_atime = atime;
  329. ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
  330. ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec);
  331. ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime);
  332. ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec);
  333. ip->i_goal = be64_to_cpu(str->di_goal_meta);
  334. ip->i_generation = be64_to_cpu(str->di_generation);
  335. ip->i_diskflags = be32_to_cpu(str->di_flags);
  336. ip->i_eattr = be64_to_cpu(str->di_eattr);
  337. /* i_diskflags and i_eattr must be set before gfs2_set_inode_flags() */
  338. gfs2_set_inode_flags(&ip->i_inode);
  339. height = be16_to_cpu(str->di_height);
  340. if (unlikely(height > GFS2_MAX_META_HEIGHT))
  341. goto corrupt;
  342. ip->i_height = (u8)height;
  343. depth = be16_to_cpu(str->di_depth);
  344. if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
  345. goto corrupt;
  346. ip->i_depth = (u8)depth;
  347. ip->i_entries = be32_to_cpu(str->di_entries);
  348. if (S_ISREG(ip->i_inode.i_mode))
  349. gfs2_set_aops(&ip->i_inode);
  350. return 0;
  351. corrupt:
  352. gfs2_consist_inode(ip);
  353. return -EIO;
  354. }
  355. /**
  356. * gfs2_inode_refresh - Refresh the incore copy of the dinode
  357. * @ip: The GFS2 inode
  358. *
  359. * Returns: errno
  360. */
  361. int gfs2_inode_refresh(struct gfs2_inode *ip)
  362. {
  363. struct buffer_head *dibh;
  364. int error;
  365. error = gfs2_meta_inode_buffer(ip, &dibh);
  366. if (error)
  367. return error;
  368. error = gfs2_dinode_in(ip, dibh->b_data);
  369. brelse(dibh);
  370. clear_bit(GIF_INVALID, &ip->i_flags);
  371. return error;
  372. }
  373. /**
  374. * inode_go_lock - operation done after an inode lock is locked by a process
  375. * @gl: the glock
  376. * @flags:
  377. *
  378. * Returns: errno
  379. */
  380. static int inode_go_lock(struct gfs2_holder *gh)
  381. {
  382. struct gfs2_glock *gl = gh->gh_gl;
  383. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  384. struct gfs2_inode *ip = gl->gl_object;
  385. int error = 0;
  386. if (!ip || (gh->gh_flags & GL_SKIP))
  387. return 0;
  388. if (test_bit(GIF_INVALID, &ip->i_flags)) {
  389. error = gfs2_inode_refresh(ip);
  390. if (error)
  391. return error;
  392. }
  393. if (gh->gh_state != LM_ST_DEFERRED)
  394. inode_dio_wait(&ip->i_inode);
  395. if ((ip->i_diskflags & GFS2_DIF_TRUNC_IN_PROG) &&
  396. (gl->gl_state == LM_ST_EXCLUSIVE) &&
  397. (gh->gh_state == LM_ST_EXCLUSIVE)) {
  398. spin_lock(&sdp->sd_trunc_lock);
  399. if (list_empty(&ip->i_trunc_list))
  400. list_add(&sdp->sd_trunc_list, &ip->i_trunc_list);
  401. spin_unlock(&sdp->sd_trunc_lock);
  402. wake_up(&sdp->sd_quota_wait);
  403. return 1;
  404. }
  405. return error;
  406. }
  407. /**
  408. * inode_go_dump - print information about an inode
  409. * @seq: The iterator
  410. * @ip: the inode
  411. *
  412. */
  413. static void inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
  414. {
  415. const struct gfs2_inode *ip = gl->gl_object;
  416. if (ip == NULL)
  417. return;
  418. gfs2_print_dbg(seq, " I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu\n",
  419. (unsigned long long)ip->i_no_formal_ino,
  420. (unsigned long long)ip->i_no_addr,
  421. IF2DT(ip->i_inode.i_mode), ip->i_flags,
  422. (unsigned int)ip->i_diskflags,
  423. (unsigned long long)i_size_read(&ip->i_inode));
  424. }
  425. /**
  426. * freeze_go_sync - promote/demote the freeze glock
  427. * @gl: the glock
  428. * @state: the requested state
  429. * @flags:
  430. *
  431. */
  432. static void freeze_go_sync(struct gfs2_glock *gl)
  433. {
  434. int error = 0;
  435. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  436. if (gl->gl_state == LM_ST_SHARED &&
  437. test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
  438. atomic_set(&sdp->sd_freeze_state, SFS_STARTING_FREEZE);
  439. error = freeze_super(sdp->sd_vfs);
  440. if (error) {
  441. printk(KERN_INFO "GFS2: couldn't freeze filesystem: %d\n", error);
  442. gfs2_assert_withdraw(sdp, 0);
  443. }
  444. queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
  445. gfs2_log_flush(sdp, NULL, FREEZE_FLUSH);
  446. }
  447. }
  448. /**
  449. * freeze_go_xmote_bh - After promoting/demoting the freeze glock
  450. * @gl: the glock
  451. *
  452. */
  453. static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh)
  454. {
  455. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  456. struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
  457. struct gfs2_glock *j_gl = ip->i_gl;
  458. struct gfs2_log_header_host head;
  459. int error;
  460. if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
  461. j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
  462. error = gfs2_find_jhead(sdp->sd_jdesc, &head);
  463. if (error)
  464. gfs2_consist(sdp);
  465. if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT))
  466. gfs2_consist(sdp);
  467. /* Initialize some head of the log stuff */
  468. if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) {
  469. sdp->sd_log_sequence = head.lh_sequence + 1;
  470. gfs2_log_pointers_init(sdp, head.lh_blkno);
  471. }
  472. }
  473. return 0;
  474. }
  475. /**
  476. * trans_go_demote_ok
  477. * @gl: the glock
  478. *
  479. * Always returns 0
  480. */
  481. static int freeze_go_demote_ok(const struct gfs2_glock *gl)
  482. {
  483. return 0;
  484. }
  485. /**
  486. * iopen_go_callback - schedule the dcache entry for the inode to be deleted
  487. * @gl: the glock
  488. *
  489. * gl_lockref.lock lock is held while calling this
  490. */
  491. static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
  492. {
  493. struct gfs2_inode *ip = gl->gl_object;
  494. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  495. if (!remote || sb_rdonly(sdp->sd_vfs))
  496. return;
  497. if (gl->gl_demote_state == LM_ST_UNLOCKED &&
  498. gl->gl_state == LM_ST_SHARED && ip) {
  499. gl->gl_lockref.count++;
  500. if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
  501. gl->gl_lockref.count--;
  502. }
  503. }
  504. const struct gfs2_glock_operations gfs2_meta_glops = {
  505. .go_type = LM_TYPE_META,
  506. };
  507. const struct gfs2_glock_operations gfs2_inode_glops = {
  508. .go_sync = inode_go_sync,
  509. .go_inval = inode_go_inval,
  510. .go_demote_ok = inode_go_demote_ok,
  511. .go_lock = inode_go_lock,
  512. .go_dump = inode_go_dump,
  513. .go_type = LM_TYPE_INODE,
  514. .go_flags = GLOF_ASPACE | GLOF_LRU,
  515. };
  516. const struct gfs2_glock_operations gfs2_rgrp_glops = {
  517. .go_sync = rgrp_go_sync,
  518. .go_inval = rgrp_go_inval,
  519. .go_lock = gfs2_rgrp_go_lock,
  520. .go_unlock = gfs2_rgrp_go_unlock,
  521. .go_dump = gfs2_rgrp_dump,
  522. .go_type = LM_TYPE_RGRP,
  523. .go_flags = GLOF_LVB,
  524. };
  525. const struct gfs2_glock_operations gfs2_freeze_glops = {
  526. .go_sync = freeze_go_sync,
  527. .go_xmote_bh = freeze_go_xmote_bh,
  528. .go_demote_ok = freeze_go_demote_ok,
  529. .go_type = LM_TYPE_NONDISK,
  530. };
  531. const struct gfs2_glock_operations gfs2_iopen_glops = {
  532. .go_type = LM_TYPE_IOPEN,
  533. .go_callback = iopen_go_callback,
  534. .go_flags = GLOF_LRU,
  535. };
  536. const struct gfs2_glock_operations gfs2_flock_glops = {
  537. .go_type = LM_TYPE_FLOCK,
  538. .go_flags = GLOF_LRU,
  539. };
  540. const struct gfs2_glock_operations gfs2_nondisk_glops = {
  541. .go_type = LM_TYPE_NONDISK,
  542. };
  543. const struct gfs2_glock_operations gfs2_quota_glops = {
  544. .go_type = LM_TYPE_QUOTA,
  545. .go_flags = GLOF_LVB | GLOF_LRU,
  546. };
  547. const struct gfs2_glock_operations gfs2_journal_glops = {
  548. .go_type = LM_TYPE_JOURNAL,
  549. };
  550. const struct gfs2_glock_operations *gfs2_glops_list[] = {
  551. [LM_TYPE_META] = &gfs2_meta_glops,
  552. [LM_TYPE_INODE] = &gfs2_inode_glops,
  553. [LM_TYPE_RGRP] = &gfs2_rgrp_glops,
  554. [LM_TYPE_IOPEN] = &gfs2_iopen_glops,
  555. [LM_TYPE_FLOCK] = &gfs2_flock_glops,
  556. [LM_TYPE_NONDISK] = &gfs2_nondisk_glops,
  557. [LM_TYPE_QUOTA] = &gfs2_quota_glops,
  558. [LM_TYPE_JOURNAL] = &gfs2_journal_glops,
  559. };