ops_super.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/statfs.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/mount.h>
  17. #include <linux/kthread.h>
  18. #include <linux/delay.h>
  19. #include <linux/gfs2_ondisk.h>
  20. #include <linux/crc32.h>
  21. #include <linux/time.h>
  22. #include "gfs2.h"
  23. #include "incore.h"
  24. #include "glock.h"
  25. #include "inode.h"
  26. #include "log.h"
  27. #include "quota.h"
  28. #include "recovery.h"
  29. #include "rgrp.h"
  30. #include "super.h"
  31. #include "sys.h"
  32. #include "util.h"
  33. #include "trans.h"
  34. #include "dir.h"
  35. #include "eattr.h"
  36. #include "bmap.h"
  37. #include "meta_io.h"
  38. #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
  39. /**
  40. * gfs2_write_inode - Make sure the inode is stable on the disk
  41. * @inode: The inode
  42. * @sync: synchronous write flag
  43. *
  44. * Returns: errno
  45. */
  46. static int gfs2_write_inode(struct inode *inode, int sync)
  47. {
  48. struct gfs2_inode *ip = GFS2_I(inode);
  49. struct gfs2_sbd *sdp = GFS2_SB(inode);
  50. struct gfs2_holder gh;
  51. struct buffer_head *bh;
  52. struct timespec atime;
  53. struct gfs2_dinode *di;
  54. int ret = 0;
  55. /* Check this is a "normal" inode, etc */
  56. if (!test_bit(GIF_USER, &ip->i_flags) ||
  57. (current->flags & PF_MEMALLOC))
  58. return 0;
  59. ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  60. if (ret)
  61. goto do_flush;
  62. ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
  63. if (ret)
  64. goto do_unlock;
  65. ret = gfs2_meta_inode_buffer(ip, &bh);
  66. if (ret == 0) {
  67. di = (struct gfs2_dinode *)bh->b_data;
  68. atime.tv_sec = be64_to_cpu(di->di_atime);
  69. atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
  70. if (timespec_compare(&inode->i_atime, &atime) > 0) {
  71. gfs2_trans_add_bh(ip->i_gl, bh, 1);
  72. gfs2_dinode_out(ip, bh->b_data);
  73. }
  74. brelse(bh);
  75. }
  76. gfs2_trans_end(sdp);
  77. do_unlock:
  78. gfs2_glock_dq_uninit(&gh);
  79. do_flush:
  80. if (sync != 0)
  81. gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
  82. return ret;
  83. }
  84. /**
  85. * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
  86. * @sdp: the filesystem
  87. *
  88. * Returns: errno
  89. */
  90. static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
  91. {
  92. struct gfs2_holder t_gh;
  93. int error;
  94. gfs2_quota_sync(sdp);
  95. gfs2_statfs_sync(sdp);
  96. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
  97. &t_gh);
  98. if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  99. return error;
  100. gfs2_meta_syncfs(sdp);
  101. gfs2_log_shutdown(sdp);
  102. clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
  103. if (t_gh.gh_gl)
  104. gfs2_glock_dq_uninit(&t_gh);
  105. gfs2_quota_cleanup(sdp);
  106. return error;
  107. }
  108. /**
  109. * gfs2_put_super - Unmount the filesystem
  110. * @sb: The VFS superblock
  111. *
  112. */
  113. static void gfs2_put_super(struct super_block *sb)
  114. {
  115. struct gfs2_sbd *sdp = sb->s_fs_info;
  116. int error;
  117. /* Unfreeze the filesystem, if we need to */
  118. mutex_lock(&sdp->sd_freeze_lock);
  119. if (sdp->sd_freeze_count)
  120. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  121. mutex_unlock(&sdp->sd_freeze_lock);
  122. kthread_stop(sdp->sd_quotad_process);
  123. kthread_stop(sdp->sd_logd_process);
  124. kthread_stop(sdp->sd_recoverd_process);
  125. if (!(sb->s_flags & MS_RDONLY)) {
  126. error = gfs2_make_fs_ro(sdp);
  127. if (error)
  128. gfs2_io_error(sdp);
  129. }
  130. /* At this point, we're through modifying the disk */
  131. /* Release stuff */
  132. iput(sdp->sd_jindex);
  133. iput(sdp->sd_inum_inode);
  134. iput(sdp->sd_statfs_inode);
  135. iput(sdp->sd_rindex);
  136. iput(sdp->sd_quota_inode);
  137. gfs2_glock_put(sdp->sd_rename_gl);
  138. gfs2_glock_put(sdp->sd_trans_gl);
  139. if (!sdp->sd_args.ar_spectator) {
  140. gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
  141. gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
  142. gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
  143. gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
  144. gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
  145. iput(sdp->sd_ir_inode);
  146. iput(sdp->sd_sc_inode);
  147. iput(sdp->sd_qc_inode);
  148. }
  149. gfs2_glock_dq_uninit(&sdp->sd_live_gh);
  150. gfs2_clear_rgrpd(sdp);
  151. gfs2_jindex_free(sdp);
  152. /* Take apart glock structures and buffer lists */
  153. gfs2_gl_hash_clear(sdp);
  154. /* Unmount the locking protocol */
  155. gfs2_lm_unmount(sdp);
  156. /* At this point, we're through participating in the lockspace */
  157. gfs2_sys_fs_del(sdp);
  158. }
  159. /**
  160. * gfs2_write_super
  161. * @sb: the superblock
  162. *
  163. */
  164. static void gfs2_write_super(struct super_block *sb)
  165. {
  166. sb->s_dirt = 0;
  167. }
  168. /**
  169. * gfs2_sync_fs - sync the filesystem
  170. * @sb: the superblock
  171. *
  172. * Flushes the log to disk.
  173. */
  174. static int gfs2_sync_fs(struct super_block *sb, int wait)
  175. {
  176. sb->s_dirt = 0;
  177. if (wait && sb->s_fs_info)
  178. gfs2_log_flush(sb->s_fs_info, NULL);
  179. return 0;
  180. }
  181. /**
  182. * gfs2_freeze - prevent further writes to the filesystem
  183. * @sb: the VFS structure for the filesystem
  184. *
  185. */
  186. static int gfs2_freeze(struct super_block *sb)
  187. {
  188. struct gfs2_sbd *sdp = sb->s_fs_info;
  189. int error;
  190. if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  191. return -EINVAL;
  192. for (;;) {
  193. error = gfs2_freeze_fs(sdp);
  194. if (!error)
  195. break;
  196. switch (error) {
  197. case -EBUSY:
  198. fs_err(sdp, "waiting for recovery before freeze\n");
  199. break;
  200. default:
  201. fs_err(sdp, "error freezing FS: %d\n", error);
  202. break;
  203. }
  204. fs_err(sdp, "retrying...\n");
  205. msleep(1000);
  206. }
  207. return 0;
  208. }
  209. /**
  210. * gfs2_unfreeze - reallow writes to the filesystem
  211. * @sb: the VFS structure for the filesystem
  212. *
  213. */
  214. static int gfs2_unfreeze(struct super_block *sb)
  215. {
  216. gfs2_unfreeze_fs(sb->s_fs_info);
  217. return 0;
  218. }
  219. /**
  220. * statfs_fill - fill in the sg for a given RG
  221. * @rgd: the RG
  222. * @sc: the sc structure
  223. *
  224. * Returns: 0 on success, -ESTALE if the LVB is invalid
  225. */
  226. static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
  227. struct gfs2_statfs_change_host *sc)
  228. {
  229. gfs2_rgrp_verify(rgd);
  230. sc->sc_total += rgd->rd_data;
  231. sc->sc_free += rgd->rd_free;
  232. sc->sc_dinodes += rgd->rd_dinodes;
  233. return 0;
  234. }
  235. /**
  236. * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
  237. * @sdp: the filesystem
  238. * @sc: the sc info that will be returned
  239. *
  240. * Any error (other than a signal) will cause this routine to fall back
  241. * to the synchronous version.
  242. *
  243. * FIXME: This really shouldn't busy wait like this.
  244. *
  245. * Returns: errno
  246. */
  247. static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
  248. {
  249. struct gfs2_holder ri_gh;
  250. struct gfs2_rgrpd *rgd_next;
  251. struct gfs2_holder *gha, *gh;
  252. unsigned int slots = 64;
  253. unsigned int x;
  254. int done;
  255. int error = 0, err;
  256. memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
  257. gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
  258. if (!gha)
  259. return -ENOMEM;
  260. error = gfs2_rindex_hold(sdp, &ri_gh);
  261. if (error)
  262. goto out;
  263. rgd_next = gfs2_rgrpd_get_first(sdp);
  264. for (;;) {
  265. done = 1;
  266. for (x = 0; x < slots; x++) {
  267. gh = gha + x;
  268. if (gh->gh_gl && gfs2_glock_poll(gh)) {
  269. err = gfs2_glock_wait(gh);
  270. if (err) {
  271. gfs2_holder_uninit(gh);
  272. error = err;
  273. } else {
  274. if (!error)
  275. error = statfs_slow_fill(
  276. gh->gh_gl->gl_object, sc);
  277. gfs2_glock_dq_uninit(gh);
  278. }
  279. }
  280. if (gh->gh_gl)
  281. done = 0;
  282. else if (rgd_next && !error) {
  283. error = gfs2_glock_nq_init(rgd_next->rd_gl,
  284. LM_ST_SHARED,
  285. GL_ASYNC,
  286. gh);
  287. rgd_next = gfs2_rgrpd_get_next(rgd_next);
  288. done = 0;
  289. }
  290. if (signal_pending(current))
  291. error = -ERESTARTSYS;
  292. }
  293. if (done)
  294. break;
  295. yield();
  296. }
  297. gfs2_glock_dq_uninit(&ri_gh);
  298. out:
  299. kfree(gha);
  300. return error;
  301. }
  302. /**
  303. * gfs2_statfs_i - Do a statfs
  304. * @sdp: the filesystem
  305. * @sg: the sg structure
  306. *
  307. * Returns: errno
  308. */
  309. static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
  310. {
  311. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  312. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  313. spin_lock(&sdp->sd_statfs_spin);
  314. *sc = *m_sc;
  315. sc->sc_total += l_sc->sc_total;
  316. sc->sc_free += l_sc->sc_free;
  317. sc->sc_dinodes += l_sc->sc_dinodes;
  318. spin_unlock(&sdp->sd_statfs_spin);
  319. if (sc->sc_free < 0)
  320. sc->sc_free = 0;
  321. if (sc->sc_free > sc->sc_total)
  322. sc->sc_free = sc->sc_total;
  323. if (sc->sc_dinodes < 0)
  324. sc->sc_dinodes = 0;
  325. return 0;
  326. }
  327. /**
  328. * gfs2_statfs - Gather and return stats about the filesystem
  329. * @sb: The superblock
  330. * @statfsbuf: The buffer
  331. *
  332. * Returns: 0 on success or error code
  333. */
  334. static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  335. {
  336. struct super_block *sb = dentry->d_inode->i_sb;
  337. struct gfs2_sbd *sdp = sb->s_fs_info;
  338. struct gfs2_statfs_change_host sc;
  339. int error;
  340. if (gfs2_tune_get(sdp, gt_statfs_slow))
  341. error = gfs2_statfs_slow(sdp, &sc);
  342. else
  343. error = gfs2_statfs_i(sdp, &sc);
  344. if (error)
  345. return error;
  346. buf->f_type = GFS2_MAGIC;
  347. buf->f_bsize = sdp->sd_sb.sb_bsize;
  348. buf->f_blocks = sc.sc_total;
  349. buf->f_bfree = sc.sc_free;
  350. buf->f_bavail = sc.sc_free;
  351. buf->f_files = sc.sc_dinodes + sc.sc_free;
  352. buf->f_ffree = sc.sc_free;
  353. buf->f_namelen = GFS2_FNAMESIZE;
  354. return 0;
  355. }
  356. /**
  357. * gfs2_remount_fs - called when the FS is remounted
  358. * @sb: the filesystem
  359. * @flags: the remount flags
  360. * @data: extra data passed in (not used right now)
  361. *
  362. * Returns: errno
  363. */
  364. static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
  365. {
  366. struct gfs2_sbd *sdp = sb->s_fs_info;
  367. struct gfs2_args args = sdp->sd_args; /* Default to current settings */
  368. struct gfs2_tune *gt = &sdp->sd_tune;
  369. int error;
  370. spin_lock(&gt->gt_spin);
  371. args.ar_commit = gt->gt_log_flush_secs;
  372. spin_unlock(&gt->gt_spin);
  373. error = gfs2_mount_args(sdp, &args, data);
  374. if (error)
  375. return error;
  376. /* Not allowed to change locking details */
  377. if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
  378. strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
  379. strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
  380. return -EINVAL;
  381. /* Some flags must not be changed */
  382. if (args_neq(&args, &sdp->sd_args, spectator) ||
  383. args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
  384. args_neq(&args, &sdp->sd_args, localflocks) ||
  385. args_neq(&args, &sdp->sd_args, localcaching) ||
  386. args_neq(&args, &sdp->sd_args, meta))
  387. return -EINVAL;
  388. if (sdp->sd_args.ar_spectator)
  389. *flags |= MS_RDONLY;
  390. if ((sb->s_flags ^ *flags) & MS_RDONLY) {
  391. if (*flags & MS_RDONLY)
  392. error = gfs2_make_fs_ro(sdp);
  393. else
  394. error = gfs2_make_fs_rw(sdp);
  395. if (error)
  396. return error;
  397. }
  398. sdp->sd_args = args;
  399. if (sdp->sd_args.ar_posix_acl)
  400. sb->s_flags |= MS_POSIXACL;
  401. else
  402. sb->s_flags &= ~MS_POSIXACL;
  403. spin_lock(&gt->gt_spin);
  404. gt->gt_log_flush_secs = args.ar_commit;
  405. spin_unlock(&gt->gt_spin);
  406. return 0;
  407. }
  408. /**
  409. * gfs2_drop_inode - Drop an inode (test for remote unlink)
  410. * @inode: The inode to drop
  411. *
  412. * If we've received a callback on an iopen lock then its because a
  413. * remote node tried to deallocate the inode but failed due to this node
  414. * still having the inode open. Here we mark the link count zero
  415. * since we know that it must have reached zero if the GLF_DEMOTE flag
  416. * is set on the iopen glock. If we didn't do a disk read since the
  417. * remote node removed the final link then we might otherwise miss
  418. * this event. This check ensures that this node will deallocate the
  419. * inode's blocks, or alternatively pass the baton on to another
  420. * node for later deallocation.
  421. */
  422. static void gfs2_drop_inode(struct inode *inode)
  423. {
  424. struct gfs2_inode *ip = GFS2_I(inode);
  425. if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
  426. struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
  427. if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
  428. clear_nlink(inode);
  429. }
  430. generic_drop_inode(inode);
  431. }
  432. /**
  433. * gfs2_clear_inode - Deallocate an inode when VFS is done with it
  434. * @inode: The VFS inode
  435. *
  436. */
  437. static void gfs2_clear_inode(struct inode *inode)
  438. {
  439. struct gfs2_inode *ip = GFS2_I(inode);
  440. /* This tells us its a "real" inode and not one which only
  441. * serves to contain an address space (see rgrp.c, meta_io.c)
  442. * which therefore doesn't have its own glocks.
  443. */
  444. if (test_bit(GIF_USER, &ip->i_flags)) {
  445. ip->i_gl->gl_object = NULL;
  446. gfs2_glock_put(ip->i_gl);
  447. ip->i_gl = NULL;
  448. if (ip->i_iopen_gh.gh_gl) {
  449. ip->i_iopen_gh.gh_gl->gl_object = NULL;
  450. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  451. }
  452. }
  453. }
  454. static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
  455. {
  456. do {
  457. if (d1 == d2)
  458. return 1;
  459. d1 = d1->d_parent;
  460. } while (!IS_ROOT(d1));
  461. return 0;
  462. }
  463. /**
  464. * gfs2_show_options - Show mount options for /proc/mounts
  465. * @s: seq_file structure
  466. * @mnt: vfsmount
  467. *
  468. * Returns: 0 on success or error code
  469. */
  470. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  471. {
  472. struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
  473. struct gfs2_args *args = &sdp->sd_args;
  474. int lfsecs;
  475. if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
  476. seq_printf(s, ",meta");
  477. if (args->ar_lockproto[0])
  478. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  479. if (args->ar_locktable[0])
  480. seq_printf(s, ",locktable=%s", args->ar_locktable);
  481. if (args->ar_hostdata[0])
  482. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  483. if (args->ar_spectator)
  484. seq_printf(s, ",spectator");
  485. if (args->ar_ignore_local_fs)
  486. seq_printf(s, ",ignore_local_fs");
  487. if (args->ar_localflocks)
  488. seq_printf(s, ",localflocks");
  489. if (args->ar_localcaching)
  490. seq_printf(s, ",localcaching");
  491. if (args->ar_debug)
  492. seq_printf(s, ",debug");
  493. if (args->ar_upgrade)
  494. seq_printf(s, ",upgrade");
  495. if (args->ar_posix_acl)
  496. seq_printf(s, ",acl");
  497. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  498. char *state;
  499. switch (args->ar_quota) {
  500. case GFS2_QUOTA_OFF:
  501. state = "off";
  502. break;
  503. case GFS2_QUOTA_ACCOUNT:
  504. state = "account";
  505. break;
  506. case GFS2_QUOTA_ON:
  507. state = "on";
  508. break;
  509. default:
  510. state = "unknown";
  511. break;
  512. }
  513. seq_printf(s, ",quota=%s", state);
  514. }
  515. if (args->ar_suiddir)
  516. seq_printf(s, ",suiddir");
  517. if (args->ar_data != GFS2_DATA_DEFAULT) {
  518. char *state;
  519. switch (args->ar_data) {
  520. case GFS2_DATA_WRITEBACK:
  521. state = "writeback";
  522. break;
  523. case GFS2_DATA_ORDERED:
  524. state = "ordered";
  525. break;
  526. default:
  527. state = "unknown";
  528. break;
  529. }
  530. seq_printf(s, ",data=%s", state);
  531. }
  532. if (args->ar_discard)
  533. seq_printf(s, ",discard");
  534. lfsecs = sdp->sd_tune.gt_log_flush_secs;
  535. if (lfsecs != 60)
  536. seq_printf(s, ",commit=%d", lfsecs);
  537. return 0;
  538. }
  539. /*
  540. * We have to (at the moment) hold the inodes main lock to cover
  541. * the gap between unlocking the shared lock on the iopen lock and
  542. * taking the exclusive lock. I'd rather do a shared -> exclusive
  543. * conversion on the iopen lock, but we can change that later. This
  544. * is safe, just less efficient.
  545. */
  546. static void gfs2_delete_inode(struct inode *inode)
  547. {
  548. struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
  549. struct gfs2_inode *ip = GFS2_I(inode);
  550. struct gfs2_holder gh;
  551. int error;
  552. if (!test_bit(GIF_USER, &ip->i_flags))
  553. goto out;
  554. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  555. if (unlikely(error)) {
  556. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  557. goto out;
  558. }
  559. gfs2_glock_dq_wait(&ip->i_iopen_gh);
  560. gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
  561. error = gfs2_glock_nq(&ip->i_iopen_gh);
  562. if (error)
  563. goto out_truncate;
  564. if (S_ISDIR(inode->i_mode) &&
  565. (ip->i_diskflags & GFS2_DIF_EXHASH)) {
  566. error = gfs2_dir_exhash_dealloc(ip);
  567. if (error)
  568. goto out_unlock;
  569. }
  570. if (ip->i_eattr) {
  571. error = gfs2_ea_dealloc(ip);
  572. if (error)
  573. goto out_unlock;
  574. }
  575. if (!gfs2_is_stuffed(ip)) {
  576. error = gfs2_file_dealloc(ip);
  577. if (error)
  578. goto out_unlock;
  579. }
  580. error = gfs2_dinode_dealloc(ip);
  581. if (error)
  582. goto out_unlock;
  583. out_truncate:
  584. error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
  585. if (error)
  586. goto out_unlock;
  587. /* Needs to be done before glock release & also in a transaction */
  588. truncate_inode_pages(&inode->i_data, 0);
  589. gfs2_trans_end(sdp);
  590. out_unlock:
  591. if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
  592. gfs2_glock_dq(&ip->i_iopen_gh);
  593. gfs2_holder_uninit(&ip->i_iopen_gh);
  594. gfs2_glock_dq_uninit(&gh);
  595. if (error && error != GLR_TRYFAILED)
  596. fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
  597. out:
  598. truncate_inode_pages(&inode->i_data, 0);
  599. clear_inode(inode);
  600. }
  601. static struct inode *gfs2_alloc_inode(struct super_block *sb)
  602. {
  603. struct gfs2_inode *ip;
  604. ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
  605. if (ip) {
  606. ip->i_flags = 0;
  607. ip->i_gl = NULL;
  608. }
  609. return &ip->i_inode;
  610. }
  611. static void gfs2_destroy_inode(struct inode *inode)
  612. {
  613. kmem_cache_free(gfs2_inode_cachep, inode);
  614. }
  615. const struct super_operations gfs2_super_ops = {
  616. .alloc_inode = gfs2_alloc_inode,
  617. .destroy_inode = gfs2_destroy_inode,
  618. .write_inode = gfs2_write_inode,
  619. .delete_inode = gfs2_delete_inode,
  620. .put_super = gfs2_put_super,
  621. .write_super = gfs2_write_super,
  622. .sync_fs = gfs2_sync_fs,
  623. .freeze_fs = gfs2_freeze,
  624. .unfreeze_fs = gfs2_unfreeze,
  625. .statfs = gfs2_statfs,
  626. .remount_fs = gfs2_remount_fs,
  627. .clear_inode = gfs2_clear_inode,
  628. .drop_inode = gfs2_drop_inode,
  629. .show_options = gfs2_show_options,
  630. };