glops.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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, GFS2_LOG_HEAD_FLUSH_NORMAL |
  97. GFS2_LFC_AIL_EMPTY_GL);
  98. }
  99. void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
  100. {
  101. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  102. unsigned int revokes = atomic_read(&gl->gl_ail_count);
  103. unsigned int max_revokes = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / sizeof(u64);
  104. int ret;
  105. if (!revokes)
  106. return;
  107. while (revokes > max_revokes)
  108. max_revokes += (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / sizeof(u64);
  109. ret = gfs2_trans_begin(sdp, 0, max_revokes);
  110. if (ret)
  111. return;
  112. __gfs2_ail_flush(gl, fsync, max_revokes);
  113. gfs2_trans_end(sdp);
  114. gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL |
  115. GFS2_LFC_AIL_FLUSH);
  116. }
  117. /**
  118. * rgrp_go_sync - sync out the metadata for this glock
  119. * @gl: the glock
  120. *
  121. * Called when demoting or unlocking an EX glock. We must flush
  122. * to disk all dirty buffers/pages relating to this glock, and must not
  123. * return to caller to demote/unlock the glock until I/O is complete.
  124. */
  125. static void rgrp_go_sync(struct gfs2_glock *gl)
  126. {
  127. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  128. struct address_space *mapping = &sdp->sd_aspace;
  129. struct gfs2_rgrpd *rgd;
  130. int error;
  131. spin_lock(&gl->gl_lockref.lock);
  132. rgd = gl->gl_object;
  133. if (rgd)
  134. gfs2_rgrp_brelse(rgd);
  135. spin_unlock(&gl->gl_lockref.lock);
  136. if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
  137. return;
  138. GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
  139. gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL |
  140. GFS2_LFC_RGRP_GO_SYNC);
  141. filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  142. error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  143. mapping_set_error(mapping, error);
  144. gfs2_ail_empty_gl(gl);
  145. spin_lock(&gl->gl_lockref.lock);
  146. rgd = gl->gl_object;
  147. if (rgd)
  148. gfs2_free_clones(rgd);
  149. spin_unlock(&gl->gl_lockref.lock);
  150. }
  151. /**
  152. * rgrp_go_inval - invalidate the metadata for this glock
  153. * @gl: the glock
  154. * @flags:
  155. *
  156. * We never used LM_ST_DEFERRED with resource groups, so that we
  157. * should always see the metadata flag set here.
  158. *
  159. */
  160. static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
  161. {
  162. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  163. struct address_space *mapping = &sdp->sd_aspace;
  164. struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
  165. if (rgd)
  166. gfs2_rgrp_brelse(rgd);
  167. WARN_ON_ONCE(!(flags & DIO_METADATA));
  168. gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
  169. truncate_inode_pages_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  170. if (rgd)
  171. rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
  172. }
  173. static struct gfs2_inode *gfs2_glock2inode(struct gfs2_glock *gl)
  174. {
  175. struct gfs2_inode *ip;
  176. spin_lock(&gl->gl_lockref.lock);
  177. ip = gl->gl_object;
  178. if (ip)
  179. set_bit(GIF_GLOP_PENDING, &ip->i_flags);
  180. spin_unlock(&gl->gl_lockref.lock);
  181. return ip;
  182. }
  183. struct gfs2_rgrpd *gfs2_glock2rgrp(struct gfs2_glock *gl)
  184. {
  185. struct gfs2_rgrpd *rgd;
  186. spin_lock(&gl->gl_lockref.lock);
  187. rgd = gl->gl_object;
  188. spin_unlock(&gl->gl_lockref.lock);
  189. return rgd;
  190. }
  191. static void gfs2_clear_glop_pending(struct gfs2_inode *ip)
  192. {
  193. if (!ip)
  194. return;
  195. clear_bit_unlock(GIF_GLOP_PENDING, &ip->i_flags);
  196. wake_up_bit(&ip->i_flags, GIF_GLOP_PENDING);
  197. }
  198. /**
  199. * inode_go_sync - Sync the dirty data and/or metadata for an inode glock
  200. * @gl: the glock protecting the inode
  201. *
  202. */
  203. static void inode_go_sync(struct gfs2_glock *gl)
  204. {
  205. struct gfs2_inode *ip = gfs2_glock2inode(gl);
  206. int isreg = ip && S_ISREG(ip->i_inode.i_mode);
  207. struct address_space *metamapping = gfs2_glock2aspace(gl);
  208. int error;
  209. if (isreg) {
  210. if (test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
  211. unmap_shared_mapping_range(ip->i_inode.i_mapping, 0, 0);
  212. inode_dio_wait(&ip->i_inode);
  213. }
  214. if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
  215. goto out;
  216. GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
  217. gfs2_log_flush(gl->gl_name.ln_sbd, gl, GFS2_LOG_HEAD_FLUSH_NORMAL |
  218. GFS2_LFC_INODE_GO_SYNC);
  219. filemap_fdatawrite(metamapping);
  220. if (isreg) {
  221. struct address_space *mapping = ip->i_inode.i_mapping;
  222. filemap_fdatawrite(mapping);
  223. error = filemap_fdatawait(mapping);
  224. mapping_set_error(mapping, error);
  225. }
  226. error = filemap_fdatawait(metamapping);
  227. mapping_set_error(metamapping, error);
  228. gfs2_ail_empty_gl(gl);
  229. /*
  230. * Writeback of the data mapping may cause the dirty flag to be set
  231. * so we have to clear it again here.
  232. */
  233. smp_mb__before_atomic();
  234. clear_bit(GLF_DIRTY, &gl->gl_flags);
  235. out:
  236. gfs2_clear_glop_pending(ip);
  237. }
  238. /**
  239. * inode_go_inval - prepare a inode glock to be released
  240. * @gl: the glock
  241. * @flags:
  242. *
  243. * Normally we invalidate everything, but if we are moving into
  244. * LM_ST_DEFERRED from LM_ST_SHARED or LM_ST_EXCLUSIVE then we
  245. * can keep hold of the metadata, since it won't have changed.
  246. *
  247. */
  248. static void inode_go_inval(struct gfs2_glock *gl, int flags)
  249. {
  250. struct gfs2_inode *ip = gfs2_glock2inode(gl);
  251. gfs2_assert_withdraw(gl->gl_name.ln_sbd, !atomic_read(&gl->gl_ail_count));
  252. if (flags & DIO_METADATA) {
  253. struct address_space *mapping = gfs2_glock2aspace(gl);
  254. truncate_inode_pages(mapping, 0);
  255. if (ip) {
  256. set_bit(GIF_INVALID, &ip->i_flags);
  257. forget_all_cached_acls(&ip->i_inode);
  258. security_inode_invalidate_secctx(&ip->i_inode);
  259. gfs2_dir_hash_inval(ip);
  260. }
  261. }
  262. if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
  263. gfs2_log_flush(gl->gl_name.ln_sbd, NULL,
  264. GFS2_LOG_HEAD_FLUSH_NORMAL |
  265. GFS2_LFC_INODE_GO_INVAL);
  266. gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
  267. }
  268. if (ip && S_ISREG(ip->i_inode.i_mode))
  269. truncate_inode_pages(ip->i_inode.i_mapping, 0);
  270. gfs2_clear_glop_pending(ip);
  271. }
  272. /**
  273. * inode_go_demote_ok - Check to see if it's ok to unlock an inode glock
  274. * @gl: the glock
  275. *
  276. * Returns: 1 if it's ok
  277. */
  278. static int inode_go_demote_ok(const struct gfs2_glock *gl)
  279. {
  280. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  281. if (sdp->sd_jindex == gl->gl_object || sdp->sd_rindex == gl->gl_object)
  282. return 0;
  283. return 1;
  284. }
  285. static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
  286. {
  287. const struct gfs2_dinode *str = buf;
  288. struct timespec64 atime;
  289. u16 height, depth;
  290. if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
  291. goto corrupt;
  292. ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino);
  293. ip->i_inode.i_mode = be32_to_cpu(str->di_mode);
  294. ip->i_inode.i_rdev = 0;
  295. switch (ip->i_inode.i_mode & S_IFMT) {
  296. case S_IFBLK:
  297. case S_IFCHR:
  298. ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major),
  299. be32_to_cpu(str->di_minor));
  300. break;
  301. };
  302. i_uid_write(&ip->i_inode, be32_to_cpu(str->di_uid));
  303. i_gid_write(&ip->i_inode, be32_to_cpu(str->di_gid));
  304. set_nlink(&ip->i_inode, be32_to_cpu(str->di_nlink));
  305. i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
  306. gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
  307. atime.tv_sec = be64_to_cpu(str->di_atime);
  308. atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
  309. if (timespec64_compare(&ip->i_inode.i_atime, &atime) < 0)
  310. ip->i_inode.i_atime = atime;
  311. ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
  312. ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec);
  313. ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime);
  314. ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec);
  315. ip->i_goal = be64_to_cpu(str->di_goal_meta);
  316. ip->i_generation = be64_to_cpu(str->di_generation);
  317. ip->i_diskflags = be32_to_cpu(str->di_flags);
  318. ip->i_eattr = be64_to_cpu(str->di_eattr);
  319. /* i_diskflags and i_eattr must be set before gfs2_set_inode_flags() */
  320. gfs2_set_inode_flags(&ip->i_inode);
  321. height = be16_to_cpu(str->di_height);
  322. if (unlikely(height > GFS2_MAX_META_HEIGHT))
  323. goto corrupt;
  324. ip->i_height = (u8)height;
  325. depth = be16_to_cpu(str->di_depth);
  326. if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
  327. goto corrupt;
  328. ip->i_depth = (u8)depth;
  329. ip->i_entries = be32_to_cpu(str->di_entries);
  330. if (S_ISREG(ip->i_inode.i_mode))
  331. gfs2_set_aops(&ip->i_inode);
  332. return 0;
  333. corrupt:
  334. gfs2_consist_inode(ip);
  335. return -EIO;
  336. }
  337. /**
  338. * gfs2_inode_refresh - Refresh the incore copy of the dinode
  339. * @ip: The GFS2 inode
  340. *
  341. * Returns: errno
  342. */
  343. int gfs2_inode_refresh(struct gfs2_inode *ip)
  344. {
  345. struct buffer_head *dibh;
  346. int error;
  347. error = gfs2_meta_inode_buffer(ip, &dibh);
  348. if (error)
  349. return error;
  350. error = gfs2_dinode_in(ip, dibh->b_data);
  351. brelse(dibh);
  352. clear_bit(GIF_INVALID, &ip->i_flags);
  353. return error;
  354. }
  355. /**
  356. * inode_go_lock - operation done after an inode lock is locked by a process
  357. * @gl: the glock
  358. * @flags:
  359. *
  360. * Returns: errno
  361. */
  362. static int inode_go_lock(struct gfs2_holder *gh)
  363. {
  364. struct gfs2_glock *gl = gh->gh_gl;
  365. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  366. struct gfs2_inode *ip = gl->gl_object;
  367. int error = 0;
  368. if (!ip || (gh->gh_flags & GL_SKIP))
  369. return 0;
  370. if (test_bit(GIF_INVALID, &ip->i_flags)) {
  371. error = gfs2_inode_refresh(ip);
  372. if (error)
  373. return error;
  374. }
  375. if (gh->gh_state != LM_ST_DEFERRED)
  376. inode_dio_wait(&ip->i_inode);
  377. if ((ip->i_diskflags & GFS2_DIF_TRUNC_IN_PROG) &&
  378. (gl->gl_state == LM_ST_EXCLUSIVE) &&
  379. (gh->gh_state == LM_ST_EXCLUSIVE)) {
  380. spin_lock(&sdp->sd_trunc_lock);
  381. if (list_empty(&ip->i_trunc_list))
  382. list_add(&ip->i_trunc_list, &sdp->sd_trunc_list);
  383. spin_unlock(&sdp->sd_trunc_lock);
  384. wake_up(&sdp->sd_quota_wait);
  385. return 1;
  386. }
  387. return error;
  388. }
  389. /**
  390. * inode_go_dump - print information about an inode
  391. * @seq: The iterator
  392. * @ip: the inode
  393. *
  394. */
  395. static void inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
  396. {
  397. const struct gfs2_inode *ip = gl->gl_object;
  398. if (ip == NULL)
  399. return;
  400. gfs2_print_dbg(seq, " I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu\n",
  401. (unsigned long long)ip->i_no_formal_ino,
  402. (unsigned long long)ip->i_no_addr,
  403. IF2DT(ip->i_inode.i_mode), ip->i_flags,
  404. (unsigned int)ip->i_diskflags,
  405. (unsigned long long)i_size_read(&ip->i_inode));
  406. }
  407. /**
  408. * freeze_go_sync - promote/demote the freeze glock
  409. * @gl: the glock
  410. * @state: the requested state
  411. * @flags:
  412. *
  413. */
  414. static void freeze_go_sync(struct gfs2_glock *gl)
  415. {
  416. int error = 0;
  417. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  418. if (gl->gl_state == LM_ST_SHARED &&
  419. test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
  420. atomic_set(&sdp->sd_freeze_state, SFS_STARTING_FREEZE);
  421. error = freeze_super(sdp->sd_vfs);
  422. if (error) {
  423. printk(KERN_INFO "GFS2: couldn't freeze filesystem: %d\n", error);
  424. gfs2_assert_withdraw(sdp, 0);
  425. }
  426. queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
  427. gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE |
  428. GFS2_LFC_FREEZE_GO_SYNC);
  429. }
  430. }
  431. /**
  432. * freeze_go_xmote_bh - After promoting/demoting the freeze glock
  433. * @gl: the glock
  434. *
  435. */
  436. static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh)
  437. {
  438. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  439. struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
  440. struct gfs2_glock *j_gl = ip->i_gl;
  441. struct gfs2_log_header_host head;
  442. int error;
  443. if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
  444. j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
  445. error = gfs2_find_jhead(sdp->sd_jdesc, &head);
  446. if (error)
  447. gfs2_consist(sdp);
  448. if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT))
  449. gfs2_consist(sdp);
  450. /* Initialize some head of the log stuff */
  451. if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) {
  452. sdp->sd_log_sequence = head.lh_sequence + 1;
  453. gfs2_log_pointers_init(sdp, head.lh_blkno);
  454. }
  455. }
  456. return 0;
  457. }
  458. /**
  459. * trans_go_demote_ok
  460. * @gl: the glock
  461. *
  462. * Always returns 0
  463. */
  464. static int freeze_go_demote_ok(const struct gfs2_glock *gl)
  465. {
  466. return 0;
  467. }
  468. /**
  469. * iopen_go_callback - schedule the dcache entry for the inode to be deleted
  470. * @gl: the glock
  471. *
  472. * gl_lockref.lock lock is held while calling this
  473. */
  474. static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
  475. {
  476. struct gfs2_inode *ip = gl->gl_object;
  477. struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
  478. if (!remote || sb_rdonly(sdp->sd_vfs))
  479. return;
  480. if (gl->gl_demote_state == LM_ST_UNLOCKED &&
  481. gl->gl_state == LM_ST_SHARED && ip) {
  482. gl->gl_lockref.count++;
  483. if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
  484. gl->gl_lockref.count--;
  485. }
  486. }
  487. const struct gfs2_glock_operations gfs2_meta_glops = {
  488. .go_type = LM_TYPE_META,
  489. };
  490. const struct gfs2_glock_operations gfs2_inode_glops = {
  491. .go_sync = inode_go_sync,
  492. .go_inval = inode_go_inval,
  493. .go_demote_ok = inode_go_demote_ok,
  494. .go_lock = inode_go_lock,
  495. .go_dump = inode_go_dump,
  496. .go_type = LM_TYPE_INODE,
  497. .go_flags = GLOF_ASPACE | GLOF_LRU,
  498. };
  499. const struct gfs2_glock_operations gfs2_rgrp_glops = {
  500. .go_sync = rgrp_go_sync,
  501. .go_inval = rgrp_go_inval,
  502. .go_lock = gfs2_rgrp_go_lock,
  503. .go_unlock = gfs2_rgrp_go_unlock,
  504. .go_dump = gfs2_rgrp_dump,
  505. .go_type = LM_TYPE_RGRP,
  506. .go_flags = GLOF_LVB,
  507. };
  508. const struct gfs2_glock_operations gfs2_freeze_glops = {
  509. .go_sync = freeze_go_sync,
  510. .go_xmote_bh = freeze_go_xmote_bh,
  511. .go_demote_ok = freeze_go_demote_ok,
  512. .go_type = LM_TYPE_NONDISK,
  513. };
  514. const struct gfs2_glock_operations gfs2_iopen_glops = {
  515. .go_type = LM_TYPE_IOPEN,
  516. .go_callback = iopen_go_callback,
  517. .go_flags = GLOF_LRU,
  518. };
  519. const struct gfs2_glock_operations gfs2_flock_glops = {
  520. .go_type = LM_TYPE_FLOCK,
  521. .go_flags = GLOF_LRU,
  522. };
  523. const struct gfs2_glock_operations gfs2_nondisk_glops = {
  524. .go_type = LM_TYPE_NONDISK,
  525. };
  526. const struct gfs2_glock_operations gfs2_quota_glops = {
  527. .go_type = LM_TYPE_QUOTA,
  528. .go_flags = GLOF_LVB | GLOF_LRU,
  529. };
  530. const struct gfs2_glock_operations gfs2_journal_glops = {
  531. .go_type = LM_TYPE_JOURNAL,
  532. };
  533. const struct gfs2_glock_operations *gfs2_glops_list[] = {
  534. [LM_TYPE_META] = &gfs2_meta_glops,
  535. [LM_TYPE_INODE] = &gfs2_inode_glops,
  536. [LM_TYPE_RGRP] = &gfs2_rgrp_glops,
  537. [LM_TYPE_IOPEN] = &gfs2_iopen_glops,
  538. [LM_TYPE_FLOCK] = &gfs2_flock_glops,
  539. [LM_TYPE_NONDISK] = &gfs2_nondisk_glops,
  540. [LM_TYPE_QUOTA] = &gfs2_quota_glops,
  541. [LM_TYPE_JOURNAL] = &gfs2_journal_glops,
  542. };