glops.c 16 KB

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