super.c 33 KB

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