super.c 33 KB

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