super.c 31 KB

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