super.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2007 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/bio.h>
  10. #include <linux/sched.h>
  11. #include <linux/slab.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/completion.h>
  14. #include <linux/buffer_head.h>
  15. #include <linux/statfs.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/mount.h>
  18. #include <linux/kthread.h>
  19. #include <linux/delay.h>
  20. #include <linux/gfs2_ondisk.h>
  21. #include <linux/crc32.h>
  22. #include <linux/time.h>
  23. #include "gfs2.h"
  24. #include "incore.h"
  25. #include "bmap.h"
  26. #include "dir.h"
  27. #include "glock.h"
  28. #include "glops.h"
  29. #include "inode.h"
  30. #include "log.h"
  31. #include "meta_io.h"
  32. #include "quota.h"
  33. #include "recovery.h"
  34. #include "rgrp.h"
  35. #include "super.h"
  36. #include "trans.h"
  37. #include "util.h"
  38. #include "sys.h"
  39. #include "eattr.h"
  40. #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
  41. enum {
  42. Opt_lockproto,
  43. Opt_locktable,
  44. Opt_hostdata,
  45. Opt_spectator,
  46. Opt_ignore_local_fs,
  47. Opt_localflocks,
  48. Opt_localcaching,
  49. Opt_debug,
  50. Opt_nodebug,
  51. Opt_upgrade,
  52. Opt_acl,
  53. Opt_noacl,
  54. Opt_quota_off,
  55. Opt_quota_account,
  56. Opt_quota_on,
  57. Opt_quota,
  58. Opt_noquota,
  59. Opt_suiddir,
  60. Opt_nosuiddir,
  61. Opt_data_writeback,
  62. Opt_data_ordered,
  63. Opt_meta,
  64. Opt_discard,
  65. Opt_nodiscard,
  66. Opt_commit,
  67. Opt_error,
  68. };
  69. static const match_table_t tokens = {
  70. {Opt_lockproto, "lockproto=%s"},
  71. {Opt_locktable, "locktable=%s"},
  72. {Opt_hostdata, "hostdata=%s"},
  73. {Opt_spectator, "spectator"},
  74. {Opt_ignore_local_fs, "ignore_local_fs"},
  75. {Opt_localflocks, "localflocks"},
  76. {Opt_localcaching, "localcaching"},
  77. {Opt_debug, "debug"},
  78. {Opt_nodebug, "nodebug"},
  79. {Opt_upgrade, "upgrade"},
  80. {Opt_acl, "acl"},
  81. {Opt_noacl, "noacl"},
  82. {Opt_quota_off, "quota=off"},
  83. {Opt_quota_account, "quota=account"},
  84. {Opt_quota_on, "quota=on"},
  85. {Opt_quota, "quota"},
  86. {Opt_noquota, "noquota"},
  87. {Opt_suiddir, "suiddir"},
  88. {Opt_nosuiddir, "nosuiddir"},
  89. {Opt_data_writeback, "data=writeback"},
  90. {Opt_data_ordered, "data=ordered"},
  91. {Opt_meta, "meta"},
  92. {Opt_discard, "discard"},
  93. {Opt_nodiscard, "nodiscard"},
  94. {Opt_commit, "commit=%d"},
  95. {Opt_error, NULL}
  96. };
  97. /**
  98. * gfs2_mount_args - Parse mount options
  99. * @sdp:
  100. * @data:
  101. *
  102. * Return: errno
  103. */
  104. int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
  105. {
  106. char *o;
  107. int token;
  108. substring_t tmp[MAX_OPT_ARGS];
  109. int rv;
  110. /* Split the options into tokens with the "," character and
  111. process them */
  112. while (1) {
  113. o = strsep(&options, ",");
  114. if (o == NULL)
  115. break;
  116. if (*o == '\0')
  117. continue;
  118. token = match_token(o, tokens, tmp);
  119. switch (token) {
  120. case Opt_lockproto:
  121. match_strlcpy(args->ar_lockproto, &tmp[0],
  122. GFS2_LOCKNAME_LEN);
  123. break;
  124. case Opt_locktable:
  125. match_strlcpy(args->ar_locktable, &tmp[0],
  126. GFS2_LOCKNAME_LEN);
  127. break;
  128. case Opt_hostdata:
  129. match_strlcpy(args->ar_hostdata, &tmp[0],
  130. GFS2_LOCKNAME_LEN);
  131. break;
  132. case Opt_spectator:
  133. args->ar_spectator = 1;
  134. break;
  135. case Opt_ignore_local_fs:
  136. args->ar_ignore_local_fs = 1;
  137. break;
  138. case Opt_localflocks:
  139. args->ar_localflocks = 1;
  140. break;
  141. case Opt_localcaching:
  142. args->ar_localcaching = 1;
  143. break;
  144. case Opt_debug:
  145. args->ar_debug = 1;
  146. break;
  147. case Opt_nodebug:
  148. args->ar_debug = 0;
  149. break;
  150. case Opt_upgrade:
  151. args->ar_upgrade = 1;
  152. break;
  153. case Opt_acl:
  154. args->ar_posix_acl = 1;
  155. break;
  156. case Opt_noacl:
  157. args->ar_posix_acl = 0;
  158. break;
  159. case Opt_quota_off:
  160. case Opt_noquota:
  161. args->ar_quota = GFS2_QUOTA_OFF;
  162. break;
  163. case Opt_quota_account:
  164. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  165. break;
  166. case Opt_quota_on:
  167. case Opt_quota:
  168. args->ar_quota = GFS2_QUOTA_ON;
  169. break;
  170. case Opt_suiddir:
  171. args->ar_suiddir = 1;
  172. break;
  173. case Opt_nosuiddir:
  174. args->ar_suiddir = 0;
  175. break;
  176. case Opt_data_writeback:
  177. args->ar_data = GFS2_DATA_WRITEBACK;
  178. break;
  179. case Opt_data_ordered:
  180. args->ar_data = GFS2_DATA_ORDERED;
  181. break;
  182. case Opt_meta:
  183. args->ar_meta = 1;
  184. break;
  185. case Opt_discard:
  186. args->ar_discard = 1;
  187. break;
  188. case Opt_nodiscard:
  189. args->ar_discard = 0;
  190. break;
  191. case Opt_commit:
  192. rv = match_int(&tmp[0], &args->ar_commit);
  193. if (rv || args->ar_commit <= 0) {
  194. fs_info(sdp, "commit mount option requires a positive numeric argument\n");
  195. return rv ? rv : -EINVAL;
  196. }
  197. break;
  198. case Opt_error:
  199. default:
  200. fs_info(sdp, "invalid mount option: %s\n", o);
  201. return -EINVAL;
  202. }
  203. }
  204. return 0;
  205. }
  206. /**
  207. * gfs2_jindex_free - Clear all the journal index information
  208. * @sdp: The GFS2 superblock
  209. *
  210. */
  211. void gfs2_jindex_free(struct gfs2_sbd *sdp)
  212. {
  213. struct list_head list, *head;
  214. struct gfs2_jdesc *jd;
  215. struct gfs2_journal_extent *jext;
  216. spin_lock(&sdp->sd_jindex_spin);
  217. list_add(&list, &sdp->sd_jindex_list);
  218. list_del_init(&sdp->sd_jindex_list);
  219. sdp->sd_journals = 0;
  220. spin_unlock(&sdp->sd_jindex_spin);
  221. while (!list_empty(&list)) {
  222. jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
  223. head = &jd->extent_list;
  224. while (!list_empty(head)) {
  225. jext = list_entry(head->next,
  226. struct gfs2_journal_extent,
  227. extent_list);
  228. list_del(&jext->extent_list);
  229. kfree(jext);
  230. }
  231. list_del(&jd->jd_list);
  232. iput(jd->jd_inode);
  233. kfree(jd);
  234. }
  235. }
  236. static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid)
  237. {
  238. struct gfs2_jdesc *jd;
  239. int found = 0;
  240. list_for_each_entry(jd, head, jd_list) {
  241. if (jd->jd_jid == jid) {
  242. found = 1;
  243. break;
  244. }
  245. }
  246. if (!found)
  247. jd = NULL;
  248. return jd;
  249. }
  250. struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid)
  251. {
  252. struct gfs2_jdesc *jd;
  253. spin_lock(&sdp->sd_jindex_spin);
  254. jd = jdesc_find_i(&sdp->sd_jindex_list, jid);
  255. spin_unlock(&sdp->sd_jindex_spin);
  256. return jd;
  257. }
  258. int gfs2_jdesc_check(struct gfs2_jdesc *jd)
  259. {
  260. struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
  261. struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
  262. int ar;
  263. int error;
  264. if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) ||
  265. (ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) {
  266. gfs2_consist_inode(ip);
  267. return -EIO;
  268. }
  269. jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift;
  270. error = gfs2_write_alloc_required(ip, 0, ip->i_disksize, &ar);
  271. if (!error && ar) {
  272. gfs2_consist_inode(ip);
  273. error = -EIO;
  274. }
  275. return error;
  276. }
  277. /**
  278. * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
  279. * @sdp: the filesystem
  280. *
  281. * Returns: errno
  282. */
  283. int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
  284. {
  285. struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
  286. struct gfs2_glock *j_gl = ip->i_gl;
  287. struct gfs2_holder t_gh;
  288. struct gfs2_log_header_host head;
  289. int error;
  290. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh);
  291. if (error)
  292. return error;
  293. j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
  294. error = gfs2_find_jhead(sdp->sd_jdesc, &head);
  295. if (error)
  296. goto fail;
  297. if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
  298. gfs2_consist(sdp);
  299. error = -EIO;
  300. goto fail;
  301. }
  302. /* Initialize some head of the log stuff */
  303. sdp->sd_log_sequence = head.lh_sequence + 1;
  304. gfs2_log_pointers_init(sdp, head.lh_blkno);
  305. error = gfs2_quota_init(sdp);
  306. if (error)
  307. goto fail;
  308. set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
  309. gfs2_glock_dq_uninit(&t_gh);
  310. return 0;
  311. fail:
  312. t_gh.gh_flags |= GL_NOCACHE;
  313. gfs2_glock_dq_uninit(&t_gh);
  314. return error;
  315. }
  316. void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf)
  317. {
  318. const struct gfs2_statfs_change *str = buf;
  319. sc->sc_total = be64_to_cpu(str->sc_total);
  320. sc->sc_free = be64_to_cpu(str->sc_free);
  321. sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
  322. }
  323. static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
  324. {
  325. struct gfs2_statfs_change *str = buf;
  326. str->sc_total = cpu_to_be64(sc->sc_total);
  327. str->sc_free = cpu_to_be64(sc->sc_free);
  328. str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
  329. }
  330. int gfs2_statfs_init(struct gfs2_sbd *sdp)
  331. {
  332. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
  333. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  334. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  335. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  336. struct buffer_head *m_bh, *l_bh;
  337. struct gfs2_holder gh;
  338. int error;
  339. error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
  340. &gh);
  341. if (error)
  342. return error;
  343. error = gfs2_meta_inode_buffer(m_ip, &m_bh);
  344. if (error)
  345. goto out;
  346. if (sdp->sd_args.ar_spectator) {
  347. spin_lock(&sdp->sd_statfs_spin);
  348. gfs2_statfs_change_in(m_sc, m_bh->b_data +
  349. sizeof(struct gfs2_dinode));
  350. spin_unlock(&sdp->sd_statfs_spin);
  351. } else {
  352. error = gfs2_meta_inode_buffer(l_ip, &l_bh);
  353. if (error)
  354. goto out_m_bh;
  355. spin_lock(&sdp->sd_statfs_spin);
  356. gfs2_statfs_change_in(m_sc, m_bh->b_data +
  357. sizeof(struct gfs2_dinode));
  358. gfs2_statfs_change_in(l_sc, l_bh->b_data +
  359. sizeof(struct gfs2_dinode));
  360. spin_unlock(&sdp->sd_statfs_spin);
  361. brelse(l_bh);
  362. }
  363. out_m_bh:
  364. brelse(m_bh);
  365. out:
  366. gfs2_glock_dq_uninit(&gh);
  367. return 0;
  368. }
  369. void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
  370. s64 dinodes)
  371. {
  372. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  373. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  374. struct buffer_head *l_bh;
  375. int error;
  376. error = gfs2_meta_inode_buffer(l_ip, &l_bh);
  377. if (error)
  378. return;
  379. gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
  380. spin_lock(&sdp->sd_statfs_spin);
  381. l_sc->sc_total += total;
  382. l_sc->sc_free += free;
  383. l_sc->sc_dinodes += dinodes;
  384. gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode));
  385. spin_unlock(&sdp->sd_statfs_spin);
  386. brelse(l_bh);
  387. }
  388. void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh,
  389. struct buffer_head *l_bh)
  390. {
  391. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
  392. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  393. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  394. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  395. gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
  396. spin_lock(&sdp->sd_statfs_spin);
  397. m_sc->sc_total += l_sc->sc_total;
  398. m_sc->sc_free += l_sc->sc_free;
  399. m_sc->sc_dinodes += l_sc->sc_dinodes;
  400. memset(l_sc, 0, sizeof(struct gfs2_statfs_change));
  401. memset(l_bh->b_data + sizeof(struct gfs2_dinode),
  402. 0, sizeof(struct gfs2_statfs_change));
  403. spin_unlock(&sdp->sd_statfs_spin);
  404. gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1);
  405. gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode));
  406. }
  407. int gfs2_statfs_sync(struct gfs2_sbd *sdp)
  408. {
  409. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
  410. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  411. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  412. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  413. struct gfs2_holder gh;
  414. struct buffer_head *m_bh, *l_bh;
  415. int error;
  416. error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
  417. &gh);
  418. if (error)
  419. return error;
  420. error = gfs2_meta_inode_buffer(m_ip, &m_bh);
  421. if (error)
  422. goto out;
  423. spin_lock(&sdp->sd_statfs_spin);
  424. gfs2_statfs_change_in(m_sc, m_bh->b_data +
  425. sizeof(struct gfs2_dinode));
  426. if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) {
  427. spin_unlock(&sdp->sd_statfs_spin);
  428. goto out_bh;
  429. }
  430. spin_unlock(&sdp->sd_statfs_spin);
  431. error = gfs2_meta_inode_buffer(l_ip, &l_bh);
  432. if (error)
  433. goto out_bh;
  434. error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0);
  435. if (error)
  436. goto out_bh2;
  437. update_statfs(sdp, m_bh, l_bh);
  438. gfs2_trans_end(sdp);
  439. out_bh2:
  440. brelse(l_bh);
  441. out_bh:
  442. brelse(m_bh);
  443. out:
  444. gfs2_glock_dq_uninit(&gh);
  445. return error;
  446. }
  447. struct lfcc {
  448. struct list_head list;
  449. struct gfs2_holder gh;
  450. };
  451. /**
  452. * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all
  453. * journals are clean
  454. * @sdp: the file system
  455. * @state: the state to put the transaction lock into
  456. * @t_gh: the hold on the transaction lock
  457. *
  458. * Returns: errno
  459. */
  460. static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
  461. struct gfs2_holder *t_gh)
  462. {
  463. struct gfs2_inode *ip;
  464. struct gfs2_jdesc *jd;
  465. struct lfcc *lfcc;
  466. LIST_HEAD(list);
  467. struct gfs2_log_header_host lh;
  468. int error;
  469. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  470. lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL);
  471. if (!lfcc) {
  472. error = -ENOMEM;
  473. goto out;
  474. }
  475. ip = GFS2_I(jd->jd_inode);
  476. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh);
  477. if (error) {
  478. kfree(lfcc);
  479. goto out;
  480. }
  481. list_add(&lfcc->list, &list);
  482. }
  483. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED,
  484. GL_NOCACHE, t_gh);
  485. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  486. error = gfs2_jdesc_check(jd);
  487. if (error)
  488. break;
  489. error = gfs2_find_jhead(jd, &lh);
  490. if (error)
  491. break;
  492. if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
  493. error = -EBUSY;
  494. break;
  495. }
  496. }
  497. if (error)
  498. gfs2_glock_dq_uninit(t_gh);
  499. out:
  500. while (!list_empty(&list)) {
  501. lfcc = list_entry(list.next, struct lfcc, list);
  502. list_del(&lfcc->list);
  503. gfs2_glock_dq_uninit(&lfcc->gh);
  504. kfree(lfcc);
  505. }
  506. return error;
  507. }
  508. /**
  509. * gfs2_freeze_fs - freezes the file system
  510. * @sdp: the file system
  511. *
  512. * This function flushes data and meta data for all machines by
  513. * aquiring the transaction log exclusively. All journals are
  514. * ensured to be in a clean state as well.
  515. *
  516. * Returns: errno
  517. */
  518. int gfs2_freeze_fs(struct gfs2_sbd *sdp)
  519. {
  520. int error = 0;
  521. mutex_lock(&sdp->sd_freeze_lock);
  522. if (!sdp->sd_freeze_count++) {
  523. error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh);
  524. if (error)
  525. sdp->sd_freeze_count--;
  526. }
  527. mutex_unlock(&sdp->sd_freeze_lock);
  528. return error;
  529. }
  530. /**
  531. * gfs2_unfreeze_fs - unfreezes the file system
  532. * @sdp: the file system
  533. *
  534. * This function allows the file system to proceed by unlocking
  535. * the exclusively held transaction lock. Other GFS2 nodes are
  536. * now free to acquire the lock shared and go on with their lives.
  537. *
  538. */
  539. void gfs2_unfreeze_fs(struct gfs2_sbd *sdp)
  540. {
  541. mutex_lock(&sdp->sd_freeze_lock);
  542. if (sdp->sd_freeze_count && !--sdp->sd_freeze_count)
  543. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  544. mutex_unlock(&sdp->sd_freeze_lock);
  545. }
  546. /**
  547. * gfs2_write_inode - Make sure the inode is stable on the disk
  548. * @inode: The inode
  549. * @sync: synchronous write flag
  550. *
  551. * Returns: errno
  552. */
  553. static int gfs2_write_inode(struct inode *inode, int sync)
  554. {
  555. struct gfs2_inode *ip = GFS2_I(inode);
  556. struct gfs2_sbd *sdp = GFS2_SB(inode);
  557. struct gfs2_holder gh;
  558. struct buffer_head *bh;
  559. struct timespec atime;
  560. struct gfs2_dinode *di;
  561. int ret = 0;
  562. /* Check this is a "normal" inode, etc */
  563. if (!test_bit(GIF_USER, &ip->i_flags) ||
  564. (current->flags & PF_MEMALLOC))
  565. return 0;
  566. ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  567. if (ret)
  568. goto do_flush;
  569. ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
  570. if (ret)
  571. goto do_unlock;
  572. ret = gfs2_meta_inode_buffer(ip, &bh);
  573. if (ret == 0) {
  574. di = (struct gfs2_dinode *)bh->b_data;
  575. atime.tv_sec = be64_to_cpu(di->di_atime);
  576. atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
  577. if (timespec_compare(&inode->i_atime, &atime) > 0) {
  578. gfs2_trans_add_bh(ip->i_gl, bh, 1);
  579. gfs2_dinode_out(ip, bh->b_data);
  580. }
  581. brelse(bh);
  582. }
  583. gfs2_trans_end(sdp);
  584. do_unlock:
  585. gfs2_glock_dq_uninit(&gh);
  586. do_flush:
  587. if (sync != 0)
  588. gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
  589. return ret;
  590. }
  591. /**
  592. * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
  593. * @sdp: the filesystem
  594. *
  595. * Returns: errno
  596. */
  597. static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
  598. {
  599. struct gfs2_holder t_gh;
  600. int error;
  601. flush_workqueue(gfs2_delete_workqueue);
  602. gfs2_quota_sync(sdp);
  603. gfs2_statfs_sync(sdp);
  604. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
  605. &t_gh);
  606. if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  607. return error;
  608. gfs2_meta_syncfs(sdp);
  609. gfs2_log_shutdown(sdp);
  610. clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
  611. if (t_gh.gh_gl)
  612. gfs2_glock_dq_uninit(&t_gh);
  613. gfs2_quota_cleanup(sdp);
  614. return error;
  615. }
  616. static int gfs2_umount_recovery_wait(void *word)
  617. {
  618. schedule();
  619. return 0;
  620. }
  621. /**
  622. * gfs2_put_super - Unmount the filesystem
  623. * @sb: The VFS superblock
  624. *
  625. */
  626. static void gfs2_put_super(struct super_block *sb)
  627. {
  628. struct gfs2_sbd *sdp = sb->s_fs_info;
  629. int error;
  630. struct gfs2_jdesc *jd;
  631. /* Unfreeze the filesystem, if we need to */
  632. mutex_lock(&sdp->sd_freeze_lock);
  633. if (sdp->sd_freeze_count)
  634. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  635. mutex_unlock(&sdp->sd_freeze_lock);
  636. /* No more recovery requests */
  637. set_bit(SDF_NORECOVERY, &sdp->sd_flags);
  638. smp_mb();
  639. /* Wait on outstanding recovery */
  640. restart:
  641. spin_lock(&sdp->sd_jindex_spin);
  642. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  643. if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
  644. continue;
  645. spin_unlock(&sdp->sd_jindex_spin);
  646. wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
  647. gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE);
  648. goto restart;
  649. }
  650. spin_unlock(&sdp->sd_jindex_spin);
  651. kthread_stop(sdp->sd_quotad_process);
  652. kthread_stop(sdp->sd_logd_process);
  653. if (!(sb->s_flags & MS_RDONLY)) {
  654. error = gfs2_make_fs_ro(sdp);
  655. if (error)
  656. gfs2_io_error(sdp);
  657. }
  658. /* At this point, we're through modifying the disk */
  659. /* Release stuff */
  660. iput(sdp->sd_jindex);
  661. iput(sdp->sd_inum_inode);
  662. iput(sdp->sd_statfs_inode);
  663. iput(sdp->sd_rindex);
  664. iput(sdp->sd_quota_inode);
  665. gfs2_glock_put(sdp->sd_rename_gl);
  666. gfs2_glock_put(sdp->sd_trans_gl);
  667. if (!sdp->sd_args.ar_spectator) {
  668. gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
  669. gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
  670. gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
  671. gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
  672. gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
  673. iput(sdp->sd_ir_inode);
  674. iput(sdp->sd_sc_inode);
  675. iput(sdp->sd_qc_inode);
  676. }
  677. gfs2_glock_dq_uninit(&sdp->sd_live_gh);
  678. gfs2_clear_rgrpd(sdp);
  679. gfs2_jindex_free(sdp);
  680. /* Take apart glock structures and buffer lists */
  681. gfs2_gl_hash_clear(sdp);
  682. /* Unmount the locking protocol */
  683. gfs2_lm_unmount(sdp);
  684. /* At this point, we're through participating in the lockspace */
  685. gfs2_sys_fs_del(sdp);
  686. }
  687. /**
  688. * gfs2_sync_fs - sync the filesystem
  689. * @sb: the superblock
  690. *
  691. * Flushes the log to disk.
  692. */
  693. static int gfs2_sync_fs(struct super_block *sb, int wait)
  694. {
  695. if (wait && sb->s_fs_info)
  696. gfs2_log_flush(sb->s_fs_info, NULL);
  697. return 0;
  698. }
  699. /**
  700. * gfs2_freeze - prevent further writes to the filesystem
  701. * @sb: the VFS structure for the filesystem
  702. *
  703. */
  704. static int gfs2_freeze(struct super_block *sb)
  705. {
  706. struct gfs2_sbd *sdp = sb->s_fs_info;
  707. int error;
  708. if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  709. return -EINVAL;
  710. for (;;) {
  711. error = gfs2_freeze_fs(sdp);
  712. if (!error)
  713. break;
  714. switch (error) {
  715. case -EBUSY:
  716. fs_err(sdp, "waiting for recovery before freeze\n");
  717. break;
  718. default:
  719. fs_err(sdp, "error freezing FS: %d\n", error);
  720. break;
  721. }
  722. fs_err(sdp, "retrying...\n");
  723. msleep(1000);
  724. }
  725. return 0;
  726. }
  727. /**
  728. * gfs2_unfreeze - reallow writes to the filesystem
  729. * @sb: the VFS structure for the filesystem
  730. *
  731. */
  732. static int gfs2_unfreeze(struct super_block *sb)
  733. {
  734. gfs2_unfreeze_fs(sb->s_fs_info);
  735. return 0;
  736. }
  737. /**
  738. * statfs_fill - fill in the sg for a given RG
  739. * @rgd: the RG
  740. * @sc: the sc structure
  741. *
  742. * Returns: 0 on success, -ESTALE if the LVB is invalid
  743. */
  744. static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
  745. struct gfs2_statfs_change_host *sc)
  746. {
  747. gfs2_rgrp_verify(rgd);
  748. sc->sc_total += rgd->rd_data;
  749. sc->sc_free += rgd->rd_free;
  750. sc->sc_dinodes += rgd->rd_dinodes;
  751. return 0;
  752. }
  753. /**
  754. * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
  755. * @sdp: the filesystem
  756. * @sc: the sc info that will be returned
  757. *
  758. * Any error (other than a signal) will cause this routine to fall back
  759. * to the synchronous version.
  760. *
  761. * FIXME: This really shouldn't busy wait like this.
  762. *
  763. * Returns: errno
  764. */
  765. static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
  766. {
  767. struct gfs2_holder ri_gh;
  768. struct gfs2_rgrpd *rgd_next;
  769. struct gfs2_holder *gha, *gh;
  770. unsigned int slots = 64;
  771. unsigned int x;
  772. int done;
  773. int error = 0, err;
  774. memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
  775. gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
  776. if (!gha)
  777. return -ENOMEM;
  778. error = gfs2_rindex_hold(sdp, &ri_gh);
  779. if (error)
  780. goto out;
  781. rgd_next = gfs2_rgrpd_get_first(sdp);
  782. for (;;) {
  783. done = 1;
  784. for (x = 0; x < slots; x++) {
  785. gh = gha + x;
  786. if (gh->gh_gl && gfs2_glock_poll(gh)) {
  787. err = gfs2_glock_wait(gh);
  788. if (err) {
  789. gfs2_holder_uninit(gh);
  790. error = err;
  791. } else {
  792. if (!error)
  793. error = statfs_slow_fill(
  794. gh->gh_gl->gl_object, sc);
  795. gfs2_glock_dq_uninit(gh);
  796. }
  797. }
  798. if (gh->gh_gl)
  799. done = 0;
  800. else if (rgd_next && !error) {
  801. error = gfs2_glock_nq_init(rgd_next->rd_gl,
  802. LM_ST_SHARED,
  803. GL_ASYNC,
  804. gh);
  805. rgd_next = gfs2_rgrpd_get_next(rgd_next);
  806. done = 0;
  807. }
  808. if (signal_pending(current))
  809. error = -ERESTARTSYS;
  810. }
  811. if (done)
  812. break;
  813. yield();
  814. }
  815. gfs2_glock_dq_uninit(&ri_gh);
  816. out:
  817. kfree(gha);
  818. return error;
  819. }
  820. /**
  821. * gfs2_statfs_i - Do a statfs
  822. * @sdp: the filesystem
  823. * @sg: the sg structure
  824. *
  825. * Returns: errno
  826. */
  827. static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
  828. {
  829. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  830. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  831. spin_lock(&sdp->sd_statfs_spin);
  832. *sc = *m_sc;
  833. sc->sc_total += l_sc->sc_total;
  834. sc->sc_free += l_sc->sc_free;
  835. sc->sc_dinodes += l_sc->sc_dinodes;
  836. spin_unlock(&sdp->sd_statfs_spin);
  837. if (sc->sc_free < 0)
  838. sc->sc_free = 0;
  839. if (sc->sc_free > sc->sc_total)
  840. sc->sc_free = sc->sc_total;
  841. if (sc->sc_dinodes < 0)
  842. sc->sc_dinodes = 0;
  843. return 0;
  844. }
  845. /**
  846. * gfs2_statfs - Gather and return stats about the filesystem
  847. * @sb: The superblock
  848. * @statfsbuf: The buffer
  849. *
  850. * Returns: 0 on success or error code
  851. */
  852. static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  853. {
  854. struct super_block *sb = dentry->d_inode->i_sb;
  855. struct gfs2_sbd *sdp = sb->s_fs_info;
  856. struct gfs2_statfs_change_host sc;
  857. int error;
  858. if (gfs2_tune_get(sdp, gt_statfs_slow))
  859. error = gfs2_statfs_slow(sdp, &sc);
  860. else
  861. error = gfs2_statfs_i(sdp, &sc);
  862. if (error)
  863. return error;
  864. buf->f_type = GFS2_MAGIC;
  865. buf->f_bsize = sdp->sd_sb.sb_bsize;
  866. buf->f_blocks = sc.sc_total;
  867. buf->f_bfree = sc.sc_free;
  868. buf->f_bavail = sc.sc_free;
  869. buf->f_files = sc.sc_dinodes + sc.sc_free;
  870. buf->f_ffree = sc.sc_free;
  871. buf->f_namelen = GFS2_FNAMESIZE;
  872. return 0;
  873. }
  874. /**
  875. * gfs2_remount_fs - called when the FS is remounted
  876. * @sb: the filesystem
  877. * @flags: the remount flags
  878. * @data: extra data passed in (not used right now)
  879. *
  880. * Returns: errno
  881. */
  882. static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
  883. {
  884. struct gfs2_sbd *sdp = sb->s_fs_info;
  885. struct gfs2_args args = sdp->sd_args; /* Default to current settings */
  886. struct gfs2_tune *gt = &sdp->sd_tune;
  887. int error;
  888. spin_lock(&gt->gt_spin);
  889. args.ar_commit = gt->gt_log_flush_secs;
  890. spin_unlock(&gt->gt_spin);
  891. error = gfs2_mount_args(sdp, &args, data);
  892. if (error)
  893. return error;
  894. /* Not allowed to change locking details */
  895. if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
  896. strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
  897. strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
  898. return -EINVAL;
  899. /* Some flags must not be changed */
  900. if (args_neq(&args, &sdp->sd_args, spectator) ||
  901. args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
  902. args_neq(&args, &sdp->sd_args, localflocks) ||
  903. args_neq(&args, &sdp->sd_args, localcaching) ||
  904. args_neq(&args, &sdp->sd_args, meta))
  905. return -EINVAL;
  906. if (sdp->sd_args.ar_spectator)
  907. *flags |= MS_RDONLY;
  908. if ((sb->s_flags ^ *flags) & MS_RDONLY) {
  909. if (*flags & MS_RDONLY)
  910. error = gfs2_make_fs_ro(sdp);
  911. else
  912. error = gfs2_make_fs_rw(sdp);
  913. if (error)
  914. return error;
  915. }
  916. sdp->sd_args = args;
  917. if (sdp->sd_args.ar_posix_acl)
  918. sb->s_flags |= MS_POSIXACL;
  919. else
  920. sb->s_flags &= ~MS_POSIXACL;
  921. spin_lock(&gt->gt_spin);
  922. gt->gt_log_flush_secs = args.ar_commit;
  923. spin_unlock(&gt->gt_spin);
  924. return 0;
  925. }
  926. /**
  927. * gfs2_drop_inode - Drop an inode (test for remote unlink)
  928. * @inode: The inode to drop
  929. *
  930. * If we've received a callback on an iopen lock then its because a
  931. * remote node tried to deallocate the inode but failed due to this node
  932. * still having the inode open. Here we mark the link count zero
  933. * since we know that it must have reached zero if the GLF_DEMOTE flag
  934. * is set on the iopen glock. If we didn't do a disk read since the
  935. * remote node removed the final link then we might otherwise miss
  936. * this event. This check ensures that this node will deallocate the
  937. * inode's blocks, or alternatively pass the baton on to another
  938. * node for later deallocation.
  939. */
  940. static void gfs2_drop_inode(struct inode *inode)
  941. {
  942. struct gfs2_inode *ip = GFS2_I(inode);
  943. if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
  944. struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
  945. if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
  946. clear_nlink(inode);
  947. }
  948. generic_drop_inode(inode);
  949. }
  950. /**
  951. * gfs2_clear_inode - Deallocate an inode when VFS is done with it
  952. * @inode: The VFS inode
  953. *
  954. */
  955. static void gfs2_clear_inode(struct inode *inode)
  956. {
  957. struct gfs2_inode *ip = GFS2_I(inode);
  958. /* This tells us its a "real" inode and not one which only
  959. * serves to contain an address space (see rgrp.c, meta_io.c)
  960. * which therefore doesn't have its own glocks.
  961. */
  962. if (test_bit(GIF_USER, &ip->i_flags)) {
  963. ip->i_gl->gl_object = NULL;
  964. gfs2_glock_put(ip->i_gl);
  965. ip->i_gl = NULL;
  966. if (ip->i_iopen_gh.gh_gl) {
  967. ip->i_iopen_gh.gh_gl->gl_object = NULL;
  968. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  969. }
  970. }
  971. }
  972. static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
  973. {
  974. do {
  975. if (d1 == d2)
  976. return 1;
  977. d1 = d1->d_parent;
  978. } while (!IS_ROOT(d1));
  979. return 0;
  980. }
  981. /**
  982. * gfs2_show_options - Show mount options for /proc/mounts
  983. * @s: seq_file structure
  984. * @mnt: vfsmount
  985. *
  986. * Returns: 0 on success or error code
  987. */
  988. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  989. {
  990. struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
  991. struct gfs2_args *args = &sdp->sd_args;
  992. int lfsecs;
  993. if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
  994. seq_printf(s, ",meta");
  995. if (args->ar_lockproto[0])
  996. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  997. if (args->ar_locktable[0])
  998. seq_printf(s, ",locktable=%s", args->ar_locktable);
  999. if (args->ar_hostdata[0])
  1000. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  1001. if (args->ar_spectator)
  1002. seq_printf(s, ",spectator");
  1003. if (args->ar_ignore_local_fs)
  1004. seq_printf(s, ",ignore_local_fs");
  1005. if (args->ar_localflocks)
  1006. seq_printf(s, ",localflocks");
  1007. if (args->ar_localcaching)
  1008. seq_printf(s, ",localcaching");
  1009. if (args->ar_debug)
  1010. seq_printf(s, ",debug");
  1011. if (args->ar_upgrade)
  1012. seq_printf(s, ",upgrade");
  1013. if (args->ar_posix_acl)
  1014. seq_printf(s, ",acl");
  1015. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  1016. char *state;
  1017. switch (args->ar_quota) {
  1018. case GFS2_QUOTA_OFF:
  1019. state = "off";
  1020. break;
  1021. case GFS2_QUOTA_ACCOUNT:
  1022. state = "account";
  1023. break;
  1024. case GFS2_QUOTA_ON:
  1025. state = "on";
  1026. break;
  1027. default:
  1028. state = "unknown";
  1029. break;
  1030. }
  1031. seq_printf(s, ",quota=%s", state);
  1032. }
  1033. if (args->ar_suiddir)
  1034. seq_printf(s, ",suiddir");
  1035. if (args->ar_data != GFS2_DATA_DEFAULT) {
  1036. char *state;
  1037. switch (args->ar_data) {
  1038. case GFS2_DATA_WRITEBACK:
  1039. state = "writeback";
  1040. break;
  1041. case GFS2_DATA_ORDERED:
  1042. state = "ordered";
  1043. break;
  1044. default:
  1045. state = "unknown";
  1046. break;
  1047. }
  1048. seq_printf(s, ",data=%s", state);
  1049. }
  1050. if (args->ar_discard)
  1051. seq_printf(s, ",discard");
  1052. lfsecs = sdp->sd_tune.gt_log_flush_secs;
  1053. if (lfsecs != 60)
  1054. seq_printf(s, ",commit=%d", lfsecs);
  1055. return 0;
  1056. }
  1057. /*
  1058. * We have to (at the moment) hold the inodes main lock to cover
  1059. * the gap between unlocking the shared lock on the iopen lock and
  1060. * taking the exclusive lock. I'd rather do a shared -> exclusive
  1061. * conversion on the iopen lock, but we can change that later. This
  1062. * is safe, just less efficient.
  1063. */
  1064. static void gfs2_delete_inode(struct inode *inode)
  1065. {
  1066. struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
  1067. struct gfs2_inode *ip = GFS2_I(inode);
  1068. struct gfs2_holder gh;
  1069. int error;
  1070. if (!test_bit(GIF_USER, &ip->i_flags))
  1071. goto out;
  1072. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  1073. if (unlikely(error)) {
  1074. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  1075. goto out;
  1076. }
  1077. gfs2_glock_dq_wait(&ip->i_iopen_gh);
  1078. gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
  1079. error = gfs2_glock_nq(&ip->i_iopen_gh);
  1080. if (error)
  1081. goto out_truncate;
  1082. if (S_ISDIR(inode->i_mode) &&
  1083. (ip->i_diskflags & GFS2_DIF_EXHASH)) {
  1084. error = gfs2_dir_exhash_dealloc(ip);
  1085. if (error)
  1086. goto out_unlock;
  1087. }
  1088. if (ip->i_eattr) {
  1089. error = gfs2_ea_dealloc(ip);
  1090. if (error)
  1091. goto out_unlock;
  1092. }
  1093. if (!gfs2_is_stuffed(ip)) {
  1094. error = gfs2_file_dealloc(ip);
  1095. if (error)
  1096. goto out_unlock;
  1097. }
  1098. error = gfs2_dinode_dealloc(ip);
  1099. if (error)
  1100. goto out_unlock;
  1101. out_truncate:
  1102. error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
  1103. if (error)
  1104. goto out_unlock;
  1105. /* Needs to be done before glock release & also in a transaction */
  1106. truncate_inode_pages(&inode->i_data, 0);
  1107. gfs2_trans_end(sdp);
  1108. out_unlock:
  1109. if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
  1110. gfs2_glock_dq(&ip->i_iopen_gh);
  1111. gfs2_holder_uninit(&ip->i_iopen_gh);
  1112. gfs2_glock_dq_uninit(&gh);
  1113. if (error && error != GLR_TRYFAILED && error != -EROFS)
  1114. fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
  1115. out:
  1116. truncate_inode_pages(&inode->i_data, 0);
  1117. clear_inode(inode);
  1118. }
  1119. static struct inode *gfs2_alloc_inode(struct super_block *sb)
  1120. {
  1121. struct gfs2_inode *ip;
  1122. ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
  1123. if (ip) {
  1124. ip->i_flags = 0;
  1125. ip->i_gl = NULL;
  1126. }
  1127. return &ip->i_inode;
  1128. }
  1129. static void gfs2_destroy_inode(struct inode *inode)
  1130. {
  1131. kmem_cache_free(gfs2_inode_cachep, inode);
  1132. }
  1133. const struct super_operations gfs2_super_ops = {
  1134. .alloc_inode = gfs2_alloc_inode,
  1135. .destroy_inode = gfs2_destroy_inode,
  1136. .write_inode = gfs2_write_inode,
  1137. .delete_inode = gfs2_delete_inode,
  1138. .put_super = gfs2_put_super,
  1139. .sync_fs = gfs2_sync_fs,
  1140. .freeze_fs = gfs2_freeze,
  1141. .unfreeze_fs = gfs2_unfreeze,
  1142. .statfs = gfs2_statfs,
  1143. .remount_fs = gfs2_remount_fs,
  1144. .clear_inode = gfs2_clear_inode,
  1145. .drop_inode = gfs2_drop_inode,
  1146. .show_options = gfs2_show_options,
  1147. };