super.c 33 KB

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