super.c 33 KB

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