ops_super.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. int error;
  369. error = gfs2_mount_args(sdp, &args, data);
  370. if (error)
  371. return error;
  372. /* Not allowed to change locking details */
  373. if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
  374. strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
  375. strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
  376. return -EINVAL;
  377. /* Some flags must not be changed */
  378. if (args_neq(&args, &sdp->sd_args, spectator) ||
  379. args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
  380. args_neq(&args, &sdp->sd_args, localflocks) ||
  381. args_neq(&args, &sdp->sd_args, localcaching) ||
  382. args_neq(&args, &sdp->sd_args, meta))
  383. return -EINVAL;
  384. if (sdp->sd_args.ar_spectator)
  385. *flags |= MS_RDONLY;
  386. if ((sb->s_flags ^ *flags) & MS_RDONLY) {
  387. if (*flags & MS_RDONLY)
  388. error = gfs2_make_fs_ro(sdp);
  389. else
  390. error = gfs2_make_fs_rw(sdp);
  391. if (error)
  392. return error;
  393. }
  394. sdp->sd_args = args;
  395. if (sdp->sd_args.ar_posix_acl)
  396. sb->s_flags |= MS_POSIXACL;
  397. else
  398. sb->s_flags &= ~MS_POSIXACL;
  399. return 0;
  400. }
  401. /**
  402. * gfs2_drop_inode - Drop an inode (test for remote unlink)
  403. * @inode: The inode to drop
  404. *
  405. * If we've received a callback on an iopen lock then its because a
  406. * remote node tried to deallocate the inode but failed due to this node
  407. * still having the inode open. Here we mark the link count zero
  408. * since we know that it must have reached zero if the GLF_DEMOTE flag
  409. * is set on the iopen glock. If we didn't do a disk read since the
  410. * remote node removed the final link then we might otherwise miss
  411. * this event. This check ensures that this node will deallocate the
  412. * inode's blocks, or alternatively pass the baton on to another
  413. * node for later deallocation.
  414. */
  415. static void gfs2_drop_inode(struct inode *inode)
  416. {
  417. struct gfs2_inode *ip = GFS2_I(inode);
  418. if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
  419. struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
  420. if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
  421. clear_nlink(inode);
  422. }
  423. generic_drop_inode(inode);
  424. }
  425. /**
  426. * gfs2_clear_inode - Deallocate an inode when VFS is done with it
  427. * @inode: The VFS inode
  428. *
  429. */
  430. static void gfs2_clear_inode(struct inode *inode)
  431. {
  432. struct gfs2_inode *ip = GFS2_I(inode);
  433. /* This tells us its a "real" inode and not one which only
  434. * serves to contain an address space (see rgrp.c, meta_io.c)
  435. * which therefore doesn't have its own glocks.
  436. */
  437. if (test_bit(GIF_USER, &ip->i_flags)) {
  438. ip->i_gl->gl_object = NULL;
  439. gfs2_glock_put(ip->i_gl);
  440. ip->i_gl = NULL;
  441. if (ip->i_iopen_gh.gh_gl) {
  442. ip->i_iopen_gh.gh_gl->gl_object = NULL;
  443. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  444. }
  445. }
  446. }
  447. static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
  448. {
  449. do {
  450. if (d1 == d2)
  451. return 1;
  452. d1 = d1->d_parent;
  453. } while (!IS_ROOT(d1));
  454. return 0;
  455. }
  456. /**
  457. * gfs2_show_options - Show mount options for /proc/mounts
  458. * @s: seq_file structure
  459. * @mnt: vfsmount
  460. *
  461. * Returns: 0 on success or error code
  462. */
  463. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  464. {
  465. struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
  466. struct gfs2_args *args = &sdp->sd_args;
  467. if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
  468. seq_printf(s, ",meta");
  469. if (args->ar_lockproto[0])
  470. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  471. if (args->ar_locktable[0])
  472. seq_printf(s, ",locktable=%s", args->ar_locktable);
  473. if (args->ar_hostdata[0])
  474. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  475. if (args->ar_spectator)
  476. seq_printf(s, ",spectator");
  477. if (args->ar_ignore_local_fs)
  478. seq_printf(s, ",ignore_local_fs");
  479. if (args->ar_localflocks)
  480. seq_printf(s, ",localflocks");
  481. if (args->ar_localcaching)
  482. seq_printf(s, ",localcaching");
  483. if (args->ar_debug)
  484. seq_printf(s, ",debug");
  485. if (args->ar_upgrade)
  486. seq_printf(s, ",upgrade");
  487. if (args->ar_posix_acl)
  488. seq_printf(s, ",acl");
  489. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  490. char *state;
  491. switch (args->ar_quota) {
  492. case GFS2_QUOTA_OFF:
  493. state = "off";
  494. break;
  495. case GFS2_QUOTA_ACCOUNT:
  496. state = "account";
  497. break;
  498. case GFS2_QUOTA_ON:
  499. state = "on";
  500. break;
  501. default:
  502. state = "unknown";
  503. break;
  504. }
  505. seq_printf(s, ",quota=%s", state);
  506. }
  507. if (args->ar_suiddir)
  508. seq_printf(s, ",suiddir");
  509. if (args->ar_data != GFS2_DATA_DEFAULT) {
  510. char *state;
  511. switch (args->ar_data) {
  512. case GFS2_DATA_WRITEBACK:
  513. state = "writeback";
  514. break;
  515. case GFS2_DATA_ORDERED:
  516. state = "ordered";
  517. break;
  518. default:
  519. state = "unknown";
  520. break;
  521. }
  522. seq_printf(s, ",data=%s", state);
  523. }
  524. if (args->ar_discard)
  525. seq_printf(s, ",discard");
  526. return 0;
  527. }
  528. /*
  529. * We have to (at the moment) hold the inodes main lock to cover
  530. * the gap between unlocking the shared lock on the iopen lock and
  531. * taking the exclusive lock. I'd rather do a shared -> exclusive
  532. * conversion on the iopen lock, but we can change that later. This
  533. * is safe, just less efficient.
  534. */
  535. static void gfs2_delete_inode(struct inode *inode)
  536. {
  537. struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
  538. struct gfs2_inode *ip = GFS2_I(inode);
  539. struct gfs2_holder gh;
  540. int error;
  541. if (!test_bit(GIF_USER, &ip->i_flags))
  542. goto out;
  543. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  544. if (unlikely(error)) {
  545. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  546. goto out;
  547. }
  548. gfs2_glock_dq_wait(&ip->i_iopen_gh);
  549. gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
  550. error = gfs2_glock_nq(&ip->i_iopen_gh);
  551. if (error)
  552. goto out_truncate;
  553. if (S_ISDIR(inode->i_mode) &&
  554. (ip->i_diskflags & GFS2_DIF_EXHASH)) {
  555. error = gfs2_dir_exhash_dealloc(ip);
  556. if (error)
  557. goto out_unlock;
  558. }
  559. if (ip->i_eattr) {
  560. error = gfs2_ea_dealloc(ip);
  561. if (error)
  562. goto out_unlock;
  563. }
  564. if (!gfs2_is_stuffed(ip)) {
  565. error = gfs2_file_dealloc(ip);
  566. if (error)
  567. goto out_unlock;
  568. }
  569. error = gfs2_dinode_dealloc(ip);
  570. if (error)
  571. goto out_unlock;
  572. out_truncate:
  573. error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
  574. if (error)
  575. goto out_unlock;
  576. /* Needs to be done before glock release & also in a transaction */
  577. truncate_inode_pages(&inode->i_data, 0);
  578. gfs2_trans_end(sdp);
  579. out_unlock:
  580. if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
  581. gfs2_glock_dq(&ip->i_iopen_gh);
  582. gfs2_holder_uninit(&ip->i_iopen_gh);
  583. gfs2_glock_dq_uninit(&gh);
  584. if (error && error != GLR_TRYFAILED)
  585. fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
  586. out:
  587. truncate_inode_pages(&inode->i_data, 0);
  588. clear_inode(inode);
  589. }
  590. static struct inode *gfs2_alloc_inode(struct super_block *sb)
  591. {
  592. struct gfs2_inode *ip;
  593. ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
  594. if (ip) {
  595. ip->i_flags = 0;
  596. ip->i_gl = NULL;
  597. }
  598. return &ip->i_inode;
  599. }
  600. static void gfs2_destroy_inode(struct inode *inode)
  601. {
  602. kmem_cache_free(gfs2_inode_cachep, inode);
  603. }
  604. const struct super_operations gfs2_super_ops = {
  605. .alloc_inode = gfs2_alloc_inode,
  606. .destroy_inode = gfs2_destroy_inode,
  607. .write_inode = gfs2_write_inode,
  608. .delete_inode = gfs2_delete_inode,
  609. .put_super = gfs2_put_super,
  610. .write_super = gfs2_write_super,
  611. .sync_fs = gfs2_sync_fs,
  612. .freeze_fs = gfs2_freeze,
  613. .unfreeze_fs = gfs2_unfreeze,
  614. .statfs = gfs2_statfs,
  615. .remount_fs = gfs2_remount_fs,
  616. .clear_inode = gfs2_clear_inode,
  617. .drop_inode = gfs2_drop_inode,
  618. .show_options = gfs2_show_options,
  619. };